Commit Graph

197 Commits

Author SHA1 Message Date
Timothy Sample b0123a9c38 core: Add the 'make-binding' builtin.
* src/eval-apply.c (make_binding): New function.
* include/mes/builtins.h (make_binding): Declare it.
* src/builtins.c (mes_builtins): Register it.
2022-04-26 16:46:08 -06:00
Timothy Sample 5167f70038 core: set!: Check for undefined variables.
* src/eval-apply.c (set_x): Add the 'define_p' argument and if it is
not set, signal an error on an undefined variable.
(eval_apply): When evaluating 'set-x!' forms, leave 'define_p'
unset; when evaluating 'define' forms, set 'define_p'.
* include/mes/mes.h (set_x): Adjust declaration accordingly.
2022-04-26 16:46:08 -06:00
Timothy Sample 01d658a356 core: Make symbol lookup extensible.
* src/module.c (set_current_module): New function.
(module_variable): Remove function.
(module_define_x): Remove function.
(current_module_variable): New function.
* src/eval-apply.c (lookup_binding): Replace 'module_variable' with
'current_module_variable'; add the 'define_p' argument.
(set_x): Adjust for 'define_p'.
(lookup_value): Likewise.
(expand_variable_): Likewise.
(eval_apply): When evaluating defines, replace 'module_define_x' with
'lookup_binding' with 'define_p' set.
* src/gc.c (gc_init)[!__M2_PLANET__]: Double ARENA_SIZE.
* include/mes/constants.h (MODULE_EVAL_CLOSURE): New constant.
* include/mes/mes.h (current_module_variable): New declaration.
(current_module_define_x): New declaration.
* include/mes/builtins.h (set_current_module): New declaration.
(lookup_binding): Declare the 'define_p' argument.
(module_variable): Remove declaration.
(module_define_x): Remove declaration.
* src/builtins.c (mes_builtins): Register 'set-current-module';
remove 'module-variable' and 'module-define!'.
* mes/module/boot-0.scm (defined?): Do not use 'module-variable'.
* mes/module/boot-00.scm (defined?): Likewise.
* mes/module/boot-01.scm (defined?): Likewise.
* mes/module/boot-02.scm (defined?): Likewise.
* mes/module/boot-03.scm (defined?): Likewise.
* scaffold/boot/60-let-syntax-expanded.scm (defined?): Likewise.
* mes/module/mes/fluids.mes (make-fluid): Do not use
'module-define!', and wrap fluids in a variable record.
* tests/macro.test (make-fluid): Likewise.

Co-authored-by: Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
2022-04-26 16:46:05 -06:00
Timothy Sample 22d89dfa97 core: Make 'primitive-load' a builtin.
In addition to simplifying the interpreter, this change ensures that
'primitive-load' evaluates the loaded file in the top level
environment.

* include/mes/symbols.h (cell_symbol_primitive_load): Remove
variable.
(cell_vm_begin_primitive_load): Remove variable.
(cell_vm_begin_expand_primitive_load): Remove variable.
(SYMBOL_MAX, CELL_SYMBOL_RECORD_TYPE): Adjust accordingly.
* src/symbol.c (init_symbols): Do not initialize removed variables.
* src/eval-apply.c (eval_apply): Remove primitive load code.
(primitive_load): New function.
* include/mes/builtins.h (primitive_load): Declare it.
* src/builtins.c (mes_builtins): Initialize it.
* mes/module/mes/boot-03.scm: Remove duplicate call to
'primitive-load'.
* mes/module/mes/boot-0.scm: Remove extra call to 'primitive-load';
adjust how the "--main" option is handled.
* tests/base/test.test: Add a test.
* tests/data/load.scm: Set the 'toplevel?' variable to support the
new test.
2022-04-26 11:22:57 -06:00
Timothy Sample 57610dc246 core: Add an 'M1' register for the current module.
* include/mes/mes.h (M1): New variable.
* src/mes.c (main): Initialize it.
* src/gc.c (gc_flip): Account for it.
(gc_): Copy it.
(gc_dump_state): Dump it.
* src/test/gc.c (test_setup, main): Initialize it.
* src/module.c (current_module): New function.
* src/builtiins.c (mes_builtins): Register it as 'current-module'.
* include/mes/builtins.h (current_module): Declare it.
2022-04-26 11:22:57 -06:00
Timothy Sample a8ce580123 core: Rename the 'current-module' symbol.
This change renames 'current-module' to 'current-environment'.  This
will make way for 'current-module' to actually be a module.

