2016-10-17 17:26:07 +01:00
|
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
2016-05-28 15:39:44 +01:00
|
|
|
|
* Mes --- Maxwell Equations of Software
|
2017-11-21 18:22:26 +00:00
|
|
|
|
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2016-05-28 15:39:44 +01:00
|
|
|
|
*
|
|
|
|
|
* This file is part of Mes.
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* 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 Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-05-02 22:30:46 +01:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <mlibc.h>
|
core: Integrate garbage collector/jam scraper.
* mes.c (r0, r1, r2, r3, stack): New globals.
(gc_loop): Handle MACRO and SCM.
(gc_copy): Handle FUNCTION, allow for pre-allocated SCM and SYMBOL.
(assq): Flag any BROKEN_HEARTs.
(vm_call): New function. Enables moving C stack to GC stack.
(evlis_env, apply_env, eval_env, expand_macro_env, begin_env,
if_env): Use vm_call-indirection.
(call_lambda): New function.
(vm_apply_env): Rename from apply_env. Remove parameters, instead
use r1, r2 and r0.
(vm_evlis_env, vm_eval_env, vm_expand_macro_env, vm_begin_env,
vm_if_env): Likewise.
(acons): New function.
(mes_environment) [!MES_FULL, MES_MINI]: Add cpp switches to create minimally
filled environment, for debugging.
(main): Print free value at exit.
* define.c (define_env): Use vm_call-indirection.
(vm_define_env): Rename from define_env.
* quasiquote.c (eval_quasiquote): Use vm_call-indirection.
(vm_eval_quasiquote): Rename from eval_quasiquote.
* tests/gc-2.test: New test.
tests/gc-2a.test: New test.
tests/gc-3.test: New test.
2016-10-28 17:42:03 +01:00
|
|
|
|
|
2018-02-03 20:43:52 +00:00
|
|
|
|
int ARENA_SIZE = 20000000; // 32B: 100 MiB, 64b: 200 MiB
|
|
|
|
|
#if __MESC__
|
2018-04-11 19:46:06 +01:00
|
|
|
|
int MAX_ARENA_SIZE = 172100000; // 32b: ~ 2GiB
|
mes: resurrect full reader in C core.
* module/mes/read-0.mes (defined?): New function.
(eat-whitespace, read-env, read-word, read-block-comment,
read-line-comment, read-list, read-character, read-hex, read-octal,
reader:read-string, lookup, read-hash, read-word): Only define if
not %c-reader.
* module/mes/base-0.mes (defined?): Remove.
* src/mes.c[MES_C_READER]: Set ARENA_SIZE=10000000.
(scm_symbol_quasiquote scm_symbol_unquote,
scm_symbol_unquote_splicing, scm_symbol_syntax,
scm_symbol_quasisyntax, scm_symbol_unsyntax,
scm_symbol_unsyntax_splicing): New symbol.
(scm_symbol_c_reader): New symbol.
(MAKE_KEYWORD)[MES_C_READER]: New define.
(mes_symbols): Define %c_reader.
* src/reader.c (read_word_)[MES_C_READER]: Extend to full Scheme
reader.
(eat_whitespace)[MES_C_READER]: Likewise.
(read_block_comment, read_hash, read_word, read_character,
read_octal, read_hex, append_char, read_string)[MES_C_READER]:
Likewise.
* make.scm (bin.gcc,bin.mescc): Define MES_C_READER=1.
2017-11-29 20:42:50 +00:00
|
|
|
|
#else
|
2018-04-11 19:46:06 +01:00
|
|
|
|
int MAX_ARENA_SIZE = 200000000; // 32b: 2.3GiB, 64b: 4.6GiB
|
mes: resurrect full reader in C core.
* module/mes/read-0.mes (defined?): New function.
(eat-whitespace, read-env, read-word, read-block-comment,
read-line-comment, read-list, read-character, read-hex, read-octal,
reader:read-string, lookup, read-hash, read-word): Only define if
not %c-reader.
* module/mes/base-0.mes (defined?): Remove.
* src/mes.c[MES_C_READER]: Set ARENA_SIZE=10000000.
(scm_symbol_quasiquote scm_symbol_unquote,
scm_symbol_unquote_splicing, scm_symbol_syntax,
scm_symbol_quasisyntax, scm_symbol_unsyntax,
scm_symbol_unsyntax_splicing): New symbol.
(scm_symbol_c_reader): New symbol.
(MAKE_KEYWORD)[MES_C_READER]: New define.
(mes_symbols): Define %c_reader.
* src/reader.c (read_word_)[MES_C_READER]: Extend to full Scheme
reader.
(eat_whitespace)[MES_C_READER]: Likewise.
(read_block_comment, read_hash, read_word, read_character,
read_octal, read_hex, append_char, read_string)[MES_C_READER]:
Likewise.
* make.scm (bin.gcc,bin.mescc): Define MES_C_READER=1.
2017-11-29 20:42:50 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2018-04-11 19:46:06 +01:00
|
|
|
|
int GC_SAFETY = 50000;
|
2016-05-15 23:07:44 +01:00
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
char *g_arena = 0;
|
2016-12-14 18:02:19 +00:00
|
|
|
|
typedef int SCM;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
|
|
|
|
|
int g_debug = 0;
|
|
|
|
|
int g_free = 0;
|
|
|
|
|
|
|
|
|
|
SCM g_continuations = 0;
|
|
|
|
|
SCM g_symbols = 0;
|
|
|
|
|
SCM g_stack = 0;
|
|
|
|
|
// a/env
|
|
|
|
|
SCM r0 = 0;
|
|
|
|
|
// param 1
|
|
|
|
|
SCM r1 = 0;
|
|
|
|
|
// save 2+load/dump
|
|
|
|
|
SCM r2 = 0;
|
|
|
|
|
// continuation
|
|
|
|
|
SCM r3 = 0;
|
2017-12-09 07:33:50 +00:00
|
|
|
|
// macro
|
|
|
|
|
SCM g_macros = 1; // cell_nil
|
2017-04-10 18:13:20 +01:00
|
|
|
|
|
2017-12-09 07:33:50 +00:00
|
|
|
|
|
|
|
|
|
enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVARIABLE, TVECTOR, TBROKEN_HEART};
|
2017-04-10 18:13:20 +01:00
|
|
|
|
|
|
|
|
|
#if !_POSIX_SOURCE
|
|
|
|
|
struct scm {
|
|
|
|
|
enum type_t type;
|
|
|
|
|
SCM car;
|
|
|
|
|
SCM cdr;
|
|
|
|
|
};
|
|
|
|
|
struct function {
|
|
|
|
|
int (*function) (void);
|
|
|
|
|
int arity;
|
|
|
|
|
char *name;
|
|
|
|
|
};
|
|
|
|
|
#else
|
2016-11-21 08:28:34 +00:00
|
|
|
|
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);
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
struct function {
|
2016-11-03 20:28:05 +00:00
|
|
|
|
union {
|
|
|
|
|
function0_t function0;
|
|
|
|
|
function1_t function1;
|
|
|
|
|
function2_t function2;
|
|
|
|
|
function3_t function3;
|
|
|
|
|
functionn_t functionn;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
};
|
2016-11-03 20:28:05 +00:00
|
|
|
|
int arity;
|
2017-03-09 22:27:12 +00:00
|
|
|
|
char const *name;
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
};
|
|
|
|
|
struct scm {
|
2016-11-21 08:28:34 +00:00
|
|
|
|
enum type_t type;
|
2016-05-28 15:39:44 +01:00
|
|
|
|
union {
|
2017-03-09 22:27:12 +00:00
|
|
|
|
char const* name;
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM car;
|
|
|
|
|
SCM ref;
|
2017-12-09 07:33:50 +00:00
|
|
|
|
SCM string;
|
|
|
|
|
SCM variable;
|
2016-07-11 09:38:02 +01:00
|
|
|
|
int length;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
};
|
2016-05-28 15:39:44 +01:00
|
|
|
|
union {
|
|
|
|
|
int value;
|
2016-11-19 21:31:30 +00:00
|
|
|
|
int function;
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM cdr;
|
2016-12-23 17:48:36 +00:00
|
|
|
|
SCM closure;
|
2016-12-28 21:04:57 +00:00
|
|
|
|
SCM continuation;
|
2017-12-09 07:33:50 +00:00
|
|
|
|
SCM global_p;
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM macro;
|
|
|
|
|
SCM vector;
|
2016-10-26 18:44:36 +01:00
|
|
|
|
int hits;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
};
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
};
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if __MESC__
|
|
|
|
|
//FIXME
|
|
|
|
|
char *foobar = 0;
|
|
|
|
|
struct scm *g_cells = foobar;
|
|
|
|
|
struct scm *g_news = foobar;
|
|
|
|
|
#else
|
|
|
|
|
struct scm *g_cells = 0;
|
|
|
|
|
struct scm *g_news = 0;
|
|
|
|
|
#endif
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
|
|
|
|
|
struct scm scm_nil = {TSPECIAL, "()",0};
|
|
|
|
|
struct scm scm_f = {TSPECIAL, "#f",0};
|
|
|
|
|
struct scm scm_t = {TSPECIAL, "#t",0};
|
|
|
|
|
struct scm scm_dot = {TSPECIAL, ".",0};
|
|
|
|
|
struct scm scm_arrow = {TSPECIAL, "=>",0};
|
|
|
|
|
struct scm scm_undefined = {TSPECIAL, "*undefined*",0};
|
|
|
|
|
struct scm scm_unspecified = {TSPECIAL, "*unspecified*",0};
|
|
|
|
|
struct scm scm_closure = {TSPECIAL, "*closure*",0};
|
|
|
|
|
struct scm scm_circular = {TSPECIAL, "*circular*",0};
|
|
|
|
|
struct scm scm_begin = {TSPECIAL, "*begin*",0};
|
|
|
|
|
|
|
|
|
|
struct scm scm_symbol_dot = {TSYMBOL, "*dot*",0};
|
|
|
|
|
struct scm scm_symbol_lambda = {TSYMBOL, "lambda",0};
|
|
|
|
|
struct scm scm_symbol_begin = {TSYMBOL, "begin",0};
|
|
|
|
|
struct scm scm_symbol_if = {TSYMBOL, "if",0};
|
|
|
|
|
struct scm scm_symbol_quote = {TSYMBOL, "quote",0};
|
2017-12-09 07:24:38 +00:00
|
|
|
|
struct scm scm_symbol_define = {TSYMBOL, "define",0};
|
|
|
|
|
struct scm scm_symbol_define_macro = {TSYMBOL, "define-macro",0};
|
mes: resurrect full reader in C core.
* module/mes/read-0.mes (defined?): New function.
(eat-whitespace, read-env, read-word, read-block-comment,
read-line-comment, read-list, read-character, read-hex, read-octal,
reader:read-string, lookup, read-hash, read-word): Only define if
not %c-reader.
* module/mes/base-0.mes (defined?): Remove.
* src/mes.c[MES_C_READER]: Set ARENA_SIZE=10000000.
(scm_symbol_quasiquote scm_symbol_unquote,
scm_symbol_unquote_splicing, scm_symbol_syntax,
scm_symbol_quasisyntax, scm_symbol_unsyntax,
scm_symbol_unsyntax_splicing): New symbol.
(scm_symbol_c_reader): New symbol.
(MAKE_KEYWORD)[MES_C_READER]: New define.
(mes_symbols): Define %c_reader.
* src/reader.c (read_word_)[MES_C_READER]: Extend to full Scheme
reader.
(eat_whitespace)[MES_C_READER]: Likewise.
(read_block_comment, read_hash, read_word, read_character,
read_octal, read_hex, append_char, read_string)[MES_C_READER]:
Likewise.
* make.scm (bin.gcc,bin.mescc): Define MES_C_READER=1.
2017-11-29 20:42:50 +00:00
|
|
|
|
|
|
|
|
|
struct scm scm_symbol_quasiquote = {TSYMBOL, "quasiquote", 0};
|
|
|
|
|
struct scm scm_symbol_unquote = {TSYMBOL, "unquote", 0};
|
|
|
|
|
struct scm scm_symbol_unquote_splicing = {TSYMBOL, "unquote-splicing", 0};
|
|
|
|
|
struct scm scm_symbol_syntax = {TSYMBOL, "syntax",0};
|
|
|
|
|
struct scm scm_symbol_quasisyntax = {TSYMBOL, "quasisyntax", 0};
|
|
|
|
|
struct scm scm_symbol_unsyntax = {TSYMBOL, "unsyntax", 0};
|
|
|
|
|
struct scm scm_symbol_unsyntax_splicing = {TSYMBOL, "unsyntax-splicing", 0};
|
|
|
|
|
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
struct scm scm_symbol_set_x = {TSYMBOL, "set!",0};
|
|
|
|
|
|
|
|
|
|
struct scm scm_symbol_sc_expand = {TSYMBOL, "sc-expand",0};
|
|
|
|
|
struct scm scm_symbol_macro_expand = {TSYMBOL, "macro-expand",0};
|
2017-12-09 07:33:50 +00:00
|
|
|
|
struct scm scm_symbol_portable_macro_expand = {TSYMBOL, "portable-macro-expand",0};
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
struct scm scm_symbol_sc_expander_alist = {TSYMBOL, "*sc-expander-alist*",0};
|
|
|
|
|
|
|
|
|
|
struct scm scm_symbol_call_with_values = {TSYMBOL, "call-with-values",0};
|
|
|
|
|
struct scm scm_call_with_current_continuation = {TSPECIAL, "*call/cc*",0};
|
|
|
|
|
struct scm scm_symbol_call_with_current_continuation = {TSYMBOL, "call-with-current-continuation",0};
|
|
|
|
|
struct scm scm_symbol_current_module = {TSYMBOL, "current-module",0};
|
|
|
|
|
struct scm scm_symbol_primitive_load = {TSYMBOL, "primitive-load",0};
|
|
|
|
|
struct scm scm_symbol_read_input_file = {TSYMBOL, "read-input-file",0};
|
|
|
|
|
struct scm scm_symbol_write = {TSYMBOL, "write",0};
|
|
|
|
|
struct scm scm_symbol_display = {TSYMBOL, "display",0};
|
|
|
|
|
|
|
|
|
|
struct scm scm_symbol_throw = {TSYMBOL, "throw",0};
|
2018-01-25 06:00:48 +00:00
|
|
|
|
struct scm scm_symbol_not_a_number = {TSYMBOL, "not-a-number",0};
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
struct scm scm_symbol_not_a_pair = {TSYMBOL, "not-a-pair",0};
|
|
|
|
|
struct scm scm_symbol_system_error = {TSYMBOL, "system-error",0};
|
|
|
|
|
struct scm scm_symbol_wrong_number_of_args = {TSYMBOL, "wrong-number-of-args",0};
|
|
|
|
|
struct scm scm_symbol_wrong_type_arg = {TSYMBOL, "wrong-type-arg",0};
|
|
|
|
|
struct scm scm_symbol_unbound_variable = {TSYMBOL, "unbound-variable",0};
|
|
|
|
|
|
|
|
|
|
struct scm scm_symbol_argv = {TSYMBOL, "%argv",0};
|
|
|
|
|
struct scm scm_symbol_mes_prefix = {TSYMBOL, "%prefix",0};
|
|
|
|
|
struct scm scm_symbol_mes_version = {TSYMBOL, "%version",0};
|
|
|
|
|
|
|
|
|
|
struct scm scm_symbol_car = {TSYMBOL, "car",0};
|
|
|
|
|
struct scm scm_symbol_cdr = {TSYMBOL, "cdr",0};
|
2017-12-09 07:33:50 +00:00
|
|
|
|
struct scm scm_symbol_pmatch_car = {TSYMBOL, "pmatch-car",0};
|
|
|
|
|
struct scm scm_symbol_pmatch_cdr = {TSYMBOL, "pmatch-cdr",0};
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
|
|
|
|
|
struct scm scm_vm_evlis = {TSPECIAL, "*vm-evlis*",0};
|
|
|
|
|
struct scm scm_vm_evlis2 = {TSPECIAL, "*vm-evlis2*",0};
|
|
|
|
|
struct scm scm_vm_evlis3 = {TSPECIAL, "*vm-evlis3*",0};
|
|
|
|
|
struct scm scm_vm_apply = {TSPECIAL, "core:apply",0};
|
|
|
|
|
struct scm scm_vm_apply2 = {TSPECIAL, "*vm-apply2*",0};
|
|
|
|
|
struct scm scm_vm_eval = {TSPECIAL, "core:eval",0};
|
|
|
|
|
|
2017-12-09 07:33:50 +00:00
|
|
|
|
struct scm scm_vm_eval_pmatch_car = {TSPECIAL, "*vm-eval-pmatch-car*",0};
|
|
|
|
|
struct scm scm_vm_eval_pmatch_cdr = {TSPECIAL, "*vm-eval-pmatch-cdr*",0};
|
2017-12-09 07:24:38 +00:00
|
|
|
|
struct scm scm_vm_eval_define = {TSPECIAL, "*vm-eval-define*",0};
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
|
|
|
|
|
struct scm scm_vm_eval_set_x = {TSPECIAL, "*vm-eval-set!*",0};
|
2018-03-04 09:05:55 +00:00
|
|
|
|
struct scm scm_vm_eval_macro_expand_eval = {TSPECIAL, "*vm:eval-macro-expand-eval*",0};
|
|
|
|
|
struct scm scm_vm_eval_macro_expand_expand = {TSPECIAL, "*vm:eval-macro-expand-expand*",0};
|
2017-03-27 19:14:48 +01:00
|
|
|
|
struct scm scm_vm_eval_check_func = {TSPECIAL, "*vm-eval-check-func*",0};
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
struct scm scm_vm_eval2 = {TSPECIAL, "*vm-eval2*",0};
|
|
|
|
|
struct scm scm_vm_macro_expand = {TSPECIAL, "core:macro-expand",0};
|
2018-03-04 09:05:55 +00:00
|
|
|
|
struct scm scm_vm_macro_expand_define = {TSPECIAL, "*vm:core:macro-expand-define*",0};
|
|
|
|
|
struct scm scm_vm_macro_expand_define_macro = {TSPECIAL, "*vm:core:macro-expand-define-macro*",0};
|
|
|
|
|
struct scm scm_vm_macro_expand_lambda = {TSPECIAL, "*vm:core:macro-expand-lambda*",0};
|
|
|
|
|
struct scm scm_vm_macro_expand_set_x = {TSPECIAL, "*vm:core:macro-expand-set!*",0};
|
|
|
|
|
struct scm scm_vm_begin_expand_primitive_load = {TSPECIAL, "*vm:core:begin-expand-primitive-load*",0};
|
|
|
|
|
struct scm scm_vm_begin_primitive_load = {TSPECIAL, "*vm:core:begin-primitive-load*",0};
|
|
|
|
|
struct scm scm_vm_macro_expand_car = {TSPECIAL, "*vm:core:macro-expand-car*",0};
|
|
|
|
|
struct scm scm_vm_macro_expand_cdr = {TSPECIAL, "*vm:macro-expand-cdr*",0};
|
|
|
|
|
struct scm scm_vm_begin_expand = {TSPECIAL, "*vm:begin-expand*",0};
|
|
|
|
|
struct scm scm_vm_begin_expand_eval = {TSPECIAL, "*vm:begin-expand-eval*",0};
|
|
|
|
|
struct scm scm_vm_begin_expand_macro = {TSPECIAL, "*vm:begin-expand-macro*",0};
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
struct scm scm_vm_begin = {TSPECIAL, "*vm-begin*",0};
|
|
|
|
|
struct scm scm_vm_begin_read_input_file = {TSPECIAL, "*vm-begin-read-input-file*",0};
|
2018-03-04 09:05:55 +00:00
|
|
|
|
struct scm scm_vm_begin_eval = {TSPECIAL, "*vm:begin-eval*",0};
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
struct scm scm_vm_if = {TSPECIAL, "*vm-if*",0};
|
|
|
|
|
struct scm scm_vm_if_expr = {TSPECIAL, "*vm-if-expr*",0};
|
|
|
|
|
struct scm scm_vm_call_with_values2 = {TSPECIAL, "*vm-call-with-values2*",0};
|
|
|
|
|
struct scm scm_vm_call_with_current_continuation2 = {TSPECIAL, "*vm-call-with-current-continuation2*",0};
|
|
|
|
|
struct scm scm_vm_return = {TSPECIAL, "*vm-return*",0};
|
|
|
|
|
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
struct scm scm_symbol_gnuc = {TSYMBOL, "%gnuc",0};
|
|
|
|
|
struct scm scm_symbol_mesc = {TSYMBOL, "%mesc",0};
|
|
|
|
|
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
struct scm scm_test = {TSYMBOL, "test",0};
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#if !_POSIX_SOURCE
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#include "mes.mes.symbols.h"
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#else
|
2016-12-14 18:02:19 +00:00
|
|
|
|
#include "mes.symbols.h"
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#endif
|
2016-12-14 18:02:19 +00:00
|
|
|
|
|
|
|
|
|
SCM tmp;
|
|
|
|
|
SCM tmp_num;
|
|
|
|
|
SCM tmp_num2;
|
|
|
|
|
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
struct function g_functions[200];
|
2016-12-14 18:02:19 +00:00
|
|
|
|
int g_function = 0;
|
|
|
|
|
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#if !__GNUC__ || !_POSIX_SOURCE
|
|
|
|
|
#include "gc.mes.h"
|
|
|
|
|
#include "lib.mes.h"
|
|
|
|
|
#include "math.mes.h"
|
|
|
|
|
#include "mes.mes.h"
|
|
|
|
|
#include "posix.mes.h"
|
|
|
|
|
#include "reader.mes.h"
|
|
|
|
|
#include "vector.mes.h"
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#else
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
#include "gc.h"
|
2016-12-14 18:02:19 +00:00
|
|
|
|
#include "lib.h"
|
|
|
|
|
#include "math.h"
|
|
|
|
|
#include "mes.h"
|
|
|
|
|
#include "posix.h"
|
|
|
|
|
#include "reader.h"
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
#include "vector.h"
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#endif
|
2016-12-14 18:02:19 +00:00
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#define TYPE(x) g_cells[x].type
|
2016-11-21 08:28:34 +00:00
|
|
|
|
#define CAR(x) g_cells[x].car
|
|
|
|
|
#define CDR(x) g_cells[x].cdr
|
2017-04-10 18:13:20 +01:00
|
|
|
|
|
|
|
|
|
#define NTYPE(x) g_news[x].type
|
|
|
|
|
#define NCAR(x) g_news[x].car
|
|
|
|
|
#define NCDR(x) g_news[x].cdr
|
|
|
|
|
|
|
|
|
|
#if !_POSIX_SOURCE
|
|
|
|
|
#define LENGTH(x) g_cells[x].car
|
|
|
|
|
#define REF(x) g_cells[x].car
|
|
|
|
|
#define STRING(x) g_cells[x].car
|
2017-12-09 07:33:50 +00:00
|
|
|
|
#define VARIABLE(x) g_cells[x].car
|
|
|
|
|
#define VARIABLE_GLOBAL_P(x) g_cells[x].cdr
|
2017-04-10 18:13:20 +01:00
|
|
|
|
|
|
|
|
|
#define CLOSURE(x) g_cells[x].cdr
|
|
|
|
|
#define CONTINUATION(x) g_cells[x].cdr
|
|
|
|
|
|
|
|
|
|
#define FUNCTION(x) g_functions[g_cells[x].cdr]
|
2017-12-09 07:33:50 +00:00
|
|
|
|
#define FUNCTION0(x) g_functions[g_cells[x].cdr].function
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#define MACRO(x) g_cells[x].cdr
|
|
|
|
|
#define VALUE(x) g_cells[x].cdr
|
|
|
|
|
#define VECTOR(x) g_cells[x].cdr
|
|
|
|
|
|
|
|
|
|
#define NLENGTH(x) g_news[x].car
|
|
|
|
|
|
|
|
|
|
#define NVALUE(x) g_news[x].cdr
|
|
|
|
|
#define NVECTOR(x) g_news[x].cdr
|
|
|
|
|
|
|
|
|
|
#else
|
2016-12-28 21:04:57 +00:00
|
|
|
|
#define CONTINUATION(x) g_cells[x].cdr
|
2016-11-21 08:30:59 +00:00
|
|
|
|
#define HITS(x) g_cells[x].hits
|
2016-11-21 08:28:34 +00:00
|
|
|
|
#define LENGTH(x) g_cells[x].length
|
2016-11-21 08:30:59 +00:00
|
|
|
|
#define NAME(x) g_cells[x].name
|
2016-11-21 08:28:34 +00:00
|
|
|
|
#define STRING(x) g_cells[x].string
|
2017-12-09 07:33:50 +00:00
|
|
|
|
#define VARIABLE(x) g_cells[x].variable
|
|
|
|
|
#define VARIABLE_GLOBAL_P(x) g_cells[x].cdr
|
|
|
|
|
|
2016-12-23 17:48:36 +00:00
|
|
|
|
#define CLOSURE(x) g_cells[x].closure
|
2016-11-21 08:28:34 +00:00
|
|
|
|
#define MACRO(x) g_cells[x].macro
|
2016-11-21 08:30:59 +00:00
|
|
|
|
#define REF(x) g_cells[x].ref
|
2016-11-21 08:28:34 +00:00
|
|
|
|
#define VALUE(x) g_cells[x].value
|
|
|
|
|
#define VECTOR(x) g_cells[x].vector
|
2017-03-02 19:26:13 +00:00
|
|
|
|
#define FUNCTION(x) g_functions[g_cells[x].function]
|
2017-12-09 07:33:50 +00:00
|
|
|
|
#define FUNCTION0(x) g_functions[g_cells[x].function].function0
|
core: Prepare gc.c for mescc, non-POSIX_SOURCE.
* mes.c (NLENGTH, NVALUE, NVECTOR): New macros.
(mes_builtins): Add comment on .i include order.
* module/language/c99/compiler.mes (mescc): Add define _POSIX_SOURCE=0.
* gc.c (gc_up_arena, gc_flip, gc_loop, gc)[!_POSIX_SOURCE]: Use eputs
rather than fprintf.
(gc_loop): Use CAR, TYPE, NVECTOR rather than .car, .type, .vector.
* gc.c (gc_up_arena)[!_POSIX_SOURCE]: Add non-POSIX mlib.c
implementation.
2017-03-26 14:55:12 +01:00
|
|
|
|
|
|
|
|
|
#define NLENGTH(x) g_news[x].length
|
|
|
|
|
|
|
|
|
|
#define NVALUE(x) g_news[x].value
|
|
|
|
|
#define NVECTOR(x) g_news[x].vector
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#endif
|
core: Prepare gc.c for mescc, non-POSIX_SOURCE.
* mes.c (NLENGTH, NVALUE, NVECTOR): New macros.
(mes_builtins): Add comment on .i include order.
* module/language/c99/compiler.mes (mescc): Add define _POSIX_SOURCE=0.
* gc.c (gc_up_arena, gc_flip, gc_loop, gc)[!_POSIX_SOURCE]: Use eputs
rather than fprintf.
(gc_loop): Use CAR, TYPE, NVECTOR rather than .car, .type, .vector.
* gc.c (gc_up_arena)[!_POSIX_SOURCE]: Add non-POSIX mlib.c
implementation.
2017-03-26 14:55:12 +01:00
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#define MAKE_CHAR(n) make_cell_ (tmp_num_ (TCHAR), 0, tmp_num2_ (n))
|
|
|
|
|
#define MAKE_CONTINUATION(n) make_cell_ (tmp_num_ (TCONTINUATION), n, g_stack)
|
|
|
|
|
#define MAKE_NUMBER(n) make_cell_ (tmp_num_ (TNUMBER), 0, tmp_num2_ (n))
|
|
|
|
|
#define MAKE_REF(n) make_cell_ (tmp_num_ (TREF), n, 0)
|
|
|
|
|
#define MAKE_STRING(x) make_cell_ (tmp_num_ (TSTRING), x, 0)
|
mes: resurrect full reader in C core.
* module/mes/read-0.mes (defined?): New function.
(eat-whitespace, read-env, read-word, read-block-comment,
read-line-comment, read-list, read-character, read-hex, read-octal,
reader:read-string, lookup, read-hash, read-word): Only define if
not %c-reader.
* module/mes/base-0.mes (defined?): Remove.
* src/mes.c[MES_C_READER]: Set ARENA_SIZE=10000000.
(scm_symbol_quasiquote scm_symbol_unquote,
scm_symbol_unquote_splicing, scm_symbol_syntax,
scm_symbol_quasisyntax, scm_symbol_unsyntax,
scm_symbol_unsyntax_splicing): New symbol.
(scm_symbol_c_reader): New symbol.
(MAKE_KEYWORD)[MES_C_READER]: New define.
(mes_symbols): Define %c_reader.
* src/reader.c (read_word_)[MES_C_READER]: Extend to full Scheme
reader.
(eat_whitespace)[MES_C_READER]: Likewise.
(read_block_comment, read_hash, read_word, read_character,
read_octal, read_hex, append_char, read_string)[MES_C_READER]:
Likewise.
* make.scm (bin.gcc,bin.mescc): Define MES_C_READER=1.
2017-11-29 20:42:50 +00:00
|
|
|
|
#define MAKE_KEYWORD(x) make_cell_ (tmp_num_ (TKEYWORD), x, 0)
|
2017-12-09 07:24:38 +00:00
|
|
|
|
#define MAKE_MACRO(name, x) make_cell_ (tmp_num_ (TMACRO), STRING (name), x)
|
core: Prepare gc.c for mescc, non-POSIX_SOURCE.
* mes.c (NLENGTH, NVALUE, NVECTOR): New macros.
(mes_builtins): Add comment on .i include order.
* module/language/c99/compiler.mes (mescc): Add define _POSIX_SOURCE=0.
* gc.c (gc_up_arena, gc_flip, gc_loop, gc)[!_POSIX_SOURCE]: Use eputs
rather than fprintf.
(gc_loop): Use CAR, TYPE, NVECTOR rather than .car, .type, .vector.
* gc.c (gc_up_arena)[!_POSIX_SOURCE]: Add non-POSIX mlib.c
implementation.
2017-03-26 14:55:12 +01:00
|
|
|
|
|
2016-11-21 08:30:59 +00:00
|
|
|
|
#define CAAR(x) CAR (CAR (x))
|
2017-03-25 14:58:44 +00:00
|
|
|
|
#define CADR(x) CAR (CDR (x))
|
2016-11-21 08:30:59 +00:00
|
|
|
|
#define CDAR(x) CDR (CAR (x))
|
2017-03-25 14:58:44 +00:00
|
|
|
|
#define CDDR(x) CDR (CDR (x))
|
2016-11-21 08:30:59 +00:00
|
|
|
|
#define CADAR(x) CAR (CDR (CAR (x)))
|
2016-11-21 20:43:06 +00:00
|
|
|
|
#define CADDR(x) CAR (CDR (CDR (x)))
|
2016-11-21 08:30:59 +00:00
|
|
|
|
#define CDADAR(x) CAR (CDR (CAR (CDR (x))))
|
2016-05-28 15:39:44 +01:00
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
SCM
|
|
|
|
|
alloc (int n)
|
|
|
|
|
{
|
|
|
|
|
assert (g_free + n < ARENA_SIZE);
|
|
|
|
|
SCM x = g_free;
|
|
|
|
|
g_free += n;
|
|
|
|
|
return x;
|
|
|
|
|
}
|
2016-10-27 15:44:09 +01:00
|
|
|
|
|
2016-12-23 17:05:45 +00:00
|
|
|
|
SCM
|
|
|
|
|
tmp_num_ (int x)
|
|
|
|
|
{
|
2017-04-10 18:13:20 +01:00
|
|
|
|
VALUE (tmp_num) = x;
|
2016-12-23 17:05:45 +00:00
|
|
|
|
return tmp_num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
tmp_num2_ (int x)
|
|
|
|
|
{
|
2017-04-10 18:13:20 +01:00
|
|
|
|
VALUE (tmp_num2) = x;
|
2016-12-23 17:05:45 +00:00
|
|
|
|
return tmp_num2;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
2017-03-25 14:58:44 +00:00
|
|
|
|
make_cell_ (SCM type, SCM car, SCM cdr)
|
2016-11-21 08:28:34 +00:00
|
|
|
|
{
|
2016-11-21 08:36:32 +00:00
|
|
|
|
SCM x = alloc (1);
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
assert (TYPE (type) == TNUMBER);
|
2016-11-21 08:30:59 +00:00
|
|
|
|
TYPE (x) = VALUE (type);
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER)
|
|
|
|
|
{
|
|
|
|
|
if (car)
|
|
|
|
|
CAR (x) = CAR (car);
|
|
|
|
|
if (cdr)
|
|
|
|
|
CDR (x) = CDR (cdr);
|
|
|
|
|
}
|
|
|
|
|
else if (VALUE (type) == TFUNCTION)
|
|
|
|
|
{
|
|
|
|
|
if (car)
|
|
|
|
|
CAR (x) = car;
|
|
|
|
|
if (cdr)
|
|
|
|
|
CDR (x) = CDR (cdr);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CAR (x) = car;
|
|
|
|
|
CDR (x) = cdr;
|
|
|
|
|
}
|
2016-10-26 18:44:36 +01:00
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-25 14:58:44 +00:00
|
|
|
|
SCM
|
2017-04-10 18:13:20 +01:00
|
|
|
|
make_symbol_ (SCM s) ///((internal))
|
2017-03-25 14:58:44 +00:00
|
|
|
|
{
|
2017-04-10 18:13:20 +01:00
|
|
|
|
VALUE (tmp_num) = TSYMBOL;
|
2017-03-25 14:58:44 +00:00
|
|
|
|
SCM x = make_cell_ (tmp_num, s, 0);
|
|
|
|
|
g_symbols = cons (x, g_symbols);
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
list_of_char_equal_p (SCM a, SCM b) ///((internal))
|
|
|
|
|
{
|
2018-04-05 20:35:31 +01:00
|
|
|
|
while (a != cell_nil && b != cell_nil && VALUE (CAR (a)) == VALUE (CAR (b)))
|
|
|
|
|
{
|
|
|
|
|
assert (TYPE (CAR (a)) == TCHAR);
|
|
|
|
|
assert (TYPE (CAR (b)) == TCHAR);
|
|
|
|
|
a = CDR (a);
|
|
|
|
|
b = CDR (b);
|
|
|
|
|
}
|
2017-03-25 14:58:44 +00:00
|
|
|
|
return (a == cell_nil && b == cell_nil) ? cell_t : cell_f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
lookup_symbol_ (SCM s)
|
|
|
|
|
{
|
|
|
|
|
SCM x = g_symbols;
|
2018-04-05 20:35:31 +01:00
|
|
|
|
while (x)
|
|
|
|
|
{
|
|
|
|
|
if (list_of_char_equal_p (STRING (CAR (x)), s) == cell_t)
|
|
|
|
|
break;
|
|
|
|
|
x = CDR (x);
|
|
|
|
|
}
|
|
|
|
|
if (x)
|
|
|
|
|
x = CAR (x);
|
|
|
|
|
if (!x)
|
|
|
|
|
x = make_symbol_ (s);
|
2017-03-25 14:58:44 +00:00
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
type_ (SCM x)
|
|
|
|
|
{
|
|
|
|
|
return MAKE_NUMBER (TYPE (x));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
car_ (SCM x)
|
|
|
|
|
{
|
|
|
|
|
return (TYPE (x) != TCONTINUATION
|
|
|
|
|
&& (TYPE (CAR (x)) == TPAIR // FIXME: this is weird
|
|
|
|
|
|| TYPE (CAR (x)) == TREF
|
|
|
|
|
|| TYPE (CAR (x)) == TSPECIAL
|
|
|
|
|
|| TYPE (CAR (x)) == TSYMBOL
|
|
|
|
|
|| TYPE (CAR (x)) == TSTRING)) ? CAR (x) : MAKE_NUMBER (CAR (x));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
cdr_ (SCM x)
|
|
|
|
|
{
|
2018-04-09 06:12:38 +01:00
|
|
|
|
return (TYPE (x) != TCHAR
|
|
|
|
|
&& TYPE (x) != TNUMBER
|
|
|
|
|
&& (TYPE (CDR (x)) == TPAIR
|
|
|
|
|
|| TYPE (CDR (x)) == TREF
|
|
|
|
|
|| TYPE (CDR (x)) == TSPECIAL
|
|
|
|
|
|| TYPE (CDR (x)) == TSYMBOL
|
|
|
|
|
|| TYPE (CDR (x)) == TSTRING)) ? CDR (x) : MAKE_NUMBER (CDR (x));
|
2017-03-25 14:58:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
arity_ (SCM x)
|
|
|
|
|
{
|
|
|
|
|
assert (TYPE (x) == TFUNCTION);
|
|
|
|
|
return MAKE_NUMBER (FUNCTION (x).arity);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
cons (SCM x, SCM y)
|
2016-05-28 15:39:44 +01:00
|
|
|
|
{
|
2017-04-10 18:13:20 +01:00
|
|
|
|
VALUE (tmp_num) = TPAIR;
|
2017-03-25 14:58:44 +00:00
|
|
|
|
return make_cell_ (tmp_num, x, y);
|
2016-05-28 15:39:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:36:32 +00:00
|
|
|
|
SCM
|
|
|
|
|
car (SCM x)
|
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#if !__MESC_MES__
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (TYPE (x) != TPAIR)
|
|
|
|
|
error (cell_symbol_not_a_pair, cons (x, cell_symbol_car));
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#endif
|
2016-11-21 08:36:32 +00:00
|
|
|
|
return CAR (x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
cdr (SCM x)
|
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#if !__MESC_MES__
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (TYPE (x) != TPAIR)
|
|
|
|
|
error (cell_symbol_not_a_pair, cons (x, cell_symbol_cdr));
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#endif
|
2016-11-21 08:36:32 +00:00
|
|
|
|
return CDR (x);
|
|
|
|
|
}
|
2017-01-18 06:38:45 +00:00
|
|
|
|
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
SCM
|
|
|
|
|
list (SCM x) ///((arity . n))
|
|
|
|
|
{
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
SCM
|
|
|
|
|
null_p (SCM x)
|
|
|
|
|
{
|
|
|
|
|
return x == cell_nil ? cell_t : cell_f;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-04 07:16:14 +00:00
|
|
|
|
SCM
|
|
|
|
|
eq_p (SCM x, SCM y)
|
|
|
|
|
{
|
|
|
|
|
return (x == y
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
|| ((TYPE (x) == TKEYWORD && TYPE (y) == TKEYWORD
|
2017-01-04 07:16:14 +00:00
|
|
|
|
&& STRING (x) == STRING (y)))
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
|| (TYPE (x) == TCHAR && TYPE (y) == TCHAR
|
2017-01-04 07:16:14 +00:00
|
|
|
|
&& VALUE (x) == VALUE (y))
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
|| (TYPE (x) == TNUMBER && TYPE (y) == TNUMBER
|
2017-01-04 07:16:14 +00:00
|
|
|
|
&& VALUE (x) == VALUE (y)))
|
|
|
|
|
? cell_t : cell_f;
|
|
|
|
|
}
|
2016-11-21 08:36:32 +00:00
|
|
|
|
|
2016-12-23 17:05:45 +00:00
|
|
|
|
SCM
|
2017-03-25 14:58:44 +00:00
|
|
|
|
values (SCM x) ///((arity . n))
|
2016-12-23 17:05:45 +00:00
|
|
|
|
{
|
2017-03-25 14:58:44 +00:00
|
|
|
|
SCM v = cons (0, x);
|
|
|
|
|
TYPE (v) = TVALUES;
|
|
|
|
|
return v;
|
2016-12-23 17:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
2017-03-25 14:58:44 +00:00
|
|
|
|
acons (SCM key, SCM value, SCM alist)
|
2016-12-23 17:05:45 +00:00
|
|
|
|
{
|
2017-03-25 14:58:44 +00:00
|
|
|
|
return cons (cons (key, value), alist);
|
2016-07-10 12:47:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
SCM
|
|
|
|
|
length (SCM x)
|
|
|
|
|
{
|
|
|
|
|
int n = 0;
|
|
|
|
|
while (x != cell_nil)
|
|
|
|
|
{
|
|
|
|
|
n++;
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (TYPE (x) != TPAIR)
|
|
|
|
|
return MAKE_NUMBER (-1);
|
2017-04-12 20:27:59 +01:00
|
|
|
|
x = CDR (x);
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
}
|
|
|
|
|
return MAKE_NUMBER (n);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-02 16:01:22 +01:00
|
|
|
|
SCM apply (SCM, SCM, SCM);
|
|
|
|
|
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
SCM
|
|
|
|
|
error (SCM key, SCM x)
|
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#if !__MESC_MES__
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
SCM throw;
|
|
|
|
|
if ((throw = assq_ref_env (cell_symbol_throw, r0)) != cell_undefined)
|
|
|
|
|
return apply (throw, cons (key, cons (x, cell_nil)), r0);
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#endif
|
2017-03-25 14:58:44 +00:00
|
|
|
|
display_error_ (key);
|
2017-03-26 21:12:24 +01:00
|
|
|
|
eputs (": ");
|
2018-01-07 15:08:11 +00:00
|
|
|
|
write_error_ (x);
|
2017-03-26 21:12:24 +01:00
|
|
|
|
eputs ("\n");
|
2017-04-10 18:13:20 +01:00
|
|
|
|
exit (1);
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
SCM
|
|
|
|
|
cstring_to_list (char const* s)
|
|
|
|
|
{
|
|
|
|
|
SCM p = cell_nil;
|
|
|
|
|
int i = strlen (s);
|
|
|
|
|
while (i--)
|
|
|
|
|
p = cons (MAKE_CHAR (s[i]), p);
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
// extra lib
|
|
|
|
|
SCM
|
|
|
|
|
assert_defined (SCM x, SCM e) ///((internal))
|
|
|
|
|
{
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (e == cell_undefined)
|
|
|
|
|
return error (cell_symbol_unbound_variable, x);
|
2017-04-10 18:13:20 +01:00
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
check_formals (SCM f, SCM formals, SCM args) ///((internal))
|
|
|
|
|
{
|
|
|
|
|
int flen = (TYPE (formals) == TNUMBER) ? VALUE (formals) : VALUE (length (formals));
|
|
|
|
|
int alen = VALUE (length (args));
|
|
|
|
|
if (alen != flen && alen != -1 && flen != -1)
|
|
|
|
|
{
|
|
|
|
|
char *s = "apply: wrong number of arguments; expected: ";
|
|
|
|
|
eputs (s);
|
|
|
|
|
eputs (itoa (flen));
|
|
|
|
|
eputs (", got: ");
|
|
|
|
|
eputs (itoa (alen));
|
|
|
|
|
eputs ("\n");
|
2018-04-09 06:12:38 +01:00
|
|
|
|
write_error_ (f);
|
2017-04-10 18:13:20 +01:00
|
|
|
|
SCM e = MAKE_STRING (cstring_to_list (s));
|
|
|
|
|
return error (cell_symbol_wrong_number_of_args, cons (e, f));
|
|
|
|
|
}
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
check_apply (SCM f, SCM e) ///((internal))
|
|
|
|
|
{
|
|
|
|
|
char* type = 0;
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (f == cell_f || f == cell_t)
|
|
|
|
|
type = "bool";
|
|
|
|
|
if (f == cell_nil)
|
|
|
|
|
type = "nil";
|
|
|
|
|
if (f == cell_unspecified)
|
|
|
|
|
type = "*unspecified*";
|
|
|
|
|
if (f == cell_undefined)
|
|
|
|
|
type = "*undefined*";
|
|
|
|
|
if (TYPE (f) == TCHAR)
|
|
|
|
|
type = "char";
|
|
|
|
|
if (TYPE (f) == TNUMBER)
|
|
|
|
|
type = "number";
|
|
|
|
|
if (TYPE (f) == TSTRING)
|
|
|
|
|
type = "string";
|
2017-04-10 18:13:20 +01:00
|
|
|
|
|
|
|
|
|
if (type)
|
|
|
|
|
{
|
|
|
|
|
char *s = "cannot apply: ";
|
|
|
|
|
eputs (s);
|
|
|
|
|
eputs (type);
|
|
|
|
|
eputs ("[");
|
2018-01-07 15:08:11 +00:00
|
|
|
|
write_error_ (e);
|
2017-04-10 18:13:20 +01:00
|
|
|
|
eputs ("]\n");
|
|
|
|
|
SCM e = MAKE_STRING (cstring_to_list (s));
|
|
|
|
|
return error (cell_symbol_wrong_type_arg, cons (e, f));
|
|
|
|
|
}
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
gc_push_frame () ///((internal))
|
|
|
|
|
{
|
|
|
|
|
SCM frame = cons (r1, cons (r2, cons (r3, cons (r0, cell_nil))));
|
|
|
|
|
g_stack = cons (frame, g_stack);
|
|
|
|
|
return g_stack;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
append2 (SCM x, SCM y)
|
2016-07-10 12:47:56 +01:00
|
|
|
|
{
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (x == cell_nil)
|
|
|
|
|
return y;
|
|
|
|
|
if (TYPE (x) != TPAIR)
|
|
|
|
|
error (cell_symbol_not_a_pair, cons (x, cell_append2));
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
return cons (car (x), append2 (cdr (x), y));
|
2016-07-10 09:43:26 +01:00
|
|
|
|
}
|
2016-05-28 15:39:44 +01:00
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
pairlis (SCM x, SCM y, SCM a)
|
2016-05-28 15:39:44 +01:00
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
|
if (x == cell_nil)
|
2016-05-28 15:39:44 +01:00
|
|
|
|
return a;
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
if (TYPE (x) != TPAIR)
|
2016-07-08 17:02:06 +01:00
|
|
|
|
return cons (cons (x, y), a);
|
2016-05-28 15:39:44 +01:00
|
|
|
|
return cons (cons (car (x), car (y)),
|
|
|
|
|
pairlis (cdr (x), cdr (y), a));
|
|
|
|
|
}
|
|
|
|
|
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
SCM
|
|
|
|
|
call (SCM fn, SCM x)
|
|
|
|
|
{
|
|
|
|
|
if ((FUNCTION (fn).arity > 0 || FUNCTION (fn).arity == -1)
|
|
|
|
|
&& x != cell_nil && TYPE (CAR (x)) == TVALUES)
|
|
|
|
|
x = cons (CADAR (x), CDR (x));
|
|
|
|
|
if ((FUNCTION (fn).arity > 1 || FUNCTION (fn).arity == -1)
|
|
|
|
|
&& x != cell_nil && TYPE (CDR (x)) == TPAIR && TYPE (CADR (x)) == TVALUES)
|
|
|
|
|
x = cons (CAR (x), cons (CDADAR (x), CDR (x)));
|
|
|
|
|
switch (FUNCTION (fn).arity)
|
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#if __MESC__ || !_POSIX_SOURCE
|
2017-04-10 18:13:20 +01:00
|
|
|
|
case 0: return (FUNCTION (fn).function) ();
|
|
|
|
|
case 1: return ((SCM(*)(SCM))(FUNCTION (fn).function)) (CAR (x));
|
|
|
|
|
case 2: return ((SCM(*)(SCM,SCM))(FUNCTION (fn).function)) (CAR (x), CADR (x));
|
2017-04-12 20:27:59 +01:00
|
|
|
|
case 3: return ((SCM(*)(SCM,SCM,SCM))(FUNCTION (fn).function)) (CAR (x), CADR (x), CAR (CDDR (x)));
|
2017-04-10 18:13:20 +01:00
|
|
|
|
case -1: return ((SCM(*)(SCM))(FUNCTION (fn).function)) (x);
|
|
|
|
|
default: return ((SCM(*)(SCM))(FUNCTION (fn).function)) (x);
|
|
|
|
|
#else
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
case 0: return FUNCTION (fn).function0 ();
|
2017-04-12 20:27:59 +01:00
|
|
|
|
case 1: return FUNCTION (fn).function1 (CAR (x));
|
|
|
|
|
case 2: return FUNCTION (fn).function2 (CAR (x), CADR (x));
|
|
|
|
|
case 3: return FUNCTION (fn).function3 (CAR (x), CADR (x), CAR (CDDR (x)));
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
case -1: return FUNCTION (fn).functionn (x);
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#endif
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
assq (SCM x, SCM a)
|
2016-05-28 15:39:44 +01:00
|
|
|
|
{
|
2017-12-12 19:25:48 +00:00
|
|
|
|
switch (TYPE (x))
|
|
|
|
|
{
|
|
|
|
|
case TCHAR:
|
|
|
|
|
case TNUMBER:
|
|
|
|
|
{
|
|
|
|
|
SCM v = VALUE (x);
|
2018-04-05 20:35:31 +01:00
|
|
|
|
while (a != cell_nil && v != VALUE (CAAR (a)))
|
|
|
|
|
a = CDR (a);
|
|
|
|
|
break;
|
2017-12-12 19:25:48 +00:00
|
|
|
|
}
|
|
|
|
|
case TKEYWORD:
|
|
|
|
|
{
|
|
|
|
|
SCM v = STRING (x);
|
2018-04-05 20:35:31 +01:00
|
|
|
|
while (a != cell_nil && v != STRING (CAAR (a)))
|
|
|
|
|
a = CDR (a);
|
|
|
|
|
break;
|
2017-12-12 19:25:48 +00:00
|
|
|
|
}
|
2017-12-09 07:33:50 +00:00
|
|
|
|
// case TSYMBOL:
|
|
|
|
|
// case TSPECIAL:
|
2017-12-12 19:25:48 +00:00
|
|
|
|
default:
|
2018-04-05 20:35:31 +01:00
|
|
|
|
while (a != cell_nil && x != CAAR (a))
|
|
|
|
|
a = CDR (a);
|
2017-12-12 19:25:48 +00:00
|
|
|
|
}
|
2017-03-25 14:58:44 +00:00
|
|
|
|
return a != cell_nil ? CAR (a) : cell_f;
|
2016-10-19 23:11:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
assq_ref_env (SCM x, SCM a)
|
2016-10-19 23:11:48 +01:00
|
|
|
|
{
|
|
|
|
|
x = assq (x, a);
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (x == cell_f)
|
|
|
|
|
return cell_undefined;
|
2017-03-25 14:58:44 +00:00
|
|
|
|
return CDR (x);
|
2016-10-19 23:11:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
SCM
|
|
|
|
|
set_car_x (SCM x, SCM e)
|
|
|
|
|
{
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (TYPE (x) != TPAIR)
|
|
|
|
|
error (cell_symbol_not_a_pair, cons (x, cell_set_car_x));
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
CAR (x) = e;
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
set_cdr_x (SCM x, SCM e)
|
|
|
|
|
{
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (TYPE (x) != TPAIR)
|
|
|
|
|
error (cell_symbol_not_a_pair, cons (x, cell_set_cdr_x));
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
CDR (x) = e;
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
set_env_x (SCM x, SCM e, SCM a)
|
|
|
|
|
{
|
2017-12-09 07:33:50 +00:00
|
|
|
|
SCM p;
|
|
|
|
|
if (TYPE (x) == TVARIABLE)
|
|
|
|
|
p = VARIABLE (x);
|
|
|
|
|
else
|
|
|
|
|
p = assert_defined (x, assq (x, a));
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (TYPE (p) != TPAIR)
|
|
|
|
|
error (cell_symbol_not_a_pair, cons (p, x));
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
return set_cdr_x (p, e);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
call_lambda (SCM e, SCM x, SCM aa, SCM a) ///((internal))
|
core: Integrate garbage collector/jam scraper.
* mes.c (r0, r1, r2, r3, stack): New globals.
(gc_loop): Handle MACRO and SCM.
(gc_copy): Handle FUNCTION, allow for pre-allocated SCM and SYMBOL.
(assq): Flag any BROKEN_HEARTs.
(vm_call): New function. Enables moving C stack to GC stack.
(evlis_env, apply_env, eval_env, expand_macro_env, begin_env,
if_env): Use vm_call-indirection.
(call_lambda): New function.
(vm_apply_env): Rename from apply_env. Remove parameters, instead
use r1, r2 and r0.
(vm_evlis_env, vm_eval_env, vm_expand_macro_env, vm_begin_env,
vm_if_env): Likewise.
(acons): New function.
(mes_environment) [!MES_FULL, MES_MINI]: Add cpp switches to create minimally
filled environment, for debugging.
(main): Print free value at exit.
* define.c (define_env): Use vm_call-indirection.
(vm_define_env): Rename from define_env.
* quasiquote.c (eval_quasiquote): Use vm_call-indirection.
(vm_eval_quasiquote): Rename from eval_quasiquote.
* tests/gc-2.test: New test.
tests/gc-2a.test: New test.
tests/gc-3.test: New test.
2016-10-28 17:42:03 +01:00
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM cl = cons (cons (cell_closure, x), x);
|
core: Integrate garbage collector/jam scraper.
* mes.c (r0, r1, r2, r3, stack): New globals.
(gc_loop): Handle MACRO and SCM.
(gc_copy): Handle FUNCTION, allow for pre-allocated SCM and SYMBOL.
(assq): Flag any BROKEN_HEARTs.
(vm_call): New function. Enables moving C stack to GC stack.
(evlis_env, apply_env, eval_env, expand_macro_env, begin_env,
if_env): Use vm_call-indirection.
(call_lambda): New function.
(vm_apply_env): Rename from apply_env. Remove parameters, instead
use r1, r2 and r0.
(vm_evlis_env, vm_eval_env, vm_expand_macro_env, vm_begin_env,
vm_if_env): Likewise.
(acons): New function.
(mes_environment) [!MES_FULL, MES_MINI]: Add cpp switches to create minimally
filled environment, for debugging.
(main): Print free value at exit.
* define.c (define_env): Use vm_call-indirection.
(vm_define_env): Rename from define_env.
* quasiquote.c (eval_quasiquote): Use vm_call-indirection.
(vm_eval_quasiquote): Rename from eval_quasiquote.
* tests/gc-2.test: New test.
tests/gc-2a.test: New test.
tests/gc-3.test: New test.
2016-10-28 17:42:03 +01:00
|
|
|
|
r1 = e;
|
|
|
|
|
r0 = cl;
|
2016-12-22 15:50:51 +00:00
|
|
|
|
return cell_unspecified;
|
core: Integrate garbage collector/jam scraper.
* mes.c (r0, r1, r2, r3, stack): New globals.
(gc_loop): Handle MACRO and SCM.
(gc_copy): Handle FUNCTION, allow for pre-allocated SCM and SYMBOL.
(assq): Flag any BROKEN_HEARTs.
(vm_call): New function. Enables moving C stack to GC stack.
(evlis_env, apply_env, eval_env, expand_macro_env, begin_env,
if_env): Use vm_call-indirection.
(call_lambda): New function.
(vm_apply_env): Rename from apply_env. Remove parameters, instead
use r1, r2 and r0.
(vm_evlis_env, vm_eval_env, vm_expand_macro_env, vm_begin_env,
vm_if_env): Likewise.
(acons): New function.
(mes_environment) [!MES_FULL, MES_MINI]: Add cpp switches to create minimally
filled environment, for debugging.
(main): Print free value at exit.
* define.c (define_env): Use vm_call-indirection.
(vm_define_env): Rename from define_env.
* quasiquote.c (eval_quasiquote): Use vm_call-indirection.
(vm_eval_quasiquote): Rename from eval_quasiquote.
* tests/gc-2.test: New test.
tests/gc-2a.test: New test.
tests/gc-3.test: New test.
2016-10-28 17:42:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
SCM
|
2017-04-10 18:13:20 +01:00
|
|
|
|
make_closure_ (SCM args, SCM body, SCM a) ///((internal))
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
{
|
2017-03-25 14:58:44 +00:00
|
|
|
|
return make_cell_ (tmp_num_ (TCLOSURE), cell_f, cons (cons (cell_circular, a), cons (args, body)));
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-09 07:33:50 +00:00
|
|
|
|
SCM
|
|
|
|
|
make_variable_ (SCM var, SCM global_p) ///((internal))
|
|
|
|
|
{
|
|
|
|
|
return make_cell_ (tmp_num_ (TVARIABLE), var, global_p);
|
|
|
|
|
}
|
|
|
|
|
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
SCM
|
2017-03-25 14:58:44 +00:00
|
|
|
|
lookup_macro_ (SCM x, SCM a) ///((internal))
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
{
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (TYPE (x) != TSYMBOL)
|
|
|
|
|
return cell_f;
|
2017-12-09 07:33:50 +00:00
|
|
|
|
SCM m = assq (x, a);
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (m != cell_f)
|
|
|
|
|
return MACRO (CDR (m));
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
return cell_f;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
SCM
|
|
|
|
|
push_cc (SCM p1, SCM p2, SCM a, SCM c) ///((internal))
|
|
|
|
|
{
|
|
|
|
|
SCM x = r3;
|
|
|
|
|
r3 = c;
|
|
|
|
|
r2 = p2;
|
|
|
|
|
gc_push_frame ();
|
|
|
|
|
r1 = p1;
|
|
|
|
|
r0 = a;
|
|
|
|
|
r3 = x;
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-17 06:42:49 +00:00
|
|
|
|
SCM
|
|
|
|
|
gc_peek_frame () ///((internal))
|
|
|
|
|
{
|
|
|
|
|
SCM frame = CAR (g_stack);
|
|
|
|
|
r1 = CAR (frame);
|
|
|
|
|
r2 = CADR (frame);
|
|
|
|
|
r3 = CAR (CDDR (frame));
|
|
|
|
|
r0 = CADR (CDDR (frame));
|
|
|
|
|
return frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
gc_pop_frame () ///((internal))
|
|
|
|
|
{
|
|
|
|
|
SCM frame = gc_peek_frame (g_stack);
|
|
|
|
|
g_stack = CDR (g_stack);
|
|
|
|
|
return frame;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-09 07:33:50 +00:00
|
|
|
|
char const* string_to_cstring (SCM s);
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
add_formals (SCM formals, SCM x)
|
|
|
|
|
{
|
|
|
|
|
while (TYPE (x) == TPAIR)
|
|
|
|
|
{
|
|
|
|
|
formals = cons (CAR (x), formals);
|
|
|
|
|
x = CDR (x);
|
|
|
|
|
}
|
|
|
|
|
if (TYPE (x) == TSYMBOL)
|
|
|
|
|
formals = cons (x, formals);
|
|
|
|
|
return formals;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
formal_p (SCM x, SCM formals) /// ((internal))
|
|
|
|
|
{
|
|
|
|
|
if (TYPE (formals) == TSYMBOL)
|
|
|
|
|
{
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (x == formals)
|
|
|
|
|
return x;
|
2017-12-09 07:33:50 +00:00
|
|
|
|
else return cell_f;
|
|
|
|
|
}
|
|
|
|
|
while (TYPE (formals) == TPAIR && CAR (formals) != x)
|
|
|
|
|
formals = CDR (formals);
|
|
|
|
|
if (TYPE (formals) == TSYMBOL)
|
|
|
|
|
return formals == x;
|
|
|
|
|
return TYPE (formals) == TPAIR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
expand_variable_ (SCM x, SCM formals, int top_p) ///((internal))
|
|
|
|
|
{
|
|
|
|
|
while (TYPE (x) == TPAIR)
|
|
|
|
|
{
|
|
|
|
|
if (TYPE (CAR (x)) == TPAIR)
|
|
|
|
|
{
|
|
|
|
|
if (CAAR (x) == cell_symbol_lambda)
|
|
|
|
|
{
|
|
|
|
|
SCM f = CAR (CDAR (x));
|
|
|
|
|
formals = add_formals (formals, f);
|
|
|
|
|
}
|
|
|
|
|
else if (CAAR (x) == cell_symbol_define
|
|
|
|
|
|| CAAR (x) == cell_symbol_define_macro)
|
|
|
|
|
{
|
|
|
|
|
SCM f = CAR (CDAR (x));
|
|
|
|
|
formals = add_formals (formals, f);
|
|
|
|
|
}
|
|
|
|
|
if (CAAR (x) != cell_symbol_quote)
|
|
|
|
|
expand_variable_ (CAR (x), formals, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (CAR (x) == cell_symbol_lambda)
|
|
|
|
|
{
|
|
|
|
|
SCM f = CADR (x);
|
|
|
|
|
formals = add_formals (formals, f);
|
|
|
|
|
x = CDR (x);
|
|
|
|
|
}
|
|
|
|
|
else if (CAR (x) == cell_symbol_define
|
|
|
|
|
|| CAR (x) == cell_symbol_define_macro)
|
|
|
|
|
{
|
|
|
|
|
SCM f = CADR (x);
|
|
|
|
|
if (top_p && TYPE (f) == TPAIR)
|
|
|
|
|
f = CDR (f);
|
|
|
|
|
formals = add_formals (formals, f);
|
|
|
|
|
x = CDR (x);
|
|
|
|
|
}
|
|
|
|
|
else if (CAR (x) == cell_symbol_quote)
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
else if (TYPE (CAR (x)) == TSYMBOL
|
|
|
|
|
&& CAR (x) != cell_begin
|
|
|
|
|
&& CAR (x) != cell_symbol_begin
|
|
|
|
|
&& CAR (x) != cell_symbol_current_module
|
|
|
|
|
&& CAR (x) != cell_symbol_primitive_load
|
|
|
|
|
&& CAR (x) != cell_symbol_if // HMM
|
|
|
|
|
&& !formal_p (CAR (x), formals))
|
|
|
|
|
{
|
|
|
|
|
SCM v = assq (CAR (x), r0);
|
|
|
|
|
if (v != cell_f)
|
|
|
|
|
CAR (x) = make_variable_ (v, cell_t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
x = CDR (x);
|
|
|
|
|
top_p = 0;
|
|
|
|
|
}
|
|
|
|
|
return cell_unspecified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
expand_variable (SCM x, SCM formals) ///((internal))
|
|
|
|
|
{
|
|
|
|
|
return expand_variable_ (x, formals, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
2016-12-22 15:34:28 +00:00
|
|
|
|
eval_apply ()
|
core: Integrate garbage collector/jam scraper.
* mes.c (r0, r1, r2, r3, stack): New globals.
(gc_loop): Handle MACRO and SCM.
(gc_copy): Handle FUNCTION, allow for pre-allocated SCM and SYMBOL.
(assq): Flag any BROKEN_HEARTs.
(vm_call): New function. Enables moving C stack to GC stack.
(evlis_env, apply_env, eval_env, expand_macro_env, begin_env,
if_env): Use vm_call-indirection.
(call_lambda): New function.
(vm_apply_env): Rename from apply_env. Remove parameters, instead
use r1, r2 and r0.
(vm_evlis_env, vm_eval_env, vm_expand_macro_env, vm_begin_env,
vm_if_env): Likewise.
(acons): New function.
(mes_environment) [!MES_FULL, MES_MINI]: Add cpp switches to create minimally
filled environment, for debugging.
(main): Print free value at exit.
* define.c (define_env): Use vm_call-indirection.
(vm_define_env): Rename from define_env.
* quasiquote.c (eval_quasiquote): Use vm_call-indirection.
(vm_eval_quasiquote): Rename from eval_quasiquote.
* tests/gc-2.test: New test.
tests/gc-2a.test: New test.
tests/gc-3.test: New test.
2016-10-28 17:42:03 +01:00
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
SCM aa;
|
|
|
|
|
SCM args;
|
|
|
|
|
SCM body;
|
|
|
|
|
SCM cl;
|
|
|
|
|
SCM entry;
|
|
|
|
|
SCM expanders;
|
|
|
|
|
SCM formals;
|
|
|
|
|
SCM input;
|
|
|
|
|
SCM name;
|
|
|
|
|
SCM macro;
|
|
|
|
|
SCM p;
|
|
|
|
|
SCM program;
|
|
|
|
|
SCM sc_expand;
|
|
|
|
|
SCM x;
|
|
|
|
|
int global_p;
|
|
|
|
|
int macro_p;
|
|
|
|
|
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
eval_apply:
|
2017-04-01 22:00:50 +01:00
|
|
|
|
gc_check ();
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
switch (r3)
|
2016-12-22 15:34:28 +00:00
|
|
|
|
{
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
case cell_vm_evlis: goto evlis;
|
|
|
|
|
case cell_vm_evlis2: goto evlis2;
|
|
|
|
|
case cell_vm_evlis3: goto evlis3;
|
|
|
|
|
case cell_vm_apply: goto apply;
|
|
|
|
|
case cell_vm_apply2: goto apply2;
|
|
|
|
|
case cell_vm_eval: goto eval;
|
2017-12-09 07:33:50 +00:00
|
|
|
|
case cell_vm_eval_pmatch_car: goto eval_pmatch_car;
|
|
|
|
|
case cell_vm_eval_pmatch_cdr: goto eval_pmatch_cdr;
|
2017-12-09 07:24:38 +00:00
|
|
|
|
case cell_vm_eval_define: goto eval_define;
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
case cell_vm_eval_set_x: goto eval_set_x;
|
2018-03-04 09:05:55 +00:00
|
|
|
|
case cell_vm_eval_macro_expand_eval: goto eval_macro_expand_eval;
|
|
|
|
|
case cell_vm_eval_macro_expand_expand: goto eval_macro_expand_expand;
|
2017-03-27 19:14:48 +01:00
|
|
|
|
case cell_vm_eval_check_func: goto eval_check_func;
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
case cell_vm_eval2: goto eval2;
|
|
|
|
|
case cell_vm_macro_expand: goto macro_expand;
|
2018-03-04 09:05:55 +00:00
|
|
|
|
case cell_vm_macro_expand_define: goto macro_expand_define;
|
|
|
|
|
case cell_vm_macro_expand_define_macro: goto macro_expand_define_macro;
|
|
|
|
|
case cell_vm_macro_expand_lambda: goto macro_expand_lambda;
|
|
|
|
|
case cell_vm_macro_expand_set_x: goto macro_expand_set_x;
|
|
|
|
|
case cell_vm_macro_expand_car: goto macro_expand_car;
|
|
|
|
|
case cell_vm_macro_expand_cdr: goto macro_expand_cdr;
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
case cell_vm_begin: goto begin;
|
2018-03-04 09:05:55 +00:00
|
|
|
|
case cell_vm_begin_eval: goto begin_eval;
|
|
|
|
|
case cell_vm_begin_primitive_load: goto begin_primitive_load;
|
|
|
|
|
case cell_vm_begin_expand: goto begin_expand;
|
|
|
|
|
case cell_vm_begin_expand_eval: goto begin_expand_eval;
|
|
|
|
|
case cell_vm_begin_expand_macro: goto begin_expand_macro;
|
|
|
|
|
case cell_vm_begin_expand_primitive_load: goto begin_expand_primitive_load;
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
case cell_vm_if: goto vm_if;
|
|
|
|
|
case cell_vm_if_expr: goto if_expr;
|
2016-12-28 21:04:57 +00:00
|
|
|
|
case cell_vm_call_with_current_continuation2: goto call_with_current_continuation2;
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
case cell_vm_call_with_values2: goto call_with_values2;
|
|
|
|
|
case cell_vm_return: goto vm_return;
|
|
|
|
|
case cell_unspecified: return r1;
|
|
|
|
|
default:
|
|
|
|
|
assert (0);
|
2016-12-22 15:34:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
evlis:
|
2017-04-01 22:00:50 +01:00
|
|
|
|
gc_check ();
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (r1 == cell_nil)
|
|
|
|
|
goto vm_return;
|
|
|
|
|
if (TYPE (r1) != TPAIR)
|
|
|
|
|
goto eval;
|
2017-04-12 20:27:59 +01:00
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_evlis2);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto eval;
|
|
|
|
|
evlis2:
|
2017-04-12 20:27:59 +01:00
|
|
|
|
push_cc (CDR (r2), r1, r0, cell_vm_evlis3);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto evlis;
|
|
|
|
|
evlis3:
|
|
|
|
|
r1 = cons (r2, r1);
|
|
|
|
|
goto vm_return;
|
2016-12-22 15:34:28 +00:00
|
|
|
|
|
|
|
|
|
apply:
|
2017-04-01 22:00:50 +01:00
|
|
|
|
gc_check ();
|
2017-04-12 20:27:59 +01:00
|
|
|
|
switch (TYPE (CAR (r1)))
|
2016-05-28 15:39:44 +01:00
|
|
|
|
{
|
2017-12-09 07:33:50 +00:00
|
|
|
|
case TFUNCTION:
|
|
|
|
|
{
|
|
|
|
|
check_formals (CAR (r1), MAKE_NUMBER (FUNCTION (CAR (r1)).arity), CDR (r1));
|
|
|
|
|
r1 = call (CAR (r1), CDR (r1)); /// FIXME: move into eval_apply
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
case TCLOSURE:
|
2016-12-14 18:02:19 +00:00
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
cl = CLOSURE (CAR (r1));
|
|
|
|
|
body = CDDR (cl);
|
|
|
|
|
formals = CADR (cl);
|
|
|
|
|
args = CDR (r1);
|
|
|
|
|
aa = CDAR (cl);
|
2017-04-12 20:27:59 +01:00
|
|
|
|
aa = CDR (aa);
|
|
|
|
|
check_formals (CAR (r1), formals, CDR (r1));
|
2018-04-12 06:07:24 +01:00
|
|
|
|
p = pairlis (formals, args, aa);
|
2016-12-23 17:48:36 +00:00
|
|
|
|
call_lambda (body, p, aa, r0);
|
|
|
|
|
goto begin;
|
|
|
|
|
}
|
2017-12-09 07:33:50 +00:00
|
|
|
|
case TCONTINUATION:
|
|
|
|
|
{
|
|
|
|
|
x = r1;
|
|
|
|
|
g_stack = CONTINUATION (CAR (r1));
|
|
|
|
|
gc_pop_frame ();
|
|
|
|
|
r1 = CADR (x);
|
|
|
|
|
goto eval_apply;
|
|
|
|
|
}
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
case TSPECIAL:
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
switch (CAR (r1))
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
{
|
|
|
|
|
case cell_vm_apply:
|
|
|
|
|
{
|
|
|
|
|
push_cc (cons (CADR (r1), CADDR (r1)), r1, r0, cell_vm_return);
|
|
|
|
|
goto apply;
|
|
|
|
|
}
|
|
|
|
|
case cell_vm_eval:
|
|
|
|
|
{
|
|
|
|
|
push_cc (CADR (r1), r1, CADDR (r1), cell_vm_return);
|
|
|
|
|
goto eval;
|
|
|
|
|
}
|
2016-12-28 21:04:57 +00:00
|
|
|
|
case cell_call_with_current_continuation:
|
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
r1 = CDR (r1);
|
2016-12-28 21:04:57 +00:00
|
|
|
|
goto call_with_current_continuation;
|
|
|
|
|
}
|
2017-04-12 20:27:59 +01:00
|
|
|
|
default: check_apply (cell_f, CAR (r1));
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
case TSYMBOL:
|
2016-12-23 17:48:36 +00:00
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
if (CAR (r1) == cell_symbol_call_with_values)
|
2016-12-23 17:48:36 +00:00
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
r1 = CDR (r1);
|
2016-12-23 17:48:36 +00:00
|
|
|
|
goto call_with_values;
|
|
|
|
|
}
|
2017-04-12 20:27:59 +01:00
|
|
|
|
if (CAR (r1) == cell_symbol_current_module)
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
{
|
|
|
|
|
r1 = r0;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
2016-12-23 17:48:36 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
case TPAIR:
|
2016-12-23 17:48:36 +00:00
|
|
|
|
{
|
2017-03-25 14:58:44 +00:00
|
|
|
|
switch (CAAR (r1))
|
2016-12-23 17:48:36 +00:00
|
|
|
|
{
|
|
|
|
|
case cell_symbol_lambda:
|
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
formals = CADR (CAR (r1));
|
|
|
|
|
args = CDR (r1);
|
|
|
|
|
body = CDDR (CAR (r1));
|
|
|
|
|
p = pairlis (formals, CDR (r1), r0);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
check_formals (r1, formals, args);
|
2016-12-23 17:48:36 +00:00
|
|
|
|
call_lambda (body, p, p, r0);
|
|
|
|
|
goto begin;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-14 18:02:19 +00:00
|
|
|
|
}
|
2016-12-23 17:48:36 +00:00
|
|
|
|
}
|
2017-04-12 20:27:59 +01:00
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_apply2);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto eval;
|
|
|
|
|
apply2:
|
2017-04-12 20:27:59 +01:00
|
|
|
|
check_apply (r1, CAR (r2));
|
|
|
|
|
r1 = cons (r1, CDR (r2));
|
2016-12-22 15:50:51 +00:00
|
|
|
|
goto apply;
|
2016-05-28 15:39:44 +01:00
|
|
|
|
|
2016-12-22 15:34:28 +00:00
|
|
|
|
eval:
|
2017-04-01 22:00:50 +01:00
|
|
|
|
gc_check ();
|
2016-11-21 08:30:59 +00:00
|
|
|
|
switch (TYPE (r1))
|
2016-05-28 15:39:44 +01:00
|
|
|
|
{
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
case TPAIR:
|
2016-11-03 20:43:01 +00:00
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
switch (CAR (r1))
|
2016-12-14 18:02:19 +00:00
|
|
|
|
{
|
2017-12-09 07:33:50 +00:00
|
|
|
|
case cell_symbol_pmatch_car:
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
{
|
2017-12-09 07:33:50 +00:00
|
|
|
|
push_cc (CADR (r1), r1, r0, cell_vm_eval_pmatch_car);
|
|
|
|
|
goto eval;
|
|
|
|
|
eval_pmatch_car:
|
|
|
|
|
x = r1;
|
|
|
|
|
gc_pop_frame ();
|
|
|
|
|
r1 = CAR (x);
|
|
|
|
|
goto eval_apply;
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
}
|
2017-12-09 07:33:50 +00:00
|
|
|
|
case cell_symbol_pmatch_cdr:
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
{
|
2017-12-09 07:33:50 +00:00
|
|
|
|
push_cc (CADR (r1), r1, r0, cell_vm_eval_pmatch_cdr);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto eval;
|
2017-12-09 07:33:50 +00:00
|
|
|
|
eval_pmatch_cdr:
|
|
|
|
|
x = r1;
|
|
|
|
|
gc_pop_frame ();
|
|
|
|
|
r1 = CDR (x);
|
|
|
|
|
goto eval_apply;
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
}
|
|
|
|
|
case cell_symbol_quote:
|
|
|
|
|
{
|
2017-12-09 07:33:50 +00:00
|
|
|
|
x = r1;
|
|
|
|
|
gc_pop_frame ();
|
|
|
|
|
r1 = CADR (x);
|
|
|
|
|
goto eval_apply;
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
}
|
2016-12-22 15:50:51 +00:00
|
|
|
|
case cell_symbol_begin: goto begin;
|
2016-12-14 18:02:19 +00:00
|
|
|
|
case cell_symbol_lambda:
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
{
|
2017-12-09 07:33:50 +00:00
|
|
|
|
r1 = make_closure_ (CADR (r1), CDDR (r1), r0);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
2017-12-09 07:33:50 +00:00
|
|
|
|
case cell_symbol_if:
|
|
|
|
|
{
|
|
|
|
|
r1=CDR (r1);
|
|
|
|
|
goto vm_if;
|
|
|
|
|
}
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
case cell_symbol_set_x:
|
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
push_cc (CAR (CDDR (r1)), r1, r0, cell_vm_eval_set_x);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto eval;
|
|
|
|
|
eval_set_x:
|
2017-12-09 07:33:50 +00:00
|
|
|
|
r1 = set_env_x (CADR (r2), r1, r0);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
|
|
|
|
case cell_vm_macro_expand:
|
|
|
|
|
{
|
2018-03-04 09:05:55 +00:00
|
|
|
|
push_cc (CADR (r1), r1, r0, cell_vm_eval_macro_expand_eval);
|
2018-01-01 14:53:13 +00:00
|
|
|
|
goto eval;
|
2018-03-04 09:05:55 +00:00
|
|
|
|
eval_macro_expand_eval:
|
|
|
|
|
push_cc (r1, r2, r0, cell_vm_eval_macro_expand_expand);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
eval_macro_expand_expand:
|
|
|
|
|
goto vm_return;
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
}
|
2018-02-03 20:43:52 +00:00
|
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
if (TYPE (r1) == TPAIR
|
|
|
|
|
&& (CAR (r1) == cell_symbol_define
|
2017-12-09 07:33:50 +00:00
|
|
|
|
|| CAR (r1) == cell_symbol_define_macro))
|
2018-02-03 20:43:52 +00:00
|
|
|
|
{
|
2017-12-09 07:33:50 +00:00
|
|
|
|
int global_p = CAAR (r0) != cell_closure;
|
|
|
|
|
int macro_p = CAR (r1) == cell_symbol_define_macro;
|
|
|
|
|
if (global_p)
|
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
name = CADR (r1);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
if (TYPE (CADR (r1)) == TPAIR)
|
|
|
|
|
name = CAR (name);
|
|
|
|
|
if (macro_p)
|
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
entry = assq (name, g_macros);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
if (entry == cell_f)
|
|
|
|
|
{
|
|
|
|
|
entry = cons (name, cell_f);
|
|
|
|
|
g_macros = cons (entry, g_macros);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
entry = assq (name, r0);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
if (entry == cell_f)
|
|
|
|
|
{
|
|
|
|
|
entry = cons (name, cell_f);
|
2018-04-12 06:07:24 +01:00
|
|
|
|
aa = cons (entry, cell_nil);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
set_cdr_x (aa, cdr (r0));
|
|
|
|
|
set_cdr_x (r0, aa);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-03 20:43:52 +00:00
|
|
|
|
r2 = r1;
|
|
|
|
|
if (TYPE (CADR (r1)) != TPAIR)
|
|
|
|
|
{
|
|
|
|
|
push_cc (CAR (CDDR (r1)), r2, cons (cons (CADR (r1), CADR (r1)), r0), cell_vm_eval_define);
|
|
|
|
|
goto eval;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
p = pairlis (CADR (r1), CADR (r1), r0);
|
|
|
|
|
formals = CDR (CADR (r1));
|
|
|
|
|
body = CDDR (r1);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (macro_p || global_p)
|
|
|
|
|
expand_variable (body, formals);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
r1 = cons (cell_symbol_lambda, cons (formals, body));
|
2018-02-03 20:43:52 +00:00
|
|
|
|
push_cc (r1, r2, p, cell_vm_eval_define);
|
|
|
|
|
goto eval;
|
|
|
|
|
}
|
|
|
|
|
eval_define:;
|
2018-04-12 06:07:24 +01:00
|
|
|
|
name = CADR (r2);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
if (TYPE (CADR (r2)) == TPAIR)
|
|
|
|
|
name = CAR (name);
|
|
|
|
|
if (macro_p)
|
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
entry = assq (name, g_macros);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
r1 = MAKE_MACRO (name, r1);
|
|
|
|
|
set_cdr_x (entry, r1);
|
|
|
|
|
}
|
|
|
|
|
else if (global_p)
|
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
entry = assq (name, r0);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
set_cdr_x (entry, r1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
entry = cons (name, r1);
|
|
|
|
|
aa = cons (entry, cell_nil);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
set_cdr_x (aa, cdr (r0));
|
|
|
|
|
set_cdr_x (r0, aa);
|
2018-04-12 06:07:24 +01:00
|
|
|
|
cl = assq (cell_closure, r0);
|
2017-12-09 07:33:50 +00:00
|
|
|
|
set_cdr_x (cl, aa);
|
|
|
|
|
}
|
2018-02-03 20:43:52 +00:00
|
|
|
|
r1 = cell_unspecified;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
2017-12-09 07:33:50 +00:00
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_eval_check_func);
|
|
|
|
|
goto eval;
|
2017-03-27 19:14:48 +01:00
|
|
|
|
eval_check_func:
|
2017-12-09 07:33:50 +00:00
|
|
|
|
push_cc (CDR (r2), r2, r0, cell_vm_eval2);
|
|
|
|
|
goto evlis;
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
eval2:
|
2018-03-04 09:05:55 +00:00
|
|
|
|
r1 = cons (CAR (r2), r1);
|
|
|
|
|
goto apply;
|
2017-12-09 07:33:50 +00:00
|
|
|
|
}
|
2016-12-14 18:02:19 +00:00
|
|
|
|
}
|
2016-11-03 20:43:01 +00:00
|
|
|
|
}
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
case TSYMBOL:
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
{
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (r1 == cell_symbol_current_module)
|
|
|
|
|
goto vm_return;
|
2017-12-09 07:33:50 +00:00
|
|
|
|
if (r1 == cell_symbol_begin) // FIXME
|
|
|
|
|
{
|
|
|
|
|
r1 = cell_begin;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
r1 = assert_defined (r1, assq_ref_env (r1, r0));
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
2017-12-09 07:33:50 +00:00
|
|
|
|
case TVARIABLE:
|
|
|
|
|
{
|
|
|
|
|
r1 = CDR (VARIABLE (r1));
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
default: goto vm_return;
|
2016-05-28 15:39:44 +01:00
|
|
|
|
}
|
2016-10-08 16:00:32 +01:00
|
|
|
|
|
2016-12-23 21:48:27 +00:00
|
|
|
|
macro_expand:
|
2018-03-04 09:05:55 +00:00
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
macro;
|
|
|
|
|
expanders;
|
2016-10-30 15:16:20 +00:00
|
|
|
|
|
2018-03-04 09:05:55 +00:00
|
|
|
|
if (TYPE (r1) != TPAIR || CAR (r1) == cell_symbol_quote)
|
|
|
|
|
goto vm_return;
|
|
|
|
|
|
2017-12-09 07:33:50 +00:00
|
|
|
|
if (CAR (r1) == cell_symbol_lambda)
|
|
|
|
|
{
|
|
|
|
|
push_cc (CDDR (r1), r1, r0, cell_vm_macro_expand_lambda);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
macro_expand_lambda:
|
|
|
|
|
CDDR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-04 09:05:55 +00:00
|
|
|
|
if (TYPE (r1) == TPAIR
|
2017-12-09 07:33:50 +00:00
|
|
|
|
&& (macro = lookup_macro_ (CAR (r1), g_macros)) != cell_f)
|
2018-03-04 09:05:55 +00:00
|
|
|
|
{
|
|
|
|
|
r1 = cons (macro, CDR (r1));
|
|
|
|
|
push_cc (r1, cell_nil, r0, cell_vm_macro_expand);
|
|
|
|
|
goto apply;
|
|
|
|
|
}
|
2017-12-09 07:33:50 +00:00
|
|
|
|
|
2018-03-04 09:05:55 +00:00
|
|
|
|
if (CAR (r1) == cell_symbol_define
|
|
|
|
|
|| CAR (r1) == cell_symbol_define_macro)
|
2016-12-07 19:26:41 +00:00
|
|
|
|
{
|
2018-03-04 09:05:55 +00:00
|
|
|
|
push_cc (CDDR (r1), r1, r0, cell_vm_macro_expand_define);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
macro_expand_define:
|
|
|
|
|
CDDR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
if (CAR (r1) == cell_symbol_define_macro)
|
2016-12-13 18:58:34 +00:00
|
|
|
|
{
|
2018-03-04 09:05:55 +00:00
|
|
|
|
push_cc (r1, r1, r0, cell_vm_macro_expand_define_macro);
|
|
|
|
|
goto eval;
|
|
|
|
|
macro_expand_define_macro:
|
|
|
|
|
r1 = r2;
|
2016-12-13 18:58:34 +00:00
|
|
|
|
}
|
2018-03-04 09:05:55 +00:00
|
|
|
|
goto vm_return;
|
2016-12-07 19:26:41 +00:00
|
|
|
|
}
|
2018-03-04 09:05:55 +00:00
|
|
|
|
|
|
|
|
|
if (CAR (r1) == cell_symbol_set_x)
|
|
|
|
|
{
|
|
|
|
|
push_cc (CDDR (r1), r1, r0, cell_vm_macro_expand_set_x);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
macro_expand_set_x:
|
|
|
|
|
CDDR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TYPE (r1) == TPAIR
|
|
|
|
|
&& TYPE (CAR (r1)) == TSYMBOL
|
|
|
|
|
&& CAR (r1) != cell_symbol_begin
|
2017-12-09 07:33:50 +00:00
|
|
|
|
&& ((macro = assq (cell_symbol_portable_macro_expand, g_macros)) != cell_f)
|
2018-03-04 09:05:55 +00:00
|
|
|
|
&& ((expanders = assq_ref_env (cell_symbol_sc_expander_alist, r0)) != cell_undefined)
|
|
|
|
|
&& ((macro = assq (CAR (r1), expanders)) != cell_f))
|
2016-12-22 15:50:51 +00:00
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
sc_expand = assq_ref_env (cell_symbol_macro_expand, r0);
|
2018-03-04 09:05:55 +00:00
|
|
|
|
r2 = r1;
|
|
|
|
|
if (sc_expand != cell_undefined && sc_expand != cell_f)
|
|
|
|
|
{
|
|
|
|
|
r1 = cons (sc_expand, cons (r1, cell_nil));
|
|
|
|
|
goto apply;
|
|
|
|
|
}
|
2016-12-22 15:50:51 +00:00
|
|
|
|
}
|
2018-03-04 09:05:55 +00:00
|
|
|
|
|
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_macro_expand_car);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
|
|
|
|
|
macro_expand_car:
|
|
|
|
|
CAR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
if (CDR (r1) == cell_nil)
|
|
|
|
|
goto vm_return;
|
|
|
|
|
|
|
|
|
|
push_cc (CDR (r1), r1, r0, cell_vm_macro_expand_cdr);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
|
|
|
|
|
macro_expand_cdr:
|
|
|
|
|
CDR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
|
|
|
|
|
goto vm_return;
|
2016-11-21 08:36:32 +00:00
|
|
|
|
}
|
2018-03-04 09:05:55 +00:00
|
|
|
|
|
|
|
|
|
begin:
|
|
|
|
|
x = cell_unspecified;
|
|
|
|
|
while (r1 != cell_nil)
|
|
|
|
|
{
|
|
|
|
|
gc_check ();
|
|
|
|
|
if (TYPE (r1) == TPAIR)
|
|
|
|
|
{
|
|
|
|
|
if (CAAR (r1) == cell_symbol_primitive_load)
|
|
|
|
|
{
|
2018-04-12 06:07:24 +01:00
|
|
|
|
program = cons (CAR (r1), cell_nil);
|
2018-03-04 09:05:55 +00:00
|
|
|
|
push_cc (program, r1, r0, cell_vm_begin_primitive_load);
|
|
|
|
|
goto begin_expand;
|
|
|
|
|
begin_primitive_load:
|
|
|
|
|
CAR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TYPE (r1) == TPAIR && TYPE (CAR (r1)) == TPAIR)
|
|
|
|
|
{
|
|
|
|
|
if (CAAR (r1) == cell_symbol_begin)
|
|
|
|
|
r1 = append2 (CDAR (r1), CDR (r1));
|
|
|
|
|
}
|
|
|
|
|
if (CDR (r1) == cell_nil)
|
|
|
|
|
{
|
|
|
|
|
r1 = CAR (r1);
|
|
|
|
|
goto eval;
|
|
|
|
|
}
|
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_begin_eval);
|
|
|
|
|
goto eval;
|
|
|
|
|
begin_eval:
|
|
|
|
|
x = r1;
|
|
|
|
|
r1 = CDR (r2);
|
|
|
|
|
}
|
|
|
|
|
r1 = x;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
begin_expand:
|
|
|
|
|
x = cell_unspecified;
|
|
|
|
|
while (r1 != cell_nil)
|
|
|
|
|
{
|
|
|
|
|
gc_check ();
|
|
|
|
|
|
|
|
|
|
if (TYPE (r1) == TPAIR)
|
|
|
|
|
{
|
|
|
|
|
if (TYPE (CAR (r1)) == TPAIR && CAAR (r1) == cell_symbol_begin)
|
|
|
|
|
r1 = append2 (CDAR (r1), CDR (r1));
|
|
|
|
|
if (CAAR (r1) == cell_symbol_primitive_load)
|
|
|
|
|
{
|
|
|
|
|
push_cc (CADR (CAR (r1)), r1, r0, cell_vm_begin_expand_primitive_load);
|
|
|
|
|
goto eval; // FIXME: expand too?!
|
|
|
|
|
begin_expand_primitive_load:;
|
2018-04-12 06:07:24 +01:00
|
|
|
|
input; // = current_input_port ();
|
2018-03-04 09:05:55 +00:00
|
|
|
|
if (TYPE (r1) == TNUMBER && VALUE (r1) == 0)
|
|
|
|
|
;
|
|
|
|
|
else if (TYPE (r1) == TSTRING)
|
|
|
|
|
input = set_current_input_port (open_input_file (r1));
|
|
|
|
|
else
|
|
|
|
|
assert (0);
|
|
|
|
|
|
|
|
|
|
push_cc (input, r2, r0, cell_vm_return);
|
|
|
|
|
x = read_input_file_env (r0);
|
|
|
|
|
gc_pop_frame ();
|
|
|
|
|
input = r1;
|
|
|
|
|
r1 = x;
|
|
|
|
|
set_current_input_port (input);
|
|
|
|
|
r1 = cons (cell_symbol_begin, r1);
|
|
|
|
|
CAR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_begin_expand_macro);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
begin_expand_macro:
|
|
|
|
|
if (r1 != CAR (r2))
|
|
|
|
|
{
|
|
|
|
|
CAR (r2) = r1;
|
|
|
|
|
r1 = r2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
r1 = r2;
|
2017-12-09 07:33:50 +00:00
|
|
|
|
expand_variable (CAR (r1), cell_nil);
|
|
|
|
|
//eputs ("expanded r1="); write_error_ (CAR (r1)); eputs ("\n");
|
2018-03-04 09:05:55 +00:00
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_begin_expand_eval);
|
|
|
|
|
goto eval;
|
|
|
|
|
begin_expand_eval:
|
|
|
|
|
x = r1;
|
|
|
|
|
r1 = CDR (r2);
|
|
|
|
|
}
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
r1 = x;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
|
|
|
|
|
vm_if:
|
2017-04-12 20:27:59 +01:00
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_if_expr);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto eval;
|
|
|
|
|
if_expr:
|
|
|
|
|
x = r1;
|
|
|
|
|
r1 = r2;
|
2016-11-21 08:36:32 +00:00
|
|
|
|
if (x != cell_f)
|
2016-12-22 15:50:51 +00:00
|
|
|
|
{
|
2017-03-25 14:58:44 +00:00
|
|
|
|
r1 = CADR (r1);
|
2016-12-22 15:50:51 +00:00
|
|
|
|
goto eval;
|
|
|
|
|
}
|
2017-03-25 14:58:44 +00:00
|
|
|
|
if (CDDR (r1) != cell_nil)
|
2016-12-22 15:50:51 +00:00
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
r1 = CAR (CDDR (r1));
|
2016-12-22 15:50:51 +00:00
|
|
|
|
goto eval;
|
|
|
|
|
}
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
r1 = cell_unspecified;
|
|
|
|
|
goto vm_return;
|
2016-11-21 08:36:32 +00:00
|
|
|
|
|
2016-12-28 21:04:57 +00:00
|
|
|
|
call_with_current_continuation:
|
|
|
|
|
gc_push_frame ();
|
|
|
|
|
x = MAKE_CONTINUATION (g_continuations++);
|
|
|
|
|
gc_pop_frame ();
|
2017-04-12 20:27:59 +01:00
|
|
|
|
push_cc (cons (CAR (r1), cons (x, cell_nil)), x, r0, cell_vm_call_with_current_continuation2);
|
2016-12-28 21:04:57 +00:00
|
|
|
|
goto apply;
|
|
|
|
|
call_with_current_continuation2:
|
|
|
|
|
CONTINUATION (r2) = g_stack;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
|
2016-12-22 15:34:28 +00:00
|
|
|
|
call_with_values:
|
2017-04-12 20:27:59 +01:00
|
|
|
|
push_cc (cons (CAR (r1), cell_nil), r1, r0, cell_vm_call_with_values2);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
goto apply;
|
|
|
|
|
call_with_values2:
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
if (TYPE (r1) == TVALUES)
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
r1 = CDR (r1);
|
2017-03-25 14:58:44 +00:00
|
|
|
|
r1 = cons (CADR (r2), r1);
|
2016-12-22 15:50:51 +00:00
|
|
|
|
goto apply;
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
|
|
|
|
|
vm_return:
|
|
|
|
|
x = r1;
|
|
|
|
|
gc_pop_frame ();
|
|
|
|
|
r1 = x;
|
|
|
|
|
goto eval_apply;
|
2016-12-10 11:07:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:36:32 +00:00
|
|
|
|
SCM
|
2017-04-10 18:13:20 +01:00
|
|
|
|
apply (SCM f, SCM x, SCM a) ///((internal))
|
2016-11-21 08:36:32 +00:00
|
|
|
|
{
|
2017-04-10 18:13:20 +01:00
|
|
|
|
push_cc (cons (f, x), cell_unspecified, r0, cell_unspecified);
|
|
|
|
|
r3 = cell_vm_apply;
|
|
|
|
|
return eval_apply ();
|
2016-11-21 08:36:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-02 16:01:22 +01:00
|
|
|
|
SCM
|
2017-04-10 18:13:20 +01:00
|
|
|
|
mes_g_stack (SCM a) ///((internal))
|
2017-04-02 16:01:22 +01:00
|
|
|
|
{
|
|
|
|
|
r0 = a;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
r1 = MAKE_CHAR (0);
|
|
|
|
|
r2 = MAKE_CHAR (0);
|
|
|
|
|
r3 = MAKE_CHAR (0);
|
|
|
|
|
g_stack = cons (cell_nil, cell_nil);
|
|
|
|
|
return r0;
|
2017-04-02 16:01:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
// Environment setup
|
2016-12-10 11:07:04 +00:00
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
SCM
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
make_tmps (struct scm* cells)
|
2016-12-10 11:07:04 +00:00
|
|
|
|
{
|
2017-01-04 07:16:14 +00:00
|
|
|
|
tmp = g_free++;
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
cells[tmp].type = TCHAR;
|
2017-01-04 07:16:14 +00:00
|
|
|
|
tmp_num = g_free++;
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
cells[tmp_num].type = TNUMBER;
|
2017-01-04 07:16:14 +00:00
|
|
|
|
tmp_num2 = g_free++;
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
cells[tmp_num2].type = TNUMBER;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
return 0;
|
2016-12-10 11:07:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#include "posix.c"
|
|
|
|
|
#include "math.c"
|
|
|
|
|
#include "lib.c"
|
|
|
|
|
|
|
|
|
|
// Jam Collector
|
|
|
|
|
SCM g_symbol_max;
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
gc_init_cells () ///((internal))
|
2016-05-15 23:07:44 +01:00
|
|
|
|
{
|
2017-04-10 18:13:20 +01:00
|
|
|
|
g_cells = (struct scm *)malloc (2*ARENA_SIZE*sizeof (struct scm));
|
|
|
|
|
|
|
|
|
|
TYPE (0) = TVECTOR;
|
|
|
|
|
LENGTH (0) = 1000;
|
|
|
|
|
VECTOR (0) = 0;
|
|
|
|
|
#if __MESC__
|
|
|
|
|
g_cells += sizeof (struct scm);
|
|
|
|
|
#else
|
core: Integrate garbage collector/jam scraper.
* mes.c (r0, r1, r2, r3, stack): New globals.
(gc_loop): Handle MACRO and SCM.
(gc_copy): Handle FUNCTION, allow for pre-allocated SCM and SYMBOL.
(assq): Flag any BROKEN_HEARTs.
(vm_call): New function. Enables moving C stack to GC stack.
(evlis_env, apply_env, eval_env, expand_macro_env, begin_env,
if_env): Use vm_call-indirection.
(call_lambda): New function.
(vm_apply_env): Rename from apply_env. Remove parameters, instead
use r1, r2 and r0.
(vm_evlis_env, vm_eval_env, vm_expand_macro_env, vm_begin_env,
vm_if_env): Likewise.
(acons): New function.
(mes_environment) [!MES_FULL, MES_MINI]: Add cpp switches to create minimally
filled environment, for debugging.
(main): Print free value at exit.
* define.c (define_env): Use vm_call-indirection.
(vm_define_env): Rename from define_env.
* quasiquote.c (eval_quasiquote): Use vm_call-indirection.
(vm_eval_quasiquote): Rename from eval_quasiquote.
* tests/gc-2.test: New test.
tests/gc-2a.test: New test.
tests/gc-3.test: New test.
2016-10-28 17:42:03 +01:00
|
|
|
|
g_cells++;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#endif
|
|
|
|
|
TYPE (0) = TCHAR;
|
|
|
|
|
VALUE (0) = 'c';
|
|
|
|
|
return 0;
|
2016-12-11 07:23:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
gc_init_news () ///((internal))
|
2016-12-11 07:23:15 +00:00
|
|
|
|
{
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#if __MESC__
|
|
|
|
|
char *p = g_cells;
|
|
|
|
|
p -= sizeof (struct scm);
|
|
|
|
|
p += ARENA_SIZE * sizeof (struct scm);
|
|
|
|
|
g_news = p;
|
|
|
|
|
#else
|
2016-12-11 07:23:15 +00:00
|
|
|
|
g_news = g_cells-1 + ARENA_SIZE;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
NTYPE (0) = TVECTOR;
|
|
|
|
|
NLENGTH (0) = 1000;
|
|
|
|
|
NVECTOR (0) = 0;
|
|
|
|
|
#if __MESC__
|
|
|
|
|
g_news += sizeof (struct scm);
|
|
|
|
|
#else
|
2016-12-11 07:23:15 +00:00
|
|
|
|
g_news++;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#endif
|
|
|
|
|
NTYPE (0) = TCHAR;
|
|
|
|
|
NVALUE (0) = 'n';
|
|
|
|
|
return 0;
|
2016-12-11 07:23:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
mes_symbols () ///((internal))
|
|
|
|
|
{
|
|
|
|
|
gc_init_cells ();
|
|
|
|
|
gc_init_news ();
|
2016-11-21 08:28:34 +00:00
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#if !_POSIX_SOURCE
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#include "mes.mes.symbols.i"
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#else
|
2016-11-21 08:28:34 +00:00
|
|
|
|
#include "mes.symbols.i"
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#endif
|
2016-11-21 08:28:34 +00:00
|
|
|
|
|
2017-01-04 07:16:14 +00:00
|
|
|
|
g_symbol_max = g_free;
|
2016-12-10 11:07:04 +00:00
|
|
|
|
make_tmps (g_cells);
|
2016-11-21 08:28:34 +00:00
|
|
|
|
|
2016-12-10 11:07:04 +00:00
|
|
|
|
g_symbols = 0;
|
|
|
|
|
for (int i=1; i<g_symbol_max; i++)
|
|
|
|
|
g_symbols = cons (i, g_symbols);
|
2016-11-19 22:25:24 +00:00
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM a = cell_nil;
|
2016-10-20 17:43:33 +01:00
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#if !_POSIX_SOURCE
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#include "mes.mes.symbol-names.i"
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#else
|
2016-12-23 09:38:41 +00:00
|
|
|
|
#include "mes.symbol-names.i"
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#endif
|
2016-12-23 09:38:41 +00:00
|
|
|
|
|
2016-12-25 14:38:26 +00:00
|
|
|
|
a = acons (cell_symbol_mes_version, MAKE_STRING (cstring_to_list (VERSION)), a);
|
|
|
|
|
a = acons (cell_symbol_mes_prefix, MAKE_STRING (cstring_to_list (PREFIX)), a);
|
|
|
|
|
|
2017-03-27 19:14:48 +01:00
|
|
|
|
a = acons (cell_symbol_call_with_values, cell_symbol_call_with_values, a);
|
|
|
|
|
a = acons (cell_symbol_current_module, cell_symbol_current_module, a);
|
2016-12-28 21:04:57 +00:00
|
|
|
|
a = acons (cell_symbol_call_with_current_continuation, cell_call_with_current_continuation, a);
|
2018-04-09 06:12:38 +01:00
|
|
|
|
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
|
|
|
|
|
#if __GNUC__
|
|
|
|
|
a = acons (cell_symbol_gnuc, cell_t, a);
|
|
|
|
|
a = acons (cell_symbol_mesc, cell_f, a);
|
|
|
|
|
#else
|
|
|
|
|
a = acons (cell_symbol_gnuc, cell_f, a);
|
|
|
|
|
a = acons (cell_symbol_mesc, cell_t, a);
|
|
|
|
|
#endif
|
2016-11-19 22:25:24 +00:00
|
|
|
|
a = acons (cell_closure, a, a);
|
|
|
|
|
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
SCM
|
|
|
|
|
mes_environment () ///((internal))
|
|
|
|
|
{
|
|
|
|
|
SCM a = mes_symbols ();
|
|
|
|
|
return mes_g_stack (a);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-19 22:25:24 +00:00
|
|
|
|
SCM
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
|
mes_builtins (SCM a) ///((internal))
|
2016-11-19 22:25:24 +00:00
|
|
|
|
{
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#if !__GNUC__ || !_POSIX_SOURCE
|
|
|
|
|
#include "mes.mes.i"
|
2017-04-10 18:13:20 +01:00
|
|
|
|
|
2017-12-09 07:33:50 +00:00
|
|
|
|
// Do not sort: Order of these includes define builtins
|
2017-04-12 20:27:59 +01:00
|
|
|
|
#include "posix.mes.i"
|
|
|
|
|
#include "math.mes.i"
|
|
|
|
|
#include "lib.mes.i"
|
|
|
|
|
#include "vector.mes.i"
|
|
|
|
|
#include "gc.mes.i"
|
|
|
|
|
#include "reader.mes.i"
|
|
|
|
|
|
|
|
|
|
#include "gc.mes.environment.i"
|
|
|
|
|
#include "lib.mes.environment.i"
|
|
|
|
|
#include "math.mes.environment.i"
|
|
|
|
|
#include "mes.mes.environment.i"
|
|
|
|
|
#include "posix.mes.environment.i"
|
|
|
|
|
#include "reader.mes.environment.i"
|
|
|
|
|
#include "vector.mes.environment.i"
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#else
|
2016-11-19 22:25:24 +00:00
|
|
|
|
#include "mes.i"
|
|
|
|
|
|
2017-12-09 07:33:50 +00:00
|
|
|
|
// Do not sort: Order of these includes define builtins
|
2016-11-19 22:25:24 +00:00
|
|
|
|
#include "posix.i"
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
#include "math.i"
|
|
|
|
|
#include "lib.i"
|
|
|
|
|
#include "vector.i"
|
|
|
|
|
#include "gc.i"
|
2017-03-25 14:58:44 +00:00
|
|
|
|
#include "reader.i"
|
2016-11-19 22:25:24 +00:00
|
|
|
|
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
#include "gc.environment.i"
|
2016-10-22 19:51:32 +01:00
|
|
|
|
#include "lib.environment.i"
|
2016-11-21 08:28:34 +00:00
|
|
|
|
#include "math.environment.i"
|
2016-10-21 21:44:50 +01:00
|
|
|
|
#include "mes.environment.i"
|
2016-11-21 08:28:34 +00:00
|
|
|
|
#include "posix.environment.i"
|
2016-11-21 08:36:32 +00:00
|
|
|
|
#include "reader.environment.i"
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
#include "vector.environment.i"
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#endif
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
|
2018-04-09 06:12:38 +01:00
|
|
|
|
if (g_debug > 3)
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
{
|
2017-04-10 18:13:20 +01:00
|
|
|
|
fputs ("functions: ", STDERR);
|
|
|
|
|
fputs (itoa (g_function), STDERR);
|
|
|
|
|
fputs ("\n", STDERR);
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
for (int i = 0; i < g_function; i++)
|
|
|
|
|
{
|
2017-04-10 18:13:20 +01:00
|
|
|
|
fputs ("[", STDERR);
|
|
|
|
|
fputs (itoa (i), STDERR);
|
|
|
|
|
fputs ("]: ", STDERR);
|
|
|
|
|
fputs (g_functions[i].name, STDERR);
|
|
|
|
|
fputs ("\n", STDERR);
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
}
|
2017-04-10 18:13:20 +01:00
|
|
|
|
fputs ("\n", STDERR);
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 20:13:01 +01:00
|
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
|
|
2016-11-19 22:25:24 +00:00
|
|
|
|
return a;
|
|
|
|
|
}
|
core: Integrate garbage collector/jam scraper.
* mes.c (r0, r1, r2, r3, stack): New globals.
(gc_loop): Handle MACRO and SCM.
(gc_copy): Handle FUNCTION, allow for pre-allocated SCM and SYMBOL.
(assq): Flag any BROKEN_HEARTs.
(vm_call): New function. Enables moving C stack to GC stack.
(evlis_env, apply_env, eval_env, expand_macro_env, begin_env,
if_env): Use vm_call-indirection.
(call_lambda): New function.
(vm_apply_env): Rename from apply_env. Remove parameters, instead
use r1, r2 and r0.
(vm_evlis_env, vm_eval_env, vm_expand_macro_env, vm_begin_env,
vm_if_env): Likewise.
(acons): New function.
(mes_environment) [!MES_FULL, MES_MINI]: Add cpp switches to create minimally
filled environment, for debugging.
(main): Print free value at exit.
* define.c (define_env): Use vm_call-indirection.
(vm_define_env): Rename from define_env.
* quasiquote.c (eval_quasiquote): Use vm_call-indirection.
(vm_eval_quasiquote): Rename from eval_quasiquote.
* tests/gc-2.test: New test.
tests/gc-2a.test: New test.
tests/gc-3.test: New test.
2016-10-28 17:42:03 +01:00
|
|
|
|
|
2017-05-23 06:16:08 +01:00
|
|
|
|
SCM read_input_file_env (SCM);
|
|
|
|
|
|
mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
(assert_defined, check_formals, check_apply, load_env,
bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
math.c, mini-posix.h, posix.c.
(greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
logior, ash): Remove.
(ungetchar, peekchar, peek_byte, read_byte, write_byte,
string_to_cstring, getenv_, open_input_file, current_input_port,
set_current_input_port, force_output): Remove.
(mes_builtins): include mini-lib.i, mini-lib.environment.i.
mini-math.i, mini-math.environment.i mini-posix.i,
mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 14:01:24 +01:00
|
|
|
|
SCM
|
|
|
|
|
load_env (SCM a) ///((internal))
|
|
|
|
|
{
|
|
|
|
|
r0 = a;
|
2017-12-09 21:38:51 +00:00
|
|
|
|
g_stdin = -1;
|
2018-02-03 20:43:52 +00:00
|
|
|
|
char boot[128];
|
|
|
|
|
char buf[128];
|
|
|
|
|
if (getenv ("MES_BOOT"))
|
|
|
|
|
strcpy (boot, getenv ("MES_BOOT"));
|
|
|
|
|
else
|
|
|
|
|
strcpy (boot, "boot-0.scm");
|
2017-12-09 21:38:51 +00:00
|
|
|
|
if (getenv ("MES_PREFIX"))
|
|
|
|
|
{
|
|
|
|
|
strcpy (buf, getenv ("MES_PREFIX"));
|
|
|
|
|
strcpy (buf + strlen (buf), "/module");
|
2018-02-03 20:43:52 +00:00
|
|
|
|
strcpy (buf + strlen (buf), "/mes/");
|
|
|
|
|
strcpy (buf + strlen (buf), boot);
|
|
|
|
|
if (getenv ("MES_DEBUG"))
|
|
|
|
|
{
|
|
|
|
|
eputs ("MES_PREFIX reading boot-0:");
|
|
|
|
|
eputs (buf);
|
|
|
|
|
eputs ("\n");
|
|
|
|
|
}
|
|
|
|
|
g_stdin = open (buf, O_RDONLY);
|
|
|
|
|
}
|
|
|
|
|
if (g_stdin < 0)
|
|
|
|
|
{
|
|
|
|
|
char const *prefix = MODULEDIR "mes/";
|
|
|
|
|
strcpy (buf, prefix);
|
|
|
|
|
strcpy (buf + strlen (buf), boot);
|
2017-12-09 21:38:51 +00:00
|
|
|
|
if (getenv ("MES_DEBUG"))
|
|
|
|
|
{
|
2018-02-03 20:43:52 +00:00
|
|
|
|
eputs ("MODULEDIR reading boot-0:");
|
2017-12-09 21:38:51 +00:00
|
|
|
|
eputs (buf);
|
|
|
|
|
eputs ("\n");
|
|
|
|
|
}
|
|
|
|
|
g_stdin = open (buf, O_RDONLY);
|
|
|
|
|
}
|
|
|
|
|
if (g_stdin < 0)
|
|
|
|
|
{
|
2018-02-03 20:43:52 +00:00
|
|
|
|
strcpy (buf, "module/mes/");
|
|
|
|
|
strcpy (buf + strlen (buf), boot);
|
2017-12-09 21:38:51 +00:00
|
|
|
|
if (getenv ("MES_DEBUG"))
|
|
|
|
|
{
|
2018-02-03 20:43:52 +00:00
|
|
|
|
eputs (". reading boot-0:");
|
|
|
|
|
eputs (buf);
|
2017-12-09 21:38:51 +00:00
|
|
|
|
eputs ("\n");
|
|
|
|
|
}
|
2018-02-03 20:43:52 +00:00
|
|
|
|
g_stdin = open (buf, O_RDONLY);
|
2017-12-09 21:38:51 +00:00
|
|
|
|
}
|
|
|
|
|
if (g_stdin < 0)
|
|
|
|
|
{
|
|
|
|
|
if (getenv ("MES_DEBUG"))
|
|
|
|
|
{
|
2018-02-03 20:43:52 +00:00
|
|
|
|
eputs (". reading boot-0:");
|
|
|
|
|
eputs (boot);
|
2017-12-09 21:38:51 +00:00
|
|
|
|
eputs ("\n");
|
|
|
|
|
}
|
2018-02-03 20:43:52 +00:00
|
|
|
|
g_stdin = open (boot, O_RDONLY);
|
2017-12-09 21:38:51 +00:00
|
|
|
|
}
|
|
|
|
|
if (g_stdin < 0)
|
|
|
|
|
{
|
2018-02-03 20:43:52 +00:00
|
|
|
|
eputs ("mes: boot failed: no such file: ");
|
|
|
|
|
eputs (boot);
|
|
|
|
|
eputs ("\n");
|
2017-12-09 21:38:51 +00:00
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (!g_function)
|
|
|
|
|
r0 = mes_builtins (r0);
|
mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
(assert_defined, check_formals, check_apply, load_env,
bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
math.c, mini-posix.h, posix.c.
(greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
logior, ash): Remove.
(ungetchar, peekchar, peek_byte, read_byte, write_byte,
string_to_cstring, getenv_, open_input_file, current_input_port,
set_current_input_port, force_output): Remove.
(mes_builtins): include mini-lib.i, mini-lib.environment.i.
mini-math.i, mini-math.environment.i mini-posix.i,
mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 14:01:24 +01:00
|
|
|
|
r2 = read_input_file_env (r0);
|
|
|
|
|
g_stdin = STDIN;
|
|
|
|
|
return r2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
bload_env (SCM a) ///((internal))
|
|
|
|
|
{
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#if __MESC__
|
|
|
|
|
char *mo = "mes/read-0-32.mo";
|
|
|
|
|
g_stdin = open ("module/mes/read-0-32.mo", O_RDONLY);
|
2017-07-26 14:42:44 +01:00
|
|
|
|
char *read0 = MODULEDIR "mes/read-0-32.mo";
|
|
|
|
|
g_stdin = g_stdin >= 0 ? g_stdin : open (read0, O_RDONLY);
|
mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
(assert_defined, check_formals, check_apply, load_env,
bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
math.c, mini-posix.h, posix.c.
(greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
logior, ash): Remove.
(ungetchar, peekchar, peek_byte, read_byte, write_byte,
string_to_cstring, getenv_, open_input_file, current_input_port,
set_current_input_port, force_output): Remove.
(mes_builtins): include mini-lib.i, mini-lib.environment.i.
mini-math.i, mini-math.environment.i mini-posix.i,
mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 14:01:24 +01:00
|
|
|
|
#else
|
2017-04-10 18:13:20 +01:00
|
|
|
|
char *mo ="mes/read-0.mo";
|
mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
(assert_defined, check_formals, check_apply, load_env,
bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
math.c, mini-posix.h, posix.c.
(greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
logior, ash): Remove.
(ungetchar, peekchar, peek_byte, read_byte, write_byte,
string_to_cstring, getenv_, open_input_file, current_input_port,
set_current_input_port, force_output): Remove.
(mes_builtins): include mini-lib.i, mini-lib.environment.i.
mini-math.i, mini-math.environment.i mini-posix.i,
mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 14:01:24 +01:00
|
|
|
|
g_stdin = open ("module/mes/read-0.mo", O_RDONLY);
|
2017-06-12 16:18:31 +01:00
|
|
|
|
g_stdin = g_stdin >= 0 ? g_stdin : open (MODULEDIR "mes/read-0.mo", O_RDONLY);
|
mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
(assert_defined, check_formals, check_apply, load_env,
bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
math.c, mini-posix.h, posix.c.
(greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
logior, ash): Remove.
(ungetchar, peekchar, peek_byte, read_byte, write_byte,
string_to_cstring, getenv_, open_input_file, current_input_port,
set_current_input_port, force_output): Remove.
(mes_builtins): include mini-lib.i, mini-lib.environment.i.
mini-math.i, mini-math.environment.i mini-posix.i,
mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 14:01:24 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (g_stdin < 0)
|
|
|
|
|
{
|
|
|
|
|
eputs ("no such file: ");eputs (mo);eputs ("\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
(assert_defined, check_formals, check_apply, load_env,
bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
math.c, mini-posix.h, posix.c.
(greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
logior, ash): Remove.
(ungetchar, peekchar, peek_byte, read_byte, write_byte,
string_to_cstring, getenv_, open_input_file, current_input_port,
set_current_input_port, force_output): Remove.
(mes_builtins): include mini-lib.i, mini-lib.environment.i.
mini-math.i, mini-math.environment.i mini-posix.i,
mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 14:01:24 +01:00
|
|
|
|
assert (getchar () == 'M');
|
|
|
|
|
assert (getchar () == 'E');
|
|
|
|
|
assert (getchar () == 'S');
|
2017-04-17 22:32:02 +01:00
|
|
|
|
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (g_debug)
|
|
|
|
|
eputs ("*GOT MES*\n");
|
mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
(assert_defined, check_formals, check_apply, load_env,
bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
math.c, mini-posix.h, posix.c.
(greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
logior, ash): Remove.
(ungetchar, peekchar, peek_byte, read_byte, write_byte,
string_to_cstring, getenv_, open_input_file, current_input_port,
set_current_input_port, force_output): Remove.
(mes_builtins): include mini-lib.i, mini-lib.environment.i.
mini-math.i, mini-math.environment.i mini-posix.i,
mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 14:01:24 +01:00
|
|
|
|
g_stack = getchar () << 8;
|
|
|
|
|
g_stack += getchar ();
|
2017-04-10 18:13:20 +01:00
|
|
|
|
|
|
|
|
|
char *p = (char*)g_cells;
|
mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
(assert_defined, check_formals, check_apply, load_env,
bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
math.c, mini-posix.h, posix.c.
(greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
logior, ash): Remove.
(ungetchar, peekchar, peek_byte, read_byte, write_byte,
string_to_cstring, getenv_, open_input_file, current_input_port,
set_current_input_port, force_output): Remove.
(mes_builtins): include mini-lib.i, mini-lib.environment.i.
mini-math.i, mini-math.environment.i mini-posix.i,
mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 14:01:24 +01:00
|
|
|
|
int c = getchar ();
|
|
|
|
|
while (c != EOF)
|
|
|
|
|
{
|
|
|
|
|
*p++ = c;
|
|
|
|
|
c = getchar ();
|
|
|
|
|
}
|
|
|
|
|
g_free = (p-(char*)g_cells) / sizeof (struct scm);
|
|
|
|
|
gc_peek_frame ();
|
|
|
|
|
g_symbols = r1;
|
|
|
|
|
g_stdin = STDIN;
|
|
|
|
|
r0 = mes_builtins (r0);
|
2017-04-10 18:13:20 +01:00
|
|
|
|
|
|
|
|
|
#if __GNUC__
|
|
|
|
|
set_env_x (cell_symbol_gnuc, cell_t, r0);
|
|
|
|
|
set_env_x (cell_symbol_mesc, cell_f, r0);
|
|
|
|
|
#else
|
|
|
|
|
set_env_x (cell_symbol_gnuc, cell_f, r0);
|
|
|
|
|
set_env_x (cell_symbol_mesc, cell_t, r0);
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-04-09 06:12:38 +01:00
|
|
|
|
if (g_debug > 3)
|
2017-04-10 18:13:20 +01:00
|
|
|
|
{
|
|
|
|
|
eputs ("symbols: ");
|
|
|
|
|
SCM s = g_symbols;
|
2018-04-05 20:35:31 +01:00
|
|
|
|
while (s && s != cell_nil)
|
|
|
|
|
{
|
|
|
|
|
display_error_ (CAR (s));
|
|
|
|
|
eputs (" ");
|
|
|
|
|
s = CDR (s);
|
|
|
|
|
}
|
2017-04-10 18:13:20 +01:00
|
|
|
|
eputs ("\n");
|
|
|
|
|
eputs ("functions: ");
|
|
|
|
|
eputs (itoa (g_function));
|
|
|
|
|
eputs ("\n");
|
|
|
|
|
for (int i = 0; i < g_function; i++)
|
|
|
|
|
{
|
|
|
|
|
eputs ("[");
|
|
|
|
|
eputs (itoa (i));
|
|
|
|
|
eputs ("]: ");
|
|
|
|
|
eputs (g_functions[i].name);
|
|
|
|
|
eputs ("\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
mini-mes: Merge with mes.c: lib.c, math.c, posix.c.
* mes.c: Include math.c after posix.c.
(assert_defined, check_formals, check_apply, load_env,
bload_env): Move from lib.c
* scaffold/mini-mes.c: Include mini-lib.h, lib.c., mini-math.h,
math.c, mini-posix.h, posix.c.
(greater_p, less_p, is_p, minus, plus, divide, modulo, multiply,
logior, ash): Remove.
(ungetchar, peekchar, peek_byte, read_byte, write_byte,
string_to_cstring, getenv_, open_input_file, current_input_port,
set_current_input_port, force_output): Remove.
(mes_builtins): include mini-lib.i, mini-lib.environment.i.
mini-math.i, mini-math.environment.i mini-posix.i,
mini-posix.environment.i.
* GNUmakefile (guile-mini-mes): Add dependencies.
2017-04-08 14:01:24 +01:00
|
|
|
|
return r2;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 18:13:20 +01:00
|
|
|
|
#include "vector.c"
|
|
|
|
|
#include "gc.c"
|
|
|
|
|
#include "reader.c"
|
|
|
|
|
|
2016-07-16 21:43:13 +01:00
|
|
|
|
int
|
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
|
{
|
2017-04-17 22:32:02 +01:00
|
|
|
|
char *p;
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (p = getenv ("MES_DEBUG"))
|
|
|
|
|
g_debug = atoi (p);
|
|
|
|
|
if (g_debug)
|
|
|
|
|
{
|
|
|
|
|
eputs (";;; MODULEDIR=");
|
2018-04-09 06:12:38 +01:00
|
|
|
|
eputs (MODULEDIR);
|
|
|
|
|
eputs ("\n");
|
2018-04-05 20:35:31 +01:00
|
|
|
|
}
|
|
|
|
|
if (p = getenv ("MES_MAX_ARENA"))
|
|
|
|
|
MAX_ARENA_SIZE = atoi (p);
|
|
|
|
|
if (p = getenv ("MES_ARENA"))
|
|
|
|
|
ARENA_SIZE = atoi (p);
|
2018-01-01 19:00:06 +00:00
|
|
|
|
GC_SAFETY = ARENA_SIZE / 400;
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (argc > 1 && !strcmp (argv[1], "--help"))
|
|
|
|
|
return puts ("Usage: mes [--dump|--load] < FILE\n");
|
|
|
|
|
if (argc > 1 && !strcmp (argv[1], "--version"))
|
|
|
|
|
{
|
|
|
|
|
puts ("Mes ");puts (VERSION);puts ("\n");
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
2017-04-02 16:01:22 +01:00
|
|
|
|
g_stdin = STDIN;
|
2017-05-19 05:56:47 +01:00
|
|
|
|
g_stdout = STDOUT;
|
2016-12-13 18:58:34 +00:00
|
|
|
|
r0 = mes_environment ();
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
|
2016-12-13 18:58:34 +00:00
|
|
|
|
SCM program = (argc > 1 && !strcmp (argv[1], "--load"))
|
|
|
|
|
? bload_env (r0) : load_env (r0);
|
2017-04-12 20:27:59 +01:00
|
|
|
|
g_tiny = argc > 2 && !strcmp (argv[2], "--tiny");
|
2018-04-05 20:35:31 +01:00
|
|
|
|
if (argc > 1 && !strcmp (argv[1], "--dump"))
|
|
|
|
|
return dump ();
|
2017-01-03 22:41:11 +00:00
|
|
|
|
|
|
|
|
|
SCM lst = cell_nil;
|
2017-04-10 18:13:20 +01:00
|
|
|
|
for (int i=argc-1; i>=0; i--) lst = cons (MAKE_STRING (cstring_to_list (argv[i])), lst);
|
2018-03-04 09:05:55 +00:00
|
|
|
|
r0 = acons (cell_symbol_argv, lst, r0); // FIXME
|
2017-01-03 22:41:11 +00:00
|
|
|
|
r0 = acons (cell_symbol_argv, lst, r0);
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
push_cc (r2, cell_unspecified, r0, cell_unspecified);
|
2018-04-09 06:12:38 +01:00
|
|
|
|
|
|
|
|
|
if (g_debug > 2)
|
|
|
|
|
{
|
|
|
|
|
eputs ("\ngc stats: [");
|
|
|
|
|
eputs (itoa (g_free));
|
|
|
|
|
eputs ("]\n");
|
|
|
|
|
}
|
|
|
|
|
if (g_debug > 3)
|
2017-04-10 18:13:20 +01:00
|
|
|
|
{
|
|
|
|
|
eputs ("program: ");
|
2018-01-07 15:08:11 +00:00
|
|
|
|
write_error_ (r1);
|
2017-04-10 18:13:20 +01:00
|
|
|
|
eputs ("\n");
|
|
|
|
|
}
|
2018-04-09 06:12:38 +01:00
|
|
|
|
if (g_debug > 3)
|
|
|
|
|
{
|
|
|
|
|
eputs ("symbols: ");
|
|
|
|
|
write_error_ (g_symbols);
|
|
|
|
|
eputs ("\n");
|
|
|
|
|
}
|
2018-03-04 09:05:55 +00:00
|
|
|
|
r3 = cell_vm_begin_expand;
|
core: Rewrite eval_apply in continuation passing style.
* mes.c (scm_vm_evlis, scm_vm_evlis2, scm_vm_evlis3, scm_vm_apply,
scm_vm_apply2, scm_vm_eval, scm_vm_eval_set_x, scm_vm_eval_macro,
scm_vm_eval2, scm_vm_macro_expand, scm_vm_begin,
scm_vm_begin_read_input_file, scm_vm_begin2, scm_vm_if,
scm_vm_if_expr, scm_vm_call_with_values, scm_vm_call_with_values2,
scm_vm_return): New specials.
(scm_vm_eval_car, scm_vm_eval_cdr, scm_vm_eval_cons,
scm_vm_eval_null_p)[PRIMITIVE-EVAL]: New specials.
(eval_apply_t, g_target): Remove.
(push_cc): New function.
(eval_apply): Rewrite.
(vm_call, eval_env, apply_env, eval_env, macro_expand_env, begin_env,
call_with_values_env): Remove.
* posix.c (stderr_): Update.
* reader.c (read_input_file_env): Update.
* module/mes/base-0.mes: Update.
2016-12-28 20:55:42 +00:00
|
|
|
|
r1 = eval_apply ();
|
2017-04-10 18:13:20 +01:00
|
|
|
|
if (g_debug)
|
|
|
|
|
{
|
2018-04-09 06:12:38 +01:00
|
|
|
|
write_error_ (r1);
|
|
|
|
|
eputs ("\n");
|
|
|
|
|
}
|
|
|
|
|
if (g_debug)
|
|
|
|
|
{
|
2018-03-04 09:05:55 +00:00
|
|
|
|
eputs ("\ngc stats: [");
|
2017-04-10 18:13:20 +01:00
|
|
|
|
eputs (itoa (g_free));
|
2018-04-09 06:12:38 +01:00
|
|
|
|
gc (g_stack);
|
|
|
|
|
eputs (" => ");
|
|
|
|
|
eputs (itoa (g_free));
|
2017-04-10 18:13:20 +01:00
|
|
|
|
eputs ("]\n");
|
|
|
|
|
}
|
2016-07-16 21:43:13 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|