2018-10-14 07:15:22 +01:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
|
|
|
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2019-01-13 10:02:28 +00:00
|
|
|
* Copyright © 2019 Jeremiah Orians <jeremiah@pdp10.guru>
|
2018-10-14 07:15:22 +01: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 14:36:22 +01:00
|
|
|
#include "mes/lib.h"
|
|
|
|
#include "mes/mes.h"
|
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *
|
|
|
|
make_module_type ()
|
2018-10-14 07:15:22 +01:00
|
|
|
{
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *record_type = cell_symbol_record_type; /* FIXME */
|
|
|
|
struct scm *fields = cell_nil;
|
2018-10-14 07:15:22 +01: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 15:57:00 +01: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 06:55:28 +01:00
|
|
|
fields = cons (cell_symbol_module, fields);
|
2018-10-15 19:42:10 +01:00
|
|
|
return make_struct (record_type, fields, cell_unspecified);
|
2018-10-15 14:45:41 +01:00
|
|
|
}
|
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *
|
|
|
|
module_variable (struct scm *module, struct scm *name)
|
2018-10-15 14:45:41 +01:00
|
|
|
{
|
2019-01-13 10:02:28 +00:00
|
|
|
/* struct scm* locals = struct_ref_ (module, 3); */
|
|
|
|
struct scm *locals = module;
|
|
|
|
struct scm *x = assq (name, locals);
|
|
|
|
|
|
|
|
if (x == cell_f)
|
|
|
|
{
|
|
|
|
struct scm *globals = struct_ref_ (M0, 5);
|
|
|
|
x = hashq_get_handle (globals, name, cell_f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
2018-10-15 19:42:10 +01:00
|
|
|
|
2018-10-15 14:45:41 +01:00
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *
|
|
|
|
module_ref (struct scm *module, struct scm *name)
|
|
|
|
{
|
|
|
|
struct scm *y = module_variable (module, name);
|
2018-10-15 14:45:41 +01:00
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
if (y == cell_f)
|
2018-10-14 08:10:30 +01:00
|
|
|
{
|
2019-01-13 10:02:28 +00:00
|
|
|
return cell_undefined;
|
2018-10-14 08:10:30 +01:00
|
|
|
}
|
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
return y->cdr;
|
2018-10-14 07:15:22 +01:00
|
|
|
}
|
2018-10-14 07:30:18 +01:00
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *
|
|
|
|
module_define_x (struct scm *module, struct scm *name, struct scm *value)
|
2018-10-14 08:10:30 +01:00
|
|
|
{
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *globals = struct_ref_ (M0, 5);
|
|
|
|
return hashq_set_x (globals, name, value);
|
2018-10-14 08:10:30 +01:00
|
|
|
}
|
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
/* External functions */
|
|
|
|
struct scm *
|
|
|
|
module_variable_ (struct scm *module, struct scm *name) /* EXTERNAL */
|
2018-10-14 08:10:30 +01:00
|
|
|
{
|
2019-01-13 10:02:28 +00:00
|
|
|
return module_variable (module, name);
|
2018-10-14 08:10:30 +01:00
|
|
|
}
|
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *
|
|
|
|
module_ref_ (struct scm *module, struct scm *name) /* EXTERNAL */
|
2018-10-14 07:30:18 +01:00
|
|
|
{
|
2019-01-13 10:02:28 +00:00
|
|
|
return module_ref (module, name);
|
2018-10-14 07:30:18 +01:00
|
|
|
}
|
|
|
|
|
2019-01-13 10:02:28 +00:00
|
|
|
struct scm *
|
|
|
|
make_module_type_ () /* EXTERNAL */
|
2018-10-14 07:30:18 +01:00
|
|
|
{
|
2019-01-13 10:02:28 +00:00
|
|
|
return make_module_type ();
|
2018-10-14 07:30:18 +01:00
|
|
|
}
|