* include/mes/symbols.h (cell_symbol_current_module): Rename this...
(cell_symbol_current_environment): ...to this.
* src/eval-apply.c: Adjust accordingly.
* src/symbol.c: Adjust accordingly, and update the Scheme name to
'current-environment'.
* mes/module/mes/base.mes: Adjust accordingly.
* mes/module/mes/boot-0.scm: Adjust accordingly.
* mes/module/mes/boot-00.scm: Adjust accordingly.
* mes/module/mes/boot-01.scm: Adjust accordingly.
* mes/module/mes/boot-02.scm: Adjust accordingly.
* mes/module/mes/boot-03.scm: Adjust accordingly.
* mes/module/mes/display.mes: Adjust accordingly.
* mes/module/mes/module.mes: Adjust accordingly.
* mes/module/mes/psyntax-0.mes: Adjust accordingly.
* mes/module/mes/repl.mes: Adjust accordingly.
* mes/module/mes/scm.mes: Adjust accordingly.
* mes/module/srfi/srfi-16.scm: Adjust accordingly.
* mes/module/srfi/srfi-26.scm: Adjust accordingly.
* module/mescc/compile.scm: Adjust accordingly.
* scaffold/boot/17-open-input-string.scm: Adjust accordingly.
* scaffold/boot/4c-quasiquote.scm: Adjust accordingly.
* scaffold/boot/4f-string-split.scm: Adjust accordingly.
* scaffold/boot/50-make-string.scm: Adjust accordingly.
* scaffold/boot/50-string-join.scm: Adjust accordingly.
* scaffold/boot/51-module.scm: Adjust accordingly.
* scaffold/boot/52-define-module.scm: Adjust accordingly.
* scaffold/boot/60-let-syntax-expanded.scm: Adjust accordingly.
* scaffold/boot/60-let-syntax.scm: Adjust accordingly.
* scaffold/gc.scm: Adjust accordingly.
* tests/gc.test: Adjust accordingly.
* tests/psyntax.test: Adjust accordingly.
2022-04-26 11:22:57 -06:00
Timothy Sample e743c1386c 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>
2022-04-26 11:22:57 -06:00
Timothy Sample c18b95620a core: Use variables for modules.
This change introduces a 'lexical?' field for bindings (called
'lexical_p' and stored in the cdr of the binding cell).  Non-lexical
bindings handle variables transparently, while lexical bindings do
not.

