Commit Graph

64 Commits

Author SHA1 Message Date
Andrius Štikonas ad18345687 core: Fix a typo in comment.
* src/gc.c (gc_init): Fix typo.
2023-05-03 08:04:32 +02:00
Jan (janneke) Nieuwenhuizen cbea14f843 core: Move M2_PTR_SIZE, M2_CELL_SIZE to include file.
* lib/posix/getenv.c (M2_PTR_SIZE),
lib/posix/setenv.c (M2_PTR_SIZE): Move definition...
* include/mes/lib-mini.h (M2_PTR_SIZE): ...here.
* src/gc.c (M2_CELL_SIZE),
src/symbol.c (M2_CELL_SIZE),
src/test/gc.c (M2_CELL_SIZE),
src/vector.c (M2_CELL_SIZE): Move definition...
* include/mes/mes.h (M2_CELL_SIZE): ...here.
2023-05-03 08:04:32 +02:00
Jan (janneke) Nieuwenhuizen dad460189f kaem.run: Remove --bootstrap-mode.
* include/linux/arm/syscall.h,
include/linux/x86/syscall.h,
include/mes/constants.h: Remove CONSTANTs.
* lib/m2/open.c: Move to...
* lib/linux/open.c: ...here.  Update to make gcc-compatible.
* scaffold/argv.kaem: Update accordingly.
* lib/linux/lseek.c (_leek, lseek): Suport M2-Planet.
* lib/linux/_open3.c (_open3): Fix cast.
* lib/linux/waitpid.c (waitpid): Suport M2-Planet.
* lib/m2/getcwd.c (PATH_MAX): Remove CONSTANT.
* lib/m2/isatty.c (TCGETS): Remove CONSTANT.
* lib/mes/ntoab.c: Support M2-Planet.
* lib/posix/getcwd.c (__getcwd_buf): Remove.
* lib/posix/getenv.c (M2_PTR_SIZE)[__M2__]: Update to #define.
* lib/posix/setenv.c: Likewise.
* lib/stub/__raise.c (SIGABRT): Remove CONSTANT.
* src/core.c (error): Use __M2__ instead of __M2_PLANET__.
* src/gc.c (M2_CELL_SIZE)[__M2__]: Update to #define.  Support
non-bootstrap-mode.
* src/symbol.c: Likewise.
* src/vector.c: Likewise.
* src/posix.c: Likewise.
(__raise): Move to...
* include/mes/lib-cc.h (__raise): ...this new file to avoid M2-Planet crash.
* include/sys/types.h: Include it.
* lib/mes/div.c (__raise): Remove prototype.
[__TINYC__ || SYSTEM_LIBC] (__raise): Remove macro.
* include/mes/lib.h (__raise)[SYSTEM_LIBC]: Remove prototype.
* kaem.run: Remove --botstrap-mode.  Update source list accordingly.
* simple.make (M2_PLANET_FLAGS): Remove --bootstrap-mode.
* simple.make (M2_SOURCES, M2_PLANET_INCLUDES): Update source list
accordingly.
* include/sys/types.h (EOF): Move to...
* include/mes/lib-cccc.h (EOF): ...here, and...
* include/m2/types.h (EOF): ...here, to avoid M2-Planet crash.
2023-05-03 08:03:48 +02:00
Gabriel Wicki 580782bb72
core: Simplify math expressions.
* src/gc.c (gc_up_arena): Use division instead of shift.
(gc_flip): Simplify (free-news) * 1.5.
2022-05-10 22:23:40 +02:00
Gabriel Wicki 7b993b35b9
core: Remove code duplication.
* src/gc.c (copy_news): Remove copy of copy_cell.
(gc_copy): Use copy_cell instead.
2022-05-13 08:27:57 +02:00
Gabriel Wicki c7777121e8
core: Remove code duplication.
* src/gc.c (news_bytes): Remove copy of cell_bytes.
(gc_copy): Use cell_bytes instead.
* include/mes/mes.h (news_bytes): Remove prototype.
2022-05-13 08:27:56 +02:00
Jan (janneke) Nieuwenhuizen 8920f558c6
core: Fix FRAME_SIZE conflict.
This avoids conflicting with FRAME_SIZE from signal.h.

