Commit Graph

202 Commits

Author SHA1 Message Date
Janneke Nieuwenhuizen 0f0a510c43 Revert "crt1: Move main declaration to mes/lib-mini.h."
This reverts commit 5b55627e0ccf7c798284a380a20a2eb4d6b9c4c0.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen 376f8a43d0 crt1: Move main declaration to mes/lib-mini.h.
* include/mes/lib-mini.h (main): New declaration.
lib/freebsd/x86-mes-gcc/crt1.c (main): Remove declaration.
lib/freebsd/x86-mes-mescc/crt1.c (main): Remove declaration.
lib/gnu/x86-mes-gcc/crt1.c (main): Remove declaration.
lib/linux/arm-mes-gcc/crt1.c (main): Remove declaration.
lib/linux/arm-mes-m2/crt1.c (main): Remove declaration.
lib/linux/arm-mes-mescc/crt1.c (main): Remove declaration.
lib/linux/riscv64-mes-gcc/crt1.c (main): Remove declaration.
lib/linux/riscv64-mes-m2/crt1.c (main): Remove declaration.
lib/linux/riscv64-mes-mescc/crt1.c (main): Remove declaration.
lib/linux/x86-mes-gcc/crt1.c (main): Remove declaration.
lib/linux/x86-mes-m2/crt1.c (main): Remove declaration.
lib/linux/x86-mes-mescc/crt1.c (main): Remove declaration.
lib/linux/x86_64-mes-gcc/crt0.c (main): Remove declaration.
lib/linux/x86_64-mes-gcc/crt1.c (main): Remove declaration.
lib/linux/x86_64-mes-m2/crt1.c (main): Remove declaration.
lib/linux/x86_64-mes-mescc/crt1.c (main): Remove declaration.
2023-09-12 11:04:11 +02:00
Andrius Štikonas e42cf58d14 riscv64: Port to word based mescc-tools.
* module/mescc/M1.scm (riscv:i-format, riscv:j-format, riscv:u-format):
New procedures for RISC-V instruction formats.
(info->M1): Use them to switch from !0xAB to M1
weird strings 'AB'.
* module/mescc/riscv64/as.scm,
lib/linux/riscv64-mes-m2/_exit.c
ib/linux/riscv64-mes-m2/_write.c,.
lib/linux/riscv64-mes-m2/crt1.M1,.
lib/linux/riscv64-mes-m2/syscall.c,.
lib/linux/riscv64-mes-mescc/_exit.c,.
lib/linux/riscv64-mes-mescc/_write.c,.
lib/linux/riscv64-mes-mescc/crt1.c,.
lib/linux/riscv64-mes-mescc/syscall-internal.c,.
lib/linux/riscv64-mes-mescc/syscall.c,.
lib/m2/riscv64/riscv64_defs.M1,.
lib/riscv64-mes-mescc/setjmp.c,.
lib/riscv64-mes/riscv64.M1: Switch to riscv64 word-based macros.
* lib/linux/open.c (open)[!SYS_open]: Add support using openat syscall.
* include/linux/riscv64/syscall.h (MAKESTRING, MAKESTRING2,
RISCV_SYSCALL): New macros.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen afe3831e66 x86: lib: Use __init_io.
* build-aux/configure-lib.sh (libc_mini_shared_SOURCES): Add init_io.c.
* include/mes/lib-mini.h (__init_io): Declare it.
* lib/linux/x86-mes-gcc/crt1.c (_start): Replace manual initialization
of __stdin, __stdout, __stderr, and environ with __init_io ().
* lib/linux/x86-mes-m2/crt1.M1 (_start): Likewise.
* lib/linux/x86-mes-mescc/crt1.c (_start): Likewise.
2023-09-12 11:04:11 +02:00
W. J. van der Laan 9044e13309 lib: Make stdarg work for GCC on RISC-V64.
* include/stdarg.h: GCC on RISC-V always passes arguments in registers.
Implementing these macros without the use of built-ins would be very
involved. So use those for now to make printf etc work.
2023-09-12 11:04:11 +02:00
W. J. van der Laan f24b1e467c lib: General Linux RISC-V64 syscall support.
* include/linux/riscv32/kernel-stat.h,
include/linux/riscv64/kernel-stat.h: New files.
* include/fcntl.h (AT_FDCWD, AT_SYMLINK_NOFOLLOW, AT_REMOVEDIR): Add
necessary constants.
* include/stdint.h: Integer size defines for RISC-V.
* include/sys/stat.h: "stat" struct for RISC-V.
* lib/linux/_open3.c (_open3)[!SYS_open]: Use SYS_openat.
* lib/linux/access.c (access)[!SYS_access]: Use SYS_faccessat.
* lib/linux/chmod.c (chmod)[!SYS_chmod]: Use SYS_fchmodat.
* lib/linux/dup2.c (dup2)[!SYS_dup2]: Use if SYS_dup3.
* lib/linux/fork.c (fork)[!SYS_fork]: Use SYS_clone.
* lib/linux/getdents.c (getdents)[!SYS_getdents]: Use SYS_getdents64.
* lib/linux/link.c (link)[!SYS_link]: Use SYS_linkat.
* lib/linux/lstat.c (lstat)[!SYS_lstat]: Use SYS_newfstatat.
* lib/linux/mkdir.c (mkdir)[!SYS_mkdir]: Use SYS_mkdirat.
* lib/linux/mknod.c (mknod)[!SYS_mknod]: Use SYS_mknodat.
* lib/linux/pipe.c (pipe)[!SYS_pipe]: Use SYS_pipe2.
* lib/linux/readlink.c (readlink)[!SYS_readlinkat]: Use SYS_readlinkat.
* lib/linux/rename.c (rename)[!SYS_rename]: Use SYS_renameat2.
* lib/linux/rmdir.c (rmdir)[!SYS_rmdir]: Use SYS_unlinkat.
* lib/linux/signal.c (_restorer_for_siginfo): Remove unused function
that causes compilation issue.
* lib/linux/stat.c (stat)[!SYS_stat]: Use SYS_newfstatat.
* lib/linux/symlink.c (symlink)[!SYS_symlinkat]: Use SYS_symlink.
* lib/linux/unlink.c (unlink)[!SYS_unlink]: Use SYS_unlinkat.
2023-09-12 11:04:10 +02:00
W. J. van der Laan 9ce2b56743 lib: Add _sys_call_5 for Linux RISC-V64.
* include/linux/syscall.h (_sys_call5): Declare 5-argument syscall needed
for SYS_renameat2, currently only used on RISC-V64.
* lib/linux/riscv64-mes-gcc/syscall.c (__sys_call5, _sys_call5):
Implement it.
2023-09-12 11:04:10 +02:00
W. J. van der Laan 33f23d652b lib: Add RISC-V64 Linux syscall numbers header.
* include/linux/riscv64/syscall.h: New file: list relevant syscall
number constants.
2023-09-12 11:04:10 +02:00
Jan (janneke) Nieuwenhuizen b9647b874c lib: Document syscalls.
* include/linux/SYSCALLS: New file.
2023-09-12 11:04:10 +02:00
Jan (janneke) Nieuwenhuizen c8294803cd x86_64: build: Cater for M2-Planet.
* build-aux/cflags.sh: Set cc_cpu.
* build-aux/config.sh.in (cc_cpu): Export.
* build-aux/export.make (cc_cpu): Likewise.
* kaem.arm (cc_cpu): New variable.
* kaem.x86 (cc_cpu): New variable.
* kaem.run (cc_cpu): New variable.  Define __<cc_cpu>__.
* scaffold/argv.kaem (cc_cpu): Likewise.  Define __linux__
* scaffold/global-array.kaem (cc_cpu): Likewise.
* scaffold/hello.kaem (cc_cpu): Likewise.
* scaffold/local-array.kaem (cc_cpu): Likewise.
* scaffold/local-static-array.kaem (cc_cpu): Likewise.
* scaffold/main.kaem (cc_cpu): Likewise.
* scaffold/read.kaem (cc_cpu): Likewise.
* kaem.x86_64: New file.
lib/m2/x86_64/ELF-x86_64.hex2,
lib/m2/x86_64/x86_64_defs.M1: New files, imported from M2Libc.
lib/linux/x86_64-mes-m2/_exit.c,
lib/linux/x86_64-mes-m2/_write.c,
lib/linux/x86_64-mes-m2/crt1.M1,
lib/linux/x86_64-mes-m2/crt1.c,
lib/linux/x86_64-mes-m2/syscall.c: New files, adapted for M2-Planet
calling convention from ...
* lib/linux/x86_64-mes-mescc: ... here.
* build-aux/build.sh.in: Also allow kaem build for x86_64.
* include/mes/lib-mini.h[__M2__]: Define as sizeof (void*).
* include/mes/mes.h[__M2__](M2_CELL_SIZE): Define as sizeof (struct scm).
* lib/x86_64-mes/x86_64.M1 (add____$i8,%rbp, mov____%rdi,%rbp): New
defines.
* src/posix.c (TIME_UNITS_PER_SECOND): Cater for 64bit M2-Planet.
2023-09-12 11:04:02 +02:00
Emily Trau c20f6ac025 lib: Define O_TMPFILE for GNU make 4.4.1.
* include/fcntl.h (O_TMPFILE): New define.
2023-07-08 15:10:05 +02:00
Jan (janneke) Nieuwenhuizen 6bc6e8354e lib: linux: Add wait4.
* lib/linux/waitpid.c (waitpid): Factor-out wait4 call to...
* lib/linux/wait4.c: ...new file here.
* include/sys/wait.h (wait4): Add prototype.  Include sys/resource.h.
* include/sys/resource.h (struct rusage): Remove gratuitous "int" for
M2-Planet.
* build-aux/configure-lib.sh (libc_SOURCES): Add it.
* kaem.run,
simple.make (M2_SOURCES),
simple.sh: Likewise.  Also add resource.h.
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
Jan (janneke) Nieuwenhuizen 4d4e6959e9 kaem: read: Remove --bootstrap-mode.
* include/mes/lib.h[__M2__](__call_at_exit,abtod,dtoab,ultoa,
* include/sys/types.h[__M2__]: Fall back to unsigned instead of using
unsigned long.
* include/stdio.h[__M2__](fprintf, fscanf, printf, snprintf, sprintf,
sscanf): Hide prototypes.
* lib/stdlib/exit.c (exit)[__M2__]: Hide call to __call_at_exit.
* lib/linux/read.c (read)[__M2__]: Hide debugging.
* lib/linux/malloc.c (malloc)[__M2__]: Hide alignment.
__mesabi_umod, __mesabi_udiv, __mesabi_uldiv): Hide prototypes.
* scaffold/argv.kaem: Use them together with lib/mes/lib-mini.h instead of
lib/mes/* specializations.  Remove --bootstrap-mode from M2-Planet call.
2023-05-02 10:22:45 +02:00
Jan (janneke) Nieuwenhuizen fda2e4b9fc kaem: hello: Remove --bootstrap-mode.
* include/mes/lib-mini.h: Remove M2 bootstrap constants.
[__M2__](size_t): Fall-back to unsigned instead of unsigned long.
* scaffold/hello.kaem: Use it instead of lib/m2/lib.h.  Remove
--bootstrap-mode from M2-Planet call.
2023-05-02 10:22:45 +02:00
Jan (janneke) Nieuwenhuizen bc1fa57851
lib: stat: Use SYS_stat64 for 32bit platforms.
This fixes <https://debbugs.gnu.org/41264>.

* include/linux/arm/syscall.h (SYS_stat64, SYS_lstat64,
SYS_fstat64)[__SIZEOF_LONG_LONG__ == 8]:
New defines.
(SYS_stat, SYS_lstat, SYS_fstat)[__SIZEOF_LONG_LONG__ == 8]: Redefine them.
* include/linux/x86/syscall.h (SYS_stat64, SYS_lstat64,
SYS_fstat64)[__SIZEOF_LONG_LONG__ == 8]:
New defines.
(SYS_stat, SYS_lstat, SYS_fstat)[__SIZEOF_LONG_LONG__ == 8]: Redefine them.
* include/sys/stat.h (struct stat): Move definition to...
* include/linux/arm/kernel-stat.h,
include/linux/m2/kernel-stat.h,
include/linux/x86/kernel-stat.h,
include/linux/x86_64/kernel-stat.h: These new files.
* include/gnu/x86/kernel-stat.h: New file.
* configure (main): Copy <srcdest>include/<kernel>/<arch>/*.h to
include/.
* configure.sh: Likewise.
* .gitignore: Ignore them.  Add copyright header.
* build-aux/GNUmakefile.in (X86_ARCH_HEADERS, ARCH_HEADERS): New
variables.
(build): Use them.
(include/arch/%.h, arch-dir): New targets.
* build-aux/bootstrap.sh.in (AM_CPPFLAGS): Replace
<srcdest>include/<kernel>/<cpu> with built ../include.
* build-aux/build.sh.in (AM_CPPFLAGS): Likewise.
* build-aux/install.sh.in: Also install built include.
* include/m2/types.h: New file.
* kaem.run: Use it.
* simple.sh: Copy kernel-stat.h, syscall.h for kernel/cpu to
include/arch.
2022-10-29 13:17:58 +02:00
Jan (janneke) Nieuwenhuizen 25e0c4d119
lib: __assert_fail: Update to standard.
* lib/mes/__assert_fail.c (__assert_fail): Add file, line, function
parameters.
* include/assert.h (assert): Update caller.
(__assert_fail): Update prototype.
* include/mes/lib.h (__assert_fail): Likewise.
* lib/mes/assert_msg.c (assert_msg): Likewise.  Include assert.h.
2022-10-26 21:14:05 +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
Dor Askayo ce54ccc2c0
Fix definition of S_ISUID.
* include/sys/stat.h (S_ISUID: Append missing zero.
2022-05-09 07:01:01 +02:00
Jan (janneke) Nieuwenhuizen d1297688a8
ARM: build: Cater for M2-Planet.
* include/linux/arm/syscall.h: Add support for M2-Planet.
* lib/linux/arm-mes-m2/_exit.c,
lib/linux/arm-mes-m2/_write.c,
lib/linux/arm-mes-m2/crt1.M1,
lib/linux/arm-mes-m2/crt1.c,
lib/linux/arm-mes-m2/syscall.c,
lib/m2/arm/ELF-arm.hex2,
lib/m2/arm/arm_defs.M1: New files.
* build-aux/build.sh.in: Also allow kaem build for ARM.
2022-04-30 22:51:42 +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 72e371d77f
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 b23c6885a6
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 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 96e6ecaf7d
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 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 fca14d27ad
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 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 ca8e9f0342
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 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 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 4bcfc155c1
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 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 020cb3661d
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 c6fd15469c
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 f8152da76a
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 e1efd41abe
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 9e684b9886
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 b30af2ce9f
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 8c6756e7f2
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 178b063ffa
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 3ff1fcb809
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 fd130a03d1
kaem: scaffold/read.kaem.
* .gitignore: Update.
* include/linux/x86/syscall.h: Update for M2-Planet.
* lib/linux/brk.c (brk): Remove cast for M2-Planet.
* lib/linux/x86-mes-m2/syscall.c: New file.
* lib/m2/malloc.c: New file.
* lib/string/memset.c (memset): Update for M2-Planet.
* scaffold/read.c: Update for M2-Planet.
* scaffold/kaem.read: New file.
2020-07-15 22:27:57 +02:00
Jan (janneke) Nieuwenhuizen e8b426ebce
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 dfe8d3c16c
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 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