* src/module.c (module_define_x): Wrap value in a variable.
* include/mes/mes.h (scm): Add 'lexical_p' to the cdr union.
(set_x): New declaration.
* src/eval-apply.c (make_binding_): Add a 'lexical_p' argument.
(lookup_handle): Remove function.
(lookup_binding): Add function.
(lookup_value): Use 'lookup_binding' and return the contents of
variables that are not bound lexically.
(set_env_x): Remove function.
(set_x): New function.
(expand_variable_): Use 'lookup_binding' in place of
'lookup_handle'.
(eval_apply): Likewise; use 'set_x' in place of 'set_env_x'; and
when evaluating a binding, return the contents of variables that are
not bound lexically.
* include/mes/builtins.h (set_env_x): Remove declaration.
* src/builtins.c (mes_builtins): Do not register 'set-env!'.
* scaffold/boot/53-closure-display.scm (closure)[mes]: Rewrite to
avoid 'module-variable'.
2022-04-26 11:22:06 -06:00
Timothy Sample 5edef591b7 core: Implement Guile-style variables.
* src/variable.c: New file.
* simple.make (LIBMES_SOURCES): Add it.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* build-aux/snarf.sh: Snarf it.
* kaem.run: Compile it.
* include/mes/builtins.h (make_variable): New function.
(variable_p): New function.
(variable_ref): New function.
(variable_set_x): New function.
(variable_printer): New function.
* src/builtins.c (mes_builtins): Register them.
* include/mes/mes.h (make_variable_type): New function.
(scm_variable_type): New variable.
* src/module.c (make_initial_module): Initialize it.
* src/gc.c (gc_flip, gc_): Keep track of it.
* include/mes/symbols.h (cell_symbol_variable): New variable.
(SYMBOL_MAX): Adjust accordingly.
* src/symbol.c (init_symbols): Initialize 'cell_symbol_variable'.
* mes/module/mes/scm.mes (make-undefined-variable): New procedure.
(variable-bound?): New procedure.
* tests/variable.test: New file.
* build-aux/check-mes.sh (TESTS): Add it.
2022-04-25 14:19:03 -06:00
Jan (janneke) Nieuwenhuizen c317e939b9 core: Replace special cell_boot_module with initial-module builtin.
* src/module.c (initial_module): New builtin.
* include/mes/builtins.h: Declare it.
* src/builtins.c (mes_builtins): Register it.
* include/mes/symbols.h (cell_boot_module): Remove.
* src/symbol.c (init_symbols_): Update.
(init_symbols): Likewise.
* src/eval-apply.c (eval_apply): Likewise.
(expand_variable_): Likewise.
* tests/macro.test (make-fluid): Likewise.
* mes/module/mes/fluids.mes (make-fluid):  Likewise.
2022-04-25 14:19:03 -06:00
Timothy Sample 870256ed3e core: Refactor name resolution.
* src/module.c (module_variable): Do not search local bindings.
(module_ref): Remove function.
* src/eval-apply.c (lookup_handle): New function.
(lookup_value): New function.
(set_env_x, expand_variable_, eval_apply): Use 'lookup-handle' and
'lookup-value' in place of 'module_variable' and 'module_ref'
respectively.
* src/core.c (error): Likewise.
* include/mes/mes.h (lookup_handle, lookup_value): Add declarations.
* include/mes/builtins.h (module_ref): Remove declaration.
* src/builtins.c (mes_builtins): Remove "module-ref".

Co-authored-by: Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
2022-04-25 14:19:03 -06:00
Timothy Sample 91b1c6e233 core: Rename variable type to binding.
This change allows us to use "variable" in the Guile sense, which is
an anonymous box for storing a value.

* include/mes/constants.h (TVARIABLE): Rename this...
(TBINDING): ...to this.
* include/mes/mes.h (scm): Rename the 'variable' field to 'binding'.
* include/mes/symbols.h (cell_type_variable): Rename this...
(cell_type_binding): ...to this.
* src/gc.c (gc_cellcpy, gc_loop, gc_dump_arena): Adjust accordingly.
* src/eval-apply.c (make_variable_): Rename this...
(make_binding_): ...to this.
(set_env_x, expand_variable_, eval_apply): Adjust accordingly.
* src/symbol.c (init_symbol): Adjust accordingly and rename the
'<cell:variable>' symbol to '<cell:binding>'.
* mes/module/mes/type-0.mes (cell:type-alist): Adjust accordingly.
(variable?): Rename this...
(binding?): ...to this.
* src/display.c (display_helper): Adjust accordingly and print
"binding" instead of "variable".
* mes/module/mes/display.mes (display): Likewise.
2022-04-25 09:22:13 -06:00
Jan (janneke) Nieuwenhuizen 07c90bdebd core: Add hashq_create_handle_x.
* src/hash.c (hash_create_handle_x): New function.
* include/mes/builtins.h: Declare it.
* src/builtins.c (mes_builtins): Register it.
* tests/hash.test: Add a test.

Co-authored-by: Timothy Sample <samplet@ngyro.com>
2022-04-25 09:22:13 -06:00
Jan (janneke) Nieuwenhuizen 64d6dff810 core: Add hash_clear!.
* src/hash.c (hash_clear_x): New builtin.
* include/mes/builtins.h: Declare it.
* src/builtins.c (mes_builtins): Register it.
* tests/hash.test: Add a test.

Co-authored-by: Timothy Sample <samplet@ngyro.com>
2022-04-25 09:22:13 -06:00
Jan (janneke) Nieuwenhuizen 858daa625d core: Add hash-table?.
* include/mes/mes.h (scm_hash_table_type): New type.
* src/hash.c (make_hash_table_type): Rename from make_hash_type, and
initialize it.
* src/symbol.c (init_symbols): Add it to environment.
* tests/hash.test: Add a test.