* include/mes/constants.h (FRAME_SIZE): Rename to...
(GC_FRAME_SIZE): ...this.
(FRAME_PROCEDURE): Rename to...
(GC_FRAME_PROCEDURE): ...this.
* src/eval-apply.c (eval_apply): Update accordingly.
* src/gc.c (gc_push_frame, gc_peek_frame, gc_pop_frame): Update accordingly.
* src/stack.c (make_frame, make_stack): Update accordingly.
2021-05-16 13:27:12 +02:00
Jan (janneke) Nieuwenhuizen 8f67315eb6
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 10:24:22 +01:00
Jan (janneke) Nieuwenhuizen b237308f26
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 a788fcfda7
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 795225ec29
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-29 13:38:38 +01:00
Jan (janneke) Nieuwenhuizen 8f2bc16e7a
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 3b29abc850
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 1cdbadfe98
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 5c9f2edd90
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-09-20 11:11:08 +02:00
Jan (janneke) Nieuwenhuizen 3f368e29e1
core: gc: Abort upon broken heart failure.
* src/gc.c (gc_cellcpy, gc_loop): Abort upon broken heart failure.
2020-09-20 10:58:36 +02:00
Jan (janneke) Nieuwenhuizen 20595cd044
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-09-20 09:35:56 +02:00
Jan (janneke) Nieuwenhuizen b05558ec00
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 3de592d441
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-09-13 18:20:52 +02:00
Jan (janneke) Nieuwenhuizen 99040a38c4
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 19ecbfe950
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 17805e9d3a
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-08-16 08:56:56 +02:00
Jan (janneke) Nieuwenhuizen a54f6e9028
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.
2020-07-16 21:56:49 +02:00
Jan (janneke) Nieuwenhuizen f9a372de13
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 52c57da02f
core: gc: FRAME_SIZE.
* src/gc.c (gc_loop, gc_): Use FRAME_SIZE.
2020-06-22 19:26:55 +02:00
Jan (janneke) Nieuwenhuizen c6670b46c3
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 94e40691ba
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 781f4f0e6c
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
Jan (janneke) Nieuwenhuizen 0f951cac5d
core: Remove macros from cell creation: make_bytes.
* src/gc.c (bytes_cells, make_bytes): Move from string.c.
* include/mes/macros.h (MAKE_BYTES0, NAME_SYMBOL): Remove.
* include/mes/m2.h: Likewise.
2020-05-18 21:57:55 +02:00
Jan (janneke) Nieuwenhuizen 7932d4bad7
core: Remove core:make-cell.
* src/gc.c (alloc, make_cell, cons): Move from mes.c
* src/mes.c: (make_cell_): Remove.
* src/lib.c (char_to_integer, integer_to_char): New function.
* src/builtins.c (mes_builtins): Add them; remove make_cell_.
* mes/module/mes/type-0.mes (char->integer, integer->char): Remove.
2020-05-18 00:40:50 +02:00
Jan (janneke) Nieuwenhuizen f746db72c5
core: Upcase register names.
* include/mes/mes.h (R0, R1, R2, R3, M0): Rename from lower case.
Update users.
2020-05-17 22:32:53 +02:00
Jan (janneke) Nieuwenhuizen 6a96134eba
core: Use assert_msg.
* src/mes.c: Use assert_msg instead of assert.
* src/gc.c: Likewise.
* src/hash.c: Likewise.
* src/lib.c: Likewise.
* src/math.c: Likewise.
* src/module.c: Likewise.
* src/posix.c: Likewise.
* src/reader.c: Likewise.
* src/string.c: Likewise.
* src/struct.c: Likewise.
* src/vector.c: Likewise.
* simple.make (LIB_SOURCES): Add lib/mes/assert_msg.c.
2020-05-17 16:07:04 +02:00
Jan (janneke) Nieuwenhuizen 948c6ef91d
core: Prepare for M2-Planet: gc.c.
* src/gc.c: Rewrite C constructs not supported by M2-Planet.
2020-04-19 13:23:47 +02:00
Jan (janneke) Nieuwenhuizen 348e070bac
build: Run indent for M2.
* src/gc.c: Indented.
* src/string.c: Likewise.
2020-04-19 11:36:18 +02:00
Jan Nieuwenhuizen 5dc245e739
build: Simplify.
core: Make mes src/ c files separate compilation units.

