Commit Graph

297 Commits

Author SHA1 Message Date
Jan (janneke) Nieuwenhuizen c9ad4b1962
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 16:21:05 +01:00
Jan (janneke) Nieuwenhuizen f2279e0a2c
core: Use unsigned constants.
* src/gc.c (FRAME_SIZE, M2_CELL_SIZE): Declare unsigned.
(gc_init): Use unsigned suffixes for divisions.
* src/posix.c (TIME_UNITS_PER_SECOND): Declare unsigned.
(UL1000000000): New constant.
(seconds_and_nanoseconds_to_long): Use it.
* src/gc.c (U10, U100): New constants.
(gc_init): Use them.
2021-01-01 16:21:04 +01:00
Jan (janneke) Nieuwenhuizen a63c508402
core: Avoid Floating point exception dividing negative numbers.
* src/posix.c (seconds_and_nanoseconds_to_long): Use unsigned division.
2021-01-01 16:19:45 +01:00
Jan (janneke) Nieuwenhuizen 87e73e5b01
core: Avoid Floating point exception dividing negative numbers.
This fixes

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

* src/math.c (modulo): Use unsigned division.
2021-01-01 16:19:45 +01:00
Jan (janneke) Nieuwenhuizen d237c18ac2
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.
2021-01-01 16:19:44 +01:00
Jan (janneke) Nieuwenhuizen ecb1551b9e
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.
2021-01-01 16:19:44 +01:00
Jan (janneke) Nieuwenhuizen cf5e1022ce
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.
2021-01-01 16:19:43 +01:00
Jan (janneke) Nieuwenhuizen 075baa0b67
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.
2021-01-01 16:19:13 +01:00
Jan (janneke) Nieuwenhuizen 2ad729ccfb
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.
2021-01-01 16:19:13 +01:00
Jan (janneke) Nieuwenhuizen 0a5c953eda
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.
2021-01-01 16:19:12 +01:00
Jan (janneke) Nieuwenhuizen 53cc732026
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.
2021-01-01 16:19:12 +01:00
Jan (janneke) Nieuwenhuizen d6d062332d
core: gc: Abort upon broken heart failure.
* src/gc.c (gc_cellcpy, gc_loop): Abort upon broken heart failure.
2021-01-01 16:19:12 +01:00
Jan (janneke) Nieuwenhuizen 91acf14cec
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.
2021-01-01 16:19:12 +01:00
Jan (janneke) Nieuwenhuizen 63db903dd2
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.
2021-01-01 16:19:12 +01:00
Jan (janneke) Nieuwenhuizen 294011d6f5
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.
2021-01-01 16:19:12 +01:00
Jan (janneke) Nieuwenhuizen 1f8cf375bd
test/gc: Add three extra gc's.
* src/test/gc.c (test_gc): Add three extra gc's.
2021-01-01 16:19:11 +01:00
Jan (janneke) Nieuwenhuizen 550753372c
test/gc: struct.
* src/test/gc.c (test_struct): New function.
(main): Call it.
2021-01-01 16:19:11 +01:00
Jan (janneke) Nieuwenhuizen 8a83f9fbfe
test/gc: vector.
* src/test/gc.c (test_vector): New function.
(main): Call it.
(print_arena): New function.
(test_gc): Call it.
2021-01-01 16:19:11 +01:00
Jan (janneke) Nieuwenhuizen 4a5d8fde29
test/gc: string.
* src/test/gc.c (test_string): New function.
(main): Call it.
2021-01-01 16:19:11 +01:00
Jan (janneke) Nieuwenhuizen c1f457bbf9
test/gc: list.
* src/test/gc.c (test_list): New function.
(main): Call it.
2021-01-01 16:19:11 +01:00
Jan (janneke) Nieuwenhuizen d5f082bfc6
test/gc: cons. 2021-01-01 16:19:11 +01:00
Jan (janneke) Nieuwenhuizen 3826af002d
test/gc: number.
* src/test/gc.c (test_number): New function.
(main): Call it.
2021-01-01 16:19:11 +01:00
Jan (janneke) Nieuwenhuizen f060a9fe09
test/gc: empty.
* src/test/gc.c (test_empty): New function.
2021-01-01 16:19:10 +01:00
Jan (janneke) Nieuwenhuizen bd3571c82d
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.
2021-01-01 16:19:10 +01:00
Jan (janneke) Nieuwenhuizen f33f0b3d26
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.
2021-01-01 16:19:10 +01:00
Jan (janneke) Nieuwenhuizen e26f2eaa13
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.
2021-01-01 16:19:10 +01:00
Jan (janneke) Nieuwenhuizen df871e695e
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.
2021-01-01 16:19:10 +01:00
Jan (janneke) Nieuwenhuizen 7c27a8db6a
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.
2021-01-01 16:19:10 +01:00
Jan (janneke) Nieuwenhuizen a2905d1a45
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.
2021-01-01 16:19:09 +01:00
Jan (janneke) Nieuwenhuizen 6e158f67ae
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.
2021-01-01 16:19:09 +01:00
Jan (janneke) Nieuwenhuizen 27988ce8a5
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.
2021-01-01 16:19:09 +01:00
Jan (janneke) Nieuwenhuizen d6ff15fb47
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.
2021-01-01 16:19:09 +01:00
Jan (janneke) Nieuwenhuizen 3d5a6e29fd
core: make_struct: Avoid creating garbage.
* src/struct.c (make_struct): Use STRUCT TYPE PRINTER FIELD0 ... FIELDN.
2021-01-01 16:19:09 +01:00
Jan (janneke) Nieuwenhuizen c1cf344957
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.
2021-01-01 16:19:09 +01:00
Jan (janneke) Nieuwenhuizen d23961af1b
core: posix: Prepare for M2-Planet.
* src/posix.c (access_p): Prepare for M2-Planet.
2021-01-01 16:17:21 +01:00
Jan (janneke) Nieuwenhuizen 72fd04018c
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.
2021-01-01 16:17:19 +01:00
Jan (janneke) Nieuwenhuizen de76be1298
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.
2021-01-01 16:17:17 +01:00
Jan (janneke) Nieuwenhuizen d5cc85e4cb
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.
2021-01-01 16:17:17 +01:00
Jan (janneke) Nieuwenhuizen c0c854df8d
core: Prepare for M2-Planet: if (foo).
Rewrite C-constructs not supported by M2-Planet

    if (foo)              -> if (foo != 0)