Co-authored-by: Timothy Sample <samplet@ngyro.com>
2022-04-25 09:22:13 -06:00
Jan (janneke) Nieuwenhuizen e4d35f5915 core: Add hash-map->list.
* src/hash.c (hash_buckets): New function.
* src/builtins.c (mes_builtins): Initialize it.
* include/mes/builtins.h: Declare it.
* mes/module/mes/scm.mes (hash-map->list): New procedure.
* tests/hash.test: Add a test.
* tests/gc.test: Bump arena size to handle more built-ins.

Co-authored-by: Timothy Sample <samplet@ngyro.com>
2022-04-25 09:22:10 -06:00
Jan (janneke) Nieuwenhuizen 3339cd11dd mes: hash: Guile interface compatibility.
* src/hash.c (hashq_get_handle): Remove the dflt argument.
(hashq_ref): Rename this...
(hashq_ref_): ...to this, update for hashq_get_handle, and handle
the dflt argument directly.
(hash_ref): Rename this...
(hash_ref_): ...to this, and fix handling of the dflt argument.
* include/mes/builtins.h: Update accordingly.
* src/eval-apply.c (macro_get_handle): Update for hashq_get_handle.
* src/module.c (module_variable): Likewise.
* src/builtins.c (mes_builtins): Set hashq-get-handle argument count
to 2; rename hashq-ref to core:hashq-ref; and rename hash-ref to
core:hash-ref.
* mes/module/mes/scm.mes (hashq-ref, hash-ref): New procedures.
* tests/hash.test: Add some tests.

Co-authored-by: Timothy Sample <samplet@ngyro.com>
2022-03-24 11:51:33 -06:00
Jan (janneke) Nieuwenhuizen 9c9824eb10
core: Resurrect gcc-10 support.
* include/mes/mes.h (g_datadir, g_debug, g_buf, g_continuations,
g_symbols, g_symbol_max, g_mini, R0, R1, R2, R3, M0, g_macros, g_ports,
ARENA_SIZE, MAX_ARENA_SIZE, STACK_SIZE, JAM_SIZE, GC_SAFETY, MAX_STRING,
g_arena, cell_arena, cell_zero, g_free, g_symbol, g_stack_array,
g_cells, g_news, g_stack, gc_count, gc_start_time, gc_end_time, gc_time,
__execl_c_argv, __open_boot_buf, __open_boot_file_name, __setenv_buf,
__reader_read_char_buf, g_start_time, __gettimeofday_time,
__get_internal_run_time_ts): Declare extern.
* include/mes/symbols.h ( cell_nil, cell_f, cell_t, cell_dot,
cell_arrow, cell_undefined, cell_unspecified, cell_closure,
cell_circular, cell_vm_apply, cell_vm_apply2, cell_vm_begin,
cell_vm_begin_eval, cell_vm_begin_expand, cell_vm_begin_expand_eval,
cell_vm_begin_expand_macro, cell_vm_begin_expand_primitive_load,
cell_vm_begin_primitive_load, cell_vm_begin_read_input_file,
cell_vm_call_with_current_continuation2, cell_vm_call_with_values2,
cell_vm_eval, cell_vm_eval2, cell_vm_eval_check_func,
cell_vm_eval_define, cell_vm_eval_macro_expand_eval,
cell_vm_eval_macro_expand_expand, cell_vm_eval_pmatch_car,
cell_vm_eval_pmatch_cdr, cell_vm_eval_set_x, cell_vm_evlis,
cell_vm_evlis2, cell_vm_evlis3, cell_vm_if, cell_vm_if_expr,
cell_vm_macro_expand, cell_vm_macro_expand_car,
cell_vm_macro_expand_cdr, cell_vm_macro_expand_define,
cell_vm_macro_expand_define_macro, cell_vm_macro_expand_lambda,
cell_vm_macro_expand_set_x, cell_vm_return, cell_symbol_lambda,
cell_symbol_begin, cell_symbol_if, cell_symbol_quote,
cell_symbol_define, cell_symbol_define_macro, cell_symbol_quasiquote,
cell_symbol_unquote, cell_symbol_unquote_splicing, cell_symbol_syntax,
cell_symbol_quasisyntax, cell_symbol_unsyntax,
cell_symbol_unsyntax_splicing, cell_symbol_set_x, cell_symbol_sc_expand,
cell_symbol_macro_expand, cell_symbol_portable_macro_expand,
cell_symbol_sc_expander_alist, cell_symbol_call_with_values,
cell_symbol_call_with_current_continuation, cell_symbol_boot_module,
cell_symbol_current_module, cell_symbol_primitive_load, cell_symbol_car,
cell_symbol_cdr, cell_symbol_not_a_number, cell_symbol_not_a_pair,
cell_symbol_system_error, cell_symbol_throw,
cell_symbol_unbound_variable, cell_symbol_wrong_number_of_args,
cell_symbol_wrong_type_arg, cell_symbol_buckets, cell_symbol_builtin,
cell_symbol_frame, cell_symbol_hashq_table, cell_symbol_module,
cell_symbol_procedure, cell_symbol_record_type, cell_symbol_size,
cell_symbol_stack, cell_symbol_argv, cell_symbol_mes_datadir,
cell_symbol_mes_version, cell_symbol_internal_time_units_per_second,
cell_symbol_compiler, cell_symbol_arch, cell_symbol_pmatch_car,
cell_symbol_pmatch_cdr, cell_type_bytes, cell_type_char,
cell_type_closure, cell_type_continuation, cell_type_function,
cell_type_keyword, cell_type_macro, cell_type_number, cell_type_pair,
cell_type_port, cell_type_ref, cell_type_special, cell_type_string,
cell_type_struct, cell_type_symbol, cell_type_values,
cell_type_variable, cell_type_vector, cell_type_broken_heart,
cell_symbol_program, cell_symbol_test): Likewise.
* src/globals.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
2021-05-02 14:58:23 +02:00
Jan (janneke) Nieuwenhuizen 5424923153
core: Move __getcwd_buf to Mes C Library.
* include/mes/mes.h (__getcwd_buf): Move to..
* lib/posix/getcwd.c (__getcwd_buf): ...here.
(getcwd): Refactor.
* src/posix.c (getcwd_): Do not use __getcwd_buf.
2021-01-01 15:43:43 +01:00
Jan (janneke) Nieuwenhuizen 083bcda827
core: Use size_t instead of long for gc sizes.
* include/mes/mes.h (ARENA_SIZE, MAX_ARENA_SIZE, STACK_SIZE, JAM_SIZE,
GC_SAFETY, MAX_STRING): Use size_t instead of long.
2021-01-01 09:47:22 +01:00
Jan (janneke) Nieuwenhuizen c3ae99de41
core: Add abort.
* lib/stub/__raise.c: New file.
* kaem.run: Use it.
* src/posix.c (__raise)[SYSTEM_LIBC]: New macro.
 (abort_): New function: possibly use it.