* include/mes/constants.h: New file.
* include/mes/macros.h: New file.
* include/mes/mes.h: New file.
* src/gc.c: Update.
* src/hash.c: Update.
* src/lib.c: Update.
* src/math.c: Update.
* src/mes.c: Update.
* src/module.c: Update.
* src/posix.c: Update.
* src/reader.c: Update.
* src/string.c: Update.
* src/struct.c: Update.
* src/vector.c: Update.

    mes: Update datadir.

* src/mes.c (g_datadir): New global.
(open_boot): Rename from read_boot.
(read_boot): New function.
* mes/module/mes/boot-0.scm: Move from boot-0.scm.in
* configure: Update.
* configure.sh: Update.

    mescc: Create libraries from separate files.

* .gitignore: Update.
* build-aux/bootstrap-mes.sh: Remove.
* build-aux/bootstrap.sh.in: Remove.
* build-aux/build-guile.sh: Update.
* build-aux/build-mes.sh: Update.
* build-aux/build-scaffold.sh: New file.
* build-aux/build.sh.in: Update.
* build-aux/cc.sh: Update.
* build-aux/check-tcc.sh: Remove.
* build-aux/config.sh.in: New file.
* build-aux/config.sh: Remove.
* build-aux/install.sh.in: Update.
* build-aux/test-boot.sh: New file.
* build-aux/test-c.sh: New file.
* build-aux/test-driver: New file.
* build-aux/test-suite.sh: New file.
* build-aux/trace.sh: Update.
* build-aux/uninstall.sh.in: Update.
* configure: Update.
* configure.sh: Update.
* lib/linux/x86-mes-mescc/crt1.c: Move from lib/linux/x86-mes.
* lib/linux/x86-mes-mescc/mini.c: Likewise.
* lib/linux/x86_64-mes-mescc/crt1.c: Move from lib/linux/x86_64-mes.
* lib/linux/x86_64-mes-mescc/mini.c: Likewise.
* lib/linux/x86-mes-gcc/syscall.c: Rename from mes.c.
* lib/linux/x86-mes-mescc/syscall.c: Likewise.
* lib/linux/x86_64-mes-gcc/syscall.c: Likewise.
* lib/linux/x86_64-mes-mescc/syscall.c: Likewise.
* lib/mes/mes_open.c: Include config.h.
* lib/tests/stdio/70-printf-hello.c: Likewise.
* lib/tests/stdio/70-printf-simple.c: Likewise.
* scaffold/gc-test.sh: New file.
* simple.sh: Update.
2019-06-08 15:36:22 +02:00
Jan Nieuwenhuizen 952b92dfec
mes: Make debug levels 4 and 5 usable.
* HACKING: Update debug policy.
* lib/linux/read.c (read): Print read in level 5.
* src/mes.c (eval_apply): Print module in level 6.
(main): Likewise.  Remove redundant module printing.
* src/gc.c (gc): Print symbols in level 6.
2019-05-27 21:30:48 +02:00
Jan Nieuwenhuizen c33d6d00bc
mes: Run build-aux/indent.sh.
* src/mes.c: Re-indent.
* src: Likewise.
* include: Likewise.
* lib: Likewise.
* scaffold: Likewise.
2019-05-18 13:27:42 +02:00
Jan Nieuwenhuizen 99ac7b59c4
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 09:55:16 +01:00
Jan Nieuwenhuizen 149f2a3e51
core: String as array of bytes.
* src/strings.c: New file.
* src/mes.c: Use it.  Update users.
2018-11-11 16:25:36 +01:00
Jan Nieuwenhuizen c2c361bf1a
core: Implement stack and frame.
* src/lib.c (frame_printer make_frame_type, make_frame,
make_stack_type, make_stack, stack_length, stack_ref): New function.
2018-10-20 18:23:20 +02:00
Jan Nieuwenhuizen 4e0e4c83d8
Revert "core: Add gc-debug for stack array."
This reverts commit f35084d1dbea889d107824e7596da1701c6b90ad.
2018-10-20 10:58:56 +02:00
Jan Nieuwenhuizen e032f6c70f
core: Add gc-debug for stack array.
* src/gc.c (gc_debug): New function.
2018-10-19 21:23:17 +02:00
Jan Nieuwenhuizen d73df09ab6
core: Use array-based stack.
* src/mes.c (STACK_SIZE)[MES_ARRAY_STACK]: New variable.
(g_stack_array): New variable.
(g_stack): Change type to SCM*.
(gc_push_frame)[MES_ARRAY_STACK]: Use g_stack_array, g_stack.
(gc_peek_frame): Likewise.
(gc_pop_frame): Likewise.
* src/gc.c (gc_check): Likewise.
(gc): Likewise.
2017-12-14 07:05:53 +01:00
Jan Nieuwenhuizen 0068fe533d
core: Add struct type.
* src/struct.c: New file.
* build-aux/snarf.sh: Snarf it.
* src/mes.c: Include it.
2018-10-13 17:34:27 +02:00
Jan Nieuwenhuizen 5a6d8c21e0
mescc: Mes C Library: Add x86_64 libc support.
* include/linux/x86_64/syscall.h: New file.
* include/linux/x86/syscall.h: New file.
* lib/linux/x86_64-mes-gcc/mes.c: New file.
* lib/linux/x86-mes/mes.c: Rename from lib/linux/mes.c.
* lib/linux/x86-mes-gcc/mes.c: Rename from lib/linux/gcc.c.
* lib/linux/libc.c: Update includes.
(waitpid)[__x86_64__]: Use wait4.
* build-aux/build-cc.sh: Build libc too.
* lib/x86-mes/x86.M1 (mov____0x8(%ebp),%esi): New macro.
2018-08-11 11:42:30 +02:00
Jan Nieuwenhuizen 72cb975213
GNU Mes.
Throughout, make these changes

   Copyright headers: GNU Mes
   First mention of name: GNU Mes
   Website: https://www.gnu.org/software/mes
   Git:     git://git.savannah.gnu.org/mes.git
