core: Remove '<module>' type.
This change removes the internal '<module>' record type, and changes the initial module to be a plain hash table. * src/symbol.c (init_symbols_): Remove 'cell_symbol_module'. * include/mes/symbols.h (cell_symbol_module): Remove declaration. (CELL_SYMBOL_MAX, CELL_SYMBOL_RECORD_TYPE): Adjust accordingly. * src/module.c (make_initial_module): Use a raw hash table instead of a struct. (module_variable, module_define_x): Adjust accordingly. (make_module_type, module_printer): Remove functions. * src/builtins.c (mes_builtins): Do not register them. * include/mes/builtins.h (make_module_type, module_printer): Remove declarations. * src/eval-apply.c (eval_apply): Replace 'module_printer' with 'hash_table_printer'. * src/mes.c (main): Likewise, and initialize 'R0' after calling 'make_initial_module'. Co-authored-by: Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
This commit is contained in:
parent
9fa03f6182
commit
67a7f485ef
|
@ -100,8 +100,6 @@ struct scm *lognot (struct scm *x);
|
|||
struct scm *logxor (struct scm *x);
|
||||
struct scm *ash (struct scm *n, struct scm *count);
|
||||
/* src/module.c */
|
||||
struct scm *make_module_type ();
|
||||
struct scm *module_printer (struct scm *module);
|
||||
struct scm *module_variable (struct scm *module, struct scm *name);
|
||||
struct scm *module_define_x (struct scm *module, struct scm *name, struct scm *value);
|
||||
struct scm *initial_module ();
|
||||
|
|
|
@ -101,7 +101,6 @@ extern struct scm *cell_symbol_buckets;
|
|||
extern struct scm *cell_symbol_builtin;
|
||||
extern struct scm *cell_symbol_frame;
|
||||
extern struct scm *cell_symbol_hashq_table;
|
||||
extern struct scm *cell_symbol_module;
|
||||
extern struct scm *cell_symbol_procedure;
|
||||
extern struct scm *cell_symbol_record_type;
|
||||
extern struct scm *cell_symbol_size;
|
||||
|
@ -137,14 +136,14 @@ extern struct scm *cell_type_broken_heart;
|
|||
extern struct scm *cell_symbol_program;
|
||||
extern struct scm *cell_symbol_test;
|
||||
|
||||
// CONSTANT SYMBOL_MAX 115
|
||||
#define SYMBOL_MAX 115
|
||||
// CONSTANT SYMBOL_MAX 114
|
||||
#define SYMBOL_MAX 114
|
||||
|
||||
// CONSTANT CELL_UNSPECIFIED 7
|
||||
#define CELL_UNSPECIFIED 7
|
||||
|
||||
// CONSTANT CELL_SYMBOL_RECORD_TYPE 81
|
||||
#define CELL_SYMBOL_RECORD_TYPE 81
|
||||
// CONSTANT CELL_SYMBOL_RECORD_TYPE 80
|
||||
#define CELL_SYMBOL_RECORD_TYPE 80
|
||||
|
||||
|
||||
#endif /* __MES_SYMBOLS_H */
|
||||
|
|
|
@ -210,8 +210,6 @@ mes_builtins (struct scm *a) /*:((internal)) */
|
|||
a = init_builtin (builtin_type, "logxor", -1, &logxor, a);
|
||||
a = init_builtin (builtin_type, "ash", 2, &ash, a);
|
||||
/* src/module.c */
|
||||
a = init_builtin (builtin_type, "make-module-type", 0, &make_module_type, a);
|
||||
a = init_builtin (builtin_type, "module-printer", 1, &module_printer, a);
|
||||
a = init_builtin (builtin_type, "module-variable", 2, &module_variable, a);
|
||||
a = init_builtin (builtin_type, "module-define!", 3, &module_define_x, a);
|
||||
a = init_builtin (builtin_type, "initial-module", 0, &initial_module, a);
|
||||
|
|
|
@ -921,7 +921,10 @@ begin_expand:
|
|||
push_cc (input, R2, R0, cell_vm_return);
|
||||
x = read_input_file_env (R0);
|
||||
if (g_debug > 5)
|
||||
module_printer (M0);
|
||||
{
|
||||
eputs ("initial module obarray\n");
|
||||
hash_table_printer (M0);
|
||||
}
|
||||
gc_pop_frame ();
|
||||
input = R1;
|
||||
R1 = x;
|
||||
|
|
11
src/mes.c
11
src/mes.c
|
@ -190,10 +190,14 @@ main (int argc, char **argv, char **envp)
|
|||
a = mes_builtins (a);
|
||||
a = init_time (a);
|
||||
M0 = make_initial_module (a);
|
||||
R0 = cell_nil;
|
||||
g_macros = make_hash_table_ (0);
|
||||
|
||||
if (g_debug > 5)
|
||||
module_printer (M0);
|
||||
{
|
||||
eputs ("initial module obarray\n");
|
||||
hash_table_printer (M0);
|
||||
}
|
||||
|
||||
struct scm *program = read_boot ();
|
||||
R0 = acons (cell_symbol_program, program, R0);
|
||||
|
@ -217,7 +221,10 @@ main (int argc, char **argv, char **envp)
|
|||
if (g_debug != 0)
|
||||
{
|
||||
if (g_debug > 5)
|
||||
module_printer (M0);
|
||||
{
|
||||
eputs ("initial module obarray\n");
|
||||
hash_table_printer (M0);
|
||||
}
|
||||
|
||||
if (g_debug < 3)
|
||||
gc_stats_ ("\ngc run");
|
||||
|
|
66
src/module.c
66
src/module.c
|
@ -21,51 +21,17 @@
|
|||
#include "mes/lib.h"
|
||||
#include "mes/mes.h"
|
||||
|
||||
struct scm *
|
||||
make_module_type () /*:(internal)) */
|
||||
{
|
||||
struct scm *fields = cell_nil;
|
||||
fields = cons (cstring_to_symbol ("globals"), fields);
|
||||
fields = cons (cstring_to_symbol ("locals"), fields);
|
||||
fields = cons (cstring_to_symbol ("name"), fields);
|
||||
fields = cons (fields, cell_nil);
|
||||
fields = cons (cell_symbol_module, fields);
|
||||
return make_struct (cell_symbol_record_type, fields, cell_unspecified);
|
||||
}
|
||||
|
||||
struct scm *
|
||||
make_initial_module (struct scm *a) /*:((internal)) */
|
||||
{
|
||||
struct scm *module_type = make_module_type ();
|
||||
a = acons (cell_symbol_module, module_type, a);
|
||||
|
||||
struct scm *hash_table_type = scm_hash_table_type;
|
||||
a = acons (cell_symbol_hashq_table, hash_table_type, a);
|
||||
|
||||
make_variable_type ();
|
||||
struct scm *variable_type = scm_variable_type;
|
||||
a = acons (cell_symbol_variable, variable_type, a);
|
||||
|
||||
struct scm *name = cons (cstring_to_symbol ("boot"), cell_nil);
|
||||
struct scm *globals = make_hash_table_ (0);
|
||||
struct scm *locals = cell_nil;
|
||||
|
||||
struct scm *values = cell_nil;
|
||||
values = cons (globals, values);
|
||||
values = cons (locals, values);
|
||||
values = cons (name, values);
|
||||
values = cons (cell_symbol_module, values);
|
||||
struct scm *module = make_struct (module_type, values, cstring_to_symbol ("module-printer"));
|
||||
R0 = cell_nil;
|
||||
R0 = cons (a->cdr->car, R0);
|
||||
R0 = cons (a->car, R0);
|
||||
M0 = module;
|
||||
struct scm *var;
|
||||
struct scm *module = make_hash_table_ (100);
|
||||
while (a->type == TPAIR)
|
||||
{
|
||||
module_define_x (module, a->car->car, a->car->cdr);
|
||||
var = make_variable (a->car->cdr);
|
||||
hashq_set_x (module, a->car->car, var);
|
||||
a = a->cdr;
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
|
@ -75,37 +41,17 @@ initial_module ()
|
|||
return M0;
|
||||
}
|
||||
|
||||
struct scm *
|
||||
module_printer (struct scm *module)
|
||||
{
|
||||
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);
|
||||
struct scm *table = struct_ref_ (module, 5);
|
||||
fdputs ("globals:\n ", __stdout);
|
||||
display_ (table);
|
||||
fdputc ('>', __stdout);
|
||||
}
|
||||
|
||||
struct scm *
|
||||
module_variable (struct scm *module, struct scm *name)
|
||||
{
|
||||
module = M0;
|
||||
struct scm *globals = struct_ref_ (module, 5);
|
||||
return hashq_get_handle (globals, name);
|
||||
return hashq_get_handle (module, name);
|
||||
}
|
||||
|
||||
struct scm *
|
||||
module_define_x (struct scm *module, struct scm *name, struct scm *value)
|
||||
{
|
||||
module = M0;
|
||||
struct scm *globals = struct_ref_ (module, 5);
|
||||
struct scm *var = make_variable (value);
|
||||
return hashq_set_x (globals, name, var);
|
||||
return hashq_set_x (module, name, var);
|
||||
}
|
||||
|
|
|
@ -136,7 +136,6 @@ init_symbols_ () /*:((internal)) */
|
|||
cell_symbol_builtin = init_symbol (g_symbol, TSYMBOL, "<builtin>");
|
||||
cell_symbol_frame = init_symbol (g_symbol, TSYMBOL, "<frame>");
|
||||
cell_symbol_hashq_table = init_symbol (g_symbol, TSYMBOL, "<hashq-table>");
|
||||
cell_symbol_module = init_symbol (g_symbol, TSYMBOL, "<module>");
|
||||
cell_symbol_procedure = init_symbol (g_symbol, TSYMBOL, "procedure");
|
||||
cell_symbol_record_type = init_symbol (g_symbol, TSYMBOL, "<record-type>");
|
||||
cell_symbol_size = init_symbol (g_symbol, TSYMBOL, "size");
|
||||
|
|
Loading…
Reference in New Issue