* include/mes/builtins.h: Declare it.
* src/builtins.c (mes_builtins): Register it.
2019-11-10 16:04:25 +01:00
Jan (janneke) Nieuwenhuizen ae9988bb3a
core: Add gc-stats.
* include/mes/mes.h (gc_start_time, gc_end_time, gc_time): New
variables.
* src/mes.c (init): Initialize them.
* src/gc.c: Use them.
* src/gc.c (gc_stats): New function.
* include/mes/builtins.h: Declare it.
* src/builtins.c (mes_builtins): Register it.
* tests/gc.test: Use it.
2020-12-31 10:34:07 +01:00
Jan (janneke) Nieuwenhuizen 23586c3304
Mes C Library: m2/ioctl.c: Remove specialization.
* lib/stub/ioctl.c (ioctl3): Move to...
* lib/stub/ioctl3.c: ...new file.
* lib/m2/ioctl3.c: Move to...
* lib/linux/ioctl3.c: ...here.
* include/mes/lib.h (ioctl3): Declare it.
* lib/m2/isatty.c (isatty): Use it.
* build-aux/configure-lib.sh (libc_SOURCES): Include it; move
lib/linux/ioctl.c to ...
(libc_gnu_SOURCES): ... here.
* kaem.run: Update accordingly.
* simple.make (M2_SOURCES): Likewise.
* simple.sh (compiler): Likewise.
2020-12-29 18:41:45 +01:00
Jan (janneke) Nieuwenhuizen f042c8d2a7
core: Use casting functions.
Silence all casting errors by using casting functions.