2018-07-22 14:24:36 +02:00
Jan Nieuwenhuizen dc24a7f76f
core: Add string ports.
* src/mes.c (type_t): Add TPORT.
  (scm_type_port): New symbol.
  (PORT): New macro.
  (MAKE_STRING_PORT): New macro.
  (eval_apply): Handle string ports in primitive-load.
  (mes_symbols): Add scm_type_port.
* src/posix.c (peekchar): Handle string ports.
  (readchar): New function.  Replace all getchar callers.
  (unreadchar): Likewise.
* module/mes/type-0 (port?): New function.
* module/mes/guile.mes (with-input-from-file): Rewrite.
  (open-input-string): Remove.
* module/mes/guile.scm (guile): Update cell types.
* src/gc.c (gc_loop): Support TPORT.
* src/lib.c (display_helper): Support TPORT.
* module/mes/display.mes (display): Support TPORT.
2018-04-29 17:48:38 +02:00
Jan Nieuwenhuizen a56d5e3efe
core: Fix gc_up_arena for x86_64.
* src/gc.c (gc_): Fix gc_up_arena for x86_64.
2018-04-29 12:04:18 +02:00
Jan Nieuwenhuizen 865e72ae8a
core: Fix compile warnings.
* src/posix.c: Include sys/stat.h.
  (chmod): Return cell_unspecified.
* include/stdlib.h: Typo.
2018-04-29 12:02:23 +02:00
Jan Nieuwenhuizen e3b929aa87
core: jam-scaper/garbage-collector: Use only one arena.
* src/mes.c (ARENA_SIZE): Lower to 200000.
  (MES_MAX_ARENA): Bump to 300000000.
  (JAM_SIZE): New global.
  (make_cell__): Remove ARENA assert.
  (gc_init_cells): Alloc ARENA_SIZE + JAM_SIZE.
  (mes_symbols): Do not init news.
  (gc_init_news): Remove.
  (main): Initialize JAM_SIZE, consider MES_JAM environment variable.
* src/gc.c (gc_init_news): Move from mes.c.  Start at g_free.
  (gc_flip): Do not flip to g_news, instead copy g_news to cells.
  (gc_up_arena): Realloc to ARENA_SIZE + JAM_SIZE.
  (gc_): Init news.  Only up arena if g_news is safe.
2018-04-25 08:35:05 +02:00