* src/posix.c: Rewrite C-constructs not supported by M2-Planet.
(current_input_port): Likewise.
* src/display.c (display_helper): : Likewise.
* src/eval-apply.c (expand_variable_): : Likewise.
(eval_apply): : Likewise.
* src/mes.c (open_boot): : Likewise.
* src/reader.c (reader_read_identifier_or_number): : Likewise.
* src/symbols.c (init_symbol): : Likewise.
2021-01-01 16:03:45 +01:00
Jan (janneke) Nieuwenhuizen cd8b7acb22
core: Outline hashq_get_handle, hash_set_x_.
* src/hash.c (hashq_ref): Use hashq_get_handle.
(hashq_set_x_): Enable.
(hash_set_x): Use it.
2021-01-01 16:03:45 +01:00
Jan (janneke) Nieuwenhuizen 481e0b2b16
core: Prepare for M2-Planet: continue.
Rewrite C-constructs not supported by M2-Planet

    continue              -> goto LABEL

* src/eval-apply.c (eval_apply): Add label: begin_expand_while.  Use it
instead of continue.
2021-01-01 16:03:45 +01:00
Jan (janneke) Nieuwenhuizen aee6bd8b2a
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.
2021-01-01 16:03:45 +01:00
Jan (janneke) Nieuwenhuizen b8b5459f8b
core: Prepare for M2-Planet: M2_CELL_SIZE.
* src/gc.c (M2_CELL_SIZE): Hack for missing pointer arithmetic in
M2-Planet.
(gc_init, alloc, make_cell, gc_up_arena, gc_copy, gc_loop, gc_): Use it.
2021-01-01 16:03:45 +01:00
Jan (janneke) Nieuwenhuizen 54386054d4
core: Use unique assert_msg.
* src/mes.c (error): Use unique assert_msg.
2021-01-01 16:03:45 +01:00
Jan (janneke) Nieuwenhuizen 6f09fb9c1e
core: read_string: Prepare for M2-Planet.
* src/string.c (read_string): Prepare for M2-Planet.
2021-01-01 16:03:44 +01:00
Jan (janneke) Nieuwenhuizen c3e1eaf69a
core: string_equal_p: Prepare for M2-Planet.
* src/string.c (string_equal_p): Prepare for M2-Planet.
2021-01-01 16:03:44 +01:00
Jan (janneke) Nieuwenhuizen 690b73c57a
core: reader_read_block_comment: Prepare for M2-Planet.
* src/reader.c (reader_read_block_comment): Prepare for M2-Planet.
2021-01-01 16:03:44 +01:00
Jan (janneke) Nieuwenhuizen 3f78f0cecc
core: reader_eat_whitespace: Prepare for M2-Planet.
* src/reader.c (reader_eat_whitespace): Prepare for M2-Planet.
2021-01-01 16:03:44 +01:00
Jan (janneke) Nieuwenhuizen 9942592c80
core: reader_read_sexp_: Prepare for M2-Planet.
* src/reader.c (reader_read_sexp_): Prepare for M2-Planet.
2021-01-01 16:03:44 +01:00
Jan (janneke) Nieuwenhuizen ef4da6a6f8
core: reader_read_identifier_or_number: Prepare for M2-Planet.
* src/reader.c (reader_read_identifier_or_number): Prepare for M2-Planet.
2021-01-01 16:03:44 +01:00