* src/cc.c (cast_charp_to_scmp, cast_charp_to_scmpp,
cast_voidp_to_charp, cast_scmp_to_long, cast_scmp_to_charp): New function.
* src/m2.c (cast_charp_to_scmp, cast_charp_to_scmpp,
cast_voidp_to_charp, cast_scmp_to_long, cast_scmp_to_charp): New function.
* include/mes/mes.h: Declare them.
(struct scm): Add car_value, cdr_value, function.
(g_continuations): Change to long.
* src/mes.c: Silence all casting errors by using casting functions.
2020-10-18 15:44:49 +02:00
Jan (janneke) Nieuwenhuizen 45e9ebad05
mescc: Mes C Library: Use casting functions.
Silence all casting errors by using casting functions.

* lib/mes/cast.c: New file.
* build-aux/configure-lib.sh (libmes_SOURCES): Add it.
* lib/m2/cast.c: New file.
* kaem.run: Add it.
* simple.make: Add them both.
* include/mes/lib.h: Add cast prototypes.
* include/m2/lib.h: Likewise.
* lib/linux/_getcwd.c (_getcwd): Use them.
* lib/linux/access.c (access): Likewise.
* lib/linux/brk.c (brk): Likewise.
* lib/linux/chmod.c (chmod): Likewise.
* lib/linux/clock_gettime.c (clock_gettime): Likewise.
* lib/linux/gettimeofday.c (gettimeofday): Likewise.
* lib/linux/unlink.c (unlink): Likewise.
* lib/mes/fdputc.c (fdputc): Likewise.
* lib/stdio/putchar.c (putchar): Likewise.
* lib/linux/malloc.c (malloc): Likewise.
2020-10-18 14:55:24 +02:00
Jan (janneke) Nieuwenhuizen 7bacad5a54
core: Switch to pointer cells.
Run

   build-aux/pointer.sh

* include/mes/macros.h: Remove.
* src/*.c: Update.
* include/mes/*.h: Update.
* simple.make: Update.
* kaem.run: Update.
2020-10-18 11:34:32 +02:00
Jan (janneke) Nieuwenhuizen fb83a7610d
core: Drop support for number based cells.
This removes the POINTER_CELLS define and all its references.

* simple.make (CFLAGS): Remove -D POINTER_CELLS.
* include/mes/mes.h: Remove #define POINTER_CELLS.
* include/mes/cc.h: Remove !POINTER_CELLS branches.
* include/mes/macros.h: Likewise.
* src/gc.c: Likewise.
* src/symbol.c: Likewise.
* src/test/gc.c: Likewise.
2020-09-20 11:32:38 +02:00
Jan (janneke) Nieuwenhuizen 46e9be9399
core: gc: Add gc_dump_arena.
* src/gc.c (dumpc, dumps, gc_dump_register, gc_dump_state,
gc_dump_stack, gc_dump_arena): New function.
2020-09-14 14:53:56 +02:00
Jan (janneke) Nieuwenhuizen b182aa0705
core: eval-apply: Prepare for M2-Planet.
* src/eval-apply.c (apply_builtin): Split M2-Planet specific and CC
specifi part off to ..
* src/cc.c: New file, and
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* src/m2.c: New file.
* simple.make (MES_SOURCES, M2_SOURCES): Likewise.
2020-08-18 23:01:53 +02:00
Jan (janneke) Nieuwenhuizen 553a52cc98
core: display: Prepare for pointer cells, M2-Planet.
Rewrite C-constructs not supported by M2-Planet

    if (foo)               -> if (foo != 0)
    if (!foo)              -> if (foo == 0)
    ;                      -> 0;
    // ...                 -> /* ... */

