Commit Graph

311 Commits

Author SHA1 Message Date
Jan (janneke) Nieuwenhuizen 981c0524b7
DRAFT core: Switch to Guile modules.
TODO XXX:
  * tests/psyntax.test fails
  * mescc

* src/mes.c (open_boot): Default to boot-5.mes.
(try_open_boot): Update messages.
2020-12-31 14:39:41 +01:00
Jan (janneke) Nieuwenhuizen 5380b5a4a2
core: Make primitive-load return properly.
* include/mes/symbols.h (cell_vm_primitive_load_return): New variable.
(SYMBOL_MAX): Update.
* src/eval-apply.c (eval_apply): Have primitive-load return properly.
2020-12-31 14:39:40 +01:00
Jan (janneke) Nieuwenhuizen ff2a5be2d5
DRAFT boot-6: Support Guile modules.
XXX TODO:
 * cleanup boot-6.mes
 * resurrect m2-planet build: kaem --verbose --strict

* src/hash.c (hashq_get_handle_): Remove default "dflt" parameter.
(hashq_ref_): Update user.
* src/module.c (module_handle, module_variable, current_module,
module_defines): New functions.
* src/variable.c (lookup_variable): Rename to ...
(lookup_handle): ...this.  Implement module lookup.
(lookup_variable_): Rename to ...
(lookup_ref_); ...this.
(handle_set_x): New function.
* include/mes/builtins.h: Update prototypes.
* src/core.c (error): Update callers.
* src/eval-apply.c (set_x, macro_get_handle, expand_variable_,
eval_apply): Likewise.
* mes/module/mes/boot-00.scm (defined?): Likewise.
* mes/module/mes/boot-01.scm (defined?): Likewise.
* mes/module/mes/boot-02.scm (defined?): Likewise.
* mes/module/mes/boot-03.scm (defined?): Likewise.
* scaffold/boot/53-closure-display.scm: Likewise.
* scaffold/boot/60-let-syntax-expanded.scm: Likewise.
* mes/module/mes/boot-5.mes,
mes/module/mes/boot-6.mes: New files.
2020-12-31 14:39:05 +01:00
Jan (janneke) Nieuwenhuizen 238b0fd460
core: Refactor lookup_variable.
* src/variable.c (lookup_variable, lookup_variable_, lookup_ref): Drop
lookup/env parameter.  Update users.
* mes/module/mes/boot-0.scm (defined?): Update users.
* mes/module/mes/boot-00.scm (defined?): Likewise.
* mes/module/mes/boot-01.scm (defined?): Likewise.
* mes/module/mes/boot-02.scm (defined?): Likewise.
* mes/module/mes/boot-03.scm (defined?): Likewise.
* scaffold/boot/53-closure-display.scm (guile): Likewise.
* scaffold/boot/60-let-syntax-expanded.scm (defined?): Likewise.
* src/builtins.c (mes_builtins): Update registration.
* include/mes/builtins.h: Update declarations.
* include/mes/mes.h: Likewise.
* mes/module/mes/display.mes (display): Update variable display.
2020-12-31 14:18:18 +01:00
Jan (janneke) Nieuwenhuizen ec6f32f80c
core: Remove set-env! as builtin.
* src/eval-apply.c (set_x): Rename from set_env_x.  Drop environment
parameter.
* include/mes/mes.h: Declare it.
* include/mes/builtins.h (set_env_x): Remove declaration.
* src/builtins.c (mes_builtins): Remove registration.
2020-12-31 14:18:18 +01:00
Jan (janneke) Nieuwenhuizen 21cf128175
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.
2020-12-31 14:18:18 +01:00
Jan (janneke) Nieuwenhuizen 79cce24028
core: Remove make_module_type, module_printer, module_variable, module_ref.
* src/module.c (make_module_type, module_printer, module_variable,
module_ref): Remove.
* include/mes/builtins.h: Remove declarations.
* src/builtins.c (mes_builtins): Remove registrations.
* src/eval-apply.c (assert_defined): Remove.
(set_env_x, eval_apply): Use lookup_variable and variable_ref.
* src/core.c (error): Likewise.
* mes/module/mes/boot-01.scm (defined?): Likewise.
* mes/module/mes/boot-02.scm (defined?): Likewise.
* mes/module/mes/boot-03.scm (defined?): Likewise.
* mes/module/mes/boot-0.scm (defined?): Likewise.
* scaffold/boot/53-closure-display.scm (guile): Likewise.
* scaffold/boot/60-let-syntax-expanded.scm (defined?): Likewise.
* src/mes.c (main): Use hash_table_printer for debugging.
2020-12-31 14:18:17 +01:00
Jan (janneke) Nieuwenhuizen 96c83134db
core: Add lookup_variable_, lookup_variable, lookup_ref.
* src/variable.c (lookup_variable, lookup_ref): New builtins, and
(lookup_variable_): New function.
* include/mes/builtins.h: Declare them.
* include/mes/mes.h: Declare it.
* src/builtins.c (mes_builtins): Register them.
2020-12-31 14:18:17 +01:00
Jan (janneke) Nieuwenhuizen ed0dbfa4b0
core: Add hashq_set_handle_x.
* src/hash.c (hash_set_x_): Return handle instead of value.  Update
callers and and use it in ...
(hashq_set_handle_x): New function.
* include/mes/builtins.h: Declare it.
2020-12-31 14:18:17 +01:00
Jan (janneke) Nieuwenhuizen b6c2ce37f7
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.
2020-12-31 14:18:17 +01:00
Jan (janneke) Nieuwenhuizen 319208a916
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.
2020-12-31 14:18:17 +01:00
Jan (janneke) Nieuwenhuizen 9db8e3e472
core: Allow non-string hash keys.
This merely allows adding non-string keys to a hash table and puts them
non-string keys in bucket 0.  Efficiency is lost.  TODO: calculate a
proper hash.

