2018-10-14 06:15:22 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
|
|
|
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-10-14 07:10:30 +00:00
|
|
|
SCM struct_ref_ (SCM x, long i);
|
|
|
|
SCM struct_set_x_ (SCM x, long i, SCM e);
|
2018-11-11 15:25:36 +00:00
|
|
|
SCM cstring_to_symbol (char const *s);
|
2018-10-14 07:10:30 +00:00
|
|
|
|
2018-10-14 06:15:22 +00:00
|
|
|
SCM
|
2018-10-15 13:45:41 +00:00
|
|
|
make_module_type () ///(internal))
|
2018-10-14 06:15:22 +00:00
|
|
|
{
|
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
|
|
|
SCM record_type = cell_symbol_record_type; // FIXME
|
2018-10-14 06:15:22 +00:00
|
|
|
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);
|
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);
|
2018-10-15 18:42:10 +00:00
|
|
|
return make_struct (record_type, fields, cell_unspecified);
|
2018-10-15 13:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
make_initial_module (SCM a) ///((internal))
|
|
|
|
{
|
2018-10-15 18:42:10 +00:00
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
2018-10-14 06:15:22 +00:00
|
|
|
SCM name = cons (cstring_to_symbol ("boot"), cell_nil);
|
2018-10-15 11:36:19 +00:00
|
|
|
SCM globals = make_hash_table_ (0);
|
2018-10-14 07:10:30 +00:00
|
|
|
SCM locals = cell_nil;
|
2018-10-15 13:45:41 +00:00
|
|
|
|
|
|
|
SCM values = cell_nil;
|
|
|
|
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);
|
core: Remove struct definitions for builtins, drop snarfing.
After making a change to the list of builtin functions, run
cat src/*.i
and move the into
src/mes.c:mes_builtins ()
and, or also after changing the list of fixed symbols in src/mes.c:mes_symbols (), do
cat src/*.h > src/builtins.h
* build-aux/build.sh.in: Remove snarfing.
* build-aux/bootstrap.sh.in: Likewise.
* mes/module/mes/display.mes (display):
* mes/module/mes/type-0.mes (cell:type-alist): Remove <cell:function>.
(function?, builtin?): Remove.
* src/builtins.h: New file.
* src/mes.c (TFUNCTION): Remove.
(struct function): Remove.
(apply_builtin): Rewrite from call.
(mes_builtins): Rewrite.
(init_builtin, make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin, builtin_p, builtin_printer): New function.
2019-01-04 08:55:16 +00:00
|
|
|
SCM module = make_struct (module_type, values, cstring_to_symbol ("module-printer"));
|
2018-10-14 07:10:30 +00:00
|
|
|
r0 = cell_nil;
|
2018-10-15 18:42:10 +00:00
|
|
|
r0 = cons (CADR (a), r0);
|
2018-10-14 07:10:30 +00:00
|
|
|
r0 = cons (CAR (a), r0);
|
|
|
|
m0 = module;
|
|
|
|
while (TYPE (a) == TPAIR)
|
|
|
|
{
|
|
|
|
module_define_x (module, CAAR (a), CDAR (a));
|
|
|
|
a = CDR (a);
|
|
|
|
}
|
|
|
|
|
2018-10-14 06:15:22 +00:00
|
|
|
return module;
|
|
|
|
}
|
2018-10-14 06:30:18 +00:00
|
|
|
|
2018-10-14 07:10:30 +00:00
|
|
|
SCM
|
|
|
|
module_printer (SCM module)
|
|
|
|
{
|
2018-10-15 18:42:10 +00:00
|
|
|
//module = m0;
|
2019-03-02 11:35:18 +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);
|
2018-10-15 18:42:10 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
module_variable (SCM module, SCM name)
|
|
|
|
{
|
|
|
|
//SCM locals = struct_ref_ (module, 3);
|
|
|
|
SCM locals = module;
|
|
|
|
SCM x = assq (name, locals);
|
|
|
|
if (x == cell_f)
|
|
|
|
{
|
|
|
|
module = m0;
|
2018-10-15 18:42:10 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-10-14 06:30:18 +00:00
|
|
|
SCM
|
|
|
|
module_ref (SCM module, SCM name)
|
|
|
|
{
|
|
|
|
SCM x = module_variable (module, name);
|
|
|
|
if (x == cell_f)
|
|
|
|
return cell_undefined;
|
|
|
|
return CDR (x);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
2018-10-14 07:10:30 +00:00
|
|
|
module_define_x (SCM module, SCM name, SCM value)
|
2018-10-14 06:30:18 +00:00
|
|
|
{
|
2018-10-14 07:10:30 +00:00
|
|
|
module = m0;
|
2018-10-15 18:42:10 +00:00
|
|
|
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
|
|
|
}
|