* src/display.c (display_helper): Use cell_ref.
2020-08-18 16:16:13 +02:00
Jan (janneke) Nieuwenhuizen 9aa4649419
core: gc: Prepare for pointer cells, M2-Planet.
* include/mes/mes.h (cell_zero): Declare.
* src/gc.c (gc_init): Initialize it.
(gc_init_news): Likewise.
2020-08-16 14:45:18 +02:00
Jan (janneke) Nieuwenhuizen bd3259a22f
core: Remove cell_call_with_current_continuation special.
* include/mes/symbols.h (cell_call_with_current_continuation): Remove.
* src/eval-apply.c (eval_apply): Update to use
cell_symbol_call_with_current_continuation.
* src/symbol.c (init_symbols_): Remove inititialization.
2020-08-18 11:06:15 +02:00
Jan (janneke) Nieuwenhuizen 36618377c8
core: Remove cell_begin special.
* include/mes/symbols.h (cell_begin): Remove.
* src/eval-apply.c (eval_apply): Update to use cell_symbol_begin.
* src/symbol.c (init_symbols_): Remove initialization.
2020-08-18 10:40:55 +02:00
Jan (janneke) Nieuwenhuizen 29ffe591ea
core: Remove unused symbols.
* include/mes/symbols.h (cell_symbol_dot, cell_symbol_read_input_file,
cell_symbol_write, cell_symbol_display): Remove
* src/symbol.c (init_symbols_): Remove initializations.
2020-08-18 10:33:56 +02:00
Jan (janneke) Nieuwenhuizen 5f5e50294d
core: builtins: MES_MINI.
* include/mes/mes.h (g_mini): New global.
* src/mes.c (init): Initialize it with environment variable MES_MINI.
* src/builtins.c (mes_builtins): Register a minimal set of builtins
when g_mini.
2020-08-18 09:36:19 +02:00
Jan (janneke) Nieuwenhuizen 8cb374724b
boot: Add gc test.
* scaffold/boot/gc.test: New file.
* build-aux/check-boot.sh (TESTS): Add it.
* include/mes/symbols.h (cell_symbol_program): New symbol.
* src/symbol.c (init_symbols_): Initialize it.
* src/mes.c (main): Add it to environment.
2020-08-16 17:36:55 +02:00
Jan (janneke) Nieuwenhuizen e6b4216a98
core: make-vector: Move to core.
* src/vector.c (make_vector_): Rename from make_vector__.  Add
parameter.  Fix double allocation.
(make_vector): Rename from make_vector_.  Use arity n.  Update users.
2020-08-16 16:54:18 +02:00
Jan (janneke) Nieuwenhuizen 8b4b679f56
mescc: Mes C Library: Add M2-Planet support.
Mes can now be built with M2-Planet by running

    kaem --verbose --strict

