2018-10-14 06:15:22 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
2020-04-20 17:47:04 +00:00
|
|
|
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2018-10-14 06:15:22 +00:00
|
|
|
*
|
|
|
|
* This file is part of GNU Mes.
|
|
|
|
*
|
|
|
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* GNU Mes is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-08 13:36:22 +00:00
|
|
|
#include "mes/lib.h"
|
|
|
|
#include "mes/mes.h"
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
2020-04-20 17:47:04 +00:00
|
|
|
make_module_type () /*:(internal)) */
|
2018-10-14 06:15:22 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *fields = cell_nil;
|
2018-10-14 06:15:22 +00:00
|
|
|
fields = cons (cstring_to_symbol ("globals"), fields);
|
|
|
|
fields = cons (cstring_to_symbol ("locals"), fields);
|
|
|
|
fields = cons (cstring_to_symbol ("name"), fields);
|
2018-10-15 14:57:00 +00:00
|
|
|
fields = cons (fields, cell_nil);
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
fields = cons (cell_symbol_module, fields);
|
2020-04-20 17:47:04 +00:00
|
|
|
return make_struct (cell_symbol_record_type, fields, cell_unspecified);
|
2018-10-15 13:45:41 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
make_initial_module (struct scm *a) /*:((internal)) */
|
2018-10-15 13:45:41 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *module_type = make_module_type ();
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
a = acons (cell_symbol_module, module_type, a);
|
2018-10-15 18:42:10 +00:00
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *hashq_type = make_hashq_type ();
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
a = acons (cell_symbol_hashq_table, hashq_type, a);
|
2018-10-15 13:45:41 +00:00
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *name = cons (cstring_to_symbol ("boot"), cell_nil);
|
|
|
|
struct scm *globals = make_hash_table_ (0);
|
|
|
|
struct scm *locals = cell_nil;
|
2018-10-15 13:45:41 +00:00
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *values = cell_nil;
|
2018-10-15 13:45:41 +00:00
|
|
|
values = cons (globals, values);
|
2018-10-14 07:10:30 +00:00
|
|
|
values = cons (locals, values);
|
2018-10-14 06:15:22 +00:00
|
|
|
values = cons (name, values);
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
values = cons (cell_symbol_module, values);
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *module = make_struct (module_type, values, cstring_to_symbol ("module-printer"));
|
2020-05-17 20:32:53 +00:00
|
|
|
R0 = cell_nil;
|
2020-10-18 09:34:32 +00:00
|
|
|
R0 = cons (a->cdr->car, R0);
|
|
|
|
R0 = cons (a->car, R0);
|
2020-05-17 20:32:53 +00:00
|
|
|
M0 = module;
|
2020-10-18 09:34:32 +00:00
|
|
|
while (a->type == TPAIR)
|
2018-10-14 07:10:30 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
module_define_x (module, a->car->car, a->car->cdr);
|
|
|
|
a = a->cdr;
|
2018-10-14 07:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-10-14 06:15:22 +00:00
|
|
|
return module;
|
|
|
|
}
|
2018-10-14 06:30:18 +00:00
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
module_printer (struct scm *module)
|
2018-10-14 07:10:30 +00:00
|
|
|
{
|
2019-05-18 11:27:42 +00:00
|
|
|
fdputs ("#<", __stdout);
|
|
|
|
display_ (struct_ref_ (module, 2));
|
|
|
|
fdputc (' ', __stdout);
|
|
|
|
fdputs ("name: ", __stdout);
|
|
|
|
display_ (struct_ref_ (module, 3));
|
|
|
|
fdputc (' ', __stdout);
|
|
|
|
fdputs ("locals: ", __stdout);
|
|
|
|
display_ (struct_ref_ (module, 4));
|
|
|
|
fdputc (' ', __stdout);
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *table = struct_ref_ (module, 5);
|
2019-03-02 11:35:18 +00:00
|
|
|
fdputs ("globals:\n ", __stdout);
|
2018-10-15 13:45:41 +00:00
|
|
|
display_ (table);
|
2019-03-02 11:35:18 +00:00
|
|
|
fdputc ('>', __stdout);
|
2018-10-14 07:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
module_variable (struct scm *module, struct scm *name)
|
2018-10-14 07:10:30 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
/*struct scm *locals = struct_ref_ (module, 3);*/
|
|
|
|
struct scm *locals = module;
|
|
|
|
struct scm *x = assq (name, locals);
|
2018-10-14 07:10:30 +00:00
|
|
|
if (x == cell_f)
|
|
|
|
{
|
2020-05-17 20:32:53 +00:00
|
|
|
module = M0;
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *globals = struct_ref_ (module, 5);
|
core: Add hashq_get_handle, hash, hash_ref, hash_set_x.
* src/mes.c (scm_symbol_hashq_table, scm_symbol_record_type,
scm_symbol_module, scm_symbol_buckets, scm_symbol_size): New symbols.
Update users.
* src/hash.c (hash_list_of_char): Rename from hashq_. Respect size,
update callers.
(hashq_, hash_ hash, hashq_get_handle, hash_ref, hash_set_x_,
hash_set_x): New function.
(hashq_ref): Do not return handle. Update callers.
2018-10-18 05:55:28 +00:00
|
|
|
x = hashq_get_handle (globals, name, cell_f);
|
2018-10-14 07:10:30 +00:00
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
module_ref (struct scm *module, struct scm *name)
|
2018-10-14 06:30:18 +00:00
|
|
|
{
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *x = module_variable (module, name);
|
2018-10-14 06:30:18 +00:00
|
|
|
if (x == cell_f)
|
|
|
|
return cell_undefined;
|
2020-10-18 09:34:32 +00:00
|
|
|
return x->cdr;
|
2018-10-14 06:30:18 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *
|
|
|
|
module_define_x (struct scm *module, struct scm *name, struct scm *value)
|
2018-10-14 06:30:18 +00:00
|
|
|
{
|
2020-05-17 20:32:53 +00:00
|
|
|
module = M0;
|
2020-10-18 09:34:32 +00:00
|
|
|
struct scm *globals = struct_ref_ (module, 5);
|
2018-10-15 11:36:19 +00:00
|
|
|
return hashq_set_x (globals, name, value);
|
2018-10-14 06:30:18 +00:00
|
|
|
}
|