Compare commits

...

180 Commits

Author SHA1 Message Date
Jan Nieuwenhuizen 09caee3706
Revert "core: M2 remove macros."
This reverts commit eaf4291b11.
2019-10-26 18:46:42 +02:00
Jan Nieuwenhuizen ac06b7addd
Revert "*CDR_PTR -> [0]"
This reverts commit 474159632a.
2019-10-26 18:46:37 +02:00
Jan Nieuwenhuizen 474159632a
*CDR_PTR -> [0] 2019-10-26 18:46:24 +02:00
Jan Nieuwenhuizen eaf4291b11
core: M2 remove macros. 2019-10-26 18:46:24 +02:00
Jan Nieuwenhuizen 2f3aa86e7d
tests: Add gc.c
* tests/gc.test: New file.
* build-aux/check-mes.sh (TESTS): Add it.
2019-10-26 16:39:43 +02:00
Jan Nieuwenhuizen ab5128960e
WIP: eval/apply i/t 2019-10-26 16:30:05 +02:00
Jan Nieuwenhuizen 606675ae8d
posix 2019-10-26 16:26:34 +02:00
Jan Nieuwenhuizen ce9bd2a891
eval/apply: continue! 2019-10-26 16:03:20 +02:00
Jan Nieuwenhuizen c474d34a4c
eval/apply 2019-10-26 14:55:28 +02:00
Jan Nieuwenhuizen 7dc31840f9
m2.h 2019-10-26 14:45:31 +02:00
Jan Nieuwenhuizen e92d17117f
eval/apply 2019-10-26 14:45:24 +02:00
Jan Nieuwenhuizen b480976ab4
eval/apply 2019-10-26 14:35:25 +02:00
Jan Nieuwenhuizen d8e99539e4
eval/apply 2019-10-26 14:28:02 +02:00
Jan Nieuwenhuizen a55e739cfb
eval/apply 2019-10-26 14:26:26 +02:00
Jan Nieuwenhuizen a9b0f8cfe0
m2.h 2019-10-26 14:23:05 +02:00
Jan Nieuwenhuizen 4e0034e07a
eval-apply 2019-10-26 14:22:57 +02:00
Jan Nieuwenhuizen d781e444c8
m2.h 2019-10-26 14:17:28 +02:00
Jan Nieuwenhuizen a4f3f01e71
eval-appy CDADR 2019-10-26 14:17:28 +02:00
Jan Nieuwenhuizen 18d255cf1f
M2: string 2019-10-26 13:45:58 +02:00
Jan Nieuwenhuizen 88fbcb5ff7
M2/VALUE: reader 2019-10-26 13:45:57 +02:00
Jan Nieuwenhuizen 20b861ac89
VALUE posix 2019-10-26 13:45:57 +02:00
Jan Nieuwenhuizen d9d8c04c16
M2: VALUE/math 2019-10-26 13:45:57 +02:00
Jan Nieuwenhuizen 3d63f99e0d
pointer 2019-10-26 13:45:57 +02:00
Jan Nieuwenhuizen d899077866
pointer 2019-10-26 13:45:57 +02:00
Jan Nieuwenhuizen e8bfa77a9b
pointer 2019-10-26 13:45:57 +02:00
Jan Nieuwenhuizen 29cf1a3ef8
eval-apply VALUE 2019-10-26 13:45:57 +02:00
Jan Nieuwenhuizen 8070c7b9a6
pointer 2019-10-26 13:45:56 +02:00
Jan Nieuwenhuizen 655568654e
m2.h: POINTER: CELL 2019-10-26 13:45:56 +02:00
Jan Nieuwenhuizen 138d4b458d
M2: setenv 2019-10-26 13:45:56 +02:00
Jan Nieuwenhuizen 920a103344
M2: ntoab 2019-10-26 13:45:56 +02:00
Jan Nieuwenhuizen 529156c393
M2: malloc 2019-10-26 13:45:56 +02:00
Jan Nieuwenhuizen c4c92c64cb
M2: getcwd 2019-10-26 13:45:56 +02:00
Jan Nieuwenhuizen c2ba415b1f
M2: memset 2019-10-26 13:45:56 +02:00
Jan Nieuwenhuizen cb35345d85
posix = 0 2019-10-26 13:45:55 +02:00
Jan Nieuwenhuizen 7cbfca3db2
eval =0 2019-10-26 13:45:55 +02:00
Jan Nieuwenhuizen 618da7a661
fisplay =0 2019-10-26 13:45:55 +02:00
Jan Nieuwenhuizen 8a70cd1154
eval-apply: 0 2019-10-26 13:45:55 +02:00
Jan Nieuwenhuizen 9feef1e51f
reader: =0 2019-10-26 13:45:55 +02:00
Jan Nieuwenhuizen e6ce0cc145
mes: = 0 2019-10-26 13:45:55 +02:00
Jan Nieuwenhuizen 3d7386dbdc
symbols: != 0 FIX 2019-10-26 13:45:55 +02:00
Jan Nieuwenhuizen be1be50f66
ASSERT_MSG: mes 2019-10-26 13:45:54 +02:00
Jan Nieuwenhuizen 6166d194ea
ASSERT_MSG: hash 2019-10-26 13:45:54 +02:00
Jan Nieuwenhuizen b2bcf6456c
ASSERT_MSG: eval-apply 2019-10-26 13:45:54 +02:00
Jan Nieuwenhuizen ad6888ded2
M2: no pointer..best ever 2019-10-26 13:45:54 +02:00
Jan Nieuwenhuizen 8a8f34c8ba
hash: outline 2019-10-26 13:44:41 +02:00
Jan Nieuwenhuizen 93bb34fa31
M2: VALUE hash.c 2019-10-26 13:44:40 +02:00
Jan Nieuwenhuizen 73c5abdcf1
M2: builtins.c VALUE 2019-10-26 13:44:40 +02:00
Jan Nieuwenhuizen 39d6995769
arith 2019-10-26 13:44:40 +02:00
Jan Nieuwenhuizen ef6f138097
m2-planet: gc: arithmetic meneer van dale 2019-10-26 13:44:40 +02:00
Jan Nieuwenhuizen 739c4eb81e
m2: memcpy! 2019-10-25 11:12:14 +02:00
Jan Nieuwenhuizen f7d33a5931
pointer cells/planeet fixups 2019-10-25 11:05:35 +02:00
Jan Nieuwenhuizen b306080171
make-bytes /gc weird M2_PLANET
* src/gc.c (make_bytes):
2019-10-24 22:30:20 +02:00
Jan Nieuwenhuizen a347ab3050
pointer.sh 2019-10-24 22:30:20 +02:00
Jan Nieuwenhuizen 6adc5f20bb
core: Prepaere for M2-Planet.
* 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.
2019-10-24 22:30:20 +02:00
Jan Nieuwenhuizen 65ac20a171
core: read_string: Prepare for M2-Planet.
* src/string.c (read_string): Prepare for M2-Planet.
2019-10-24 21:44:40 +02:00
Jan Nieuwenhuizen 7c1fcb82e7
core: string_equal_p: Prepare for M2-Planet.
* src/string.c (string_equal_p): Prepare for M2-Planet.
2019-10-24 21:43:29 +02:00
Jan Nieuwenhuizen 0fd071baf9
core: reader_read_block_comment: Prepare for M2-Planet.
* src/reader.c (reader_read_block_comment): Prepare for M2-Planet.
2019-10-24 21:38:21 +02:00
Jan Nieuwenhuizen 2f6f275adc
core: reader_eat_whitespace: Prepare for M2-Planet.
* src/reader.c (reader_eat_whitespace): Prepare for M2-Planet.
2019-10-24 21:37:41 +02:00
Jan Nieuwenhuizen fd2828518e
core: reader_read_sexp_: Prepare for M2-Planet.
* src/reader.c (reader_read_sexp_): Prepare for M2-Planet.
2019-10-24 21:36:36 +02:00
Jan Nieuwenhuizen 976adefb7b
core: reader_read_identifier_or_number: Prepare for M2-Planet.
* src/reader.c (reader_read_identifier_or_number): Prepare for M2-Planet.
2019-10-24 21:35:50 +02:00
Jan Nieuwenhuizen 5b40e70904
core: open_output_file: Prepare for M2-Planet.
* src/posix.c (open_output_file): Prepare for M2-Planet.
2019-10-24 21:32:39 +02:00
Jan Nieuwenhuizen 2b9c900048
core: current_input_port: Prepare for M2-Planet.
* src/posix.c (current_input_port): Prepare for M2-Planet.
2019-10-24 21:31:51 +02:00
Jan Nieuwenhuizen 87c8c920d4
core: write_byte: Prepare for M2-Planet.
* src/posix.c (write_byte): Prepare for M2-Planet.
2019-10-24 21:29:45 +02:00
Jan Nieuwenhuizen cbae4a240b
core: read_char: Prepare for M2-Planet.
* src/posix.c (read_char): Prepare for M2-Planet.
2019-10-24 21:26:24 +02:00
Jan Nieuwenhuizen 7660840caa
core: last_pair: Prepare for M2-Planet.
* src/lib.c (last_pair): Prepare for M2-Planet.
2019-10-24 21:25:06 +02:00
Jan Nieuwenhuizen 4fb20ba835
core: memq: Prepare for M2-Planet.
* src/lib.c (memq): Prepare for M2-Planet.
2019-10-24 21:23:38 +02:00
Jan Nieuwenhuizen c6526bd1dc
core: xassq: Prepare for M2-Planet.
* src/lib.c (xassq): Prepare for M2-Planet.
2019-10-24 21:20:17 +02:00
Jan Nieuwenhuizen 132b1915dd
core: hash_cstring: Prepare for M2-Planet.
* src/hash.c (hash_cstring): Prepare for M2-Planet.
2019-10-24 21:19:06 +02:00
Jan Nieuwenhuizen 0f6321fab0
core: eval_apply: Prepare for M2-Planet.
* src/eval-apply.c (eval_apply): Prepare for M2-Planet.
2019-10-24 21:11:17 +02:00
Jan Nieuwenhuizen 1cf36a4666
core: apply_builtin: Prepare for M2-Planet.
* src/eval-apply.c (apply_builtin): Prepare for M2-Planet.
2019-10-24 21:11:17 +02:00
Jan Nieuwenhuizen aa9cd4a395
core: formal_p: Prepare for M2-Planet.
* src/eval-apply.c (formal_p): Prepare for M2-Planet.
2019-10-24 21:11:11 +02:00
Jan Nieuwenhuizen b6441309ca
core: builtin_p: Prepare for M2-Planet.
* src/builtins.c (builtin_p): Prepare for M2-Planet.
2019-10-24 19:08:12 +02:00
Jan Nieuwenhuizen 72a3247db2
core: assoc: Prepare for M2-Planet.
* src/mes.c (assoc): Prepare for M2-Planet.
2019-10-24 19:08:08 +02:00
Jan Nieuwenhuizen 8679bad7bf
core: assq: Prepare for M2-Planet.
* src/mes.c (assq): Prepare for M2-Planet.
2019-10-24 19:08:04 +02:00
Jan Nieuwenhuizen 4ec65def60
core: eq_p: Prepare for M2-Planet.
* src/mes.c (eq_p): Prepare for M2-Planet.
2019-10-24 19:07:59 +02:00
Jan Nieuwenhuizen 0360ba91d5
core: assoc_string: Prepare for M2-Planet.
src/mes.c (assoc_string): Prepare for M2-Planet.
2019-10-24 19:07:55 +02:00
Jan Nieuwenhuizen 09dad49b65
m2 lib 2019-10-24 10:45:38 +02:00
Jan Nieuwenhuizen d22f7036d0
simple.make 2019-10-24 09:23:30 +02:00
Jan Nieuwenhuizen df1a1cf505
simple.make 2019-10-24 09:09:20 +02:00
Jan Nieuwenhuizen 820cb6d50d
kaem.run 2019-10-24 09:09:15 +02:00
Jan Nieuwenhuizen 44cd2f132f
m2 lib c 2019-10-24 09:09:08 +02:00
Jan Nieuwenhuizen fcb694be6b
m2: getenv 2019-10-24 07:19:57 +02:00
Jan Nieuwenhuizen 99c1d3df1c
simple.make 2019-10-24 07:19:32 +02:00
Jan Nieuwenhuizen 3f32b479bd
simple.make 2019-10-24 00:12:54 +02:00
Jan Nieuwenhuizen f19d7b78d6
kaem.run: New file.
* kaem.run: New file.
* lib/m2/missing.hex2: New file.
2019-10-24 00:12:53 +02:00
Jan Nieuwenhuizen 5582a673ce
kaem: scaffold/read.kaem. 2019-10-23 23:51:51 +02:00
Jan Nieuwenhuizen fe2d7c7b4f
kaem: scaffold/argv.kaem 2019-10-23 23:51:51 +02:00
Jan Nieuwenhuizen 59c1570c57
kaem: scaffold/hello.kaem. 2019-10-23 23:51:51 +02:00
Jan Nieuwenhuizen ac297d36db
kaem: scaffold/main.kaem. 2019-10-23 23:51:50 +02:00
Jan Nieuwenhuizen 9e0858bb57
REVERTME simple.make: M2 missing symbols 2019-10-23 23:51:50 +02:00
Jan Nieuwenhuizen afeadbb4d7
pointer.sh: headers, inclusief symbols 2019-10-23 23:51:50 +02:00
Jan Nieuwenhuizen ea67ec49af
pointer fix + struct scm* 2019-10-23 18:00:02 +02:00
Jan Nieuwenhuizen 61d6b37d2c
WIP: pointer cells 2019-10-23 18:00:02 +02:00
Jan Nieuwenhuizen 89aecd135b
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.
2019-10-23 18:00:02 +02:00
Jan Nieuwenhuizen 76f739922a
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.
2019-10-23 18:00:02 +02:00
Jan Nieuwenhuizen b43f85869d
core: Prepare for conversion to pointer cells.
* src/posix.c (execl_): Prepare for conversion to pointer cells.
2019-10-23 18:00:02 +02:00
Jan Nieuwenhuizen 630e11422c
build: Add pointer.sh.
* build-aux/pointer.sh: New script.
2019-10-23 18:00:02 +02:00
Jan Nieuwenhuizen 1355801104
core: Remove dead macros.
* include/mes/macros.h (CSTRING_STRUCT, START, LEN): Remove.
2019-10-23 18:00:01 +02:00
Jan Nieuwenhuizen edddad5af6
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.
2019-10-23 18:00:01 +02:00
Jan Nieuwenhuizen 6d2fc8f07c
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.
2019-10-23 18:00:01 +02:00
Jan Nieuwenhuizen 9742f12b90
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.
2019-10-23 18:00:01 +02:00
Jan Nieuwenhuizen 89c3e0bd68
core: Refactor display. 2019-10-23 18:00:01 +02:00
Jan Nieuwenhuizen 99a52a32ed
core: Upcase register names.
* include/mes/mes.h (R0, R1, R2, R3, M0): Rename from lower case.
Update users.
2019-10-23 18:00:01 +02:00
Jan Nieuwenhuizen 9c82a919de
core: Split-out symbols.c.
* src/mes.c (init_symbol, mes_symbols): Move to ..
* src/symbols.c: New file.
* simple.make: Add it.
* src/eval.c (assert_defined): Likewise.
* include/mes/mes.h: Declare init_symbols.
2019-10-23 18:00:01 +02:00
Jan Nieuwenhuizen 8a3691da6c
core: Split-out display.c.
* src/lib.c (display_helper, display_, display_error_, display_port_,
write_, write_error_, write_port_, fdisplay_): Move to ..
* src/display.c: New file.
* simple.make: Add it.
* src/eval.c (assert_defined): Likewise.
2019-10-23 18:00:00 +02:00
Jan Nieuwenhuizen e92bed72c5
core: Split-out eval-apply.c.
* src/mes.c (check_formals, check_apply, pairlis, set_car_x, set_cdr_x,
set_env_x, call_lambda, make_closure_, make_variable_, macro_get_handle,
get_macro, macro_set_x, push_cc, add_formals, formal_p,
expand_variable_, expand_variable, apply_builtin, eval_apply, apply):
Move to ..
* src/eval-apply.c: New file.
* simple.make: Add it.
* src/eval.c (assert_defined): Likewise.
2019-10-23 18:00:00 +02:00
Jan Nieuwenhuizen f84de37e5b
build: Update mes-snarf.
* build-aux/snarf.sh: Support C-style annotations.
2019-10-23 18:00:00 +02:00
Jan Nieuwenhuizen 8129434bfd
mescc: Mes C Library: Add M2-Planet support. WIP
* lib/m2/abtolc.: New file.
* lib/m2/accessc.: New file.
* lib/m2/atoic.: New file.
* lib/m2/chmodc.: New file.
* lib/m2/clock_gettimec.: New file.
* lib/m2/dupc.: New file.
* lib/m2/dup2c.: New file.
* lib/m2/eputsc.: New file.
* lib/m2/execvc.: New file.
* lib/m2/execvec.: New file.
* lib/m2/exitc.: New file.
* lib/m2/fdputcc.: New file.
* lib/m2/forkc.: New file.
* lib/m2/getcwdc.: New file.
* lib/m2/getenvc.: New file.
* lib/m2/isattyc.: New file.
* lib/m2/memchrc.: New file.
* lib/m2/memcmpc.: New file.
* lib/m2/memcpyc.: New file.
* lib/m2/mes_openc.: New file.
* lib/m2/ntoabc.: New file.
* lib/m2/openc.: New file.
* lib/m2/readc.: New file.
* lib/m2/setenvc.: New file.
* lib/m2/strcmpc.: New file.
* lib/m2/strcpyc.: New file.
* lib/m2/strlenc.: New file.
* lib/m2/strncmpc.: New file.
* lib/m2/timec.: New file.
* lib/m2/unlinkc.: New file.
* lib/m2/waitpidc.: New file.
* lib/m2/writec.: New file.
2019-10-23 18:00:00 +02:00
Jan Nieuwenhuizen 998a3fdc15
mescc: Mes C Library: Prepare for M2-Planet: setenv.
* lib/posix/setenv.c: Rewrite C-constructs not supported by M2-Planet.
2019-10-23 17:59:37 +02:00
Jan Nieuwenhuizen c01fb5aa4a
mescc: Mes C Library: Prepare for M2-Planet: getenv.
* lib/posix/getenv.c: Rewrite C-constructs not supported by M2-Planet.
2019-10-23 17:59:37 +02:00
Jan Nieuwenhuizen ade7d6aa42
WIP FIXUP: ntoab 2019-10-23 17:59:37 +02:00
Jan Nieuwenhuizen 2dd3ae31ce
mescc: Mes C Library: Prepare for M2-Planet: ntoab.
* lib/mes/ntoab.c: Rewrite C-constructs not supported by M2-Planet.
2019-10-23 17:59:37 +02:00
Jan Nieuwenhuizen 58e06f1faa
mescc: Mes C Library: Prepare for M2-Planet: malloc.
* lib/stdlib/malloc.c: Rewrite C-constructs not supported by M2-Planet.
2019-10-23 17:59:37 +02:00
Jan Nieuwenhuizen 62ddf437b1
mescc: Mes C Library: Prepare for M2-Planet: fdungetc.
* lib/mes/fdungetc.c: Rewrite C-constructs not supported by M2-Planet.
2019-10-23 17:59:37 +02:00
Jan Nieuwenhuizen 74dbd3c8d0
mescc: Mes C Library: Prepare for M2-Planet: fdgetc.
* lib/mes/fdgetc.c: Rewrite C-constructs not supported by M2-Planet.
2019-10-23 17:59:36 +02:00
Jan Nieuwenhuizen 5994b93df9
mescc: Mes C Library: Prepare for M2-Planet: abtol.
* lib/mes/abtol.c: Rewrite C-constructs not supported by M2-Planet.
2019-10-23 17:59:36 +02:00
Jan Nieuwenhuizen 5bac3f4701
mescc: Mes C Library: Prepare for M2-Planet: memcmp.
* lib/string/memcmp.c: Rewrite C-constructs not supported by M2-Planet.
2019-10-23 17:59:36 +02:00
Jan Nieuwenhuizen 214fd948da
mescc: Mes C Library: Prepare for M2-Planet: memcpy.
* lib/string/memcpy.c: Rewrite C-constructs not supported by M2-Planet.
2019-10-23 17:59:36 +02:00
Jan Nieuwenhuizen 5ab4840e03
mescc: Mes C Library: Prepare for M2-Planet: memchr.
* lib/string/memchr.c: Rewrite C-constructs not supported by M2-Planet.
2019-10-23 17:59:36 +02:00
Jan Nieuwenhuizen f96a548103
mescc: Mes C Library: Prepare for M2-Planet: strncmp.
* lib/string/strncmp.c: Rewrite C-constructs not supported by M2-Planet.
2019-10-23 17:59:36 +02:00
Jan Nieuwenhuizen 3eb5a70ec8
mescc: Mes C Library: Prepare for M2-Planet: strlen.
* lib/string/strlen.c: : Rewrite C-constructs not supported by M2-Planet.
2019-10-23 17:59:36 +02:00
Jan Nieuwenhuizen 38833c9cbf
mescc: Mes C Library: Prepare for M2-Planet: strcpy.
* lib/string/strcpy.c: Rewrite C-constructs not supported by M2-Planet.
2019-10-23 17:59:35 +02:00
Jan Nieuwenhuizen 262ec7f603
mescc: Mes C Library: Prepare for M2-Planet: strcmp.
* lib/string/strcmp.c: Rewrite C-constructs not supported by M2-Planet.
2019-10-23 17:59:35 +02:00
Jan Nieuwenhuizen 6e7313263f
mescc: Mes C Library: Prepare for M2-Planet: __assert_fail.
Rewrite C-constructs not supported by M2-Planet, such as

    foo ? bar : baz;       -> if (foo) bar; else baz;
    static char foo[1024]  -> __func_buf = malloc (1024); ... char *foo = __func_buf;
    *foo                   -> foo[0]
    foo++                  -> foo = foo + 1   TODO: pointer arithmetic
    foo += 1;              -> foo = foo + 1
    for (int foo = ;       -> int foo; for (foo=
    if (foo)               -> if (foo != 0)
    if (!foo)              -> if (foo == 0)
    ;                      -> 0;

* lib/mes/__assert_fail.c: Rewrite C-constructs not supported by
M2-Planet.
2019-10-23 17:59:35 +02:00
Jan Nieuwenhuizen e4e0b3865d
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.
2019-10-23 17:59:35 +02:00
Jan Nieuwenhuizen f4d38292cf
mescc: Mes C Library: Add assert_msg.
* lib/mes/assert_msg.c: New file.
2019-10-23 17:59:35 +02:00
Jan Nieuwenhuizen 99492887a6
core: Prepare for M2-Planet: vector.c.
* src/vector.c: Rewrite C constructs not supported by M2-Planet.
2019-10-23 17:59:35 +02:00
Jan Nieuwenhuizen f72b50071a
core: Prepare for M2-Planet: struct.c.
* src/struct.c: Rewrite C constructs not supported by M2-Planet.
2019-10-23 17:59:35 +02:00
Jan Nieuwenhuizen 0b29b305e7
core: Prepare for M2-Planet: string.c.
* src/string.c: Rewrite C constructs not supported by M2-Planet.
2019-10-23 17:59:34 +02:00
Jan Nieuwenhuizen 50e145e109
core: Prepare for M2-Planet: reader.c.
* src/reader.c: Rewrite C constructs not supported by M2-Planet.
2019-10-23 17:59:34 +02:00
Jan Nieuwenhuizen c53fbf31b6
core: Prepare for M2-Planet: posix.c.
* src/posix.c: Rewrite C constructs not supported by M2-Planet.
2019-10-23 17:59:34 +02:00
Jan Nieuwenhuizen 5cddc8ce78
core: Prepare for M2-Planet: module.c.
* src/module.c: Rewrite C constructs not supported by M2-Planet.
2019-10-23 17:59:34 +02:00
Jan Nieuwenhuizen a7c144b74b
core: Prepare for M2-Planet: math.c.
* src/math.c: Rewrite C constructs not supported by M2-Planet.
2019-10-23 17:59:34 +02:00
Jan Nieuwenhuizen 4cdd2eb059
core: Prepare for M2-Planet: lib.c.
* src/lib.c: Rewrite C constructs not supported by M2-Planet.
2019-10-23 17:59:34 +02:00
Jan Nieuwenhuizen eccf7ab6d4
core: Prepare for M2-Planet: hash.c.
* src/hash.c: Rewrite C constructs not supported by M2-Planet.
2019-10-23 17:59:34 +02:00
Jan Nieuwenhuizen 7dc7ba32b6
core: Prepare for M2-Planet: gc.c.
* src/gc.c: Rewrite C constructs not supported by M2-Planet.
2019-10-23 17:59:33 +02:00
Jan Nieuwenhuizen a37d405863
core: Prepare for M2-Planet: builtins.c.
* src/builtins.c: Rewrite C constructs not supported by M2-Planet.
2019-10-23 17:59:33 +02:00
Jan Nieuwenhuizen c0746b3e79
core: Prepare for M2-Planet: mes.c.
Rewrite C-constructs not supported by M2-Planet, such as

    foo ? bar : baz;       -> if (foo) bar; else baz;
    static char foo[1024]  -> __func_buf = malloc (1024); ... char *foo = __func_buf;
    *foo                   -> foo[0]
    foo++                  -> foo = foo + 1   TODO: pointer arithmetic
    foo += 1;              -> foo = foo + 1
    for (int foo = ;       -> int foo; for (foo=
    if (foo)               -> if (foo != 0)
    if (!foo)              -> if (foo == 0)
    ;                      -> 0;
    // ...                 -> /* ... */

* src/mes.c: Rewrite C constructs not supported by M2-Planet.
* include/mes/mes.h (__execl_c_argv, __getcwd_buf, __open_boot_buf,
__open_boot_file_name, __setenv_buf, __reader_read_char_buf): Declare
buffers.
(init): Initialize them.
* include/mes/macros.h(__M2_PLANET__): Temporary M2 macros.
2019-10-23 17:59:33 +02:00
Jan Nieuwenhuizen 82006f2091
mescc: stack: unbump WIP 2019-10-23 17:59:33 +02:00
Jan Nieuwenhuizen 659113805e
build: Run indent for M2.
* src/gc.c: Indented.
* src/string.c: Likewise.
2019-10-23 17:59:33 +02:00
Jan Nieuwenhuizen d6dbb008bf
build: mes-snarf.scm: Resurrect.
* build-aux/mes-snarf.scm (snarf-functions): Strip whitespace from
parameter list.
(function->source): Use function-scm-name, add (function1_t).
* build-aux/snarf.sh: Resurrect, combined dump to s, h, c.
* include/mes/builtins.h:
2019-10-23 17:59:33 +02:00
Jan Nieuwenhuizen 6ce5ea4ff1
core: Split-out builtins.c.
* src/mes.c make_builtin_type, make_builtin, builtin_name,
builtin_arity, builtin_function, builtin_p, builtin_printer,
init_builtin, mes_builtins): Move to ..
* src/builtins.c: New file.
* build-aux/build-mes.sh (mes_sources): Add it.
* build-aux/snarf.sh: Likewise.
* include/mes/builtins.h: Remove constants.
* include/mes/mes.h: Add prototypes.
* include/mes/constants.h (cell_symbol_test): Rename from cell_test.
* simple.make: New file.
2019-10-23 17:59:32 +02:00
Jan Nieuwenhuizen bcc44bb94f
build: simple.make.
* simple.make: New file.
2019-10-23 17:59:32 +02:00
Jan Nieuwenhuizen dabb424e65
m2: Add scripts/m2-merge.scm.
* scripts/m2-merge.scm.in: New file.
* configure: Substitute it.
* .gitignore: Update.
2019-10-21 21:43:04 +02:00
Jan Nieuwenhuizen 60339608dc
doc update 2019-10-21 21:43:04 +02:00
Jan Nieuwenhuizen 1d1dcdfe40
mescc: Mes C Libray: Fix off_t.
* include/sys/types.h (off_t): Drop unsigned.
2019-10-21 21:43:04 +02:00
Danny Milosavljevic 738264c3bb
Add missing #include.
* lib/stdlib/mbstowcs.c: Add missing #include.
2019-10-21 21:43:04 +02:00
Danny Milosavljevic 30d362321e
Fix dtoab.
* lib/mes/dtoab.c (dtoab): Fix it.
* lib/tests/mes/90-dtoab.c (main): Fix test.
* build-aux/check-mescc.sh (XFAIL_TESTS: Remove it.
2019-10-21 21:43:03 +02:00
Danny Milosavljevic 11542affea
va_align: Fix compiler warning.
Follow-up to 49b0cd7d2e6952044d7436260d6ba950e40ee05f.

* include/stdarg.h: Fix compiler warning.
2019-10-05 17:38:20 +02:00
Danny Milosavljevic fce055e9da
Add missing #include.
* lib/tests/mes/90-abtod.c (main): Add missing #include.
2019-10-05 17:38:20 +02:00
Danny Milosavljevic a840c5398f
Fix variable argument list traversal for doubles.
* include/stdarg.h (va_align): New macro.
(va_arg8): New macro.
* lib/stdio/vfprintf.c (vfprintf): Use it.
* lib/stdio/vsnprintf.c (vsnprintf): Use it.
2019-10-05 17:38:19 +02:00
Jan Nieuwenhuizen 52b9dd2b0e
build: Improve --with-system-libc support.
* build-aux/build-lib.sh: Avoid building libc for --with-system-libc.
Make libmes richer.
build-aux/check-mescc.sh: Enable 50-malloc test.
* include/dirstream.h: Use HAVE_DIRSTREAM_H to cater for non-existing
dirstream.h.
* include/grp.h[SYSTEM_LIBC]: Typo.
* include/mes/lib.h (__brk, __call_at_exit)[SYSTEM_LIBC]: Declare.
* include/stdlib.h (comparison_fn_t)[SYSTEM_LIBC]: Declare.
* include/time.h (mktime): Return time_t.
* lib/posix/isatty.c [SYSTEM_LIBC]: Do not (re)declare termios.
* lib/stub/mktime.c (mktime): Return time_t.
* lib/tests/scaffold/41-ternary.c (main): Remove assumption that
locals are initialized.
* lib/tests/scaffold/70-stdarg.c: Cater for SYSTEM_LIBC.
* lib/tests/setjmp/80-setjmp.c: Declare jmp buf.
* lib/*/*.c: Add missing mes/lib.h, errno.h includes.
2019-10-05 17:38:15 +02:00
Jan Nieuwenhuizen 7181d3dd9a
mescc: Mes C Library: vfprintf, vsnprintf: Pad floats with space.
* lib/stdio/vfprintf.c (vfprintf): Pad floats with space.
* lib/stdio/vsnprintf.c (vsnprintf): Pad floats with space.
* lib/tests/stdio/90-sprintf.c: Test it.
2019-10-05 17:37:28 +02:00
Jan Nieuwenhuizen f4d6851c63
mescc: Mes C Library: vsscanf: Increase count for scanned float.
* lib/stdio/vsscanf.c (vsscanf): Increase count for scanned float.
2019-10-05 17:37:05 +02:00
Jan Nieuwenhuizen 36e9f532be
mescc: Mes C Library: Support GNU Tar: Fix getpwnam, getpwuid stubs.
* lib/stub/getpwnam.c (getpwnam): Return pointer to static struct
passwd.
* lib/stub/getpwuid.c (getpwuid): Likewise.
2019-10-05 17:37:04 +02:00
Jan Nieuwenhuizen eff0077d63
mescc: Mes C Library: Support GNU Tar: Add getgrgid, getgrnam, setgrent stub.
* include/grp.h: New file.
* lib/stub/getgrgid.c: New file.
* lib/stub/getgrnam.c: New file.
* lib/stub/setgrent.c: New file.
* lib/libc+gnu.c: Include them.
2019-10-05 17:37:04 +02:00
Jan Nieuwenhuizen a0efce35a0
mescc: Mes C Library: Support GNU Awk: Add wchar_t.
* include/sys/types.h (wchar_t): New typedef.
2019-10-05 17:37:04 +02:00
Jan Nieuwenhuizen 4cbdc75bb4
mescc: Mes C Library: Support GNU Awk: Add getpgid, getpgrp stubs.
* include/unistd.h (getpgid, getpgrp): Declare.
* lib/stub/getpgid.c: New file.
* lib/stub/getpgrp.c: New file.
* lib/libc+gnu.c: Include them.
2019-10-05 17:37:04 +02:00
Jan Nieuwenhuizen 1f21136539
mescc: Mes C Library: Support GNU Tar: Add mktime stub, fix localtime stub.
* include/time.h (mktime): Declare.
* lib/stub/mktime.c: New stub.
* lib/libc+gnu.c: Include it.
* lib/stub/localtime.c (localtime): Return pointer to static struct
tm.  Avoids segfaults.
2019-10-05 17:37:04 +02:00
Jan Nieuwenhuizen 18adda19fd
mescc: Mes C Library: Support GNU Tar: Add creat, mknod.
* include/linux/x86_64/syscall.h (SYS_mknod): New macro.
* include/linux/x86/syscall.h (SYS_mknod): New macro.
* lib/linux/mknod.c: New file.
* build-aux/configure-lib.sh (libc_gnu_SOURCES): Add it.
* include/sys/stat.h (mknod): Declare it.
* include/fcntl.h (creat): New macro.
2019-10-05 17:37:04 +02:00
Jan Nieuwenhuizen dfdaaa092b
mescc: Mes C Library: Support GNU Tar: Add missing defines.
* include/errno.h (ENXIO): New macro.
* include/sys/stat.h (S_IFIFO, S_ISFIFO): New macro.
2019-10-05 17:37:04 +02:00
Jan Nieuwenhuizen 9d29892750
mescc: Mes C Library: Support GNU Bash: Add struct winsize.
* include/termio.h (struct winsize): New type.
2019-10-05 17:37:03 +02:00
Jan Nieuwenhuizen 8b2e2cebde
mescc: Mes C Library: Support GNU Awk: Implement atof.
* lib/stdlib/atoi.c: Update.
* lib/stdlib/atof.c: Rename from stub/atof.c; Implement.
* lib/libc+gnu.c: Update include.
* lib/libg.c: Update include.
2019-10-05 17:37:03 +02:00
Jan Nieuwenhuizen 92e6a8e323
mescc: Mes C Library: Support GNU Awk: Add dtoab, %f in vfprintf, vsnprintf.
* include/libmes.h (dtoab): Declare.
* lib/mes/ntoab.c (ntoab): Update.
* lib/mes/dtoab.c: New file.
* build-aux/configure-lib.sh (libmes_SOURCES, libc_tcc_SOURCES): Add
it.
* lib/tests/mes/90-dtoab.c: Test it.
* lib/tests/stdio/90-sprintf.c: Test it.
* build-aux/check-mescc.sh (tests): Run it, against...
* lib/tests/mes/90-dtoab.stdout: ...baseline.
* lib/stdio/vfprintf.c (vfprintf): Support %f, even more naive support
for %e, %E, %g, %G.
* lib/stdio/vsnprintf.c (vsnprintf): Likewise.
2019-10-05 17:37:03 +02:00
Jan Nieuwenhuizen 5d40ba08b6
mescc: Mes C Library: Support GNU Awk: Add abtod, implementing strtod.
* include/libmes.h (abtod): Declare.
* lib/mes/abtod.c: New file.
* build-aux/configure-lib.sh (libmes_SOURCES, libc_tcc_SOURCES): Add
it.
* lib/mes/abtol.c: Update.
* lib/stdlib/strtod.c: Use it to implement; move from stub/strtod.
* lib/tests/mes/90-abtod.c: Test it.
* lib/tests/mes/90-abtod.stdout: Baseline.
* build-aux/check-mescc.sh (tests): Run it.
2019-10-05 17:37:03 +02:00
Jan Nieuwenhuizen e7e69fff7b
mescc: Mes C Library: Support GNU Awk: vsscanf: Support %f.
* lib/stdio/vsscanf.c (vsscanf): Support %f.
2019-10-05 17:37:03 +02:00
Jan Nieuwenhuizen 3f74342f36
mescc: Mes C Library: Support GNU Awk: Do not flush std files.
* lib/stdio/fflush.c (fflush): Do not flush std files.
2019-10-05 17:37:03 +02:00
Jan Nieuwenhuizen 5dfe2459c8
mescc: Mes C Library: Support GNU Awk: Add isgraph.
* lib/ctype/isgraph.c: New file.
* lib/libc+gnu.c: Include it.
* include/ctype.h: Add missing prototypes.
2019-10-05 17:37:03 +02:00
Jan Nieuwenhuizen 396b666b38
mescc: Mes C Library: Support GNU Tar: Add readlink, readlink.
* lib/linux/gnu.c (readlink, symlink): New function.
* include/unistd.h (readlink, symlink): Declare.
* include/linux/x86/syscall.h (SYS_readlink, SYS_symlink): New macro.
* include/linux/x86_64/syscall.h (SYS_symlink, SYS_readlink): New
macro.
2019-10-05 17:37:03 +02:00
Jan Nieuwenhuizen 30e931920d
mescc: Mes C Library: Support GNU Tar: Add execlp.
* lib/posix/execl.c (vexec): New function.
(execl): Use it.
* lib/posix/execlp.c: New file.
* build-aux/configure-lib.sh (libc_tcc_SOURCES): Add it.
* lib/libc+gnu.c: Include it.
* include/unistd.h (execlp): Declare.
* lib/tests/posix/90-execlp.c: New file.
* lib/tests/posix/90-execlp.stdout: New file.
* build-aux/check-mescc.sh: Test it.
2019-10-05 17:37:02 +02:00
Jan Nieuwenhuizen aae5f0f578
mescc: Mes C Library: Fix compile warnings.
* include/stdlib.h (abort): Add prototype.
2019-10-05 17:37:02 +02:00
Jan Nieuwenhuizen e086d0456d
mescc: Bump stack. WIP.
* scripts/mescc.in (MES_MAX_ARENA): Also set.
(MES_STACK): Bump to 10000000.
* build-aux/bootstrap.sh.in (MES_STACK): Likewise.  Export them.
2019-10-01 19:21:52 +02:00
Jan Nieuwenhuizen 0c542fe3f6
build: Split-out build-source-lib.sh from build-lib.sh.
* build-aux/build-lib.sh: Remove building of source lib.
* build-aux/build-source-lib.sh: New file.
* build-aux/build.sh.in: Invoke it.
* build-aux/bootstrap.sh.in: Likewise.
2019-10-01 19:21:52 +02:00
Jan Nieuwenhuizen a3a53037c8
build: Avoid tar --exclude=.
* build-aux/install.sh.in: Only use `tar --exclude=' if we also have .go
files compiled by Guile.
2019-10-01 19:21:52 +02:00
Jan Nieuwenhuizen 5492fffe04
build: mesar: Remove bashisms.
* scripts/mesar.in: Remove bashisms.
2019-10-01 19:21:51 +02:00
Jan Nieuwenhuizen 732530d9f9
configure.sh: Cleanup argument parsing. Thanks, Timothy!
* configure.sh: Cleanup argument parsing.
2019-10-01 19:21:51 +02:00
Jan Nieuwenhuizen 5de5853c76
configure.sh: Remove bashisms.
* configure.sh: Remove bashisms.  Fixes running with Gash 0.1.
2019-09-20 19:44:30 +02:00
Jan Nieuwenhuizen 9405075e09
Revert "nyacc: 0.86.0 compatibility stub. WIP"
This reverts commit 0183cc1c42437fda27196e27b490285a61d47f59.

While it works to run Nyacc 0.86.0, it breaks running Nyacc 0.93 and
up.  This would need more thought and work, adding a nyacc-compat
directory or so.  Seems not worth the effort right now.
2019-09-20 19:43:24 +02:00
Jan Nieuwenhuizen 8bed92b7bd
nyacc: 0.86.0 compatibility stub. WIP
* mes/module/nyacc/lang/c99/util.scm: 0.86.0 compatibility stub.
2019-09-20 19:42:50 +02:00
Jan Nieuwenhuizen 2d7c2f9791
doc: Post-release update.
* doc/announce/ANNOUNCE-0.20: Update.
* guix/git/mes.scm (mes): Update.
2019-09-20 19:42:50 +02:00
171 changed files with 7303 additions and 3241 deletions

74
.gitignore vendored
View File

@ -33,32 +33,15 @@
*.mini-hex2 *.mini-hex2
*.a *.a
*.o *.o
*.h.m2
*.c.m2
*.seed-out *.seed-out
*.stderr *.stderr
*.stdout *.stdout
*.x86-out *.x86-out
*.x86-mes-E /TAGS
*.x86-mes-S
*.x86-mes-gcc-a
*.x86-mes-gcc-o
*.x86-mes-gcc-out
*.x86-mes-gcc-stdout
*.x86-mes-o
*.x86-mes-out
*.x86-mes-stdout
*.x86_64-mes-E
*.x86_64-mes-S
*.x86_64-mes-gcc-a
*.x86_64-mes-gcc-o
*.x86_64-mes-gcc-out
*.x86_64-mes-gcc-stdout
*.x86_64-mes-o
*.x86_64-mes-out
*.x86_64-mes-stdout
*.x86_64-out
/lib/x86-mes/0exit-42 /lib/x86-mes/0exit-42
/lib/x86-mes/exit-42 /lib/x86-mes/exit-42
@ -69,58 +52,30 @@
!/lib/tests/*/*.exit !/lib/tests/*/*.exit
!/lib/tests/*/*.stdout !/lib/tests/*/*.stdout
/scaffold/*.M1
/scaffold/*.m2
/scaffold/*.hex2
/scaffold/argv /scaffold/argv
/scaffold/hello /scaffold/hello
/scaffold/main /scaffold/main
/scaffold/micro-mes /scaffold/micro-mes
/scaffold/read
/scaffold/tiny-mes /scaffold/tiny-mes
/scaffold/x86-mes-* /scaffold/argv-m2
/scaffold/x86_64-mes-* /scaffold/hello-m2
/scaffold/main-m2
/scaffold/tests/x86-mes-* /scaffold/micro-mes-m2
/scaffold/tests/[0-9a][0-9a-z]-* /scaffold/read-m2
/scaffold/tests/t.* /scaffold/tiny-mes-m2
!/scaffold/tests/*.c
!/scaffold/tests/*.exit
!/scaffold/tests/*.stdout
/src/mes.mes.symbols.h
/src/gc.mes.h
/src/hash.mes.h
/src/lib.mes.h
/src/math.mes.h
/src/mes.mes.h
/src/module.mes.h
/src/posix.mes.h
/src/reader.mes.h
/src/strings.mes.h
/src/struct.mes.h
/src/vector.mes.h
/src/gc.mes.i
/src/hash.mes.i
/src/lib.mes.i
/src/math.mes.i
/src/mes.mes.i
/src/module.mes.i
/src/posix.mes.i
/src/reader.mes.i
/src/strings.mes.i
/src/struct.mes.i
/src/vector.mes.i
/src/mes /src/mes
/src/x86-mes-mes
/src/x86_64-mes-mes
/.config
/.config.make /.config.make
/.store /.store
/.tarball-version /.tarball-version
#keep this: bootstrap
#/mes.mes
/out
? ?
?.mes ?.mes
\#*# \#*#
@ -147,6 +102,7 @@
/install.sh /install.sh
/uninstall.sh /uninstall.sh
/mes/module/mes/boot-0.scm /mes/module/mes/boot-0.scm
/scripts/m2-merge.scm
/scripts/mesar /scripts/mesar
/scripts/mescc.scm /scripts/mescc.scm
/scripts/mescc /scripts/mescc

View File

@ -20,8 +20,11 @@
LANG= LANG=
MES_ARENA=${MES_ARENA-100000000} MES_ARENA=${MES_ARENA-100000000}
MES_MAX_ARENA=${MES_MAX_ARENA-100000000} export MES_ARENA
MES_STACK=${MES_STACK-500000} MES_MAX_ARENA=${MES_MAX_ARENA-${MES_ARENA}}
export MES_MAX_ARENA
MES_STACK=${MES_STACK-10000000}
export MES_STACK
. build-aux/configure-lib.sh . build-aux/configure-lib.sh
@ -81,3 +84,15 @@ for c in $mes_SOURCES; do
done done
echo "CCLD src/mes" echo "CCLD src/mes"
$CC -nostdlib -o src/mes -L mescc-lib mescc-lib/crt1.o $objects -lc $CC -nostdlib -o src/mes -L mescc-lib mescc-lib/crt1.o $objects -lc
(
mkdir -p gcc-lib
cp config.sh gcc-lib
cd gcc-lib
compiler=gcc
if test -z "$srcdest"; then
srcdest=../
srcdir=../
fi
@SHELL@ ${srcdest}build-aux/build-source-lib.sh
)

View File

@ -79,26 +79,3 @@ cp libgetopt.a $mes_cpu-mes
if test -e libgetopt.s; then if test -e libgetopt.s; then
cp libgetopt.s $mes_cpu-mes cp libgetopt.s $mes_cpu-mes
fi fi
cp ${srcdest}lib/$mes_kernel/$mes_cpu-mes-$compiler/crt*.c $mes_cpu-mes
rm -f libc+gnu.c
cat > libc+gnu.c <<EOF
// Generated from Mes -- do not edit
// compiler: $compiler
// cpu: $mes_cpu
// bits: $mes_bits
// libc: $mes_libc
// kernel: $mes_kernel
// system: $mes_system
EOF
for c in $libc_gnu_SOURCES; do
echo "// $c" >> libc+gnu.c
cat ${srcdest}$c >> libc+gnu.c
echo >> libc+gnu.c
done
cp libc+gnu.c $mes_cpu-mes
cp ${srcdest}lib/libtcc1.c $mes_cpu-mes
cp ${srcdest}lib/posix/getopt.c $mes_cpu-mes/libgetopt.c

View File

@ -35,6 +35,9 @@ trap 'test -f .log && cat .log' EXIT
srcdest=${srcdest-} srcdest=${srcdest-}
mes_sources=" mes_sources="
src/builtins.c
src/display.c
src/eval-apply.c
src/gc.c src/gc.c
src/hash.c src/hash.c
src/lib.c src/lib.c
@ -45,6 +48,7 @@ src/posix.c
src/reader.c src/reader.c
src/string.c src/string.c
src/struct.c src/struct.c
src/symbols.c
src/vector.c src/vector.c
" "

View File

@ -0,0 +1,53 @@
#! /bin/sh
# GNU Mes --- Maxwell Equations of Software
# Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
#
# This file is part of GNU Mes.
#
# GNU Mes is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# GNU Mes is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
set -e
if test "$V" = 2; then
set -x
fi
set -u
srcdest=${srcdest-}
. ${srcdest}build-aux/configure-lib.sh
mkdir -p $mes_cpu-mes
cp ${srcdest}lib/$mes_kernel/$mes_cpu-mes-$compiler/crt*.c $mes_cpu-mes
rm -f libc+gnu.c
cat > libc+gnu.c <<EOF
// Generated from Mes -- do not edit
// compiler: $compiler
// cpu: $mes_cpu
// bits: $mes_bits
// libc: $mes_libc
// kernel: $mes_kernel
// system: $mes_system
EOF
for c in $libc_gnu_SOURCES; do
echo "// $c" >> libc+gnu.c
cat ${srcdest}$c >> libc+gnu.c
echo >> libc+gnu.c
done
cp libc+gnu.c $mes_cpu-mes
cp ${srcdest}lib/libtcc1.c $mes_cpu-mes
cp ${srcdest}lib/posix/getopt.c $mes_cpu-mes/libgetopt.c

View File

@ -87,15 +87,15 @@ export CPPFLAGS
export LDFLAGS export LDFLAGS
export LIBS export LIBS
if test $compiler = gcc; then (
( mkdir -p gcc-lib
mkdir -p gcc-lib cp config.sh gcc-lib
cp config.sh gcc-lib cd gcc-lib
cd gcc-lib if test -z "$srcdest"; then
if test -z "$srcdest"; then srcdest=../
srcdest=../ srcdir=../
srcdir=../ fi
fi if test $compiler = gcc; then
CPPFLAGS=" CPPFLAGS="
-D HAVE_CONFIG_H=1 -D HAVE_CONFIG_H=1
-I include -I include
@ -104,8 +104,9 @@ if test $compiler = gcc; then
" "
${SHELL} ${srcdest}build-aux/build-lib.sh ${SHELL} ${srcdest}build-aux/build-lib.sh
cp crt1.o .. cp crt1.o ..
) fi
fi compiler=gcc ${SHELL} ${srcdest}build-aux/build-source-lib.sh
)
( (
if test $compiler = gcc; then if test $compiler = gcc; then
@ -145,4 +146,5 @@ fi
AR="${srcdest}pre-inst-env mesar" AR="${srcdest}pre-inst-env mesar"
CC="${srcdest}pre-inst-env mescc -m $mes_bits" CC="${srcdest}pre-inst-env mescc -m $mes_bits"
${SHELL} ${srcdest}build-aux/build-lib.sh ${SHELL} ${srcdest}build-aux/build-lib.sh
${SHELL} ${srcdest}build-aux/build-source-lib.sh
) )

View File

@ -27,6 +27,7 @@ tests/boot.test
tests/read.test tests/read.test
tests/srfi-0.test tests/srfi-0.test
tests/macro.test tests/macro.test
tests/gc.test
tests/perform.test tests/perform.test
tests/base.test tests/base.test
tests/quasiquote.test tests/quasiquote.test

View File

@ -200,12 +200,16 @@ if test -z "$bootstrap"; then
TESTS="$TESTS TESTS="$TESTS
lib/tests/dirent/90-readdir.c lib/tests/dirent/90-readdir.c
lib/tests/io/90-stat.c lib/tests/io/90-stat.c
lib/tests/mes/90-abtod.c
lib/tests/mes/90-dtoab.c
lib/tests/posix/90-execlp.c
lib/tests/posix/90-unsetenv.c lib/tests/posix/90-unsetenv.c
lib/tests/signal/90-signal.c lib/tests/signal/90-signal.c
lib/tests/stdio/90-fopen.c lib/tests/stdio/90-fopen.c
lib/tests/stdio/90-fopen-append.c lib/tests/stdio/90-fopen-append.c
lib/tests/stdio/90-fread-fwrite.c lib/tests/stdio/90-fread-fwrite.c
lib/tests/stdio/90-fseek.c lib/tests/stdio/90-fseek.c
lib/tests/stdio/90-sprintf.c
lib/tests/stdlib/90-strtol.c lib/tests/stdlib/90-strtol.c
lib/tests/string/90-snprintf.c lib/tests/string/90-snprintf.c
lib/tests/string/90-strpbrk.c lib/tests/string/90-strpbrk.c
@ -222,7 +226,7 @@ lib/tests/scaffold/a1-global-no-clobber.c
fi fi
XFAIL_TESTS=" XFAIL_TESTS="
lib/tests/stdio/90-sprintf.c lib/tests/mes/90-abtod.c
lib/tests/stdio/90-sprintf.c lib/tests/stdio/90-sprintf.c
" "
@ -232,6 +236,7 @@ lib/tests/scaffold/17-compare-unsigned-char-le.c
lib/tests/scaffold/17-compare-unsigned-short-le.c lib/tests/scaffold/17-compare-unsigned-short-le.c
lib/tests/scaffold/66-local-char-array.c lib/tests/scaffold/66-local-char-array.c
lib/tests/scaffold/72-typedef-struct-def-local.c lib/tests/scaffold/72-typedef-struct-def-local.c
lib/tests/mes/90-dtoab.c
lib/tests/scaffold/90-goto-var.c lib/tests/scaffold/90-goto-var.c
lib/tests/scaffold/91-goto-array.c lib/tests/scaffold/91-goto-array.c
" "
@ -248,11 +253,6 @@ lib/tests/scaffold/a0-call-trunc-int.c
fi fi
fi fi
if test $mes_cpu = x86; then
XFAIL_TESTS="$XFAIL_TESTS
"
fi
if test $mes_cpu = x86_64; then if test $mes_cpu = x86_64; then
XFAIL_TESTS="$XFAIL_TESTS XFAIL_TESTS="$XFAIL_TESTS
lib/tests/stdio/70-printf-stdarg.c lib/tests/stdio/70-printf-stdarg.c
@ -261,10 +261,12 @@ fi
if test $compiler = gcc; then if test $compiler = gcc; then
XFAIL_TESTS="$XFAIL_TESTS XFAIL_TESTS="$XFAIL_TESTS
lib/tests/mes/90-abtod.c
" "
if test $mes_cpu = x86; then if test $mes_cpu = x86; then
XFAIL_TESTS="$XFAIL_TESTS XFAIL_TESTS="$XFAIL_TESTS
lib/tests/mes/90-dtoab.c
" "
fi fi

View File

@ -76,6 +76,7 @@ if test $mes_libc = mes; then
lib/ctype/isdigit.c lib/ctype/isdigit.c
lib/ctype/isspace.c lib/ctype/isspace.c
lib/ctype/isxdigit.c lib/ctype/isxdigit.c
lib/mes/assert_msg.c
lib/posix/write.c lib/posix/write.c
lib/stdlib/atoi.c lib/stdlib/atoi.c
" "
@ -86,6 +87,8 @@ lib/linux/lseek.c
fi fi
else else
libmes_SOURCES="$libmes_SOURCES libmes_SOURCES="$libmes_SOURCES
lib/mes/abtod.c
lib/mes/dtoab.c
" "
fi fi
@ -156,6 +159,8 @@ lib/ctype/islower.c
lib/ctype/isupper.c lib/ctype/isupper.c
lib/ctype/tolower.c lib/ctype/tolower.c
lib/ctype/toupper.c lib/ctype/toupper.c
lib/mes/abtod.c
lib/mes/dtoab.c
lib/mes/search-path.c lib/mes/search-path.c
lib/posix/execvp.c lib/posix/execvp.c
lib/stdio/fclose.c lib/stdio/fclose.c
@ -180,6 +185,7 @@ lib/stdio/vsprintf.c
lib/stdio/vsscanf.c lib/stdio/vsscanf.c
lib/stdlib/calloc.c lib/stdlib/calloc.c
lib/stdlib/qsort.c lib/stdlib/qsort.c
lib/stdlib/strtod.c
lib/stdlib/strtof.c lib/stdlib/strtof.c
lib/stdlib/strtol.c lib/stdlib/strtol.c
lib/stdlib/strtold.c lib/stdlib/strtold.c
@ -199,7 +205,6 @@ lib/stub/ldexp.c
lib/stub/mprotect.c lib/stub/mprotect.c
lib/stub/localtime.c lib/stub/localtime.c
lib/stub/sigemptyset.c lib/stub/sigemptyset.c
lib/stub/strtod.c
lib/$mes_cpu-mes-$compiler/setjmp.c lib/$mes_cpu-mes-$compiler/setjmp.c
" "
@ -217,6 +222,7 @@ lib/ctype/isalnum.c
lib/ctype/isalpha.c lib/ctype/isalpha.c
lib/ctype/isascii.c lib/ctype/isascii.c
lib/ctype/iscntrl.c lib/ctype/iscntrl.c
lib/ctype/isgraph.c
lib/ctype/isprint.c lib/ctype/isprint.c
lib/ctype/ispunct.c lib/ctype/ispunct.c
lib/dirent/__getdirentries.c lib/dirent/__getdirentries.c
@ -227,6 +233,7 @@ lib/math/fabs.c
lib/mes/fdgets.c lib/mes/fdgets.c
lib/posix/alarm.c lib/posix/alarm.c
lib/posix/execl.c lib/posix/execl.c
lib/posix/execlp.c
lib/posix/mktemp.c lib/posix/mktemp.c
lib/posix/raise.c lib/posix/raise.c
lib/posix/sbrk.c lib/posix/sbrk.c
@ -243,6 +250,7 @@ lib/stdlib/abort.c
lib/stdlib/abs.c lib/stdlib/abs.c
lib/stdlib/alloca.c lib/stdlib/alloca.c
lib/stdlib/atexit.c lib/stdlib/atexit.c
lib/stdlib/atof.c
lib/stdlib/atol.c lib/stdlib/atol.c
lib/stdlib/mbstowcs.c lib/stdlib/mbstowcs.c
lib/string/bcmp.c lib/string/bcmp.c
@ -263,14 +271,20 @@ lib/stub/ctime.c
lib/stub/fpurge.c lib/stub/fpurge.c
lib/stub/freadahead.c lib/stub/freadahead.c
lib/stub/frexp.c lib/stub/frexp.c
lib/stub/getgrgid.c
lib/stub/getgrnam.c
lib/stub/getlogin.c lib/stub/getlogin.c
lib/stub/getpgid.c
lib/stub/getpgrp.c
lib/stub/getpwnam.c lib/stub/getpwnam.c
lib/stub/getpwuid.c lib/stub/getpwuid.c
lib/stub/gmtime.c lib/stub/gmtime.c
lib/stub/mktime.c
lib/stub/pclose.c lib/stub/pclose.c
lib/stub/popen.c lib/stub/popen.c
lib/stub/rand.c lib/stub/rand.c
lib/stub/setbuf.c lib/stub/setbuf.c
lib/stub/setgrent.c
lib/stub/setlocale.c lib/stub/setlocale.c
lib/stub/setvbuf.c lib/stub/setvbuf.c
lib/stub/sigaddset.c lib/stub/sigaddset.c
@ -303,14 +317,17 @@ lib/linux/kill.c
lib/linux/link.c lib/linux/link.c
lib/linux/lstat.c lib/linux/lstat.c
lib/linux/mkdir.c lib/linux/mkdir.c
lib/linux/mknod.c
lib/linux/nanosleep.c lib/linux/nanosleep.c
lib/linux/pipe.c lib/linux/pipe.c
lib/linux/readlink.c
lib/linux/rename.c lib/linux/rename.c
lib/linux/setgid.c lib/linux/setgid.c
lib/linux/settimer.c lib/linux/settimer.c
lib/linux/setuid.c lib/linux/setuid.c
lib/linux/signal.c lib/linux/signal.c
lib/linux/sigprogmask.c lib/linux/sigprogmask.c
lib/linux/symlink.c
" "
fi fi

View File

@ -19,3 +19,4 @@
# along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. # along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
for i in $(find . -name '*.c' -o -name '*.h' -o -name '*.i'); do indent $i --no-tabs --line-length 110 --honour-newlines; done for i in $(find . -name '*.c' -o -name '*.h' -o -name '*.i'); do indent $i --no-tabs --line-length 110 --honour-newlines; done
rm -f $(find . -name '*~')

View File

@ -77,13 +77,15 @@ else
cp $_v ChangeLog ${DESTDIR}${docdir} cp $_v ChangeLog ${DESTDIR}${docdir}
fi fi
if test -f module/mescc.go; then
__exclude_go=--exclude='*.go'
__exclude_scm=--exclude='*.scm'
fi
mkdir -p $DESTDIR$libdir mkdir -p $DESTDIR$libdir
mkdir -p $DESTDIR$pkgdatadir mkdir -p $DESTDIR$pkgdatadir
# rm -f $(find lib -type f -a -executable)
# rm -f $(find scaffold -type f -a -executable)
tar -cf- -C ${srcdir} include lib/$mes_cpu-mes | tar -${v}xf- -C $DESTDIR$prefix tar -cf- -C ${srcdir} include lib/$mes_cpu-mes | tar -${v}xf- -C $DESTDIR$prefix
if test -z "$srcdest"; then if test -z "$srcdest"; then
tar -cf- --exclude='*.go' module | tar -${v}xf- -C $DESTDIR$pkgdatadir tar -cf- $__exclude_go module | tar -${v}xf- -C $DESTDIR$pkgdatadir
else else
tar -cf- -C ${srcdest} module | tar -${v}xf- -C $DESTDIR$pkgdatadir tar -cf- -C ${srcdest} module | tar -${v}xf- -C $DESTDIR$pkgdatadir
fi fi
@ -97,8 +99,8 @@ fi
mkdir -p ${DESTDIR}${guile_site_dir} mkdir -p ${DESTDIR}${guile_site_dir}
mkdir -p ${DESTDIR}${guile_site_ccache_dir} mkdir -p ${DESTDIR}${guile_site_ccache_dir}
tar -cf- -C ${srcdest}module --exclude='*.go' . | tar -${v}xf- -C ${DESTDIR}${guile_site_dir} tar -cf- -C ${srcdest}module $__exclude_go . | tar -${v}xf- -C ${DESTDIR}${guile_site_dir}
tar -cf- -C module --exclude='*.scm' . | tar -${v}xf- -C ${DESTDIR}${guile_site_ccache_dir} tar -cf- -C module $__exclude_scm . | tar -${v}xf- -C ${DESTDIR}${guile_site_ccache_dir}
if test -f doc/mes.info; then if test -f doc/mes.info; then
mkdir -p ${DESTDIR}${infodir} mkdir -p ${DESTDIR}${infodir}

View File

@ -4,7 +4,7 @@ exec ${GUILE-guile} --no-auto-compile -L $(dirname $0) -C $(dirname $0) -e '(mes
!# !#
;;; GNU Mes --- Maxwell Equations of Software ;;; GNU Mes --- Maxwell Equations of Software
;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> ;;; Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; ;;;
;;; mes-snarf.scm: This file is part of GNU Mes. ;;; mes-snarf.scm: This file is part of GNU Mes.
;;; ;;;
@ -85,8 +85,7 @@ exec ${GUILE-guile} --no-auto-compile -L $(dirname $0) -C $(dirname $0) -e '(mes
(cut string-replace-string <> "_to_" "->") (cut string-replace-string <> "_to_" "->")
(cut string-replace-suffix <> "_x" "!") (cut string-replace-suffix <> "_x" "!")
(cut string-replace-suffix <> "_x_" "!-") (cut string-replace-suffix <> "_x_" "!-")
(cut string-replace-suffix <> "_p" "?") (cut string-replace-suffix <> "_p" "?"))
)
(function.name f)))) (function.name f))))
(if (not (string-suffix? "-" name)) name (if (not (string-suffix? "-" name)) name
(string-append "core:" (string-drop-right name 1)))))) (string-append "core:" (string-drop-right name 1))))))
@ -117,7 +116,7 @@ exec ${GUILE-guile} --no-auto-compile -L $(dirname $0) -C $(dirname $0) -e '(mes
(if (string-null? (function.formals f)) 0 (if (string-null? (function.formals f)) 0
(length (string-split (function.formals f) #\,))))) (length (string-split (function.formals f) #\,)))))
(n (if (eq? arity 'n) -1 arity))) (n (if (eq? arity 'n) -1 arity)))
(format #f " a = init_builtin (builtin_type, ~s, ~a, &~a, a);\n" (function.name f) n (function.name f)))) (format #f " a = init_builtin (builtin_type, ~s, ~a, &~a, a);\n" (function-scm-name f) n (function.name f))))
(define (disjoin . predicates) (define (disjoin . predicates)
(lambda (. arguments) (lambda (. arguments)
@ -150,9 +149,16 @@ exec ${GUILE-guile} --no-auto-compile -L $(dirname $0) -C $(dirname $0) -e '(mes
(not (string-prefix? "/" function)) (not (string-prefix? "/" function))
rest rest
(receive (parameter-list annotation) (receive (parameter-list annotation)
(apply values (string-split-string rest " ///")) (apply values (string-split-string rest " /*:"))
(let* ((parameters (string-drop parameter-list 1)) (let* ((parameters (string-trim-both parameter-list))
(parameters (string-drop parameters 1))
(parameters (string-drop-right parameters 1)) (parameters (string-drop-right parameters 1))
(annotation (if (string? annotation) (string-trim-both annotation)
annotation))
(annotation (if (and (string? annotation)
(string-suffix? "*/" annotation))
(string-drop-right annotation 2)
annotation))
(formals (if (string-null? parameters) '() (formals (if (string-null? parameters) '()
(string-split parameters #\,))) (string-split parameters #\,)))
(formals (map string-trim formals))) (formals (map string-trim formals)))

60
build-aux/pointer.sh Executable file
View File

@ -0,0 +1,60 @@
#! /bin/sh
set -x
ptr_once='s,([^N])(MACRO|NAME|VALUE) \(([^()]*)\),\1\3->\L\2,'
ptr_once='s,([^N])(BYTES|CAR|CDR|CLOSURE|CONTINUATION|LENGTH|MACRO|NAME|PORT|REF|STRING|STRUCT|TYPE|VALUE|VARIABLE|VECTOR) \(([^()]*)\),\1\3->\L\2,'
n_once='s,N(TYPE|CAR|CDR|LENGTH|VECTOR) \(([^()]*)\),\2->\L\1,'
ncbytes='s,NC(BYTES) \(([^()]*)\),news_\L\1 (\2),'
cbytes='s,([^N])C(BYTES) \(([^()]*)\),\1cell_\L\2 (\3),'
cstring='s,C(STRING) \(([^()]*)\),cell_bytes (STRING (\2)),'
struct='s,SCM,struct scm*,g'
sed -ri \
-e 's,#define POINTER_CELLS 0,#define POINTER_CELLS 1', \
-e "$ncbytes" \
-e "$cbytes" \
-e "$cstring" \
\
-e "$ncbytes" \
-e "$cbytes" \
-e "$cstring" \
\
-e "$ptr_once" \
-e "$ptr_once" \
-e "$ptr_once" \
-e 's,->\<struct\>,->structure,g' \
-e "$struct" \
\
-e "$n_once" \
-e "$n_once" \
\
-e 's,CAR \(([^()]*)\),\1->cdr,' \
-e 's,CAAR \(([^()]*)\),\1->car->car,' \
-e 's,CADR \(([^()]*)\),\1->cdr->car,' \
-e 's,CDAR \(([^()]*)\),\1->car->cdr,' \
-e 's,CDDR \(([^()]*)\),\1->cdr->cdr,' \
-e 's,CADAR \(([^()]*)\),\1->car->cdr->car,' \
-e 's,CADDR \(([^()]*)\),\1->cdr->cdr->car,' \
-e 's,CDDDR \(([^()]*)\),\1->cdr->cdr->cdr,' \
-e 's,CDADAR \(([^()]*)\),\1->cdr->car->cdr->car,' \
\
include/mes/builtins.h \
include/mes/mes.h \
include/mes/symbols.h \
include/mes/builtins.h \
src/builtins.c \
src/display.c \
src/eval-apply.c \
src/gc.c \
src/hash.c \
src/lib.c \
src/math.c \
src/mes.c \
src/module.c \
src/posix.c \
src/reader.c \
src/string.c \
src/struct.c \
src/symbols.c \
src/vector.c

View File

@ -1,7 +1,7 @@
#! /bin/sh #! /bin/sh
# GNU Mes --- Maxwell Equations of Software # GNU Mes --- Maxwell Equations of Software
# Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> # Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
# #
# This file is part of GNU Mes. # This file is part of GNU Mes.
# #
@ -20,17 +20,41 @@
set -e set -e
. ${srcdest}build-aux/config.sh srcdest=${srcdest-./}
. ${srcdest}config.sh
. ${srcdest}build-aux/trace.sh . ${srcdest}build-aux/trace.sh
trace "SNARF$snarf gc.c" ${srcdest}build-aux/mes-snarf.scm src/gc.c trace "SNARF$snarf builtins.c" ${srcdest}build-aux/mes-snarf.scm src/builtins.c
trace "SNARF$snarf hash.c" ${srcdest}build-aux/mes-snarf.scm src/hash.c trace "SNARF$snarf display.c" ${srcdest}build-aux/mes-snarf.scm src/display.c
trace "SNARF$snarf lib.c" ${srcdest}build-aux/mes-snarf.scm src/lib.c trace "SNARF$snarf eval-apply.c" ${srcdest}build-aux/mes-snarf.scm src/eval-apply.c
trace "SNARF$snarf math.c" ${srcdest}build-aux/mes-snarf.scm src/math.c trace "SNARF$snarf gc.c" ${srcdest}build-aux/mes-snarf.scm src/gc.c
trace "SNARF$snarf mes.c" ${srcdest}build-aux/mes-snarf.scm src/mes.c trace "SNARF$snarf hash.c" ${srcdest}build-aux/mes-snarf.scm src/hash.c
trace "SNARF$snarf module.c" ${srcdest}build-aux/mes-snarf.scm src/module.c trace "SNARF$snarf lib.c" ${srcdest}build-aux/mes-snarf.scm src/lib.c
trace "SNARF$snarf posix.c" ${srcdest}build-aux/mes-snarf.scm src/posix.c trace "SNARF$snarf math.c" ${srcdest}build-aux/mes-snarf.scm src/math.c
trace "SNARF$snarf reader.c" ${srcdest}build-aux/mes-snarf.scm src/reader.c trace "SNARF$snarf mes.c" ${srcdest}build-aux/mes-snarf.scm src/mes.c
trace "SNARF$snarf strings.c" ${srcdest}build-aux/mes-snarf.scm src/string.c trace "SNARF$snarf module.c" ${srcdest}build-aux/mes-snarf.scm src/module.c
trace "SNARF$snarf struct.c" ${srcdest}build-aux/mes-snarf.scm src/struct.c trace "SNARF$snarf posix.c" ${srcdest}build-aux/mes-snarf.scm src/posix.c
trace "SNARF$snarf vector.c" ${srcdest}build-aux/mes-snarf.scm src/vector.c trace "SNARF$snarf reader.c" ${srcdest}build-aux/mes-snarf.scm src/reader.c
trace "SNARF$snarf strings.c" ${srcdest}build-aux/mes-snarf.scm src/string.c
trace "SNARF$snarf struct.c" ${srcdest}build-aux/mes-snarf.scm src/struct.c
trace "SNARF$snarf symbols.c" ${srcdest}build-aux/mes-snarf.scm src/symbols.c
trace "SNARF$snarf vector.c" ${srcdest}build-aux/mes-snarf.scm src/vector.c
for i in src/*.symbols.h; do
n=$(basename $i .symbols.h)
echo "/* src/$n.c */"
cat $i
mv $i $(basename $i .symbols.h).s
done > s
for i in src/*.h; do
n=$(basename $i .h)
echo "/* src/$n.c */"
cat $i
done > h
for i in src/*.i; do
n=$(basename $i .i)
echo " /* src/$n.c */"
cat $i
done > c

2
configure vendored
View File

@ -632,11 +632,13 @@ See \"Porting GNU Mes\" in the manual, or try --with-courage\n" mes-system)
"build-aux/install.sh.in" "build-aux/install.sh.in"
"build-aux/pre-inst-env.in" "build-aux/pre-inst-env.in"
"build-aux/uninstall.sh.in" "build-aux/uninstall.sh.in"
"scripts/m2-merge.scm.in"
"scripts/mesar.in" "scripts/mesar.in"
"scripts/mescc.scm.in" "scripts/mescc.scm.in"
"scripts/mescc.in" "scripts/mescc.in"
)) ))
(chmod "pre-inst-env" #o755) (chmod "pre-inst-env" #o755)
(chmod "scripts/m2-merge.scm" #o755)
(chmod "scripts/mesar" #o755) (chmod "scripts/mesar" #o755)
(chmod "scripts/mescc" #o755) (chmod "scripts/mescc" #o755)
(chmod "scripts/mescc.scm" #o755) (chmod "scripts/mescc.scm" #o755)

View File

@ -24,65 +24,35 @@ VERSION=0.20
srcdir=${srcdir-$(dirname $0)} srcdir=${srcdir-$(dirname $0)}
. ${srcdest}build-aux/trace.sh . ${srcdest}build-aux/trace.sh
# parse --with-system-libc # parse arguments
cmdline=$(echo " $@") while [ $# -gt 0 ]; do
p=${cmdline/ --with-system-libc/} case $1 in
if test "$p" != "$cmdline"; then (--with-courage)
mes_libc=${mes_libc-system} courageous=true
else ;;
mes_libc=mes (--with-system-libc)
fi mes_libc=system
;;
(--build=*)
build=${1#--build=}
;;
(--host=*)
host=${1#--host=}
;;
(--prefix=*)
prefix=${1#--prefix=}
;;
(--program-prefix=*)
program_prefix=${1#--program-prefix=}
;;
esac
shift
done
# parse --with-courage prefix=${prefix-/usr/local}
cmdline=$(echo " $@") mes_libc=${mes_libc-mes}
p=${cmdline/ --with-courage/} courageous=${courageous-false}
if test "$p" != "$cmdline"; then host=${host-$build}
courageous=true
else
courageous=false
fi
# parse --prefix=PREFIX
p=${cmdline/ --prefix=/ -prefix=}
if test "$p" != "$cmdline"; then
p=${p##* -prefix=}
p=${p% *}
p=${p% -*}
prefix=${p-/usr/local}
else
prefix=${prefix-/usr/local}
fi
# parse --build=BUILD
p=${cmdline/ --build=/ -build=}
if [ "$p" != "$cmdline" ]; then
p=${p##* -build=}
p=${p% *}
p=${p% -*}
build=${p-$build}
else
build=$build
fi
# parse --host=HOST
p=${cmdline/ --host=/ -host=}
if [ "$p" != "$cmdline" ]; then
p=${p##* -host=}
p=${p% *}
p=${p% -*}
host=${p-$build}
elif test -n "$build"; then
host=${host-$build}
fi
# parse --program-prefix=
p=${cmdline/ --program-prefix=/ -program-prefix=}
if test "$p" != "$cmdline"; then
p=${p##* -program-prefix=}
p=${p% *}
p=${p% -*}
program_prefix=$p
fi
AR=${AR-$(command -v ar)} || true AR=${AR-$(command -v ar)} || true
BASH=${BASH-$(command -v bash)} BASH=${BASH-$(command -v bash)}

View File

@ -7,7 +7,9 @@ We are pleased to announce the release of GNU Mes 0.20, representing
147 commits over 38 weeks. 147 commits over 38 weeks.
Mes has now brought the Reduced Binary Seed bootstrap to Guix (bootstrap Mes has now brought the Reduced Binary Seed bootstrap to Guix (bootstrap
a GNU/Linux system without binary GNU toolchain or equivalent). a GNU/Linux system without binary GNU toolchain or equivalent). It
should land in Guix master any day now: a big thank you to everyone who
helped, notably Ludovic and Mark.
This release is a step towards the upcoming Scheme-only bootstrap and This release is a step towards the upcoming Scheme-only bootstrap and
bringing Mes into NixOS and Debian. This effort is now sponsored by bringing Mes into NixOS and Debian. This effort is now sponsored by
@ -67,8 +69,8 @@ Packages are available in Guix master.
Here are the MD5 and SHA1 checksums: Here are the MD5 and SHA1 checksums:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx mes-0.20.tar.gz df839a83e4a2ad6c2a4accc5bf17b1a7 mes-0.20.tar.gz
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx mes-0.20.tar.gz 38d4cb3fa28fa1f5fc57fea9e046d4d8052bbb8c mes-0.20.tar.gz
[*] Use a .sig file to verify that the corresponding file (without the [*] Use a .sig file to verify that the corresponding file (without the
.sig suffix) is intact. First, be sure to download both the .sig file .sig suffix) is intact. First, be sure to download both the .sig file
@ -83,6 +85,11 @@ Packages are available in Guix master.
and rerun the 'gpg --verify' command. and rerun the 'gpg --verify' command.
* Get informed, get involved
See https://bootstrappable.org
Join #bootstrappable on irc.freenode.net.
* Changes in 0.20 since 0.19 * Changes in 0.20 since 0.19
** Core ** Core
*** The build system has been simplified, again. *** The build system has been simplified, again.
@ -108,6 +115,9 @@ Packages are available in Guix master.
*** string->number now support #x hex-prefix. *** string->number now support #x hex-prefix.
*** ungetc now has a buffer per file handle. *** ungetc now has a buffer per file handle.
Greetings,
janneke and Danny.
[0] https://www.gnu.org/software/mes [0] https://www.gnu.org/software/mes
[1] http://joyofsource.com/reduced-binary-seed-bootstrap.html [1] http://joyofsource.com/reduced-binary-seed-bootstrap.html
[2] https://www.gnu.org/software/guix [2] https://www.gnu.org/software/guix
@ -119,5 +129,5 @@ Packages are available in Guix master.
[8] https://www.nongnu.org/nyacc [8] https://www.nongnu.org/nyacc
[9] https://gitlab.com/janneke/tinycc [9] https://gitlab.com/janneke/tinycc
[10] http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf [10] http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf
[11] https://github.com/oriansj/stage0 [11] https://savannah.nongnu.org/projects/stage0
[12] https://nlnet.nl/project/GNUMes [12] https://nlnet.nl/project/GNUMes

View File

@ -131,7 +131,7 @@ extensive examples, including parsers for the Javascript and C99 languages.")
(uri (string-append (uri (string-append
"https://ftp.gnu.org/pub/gnu/mes/mes-" version ".tar.gz")) "https://ftp.gnu.org/pub/gnu/mes/mes-" version ".tar.gz"))
(sha256 (sha256
(base32 #!mes!# "06qkwkahcpzk5v4qydpvcvzm7lx8g8pflc48f9l7bpjz6hl5lk4s")))) (base32 #!mes!# "04pajp8v31na34ls4730ig5f6miiplhdvkmsb9ls1b8bbmw2vb4n"))))
(build-system gnu-build-system) (build-system gnu-build-system)
(supported-systems '("i686-linux" "x86_64-linux")) (supported-systems '("i686-linux" "x86_64-linux"))
(propagated-inputs (propagated-inputs

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -35,6 +35,7 @@ int isalpha (int c);
int isascii (int c); int isascii (int c);
int iscntrl (int c); int iscntrl (int c);
int isdigit (int c); int isdigit (int c);
int isgraph (int c);
int islower (int c); int islower (int c);
int isnumber (int c, int base); int isnumber (int c, int base);
int isprint (int c); int isprint (int c);

View File

@ -38,14 +38,16 @@ int errno;
#define ENOENT 2 #define ENOENT 2
#define EINTR 4 #define EINTR 4
#define EIO 5 #define EIO 5
#define ENXIO 6
#define E2BIG 7 #define E2BIG 7
#define ENOEXEC 8 #define ENOEXEC 8
#define EBADF 9 #define EBADF 9
#define ECHILD 10 #define ECHILD 10
#define EAGAIN 11 #define EAGAIN 11
#define ENOMEM 12 #define ENOMEM 12
#define EACCES 13 #define EACCES 13
#define EEXIST 17 #define EEXIST 17
#define EXDEV 18
#define ENOTDIR 20 #define ENOTDIR 20
#define EISDIR 21 #define EISDIR 21
#define EINVAL 22 #define EINVAL 22

View File

@ -48,6 +48,7 @@
#define F_GETFL 3 #define F_GETFL 3
#define F_SETFL 4 #define F_SETFL 4
#define creat(file_name, mode) open (file_name, O_WRONLY | O_CREAT | O_TRUNC, mode)
int dup (int old); int dup (int old);
int dup2 (int old, int new); int dup2 (int old, int new);
int fcntl (int filedes, int command, ...); int fcntl (int filedes, int command, ...);

View File

@ -20,24 +20,43 @@
#ifndef __MES_LINUX_X86_SYSCALL_H #ifndef __MES_LINUX_X86_SYSCALL_H
#define __MES_LINUX_X86_SYSCALL_H 1 #define __MES_LINUX_X86_SYSCALL_H 1
// libc-mini /* libc-mini */
// #define SYS_exit 0x01 #ifndef SYS_exit
// #define SYS_write 0x04 // CONSTANT SYS_exit 0x01
#define SYS_exit 0x01
#endif
#ifndef SYS_write
// CONSTANT SYS_write 0x04
#define SYS_write 0x04
#endif
// libc /* libc */
// CONSTANT SYS_fork 0x02
#define SYS_fork 0x02 #define SYS_fork 0x02
// CONSTANT SYS_read 0x03
#define SYS_read 0x03 #define SYS_read 0x03
// CONSTANT SYS_open 0x05
#define SYS_open 0x05 #define SYS_open 0x05
// CONSTANT SYS_waitpid 0x07
#define SYS_waitpid 0x07 #define SYS_waitpid 0x07
// CONSTANT SYS_wait4 0x72
#define SYS_wait4 0x72 #define SYS_wait4 0x72
// CONSTANT SYS_execve 0x0b
#define SYS_execve 0x0b #define SYS_execve 0x0b
// CONSTANT SYS_chmod 0x0f
#define SYS_chmod 0x0f #define SYS_chmod 0x0f
// CONSTANT SYS_access 0x21
#define SYS_access 0x21 #define SYS_access 0x21
// CONSTANT SYS_brk 0x2d
#define SYS_brk 0x2d #define SYS_brk 0x2d
// CONSTANT SYS_ioctl 0x36
#define SYS_ioctl 0x36 #define SYS_ioctl 0x36
// CONSTANT SYS_fsync 0x76
#define SYS_fsync 0x76 #define SYS_fsync 0x76
// CONSTANT SYS_getcwd 0xb7
#define SYS_getcwd 0xb7
// libc+tcc /* libc+tcc */
#define SYS_close 0x06 #define SYS_close 0x06
#define SYS_time 0x0d #define SYS_time 0x0d
#define SYS_lseek 0x13 #define SYS_lseek 0x13
@ -45,9 +64,8 @@
#define SYS_rmdir 0x28 #define SYS_rmdir 0x28
#define SYS_gettimeofday 0x4e #define SYS_gettimeofday 0x4e
#define SYS_stat 0x6a #define SYS_stat 0x6a
#define SYS_getcwd 0xb7
// libc+gnu /* libc+gnu */
#define SYS_chdir 0x0c #define SYS_chdir 0x0c
#define SYS_link 0x09 #define SYS_link 0x09
@ -73,14 +91,19 @@
#define SYS_getdents 0x8d #define SYS_getdents 0x8d
#define SYS_clock_gettime 0x109 #define SYS_clock_gettime 0x109
// bash /* bash */
#define SYS_setuid 0x17 #define SYS_setuid 0x17
#define SYS_geteuid 0x31 #define SYS_geteuid 0x31
#define SYS_getegid 0x32 #define SYS_getegid 0x32
#define SYS_setgid 0x3e #define SYS_setgid 0x3e
#define SYS_getppid 0x40 #define SYS_getppid 0x40
// make+POSIX /* make+POSIX */
#define SYS_sigprocmask 0x7e #define SYS_sigprocmask 0x7e
#endif // __MES_LINUX_X86_SYSCALL_H /* tar */
#define SYS_symlink 0x53
#define SYS_readlink 0x55
#define SYS_mknod 0x0e
#endif /* __MES_LINUX_X86_SYSCALL_H */

View File

@ -80,4 +80,9 @@
// make+SYSTEM_LIBC // make+SYSTEM_LIBC
#define SYS_rt_sigprocmask 0x0e #define SYS_rt_sigprocmask 0x0e
// tar
#define SYS_symlink 0x58
#define SYS_readlink 0x59
#define SYS_mknod 0x85
#endif // __MES_LINUX_X86_64_SYSCALL_H #endif // __MES_LINUX_X86_64_SYSCALL_H

View File

@ -21,10 +21,31 @@
#ifndef __MES_BUILTINS_H #ifndef __MES_BUILTINS_H
#define __MES_BUILTINS_H #define __MES_BUILTINS_H
// src/gc.mes /* src/builtins.c */
SCM make_builtin (SCM builtin_type, SCM name, SCM arity, SCM function);
SCM builtin_name (SCM builtin);
SCM builtin_arity (SCM builtin);
SCM builtin_p (SCM x);
SCM builtin_printer (SCM builtin);
/* src/display.c */
SCM display_ (SCM x);
SCM display_error_ (SCM x);
SCM display_port_ (SCM x, SCM p);
SCM write_ (SCM x);
SCM write_error_ (SCM x);
SCM write_port_ (SCM x, SCM p);
/* src/eval-apply.c */
SCM pairlis (SCM x, SCM y, SCM a);
SCM set_car_x (SCM x, SCM e);
SCM set_cdr_x (SCM x, SCM e);
SCM set_env_x (SCM x, SCM e, SCM a);
SCM macro_get_handle (SCM name);
SCM add_formals (SCM formals, SCM x);
SCM eval_apply ();
/* src/gc.c */
SCM gc_check (); SCM gc_check ();
SCM gc (); SCM gc ();
// src/hash.mes /* src/hash.c */
SCM hashq (SCM x, SCM size); SCM hashq (SCM x, SCM size);
SCM hash (SCM x, SCM size); SCM hash (SCM x, SCM size);
SCM hashq_get_handle (SCM table, SCM key, SCM dflt); SCM hashq_get_handle (SCM table, SCM key, SCM dflt);
@ -34,14 +55,7 @@ SCM hashq_set_x (SCM table, SCM key, SCM value);
SCM hash_set_x (SCM table, SCM key, SCM value); SCM hash_set_x (SCM table, SCM key, SCM value);
SCM hash_table_printer (SCM table); SCM hash_table_printer (SCM table);
SCM make_hash_table (SCM x); SCM make_hash_table (SCM x);
// src/lib.mes /* src/lib.c */
SCM procedure_name_ (SCM x);
SCM display_ (SCM x);
SCM display_error_ (SCM x);
SCM display_port_ (SCM x, SCM p);
SCM write_ (SCM x);
SCM write_error_ (SCM x);
SCM write_port_ (SCM x, SCM p);
SCM exit_ (SCM x); SCM exit_ (SCM x);
SCM frame_printer (SCM frame); SCM frame_printer (SCM frame);
SCM make_stack (SCM stack); SCM make_stack (SCM stack);
@ -52,7 +66,9 @@ SCM memq (SCM x, SCM a);
SCM equal2_p (SCM a, SCM b); SCM equal2_p (SCM a, SCM b);
SCM last_pair (SCM x); SCM last_pair (SCM x);
SCM pair_p (SCM x); SCM pair_p (SCM x);
// src/math.mes SCM char_to_integer (SCM x);
SCM integer_to_char (SCM x);
/* src/math.mes */
SCM greater_p (SCM x); SCM greater_p (SCM x);
SCM less_p (SCM x); SCM less_p (SCM x);
SCM is_p (SCM x); SCM is_p (SCM x);
@ -66,12 +82,11 @@ SCM logior (SCM x);
SCM lognot (SCM x); SCM lognot (SCM x);
SCM logxor (SCM x); SCM logxor (SCM x);
SCM ash (SCM n, SCM count); SCM ash (SCM n, SCM count);
// src/mes.mes /* src/mes.c */
SCM make_cell_ (SCM type, SCM car, SCM cdr); SCM make_cell_ (SCM type, SCM car, SCM cdr);
SCM type_ (SCM x); SCM type_ (SCM x);
SCM car_ (SCM x); SCM car_ (SCM x);
SCM cdr_ (SCM x); SCM cdr_ (SCM x);
SCM arity_ (SCM x);
SCM cons (SCM x, SCM y); SCM cons (SCM x, SCM y);
SCM car (SCM x); SCM car (SCM x);
SCM cdr (SCM x); SCM cdr (SCM x);
@ -85,264 +100,20 @@ SCM error (SCM key, SCM x);
SCM append2 (SCM x, SCM y); SCM append2 (SCM x, SCM y);
SCM append_reverse (SCM x, SCM y); SCM append_reverse (SCM x, SCM y);
SCM reverse_x_ (SCM x, SCM t); SCM reverse_x_ (SCM x, SCM t);
SCM pairlis (SCM x, SCM y, SCM a);
SCM call (SCM fn, SCM x);
SCM assq (SCM x, SCM a); SCM assq (SCM x, SCM a);
SCM assoc (SCM x, SCM a); SCM assoc (SCM x, SCM a);
SCM set_car_x (SCM x, SCM e); SCM set_car_x (SCM x, SCM e);
SCM set_cdr_x (SCM x, SCM e); SCM set_cdr_x (SCM x, SCM e);
SCM set_env_x (SCM x, SCM e, SCM a); SCM set_env_x (SCM x, SCM e, SCM a);
SCM macro_get_handle (SCM name);
SCM add_formals (SCM formals, SCM x); SCM add_formals (SCM formals, SCM x);
SCM eval_apply (); SCM eval_apply ();
SCM make_builtin_type (); /* src/module.c */
SCM make_builtin (SCM builtin_type, SCM name, SCM arity, SCM function);
SCM builtin_arity (SCM builtin);
SCM builtin_p (SCM x);
SCM builtin_printer (SCM builtin);
// CONSTANT cell_nil 1
#define cell_nil 1
// CONSTANT cell_f 2
#define cell_f 2
// CONSTANT cell_t 3
#define cell_t 3
// CONSTANT cell_dot 4
#define cell_dot 4
// CONSTANT cell_arrow 5
#define cell_arrow 5
// CONSTANT cell_undefined 6
#define cell_undefined 6
// CONSTANT cell_unspecified 7
#define cell_unspecified 7
// CONSTANT cell_closure 8
#define cell_closure 8
// CONSTANT cell_circular 9
#define cell_circular 9
// CONSTANT cell_begin 10
#define cell_begin 10
// CONSTANT cell_call_with_current_continuation 11
#define cell_call_with_current_continuation 11
// CONSTANT cell_vm_apply 12
#define cell_vm_apply 12
// CONSTANT cell_vm_apply2 13
#define cell_vm_apply2 13
// CONSTANT cell_vm_begin 14
#define cell_vm_begin 14
// CONSTANT cell_vm_begin_eval 15
#define cell_vm_begin_eval 15
// CONSTANT cell_vm_begin_expand 16
#define cell_vm_begin_expand 16
// CONSTANT cell_vm_begin_expand_eval 17
#define cell_vm_begin_expand_eval 17
// CONSTANT cell_vm_begin_expand_macro 18
#define cell_vm_begin_expand_macro 18
// CONSTANT cell_vm_begin_expand_primitive_load 19
#define cell_vm_begin_expand_primitive_load 19
// CONSTANT cell_vm_begin_primitive_load 20
#define cell_vm_begin_primitive_load 20
// CONSTANT cell_vm_begin_read_input_file 21
#define cell_vm_begin_read_input_file 21
// CONSTANT cell_vm_call_with_current_continuation2 22
#define cell_vm_call_with_current_continuation2 22
// CONSTANT cell_vm_call_with_values2 23
#define cell_vm_call_with_values2 23
// CONSTANT cell_vm_eval 24
#define cell_vm_eval 24
// CONSTANT cell_vm_eval2 25
#define cell_vm_eval2 25
// CONSTANT cell_vm_eval_check_func 26
#define cell_vm_eval_check_func 26
// CONSTANT cell_vm_eval_define 27
#define cell_vm_eval_define 27
// CONSTANT cell_vm_eval_macro_expand_eval 28
#define cell_vm_eval_macro_expand_eval 28
// CONSTANT cell_vm_eval_macro_expand_expand 29
#define cell_vm_eval_macro_expand_expand 29
// CONSTANT cell_vm_eval_pmatch_car 30
#define cell_vm_eval_pmatch_car 30
// CONSTANT cell_vm_eval_pmatch_cdr 31
#define cell_vm_eval_pmatch_cdr 31
// CONSTANT cell_vm_eval_set_x 32
#define cell_vm_eval_set_x 32
// CONSTANT cell_vm_evlis 33
#define cell_vm_evlis 33
// CONSTANT cell_vm_evlis2 34
#define cell_vm_evlis2 34
// CONSTANT cell_vm_evlis3 35
#define cell_vm_evlis3 35
// CONSTANT cell_vm_if 36
#define cell_vm_if 36
// CONSTANT cell_vm_if_expr 37
#define cell_vm_if_expr 37
// CONSTANT cell_vm_macro_expand 38
#define cell_vm_macro_expand 38
// CONSTANT cell_vm_macro_expand_car 39
#define cell_vm_macro_expand_car 39
// CONSTANT cell_vm_macro_expand_cdr 40
#define cell_vm_macro_expand_cdr 40
// CONSTANT cell_vm_macro_expand_define 41
#define cell_vm_macro_expand_define 41
// CONSTANT cell_vm_macro_expand_define_macro 42
#define cell_vm_macro_expand_define_macro 42
// CONSTANT cell_vm_macro_expand_lambda 43
#define cell_vm_macro_expand_lambda 43
// CONSTANT cell_vm_macro_expand_set_x 44
#define cell_vm_macro_expand_set_x 44
// CONSTANT cell_vm_return 45
#define cell_vm_return 45
// CONSTANT cell_symbol_dot 46
#define cell_symbol_dot 46
// CONSTANT cell_symbol_lambda 47
#define cell_symbol_lambda 47
// CONSTANT cell_symbol_begin 48
#define cell_symbol_begin 48
// CONSTANT cell_symbol_if 49
#define cell_symbol_if 49
// CONSTANT cell_symbol_quote 50
#define cell_symbol_quote 50
// CONSTANT cell_symbol_define 51
#define cell_symbol_define 51
// CONSTANT cell_symbol_define_macro 52
#define cell_symbol_define_macro 52
// CONSTANT cell_symbol_quasiquote 53
#define cell_symbol_quasiquote 53
// CONSTANT cell_symbol_unquote 54
#define cell_symbol_unquote 54
// CONSTANT cell_symbol_unquote_splicing 55
#define cell_symbol_unquote_splicing 55
// CONSTANT cell_symbol_syntax 56
#define cell_symbol_syntax 56
// CONSTANT cell_symbol_quasisyntax 57
#define cell_symbol_quasisyntax 57
// CONSTANT cell_symbol_unsyntax 58
#define cell_symbol_unsyntax 58
// CONSTANT cell_symbol_unsyntax_splicing 59
#define cell_symbol_unsyntax_splicing 59
// CONSTANT cell_symbol_set_x 60
#define cell_symbol_set_x 60
// CONSTANT cell_symbol_sc_expand 61
#define cell_symbol_sc_expand 61
// CONSTANT cell_symbol_macro_expand 62
#define cell_symbol_macro_expand 62
// CONSTANT cell_symbol_portable_macro_expand 63
#define cell_symbol_portable_macro_expand 63
// CONSTANT cell_symbol_sc_expander_alist 64
#define cell_symbol_sc_expander_alist 64
// CONSTANT cell_symbol_call_with_values 65
#define cell_symbol_call_with_values 65
// CONSTANT cell_symbol_call_with_current_continuation 66
#define cell_symbol_call_with_current_continuation 66
// CONSTANT cell_symbol_boot_module 67
#define cell_symbol_boot_module 67
// CONSTANT cell_symbol_current_module 68
#define cell_symbol_current_module 68
// CONSTANT cell_symbol_primitive_load 69
#define cell_symbol_primitive_load 69
// CONSTANT cell_symbol_read_input_file 70
#define cell_symbol_read_input_file 70
// CONSTANT cell_symbol_write 71
#define cell_symbol_write 71
// CONSTANT cell_symbol_display 72
#define cell_symbol_display 72
// CONSTANT cell_symbol_car 73
#define cell_symbol_car 73
// CONSTANT cell_symbol_cdr 74
#define cell_symbol_cdr 74
// CONSTANT cell_symbol_not_a_number 75
#define cell_symbol_not_a_number 75
// CONSTANT cell_symbol_not_a_pair 76
#define cell_symbol_not_a_pair 76
// CONSTANT cell_symbol_system_error 77
#define cell_symbol_system_error 77
// CONSTANT cell_symbol_throw 78
#define cell_symbol_throw 78
// CONSTANT cell_symbol_unbound_variable 79
#define cell_symbol_unbound_variable 79
// CONSTANT cell_symbol_wrong_number_of_args 80
#define cell_symbol_wrong_number_of_args 80
// CONSTANT cell_symbol_wrong_type_arg 81
#define cell_symbol_wrong_type_arg 81
// CONSTANT cell_symbol_buckets 82
#define cell_symbol_buckets 82
// CONSTANT cell_symbol_builtin 83
#define cell_symbol_builtin 83
// CONSTANT cell_symbol_frame 84
#define cell_symbol_frame 84
// CONSTANT cell_symbol_hashq_table 85
#define cell_symbol_hashq_table 85
// CONSTANT cell_symbol_module 86
#define cell_symbol_module 86
// CONSTANT cell_symbol_procedure 87
#define cell_symbol_procedure 87
// CONSTANT cell_symbol_record_type 88
#define cell_symbol_record_type 88
// CONSTANT cell_symbol_size 89
#define cell_symbol_size 89
// CONSTANT cell_symbol_stack 90
#define cell_symbol_stack 90
// CONSTANT cell_symbol_argv 91
#define cell_symbol_argv 91
// CONSTANT cell_symbol_mes_prefix 92
#define cell_symbol_mes_prefix 92
// CONSTANT cell_symbol_mes_version 93
#define cell_symbol_mes_version 93
// CONSTANT cell_symbol_internal_time_units_per_second 94
#define cell_symbol_internal_time_units_per_second 94
// CONSTANT cell_symbol_compiler 95
#define cell_symbol_compiler 95
// CONSTANT cell_symbol_arch 96
#define cell_symbol_arch 96
// CONSTANT cell_symbol_pmatch_car 97
#define cell_symbol_pmatch_car 97
// CONSTANT cell_symbol_pmatch_cdr 98
#define cell_symbol_pmatch_cdr 98
// CONSTANT cell_type_bytes 99
#define cell_type_bytes 99
// CONSTANT cell_type_char 100
#define cell_type_char 100
// CONSTANT cell_type_closure 101
#define cell_type_closure 101
// CONSTANT cell_type_continuation 102
#define cell_type_continuation 102
// CONSTANT cell_type_function 103
#define cell_type_function 103
// CONSTANT cell_type_keyword 104
#define cell_type_keyword 104
// CONSTANT cell_type_macro 105
#define cell_type_macro 105
// CONSTANT cell_type_number 106
#define cell_type_number 106
// CONSTANT cell_type_pair 107
#define cell_type_pair 107
// CONSTANT cell_type_port 108
#define cell_type_port 108
// CONSTANT cell_type_ref 109
#define cell_type_ref 109
// CONSTANT cell_type_special 110
#define cell_type_special 110
// CONSTANT cell_type_string 111
#define cell_type_string 111
// CONSTANT cell_type_struct 112
#define cell_type_struct 112
// CONSTANT cell_type_symbol 113
#define cell_type_symbol 113
// CONSTANT cell_type_values 114
#define cell_type_values 114
// CONSTANT cell_type_variable 115
#define cell_type_variable 115
// CONSTANT cell_type_vector 116
#define cell_type_vector 116
// CONSTANT cell_type_broken_heart 117
#define cell_type_broken_heart 117
// CONSTANT cell_symbol_test 118
#define cell_symbol_test 118
// src/module.mes
SCM make_module_type (); SCM make_module_type ();
SCM module_printer (SCM module); SCM module_printer (SCM module);
SCM module_variable (SCM module, SCM name); SCM module_variable (SCM module, SCM name);
SCM module_ref (SCM module, SCM name); SCM module_ref (SCM module, SCM name);
SCM module_define_x (SCM module, SCM name, SCM value); SCM module_define_x (SCM module, SCM name, SCM value);
// src/posix.mes /* src/posix.c */
SCM peek_byte (); SCM peek_byte ();
SCM read_byte (); SCM read_byte ();
SCM unread_byte (SCM i); SCM unread_byte (SCM i);
@ -363,7 +134,6 @@ SCM current_error_port ();
SCM open_output_file (SCM x); SCM open_output_file (SCM x);
SCM set_current_output_port (SCM port); SCM set_current_output_port (SCM port);
SCM set_current_error_port (SCM port); SCM set_current_error_port (SCM port);
SCM force_output (SCM p);
SCM chmod_ (SCM file_name, SCM mode); SCM chmod_ (SCM file_name, SCM mode);
SCM isatty_p (SCM port); SCM isatty_p (SCM port);
SCM primitive_fork (); SCM primitive_fork ();
@ -376,7 +146,7 @@ SCM getcwd_ ();
SCM dup_ (SCM port); SCM dup_ (SCM port);
SCM dup2_ (SCM old, SCM new); SCM dup2_ (SCM old, SCM new);
SCM delete_file (SCM file_name); SCM delete_file (SCM file_name);
// src/reader.mes /* src/reader.c */
SCM read_input_file_env_ (SCM e, SCM a); SCM read_input_file_env_ (SCM e, SCM a);
SCM read_input_file_env (SCM a); SCM read_input_file_env (SCM a);
SCM read_env (SCM a); SCM read_env (SCM a);
@ -386,7 +156,7 @@ SCM reader_read_binary ();
SCM reader_read_octal (); SCM reader_read_octal ();
SCM reader_read_hex (); SCM reader_read_hex ();
SCM reader_read_string (); SCM reader_read_string ();
// src/strings.mes /* src/string.c */
SCM string_equal_p (SCM a, SCM b); SCM string_equal_p (SCM a, SCM b);
SCM symbol_to_string (SCM symbol); SCM symbol_to_string (SCM symbol);
SCM symbol_to_keyword (SCM symbol); SCM symbol_to_keyword (SCM symbol);
@ -399,12 +169,12 @@ SCM read_string (SCM port);
SCM string_append (SCM x); SCM string_append (SCM x);
SCM string_length (SCM string); SCM string_length (SCM string);
SCM string_ref (SCM str, SCM k); SCM string_ref (SCM str, SCM k);
// src/struct.mes /* src/struct.c */
SCM make_struct (SCM type, SCM fields, SCM printer); SCM make_struct (SCM type, SCM fields, SCM printer);
SCM struct_length (SCM x); SCM struct_length (SCM x);
SCM struct_ref (SCM x, SCM i); SCM struct_ref (SCM x, SCM i);
SCM struct_set_x (SCM x, SCM i, SCM e); SCM struct_set_x (SCM x, SCM i, SCM e);
// src/vector.mes /* src/vector.c */
SCM make_vector_ (SCM n); SCM make_vector_ (SCM n);
SCM vector_length (SCM x); SCM vector_length (SCM x);
SCM vector_ref (SCM x, SCM i); SCM vector_ref (SCM x, SCM i);
@ -413,4 +183,4 @@ SCM vector_set_x (SCM x, SCM i, SCM e);
SCM list_to_vector (SCM x); SCM list_to_vector (SCM x);
SCM vector_to_list (SCM v); SCM vector_to_list (SCM v);
#endif //__MES_BUILTINS_H #endif /* __MES_BUILTINS_H */

46
include/mes/cc.h Normal file
View File

@ -0,0 +1,46 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MES_CC_H
#define __MES_CC_H
#if POINTER_CELLS
typedef struct scm* SCM;
#else
typedef long SCM;
#endif
#if __MESC__
typedef long FUNCTION;
typedef long function0_t;
typedef long function1_t;
typedef long function2_t;
typedef long function3_t;
typedef long functionn_t;
#else // !__MESC__
typedef SCM (*FUNCTION) (void);
typedef SCM (*function0_t) (void);
typedef SCM (*function1_t) (SCM);
typedef SCM (*function2_t) (SCM, SCM);
typedef SCM (*function3_t) (SCM, SCM, SCM);
typedef SCM (*functionn_t) (SCM);
#endif // !__MESC__
#endif //__MES_CC_H

View File

@ -21,257 +21,6 @@
#ifndef __MES_CONSTANTS_H #ifndef __MES_CONSTANTS_H
#define __MES_CONSTANTS_H #define __MES_CONSTANTS_H
/* Symbols */
// CONSTANT cell_nil 1
#define cell_nil 1
// CONSTANT cell_f 2
#define cell_f 2
// CONSTANT cell_t 3
#define cell_t 3
// CONSTANT cell_dot 4
#define cell_dot 4
// CONSTANT cell_arrow 5
#define cell_arrow 5
// CONSTANT cell_undefined 6
#define cell_undefined 6
// CONSTANT cell_unspecified 7
#define cell_unspecified 7
// CONSTANT cell_closure 8
#define cell_closure 8
// CONSTANT cell_circular 9
#define cell_circular 9
// CONSTANT cell_begin 10
#define cell_begin 10
// CONSTANT cell_call_with_current_continuation 11
#define cell_call_with_current_continuation 11
// CONSTANT cell_vm_apply 12
#define cell_vm_apply 12
// CONSTANT cell_vm_apply2 13
#define cell_vm_apply2 13
// CONSTANT cell_vm_begin 14
#define cell_vm_begin 14
// CONSTANT cell_vm_begin_eval 15
#define cell_vm_begin_eval 15
// CONSTANT cell_vm_begin_expand 16
#define cell_vm_begin_expand 16
// CONSTANT cell_vm_begin_expand_eval 17
#define cell_vm_begin_expand_eval 17
// CONSTANT cell_vm_begin_expand_macro 18
#define cell_vm_begin_expand_macro 18
// CONSTANT cell_vm_begin_expand_primitive_load 19
#define cell_vm_begin_expand_primitive_load 19
// CONSTANT cell_vm_begin_primitive_load 20
#define cell_vm_begin_primitive_load 20
// CONSTANT cell_vm_begin_read_input_file 21
#define cell_vm_begin_read_input_file 21
// CONSTANT cell_vm_call_with_current_continuation2 22
#define cell_vm_call_with_current_continuation2 22
// CONSTANT cell_vm_call_with_values2 23
#define cell_vm_call_with_values2 23
// CONSTANT cell_vm_eval 24
#define cell_vm_eval 24
// CONSTANT cell_vm_eval2 25
#define cell_vm_eval2 25
// CONSTANT cell_vm_eval_check_func 26
#define cell_vm_eval_check_func 26
// CONSTANT cell_vm_eval_define 27
#define cell_vm_eval_define 27
// CONSTANT cell_vm_eval_macro_expand_eval 28
#define cell_vm_eval_macro_expand_eval 28
// CONSTANT cell_vm_eval_macro_expand_expand 29
#define cell_vm_eval_macro_expand_expand 29
// CONSTANT cell_vm_eval_pmatch_car 30
#define cell_vm_eval_pmatch_car 30
// CONSTANT cell_vm_eval_pmatch_cdr 31
#define cell_vm_eval_pmatch_cdr 31
// CONSTANT cell_vm_eval_set_x 32
#define cell_vm_eval_set_x 32
// CONSTANT cell_vm_evlis 33
#define cell_vm_evlis 33
// CONSTANT cell_vm_evlis2 34
#define cell_vm_evlis2 34
// CONSTANT cell_vm_evlis3 35
#define cell_vm_evlis3 35
// CONSTANT cell_vm_if 36
#define cell_vm_if 36
// CONSTANT cell_vm_if_expr 37
#define cell_vm_if_expr 37
// CONSTANT cell_vm_macro_expand 38
#define cell_vm_macro_expand 38
// CONSTANT cell_vm_macro_expand_car 39
#define cell_vm_macro_expand_car 39
// CONSTANT cell_vm_macro_expand_cdr 40
#define cell_vm_macro_expand_cdr 40
// CONSTANT cell_vm_macro_expand_define 41
#define cell_vm_macro_expand_define 41
// CONSTANT cell_vm_macro_expand_define_macro 42
#define cell_vm_macro_expand_define_macro 42
// CONSTANT cell_vm_macro_expand_lambda 43
#define cell_vm_macro_expand_lambda 43
// CONSTANT cell_vm_macro_expand_set_x 44
#define cell_vm_macro_expand_set_x 44
// CONSTANT cell_vm_return 45
#define cell_vm_return 45
// CONSTANT cell_symbol_dot 46
#define cell_symbol_dot 46
// CONSTANT cell_symbol_lambda 47
#define cell_symbol_lambda 47
// CONSTANT cell_symbol_begin 48
#define cell_symbol_begin 48
// CONSTANT cell_symbol_if 49
#define cell_symbol_if 49
// CONSTANT cell_symbol_quote 50
#define cell_symbol_quote 50
// CONSTANT cell_symbol_define 51
#define cell_symbol_define 51
// CONSTANT cell_symbol_define_macro 52
#define cell_symbol_define_macro 52
// CONSTANT cell_symbol_quasiquote 53
#define cell_symbol_quasiquote 53
// CONSTANT cell_symbol_unquote 54
#define cell_symbol_unquote 54
// CONSTANT cell_symbol_unquote_splicing 55
#define cell_symbol_unquote_splicing 55
// CONSTANT cell_symbol_syntax 56
#define cell_symbol_syntax 56
// CONSTANT cell_symbol_quasisyntax 57
#define cell_symbol_quasisyntax 57
// CONSTANT cell_symbol_unsyntax 58
#define cell_symbol_unsyntax 58
// CONSTANT cell_symbol_unsyntax_splicing 59
#define cell_symbol_unsyntax_splicing 59
// CONSTANT cell_symbol_set_x 60
#define cell_symbol_set_x 60
// CONSTANT cell_symbol_sc_expand 61
#define cell_symbol_sc_expand 61
// CONSTANT cell_symbol_macro_expand 62
#define cell_symbol_macro_expand 62
// CONSTANT cell_symbol_portable_macro_expand 63
#define cell_symbol_portable_macro_expand 63
// CONSTANT cell_symbol_sc_expander_alist 64
#define cell_symbol_sc_expander_alist 64
// CONSTANT cell_symbol_call_with_values 65
#define cell_symbol_call_with_values 65
// CONSTANT cell_symbol_call_with_current_continuation 66
#define cell_symbol_call_with_current_continuation 66
// CONSTANT cell_symbol_boot_module 67
#define cell_symbol_boot_module 67
// CONSTANT cell_symbol_current_module 68
#define cell_symbol_current_module 68
// CONSTANT cell_symbol_primitive_load 69
#define cell_symbol_primitive_load 69
// CONSTANT cell_symbol_read_input_file 70
#define cell_symbol_read_input_file 70
// CONSTANT cell_symbol_write 71
#define cell_symbol_write 71
// CONSTANT cell_symbol_display 72
#define cell_symbol_display 72
// CONSTANT cell_symbol_car 73
#define cell_symbol_car 73
// CONSTANT cell_symbol_cdr 74
#define cell_symbol_cdr 74
// CONSTANT cell_symbol_not_a_number 75
#define cell_symbol_not_a_number 75
// CONSTANT cell_symbol_not_a_pair 76
#define cell_symbol_not_a_pair 76
// CONSTANT cell_symbol_system_error 77
#define cell_symbol_system_error 77
// CONSTANT cell_symbol_throw 78
#define cell_symbol_throw 78
// CONSTANT cell_symbol_unbound_variable 79
#define cell_symbol_unbound_variable 79
// CONSTANT cell_symbol_wrong_number_of_args 80
#define cell_symbol_wrong_number_of_args 80
// CONSTANT cell_symbol_wrong_type_arg 81
#define cell_symbol_wrong_type_arg 81
// CONSTANT cell_symbol_buckets 82
#define cell_symbol_buckets 82
// CONSTANT cell_symbol_builtin 83
#define cell_symbol_builtin 83
// CONSTANT cell_symbol_frame 84
#define cell_symbol_frame 84
// CONSTANT cell_symbol_hashq_table 85
#define cell_symbol_hashq_table 85
// CONSTANT cell_symbol_module 86
#define cell_symbol_module 86
// CONSTANT cell_symbol_procedure 87
#define cell_symbol_procedure 87
// CONSTANT cell_symbol_record_type 88
#define cell_symbol_record_type 88
// CONSTANT cell_symbol_size 89
#define cell_symbol_size 89
// CONSTANT cell_symbol_stack 90
#define cell_symbol_stack 90
// CONSTANT cell_symbol_argv 91
#define cell_symbol_argv 91
// CONSTANT cell_symbol_mes_datadir 92
#define cell_symbol_mes_datadir 92
// CONSTANT cell_symbol_mes_version 93
#define cell_symbol_mes_version 93
// CONSTANT cell_symbol_internal_time_units_per_second 94
#define cell_symbol_internal_time_units_per_second 94
// CONSTANT cell_symbol_compiler 95
#define cell_symbol_compiler 95
// CONSTANT cell_symbol_arch 96
#define cell_symbol_arch 96
// CONSTANT cell_symbol_pmatch_car 97
#define cell_symbol_pmatch_car 97
// CONSTANT cell_symbol_pmatch_cdr 98
#define cell_symbol_pmatch_cdr 98
// CONSTANT cell_type_bytes 99
#define cell_type_bytes 99
// CONSTANT cell_type_char 100
#define cell_type_char 100
// CONSTANT cell_type_closure 101
#define cell_type_closure 101
// CONSTANT cell_type_continuation 102
#define cell_type_continuation 102
// CONSTANT cell_type_function 103
#define cell_type_function 103
// CONSTANT cell_type_keyword 104
#define cell_type_keyword 104
// CONSTANT cell_type_macro 105
#define cell_type_macro 105
// CONSTANT cell_type_number 106
#define cell_type_number 106
// CONSTANT cell_type_pair 107
#define cell_type_pair 107
// CONSTANT cell_type_port 108
#define cell_type_port 108
// CONSTANT cell_type_ref 109
#define cell_type_ref 109
// CONSTANT cell_type_special 110
#define cell_type_special 110
// CONSTANT cell_type_string 111
#define cell_type_string 111
// CONSTANT cell_type_struct 112
#define cell_type_struct 112
// CONSTANT cell_type_symbol 113
#define cell_type_symbol 113
// CONSTANT cell_type_values 114
#define cell_type_values 114
// CONSTANT cell_type_variable 115
#define cell_type_variable 115
// CONSTANT cell_type_vector 116
#define cell_type_vector 116
// CONSTANT cell_type_broken_heart 117
#define cell_type_broken_heart 117
// CONSTANT cell_test 118
#define cell_test 118
/* Cell types */ /* Cell types */
// CONSTANT TBYTES 0 // CONSTANT TBYTES 0
@ -318,7 +67,31 @@
// CONSTANT STRUCT_PRINTER 1 // CONSTANT STRUCT_PRINTER 1
#define STRUCT_PRINTER 1 #define STRUCT_PRINTER 1
// CONSTANT FRAME_SIZE 5
#define FRAME_SIZE 5 #define FRAME_SIZE 5
// CONSTANT FRAME_PROCEDURE 4
#define FRAME_PROCEDURE 4 #define FRAME_PROCEDURE 4
#endif //__MES_CONSTANTS_H // CONSTANT STDIN 0
// CONSTANT STDOUT 1
// CONSTANT STDERR 2
/* Unknown type 1
// CONSTANT EOF -1
*/
// CONSTANT O_RDONLY 0
// CONSTANT O_WRONLY 1
// CONSTANT O_CREAT 0x40
// CONSTANT O_TRUNC 0x200
// CONSTANT PATH_MAX 1024
// CONSTANT __FILEDES_MAX 512
// CONSTANT S_IRUSR 00400
// CONSTANT S_IWUSR 00200
// CONSTANT CLOCK_PROCESS_CPUTIME_ID 2
#endif /* __MES_CONSTANTS_H */

View File

@ -28,7 +28,9 @@ void __ungetc_init ();
void __ungetc_clear (int filedes); void __ungetc_clear (int filedes);
void __ungetc_set (int filedes, int c); void __ungetc_set (int filedes, int c);
int __ungetc_p (int filedes); int __ungetc_p (int filedes);
double abtod (char const **p, int base);
long abtol (char const **p, int base); long abtol (char const **p, int base);
char *dtoab (double number, int base, int signed_p);
char *itoa (int number); char *itoa (int number);
char *ltoa (long number); char *ltoa (long number);
char *ltoab (long x, int base); char *ltoab (long x, int base);
@ -50,6 +52,7 @@ int oputc (int c);
int oputs (char const *s); int oputs (char const *s);
char *search_path (char const *file_name); char *search_path (char const *file_name);
ssize_t _read (int fd, void *buffer, size_t size); ssize_t _read (int fd, void *buffer, size_t size);
void assert_msg (int check, char *msg);
extern char *__brk; extern char *__brk;
extern void (*__call_at_exit) (void); extern void (*__call_at_exit) (void);

109
include/mes/m2.h Normal file
View File

@ -0,0 +1,109 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MES_M2_H
#define __MES_M2_H
char **environ;
int __stdin;
int __stdout;
int __stderr;
int __ungetc_p (int filedes);
int eputs (char *s);
int oputs (char *s);
int puts (char *s);
size_t strlen (char *s);
ssize_t _write ();
ssize_t write (int filedes, void *buffer, size_t size);
void __ungetc_clear (int filedes);
void __ungetc_init ();
void __ungetc_set (int filedes, int c);
/* Recieved SCM in program
struct timespec
{
long tv_sec;
long tv_nsec;
};
struct timeval
{
long tv_sec;
long tv_usec;
};
*/
#define struct_size 12
#if POINTER_CELLS
#define CELL(x) (x)
#else
#define CELL(x) ((x*struct_size)+g_cells)
#define TYPE(x) ((x*struct_size)+g_cells)->type
#define CAR(x) ((x*struct_size)+g_cells)->car
#define CDR(x) ((x*struct_size)+g_cells)->cdr
#define NTYPE(x) ((x*struct_size)+g_news)->type
#define NCAR(x) ((x*struct_size)+g_news)->car
#define NCDR(x) ((x*struct_size)+g_news)->cdr
#define BYTES(x) ((x*struct_size)+g_cells)->car
#define LENGTH(x) ((x*struct_size)+g_cells)->car
#define MACRO(x) ((x*struct_size)+g_cells)->car
#define PORT(x) ((x*struct_size)+g_cells)->car
#define REF(x) ((x*struct_size)+g_cells)->car
#define VARIABLE(x) ((x*struct_size)+g_cells)->car
#define CLOSURE(x) ((x*struct_size)+g_cells)->cdr
#define CONTINUATION(x) ((x*struct_size)+g_cells)->cdr
#define CBYTES(x) (((x*struct_size)+g_cells) + 8)
#define NAME(x) ((x*struct_size)+g_cells)->cdr
#define STRING(x) ((x*struct_size)+g_cells)->cdr
#define STRUCT(x) ((x*struct_size)+g_cells)->cdr
#define VALUE(x) ((x*struct_size)+g_cells)->cdr
#define VECTOR(x) ((x*struct_size)+g_cells)->cdr
#define NLENGTH(x) ((x*struct_size)+g_news)->car
#define NVALUE(x) ((x*struct_size)+g_news)->cdr
#define NSTRING(x) ((x*struct_size)+g_news)->cdr
#define NVECTOR(x) ((x*struct_size)+g_news)->cdr
#define CAAR(x) CAR (CAR (x))
#define CADR(x) CAR (CDR (x))
#define CDAR(x) CDR (CAR (x))
#define CDDR(x) CDR (CDR (x))
#define CADAR(x) CAR (CDR (CAR (x)))
#define CADDR(x) CAR (CDR (CDR (x)))
#define CDADR(x) CDR (CAR (CDR (x)))
#define CDDAR(x) CDR (CDR (CAR (x)))
#endif
#endif /* __MES_M2_H */

View File

@ -21,6 +21,76 @@
#ifndef __MES_MACROS_H #ifndef __MES_MACROS_H
#define __MES_MACROS_H #define __MES_MACROS_H
#if POINTER_CELLS
// #define TYPE(x) x->type
// #define CAR(x) x->car
// #define CDR(x) x->cdr
// #define NTYPE(x) x->type
// #define NCAR(x) x->car
// #define NCDR(x) x->cdr
// #define BYTES(x) x->car
// #define LENGTH(x) x->car
// #define REF(x) x->car
// #define VARIABLE(x) x->car
// #define CLOSURE(x) x->cdr
// #define CONTINUATION(x) x->cdr
// #define MACRO(x) x->car
// #define NAME(x) x->cdr
// #define PORT(x) x->car
// #define STRING(x) x->cdr
// #define STRUCT(x) x->cdr
// #define VALUE(x) x->cdr
// #define VECTOR(x) x->cdr
// #define NLENGTH(x) x->car
// #define NVALUE(x) x->cdr
// #define NSTRING(x) x->cdr
// #define NVECTOR(x) x->cdr
#define TYPE(x) g_cells[x - g_cells].type
#define CAR(x) g_cells[x - g_cells].car
#define CDR(x) g_cells[x - g_cells].cdr
#define NTYPE(x) g_news[x - g_news].type
#define NCAR(x) g_news[x - g_news].car
#define NCDR(x) g_news[x - g_news].cdr
// #define STYPE(x) g_stack_array[x].type
// #define SCAR(x) g_stack_array[x].car
// #define SCDR(x) g_stack_arraynews[x].cdr
#define STYPE(x) TYPE (g_stack_array[x])
#define SCAR(x) CAR (g_stack_array[x])
#define SCDR(x) CDR (g_stack_arraynews[x])
#define BYTES(x) g_cells[x - g_cells].bytes
#define LENGTH(x) g_cells[x - g_cells].length
#define MACRO(x) g_cells[x - g_cells].macro
#define PORT(x) g_cells[x - g_cells].port
#define REF(x) g_cells[x - g_cells].ref
#define VARIABLE(x) g_cells[x - g_cells].variable
#define CLOSURE(x) g_cells[x - g_cells].closure
#define CONTINUATION(x) g_cells[x - g_cells].continuation
#define NAME(x) g_cells[x - g_cells].name
#define STRING(x) g_cells[x - g_cells].string
#define STRUCT(x) g_cells[x - g_cells].structure
#define VALUE(x) g_cells[x - g_cells].value
#define VECTOR(x) g_cells[x - g_cells].vector
#define NLENGTH(x) g_news[x - g_news].length
#define NVALUE(x) g_news[x - g_news].value
#define NSTRING(x) g_news[x - g_news].string
#define NVECTOR(x) g_news[x - g_news].vector
#else
#define TYPE(x) g_cells[x].type #define TYPE(x) g_cells[x].type
#define CAR(x) g_cells[x].car #define CAR(x) g_cells[x].car
#define CDR(x) g_cells[x].cdr #define CDR(x) g_cells[x].cdr
@ -29,19 +99,18 @@
#define NCAR(x) g_news[x].car #define NCAR(x) g_news[x].car
#define NCDR(x) g_news[x].cdr #define NCDR(x) g_news[x].cdr
#define STYPE(x) TYPE (g_stack_array[x])
#define SCAR(x) CAR (g_stack_array[x])
#define SCDR(x) CDR (g_stack_array[x])
#define BYTES(x) g_cells[x].car #define BYTES(x) g_cells[x].car
#define LENGTH(x) g_cells[x].car #define LENGTH(x) g_cells[x].car
#define REF(x) g_cells[x].car #define REF(x) g_cells[x].car
#define START(x) (g_cells[x].car >> 16)
#define LEN(x) (g_cells[x].car & 0xffff)
#define VARIABLE(x) g_cells[x].car #define VARIABLE(x) g_cells[x].car
#define CLOSURE(x) g_cells[x].cdr #define CLOSURE(x) g_cells[x].cdr
#define CONTINUATION(x) g_cells[x].cdr #define CONTINUATION(x) g_cells[x].cdr
#define CBYTES(x) (char*)&g_cells[x].cdr
#define CSTRING_STRUCT(x) (char*)&g_cells[x.cdr].cdr
#define MACRO(x) g_cells[x].car #define MACRO(x) g_cells[x].car
#define NAME(x) g_cells[x].cdr #define NAME(x) g_cells[x].cdr
#define PORT(x) g_cells[x].car #define PORT(x) g_cells[x].car
@ -51,23 +120,11 @@
#define VECTOR(x) g_cells[x].cdr #define VECTOR(x) g_cells[x].cdr
#define NLENGTH(x) g_news[x].car #define NLENGTH(x) g_news[x].car
#define NCBYTES(x) (char*)&g_news[x].cdr
#define NVALUE(x) g_news[x].cdr #define NVALUE(x) g_news[x].cdr
#define NSTRING(x) g_news[x].cdr #define NSTRING(x) g_news[x].cdr
#define NVECTOR(x) g_news[x].cdr #define NVECTOR(x) g_news[x].cdr
#define CSTRING(x) CBYTES (STRING (x)) #endif
#define MAKE_BYTES0(x) make_bytes (x, strlen (x))
#define NAME_SYMBOL(symbol,name) {size_t s = strlen (name); CAR (symbol) = s; CDR (symbol) = make_bytes (name, s);}
#define MAKE_CHAR(n) make_cell__ (TCHAR, 0, n)
#define MAKE_CONTINUATION(n) make_cell__ (TCONTINUATION, n, g_stack)
#define MAKE_NUMBER(n) make_cell__ (TNUMBER, 0, (long)n)
#define MAKE_REF(n) make_cell__ (TREF, n, 0)
#define MAKE_STRING0(x) make_string (x, strlen (x))
#define MAKE_STRING_PORT(x) make_cell__ (TPORT, -length__ (g_ports) - 2, x)
#define MAKE_MACRO(name, x) make_cell__ (TMACRO, x, STRING (name))
#define CAAR(x) CAR (CAR (x)) #define CAAR(x) CAR (CAR (x))
#define CADR(x) CAR (CDR (x)) #define CADR(x) CAR (CDR (x))
@ -75,6 +132,7 @@
#define CDDR(x) CDR (CDR (x)) #define CDDR(x) CDR (CDR (x))
#define CADAR(x) CAR (CDR (CAR (x))) #define CADAR(x) CAR (CDR (CAR (x)))
#define CADDR(x) CAR (CDR (CDR (x))) #define CADDR(x) CAR (CDR (CDR (x)))
#define CDADAR(x) CAR (CDR (CAR (CDR (x)))) #define CDADR(x) CDR (CAR (CDR (x)))
#define CDDAR(x) CDR (CDR (CAR (x)))
#endif //__MES_MACROS_H #endif //__MES_MACROS_H

View File

@ -21,86 +21,148 @@
#ifndef __MES_MES_H #ifndef __MES_MES_H
#define __MES_MES_H #define __MES_MES_H
#define POINTER_CELLS 0
#include <sys/types.h> #include <sys/types.h>
#include "mes/cc.h"
typedef long SCM; #if POINTER_CELLS
struct scm
{
long type;
union
{
SCM car;
char *bytes;
long length;
SCM ref;
SCM variable;
SCM macro;
long port;
};
union
{
SCM cdr;
SCM closure;
SCM continuation;
char *name;
SCM string;
SCM structure;
long value;
SCM vector;
};
};
#else
struct scm struct scm
{ {
long type; long type;
SCM car; SCM car;
SCM cdr; SCM cdr;
}; };
#endif
// mes /* mes */
extern int g_debug; char *g_datadir;
extern char *g_buf; int g_debug;
extern SCM g_continuations; char *g_buf;
extern SCM g_symbols; SCM g_continuations;
extern SCM g_symbol_max; SCM g_symbols;
SCM g_symbol_max;
// a/env /* a/env */
extern SCM r0; SCM R0;
// param 1 /* param 1 */
extern SCM r1; SCM R1;
// save 2 /* save 2 */
extern SCM r2; SCM R2;
// continuation /* continuation */
extern SCM r3; SCM R3;
// current-module /* current-module */
extern SCM m0; SCM M0;
// macro /* macro */
extern SCM g_macros; SCM g_macros;
extern SCM g_ports; SCM g_ports;
// gc /* gc */
extern long ARENA_SIZE; long ARENA_SIZE;
extern long MAX_ARENA_SIZE; long MAX_ARENA_SIZE;
extern long STACK_SIZE; long STACK_SIZE;
extern long JAM_SIZE; long JAM_SIZE;
extern long GC_SAFETY; long GC_SAFETY;
extern long MAX_STRING; long MAX_STRING;
extern char *g_arena; char *g_arena;
extern long g_free; SCM cell_arena;
extern SCM g_stack;
extern SCM *g_stack_array; #if POINTER_CELLS
extern struct scm *g_cells; SCM g_free;
extern struct scm *g_news; long g_stack;
#else
long g_free;
SCM g_stack;
#endif
SCM *g_stack_array;
struct scm *g_cells;
struct scm *g_news;
char **__execl_c_argv;
char *__getcwd_buf;
char *__open_boot_buf;
char *__open_boot_file_name;
char *__setenv_buf;
char *__reader_read_char_buf;
SCM alloc (long n); SCM alloc (long n);
SCM apply (SCM f, SCM x, SCM a); SCM apply (SCM f, SCM x, SCM a);
SCM apply_builtin (SCM fn, SCM x); SCM apply_builtin (SCM fn, SCM x);
SCM builtin_name (SCM builtin);
SCM cstring_to_list (char const *s); SCM cstring_to_list (char const *s);
SCM cstring_to_symbol (char const *s); SCM cstring_to_symbol (char const *s);
SCM display_ (SCM x); SCM cell_ref (SCM cell, long index);
SCM fdisplay_ (SCM, int, int); SCM fdisplay_ (SCM, int, int);
SCM gc_init (); SCM gc_init ();
SCM gc_peek_frame (); SCM gc_peek_frame ();
SCM gc_pop_frame (); SCM gc_pop_frame ();
SCM gc_push_frame (); SCM gc_push_frame ();
SCM init_symbols ();
SCM init_time (SCM a); SCM init_time (SCM a);
SCM make_builtin_type ();
SCM make_bytes (char const *s, size_t length); SCM make_bytes (char const *s, size_t length);
SCM make_cell__ (long type, SCM car, SCM cdr); SCM make_cell (long type, SCM car, SCM cdr);
SCM make_char (int n);
SCM make_continuation (long n);
SCM make_hash_table_ (long size); SCM make_hash_table_ (long size);
SCM make_hashq_type (); SCM make_hashq_type ();
SCM make_initial_module (SCM a); SCM make_initial_module (SCM a);
SCM make_macro (SCM name, SCM x);
SCM make_number (long n);
SCM make_ref (SCM x);
SCM make_string (char const *s, size_t length); SCM make_string (char const *s, size_t length);
SCM make_string0 (char const *s);
SCM make_string_port (SCM x);
SCM make_vector__ (long k); SCM make_vector__ (long k);
SCM read_input_file_env (SCM); SCM mes_builtins (SCM a);
SCM string_equal_p (SCM a, SCM b); SCM push_cc (SCM p1, SCM p2, SCM a, SCM c);
SCM struct_ref_ (SCM x, long i); SCM struct_ref_ (SCM x, long i);
SCM struct_set_x_ (SCM x, long i, SCM e); SCM struct_set_x_ (SCM x, long i, SCM e);
SCM vector_ref_ (SCM x, long i); SCM vector_ref_ (SCM x, long i);
SCM vector_set_x_ (SCM x, long i, SCM e); SCM vector_set_x_ (SCM x, long i, SCM e);
FUNCTION builtin_function (SCM builtin);
char *cell_bytes (SCM x);
char *news_bytes (SCM x);
int peekchar (); int peekchar ();
int readchar (); int readchar ();
int unreadchar (); int unreadchar ();
long length__ (SCM x); long length__ (SCM x);
size_t bytes_cells (size_t length); size_t bytes_cells (size_t length);
void assert_max_string (size_t i, char const *msg, char *string); void assert_max_string (size_t i, char const *msg, char *string);
void assert_msg (int check, char *msg);
void copy_cell (SCM to, SCM from);
void gc_stats_ (char const* where);
#include "mes/builtins.h" #include "mes/builtins.h"
#include "mes/constants.h" #include "mes/constants.h"
#include "mes/macros.h" #include "mes/macros.h"
#include "mes/symbols.h"
#endif //__MES_MES_H #endif /* __MES_MES_H */

153
include/mes/symbols.h Normal file
View File

@ -0,0 +1,153 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MES_SYMBOLS_H
#define __MES_SYMBOLS_H
SCM cell_nil;
SCM cell_f;
SCM cell_t;
SCM cell_dot;
SCM cell_arrow;
SCM cell_undefined;
SCM cell_unspecified;
SCM cell_closure;
SCM cell_circular;
SCM cell_begin;
SCM cell_call_with_current_continuation;
SCM cell_vm_apply;
SCM cell_vm_apply2;
SCM cell_vm_begin;
SCM cell_vm_begin_eval;
SCM cell_vm_begin_expand;
SCM cell_vm_begin_expand_eval;
SCM cell_vm_begin_expand_macro;
SCM cell_vm_begin_expand_primitive_load;
SCM cell_vm_begin_primitive_load;
SCM cell_vm_begin_read_input_file;
SCM cell_vm_call_with_current_continuation2;
SCM cell_vm_call_with_values2;
SCM cell_vm_eval;
SCM cell_vm_eval2;
SCM cell_vm_eval_check_func;
SCM cell_vm_eval_define;
SCM cell_vm_eval_macro_expand_eval;
SCM cell_vm_eval_macro_expand_expand;
SCM cell_vm_eval_pmatch_car;
SCM cell_vm_eval_pmatch_cdr;
SCM cell_vm_eval_set_x;
SCM cell_vm_evlis;
SCM cell_vm_evlis2;
SCM cell_vm_evlis3;
SCM cell_vm_if;
SCM cell_vm_if_expr;
SCM cell_vm_macro_expand;
SCM cell_vm_macro_expand_car;
SCM cell_vm_macro_expand_cdr;
SCM cell_vm_macro_expand_define;
SCM cell_vm_macro_expand_define_macro;
SCM cell_vm_macro_expand_lambda;
SCM cell_vm_macro_expand_set_x;
SCM cell_vm_return;
SCM cell_symbol_dot;
SCM cell_symbol_lambda;
SCM cell_symbol_begin;
SCM cell_symbol_if;
SCM cell_symbol_quote;
SCM cell_symbol_define;
SCM cell_symbol_define_macro;
SCM cell_symbol_quasiquote;
SCM cell_symbol_unquote;
SCM cell_symbol_unquote_splicing;
SCM cell_symbol_syntax;
SCM cell_symbol_quasisyntax;
SCM cell_symbol_unsyntax;
SCM cell_symbol_unsyntax_splicing;
SCM cell_symbol_set_x;
SCM cell_symbol_sc_expand;
SCM cell_symbol_macro_expand;
SCM cell_symbol_portable_macro_expand;
SCM cell_symbol_sc_expander_alist;
SCM cell_symbol_call_with_values;
SCM cell_symbol_call_with_current_continuation;
SCM cell_symbol_boot_module;
SCM cell_symbol_current_module;
SCM cell_symbol_primitive_load;
SCM cell_symbol_read_input_file;
SCM cell_symbol_write;
SCM cell_symbol_display;
SCM cell_symbol_car;
SCM cell_symbol_cdr;
SCM cell_symbol_not_a_number;
SCM cell_symbol_not_a_pair;
SCM cell_symbol_system_error;
SCM cell_symbol_throw;
SCM cell_symbol_unbound_variable;
SCM cell_symbol_wrong_number_of_args;
SCM cell_symbol_wrong_type_arg;
SCM cell_symbol_buckets;
SCM cell_symbol_builtin;
SCM cell_symbol_frame;
SCM cell_symbol_hashq_table;
SCM cell_symbol_module;
SCM cell_symbol_procedure;
SCM cell_symbol_record_type;
SCM cell_symbol_size;
SCM cell_symbol_stack;
SCM cell_symbol_argv;
SCM cell_symbol_mes_datadir;
SCM cell_symbol_mes_version;
SCM cell_symbol_internal_time_units_per_second;
SCM cell_symbol_compiler;
SCM cell_symbol_arch;
SCM cell_symbol_pmatch_car;
SCM cell_symbol_pmatch_cdr;
SCM cell_type_bytes;
SCM cell_type_char;
SCM cell_type_closure;
SCM cell_type_continuation;
SCM cell_type_function;
SCM cell_type_keyword;
SCM cell_type_macro;
SCM cell_type_number;
SCM cell_type_pair;
SCM cell_type_port;
SCM cell_type_ref;
SCM cell_type_special;
SCM cell_type_string;
SCM cell_type_struct;
SCM cell_type_symbol;
SCM cell_type_values;
SCM cell_type_variable;
SCM cell_type_vector;
SCM cell_type_broken_heart;
SCM cell_symbol_test;
// CONSTANT SYMBOL_MAX 119
#define SYMBOL_MAX 119
// CONSTANT CELL_UNSPECIFIED 7
#define CELL_UNSPECIFIED 7
// CONSTANT CELL_SYMBOL_RECORD_TYPE 88
#define CELL_SYMBOL_RECORD_TYPE 88
#endif /* __MES_SYMBOLS_H */

View File

@ -34,6 +34,8 @@
typedef char *va_list; typedef char *va_list;
#define va_start(ap, last) (void)((ap) = (char*)(&(last) + 1)) #define va_start(ap, last) (void)((ap) = (char*)(&(last) + 1))
#define va_arg(ap, type) (type)(((long*)((ap) = ((ap) + sizeof (void*))))[-1]) #define va_arg(ap, type) (type)(((long*)((ap) = ((ap) + sizeof (void*))))[-1])
#define va_align(ap, alignment) ((char*)((((unsigned long) (ap)) + (alignment) - 1) &~ ((alignment) - 1)))
#define va_arg8(ap, type) (type)(((double*)((ap) = (va_align((ap), 8) + sizeof(double))))[-1])
#define va_end(ap) (void)((ap) = 0) #define va_end(ap) (void)((ap) = 0)
#define va_copy(dest, src) dest = src #define va_copy(dest, src) dest = src

View File

@ -36,6 +36,7 @@ typedef int (*comparison_fn_t) (void const *, void const *);
#include <sys/types.h> #include <sys/types.h>
#include <alloca.h> #include <alloca.h>
void abort (void);
double atof (char const *s); double atof (char const *s);
int atoi (char const *s); int atoi (char const *s);
int atexit (void (*function) (void)); int atexit (void (*function) (void));

View File

@ -85,10 +85,12 @@ struct stat
int chmod (char const *file_name, mode_t mode); int chmod (char const *file_name, mode_t mode);
int fstat (int filedes, struct stat *buf); int fstat (int filedes, struct stat *buf);
int mkdir (char const *file_name, mode_t mode); int mkdir (char const *file_name, mode_t mode);
int mknod (char const *file_name, mode_t mode, dev_t dev);
int chown (char const *file_name, uid_t owner, gid_t group); int chown (char const *file_name, uid_t owner, gid_t group);
int rmdir (char const *file_name); int rmdir (char const *file_name);
int stat (char const *file_name, struct stat *buf); int stat (char const *file_name, struct stat *buf);
#define S_IFIFO 0010000
#define S_IFCHR 0020000 #define S_IFCHR 0020000
#define S_IFDIR 0040000 #define S_IFDIR 0040000
#define S_IFBLK 0060000 #define S_IFBLK 0060000
@ -96,6 +98,7 @@ int stat (char const *file_name, struct stat *buf);
#define S_IFLNK 0120000 #define S_IFLNK 0120000
#define S_IFMT 0170000 #define S_IFMT 0170000
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)

View File

@ -87,7 +87,7 @@ typedef unsigned long uintptr_t;
#ifndef __MES_OFF_T #ifndef __MES_OFF_T
#define __MES_OFF_T #define __MES_OFF_T
#undef off_t #undef off_t
typedef unsigned long off_t; typedef long off_t;
#endif #endif
#ifndef __MES_OFF64_T #ifndef __MES_OFF64_T
@ -138,6 +138,15 @@ typedef long ssize_t;
typedef unsigned uid_t; typedef unsigned uid_t;
#endif #endif
#ifndef __WCHAR_T
#define __WCHAR_T
#ifndef __MES_WCHAR_T
#define __MES_WCHAR_T
#undef wchar_t
typedef int wchar_t;
#endif
#endif
#endif // ! SYSTEM_LIBC #endif // ! SYSTEM_LIBC
#endif // __MES_SYS_TYPES_H #endif // __MES_SYS_TYPES_H

View File

@ -49,6 +49,14 @@
#define CS8 0000060 #define CS8 0000060
#define PARENB 0000400 #define PARENB 0000400
struct winsize
{
unsigned short ws_row;
unsigned short ws_col;
unsigned short ws_xpixel;
unsigned short ws_ypixel;
};
struct termio struct termio
{ {
unsigned short c_iflag; unsigned short c_iflag;

View File

@ -59,6 +59,7 @@ struct timespec
int clock_gettime (clockid_t clk_id, struct timespec *tp); int clock_gettime (clockid_t clk_id, struct timespec *tp);
struct tm *localtime (time_t const *timep); struct tm *localtime (time_t const *timep);
struct tm *gmtime (time_t const *time); struct tm *gmtime (time_t const *time);
time_t mktime (struct tm *broken_time);
int nanosleep (struct timespec const *requested_time, struct timespec const *remaining); int nanosleep (struct timespec const *requested_time, struct timespec const *remaining);
time_t time (time_t * tloc); time_t time (time_t * tloc);

View File

@ -62,6 +62,7 @@ unsigned int alarm (unsigned int seconds);
int close (int fd); int close (int fd);
int execv (char const *file_name, char *const argv[]); int execv (char const *file_name, char *const argv[]);
int execl (char const *file_name, char const *arg, ...); int execl (char const *file_name, char const *arg, ...);
int execlp (char const *file_name, char const *arg, ...);
int execve (char const *file, char *const argv[], char *const env[]); int execve (char const *file, char *const argv[], char *const env[]);
int execvp (char const *file, char *const argv[]); int execvp (char const *file, char *const argv[]);
int fork (void); int fork (void);
@ -73,21 +74,24 @@ int setgid (gid_t newgid);
int setuid (uid_t newuid); int setuid (uid_t newuid);
uid_t geteuid (void); uid_t geteuid (void);
gid_t getegid (void); gid_t getegid (void);
pid_t getpgrp (void);
pid_t getpid (void); pid_t getpid (void);
pid_t getppid (void); pid_t getppid (void);
int getpgid (pid_t pid);
int isatty (int fd); int isatty (int fd);
int link (char const *oldname, char const *newname); int link (char const *old_name, char const *new_name);
off_t lseek (int fd, off_t offset, int whence); off_t lseek (int fd, off_t offset, int whence);
ssize_t read (int fd, void *buffer, size_t size); ssize_t read (int fd, void *buffer, size_t size);
ssize_t readlink (char const *file_name, char *buffer, size_t size);
#if __SBRK_CHAR_PTRDIFF #if __SBRK_CHAR_PTRDIFF
/* xmalloc in binutils <= 2.10.1 uses this old prototype */ /* xmalloc in binutils <= 2.10.1 uses this old prototype */
char *sbrk (ptrdiff_t delta); char *sbrk (ptrdiff_t delta);
#else #else
void *sbrk (intptr_t delta); void *sbrk (intptr_t delta);
#endif #endif
int symlink (char const *old_name, char const *new_name);
int unlink (char const *file_name); int unlink (char const *file_name);
ssize_t write (int filedes, void const *buffer, size_t size); ssize_t write (int filedes, void const *buffer, size_t size);
pid_t getpid (void);
#endif // ! SYSTEM_LIBC #endif // ! SYSTEM_LIBC

130
kaem.run Normal file
View File

@ -0,0 +1,130 @@
#!/bin/bash
# Copyright (C) 2019 Jeremiah Orians <jeremiah@pdp10.guru>
# This file is part of Gnu Mes
#
# Gnu Mes is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Gnu Mes is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Gnu Mes. If not, see <http://www.gnu.org/licenses/>.
# Usage:
# kaem --verbose --strict
# bin/mes-m2 --boot scaffold/boot/14-exit.scm
# bin/mes-m2 --boot scaffold/boot/15-display.scm
M2-Planet \
--debug \
--architecture x86 \
-f lib/linux/x86-mes-m2/crt1.c \
-f lib/linux/x86-mes-m2/mini.c \
-f lib/m2/exit.c \
-f lib/m2/write.c \
-f lib/linux/x86-mes-m2/syscall.c \
-f include/linux/x86/syscall.h \
-f lib/m2/brk.c \
-f lib/m2/malloc.c \
-f lib/m2/memset.c \
-f lib/m2/read.c \
-f lib/m2/fdgetc.c \
-f lib/stdio/getchar.c \
-f lib/m2/putchar.c \
-f lib/m2/open.c \
-f lib/m2/mes_open.c \
-f lib/m2/strlen.c \
-f lib/m2/eputs.c \
-f lib/m2/fdputc.c \
-f lib/mes/eputc.c \
\
-f include/mes/mes.h.m2 \
-f include/mes/m2.h.m2 \
-f include/mes/builtins.h.m2 \
-f include/mes/constants.h.m2 \
-f include/mes/symbols.h.m2 \
\
-f lib/mes/__assert_fail.c \
-f lib/mes/assert_msg.c \
\
-f lib/m2/fdputc.c \
-f lib/m2/strncmp.c \
-f lib/m2/getenv.c \
-f lib/mes/fdputs.c.m2 \
-f lib/m2/ntoab.c \
-f lib/ctype/isdigit.c.m2 \
-f lib/ctype/isxdigit.c.m2 \
-f lib/ctype/isspace.c.m2 \
-f lib/ctype/isnumber.c.m2 \
-f lib/m2/abtol.c \
-f lib/m2/atoi.c \
-f lib/m2/memcpy.c \
-f lib/stdlib/free.c \
-f lib/stdlib/realloc.c.m2 \
-f lib/m2/strcpy.c \
-f lib/mes/itoa.c.m2 \
-f lib/mes/fdungetc.c.m2 \
-f lib/m2/setenv.c \
-f lib/m2/access.c \
-f lib/m2/chmod.c \
-f lib/m2/isatty.c \
-f lib/m2/fork.c \
-f lib/m2/execve.c \
-f lib/m2/execv.c \
-f lib/m2/waitpid.c \
-f lib/m2/clock_gettime.c \
-f lib/m2/time.c \
-f lib/m2/_getcwd.c \
-f lib/m2/getcwd.c \
-f lib/m2/dup.c \
-f lib/m2/dup2.c \
-f lib/m2/unlink.c \
-f lib/m2/strcmp.c \
-f lib/m2/memcmp.c \
-f src/builtins.c.m2 \
-f src/display.c.m2 \
-f src/eval-apply.c.m2 \
-f src/gc.c.m2 \
-f src/hash.c.m2 \
-f src/lib.c.m2 \
-f src/math.c.m2 \
-f src/mes.c.m2 \
-f src/module.c.m2 \
-f src/posix.c.m2 \
-f src/reader.c.m2 \
-f src/string.c.m2 \
-f src/struct.c.m2 \
-f src/symbols.c.m2 \
-f src/vector.c.m2 \
-o bin/mes.M1
blood-elf -f bin/mes.M1 -o bin/mes.blood-elf-M1
M1 \
--LittleEndian \
--architecture x86 \
-f lib/m2/x86/x86_defs.M1 \
-f lib/x86-mes/x86.M1 \
-f lib/linux/x86-mes-m2/crt1.M1 \
-f bin/mes.M1 \
-f bin/mes.blood-elf-M1 \
-o bin/mes.hex2
hex2 \
--LittleEndian \
--architecture x86 \
--BaseAddress 0x1000000 \
--exec_enable \
-f lib/x86-mes/elf32-header.hex2 \
-f bin/mes.hex2 \
-f lib/m2/missing.hex2 \
-o bin/mes-m2
echo Running mes-m2
./bin/mes-m2 --boot scaffold/boot/14-exit.scm
#./bin/mes-m2 --boot scaffold/boot/15-display.scm

27
lib/ctype/isgraph.c Normal file
View File

@ -0,0 +1,27 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ctype.h>
int
isgraph (int c)
{
return c > 32 && c < 127;
}

29
lib/linux/mknod.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/syscall.h>
#include <syscall.h>
#include <sys/stat.h>
int
mknod (char const *file_name, mode_t mode, dev_t dev)
{
return _sys_call3 (SYS_mknod, (long) file_name, (long) mode, (long) dev);
}

29
lib/linux/readlink.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/syscall.h>
#include <syscall.h>
#include <sys/stat.h>
ssize_t
readlink (char const *file_name, char *buffer, size_t size)
{
return _sys_call3 (SYS_readlink, (long) file_name, (long) buffer, (long) size);
}

29
lib/linux/symlink.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/syscall.h>
#include <syscall.h>
#include <unistd.h>
int
symlink (char const *old_name, char const *new_name)
{
return _sys_call2 (SYS_symlink, (long) old_name, (long) new_name);
}

View File

@ -0,0 +1,43 @@
DEFINE mov____%edi,%ebp 89fd
DEFINE mov____%esp,%edi 89e7
:_start
push___%ebp
mov____%esp,%ebp
sub____$i32,%esp %0x1054
mov____$i8,%eax !0
mov____%eax,0x32 &GLOBAL___stdin
mov____$i8,%eax !1
mov____%eax,0x32 &GLOBAL___stdout
mov____$i8,%eax !2
mov____%eax,0x32 &GLOBAL___stderr
mov____%ebp,%eax
add____$i8,%eax !4
movzbl_(%eax),%eax
add____$i8,%eax !3
shl____$i8,%eax !0x02
add____%ebp,%eax
mov____%eax,0x32 &GLOBAL_environ
mov____%esp,%edi ; M2-Planet calling convention pushes forward
mov____%ebp,%eax ; argc
add____$i8,%eax !4
movzbl_(%eax),%eax
push___%eax
mov____%ebp,%eax ; argv
add____$i8,%eax !8
push___%eax
mov____0x32,%eax &GLOBAL_environ
push___%eax
mov____%edi,%ebp ; M2-Planet calling convention
call32 %FUNCTION_main
add____$i8,%esp !0x0
test___%eax,%eax
mov____%eax,%ebx
mov____$i32,%eax %1
int____$0x80
hlt
leave
ret

View File

@ -0,0 +1,68 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mes/lib-mini.h"
int __stdin;
int __stdout;
int __stderr;
char **environ;
int main (int argc, char **argv, char **envp);
/* FIXME: this is going to be called `FUNCTION__start'
int
_start ()
{
asm ("mov____$i8,%eax !0");
asm ("mov____%eax,0x32 &GLOBAL___stdin");
asm ("mov____$i8,%eax !1");
asm ("mov____%eax,0x32 &GLOBAL___stdout");
asm ("mov____$i8,%eax !2");
asm ("mov____%eax,0x32 &GLOBAL___stderr");
asm ("mov____%ebp,%eax");
asm ("add____$i8,%eax !4");
asm ("movzbl_(%eax),%eax");
asm ("add____$i8,%eax !3");
asm ("shl____$i8,%eax !0x02");
asm ("add____%ebp,%eax");
asm ("mov____%eax,0x32 &GLOBAL_environ");
asm ("push___%eax");
asm ("mov____%ebp,%eax");
asm ("add____$i8,%eax !8");
asm ("push___%eax");
asm ("mov____%ebp,%eax");
asm ("add____$i8,%eax !4");
asm ("movzbl_(%eax),%eax");
asm ("push___%eax");
main ();
asm ("mov____%eax,%ebx");
asm ("mov____$i32,%eax %1");
asm ("int____$0x80");
asm ("hlt");
}
*/

View File

@ -0,0 +1,37 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
void
_exit ()
{
asm ("mov____$i32,%eax SYS_exit");
asm ("mov____0x8(%ebp),%ebx !-4");
asm ("int____$0x80");
}
void
_write (int filedes, void *buffer, int size)
{
asm ("mov____$i32,%eax SYS_write");
asm ("mov____0x8(%ebp),%ebx !-4");
asm ("mov____0x8(%ebp),%ecx !-8");
asm ("mov____0x8(%ebp),%edx !-12");
asm ("int____$0x80");
}

View File

@ -0,0 +1,139 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <linux/x86/syscall.h>
int errno;
int
__sys_call (int sys_call)
{
asm ("mov____0x8(%ebp),%eax !-4");
asm ("int____$0x80");
}
int
__sys_call1 (int sys_call, int one)
{
asm ("mov____0x8(%ebp),%eax !-4");
asm ("mov____0x8(%ebp),%ebx !-8");
asm ("int____$0x80");
}
int
__sys_call2 (int sys_call, int one, int two)
{
asm ("mov____0x8(%ebp),%eax !-4");
asm ("mov____0x8(%ebp),%ebx !-8");
asm ("mov____0x8(%ebp),%ecx !-12");
asm ("int____$0x80");
}
int
__sys_call3 (int sys_call, int one, int two, int three)
{
asm ("mov____0x8(%ebp),%eax !-4");
asm ("mov____0x8(%ebp),%ebx !-8");
asm ("mov____0x8(%ebp),%ecx !-12");
asm ("mov____0x8(%ebp),%edx !-16");
asm ("int____$0x80");
}
int
__sys_call4 (int sys_call, int one, int two, int three, int four)
{
asm ("mov____0x8(%ebp),%eax !-4");
asm ("mov____0x8(%ebp),%ebx !-8");
asm ("mov____0x8(%ebp),%ecx !-12");
asm ("mov____0x8(%ebp),%edx !-16");
asm ("mov____0x8(%ebp),%esi !-24");
asm ("int____$0x80");
}
int
_sys_call (int sys_call)
{
int r = __sys_call (sys_call);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
int
_sys_call1 (int sys_call, int one)
{
int r = __sys_call1 (sys_call, one);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
int
_sys_call2 (int sys_call, int one, int two)
{
int r = __sys_call2 (sys_call, one, two);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
int
_sys_call3 (int sys_call, int one, int two, int three)
{
int r = __sys_call3 (sys_call, one, two, three);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
int
_sys_call4 (int sys_call, int one, int two, int three, int four)
{
int r = __sys_call4 (sys_call, one, two, three, four);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}

32
lib/m2/_getcwd.c Normal file
View File

@ -0,0 +1,32 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib-mini.h>
#include <linux/syscall.h>
#include <syscall.h>
char *
_getcwd (char *buffer, int size)
{
int r = _sys_call2 (SYS_getcwd, buffer, size);
if (r >= 0)
return buffer;
return 0;
}

55
lib/m2/abtol.c Normal file
View File

@ -0,0 +1,55 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <ctype.h>
int
abtol (char **p, int base)
{
char *s = p[0];
int i = 0;
int sign_p = 0;
if (base == 0)
base = 10;
while (isspace (s[0]) != 0)
s = s + 1;
if (s[0] != 0 && s[0] == '+')
s = s + 1;
if (s[0] != 0 && s[0] == '-')
{
sign_p = 1;
s = s + 1;
}
while (isnumber (s[0], base) != 0)
{
i = i * base;
int m = '0';
if (s[0] > '9')
m = 'a' - 10;
i = i + s[0] - m;
s = s + 1;
}
p[0] = s;
if (sign_p != 0)
return -i;
return i;
}

21
lib/m2/access.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int access (char *file_name, int how);

26
lib/m2/atoi.c Normal file
View File

@ -0,0 +1,26 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int
atoi (char *string)
{
char *p = string;
return abtol (&p, 0);
}

28
lib/m2/brk.c Normal file
View File

@ -0,0 +1,28 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/syscall.h>
#include <syscall.h>
int /*long*/
brk (void *addr)
{
return _sys_call1 (SYS_brk, addr);
}

21
lib/m2/chmod.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int chmod (char *file_name, int mode);

27
lib/m2/clock_gettime.c Normal file
View File

@ -0,0 +1,27 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
struct timespec
{
int tv_sec;
int tv_nsec;
};
int clock_gettime (int clk_id, struct timespec *tp);

21
lib/m2/dup.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int dup (int old);

21
lib/m2/dup2.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int dup2 (int old, int new);

27
lib/m2/eputs.c Normal file
View File

@ -0,0 +1,27 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int
eputs (char *s)
{
int i = strlen (s);
write (__stderr, s, i);
return 0;
}

25
lib/m2/execv.c Normal file
View File

@ -0,0 +1,25 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int
execv (char *file_name, char **argv)
{
return execve (file_name, argv, environ);
}

21
lib/m2/execve.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int execve (char *file_name, char **argv, char **envp);

29
lib/m2/exit.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
void _exit (int code);
void
exit (int code)
{
_exit (code);
}

84
lib/m2/fdgetc.c Normal file
View File

@ -0,0 +1,84 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
#include <unistd.h>
// CONSTANT __FILEDES_MAX 512
int errno;
int *__ungetc_buf;
int
__ungetc_p (int filedes)
{
return __ungetc_buf[filedes] >= 0;
}
void
__ungetc_init ()
{
if (__ungetc_buf == 0)
{
int save_errno = errno;
__ungetc_buf = malloc ((__FILEDES_MAX + 1) * sizeof (int));
errno = save_errno;
memset (__ungetc_buf, -1, (__FILEDES_MAX + 1) * sizeof (int));
}
}
void
__ungetc_clear (int filedes)
{
__ungetc_buf[filedes] = -1;
}
void
__ungetc_set (int filedes, int c)
{
__ungetc_buf[filedes] = c;
}
int
fdgetc (int fd)
{
__ungetc_init ();
char c;
int i = __ungetc_buf[fd];
if (i >= 0)
__ungetc_buf[fd] = -1;
else
{
int r = read (fd, &c, 1);
if (r < 1)
return -1;
i = c;
}
if (i < 0)
i = i + 256;
return i;
}

28
lib/m2/fdputc.c Normal file
View File

@ -0,0 +1,28 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
int
fdputc (int c, int fd)
{
write (fd, &c, 1);
return 0;
}

21
lib/m2/fork.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int fork ();

37
lib/m2/getcwd.c Normal file
View File

@ -0,0 +1,37 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <limits.h>
#include <sys/types.h>
#include <mes/lib.h>
// CONSTANT PATH_MAX 1024
char *
getcwd (char *buffer, int size)
{
if (__getcwd_buf == 0)
__getcwd_buf = malloc (PATH_MAX);
char *buf = __itoa_buf;
if (buffer != 0)
return _getcwd (buffer, size);
return _getcwd (buf, PATH_MAX);
}

47
lib/m2/getenv.c Normal file
View File

@ -0,0 +1,47 @@
/* -*-comment-start: "
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <string.h>
#include <stdlib.h>
char *
getenv (char *s)
{
/* eputs ("\ngetenv s="); eputs (s); eputs ("\n"); */
char **p = environ;
int length = strlen (s);
while (p[0] != 0)
{
/* eputs ("getenv p[0]="); eputs (p[0]); eputs ("\n"); */
if (strncmp (s, p[0], length) == 0)
{
/* eputs ("found!\n"); */
char *q = p[0] + length;
if (q[0] == '=')
return q + 1;
}
/* else */
/* eputs ("not found!\n"); */
p = p + sizeof (char *); /* FIXME! */
}
return 0;
}

21
lib/m2/isatty.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int isatty (int filedes);

36
lib/m2/malloc.c Normal file
View File

@ -0,0 +1,36 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <string.h>
char *__brk = 0;
void *
malloc (int size)
{
if (__brk == 0)
__brk = brk (0);
if (brk (__brk + size) == -1)
return 0;
char *p = __brk;
__brk = __brk + size;
return p;
}

37
lib/m2/memchr.c Normal file
View File

@ -0,0 +1,37 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
void *
memchr (void *block, int c, size_t size)
{
char *p = block;
while (size != 0)
{
size = size - 1;
if (c == p[0])
return p;
p = p + 1;
}
return 0;
}

39
lib/m2/memcmp.c Normal file
View File

@ -0,0 +1,39 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
int
memcmp (void *s1, void *s2, int size)
{
if (size == 0)
return 0;
char *a = s1;
char *b = s2;
while (a[0] == b[0] && size > 0)
{
size = size - 1;
a = a + 1;
b = b + 1;
}
return a[0] - b[0];
}

38
lib/m2/memcpy.c Normal file
View File

@ -0,0 +1,38 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <string.h>
void *
memcpy (void *dest, void *src, int n)
{
char *p = dest;
while (n != 0)
{
n = n - 1;
dest[0] = src[0];
dest = dest + 1;
src = src + 1;
}
return p;
}

34
lib/m2/memset.c Normal file
View File

@ -0,0 +1,34 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
void *
memset (void *s, int c, int n)
{
char *p = s;
while (n != 0)
{
n = n - 1;
s[0] = c;
s = s + 1;
}
return p;
}

29
lib/m2/mes_open.c Normal file
View File

@ -0,0 +1,29 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int
mes_open (char *file_name, int flags, int mask)
{
__ungetc_init ();
int filedes = open (file_name, flags, mask);
if (filedes > 2)
__ungetc_clear (filedes);
return filedes;
}

24
lib/m2/missing.hex2 Normal file
View File

@ -0,0 +1,24 @@
:FUNCTION_execve
C3
:FUNCTION_access
C3
:FUNCTION_chmod
C3
:FUNCTION_isatty
C3
:FUNCTION_fork
C3
:FUNCTION_waitpid
C3
:FUNCTION_clock_gettime
C3
:FUNCTION_time
C3
:FUNCTION_getcwd
C3
:FUNCTION_dup
C3
:FUNCTION_dup2
C3
:FUNCTION_unlink
C3

69
lib/m2/ntoab.c Normal file
View File

@ -0,0 +1,69 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <assert.h>
#include <string.h>
char *__itoa_buf;
char *
ntoab (int x, int base, int signed_p)
{
if (__itoa_buf == 0)
__itoa_buf = malloc (20);
char *buf = __itoa_buf;
char *p = buf + 11;
p[0] = 0;
p = p - 1;
assert_msg (base > 0, "base > 0");
int sign_p = 0;
unsigned u;
if (signed_p != 0 && x < 0)
{
sign_p = 1;
u = -x;
}
else
u = x;
do
{
unsigned i;
i = u % base;
u = u / base;
if (i > 9)
p[0] = 'a' + i - 10;
else
p[0] = '0' + i;
p = p - 1;
}
while (u != 0);
if (sign_p && p[1] != '0')
{
p[0] = '-';
p = p - 1;
}
return p + 1;
}

33
lib/m2/open.c Normal file
View File

@ -0,0 +1,33 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <fcntl.h>
#include <stdarg.h>
int
open (char *file_name, int flags, int mask)
{
int r = _sys_call3 (SYS_open, file_name, flags, mask);
__ungetc_init ();
if (r > 2)
__ungetc_clear (r);
return r;
}

28
lib/m2/putchar.c Normal file
View File

@ -0,0 +1,28 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
int
putchar (int c)
{
write (__stdout, &c, 1);
return 0;
}

31
lib/m2/read.c Normal file
View File

@ -0,0 +1,31 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/syscall.h>
#include <syscall.h>
#include <mes/lib.h>
#include <fcntl.h>
int
read (int filedes, void *buffer, int size)
{
int bytes = _sys_call3 (SYS_read, filedes, buffer, size);
return bytes;
}

52
lib/m2/setenv.c Normal file
View File

@ -0,0 +1,52 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <string.h>
#include <stdlib.h>
int
setenv (char *s, char *v, int overwrite_p)
{
char **p = environ;
int length = strlen (s);
while (p[0] != 0)
{
if (strncmp (s, p[0], length) == 0)
{
char *q = p[0] + length;
if (q[0] == '=')
break;
}
p = p + 1;
}
char *entry = malloc (length + strlen (v) + 2);
int end_p = p[0] == 0;
p[0] = entry;
strcpy (entry, s);
strcpy (entry + length, "=");
strcpy (entry + length + 1, v);
entry[length + strlen (v) + 2] = 0;
if (end_p != 0)
p[1] = 0;
return 0;
}

33
lib/m2/strcmp.c Normal file
View File

@ -0,0 +1,33 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
int
strcmp (char *a, char *b)
{
while (a[0] != 0 && b[0] != 0 && a[0] == b[0])
{
a = a + 1;
b = b + 1;
}
return a[0] - b[0];
}

51
lib/m2/strcpy.c Normal file
View File

@ -0,0 +1,51 @@
/* -*-comment-start: "
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
char *
strcpy (char *dest, char *src)
{
/* eputs ("\nstrcpy: src="); */
/* eputs (src); */
/* eputs ("\n"); */
char *p = dest;
char *orig = dest;
/* eputs ("dest="); */
/* eputs (dest); */
/* eputs ("\n"); */
/* eputs ("c:" ); */
while (0 != src[0])
{
/* eputc (src[0]); */
/* eputs (" "); */
dest[0] = src[0];
dest = dest + 1;
src = src + 1;
}
dest[0] = 0;
/* eputs ("\n => orig="); */
/* eputs (orig); */
/* eputs ("\n"); */
return p;
}

30
lib/m2/strlen.c Normal file
View File

@ -0,0 +1,30 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int
strlen (char *s)
{
int i = 0;
while (s[i] != 0)
i = i + 1;
return i;
}

35
lib/m2/strncmp.c Normal file
View File

@ -0,0 +1,35 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int
strncmp (char *a, char *b, int size)
{
if (size == 0)
return 0;
while (a[0] != 0 && b[0] != 0 && a[0] == b[0] && size > 1)
{
size = size - 1;
a = a + 1;
b = b + 1;
}
return a[0] - b[0];
}

21
lib/m2/time.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int time (int *result);

21
lib/m2/unlink.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int unlink (char *file_name);

21
lib/m2/waitpid.c Normal file
View File

@ -0,0 +1,21 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
int waitpid (int pid, int *status_ptr, int options);

38
lib/m2/write.c Normal file
View File

@ -0,0 +1,38 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <errno.h>
int errno;
int
write (int filedes, void *buffer, int size)
{
int r = _write (filedes, buffer, size);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}

90
lib/m2/x86/x86_defs.M1 Normal file
View File

@ -0,0 +1,90 @@
## Copyright (C) 2017 Jeremiah Orians
## This file is part of M2-Planet.
##
## M2-Planet is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## M2-Planet is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
DEFINE ADD_IMMEDIATE_to_eax 81C0
DEFINE ADD_IMMEDIATE_to_ebp 81C5
DEFINE ADD_eax_to_ebx 01C3
DEFINE ADD_ebp_to_eax 01E8
DEFINE ADD_ebx_to_eax 01D8
DEFINE AND_eax_ebx 21D8
DEFINE CALL_IMMEDIATE E8
DEFINE CALL_eax FFD0
DEFINE CMP 39C3
DEFINE COPY_eax_to_ebx 89C3
DEFINE COPY_eax_to_ecx 89C1
DEFINE COPY_ebp_to_eax 89E8
DEFINE COPY_ebx_to_eax 89D8
DEFINE COPY_ebx_to_edx 89DA
DEFINE COPY_ecx_to_ebp 89CD
DEFINE COPY_edi_to_ebp 89fd
DEFINE COPY_esp_to_ebp 89E5
DEFINE COPY_esp_to_ecx 89E1
DEFINE COPY_esp_to_edi 89E7
DEFINE DIVIDE_eax_by_ebx_into_eax F7FB
DEFINE INT_80 CD80
DEFINE JUMP E9
DEFINE JUMP_EQ 0F84
DEFINE JUMP_NE 0F85
DEFINE JUMP_EQ8 74
DEFINE JUMP_NE8 75
DEFINE LOAD_BASE_ADDRESS_eax 8D85
DEFINE LOAD_BYTE 0FBE00
DEFINE LOAD_EFFECTIVE_ADDRESS 8D8424
DEFINE LOAD_EFFECTIVE_ADDRESS_ebx 8D9C24
DEFINE LOAD_EFFECTIVE_ADDRESS_ecx 8D8C24
DEFINE LOAD_EFFECTIVE_ADDRESS_edx 8D9424
DEFINE LOAD_ESP_IMMEDIATE_into_eax 8B8424
DEFINE LOAD_IMMEDIATE_eax B8
DEFINE LOAD_IMMEDIATE_ebx BB
DEFINE LOAD_IMMEDIATE_edx BA
DEFINE LOAD_INTEGER 8B00
DEFINE LOAD_INTEGER_ebx 8B1B
DEFINE LOAD_INTEGER_ecx 8B09
DEFINE LOAD_INTEGER_edx 8B12
DEFINE MODULUS_eax_from_ebx_into_ebx F7FB
DEFINE MOVEZBL 0FB6C0
DEFINE MOVE_ebx_to_eax 89D8
DEFINE MOVE_ecx_to_eax 89C8
DEFINE MOVE_edx_to_eax 89D0
DEFINE MULTIPLY_eax_by_ebx_into_eax F7E3
DEFINE NOP 00000000
DEFINE NOT_eax F7D0
DEFINE OR_eax_ebx 09D8
DEFINE POP_eax 58
DEFINE POP_ebx 5B
DEFINE POP_ebp 5D
DEFINE POP_edi 5F
DEFINE PUSH_eax 50
DEFINE PUSH_ebx 53
DEFINE PUSH_ebp 55
DEFINE PUSH_edi 57
DEFINE RETURN C3
DEFINE SAL_eax_Immediate8 C1E0
DEFINE SAL_eax_cl D3E0
DEFINE SAR_eax_cl D3F8
DEFINE SETE 0F94C0
DEFINE SETLE 0F9EC0
DEFINE SETL 0F9CC0
DEFINE SETGE 0F9DC0
DEFINE SETG 0F9FC0
DEFINE SETNE 0F95C0
DEFINE STORE_CHAR 8803
DEFINE STORE_INTEGER 8903
DEFINE SUBTRACT_eax_from_ebx_into_ebx 29C3
DEFINE TEST 85C0
DEFINE XCHG_eax_ebx 93
DEFINE XOR_ebx_eax_into_eax 31D8

View File

@ -28,5 +28,5 @@ __assert_fail (char *s)
eputs ("\n"); eputs ("\n");
char *fail = s; char *fail = s;
fail = 0; fail = 0;
*fail = 0; fail[0] = 0;
} }

53
lib/mes/abtod.c Normal file
View File

@ -0,0 +1,53 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
double
abtod (char const **p, int base)
{
char const *s = *p;
double d = 0;
int sign_p = 0;
if (!base)
base = 10;
double dbase = base;
long i = abtol (&s, base);
long f = 0;
long e = 0;
if (*s == '.')
{
s++;
f = abtol (&s, base);
}
if (*s == 'e')
{
s++;
e = abtol (&s, base);
}
d = i + f / dbase;
if (e < 0)
while (e++)
d = d / dbase;
while (e--)
d = d * dbase;
*p = s;
return sign_p ? -d : d;
}

View File

@ -24,23 +24,32 @@
long long
abtol (char const **p, int base) abtol (char const **p, int base)
{ {
char const *s = *p; char const *s = p[0];
int i = 0; int i = 0;
int sign = 1; int sign_p = 0;
if (!base) if (base == 0)
base = 10; base = 10;
if (*s && *s == '-') while (isspace (s[0]) != 0)
s = s + 1;
if (s[0] != 0 && s[0] == '+')
s = s + 1;
if (s[0] != 0 && s[0] == '-')
{ {
sign = -1; sign_p = 1;
s++; s = s + 1;
} }
while (isnumber (*s, base)) while (isnumber (s[0], base) != 0)
{ {
i *= base; i = i * base;
int m = *s > '9' ? 'a' - 10 : '0'; int m = '0';
i += *s - m; if (s[0] > '9')
s++; m = 'a' - 10;
i = i + s[0] - m;
s = s + 1;
} }
*p = s; p[0] = s;
return i * sign; if (sign_p != 0)
return -i;
return i;
} }

30
lib/mes/assert_msg.c Normal file
View File

@ -0,0 +1,30 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jeremiah Orians <jeremiah@pdp10.guru>
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <stdlib.h>
void
assert_msg (int bool, char *msg)
{
if (bool == 0)
__assert_fail (msg);
}

46
lib/mes/dtoab.c Normal file
View File

@ -0,0 +1,46 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <limits.h>
#include <string.h>
char *
dtoab (double d, int base, int signed_p)
{
static char dtoa_buf[40];
long i = (long) d;
char *p = ntoab (i, base, signed_p);
strcpy (dtoa_buf, p);
long f = (d - (double) i) * (double) 100000000;
if (f)
{
if (f < 0)
f = -f;
strcat (dtoa_buf, ".");
p = ntoab (f, base, 1);
strcat (dtoa_buf, p);
p = strchr (dtoa_buf, 0);
p--;
while (*p && *p == '0')
*p-- = 0;
}
return dtoa_buf;
}

View File

@ -19,12 +19,15 @@
*/ */
#include <mes/lib.h> #include <mes/lib.h>
#include <errno.h>
#include <limits.h> #include <limits.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <unistd.h> #include <unistd.h>
int __ungetc_buf[__FILEDES_MAX + 1] = { 0 }; int errno;
int *__ungetc_buf;
int int
__ungetc_p (int filedes) __ungetc_p (int filedes)
@ -35,8 +38,13 @@ __ungetc_p (int filedes)
void void
__ungetc_init () __ungetc_init ()
{ {
if (__ungetc_buf[__FILEDES_MAX] == 0) if (__ungetc_buf == 0)
memset (__ungetc_buf, -1, (__FILEDES_MAX + 1) * sizeof (int)); {
int save_errno = errno;
__ungetc_buf = malloc ((__FILEDES_MAX + 1) * sizeof (int));
errno = save_errno;
memset (__ungetc_buf, -1, (__FILEDES_MAX + 1) * sizeof (int));
}
} }
void void
@ -65,10 +73,10 @@ fdgetc (int fd)
int r = read (fd, &c, 1); int r = read (fd, &c, 1);
if (r < 1) if (r < 1)
return -1; return -1;
i = (int) c; i = c;
} }
if (i < 0) if (i < 0)
i += 256; i = i + 256;
return i; return i;
} }

View File

@ -19,7 +19,6 @@
*/ */
#include <mes/lib.h> #include <mes/lib.h>
#include <assert.h>
int int
fdungetc (int c, int fd) fdungetc (int c, int fd)
@ -32,7 +31,7 @@ fdungetc (int c, int fd)
eputs (" ***MES C LIB*** fdungetc ungetc buffer overflow fd="); eputs (" ***MES C LIB*** fdungetc ungetc buffer overflow fd=");
eputs (itoa (fd)); eputs (itoa (fd));
eputs ("\n"); eputs ("\n");
assert (0); assert_msg (0, "0");
} }
__ungetc_set (fd, c); __ungetc_set (fd, c);
return c; return c;

View File

@ -18,20 +18,32 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <assert.h>
#include <mes/lib.h> #include <mes/lib.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
char *__itoa_buf;
char * char *
ntoab (long x, int base, int signed_p) ntoab (long x, int base, int signed_p)
{ {
static char itoa_buf[20]; #if 0
char *p = itoa_buf + 11; if (! __itoa_buf)
*p-- = 0; __itoa_buf = malloc (20);
assert(base > 0); p = __itoa_buf + 11;
#else
static char buf[20];
char *p = buf + 19;
#endif
p[0] = 0;
p = p - 1;
assert_msg (base > 0, "base > 0");
int sign_p = 0; int sign_p = 0;
unsigned long u; unsigned long u;
if (signed_p && x < 0) if (signed_p != 0 && x < 0)
{ {
sign_p = 1; sign_p = 1;
u = -x; u = -x;
@ -48,12 +60,19 @@ ntoab (long x, int base, int signed_p)
i = u % base; i = u % base;
u = u / base; u = u / base;
#endif #endif
*p-- = i > 9 ? 'a' + i - 10 : '0' + i; if (i > 9)
p[0] = 'a' + i - 10;
else
p[0] = '0' + i;
p = p - 1;
} }
while (u); while (u != 0);
if (sign_p && *(p + 1) != '0') if (sign_p && p[1] != '0')
*p-- = '-'; {
p[0] = '-';
p = p - 1;
}
return p + 1; return p + 1;
} }

View File

@ -23,22 +23,13 @@
#include <unistd.h> #include <unistd.h>
int int
execl (char const *file_name, char const *arg, ...) vexec (char const *file_name, va_list ap)
{ {
if (__mes_debug () > 2) char *arg = va_arg (ap, char *);
{
eputs ("execl ");
eputs (file_name);
eputs ("\n");
}
char *argv[1000]; // POSIX minimum 4096 char *argv[1000]; // POSIX minimum 4096
int i = 0; int i = 0;
va_list ap; argv[i++] = (char *) file_name;
va_start (ap, arg);
argv[i++] = (char *)file_name;
arg = va_arg (ap, char const *);
while (arg) while (arg)
{ {
argv[i++] = arg; argv[i++] = arg;
@ -57,3 +48,20 @@ execl (char const *file_name, char const *arg, ...)
va_end (ap); va_end (ap);
return r; return r;
} }
int
execl (char const *file_name, char const *arg, ...)
{
va_list ap;
int r;
va_start (ap, arg);
if (__mes_debug () > 2)
{
eputs ("execl ");
eputs (file_name);
eputs ("\n");
}
r = vexec (file_name, ap);
va_end (ap);
return r;
}

47
lib/posix/execlp.c Normal file
View File

@ -0,0 +1,47 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <errno.h>
#include <stdarg.h>
int
execlp (char const *file_name, char const *arg, ...)
{
va_list ap;
int r;
va_start (ap, arg);
if (file_name[0] != '/')
file_name = search_path (file_name);
if (__mes_debug () > 2)
{
eputs ("execlp ");
eputs (file_name ? file_name : "0");
eputs ("\n");
}
if (!file_name)
{
errno = ENOENT;
return -1;
}
r = vexec (file_name, ap);
va_end (ap);
return r;
}

View File

@ -27,11 +27,17 @@ getenv (char const *s)
{ {
char **p = environ; char **p = environ;
int length = strlen (s); int length = strlen (s);
while (*p)
while (p[0] != 0)
{ {
if (!strncmp (s, *p, length) && *(*p + length) == '=') if (strncmp (s, p[0], length) == 0)
return (*p + length + 1); {
p++; char *q = p[0] + length;
if (q[0] == '=')
return q + 1;
}
p = p + 1;
} }
return 0; return 0;
} }

View File

@ -27,20 +27,25 @@ setenv (char const *s, char const *v, int overwrite_p)
{ {
char **p = environ; char **p = environ;
int length = strlen (s); int length = strlen (s);
while (*p) while (p[0])
{ {
if (!strncmp (s, *p, length) && *(*p + length) == '=') if (strncmp (s, p[0], length) == 0)
break; {
p++; char *q = p[0] + length;
if (q[0] == '=')
break;
}
p = p + 1;
} }
char *entry = malloc (length + strlen (v) + 2); char *entry = malloc (length + strlen (v) + 2);
int end_p = *p == 0; int end_p = p[0] == 0;
*p = entry; p[0] = entry;
strcpy (entry, s); strcpy (entry, s);
strcpy (entry + length, "="); strcpy (entry + length, "=");
strcpy (entry + length + 1, v); strcpy (entry + length + 1, v);
*(entry + length + strlen (v) + 2) = 0; entry[length + strlen (v) + 2] = 0;
if (end_p) if (end_p)
*++p = 0; p[1] = 0;
return 0; return 0;
} }

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -25,5 +25,8 @@
int int
fflush (FILE * stream) fflush (FILE * stream)
{ {
fsync ((long) stream); int filedes = (long) stream;
if (filedes < 3)
return 0;
return fsync (filedes);
} }

Some files were not shown because too many files have changed in this diff Show More