* include/linux/x86/syscall.h (SYS_getcwd, SYS_dup, SYS_dup2,
SYS_unlilnk, SYS_gettimeofday, SYS_clock_gettime, SYS_time): Move to
libc section.  Add M2-Planet constants.
* include/m2/lib.h (struct timezone, struct timespec): struct timeval):
Define.  Add M2-Planet flavor prototypes for mes libc.
* include/mes/m2.h: Remove macros.
* include/mes/mes.h (g_start_time, __gettimeofday_time,
__get_internal_run_time_ts): Declare.
* src/mes.c (init): Initialize them.
* src/posix.c: Use them.
* simple.make: Use them.  Remove macro preprocessing for M2-Planet.
* kaem.run: New file.
2020-07-25 20:00:44 +02:00
Jan (janneke) Nieuwenhuizen dab06b39a4
core: Split-out stack.c
* src/lib.c (exit_, frame_printer, make_frame_type, make_frame,
make_stack_type, make_stack, stack_length, stack_ref_): Move to ..
* src/posix.c (exit_): Here and to ..
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (LIBMES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 08:53:46 +02:00
Jan (janneke) Nieuwenhuizen 856ac39dab
core: Split-out core.c.
* src/mes.c (assoc_string, car, cdr, list, null_p, eq_p, values, acons,
length__, length, error, append2, append_reverse, reverse_x_, assq,
assoc): Move to ...
* src/core.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* simple.make (MES_SOURCES): Likewise.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
2020-07-19 08:49:23 +02:00
Jan (janneke) Nieuwenhuizen bbddd47e71
kaem: scaffold/read.kaem.
* .gitignore: Update.
* include/linux/x86/syscall.h: Update for M2-Planet.
* scaffold/read.c: Update for M2-Planet.
* lib/m2/malloc.c: New file.
* lib/string/memset.c (memset): Update for M2-Planet.
* lib/linux/brk.c (brk): Remove cast for M2-Planet.
2020-07-15 22:27:57 +02:00
Jan (janneke) Nieuwenhuizen dfe9f0a258
kaem: scaffold/hello.kaem.
* include/m2/lib.h: New file.
* scaffold/hello.kaem: New file.
2020-07-15 21:12:12 +02:00
Jan (janneke) Nieuwenhuizen a5ce8551c4
core: Prepare for M2-Planet: VALUE/TYPE indirections.
Rewrite C-constructs not supported by M2-Planet

    VALUE (CAR (foo))           -> SCM a = CAR (foo); VALUE (a)
    TYPE (CAR (foo))            -> SCM t = CAR (foo); TYPE (a)

* src/builtins.c (builtin_function): Use VALUE indirections.
(builtin_printer): Likewise.
* src/eval-apply.c (apply_builtin): Likewise.
(get_macro): Likewise.
(expand_variable_): Likewise.
(eval_apply): Likewise.
* src/hash.c (hashq_get_handle): Likewise.
(hashq_ref): Likewise.
(hash_ref): Likewise.
(hash_set_x): Likewise.
(hash_table_printer): Likewise.
* src/math.c (greater_p): Likewise.
(less_p): Likewise.
(is_p): Likewise.
(minus): Likewise.
(plus): Likewise.
(divide): Likewise.
(multiply): Likewise.
(logand): Likewise.
(logior): Likewise.
(logxor): Likewise.
* src/posix.c (current_input_port): Likewise.
(set_current_output_port): Likewise.
* src/reader.c (reader_read_list): Likewise.
(reader_read_character): Likewise.
(reader_read_string): Likewise.
* src/string.c (list_to_cstring): Likewise.
(read_string): Likewise.
2020-07-17 14:30:01 +02:00
Jan (janneke) Nieuwenhuizen 4e8a95e385
core: Prepare for pointer cells.
* include/mes/cc.h: Prepare for pointer-based cells.
* include/mes/macros.h[POINTER_CELLS]: Alternative set of macros.
* include/mes/mes.h (struct scm)[POINTER_CELLS]: Alternative definition.
* src/gc.c (copy_cell, copy_news): New function.
* include/mes/mes.h: Declare them.
2020-07-14 15:57:49 +02:00
Jan (janneke) Nieuwenhuizen 97862022d3
core: gc: FRAME_SIZE.
* src/gc.c (gc_loop, gc_): Use FRAME_SIZE.
2020-06-22 19:26:55 +02:00
Jan (janneke) Nieuwenhuizen 2dfc5f80bd
core: gc: Fixes.
* src/gc.c (gc_init, gc_up_arena, gc_flip): Change to void function.
Fixes 0 returns.
(make_bytes): Use plain.
(make_string): Add 1 to length, for zero-terminated C strings.
(gc_copy): Use plain bytes length.
(gc_loop): Manually reformat.
2020-06-22 18:00:15 +02:00
Jan (janneke) Nieuwenhuizen 5e25dc6311
core: Create symbols dynamically.
* include/mes/symbols.h: New file.
* include/mes/mes.hh: Include it.
* include/mes/constants.h: Remove symbol constants.
* src/symbols.c (init_symbols): Create symbols dynamically.
* build-aux/mes-snarf.scm (snarf-symbols): Update.
2020-06-16 15:59:26 +02:00
Jan (janneke) Nieuwenhuizen 8bd5337c2c
core: Remove CBYTES, CSTRING, NCBYTES macros.
* src/gc.c (cell_bytes, news_bytes): New function.
* include/mes/macros.h (CBYTES, CSTRING, NCBYTES): Remove.  Update
users.
* include/mes/m2.h: Likewise.
2020-05-19 08:55:41 +02:00
Jan (janneke) Nieuwenhuizen 6b6b212bfb
core: Remove dead macros.
* include/mes/macros.h (CSTRING_STRUCT, START, LEN): Remove.
2020-05-19 08:49:55 +02:00
Jan (janneke) Nieuwenhuizen 8b7f52b256
core: Remove macros from cell creation: make_char .. make_string.
* src/gc.c (make_char, make_continuation, make_macro, make_number,
make_ref, make_string0, make_string_port): New function.
(make_string): Move from string.c.
* include/mes/macros.h (MAKE_CHAR, MAKE_CONTINUATION, MAKE_MACRO,
MAKE_NUMBER, MAKE_REF, MAKE_STRING0, MAKE_STRING_PORT): Remove macro.
Update users.
* include/mes/m2.h: Likewise.
2020-05-18 22:35:12 +02:00