Jan Nieuwenhuizen
1e2e2f2a4a
core: Support switching of input stream.
...
* mes.c (g_stdin): New global.
(getchar): New function, use g_stdin.
(ungetchar): Use g_stdin.
(main): Initialize g_stdin to stdin.
2016-12-12 20:33:49 +01:00
Jan Nieuwenhuizen
2b373ff40f
Finalize psyntax integration.
...
* mes.c (sc_expand_env): Exclude primitives, expand native macros.
(symbol_expand_macro): New symbol.
* module/mes/psyntax-0.mes (properties-alist): New function.
* module/mes/psyntax-1.mes: Set expand-macro.
(define-syntax, syntax-rules, let-syntax): Remove macro.
* module/language/c/parser.mes: Use psyntax modules, remove syntax module.
* module/language/paren.mes: Likewise.
* scripts/repl.mes: Likewise.
* tests/match.test: Likewise.
* tests/record.test: Likewise.
* tests/psyntax.test (define-syntax swap!): Add test.
* module/mes/let-syntax.mes: Remove.
* module/mes/syntax.mes: Remove.
2016-12-12 20:33:49 +01:00
Jan Nieuwenhuizen
c851935d4d
core: Quoted internals are symbols.
...
* mes.c (begin_env): Rename from begin. Update callers.
(scm_begin, scm_if, scm_define, scm_set_x): Rename from symbol_*.
(symbol_begin, symbol_define, symbol_if, scm_lambda, scm_set_x): New symbols.
(mes_environment): Add them to environment, SYMBOL->SCM.
* define.c (define_env): Rename from define. Update callers.
* build-aux/mes-snarf.scm: Shadow internals (SCM) by their symbol.
2016-12-12 20:33:49 +01:00
Jan Nieuwenhuizen
f1ae9edd0d
core: Fix quasisyntax reading.
...
* mes.c (readword): Avoid unspecified behaviour in comma list.
2016-12-12 20:33:49 +01:00
Jan Nieuwenhuizen
d18542e25f
Initial psyntax integration.
...
* mes.c (sc_expand_env): New function.
(builtin_eval): Use it.
* module/mes/psyntax-0.mes: New file.
* module/mes/psyntax-1.mes: New file.
* tests/psyntax.test: New file.
* GNUmakefile (TESTS): Add it.
2016-12-12 20:33:49 +01:00
Jan Nieuwenhuizen
d34dba24f2
core: Add compile time switch for quasisyntax.
...
* mes.c [QUASISYNTAX]: New switch. Default off.
(builtin_eval) [QUASISYNTAX]: Handle syntax, unsyntax, quasisyntax.
* quasiquote.c (syntax, unsyntax, unsyntax_splicing, eval_quasisyntax,
add_unsyntaxers) [QUASISYNTAX]: Available only.
2016-12-12 20:33:49 +01:00
Jan Nieuwenhuizen
ad717d4bba
More error handling on apply_env.
...
* mes.c (apply_env): Assert if applying *unspecified*.
2016-12-12 20:33:49 +01:00
Jan Nieuwenhuizen
332d2655cf
Bugfix assq_ref_cache for running without environment cache.
...
* mes.c (assq_ref_cache) [!ENV_CACHE]: Return *undefined* if nothing
found.
2016-12-12 20:33:49 +01:00
Jan Nieuwenhuizen
2cad00527e
Error handling on failing set!.
...
* mes.c (set_env_x): Produce error message [WAS: dump core].
2016-12-12 20:33:49 +01:00
Jan Nieuwenhuizen
3b4e9f36c8
Simplify toplevel read.
...
* mes.c (read_file_env): Rename from read_file.
(load_file_env): New function.
(main): Use it.
2016-12-12 20:33:49 +01:00
Jan Nieuwenhuizen
1f511481a3
Fix values.
...
* mes.c (call): Respect any other non-value arguments.
* tests/scm.test (values, values 2, values 3, call-with-values): New test.
2016-12-12 20:33:49 +01:00
Jan Nieuwenhuizen
f593a5c9d7
Define garbage collector/jam collector primitives.
...
* mes.c (make_cell): New primitive alongside make_vector for allocation.
(cons, make_char, make_macro, make_number, make_ref,
internal_make_symbol, make_vector): Use it.
2016-12-12 20:33:49 +01:00
Jan Nieuwenhuizen
16f678a158
Implement strings and symbols as list of characters [WAS: c-string].
...
* mes.c (scm_t): Add string field.
(make_string, internal_lookup_symbol, internal_make_symbol,
make_symbol, lookup, readword): Take scm*. Update callers.
(display_helper): Support string field.
(append_char): New function.
(readstring): Use it. Produce scm*.
(cstring_to_list): New function.
(add_environment, internal_make_symbol): Use it.
(list_of_char_equal_p): New function.
(internal_lookup_symbol): Use it.
* lib.c (list_ref): New function.
* string.c (string_ref): Use it.
(string, string_append, string_length, substring, number_to_string,
string_to_symbol, symbol_to_string): Update to list-of-characters
implementation.
2016-12-12 20:33:48 +01:00
Jan Nieuwenhuizen
d209a18121
Introduce reference type, use vectors of SCM.
...
* mes.c (type): Add REF.
(scm_t): Add ref, change vector to *scm_t. Update users.
(alloc): New function.
(cons, make_char, make_macro, make_number, make_string,
internal_make_symbol, make_vector): Use it.
(make_ref): New function.
(vector_entry): New function.
(make_vector, list_to_vector, vector_set_x): Use it.
(vector_ref): Dereference REF entry.
(display_helper): Handle REF.
* lib.c (vector_to_list): Handle REF.
* type.c (ref_p): New function.
* tests/vector.test (vector list): New test.
Bugfix vector-ref.
* mes.c (vector-ref): Make copies of simple values. Fixes lalr.
* tests/vector.test (vector-set! 3): New test.
2016-12-12 20:33:48 +01:00
Jan Nieuwenhuizen
3849c48f79
Release 0.1.
...
* configure (VERSION): Bump to 0.1.
* mes.c (main): Likewise.
* module/mes/repl.mes: Likewise.
2016-11-20 21:47:47 +01:00
Jan Nieuwenhuizen
2823fca025
Avoid gratuitous consing with begin and quasiquote.
...
* mes.c (apply_env, main): Call begin rather than eval with cons'ed
symbol begin.
* module/mes/mes-0.mes (apply-env): Likewise.
* quasiquote.c (add_unquoters): cons global unquoters rather than
creating it fresh.
* module/mes/mes-0.mes (add-unquoters): Likewise.
2016-10-23 10:08:04 +02:00
Jan Nieuwenhuizen
011102bc12
Remove dead code.
...
* mes.c (mes_environment): Remove dead code.
2016-10-22 20:58:33 +02:00
Jan Nieuwenhuizen
6a4395869b
Move other post-boot and derived functions to lib.c.
...
* mes.c (c*r, length, last_pair, builtin_list, vector_to_list,
integer_to_char, char_to_integer, builtin_exit): Move to lib.c.
* lib.c: New file.
* GNUmakefile (mes.o): Depend on lib snarf output.
2016-10-22 20:51:32 +02:00
Jan Nieuwenhuizen
e282117de9
Move strings to string.c.
...
* mes.c (string, string_append, list_to_string, string_length,
string_ref, substring, number_to_string, string_to_symbol,
symbol_to_string): Move to string.c
* string.c: New file.
* GNUmakefile (mes.o): Depend on string snarf output.
2016-10-22 20:18:03 +02:00
Jan Nieuwenhuizen
be2f3bc274
Move arithmetic functions to math.c.
...
* mes.c (greater_p, less_p, is_p, minus, divide, modulo, multiply,
logior): Move to math.c.
* math.c: New file.
* GNUmakefile (mes.o): Depend on math snarf output.
2016-10-22 20:07:12 +02:00
Jan Nieuwenhuizen
27247383d7
Move define, define-macro to define.c.
...
* mes.c (define, define-macro): Move to define.c
* define.c: New file.
* GNUmakefile (mes.o): Depend on define snarf output.
2016-10-22 19:36:54 +02:00
Jan Nieuwenhuizen
bd7beddcda
Move quasiquote to quasiquote.c.
...
* mes.c (unquote, unquote_splicing, syntax, unsyntax,
unsyntax_splicing, eval_quasiquote, eval_quasisyntax, add_unquoters,
add_unsyntaxers): Move to quasiquote.c
* quasiquote.c: New file.
* GNUmakefile (mes.o): Depend on quasiquote snarf output.
2016-10-22 19:26:12 +02:00
Jan Nieuwenhuizen
2586f0bb2c
Move optional type predicates to type.c.
...
* mes.c (char_p, macro_p, number_p, pair_p, string_p, symbol_p,
vector_p, builtin_p, boolean_p): Move to type.c
* type.c: New file.
* GNUmakefile (mes.o): Depend on type snarf output.
* module/mes/loop-0.mes (cond, map, let, or, and not, evlis-env,
apply-env, eval-expand, uquote, add-unquoters, eval,
expand-macro-env, eval-begin-env, eval-if-env, sexp:define,
env:define, env:macro): Move to mes-0.mes.
* module/mes/mes-0.mes: New file.
* module/mes/type-0.mes: New file.
* scripts/include.mes: If BOOT, also include mes-0.mes. If TYPE0,
also include type-0.mes.
2016-10-22 12:16:19 +02:00
Jan Nieuwenhuizen
3e03a12a4d
Generate C header and includes using snarfing.
...
* mes.c: Move specific renames and n-args to alist annotation.
* build-aux/mes-snarf.scm: New file.
* GNUmakefile (mes.environment.h): Use it.
(mes.h): Remove.
(clean): Update.
(mes.o): New dependency rule.
* .gitignore: Update.
2016-10-21 22:44:50 +02:00
Jan Nieuwenhuizen
18aa0beaa9
Revert "Flip sign of cached symbols: only search cache if symbol is cached."
...
This reverts commit cef058be0d6ef5322f74e644bbcd96f1725c6327.
2016-10-22 18:13:37 +02:00
Jan Nieuwenhuizen
1684564ea1
Flip sign of cached symbols: only search cache if symbol is cached.
...
* mes.c (cache_save): Flip sign when caching and invalidating.
(cache_invalidate): Flip sign when invalidating.
2016-10-21 20:44:18 +02:00
Jan Nieuwenhuizen
2545605a69
Environment cache heuristicts.
...
* mes.c (ENV_HEAD): New define.
(assq_ref_cache): Use it.
2016-10-21 10:43:32 +02:00
Jan Nieuwenhuizen
46eca44fb4
boot: vector support.
...
* mes.c (make_vector): Change to scm interface.
(temp_number): New global.
(list_to_vector): Use it.
* module/mes/scm.mes (c:make-vector): New function.
* tests/scm.test: Remove vector tests.
* tests/vector.test: New file.
* GNUmakefile (TESTS): Add it.
2016-10-21 10:51:09 +02:00
Jan Nieuwenhuizen
c8e87f3021
Switch fat-c/boot using environment variable BOOT.
...
* GNUmakefile: check for BOOT, set CFLAGS.
* mes.c: Remove hardcoded BOOT define.
* scripts/include.mes: include loop-0 when BOOT is set.
2016-10-20 22:03:17 +02:00
Jan Nieuwenhuizen
1d0cbcd59c
Reduce eval/apply in core, extend in Scheme.
...
* mes.c (eval_env_)[BOOT]: Rename from eval_env. Remove define, defin-macro.
(eval_env): New function.
(make_macro): Swap parameter ordering.
(apply_env)[BOOT]: Support label.
2016-10-20 18:43:33 +02:00
Jan Nieuwenhuizen
1e62bbf8c9
Avoid adding top of environment to cache.
...
* mes.c (assq_ref_cache): Only consider caching symbols deeper than
4*CACHE_SIZE depth. 50% speedup.
2016-10-20 00:21:06 +02:00
Jan Nieuwenhuizen
7885096526
Implement environment cache.
...
* mes.c (cache_save, cache_lookup, cache_invalidate,
cache_invalidate_range): Implement cache for environment.
(assq_ref_cache): New function, perform cached lookups.
(builtin_eval,lookup_macro): Use it.
(set_cdr_x): Invalidate cache.
(set_x): Likewise.
(apply_env): Likewise.
2016-10-20 00:11:48 +02:00
Jan Nieuwenhuizen
d1b8f0ff0c
Introduce SCM type for special symbols.
...
* GNUmakefile (mes.h): Also export SCM to symbols.i
* mes.c: Introduce SCM type for special symbols.
(builtin_eval): Rename from eval_env. Update callers.
* module/mes/base-0.mes (eval): Remove.
* module/mes/repl.mes (repl): Use eval.
2016-10-20 19:19:32 +02:00
Jan Nieuwenhuizen
cdd903054c
Remove static primitives hack.
...
* mes.c (internal_primitive_p, internal_p, lookup_primitive,
mes_primitives): Remove.
2016-10-20 09:37:14 +02:00
Jan Nieuwenhuizen
9c986748e1
Refactor primitives lookup.
...
* mes.c (lookup_primitive_): Rename from internal_lookup_primitive,
use scm-compatible signature.
(lookup): Update caller.
(eval_env): Check for builtins first.
2016-10-19 07:22:15 +02:00
Jan Nieuwenhuizen
035b0a8d5d
Remove unused symbol.
...
* mes.c (symbol_cond): Remove.
2016-10-18 20:05:51 +02:00
Jan Nieuwenhuizen
2a8d3c57b7
Differentiate apply asserts.
...
* mes.c (apply_env): Split bool assert into bool, number and string.
2016-10-18 09:21:49 +02:00
Jan Nieuwenhuizen
b9bbac3d0c
Add display tag for builtin procedures.
...
* mes.c (display_helper): Show builtin functions as #<procedure ...>.
2016-10-18 09:08:42 +02:00
Jan Nieuwenhuizen
0eae7674b6
Remove macro expansion from apply.
...
mes.c (apply_env): Remove macro expansion.
2016-10-17 18:26:07 +02:00
Jan Nieuwenhuizen
ac4b1eed3f
Add --help, --version.
...
* mes.c (main): Handle --help, --version.
* scripts/include.mes: Handle --help.
* scripts/elf.mes: Pass any arguments on to mes.
* scripts/mescc.mes: Likewise.
* scripts/paren.mes: Likewise.
* scripts/repl.mes: Likewise.
2016-10-19 00:36:12 +02:00
Jan Nieuwenhuizen
bd2b81755a
Remove evcon (Sorry John).
...
* mes.c (evcon): Remove, remove callers.
* base0-if.mes (cond): Rename from disabled-cond.
2016-10-15 11:56:18 +02:00
Jan Nieuwenhuizen
83970245e5
Support quasisyntax.
...
* mes.c (eval_quasisyntax, add_unsyntaxers): New functions.
(eval_env): Use them.
2016-10-16 01:41:07 +02:00
Jan Nieuwenhuizen
2715e241e5
Add REPL.
...
* mes.c (expand_macro_env, force_output): New function. Use STRING_MAX
for string buffers throughout. (eval_env, eval_begin_env): Rename
from eval, eval_begin. Update callers.
* repl.mes: New file.
* base.mes (list?): Move from scm.mes.
* scm.mes (eval, apply, primitive-eval, expand-macro): New function.
* GNUmakefile: New repl target.
2016-10-16 09:44:52 +02:00
Jan Nieuwenhuizen
422b6e6ce9
Avoid 90% of cdr'ing environment, assuming static primitives.
...
* mes.c (internal_primitive_p)[STATIC_PRIMITIVES: New function.
(lookup_macro)[STATIC_PRIMITIVES]: Use it.
(internal_lookup_primitive)[STATIC_PRIMITIVES]: New function.
(lookup)[STATIC_PRIMITIVES]: Use it.
(mes_primitives)[STATIC_PRIMITIVES]: New function.
(main): Use it.
* base0-if.mes (disabled-cond): Rename from xcond.
* GNUmakefile: Add commented profiling CFLAGS.
2016-10-12 21:14:06 +02:00
Jan Nieuwenhuizen
1bb3d1de11
speedup: use ->car etc.
2016-10-08 17:00:32 +02:00
Jan Nieuwenhuizen
c5e3e3818d
Avoid out-of-spec strncat usage.
...
mes.c (readword): Use character assignment instead of strncat. Fixes
Valgrind nit.
2016-10-11 18:50:14 +02:00
Jan Nieuwenhuizen
513bd09f76
Discern between primitive atoms and symbols.
...
* mes.c (internal_symbol_p): New function.
(eval): Use it.
2016-10-11 07:10:01 +02:00
Jan Nieuwenhuizen
a265f933d8
speedup: use ->car etc.
2016-10-08 17:00:32 +02:00
Jan Nieuwenhuizen
4514be76d9
use IF as primitive, drop using cond/evcon only option.
2016-10-08 16:54:59 +02:00
Jan Nieuwenhuizen
7c759e0670
c++ type-safety.
2016-10-08 10:14:17 +02:00
Jan Nieuwenhuizen
e504998b03
assq: use while instead of recursion.
2016-10-08 08:47:23 +02:00
Jan Nieuwenhuizen
509bf3956e
mes.c: uniquify symbols.
2016-10-08 08:41:30 +02:00
Jan Nieuwenhuizen
ec8553dc4f
mes.c: implement string->list.
2016-08-13 18:42:11 +02:00
Jan Nieuwenhuizen
697858f670
Revert "mes.c: use single malloc with arena."
...
This reverts commit 38c364faeff430a5ee28f402d24b073f6bf9a548.
2016-09-25 10:13:09 +02:00
Jan Nieuwenhuizen
b955b84d20
mes.c: use single malloc with arena.
2016-08-13 00:58:00 +02:00
Jan Nieuwenhuizen
2097e9e4ef
mes.c: display, newline: take optional port; add write-char, read hex #xXX.
2016-08-12 14:17:20 +02:00
Jan Nieuwenhuizen
287c0284fe
Use IF iso COND as primitive; keep COND primitive as option.
2016-07-27 08:49:45 +02:00
Jan Nieuwenhuizen
56fcde0966
macro hax0rz
2016-07-27 00:32:30 +02:00
Jan Nieuwenhuizen
3864d434fc
split-up test suite, implement quasiquote in scheme.
2016-07-25 14:39:56 +02:00
Jan Nieuwenhuizen
f170735edb
mescc: mes parses simplest main with lalr.
2016-07-25 01:12:22 +02:00
Jan Nieuwenhuizen
479d988e42
mes.c: add set-cdr, substring, string-ref.
2016-07-25 00:06:18 +02:00
Jan Nieuwenhuizen
87678add4a
mes.c: support whitespace characters.
2016-07-24 23:41:16 +02:00
Jan Nieuwenhuizen
46387d411b
mes.c: when reading `EOF', defer read control to program.
2016-07-24 18:28:45 +02:00
Jan Nieuwenhuizen
8dacd68fe8
mes.c, scm.c: add read-char, peek-char, char=?, char-alphabetic?.
2016-07-24 17:35:31 +02:00
Jan Nieuwenhuizen
2983578531
mes.c: add logior.
2016-07-24 17:21:30 +02:00
Jan Nieuwenhuizen
b5ab19aab7
mes.c: add quotient and modulo.
2016-07-24 15:25:16 +02:00
Jan Nieuwenhuizen
87c52609ff
mes.c: less_p, greater_p, is_p: take multiple arguments.
2016-07-24 15:26:49 +02:00
Jan Nieuwenhuizen
675bc3dead
mes.c: display_helper fix for vector.
2016-07-24 15:25:47 +02:00
Jan Nieuwenhuizen
99762c07ca
mes.c: fix apply.
2016-07-24 13:27:05 +02:00
Jan Nieuwenhuizen
8c1a5f19da
fix for-each.
2016-07-24 12:40:44 +02:00
Jan Nieuwenhuizen
478087abe4
mes.c: grok #\tab.
2016-07-24 12:06:05 +02:00
Jan Nieuwenhuizen
d4e335b447
mes.c: add syntax, quasisyntax to reader....
2016-07-24 00:40:37 +02:00
Jan Nieuwenhuizen
28ae662e0e
srfi-9 records!
2016-07-24 00:14:40 +02:00
Jan Nieuwenhuizen
711a29f4f9
mes.c: refactor begin and closures. Fixes bugs/top.mes.
2016-07-24 00:01:31 +02:00
Jan Nieuwenhuizen
ab381c841a
mes.c: remove hacks
2016-07-23 15:11:32 +02:00
Jan Nieuwenhuizen
5126e16e66
trying to get records up....WIP
2016-07-23 14:39:33 +02:00
Jan Nieuwenhuizen
b63444d919
mes.c: barf on unknown symbols.
2016-07-23 11:51:06 +02:00
Jan Nieuwenhuizen
efdd84b4c4
mes.c: add new macro type, junk *macro* hack.
2016-07-22 17:13:51 +02:00
Jan Nieuwenhuizen
04f3323f10
mes.c: store actual environment with closures.
2016-07-22 12:23:23 +02:00
Jan Nieuwenhuizen
dbbfcb5899
fix closure 5
2016-07-22 09:00:32 +02:00
Jan Nieuwenhuizen
24be64787b
mes.c: store enviroment depth in closures. Fixes c1, c3 and more.
2016-07-19 21:37:39 +02:00
Jan Nieuwenhuizen
61bbbdffbf
mes.c: move begin_env into eval, decruft.
2016-07-19 18:18:27 +02:00
Jan Nieuwenhuizen
80e6f95f91
fix some tests.
2016-07-18 22:59:33 +02:00
Jan Nieuwenhuizen
3a28828bdf
remove booting into mes (would need VM), boot.mes; rewrite test.mes.
2016-07-18 22:43:16 +02:00
Jan Nieuwenhuizen
be2326f351
unquoting fix.
2016-07-17 23:43:16 +02:00
Jan Nieuwenhuizen
005f146b68
no closuring in macro body...
2016-07-17 23:07:35 +02:00
Jan Nieuwenhuizen
59cdf9632f
closures: mostly supported...
2016-07-17 22:15:31 +02:00
Jan Nieuwenhuizen
bfb2f42cd5
mes.c: single-statement body lambda closures.
2016-07-17 15:59:21 +02:00
Jan Nieuwenhuizen
0a497a2765
mes.c: add boolean_p.
2016-07-17 13:32:52 +02:00
Jan Nieuwenhuizen
f19d6dfde4
mes.c: fix symbol? for nil.
2016-07-17 13:16:10 +02:00
Jan Nieuwenhuizen
71a89be833
mes.c: evcon: support clause without cdr. Fixes or.
2016-07-17 12:57:06 +02:00
Jan Nieuwenhuizen
341d064a34
hax0rz..ugh + next name? test in macro.mes.
2016-07-17 11:37:22 +02:00
Jan Nieuwenhuizen
40bbb3dff1
mes.c: another macro clue-bat in apply. now macro.mes equals guile -s macro.mes.
2016-07-17 10:38:29 +02:00
Jan Nieuwenhuizen
c565e2fc22
mes.c: begin_env: bugfix, keep going in body after set!
2016-07-17 09:17:47 +02:00
Jan Nieuwenhuizen
6baafb2380
mes.c: bugfix for eval_quasiquote: stay in quasiquote mode after next quote.
2016-07-17 09:06:48 +02:00
Jan Nieuwenhuizen
be12facd6d
support define-macro inside eval (i.e., inside define-macro)
2016-07-16 23:35:07 +02:00
Jan Nieuwenhuizen
d1a089caed
mes.c: move define, define-macro into begin_env, remove loop. fixes inner defines.
2016-07-16 22:43:13 +02:00
Jan Nieuwenhuizen
dc8325ded3
implement unquote-splicing, cleanup some macros
2016-07-16 17:18:11 +02:00
Jan Nieuwenhuizen
02dc00d11c
update macro, fix andmap.
2016-07-16 13:24:38 +02:00
Jan Nieuwenhuizen
c1886195e6
add scheme apply, rename apply-> apply_env.
2016-07-16 08:17:56 +02:00