* src/hash.c (hash_): Allow non-string keys in bucket 0.
2020-12-31 14:18:16 +01:00
Jan (janneke) Nieuwenhuizen be98cabb58
core: Add hash-map->list.
* src/hash.c (hash_map_to_list): New function.
* src/builtins.c (mes_builtins): Update.
* include/mes/builtins.h: Update.
2020-12-31 14:18:16 +01:00
Jan (janneke) Nieuwenhuizen 430d2f98ee
core: variable: Guile interface compliance.
* src/lib.c (assert_variable):
* src/gc.c (make_variable): Move from
* src/eval-apply.c (make_variable): here; Remove.
* include/mes/builtins.h: Update.
* src/builtins.c (mes_builtins): Update.
* mes/module/mes/scm.mes (make-undefined-variable): New function.
* src/variable.c: New file.
* build-aux/configure-lib.sh (mes_SOURCES): Add it.
* kaem.run: Likewise.
* simple.make (LIBMES_SOURCES): Likewise.
* build-aux/snarf.sh (srcdest): Likewise.
2020-12-31 14:18:16 +01:00
Jan (janneke) Nieuwenhuizen 6016deef3c
DRAFT core: Use exceptions instead of asserts.
XXX prototypes

* src/lib.c (assert_num, assert_struct, (assert_range): New functions.
* src/struct.c (struct_ref_): Use them.
* src/hash.c (make_hash_table): Use assert_number.
2020-12-31 14:18:16 +01:00
Jan (janneke) Nieuwenhuizen 9d6ab2de67
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.
2020-12-31 14:18:15 +01:00
Jan (janneke) Nieuwenhuizen 4200e3f472
mes: hash: Guile interface compatibility.
* mes/module/mes/scm.mes (hashq-get-handle, hashq-ref, hash-ref): New
function.
* src/hash.c (hashq_get_handle_): Rename from hashq_get_handle.
Update users.
(hashq_ref_): Likewise.
(hash_ref_): Likewise.
2020-12-31 14:18:15 +01:00
Jan (janneke) Nieuwenhuizen 0ecac6522b
core: make-hash-table: Fix optional argument.
* src/hash.c (make_hash_table): Fix optional argument.
* src/builtins.c (mes_builtins): Update arity.
2020-12-31 14:18:15 +01:00
Jan (janneke) Nieuwenhuizen f2a99e4855
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 14:00:45 +01:00
Jan (janneke) Nieuwenhuizen a7827ca598
core: Avoid Floating point exception dividing negative numbers.
This fixes

    kaem --verbose --strict
    bin/mes-m2 -c '(display (/ -1 1))'

* src/math.c (divide): Use signed division.
2020-12-31 14:00:45 +01:00
Jan (janneke) Nieuwenhuizen a44d81e560
core: Prepare for M2-Planet 1.7.0.
* src/eval-apply.c (expand_variable_, apply_builtin): Declare variables
at toplevel.
* src/gc.c (gc_cellcpy, gc_loop, gc_dump_arena): Likewise.
* src/hash.c (hash_table_printer): Likewise.
* src/lib.c (equal2_p): Likewise.
* src/math.c (greater_p, less_p, is_p, minus, plus, divide, multiply,
logand, logior, logxor): Likewise.
* src/posix.c (current_input_port, execl_): Likewise.
* src/reader.c (reader_read_string): Likewise.
* src/stack.c (make_stack): Likewise.
* src/string.c (list_to_cstring, bytes_to_list, string_append):
Likewise.
* src/struct.c (make_struct): Likewise.
* src/vector.c (vector_to_list): Likewise.
2020-12-31 14:00:43 +01:00
Jan (janneke) Nieuwenhuizen bcb2cc9dc6
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-12-31 14:00:42 +01:00
Jan (janneke) Nieuwenhuizen fd20ea1e0a
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-12-31 14:00:42 +01:00
Jan (janneke) Nieuwenhuizen 48fcb82d1a
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-12-31 14:00:41 +01:00
Jan (janneke) Nieuwenhuizen 15dedde333
core: gc: Pointer cells: Drop cells->news->cells flipping.
* src/gc.c (gc_init): Undo doubling of initial memory.
(gc_init_news)[!GC_NOFLIP]: Remove.
(gc_)[!GC_NOFLIP]: Remove symbol relocation.
(gc)[!GC_NOFLIP]: Remove second gc.
2020-12-31 14:00:41 +01:00
Jan (janneke) Nieuwenhuizen 85a7f71474
core: gc: Abort upon broken heart failure.
* src/gc.c (gc_cellcpy, gc_loop): Abort upon broken heart failure.
2020-12-31 14:00:41 +01:00
Jan (janneke) Nieuwenhuizen b040d07828
core: gc: Enable memory dump debugging.
* src/gc.c (gc): If MES_DUMP is set, dump arena.  [POINTER_CELLS &&
!GC_NOFLIP]: Run gc_ twice to enable comparing memory dumps.
2020-12-31 14:00:41 +01:00
Jan (janneke) Nieuwenhuizen 7f8ca5d69e
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-12-31 14:00:41 +01:00
Jan (janneke) Nieuwenhuizen 4c86ceddca
core: Pointer cells: Allow smaller memory footprint using cellcpy.
* src/gc.c (gc_init)[GC_NOFLIP]: Do not use double sized arena.
(gc_cellcpy): New function.
* src/gc.c (gc_flip): Use it, do not flip.
(gc_init_news)[GC_NOFLIP]: Update.
2020-12-31 14:00:41 +01:00
Jan (janneke) Nieuwenhuizen 12ef538fa1
test/gc: Add three extra gc's.
* src/test/gc.c (test_gc): Add three extra gc's.
2020-12-31 14:00:41 +01:00
Jan (janneke) Nieuwenhuizen e8c1d48817
test/gc: struct.
* src/test/gc.c (test_struct): New function.
(main): Call it.
2020-12-31 14:00:40 +01:00
Jan (janneke) Nieuwenhuizen 75307bcd96
test/gc: vector.
* src/test/gc.c (test_vector): New function.
(main): Call it.
(print_arena): New function.
(test_gc): Call it.
2020-12-31 14:00:40 +01:00
Jan (janneke) Nieuwenhuizen 37c0b456e1
test/gc: string.
* src/test/gc.c (test_string): New function.
(main): Call it.
2020-12-31 14:00:40 +01:00
Jan (janneke) Nieuwenhuizen 8d5dfdfbbd
test/gc: list.
* src/test/gc.c (test_list): New function.
(main): Call it.
2020-12-31 14:00:40 +01:00
Jan (janneke) Nieuwenhuizen c6606a2052
test/gc: cons. 2020-12-31 14:00:40 +01:00
Jan (janneke) Nieuwenhuizen de089ce24a
test/gc: number.
* src/test/gc.c (test_number): New function.
(main): Call it.
2020-12-31 14:00:40 +01:00
Jan (janneke) Nieuwenhuizen 458171ca61
test/gc: empty.
* src/test/gc.c (test_empty): New function.
2020-12-31 14:00:40 +01:00
Jan (janneke) Nieuwenhuizen e4977b7f37
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-12-31 14:00:39 +01:00
Jan (janneke) Nieuwenhuizen 6bb228a061
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-12-31 14:00:39 +01:00
Jan (janneke) Nieuwenhuizen 2d6b7d0580
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-12-31 14:00:39 +01:00
Jan (janneke) Nieuwenhuizen 906a4cf2a8
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-12-31 14:00:39 +01:00
Jan (janneke) Nieuwenhuizen bd97647ce8
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-12-31 14:00:39 +01:00
Jan (janneke) Nieuwenhuizen bef7e30b8d
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-12-31 14:00:39 +01:00
Jan (janneke) Nieuwenhuizen f5906b4628
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-12-31 14:00:39 +01:00
Jan (janneke) Nieuwenhuizen f69753d169
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-12-31 14:00:38 +01:00
Jan (janneke) Nieuwenhuizen 79b8e8f56b
test/gc: Add gc inspection test.
* src/test/gc.c (main): New unit test.
* simple.make (test-gcc, test-m2): New target to build it.
* build-aux/pointer.sh: Add it.
2020-12-31 14:00:38 +01:00
Jan (janneke) Nieuwenhuizen 168dd67e67
core: make_struct: Avoid creating garbage.
* src/struct.c (make_struct): Use STRUCT TYPE PRINTER FIELD0 ... FIELDN.
2020-12-31 14:00:38 +01:00
Jan (janneke) Nieuwenhuizen a50927442f
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-12-31 14:00:38 +01:00
Jan (janneke) Nieuwenhuizen 43152991f4
core: posix: Prepare for M2-Planet.
* src/posix.c (access_p): Prepare for M2-Planet.
2020-12-31 14:00:38 +01:00
Jan (janneke) Nieuwenhuizen 115a6ec7a2
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-12-31 14:00:36 +01:00