2016-10-17 16:26:07 +00:00
|
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
2016-05-28 14:39:44 +00:00
|
|
|
|
* Mes --- Maxwell Equations of Software
|
2017-01-03 22:41:11 +00:00
|
|
|
|
* Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
2016-05-28 14:39:44 +00: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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
2017-01-04 07:16:14 +00:00
|
|
|
|
#if __GNUC__
|
|
|
|
|
#define __NYACC__ 0
|
|
|
|
|
#define NYACC
|
|
|
|
|
#define NYACC2
|
2016-05-28 14:39:44 +00:00
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <ctype.h>
|
2016-12-11 07:23:15 +00:00
|
|
|
|
#include <errno.h>
|
2016-07-24 13:26:49 +00:00
|
|
|
|
#include <limits.h>
|
2016-05-28 14:39:44 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdbool.h>
|
2017-01-04 07:16:14 +00:00
|
|
|
|
#else
|
|
|
|
|
typedef int bool;
|
|
|
|
|
#define __NYACC__ 1
|
|
|
|
|
#define NYACC nyacc
|
|
|
|
|
#define NYACC2 nyacc2
|
|
|
|
|
#endif
|
2016-05-28 14:39:44 +00:00
|
|
|
|
|
2016-05-15 22:07:44 +00:00
|
|
|
|
#define DEBUG 0
|
2016-11-21 20:43:06 +00:00
|
|
|
|
#define FIXED_PRIMITIVES 1
|
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 16:42:03 +00:00
|
|
|
|
|
2016-12-11 07:23:15 +00:00
|
|
|
|
int ARENA_SIZE = 100000;
|
2016-12-11 17:41:08 +00:00
|
|
|
|
int MAX_ARENA_SIZE = 20000000;
|
2016-12-11 07:23:15 +00:00
|
|
|
|
int GC_SAFETY = 100;
|
2016-05-15 22:07:44 +00:00
|
|
|
|
|
2016-12-14 18:02:19 +00:00
|
|
|
|
typedef int SCM;
|
2016-12-28 21:04:57 +00:00
|
|
|
|
enum type_t {CHAR, CLOSURE, CONTINUATION, FUNCTION, KEYWORD, MACRO, NUMBER, PAIR, REF, SPECIAL, STRING, SYMBOL, VALUES, VECTOR, BROKEN_HEART};
|
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);
|
2017-01-04 07:16:14 +00:00
|
|
|
|
typedef struct function_struct {
|
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-01-04 07:16:14 +00:00
|
|
|
|
} NYACC;
|
2016-11-03 20:28:05 +00:00
|
|
|
|
int arity;
|
2017-01-04 07:16:14 +00:00
|
|
|
|
} function_t;
|
|
|
|
|
struct scm;
|
|
|
|
|
typedef struct scm_struct {
|
2016-11-21 08:28:34 +00:00
|
|
|
|
enum type_t type;
|
2016-05-28 14:39:44 +00:00
|
|
|
|
union {
|
2016-10-08 08:14:17 +00:00
|
|
|
|
char const *name;
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM string;
|
|
|
|
|
SCM car;
|
|
|
|
|
SCM ref;
|
2016-07-11 08:38:02 +00:00
|
|
|
|
int length;
|
2017-01-04 07:16:14 +00:00
|
|
|
|
} NYACC;
|
2016-05-28 14:39:44 +00: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;
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM macro;
|
|
|
|
|
SCM vector;
|
2016-10-26 17:44:36 +00:00
|
|
|
|
int hits;
|
2017-01-04 07:16:14 +00:00
|
|
|
|
} NYACC2;
|
2016-05-28 14:39:44 +00:00
|
|
|
|
} scm;
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
scm scm_nil = {SPECIAL, "()"};
|
|
|
|
|
scm scm_f = {SPECIAL, "#f"};
|
|
|
|
|
scm scm_t = {SPECIAL, "#t"};
|
|
|
|
|
scm scm_dot = {SPECIAL, "."};
|
2016-12-16 19:18:38 +00:00
|
|
|
|
scm scm_arrow = {SPECIAL, "=>"};
|
2016-11-21 08:28:34 +00:00
|
|
|
|
scm scm_undefined = {SPECIAL, "*undefined*"};
|
|
|
|
|
scm scm_unspecified = {SPECIAL, "*unspecified*"};
|
|
|
|
|
scm scm_closure = {SPECIAL, "*closure*"};
|
|
|
|
|
scm scm_circular = {SPECIAL, "*circular*"};
|
|
|
|
|
scm scm_begin = {SPECIAL, "*begin*"};
|
|
|
|
|
|
2016-12-23 16:02:23 +00:00
|
|
|
|
scm scm_symbol_dot = {SYMBOL, "*dot*"};
|
2016-11-21 08:28:34 +00:00
|
|
|
|
scm scm_symbol_lambda = {SYMBOL, "lambda"};
|
|
|
|
|
scm scm_symbol_begin = {SYMBOL, "begin"};
|
|
|
|
|
scm scm_symbol_if = {SYMBOL, "if"};
|
|
|
|
|
scm scm_symbol_quote = {SYMBOL, "quote"};
|
2017-01-04 07:16:14 +00:00
|
|
|
|
scm scm_symbol_set_x = {SYMBOL, "set!"};
|
2016-11-21 08:28:34 +00:00
|
|
|
|
|
|
|
|
|
scm scm_symbol_sc_expand = {SYMBOL, "sc-expand"};
|
2016-12-22 15:34:28 +00:00
|
|
|
|
scm scm_symbol_macro_expand = {SYMBOL, "macro-expand"};
|
2016-11-21 08:28:34 +00:00
|
|
|
|
scm scm_symbol_sc_expander_alist = {SYMBOL, "*sc-expander-alist*"};
|
|
|
|
|
|
|
|
|
|
scm scm_symbol_call_with_values = {SYMBOL, "call-with-values"};
|
2016-12-28 21:04:57 +00:00
|
|
|
|
scm scm_call_with_current_continuation = {SPECIAL, "*call/cc*"};
|
|
|
|
|
scm scm_symbol_call_with_current_continuation = {SYMBOL, "call-with-current-continuation"};
|
2016-11-21 08:28:34 +00:00
|
|
|
|
scm scm_symbol_current_module = {SYMBOL, "current-module"};
|
|
|
|
|
scm scm_symbol_primitive_load = {SYMBOL, "primitive-load"};
|
2016-12-13 18:58:34 +00:00
|
|
|
|
scm scm_symbol_read_input_file = {SYMBOL, "read-input-file"};
|
2016-12-24 21:16:53 +00:00
|
|
|
|
scm scm_symbol_write = {SYMBOL, "write"};
|
2016-12-24 00:23:50 +00:00
|
|
|
|
scm scm_symbol_display = {SYMBOL, "display"};
|
core: Throw exceptions rather than asserts.
* lib.c (error): Throw instead of assert.
(check_formals, check_apply): Update.
* mes.c (scm_symbol_unbound_variable, scm_symbol_not_a_pair,
scm_symbol_system_error, scm_symbol_wrong_number_of_args,
scm_symbol_wrong_type_arg, scm_symbol_unbound_variable): New symbols.
(car, cdr, set_cdr_x, set_env_x, eval_apply, gc_up_arena): Update.
2016-12-28 21:26:33 +00:00
|
|
|
|
|
2016-12-28 21:26:07 +00:00
|
|
|
|
scm scm_symbol_throw = {SYMBOL, "throw"};
|
core: Throw exceptions rather than asserts.
* lib.c (error): Throw instead of assert.
(check_formals, check_apply): Update.
* mes.c (scm_symbol_unbound_variable, scm_symbol_not_a_pair,
scm_symbol_system_error, scm_symbol_wrong_number_of_args,
scm_symbol_wrong_type_arg, scm_symbol_unbound_variable): New symbols.
(car, cdr, set_cdr_x, set_env_x, eval_apply, gc_up_arena): Update.
2016-12-28 21:26:33 +00:00
|
|
|
|
scm scm_symbol_not_a_pair = {SYMBOL, "not-a-pair"};
|
|
|
|
|
scm scm_symbol_system_error = {SYMBOL, "system-error"};
|
|
|
|
|
scm scm_symbol_wrong_number_of_args = {SYMBOL, "wrong-number-of-args"};
|
|
|
|
|
scm scm_symbol_wrong_type_arg = {SYMBOL, "wrong-type-arg"};
|
|
|
|
|
scm scm_symbol_unbound_variable = {SYMBOL, "unbound-variable"};
|
2016-05-28 14:39:44 +00:00
|
|
|
|
|
2016-12-28 21:26:07 +00:00
|
|
|
|
scm scm_symbol_argv = {SYMBOL, "%argv"};
|
2016-12-25 14:38:26 +00:00
|
|
|
|
scm scm_symbol_mes_prefix = {SYMBOL, "%prefix"};
|
2016-12-28 21:26:07 +00:00
|
|
|
|
scm scm_symbol_mes_version = {SYMBOL, "%version"};
|
2016-12-25 14:38:26 +00:00
|
|
|
|
|
2016-11-21 20:43:06 +00:00
|
|
|
|
scm scm_symbol_car = {SYMBOL, "car"};
|
|
|
|
|
scm scm_symbol_cdr = {SYMBOL, "cdr"};
|
|
|
|
|
scm scm_symbol_null_p = {SYMBOL, "null?"};
|
|
|
|
|
scm scm_symbol_eq_p = {SYMBOL, "eq?"};
|
|
|
|
|
scm scm_symbol_cons = {SYMBOL, "cons"};
|
|
|
|
|
|
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
|
|
|
|
scm scm_vm_evlis = {SPECIAL, "*vm-evlis*"};
|
|
|
|
|
scm scm_vm_evlis2 = {SPECIAL, "*vm-evlis2*"};
|
|
|
|
|
scm scm_vm_evlis3 = {SPECIAL, "*vm-evlis3*"};
|
|
|
|
|
scm scm_vm_apply = {SPECIAL, "core:apply"};
|
|
|
|
|
scm scm_vm_apply2 = {SPECIAL, "*vm-apply2*"};
|
|
|
|
|
scm scm_vm_eval = {SPECIAL, "core:eval"};
|
|
|
|
|
|
|
|
|
|
#if FIXED_PRIMITIVES
|
|
|
|
|
scm scm_vm_eval_car = {SPECIAL, "*vm-eval-car*"};
|
|
|
|
|
scm scm_vm_eval_cdr = {SPECIAL, "*vm-eval-cdr*"};
|
|
|
|
|
scm scm_vm_eval_cons = {SPECIAL, "*vm-eval-cons*"};
|
|
|
|
|
scm scm_vm_eval_null_p = {SPECIAL, "*vm-eval-null-p*"};
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
scm scm_vm_eval_set_x = {SPECIAL, "*vm-eval-set!*"};
|
|
|
|
|
scm scm_vm_eval_macro = {SPECIAL, "*vm-eval-macro*"};
|
|
|
|
|
scm scm_vm_eval2 = {SPECIAL, "*vm-eval2*"};
|
|
|
|
|
scm scm_vm_macro_expand = {SPECIAL, "core:macro-expand"};
|
|
|
|
|
scm scm_vm_begin = {SPECIAL, "*vm-begin*"};
|
|
|
|
|
scm scm_vm_begin_read_input_file = {SPECIAL, "*vm-begin-read-input-file*"};
|
|
|
|
|
scm scm_vm_begin2 = {SPECIAL, "*vm-begin2*"};
|
|
|
|
|
scm scm_vm_if = {SPECIAL, "*vm-if*"};
|
|
|
|
|
scm scm_vm_if_expr = {SPECIAL, "*vm-if-expr*"};
|
|
|
|
|
scm scm_vm_call_with_values2 = {SPECIAL, "*vm-call-with-values2*"};
|
2016-12-28 21:04:57 +00:00
|
|
|
|
scm scm_vm_call_with_current_continuation2 = {SPECIAL, "*vm-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
|
|
|
|
scm scm_vm_return = {SPECIAL, "*vm-return*"};
|
|
|
|
|
|
|
|
|
|
scm scm_test = {SYMBOL, "test"};
|
|
|
|
|
|
2017-01-04 07:16:14 +00:00
|
|
|
|
int g_free = 0;
|
2016-11-21 08:28:34 +00:00
|
|
|
|
scm *g_cells;
|
|
|
|
|
scm *g_news = 0;
|
2016-05-15 22:07:44 +00:00
|
|
|
|
|
2016-12-14 18:02:19 +00:00
|
|
|
|
#include "mes.symbols.h"
|
|
|
|
|
|
|
|
|
|
SCM tmp;
|
|
|
|
|
SCM tmp_num;
|
|
|
|
|
SCM tmp_num2;
|
|
|
|
|
|
2017-01-04 07:16:14 +00:00
|
|
|
|
function_t functions[200];
|
2016-12-14 18:02:19 +00:00
|
|
|
|
int g_function = 0;
|
|
|
|
|
|
2016-12-28 21:04:57 +00:00
|
|
|
|
SCM g_continuations = 0;
|
2016-12-14 18:02:19 +00:00
|
|
|
|
SCM g_symbols = 0;
|
2016-12-26 08:00:43 +00:00
|
|
|
|
SCM g_stack = 0;
|
2016-12-14 18:02:19 +00:00
|
|
|
|
SCM r0 = 0; // a/env
|
|
|
|
|
SCM r1 = 0; // param 1
|
2016-12-26 08:04:40 +00:00
|
|
|
|
SCM r2 = 0; // save 2+load/dump
|
2017-01-04 08:07:11 +00:00
|
|
|
|
SCM r3 = 0; // continuation
|
2016-12-14 18:02:19 +00:00
|
|
|
|
|
|
|
|
|
#include "lib.h"
|
|
|
|
|
#include "math.h"
|
|
|
|
|
#include "mes.h"
|
|
|
|
|
#include "posix.h"
|
|
|
|
|
#include "reader.h"
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
#define CAR(x) g_cells[x].car
|
|
|
|
|
#define CDR(x) g_cells[x].cdr
|
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
|
|
|
|
|
#define TYPE(x) g_cells[x].type
|
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
|
2016-11-19 21:31:30 +00:00
|
|
|
|
#define FUNCTION(x) functions[g_cells[x].function]
|
2016-11-21 08:28:34 +00:00
|
|
|
|
#define NCAR(x) g_news[x].car
|
|
|
|
|
#define NTYPE(x) g_news[x].type
|
|
|
|
|
|
2016-11-21 08:30:59 +00:00
|
|
|
|
#define CAAR(x) CAR (CAR (x))
|
|
|
|
|
#define CDAR(x) CDR (CAR (x))
|
|
|
|
|
#define CAAR(x) CAR (CAR (x))
|
|
|
|
|
#define CADAR(x) CAR (CDR (CAR (x)))
|
2016-11-21 20:43:06 +00:00
|
|
|
|
#define CADDR(x) CAR (CDR (CDR (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
|
|
|
|
#define CDDDR(x) CDR (CDR (CDR (x)))
|
2016-11-21 08:30:59 +00:00
|
|
|
|
#define CDADAR(x) CAR (CDR (CAR (CDR (x))))
|
|
|
|
|
#define CADR(x) CAR (CDR (x))
|
2016-05-28 14:39:44 +00:00
|
|
|
|
|
2016-12-23 15:26:00 +00:00
|
|
|
|
#define MAKE_CHAR(n) make_cell (tmp_num_ (CHAR), 0, tmp_num2_ (n))
|
2016-12-28 21:04:57 +00:00
|
|
|
|
#define MAKE_CONTINUATION(n) make_cell (tmp_num_ (CONTINUATION), n, g_stack)
|
2016-12-23 15:22:19 +00:00
|
|
|
|
#define MAKE_NUMBER(n) make_cell (tmp_num_ (NUMBER), 0, tmp_num2_ (n))
|
2016-12-24 13:09:48 +00:00
|
|
|
|
#define MAKE_REF(n) make_cell (tmp_num_ (REF), n, 0)
|
|
|
|
|
#define MAKE_STRING(x) make_cell (tmp_num_ (STRING), x, 0)
|
2016-12-23 15:22:19 +00:00
|
|
|
|
|
2016-12-26 08:04:40 +00:00
|
|
|
|
SCM vm_call (function0_t f, SCM p1, SCM a);
|
2016-10-27 14:44:09 +00:00
|
|
|
|
|
2016-12-23 17:05:45 +00:00
|
|
|
|
SCM
|
|
|
|
|
tmp_num_ (int x)
|
|
|
|
|
{
|
|
|
|
|
g_cells[tmp_num].value = x;
|
|
|
|
|
return tmp_num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
tmp_num2_ (int x)
|
|
|
|
|
{
|
|
|
|
|
g_cells[tmp_num2].value = x;
|
|
|
|
|
return tmp_num2;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
2016-11-21 08:36:32 +00:00
|
|
|
|
alloc (int n)
|
2016-10-27 14:44:09 +00:00
|
|
|
|
{
|
2017-01-04 07:16:14 +00:00
|
|
|
|
assert (g_free + n < ARENA_SIZE);
|
|
|
|
|
SCM x = g_free;
|
|
|
|
|
g_free += n;
|
2016-10-27 14:44:09 +00:00
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
make_cell (SCM type, SCM car, SCM cdr)
|
|
|
|
|
{
|
2016-11-21 08:36:32 +00:00
|
|
|
|
SCM x = alloc (1);
|
2016-11-21 08:30:59 +00:00
|
|
|
|
assert (TYPE (type) == NUMBER);
|
|
|
|
|
TYPE (x) = VALUE (type);
|
2016-11-21 08:28:34 +00:00
|
|
|
|
if (VALUE (type) == CHAR || VALUE (type) == NUMBER) {
|
2016-11-21 08:30:59 +00:00
|
|
|
|
if (car) CAR (x) = CAR (car);
|
|
|
|
|
if (cdr) CDR (x) = CDR (cdr);
|
2016-11-19 21:31:30 +00:00
|
|
|
|
} else if (VALUE (type) == FUNCTION) {
|
2016-11-21 08:30:59 +00:00
|
|
|
|
if (car) CAR (x) = car;
|
|
|
|
|
if (cdr) CDR (x) = CDR (cdr);
|
2016-10-26 17:44:36 +00:00
|
|
|
|
} else {
|
2016-11-21 08:30:59 +00:00
|
|
|
|
CAR (x) = car;
|
|
|
|
|
CDR (x) = cdr;
|
2016-10-26 17:44:36 +00:00
|
|
|
|
}
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
cons (SCM x, SCM y)
|
2016-05-28 14:39:44 +00:00
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
|
g_cells[tmp_num].value = PAIR;
|
|
|
|
|
return make_cell (tmp_num, x, y);
|
2016-05-28 14:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:36:32 +00:00
|
|
|
|
SCM
|
|
|
|
|
car (SCM x)
|
|
|
|
|
{
|
core: Throw exceptions rather than asserts.
* lib.c (error): Throw instead of assert.
(check_formals, check_apply): Update.
* mes.c (scm_symbol_unbound_variable, scm_symbol_not_a_pair,
scm_symbol_system_error, scm_symbol_wrong_number_of_args,
scm_symbol_wrong_type_arg, scm_symbol_unbound_variable): New symbols.
(car, cdr, set_cdr_x, set_env_x, eval_apply, gc_up_arena): Update.
2016-12-28 21:26:33 +00:00
|
|
|
|
if (TYPE (x) != PAIR) error (cell_symbol_not_a_pair, cons (x, cell_symbol_car));
|
2016-11-21 08:36:32 +00:00
|
|
|
|
return CAR (x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
cdr (SCM x)
|
|
|
|
|
{
|
core: Throw exceptions rather than asserts.
* lib.c (error): Throw instead of assert.
(check_formals, check_apply): Update.
* mes.c (scm_symbol_unbound_variable, scm_symbol_not_a_pair,
scm_symbol_system_error, scm_symbol_wrong_number_of_args,
scm_symbol_wrong_type_arg, scm_symbol_unbound_variable): New symbols.
(car, cdr, set_cdr_x, set_env_x, eval_apply, gc_up_arena): Update.
2016-12-28 21:26:33 +00:00
|
|
|
|
if (TYPE (x) != PAIR) error (cell_symbol_not_a_pair, cons (x, cell_symbol_cdr));
|
2016-11-21 08:36:32 +00:00
|
|
|
|
return CDR (x);
|
|
|
|
|
}
|
2017-01-18 06:38:45 +00:00
|
|
|
|
|
2017-01-04 07:16:14 +00:00
|
|
|
|
SCM
|
|
|
|
|
eq_p (SCM x, SCM y)
|
|
|
|
|
{
|
|
|
|
|
return (x == y
|
|
|
|
|
|| ((TYPE (x) == KEYWORD && TYPE (y) == KEYWORD
|
|
|
|
|
&& STRING (x) == STRING (y)))
|
|
|
|
|
|| (TYPE (x) == CHAR && TYPE (y) == CHAR
|
|
|
|
|
&& VALUE (x) == VALUE (y))
|
|
|
|
|
|| (TYPE (x) == NUMBER && TYPE (y) == NUMBER
|
|
|
|
|
&& 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
|
|
|
|
|
type_ (SCM x)
|
|
|
|
|
{
|
|
|
|
|
return MAKE_NUMBER (TYPE (x));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
car_ (SCM x)
|
|
|
|
|
{
|
2016-12-28 21:04:57 +00:00
|
|
|
|
return (TYPE (x) != CONTINUATION
|
|
|
|
|
&& (TYPE (CAR (x)) == PAIR // FIXME: this is weird
|
|
|
|
|
|| TYPE (CAR (x)) == REF
|
|
|
|
|
|| TYPE (CAR (x)) == SPECIAL
|
|
|
|
|
|| TYPE (CAR (x)) == SYMBOL
|
|
|
|
|
|| TYPE (CAR (x)) == STRING)) ? CAR (x) : MAKE_NUMBER (CAR (x));
|
2016-12-23 17:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
cdr_ (SCM x)
|
|
|
|
|
{
|
|
|
|
|
return (TYPE (CDR (x)) == PAIR
|
|
|
|
|
|| TYPE (CDR (x)) == REF
|
2016-12-25 23:14:28 +00:00
|
|
|
|
|| TYPE (CAR (x)) == SPECIAL
|
2016-12-23 17:05:45 +00:00
|
|
|
|
|| TYPE (CDR (x)) == SYMBOL
|
|
|
|
|
|| TYPE (CDR (x)) == STRING) ? CDR (x) : MAKE_NUMBER (CDR (x));
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
set_car_x (SCM x, SCM e)
|
2016-07-24 22:06:18 +00:00
|
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
|
assert (TYPE (x) == PAIR);
|
|
|
|
|
CAR (x) = e;
|
2016-11-21 08:28:34 +00:00
|
|
|
|
return cell_unspecified;
|
2016-07-24 22:06:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
set_cdr_x (SCM x, SCM e)
|
2016-07-10 08:43:26 +00:00
|
|
|
|
{
|
core: Throw exceptions rather than asserts.
* lib.c (error): Throw instead of assert.
(check_formals, check_apply): Update.
* mes.c (scm_symbol_unbound_variable, scm_symbol_not_a_pair,
scm_symbol_system_error, scm_symbol_wrong_number_of_args,
scm_symbol_wrong_type_arg, scm_symbol_unbound_variable): New symbols.
(car, cdr, set_cdr_x, set_env_x, eval_apply, gc_up_arena): Update.
2016-12-28 21:26:33 +00:00
|
|
|
|
if (TYPE (x) != PAIR) error (cell_symbol_not_a_pair, cons (x, cell_set_cdr_x));
|
2016-11-21 08:30:59 +00:00
|
|
|
|
CDR (x) = e;
|
2016-11-21 08:28:34 +00:00
|
|
|
|
return cell_unspecified;
|
2016-07-10 11:47:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
set_env_x (SCM x, SCM e, SCM a)
|
2016-07-10 11:47:56 +00:00
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM p = assert_defined (x, assq (x, a));
|
core: Throw exceptions rather than asserts.
* lib.c (error): Throw instead of assert.
(check_formals, check_apply): Update.
* mes.c (scm_symbol_unbound_variable, scm_symbol_not_a_pair,
scm_symbol_system_error, scm_symbol_wrong_number_of_args,
scm_symbol_wrong_type_arg, scm_symbol_unbound_variable): New symbols.
(car, cdr, set_cdr_x, set_env_x, eval_apply, gc_up_arena): Update.
2016-12-28 21:26:33 +00:00
|
|
|
|
if (TYPE (p) != PAIR) error (cell_symbol_not_a_pair, cons (p, x));
|
2016-10-30 14:38:27 +00:00
|
|
|
|
return set_cdr_x (p, e);
|
2016-07-10 08:43:26 +00:00
|
|
|
|
}
|
2016-05-28 14:39:44 +00:00
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
pairlis (SCM x, SCM y, SCM a)
|
2016-05-28 14:39:44 +00:00
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
|
if (x == cell_nil)
|
2016-05-28 14:39:44 +00:00
|
|
|
|
return a;
|
2016-12-23 17:05:45 +00:00
|
|
|
|
if (TYPE (x) != PAIR)
|
2016-07-08 16:02:06 +00:00
|
|
|
|
return cons (cons (x, y), a);
|
2016-05-28 14:39:44 +00:00
|
|
|
|
return cons (cons (car (x), car (y)),
|
|
|
|
|
pairlis (cdr (x), cdr (y), a));
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
assq (SCM x, SCM a)
|
2016-05-28 14:39:44 +00:00
|
|
|
|
{
|
2016-12-26 09:00:17 +00:00
|
|
|
|
while (a != cell_nil && eq_p (x, CAAR (a)) == cell_f) a = CDR (a);
|
2016-11-21 08:28:34 +00:00
|
|
|
|
return a != cell_nil ? car (a) : cell_f;
|
2016-10-19 22:11:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
assq_ref_cache (SCM x, SCM a)
|
2016-10-19 22:11:48 +00:00
|
|
|
|
{
|
|
|
|
|
x = assq (x, a);
|
2016-11-21 08:28:34 +00:00
|
|
|
|
if (x == cell_f) return cell_undefined;
|
|
|
|
|
return cdr (x);
|
2016-10-19 22:11:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
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 16:42:03 +00: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 16:42:03 +00: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 16:42:03 +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
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
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 16:42:03 +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
|
|
|
|
eval_apply:
|
|
|
|
|
if (g_free + GC_SAFETY > ARENA_SIZE)
|
|
|
|
|
gc_pop_frame (gc (gc_push_frame ()));
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
#if FIXED_PRIMITIVES
|
|
|
|
|
case cell_vm_eval_car: goto eval_car;
|
|
|
|
|
case cell_vm_eval_cdr: goto eval_cdr;
|
|
|
|
|
case cell_vm_eval_cons: goto eval_cons;
|
|
|
|
|
case cell_vm_eval_null_p: goto eval_null_p;
|
|
|
|
|
#endif
|
|
|
|
|
case cell_vm_eval_set_x: goto eval_set_x;
|
|
|
|
|
case cell_vm_eval_macro: goto eval_macro;
|
|
|
|
|
case cell_vm_eval2: goto eval2;
|
|
|
|
|
case cell_vm_macro_expand: goto macro_expand;
|
|
|
|
|
case cell_vm_begin: goto begin;
|
|
|
|
|
case cell_vm_begin_read_input_file: goto begin_read_input_file;
|
|
|
|
|
case cell_vm_begin2: goto begin2;
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
SCM x = cell_nil;
|
|
|
|
|
SCM y = cell_nil;
|
2016-12-22 15:34:28 +00:00
|
|
|
|
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
|
|
|
|
if (r1 == cell_nil) goto vm_return;
|
2016-12-22 15:50:51 +00:00
|
|
|
|
if (TYPE (r1) != PAIR) 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
|
|
|
|
push_cc (car (r1), r1, r0, cell_vm_evlis2);
|
|
|
|
|
goto eval;
|
|
|
|
|
evlis2:
|
|
|
|
|
push_cc (cdr (r2), r1, r0, cell_vm_evlis3);
|
|
|
|
|
goto evlis;
|
|
|
|
|
evlis3:
|
|
|
|
|
r1 = cons (r2, r1);
|
|
|
|
|
goto vm_return;
|
2016-12-22 15:34:28 +00:00
|
|
|
|
|
|
|
|
|
apply:
|
2016-12-26 08:04:40 +00:00
|
|
|
|
switch (TYPE (car (r1)))
|
2016-05-28 14:39:44 +00:00
|
|
|
|
{
|
2016-12-24 11:10:05 +00:00
|
|
|
|
case FUNCTION: {
|
2016-12-26 08:04:40 +00:00
|
|
|
|
check_formals (car (r1), MAKE_NUMBER (FUNCTION (car (r1)).arity), cdr (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
|
|
|
|
r1 = call (car (r1), cdr (r1)); /// FIXME: move into eval_apply
|
|
|
|
|
goto vm_return;
|
2016-12-24 11:10:05 +00:00
|
|
|
|
}
|
2016-12-23 17:48:36 +00:00
|
|
|
|
case CLOSURE:
|
2016-12-14 18:02:19 +00:00
|
|
|
|
{
|
2016-12-26 08:04:40 +00:00
|
|
|
|
SCM cl = CLOSURE (car (r1));
|
2016-12-24 11:10:05 +00:00
|
|
|
|
SCM formals = cadr (cl);
|
2016-12-23 17:48:36 +00:00
|
|
|
|
SCM body = cddr (cl);
|
|
|
|
|
SCM aa = cdar (cl);
|
|
|
|
|
aa = cdr (aa);
|
2016-12-26 08:04:40 +00:00
|
|
|
|
check_formals (car (r1), formals, cdr (r1));
|
|
|
|
|
SCM p = pairlis (formals, cdr (r1), aa);
|
2016-12-23 17:48:36 +00:00
|
|
|
|
call_lambda (body, p, aa, r0);
|
|
|
|
|
goto begin;
|
|
|
|
|
}
|
2016-12-28 21:04:57 +00:00
|
|
|
|
case CONTINUATION:
|
|
|
|
|
{
|
|
|
|
|
x = r1;
|
|
|
|
|
g_stack = CONTINUATION (CAR (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
|
|
|
|
case SPECIAL:
|
|
|
|
|
{
|
|
|
|
|
switch (car (r1))
|
|
|
|
|
{
|
|
|
|
|
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:
|
|
|
|
|
{
|
|
|
|
|
r1 = cdr (r1);
|
|
|
|
|
goto call_with_current_continuation;
|
|
|
|
|
}
|
core: Throw exceptions rather than asserts.
* lib.c (error): Throw instead of assert.
(check_formals, check_apply): Update.
* mes.c (scm_symbol_unbound_variable, scm_symbol_not_a_pair,
scm_symbol_system_error, scm_symbol_wrong_number_of_args,
scm_symbol_wrong_type_arg, scm_symbol_unbound_variable): New symbols.
(car, cdr, set_cdr_x, set_env_x, eval_apply, gc_up_arena): Update.
2016-12-28 21:26:33 +00: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
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-23 17:48:36 +00:00
|
|
|
|
case SYMBOL:
|
|
|
|
|
{
|
2016-12-26 08:04:40 +00:00
|
|
|
|
if (car (r1) == cell_symbol_call_with_values)
|
2016-12-23 17:48:36 +00:00
|
|
|
|
{
|
2016-12-26 08:04:40 +00:00
|
|
|
|
r1 = cdr (r1);
|
2016-12-23 17:48:36 +00:00
|
|
|
|
goto call_with_values;
|
|
|
|
|
}
|
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
|
|
|
|
if (car (r1) == cell_symbol_current_module)
|
|
|
|
|
{
|
|
|
|
|
r1 = r0;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
2016-12-23 17:48:36 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case PAIR:
|
|
|
|
|
{
|
2016-12-26 08:04:40 +00:00
|
|
|
|
switch (caar (r1))
|
2016-12-23 17:48:36 +00:00
|
|
|
|
{
|
|
|
|
|
case cell_symbol_lambda:
|
|
|
|
|
{
|
2016-12-26 08:04:40 +00:00
|
|
|
|
SCM formals = cadr (car (r1));
|
|
|
|
|
SCM body = cddr (car (r1));
|
|
|
|
|
SCM p = pairlis (formals, cdr (r1), r0);
|
|
|
|
|
check_formals (r1, formals, cdr (r1));
|
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
|
|
|
|
}
|
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 (car (r1), r1, r0, cell_vm_apply2);
|
|
|
|
|
goto eval;
|
|
|
|
|
apply2:
|
|
|
|
|
check_apply (r1, car (r2));
|
|
|
|
|
r1 = cons (r1, cdr (r2));
|
2016-12-22 15:50:51 +00:00
|
|
|
|
goto apply;
|
2016-05-28 14:39:44 +00:00
|
|
|
|
|
2016-12-22 15:34:28 +00:00
|
|
|
|
eval:
|
2016-11-21 08:30:59 +00:00
|
|
|
|
switch (TYPE (r1))
|
2016-05-28 14:39:44 +00:00
|
|
|
|
{
|
2016-11-03 20:43:01 +00:00
|
|
|
|
case PAIR:
|
|
|
|
|
{
|
2016-12-14 18:02:19 +00:00
|
|
|
|
switch (car (r1))
|
|
|
|
|
{
|
2016-11-21 20:43:06 +00:00
|
|
|
|
#if FIXED_PRIMITIVES
|
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_car:
|
|
|
|
|
{
|
|
|
|
|
push_cc (CADR (r1), r1, r0, cell_vm_eval_car); goto eval;
|
|
|
|
|
eval_car:
|
|
|
|
|
x = r1; gc_pop_frame (); r1 = car (x); goto eval_apply;
|
|
|
|
|
}
|
|
|
|
|
case cell_symbol_cdr:
|
|
|
|
|
{
|
|
|
|
|
push_cc (CADR (r1), r1, r0, cell_vm_eval_cdr); goto eval;
|
|
|
|
|
eval_cdr:
|
|
|
|
|
x = r1; gc_pop_frame (); r1 = cdr (x); goto eval_apply;
|
|
|
|
|
}
|
|
|
|
|
case cell_symbol_cons: {
|
|
|
|
|
push_cc (CDR (r1), r1, r0, cell_vm_eval_cons); goto evlis;
|
|
|
|
|
eval_cons:
|
|
|
|
|
x = r1;
|
|
|
|
|
gc_pop_frame ();
|
|
|
|
|
r1 = cons (CAR (x), CADR (x));
|
|
|
|
|
goto eval_apply;
|
|
|
|
|
}
|
|
|
|
|
case cell_symbol_null_p:
|
|
|
|
|
{
|
|
|
|
|
push_cc (CADR (r1), r1, r0, cell_vm_eval_null_p);
|
|
|
|
|
goto eval;
|
|
|
|
|
eval_null_p:
|
|
|
|
|
x = r1; gc_pop_frame (); r1 = null_p (x); goto eval_apply;
|
|
|
|
|
}
|
2016-11-21 20:43:06 +00:00
|
|
|
|
#endif // FIXED_PRIMITIVES
|
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:
|
|
|
|
|
{
|
|
|
|
|
x = r1; gc_pop_frame (); r1 = cadr (x); goto eval_apply;
|
|
|
|
|
}
|
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
|
|
|
|
{
|
|
|
|
|
r1 = make_closure (cadr (r1), cddr (r1), assq (cell_closure, r0));
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
|
|
|
|
case cell_symbol_if: {r1=cdr (r1); goto vm_if;}
|
|
|
|
|
case cell_symbol_set_x:
|
|
|
|
|
{
|
|
|
|
|
push_cc (car (cddr (r1)), r1, r0, cell_vm_eval_set_x);
|
|
|
|
|
goto eval;
|
|
|
|
|
eval_set_x:
|
|
|
|
|
x = r2;
|
|
|
|
|
r1 = set_env_x (cadr (x), r1, r0);
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
|
|
|
|
case cell_vm_macro_expand:
|
|
|
|
|
{
|
|
|
|
|
push_cc (cadr (r1), r1, r0, cell_vm_return);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
}
|
2016-12-14 18:02:19 +00:00
|
|
|
|
default: {
|
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 (r1, r1, r0, cell_vm_eval_macro);
|
|
|
|
|
goto macro_expand;
|
|
|
|
|
eval_macro:
|
|
|
|
|
x = r2;
|
|
|
|
|
if (r1 != r2)
|
2016-12-22 07:31:20 +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
|
|
|
|
if (TYPE (r1) == PAIR)
|
2016-12-22 07:31:20 +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
|
|
|
|
set_cdr_x (r2, cdr (r1));
|
|
|
|
|
set_car_x (r2, car (r1));
|
2016-12-22 07:31:20 +00:00
|
|
|
|
}
|
2016-12-22 15:50:51 +00:00
|
|
|
|
goto eval;
|
2016-12-22 07:31:20 +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
|
|
|
|
push_cc (CDR (r1), r1, r0, cell_vm_eval2); goto evlis;
|
|
|
|
|
eval2:
|
|
|
|
|
r1 = cons (car (r2), r1);
|
2016-12-22 15:50:51 +00:00
|
|
|
|
goto apply;
|
2016-12-14 18:02:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-03 20:43:01 +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 SYMBOL:
|
|
|
|
|
{
|
|
|
|
|
r1 = assert_defined (r1, assq_ref_cache (r1, r0));
|
|
|
|
|
goto vm_return;
|
|
|
|
|
}
|
|
|
|
|
default: goto vm_return;
|
2016-05-28 14:39:44 +00:00
|
|
|
|
}
|
2016-10-08 15:00:32 +00:00
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM macro;
|
|
|
|
|
SCM expanders;
|
2016-12-23 21:48:27 +00:00
|
|
|
|
macro_expand:
|
2016-11-21 08:28:34 +00:00
|
|
|
|
if (TYPE (r1) == PAIR
|
|
|
|
|
&& (macro = lookup_macro (car (r1), r0)) != cell_f)
|
2016-12-22 15:50:51 +00:00
|
|
|
|
{
|
2016-12-26 08:04:40 +00:00
|
|
|
|
r1 = cons (macro, CDR (r1));
|
2016-12-22 15:50:51 +00:00
|
|
|
|
goto apply;
|
|
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
|
else if (TYPE (r1) == PAIR
|
|
|
|
|
&& TYPE (CAR (r1)) == SYMBOL
|
|
|
|
|
&& ((expanders = assq_ref_cache (cell_symbol_sc_expander_alist, r0)) != cell_undefined)
|
|
|
|
|
&& ((macro = assq (CAR (r1), expanders)) != cell_f))
|
2016-10-30 15:16:20 +00:00
|
|
|
|
{
|
2016-12-22 15:34:28 +00:00
|
|
|
|
SCM sc_expand = assq_ref_cache (cell_symbol_macro_expand, r0);
|
2016-11-21 08:28:34 +00:00
|
|
|
|
if (sc_expand != cell_undefined && sc_expand != cell_f)
|
2016-12-22 15:50:51 +00:00
|
|
|
|
{
|
2016-12-26 08:04:40 +00:00
|
|
|
|
r1 = cons (sc_expand, cons (r1, cell_nil));
|
2016-12-22 15:50:51 +00:00
|
|
|
|
goto apply;
|
|
|
|
|
}
|
2016-10-30 15:16:20 +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
|
|
|
|
goto vm_return;
|
2016-10-30 15:16:20 +00:00
|
|
|
|
|
2016-12-22 15:34:28 +00:00
|
|
|
|
begin:
|
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
|
|
|
|
x = cell_unspecified;
|
2016-11-21 08:36:32 +00:00
|
|
|
|
while (r1 != cell_nil) {
|
2016-12-07 19:26:41 +00:00
|
|
|
|
if (TYPE (r1) == PAIR && TYPE (CAR (r1)) == PAIR)
|
|
|
|
|
{
|
|
|
|
|
if (caar (r1) == cell_symbol_begin)
|
|
|
|
|
r1 = append2 (cdar (r1), cdr (r1));
|
|
|
|
|
else if (caar (r1) == cell_symbol_primitive_load)
|
2016-12-13 18:58:34 +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
|
|
|
|
push_cc (cons (cell_symbol_read_input_file, cell_nil), r1, r0, cell_vm_begin_read_input_file);
|
|
|
|
|
goto apply;
|
|
|
|
|
begin_read_input_file:
|
|
|
|
|
r1 = append2 (r1, cdr (r2));
|
2016-12-13 18:58:34 +00:00
|
|
|
|
}
|
2016-12-07 19:26:41 +00:00
|
|
|
|
}
|
2016-12-22 15:50:51 +00:00
|
|
|
|
if (CDR (r1) == cell_nil)
|
|
|
|
|
{
|
|
|
|
|
r1 = car (r1);
|
|
|
|
|
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
|
|
|
|
push_cc (CAR (r1), r1, r0, cell_vm_begin2);
|
|
|
|
|
goto eval;
|
|
|
|
|
begin2:
|
|
|
|
|
x = r1;
|
|
|
|
|
r1 = CDR (r2);
|
2016-11-21 08:36:32 +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
|
|
|
|
r1 = x;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
|
|
|
|
|
vm_if:
|
|
|
|
|
push_cc (car (r1), r1, r0, cell_vm_if_expr);
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
r1 = cadr (r1);
|
|
|
|
|
goto eval;
|
|
|
|
|
}
|
2016-11-21 08:36:32 +00:00
|
|
|
|
if (cddr (r1) != cell_nil)
|
2016-12-22 15:50:51 +00:00
|
|
|
|
{
|
core: Remove c3+r abbreviatons.
* lib.c (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr, cadddr):
Remove.
* mes.c: Rewrite callers
* module/mes/read-0.mes: Rewrite callers.
* module/mes/base.mes (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr,
cadddr): New function.
2016-12-24 13:21:36 +00: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 ();
|
|
|
|
|
push_cc (cons (car (r1), cons (x, cell_nil)), x, r0, cell_vm_call_with_current_continuation2);
|
|
|
|
|
goto apply;
|
|
|
|
|
call_with_current_continuation2:
|
|
|
|
|
CONTINUATION (r2) = g_stack;
|
|
|
|
|
goto vm_return;
|
|
|
|
|
|
2016-12-22 15:34:28 +00:00
|
|
|
|
call_with_values:
|
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 (cons (car (r1), cell_nil), r1, r0, cell_vm_call_with_values2);
|
|
|
|
|
goto apply;
|
|
|
|
|
call_with_values2:
|
|
|
|
|
if (TYPE (r1) == VALUES)
|
|
|
|
|
r1 = CDR (r1);
|
|
|
|
|
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
|
|
|
|
|
call (SCM fn, SCM x)
|
|
|
|
|
{
|
|
|
|
|
if ((FUNCTION (fn).arity > 0 || FUNCTION (fn).arity == -1)
|
|
|
|
|
&& x != cell_nil && TYPE (CAR (x)) == VALUES)
|
|
|
|
|
x = cons (CADAR (x), CDR (x));
|
|
|
|
|
if ((FUNCTION (fn).arity > 1 || FUNCTION (fn).arity == -1)
|
|
|
|
|
&& x != cell_nil && TYPE (CDR (x)) == PAIR && TYPE (CADR (x)) == VALUES)
|
|
|
|
|
x = cons (CAR (x), cons (CDADAR (x), CDR (x)));
|
|
|
|
|
switch (FUNCTION (fn).arity)
|
|
|
|
|
{
|
|
|
|
|
case 0: return FUNCTION (fn).function0 ();
|
|
|
|
|
case 1: return FUNCTION (fn).function1 (car (x));
|
|
|
|
|
case 2: return FUNCTION (fn).function2 (car (x), cadr (x));
|
core: Remove c3+r abbreviatons.
* lib.c (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr, cadddr):
Remove.
* mes.c: Rewrite callers
* module/mes/read-0.mes: Rewrite callers.
* module/mes/base.mes (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr,
cadddr): New function.
2016-12-24 13:21:36 +00:00
|
|
|
|
case 3: return FUNCTION (fn).function3 (car (x), cadr (x), car (cddr (x)));
|
2016-11-21 08:36:32 +00:00
|
|
|
|
case -1: return FUNCTION (fn).functionn (x);
|
|
|
|
|
}
|
2016-12-24 11:10:05 +00:00
|
|
|
|
|
2016-11-21 08:36:32 +00:00
|
|
|
|
return cell_unspecified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
2016-12-26 08:00:43 +00:00
|
|
|
|
gc_peek_frame ()
|
2016-11-21 08:36:32 +00:00
|
|
|
|
{
|
2016-12-26 08:00:43 +00:00
|
|
|
|
SCM frame = car (g_stack);
|
2016-11-21 08:36:32 +00:00
|
|
|
|
r1 = car (frame);
|
|
|
|
|
r2 = cadr (frame);
|
2017-01-04 08:07:11 +00:00
|
|
|
|
r3 = car (cddr (frame));
|
core: Remove c3+r abbreviatons.
* lib.c (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr, cadddr):
Remove.
* mes.c: Rewrite callers
* module/mes/read-0.mes: Rewrite callers.
* module/mes/base.mes (caaar, caadr, caddr, cdadr, cadar, cddar, cdddr,
cadddr): New function.
2016-12-24 13:21:36 +00:00
|
|
|
|
r0 = cadr (cddr (frame));
|
2016-11-21 08:36:32 +00:00
|
|
|
|
return frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
2016-12-26 08:00:43 +00:00
|
|
|
|
gc_pop_frame ()
|
|
|
|
|
{
|
|
|
|
|
SCM frame = gc_peek_frame (g_stack);
|
|
|
|
|
g_stack = cdr (g_stack);
|
|
|
|
|
return frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
gc_push_frame ()
|
2016-11-21 08:36:32 +00:00
|
|
|
|
{
|
2017-01-04 08:07:11 +00:00
|
|
|
|
SCM frame = cons (r1, cons (r2, cons (r3, cons (r0, cell_nil))));
|
2016-12-26 08:00:43 +00:00
|
|
|
|
return g_stack = cons (frame, g_stack);
|
2016-11-21 08:36:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
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
|
|
|
|
apply (SCM f, SCM x, SCM a) ///((internal))
|
2016-11-21 08:36:32 +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
|
|
|
|
push_cc (cons (f, x), cell_unspecified, r0, cell_unspecified);
|
|
|
|
|
r3 = cell_vm_apply;
|
|
|
|
|
return eval_apply ();
|
2016-12-10 11:07:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
append2 (SCM x, SCM y)
|
2016-05-28 14:39:44 +00:00
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
|
if (x == cell_nil) return y;
|
2016-11-21 08:30:59 +00:00
|
|
|
|
assert (TYPE (x) == PAIR);
|
2016-07-11 19:50:59 +00:00
|
|
|
|
return cons (car (x), append2 (cdr (x), y));
|
2016-05-28 14:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
append (SCM x) ///((arity . n))
|
2016-07-11 19:50:59 +00:00
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
|
if (x == cell_nil) return cell_nil;
|
2016-12-22 13:22:40 +00:00
|
|
|
|
if (cdr (x) == cell_nil) return car (x);
|
2016-07-11 19:50:59 +00:00
|
|
|
|
return append2 (car (x), append (cdr (x)));
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
Implement strings and symbols as list of characters [WAS: c-string].
* mes.c (scm_t): Add string field.
(make_string, internal_lookup_symbol, internal_make_symbol,
make_symbol, lookup, readword): Take scm*. Update callers.
(display_helper): Support string field.
(append_char): New function.
(readstring): Use it. Produce scm*.
(cstring_to_list): New function.
(add_environment, internal_make_symbol): Use it.
(list_of_char_equal_p): New function.
(internal_lookup_symbol): Use it.
* lib.c (list_ref): New function.
* string.c (string_ref): Use it.
(string, string_append, string_length, substring, number_to_string,
string_to_symbol, symbol_to_string): Update to list-of-characters
implementation.
2016-10-25 14:50:19 +00:00
|
|
|
|
cstring_to_list (char const* s)
|
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM p = cell_nil;
|
|
|
|
|
int i = strlen (s);
|
|
|
|
|
while (i--)
|
2016-12-23 15:26:00 +00:00
|
|
|
|
p = cons (MAKE_CHAR (s[i]), p);
|
2016-05-28 14:39:44 +00:00
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-19 22:25:24 +00:00
|
|
|
|
SCM
|
|
|
|
|
null_p (SCM x)
|
|
|
|
|
{
|
|
|
|
|
return x == cell_nil ? cell_t : cell_f;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
2016-12-23 10:31:34 +00:00
|
|
|
|
make_symbol_ (SCM s)
|
2016-10-08 06:41:30 +00:00
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
|
g_cells[tmp_num].value = SYMBOL;
|
|
|
|
|
SCM x = make_cell (tmp_num, s, 0);
|
2016-12-10 11:07:04 +00:00
|
|
|
|
g_symbols = cons (x, g_symbols);
|
2016-10-08 06:41:30 +00:00
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
make_symbol (SCM s)
|
2016-05-28 14:39:44 +00:00
|
|
|
|
{
|
2016-12-23 10:31:34 +00:00
|
|
|
|
SCM x = lookup_symbol_ (s);
|
|
|
|
|
return x ? x : make_symbol_ (s);
|
2016-05-28 14:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
make_vector (SCM n)
|
2016-07-11 08:38:02 +00:00
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
|
int k = VALUE (n);
|
|
|
|
|
g_cells[tmp_num].value = VECTOR;
|
2016-11-21 08:36:32 +00:00
|
|
|
|
SCM v = alloc (k);
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM x = make_cell (tmp_num, k, v);
|
|
|
|
|
for (int i=0; i<k; i++) g_cells[v+i] = g_cells[vector_entry (cell_unspecified)];
|
2016-10-26 17:44:36 +00:00
|
|
|
|
return x;
|
2016-07-11 08:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-24 00:23:50 +00:00
|
|
|
|
SCM
|
|
|
|
|
arity_ (SCM x)
|
|
|
|
|
{
|
|
|
|
|
assert (TYPE (x) == FUNCTION);
|
|
|
|
|
return MAKE_NUMBER (FUNCTION (x).arity);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
values (SCM x) ///((arity . n))
|
2016-07-11 17:32:11 +00:00
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM v = cons (0, x);
|
2016-11-21 08:30:59 +00:00
|
|
|
|
TYPE (v) = VALUES;
|
2016-07-11 17:32:11 +00:00
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
vector_length (SCM x)
|
2016-07-11 08:38:02 +00:00
|
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
|
assert (TYPE (x) == VECTOR);
|
2016-12-23 15:22:19 +00:00
|
|
|
|
return MAKE_NUMBER (LENGTH (x));
|
2016-07-11 08:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
vector_ref (SCM x, SCM i)
|
|
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
|
assert (TYPE (x) == VECTOR);
|
|
|
|
|
assert (VALUE (i) < LENGTH (x));
|
|
|
|
|
SCM e = VECTOR (x) + VALUE (i);
|
|
|
|
|
if (TYPE (e) == REF) e = g_cells[e].ref;
|
2016-12-23 15:26:00 +00:00
|
|
|
|
if (TYPE (e) == CHAR) e = MAKE_CHAR (VALUE (e));
|
2016-12-23 15:22:19 +00:00
|
|
|
|
if (TYPE (e) == NUMBER) e = MAKE_NUMBER (VALUE (e));
|
Introduce reference type, use vectors of SCM.
* mes.c (type): Add REF.
(scm_t): Add ref, change vector to *scm_t. Update users.
(alloc): New function.
(cons, make_char, make_macro, make_number, make_string,
internal_make_symbol, make_vector): Use it.
(make_ref): New function.
(vector_entry): New function.
(make_vector, list_to_vector, vector_set_x): Use it.
(vector_ref): Dereference REF entry.
(display_helper): Handle REF.
* lib.c (vector_to_list): Handle REF.
* type.c (ref_p): New function.
* tests/vector.test (vector list): New test.
Bugfix vector-ref.
* mes.c (vector-ref): Make copies of simple values. Fixes lalr.
* tests/vector.test (vector-set! 3): New test.
2016-10-24 22:21:28 +00:00
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
vector_entry (SCM x) {
|
2016-12-23 15:31:56 +00:00
|
|
|
|
if (TYPE (x) == PAIR || TYPE (x) == SPECIAL || TYPE (x) == STRING || TYPE (x) == SYMBOL || TYPE (x) == VECTOR) x = MAKE_REF (x);
|
Introduce reference type, use vectors of SCM.
* mes.c (type): Add REF.
(scm_t): Add ref, change vector to *scm_t. Update users.
(alloc): New function.
(cons, make_char, make_macro, make_number, make_string,
internal_make_symbol, make_vector): Use it.
(make_ref): New function.
(vector_entry): New function.
(make_vector, list_to_vector, vector_set_x): Use it.
(vector_ref): Dereference REF entry.
(display_helper): Handle REF.
* lib.c (vector_to_list): Handle REF.
* type.c (ref_p): New function.
* tests/vector.test (vector list): New test.
Bugfix vector-ref.
* mes.c (vector-ref): Make copies of simple values. Fixes lalr.
* tests/vector.test (vector-set! 3): New test.
2016-10-24 22:21:28 +00:00
|
|
|
|
return x;
|
2016-07-11 08:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
vector_set_x (SCM x, SCM i, SCM e)
|
2016-07-11 08:38:02 +00:00
|
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
|
assert (TYPE (x) == VECTOR);
|
|
|
|
|
assert (VALUE (i) < LENGTH (x));
|
2016-11-21 08:28:34 +00:00
|
|
|
|
g_cells[VECTOR (x)+g_cells[i].value] = g_cells[vector_entry (e)];
|
|
|
|
|
return cell_unspecified;
|
2016-07-11 08:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-19 22:25:24 +00:00
|
|
|
|
SCM
|
|
|
|
|
list_to_vector (SCM x)
|
|
|
|
|
{
|
|
|
|
|
VALUE (tmp_num) = VALUE (length (x));
|
|
|
|
|
SCM v = make_vector (tmp_num);
|
|
|
|
|
SCM p = VECTOR (v);
|
|
|
|
|
while (x != cell_nil)
|
|
|
|
|
{
|
|
|
|
|
g_cells[p++] = g_cells[vector_entry (car (x))];
|
|
|
|
|
x = cdr (x);
|
|
|
|
|
}
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-23 19:09:57 +00:00
|
|
|
|
SCM
|
|
|
|
|
vector_to_list (SCM v)
|
|
|
|
|
{
|
|
|
|
|
SCM x = cell_nil;
|
|
|
|
|
for (int i = 0; i < LENGTH (v); i++) {
|
|
|
|
|
SCM e = VECTOR (v)+i;
|
|
|
|
|
if (TYPE (e) == REF) e = g_cells[e].ref;
|
|
|
|
|
x = append2 (x, cons (e, cell_nil));
|
|
|
|
|
}
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-10 11:07:04 +00:00
|
|
|
|
void
|
|
|
|
|
make_tmps (scm* cells)
|
|
|
|
|
{
|
2017-01-04 07:16:14 +00:00
|
|
|
|
tmp = g_free++;
|
2016-12-10 11:07:04 +00:00
|
|
|
|
cells[tmp].type = CHAR;
|
2017-01-04 07:16:14 +00:00
|
|
|
|
tmp_num = g_free++;
|
2016-12-10 11:07:04 +00:00
|
|
|
|
cells[tmp_num].type = NUMBER;
|
2017-01-04 07:16:14 +00:00
|
|
|
|
tmp_num2 = g_free++;
|
2016-12-10 11:07:04 +00:00
|
|
|
|
cells[tmp_num2].type = NUMBER;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:36:32 +00:00
|
|
|
|
// Jam Collector
|
2016-12-10 11:07:04 +00:00
|
|
|
|
SCM g_symbol_max;
|
2016-12-11 07:23:15 +00:00
|
|
|
|
bool g_debug = false;
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
gc_up_arena ()
|
2016-05-28 14:39:44 +00:00
|
|
|
|
{
|
2016-12-11 07:23:15 +00:00
|
|
|
|
ARENA_SIZE *= 2;
|
|
|
|
|
void *p = realloc (g_cells-1, 2*ARENA_SIZE*sizeof(scm));
|
core: Throw exceptions rather than asserts.
* lib.c (error): Throw instead of assert.
(check_formals, check_apply): Update.
* mes.c (scm_symbol_unbound_variable, scm_symbol_not_a_pair,
scm_symbol_system_error, scm_symbol_wrong_number_of_args,
scm_symbol_wrong_type_arg, scm_symbol_unbound_variable): New symbols.
(car, cdr, set_cdr_x, set_env_x, eval_apply, gc_up_arena): Update.
2016-12-28 21:26:33 +00:00
|
|
|
|
if (!p) error (cell_symbol_system_error, cons (MAKE_STRING (cstring_to_list (strerror (errno))), MAKE_NUMBER (g_free)));
|
2016-12-11 07:23:15 +00:00
|
|
|
|
g_cells = (scm*)p;
|
|
|
|
|
g_cells++;
|
|
|
|
|
gc_init_news ();
|
2016-05-28 14:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
2016-11-21 08:36:32 +00:00
|
|
|
|
gc ()
|
2016-07-10 22:15:28 +00:00
|
|
|
|
{
|
2017-01-04 07:16:14 +00:00
|
|
|
|
if (g_debug) fprintf (stderr, "***gc[%d]...", g_free);
|
|
|
|
|
g_free = 1;
|
2016-12-11 17:41:08 +00:00
|
|
|
|
if (g_cells < g_news && ARENA_SIZE < MAX_ARENA_SIZE) gc_up_arena ();
|
2017-01-04 07:16:14 +00:00
|
|
|
|
for (int i=g_free; i<g_symbol_max; i++)
|
2016-11-21 08:36:32 +00:00
|
|
|
|
gc_copy (i);
|
2016-12-10 11:07:04 +00:00
|
|
|
|
make_tmps (g_news);
|
|
|
|
|
g_symbols = gc_copy (g_symbols);
|
2016-12-26 08:00:43 +00:00
|
|
|
|
SCM new = gc_copy (g_stack);
|
|
|
|
|
if (g_debug) fprintf (stderr, "new=%d\n", new, g_stack);
|
|
|
|
|
g_stack = new;
|
2016-11-21 08:36:32 +00:00
|
|
|
|
return gc_loop (1);
|
2016-07-10 22:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-19 22:25:24 +00:00
|
|
|
|
SCM
|
2016-11-21 08:36:32 +00:00
|
|
|
|
gc_loop (SCM scan)
|
2016-11-19 22:25:24 +00:00
|
|
|
|
{
|
2017-01-04 07:16:14 +00:00
|
|
|
|
while (scan < g_free)
|
2016-11-21 08:36:32 +00:00
|
|
|
|
{
|
2016-12-23 17:48:36 +00:00
|
|
|
|
if (NTYPE (scan) == CLOSURE
|
2016-12-28 21:04:57 +00:00
|
|
|
|
|| NTYPE (scan) == CONTINUATION
|
2016-12-24 00:23:50 +00:00
|
|
|
|
|| NTYPE (scan) == FUNCTION
|
2016-12-23 17:48:36 +00:00
|
|
|
|
|| NTYPE (scan) == KEYWORD
|
2016-12-16 22:30:33 +00:00
|
|
|
|
|| NTYPE (scan) == MACRO
|
2016-11-21 08:36:32 +00:00
|
|
|
|
|| NTYPE (scan) == PAIR
|
|
|
|
|
|| NTYPE (scan) == REF
|
2016-12-10 11:07:04 +00:00
|
|
|
|
|| scan == 1 // null
|
|
|
|
|
|| NTYPE (scan) == SPECIAL
|
|
|
|
|
|| NTYPE (scan) == STRING
|
|
|
|
|
|| NTYPE (scan) == SYMBOL)
|
2016-11-21 08:36:32 +00:00
|
|
|
|
{
|
|
|
|
|
SCM car = gc_copy (g_news[scan].car);
|
|
|
|
|
gc_relocate_car (scan, car);
|
|
|
|
|
}
|
2016-12-23 17:48:36 +00:00
|
|
|
|
if ((NTYPE (scan) == CLOSURE
|
2016-12-28 21:04:57 +00:00
|
|
|
|
|| NTYPE (scan) == CONTINUATION
|
2016-12-23 17:48:36 +00:00
|
|
|
|
|| NTYPE (scan) == MACRO
|
2016-11-21 08:36:32 +00:00
|
|
|
|
|| NTYPE (scan) == PAIR
|
|
|
|
|
|| NTYPE (scan) == VALUES)
|
|
|
|
|
&& g_news[scan].cdr) // allow for 0 terminated list of symbols
|
|
|
|
|
{
|
|
|
|
|
SCM cdr = gc_copy (g_news[scan].cdr);
|
|
|
|
|
gc_relocate_cdr (scan, cdr);
|
|
|
|
|
}
|
|
|
|
|
scan++;
|
|
|
|
|
}
|
|
|
|
|
return gc_flip ();
|
2016-11-19 22:25:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
2016-11-21 08:36:32 +00:00
|
|
|
|
gc_copy (SCM old)
|
Implement strings and symbols as list of characters [WAS: c-string].
* mes.c (scm_t): Add string field.
(make_string, internal_lookup_symbol, internal_make_symbol,
make_symbol, lookup, readword): Take scm*. Update callers.
(display_helper): Support string field.
(append_char): New function.
(readstring): Use it. Produce scm*.
(cstring_to_list): New function.
(add_environment, internal_make_symbol): Use it.
(list_of_char_equal_p): New function.
(internal_lookup_symbol): Use it.
* lib.c (list_ref): New function.
* string.c (string_ref): Use it.
(string, string_append, string_length, substring, number_to_string,
string_to_symbol, symbol_to_string): Update to list-of-characters
implementation.
2016-10-25 14:50:19 +00:00
|
|
|
|
{
|
2016-11-21 08:36:32 +00:00
|
|
|
|
if (TYPE (old) == BROKEN_HEART) return g_cells[old].car;
|
2017-01-04 07:16:14 +00:00
|
|
|
|
SCM new = g_free++;
|
2016-11-21 08:36:32 +00:00
|
|
|
|
g_news[new] = g_cells[old];
|
|
|
|
|
if (NTYPE (new) == VECTOR)
|
|
|
|
|
{
|
2017-01-04 07:16:14 +00:00
|
|
|
|
g_news[new].vector = g_free;
|
2016-11-21 08:36:32 +00:00
|
|
|
|
for (int i=0; i<LENGTH (old); i++)
|
2017-01-04 07:16:14 +00:00
|
|
|
|
g_news[g_free++] = g_cells[VECTOR (old)+i];
|
2016-11-21 08:36:32 +00:00
|
|
|
|
}
|
|
|
|
|
g_cells[old].type = BROKEN_HEART;
|
|
|
|
|
g_cells[old].car = new;
|
|
|
|
|
return new;
|
Implement strings and symbols as list of characters [WAS: c-string].
* mes.c (scm_t): Add string field.
(make_string, internal_lookup_symbol, internal_make_symbol,
make_symbol, lookup, readword): Take scm*. Update callers.
(display_helper): Support string field.
(append_char): New function.
(readstring): Use it. Produce scm*.
(cstring_to_list): New function.
(add_environment, internal_make_symbol): Use it.
(list_of_char_equal_p): New function.
(internal_lookup_symbol): Use it.
* lib.c (list_ref): New function.
* string.c (string_ref): Use it.
(string, string_append, string_length, substring, number_to_string,
string_to_symbol, symbol_to_string): Update to list-of-characters
implementation.
2016-10-25 14:50:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
2016-11-21 08:36:32 +00:00
|
|
|
|
gc_relocate_car (SCM new, SCM car)
|
2016-07-10 20:43:23 +00:00
|
|
|
|
{
|
2016-11-21 08:36:32 +00:00
|
|
|
|
g_news[new].car = car;
|
|
|
|
|
return cell_unspecified;
|
2016-07-10 20:43:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:36:32 +00:00
|
|
|
|
SCM
|
|
|
|
|
gc_relocate_cdr (SCM new, SCM cdr)
|
2016-07-09 16:56:59 +00:00
|
|
|
|
{
|
2016-11-21 08:36:32 +00:00
|
|
|
|
g_news[new].cdr = cdr;
|
|
|
|
|
return cell_unspecified;
|
2016-07-09 16:56:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
2016-11-21 08:36:32 +00:00
|
|
|
|
gc_flip ()
|
2016-05-28 14:39:44 +00:00
|
|
|
|
{
|
2016-11-21 08:36:32 +00:00
|
|
|
|
scm *cells = g_cells;
|
|
|
|
|
g_cells = g_news;
|
|
|
|
|
g_news = cells;
|
2017-01-04 07:16:14 +00:00
|
|
|
|
if (g_debug) fprintf (stderr, " => jam[%d]\n", g_free);
|
2016-12-26 08:00:43 +00:00
|
|
|
|
return g_stack;
|
2016-05-28 14:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:36:32 +00:00
|
|
|
|
// Environment setup
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
acons (SCM key, SCM value, SCM alist)
|
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 16:42:03 +00:00
|
|
|
|
{
|
|
|
|
|
return cons (cons (key, value), alist);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
2016-12-11 07:23:15 +00:00
|
|
|
|
gc_init_cells ()
|
2016-05-15 22:07:44 +00:00
|
|
|
|
{
|
2016-12-11 07:23:15 +00:00
|
|
|
|
g_cells = (scm *)malloc (2*ARENA_SIZE*sizeof(scm));
|
2016-10-27 14:44:09 +00:00
|
|
|
|
g_cells[0].type = VECTOR;
|
2016-11-19 22:25:24 +00:00
|
|
|
|
g_cells[0].length = 1000;
|
2016-11-21 08:28:34 +00:00
|
|
|
|
g_cells[0].vector = 0;
|
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 16:42:03 +00:00
|
|
|
|
g_cells++;
|
2016-11-21 08:28:34 +00:00
|
|
|
|
g_cells[0].type = CHAR;
|
|
|
|
|
g_cells[0].value = 'c';
|
2016-12-11 07:23:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
gc_init_news ()
|
|
|
|
|
{
|
|
|
|
|
g_news = g_cells-1 + ARENA_SIZE;
|
|
|
|
|
g_news[0].type = VECTOR;
|
|
|
|
|
g_news[0].length = 1000;
|
|
|
|
|
g_news[0].vector = 0;
|
|
|
|
|
g_news++;
|
|
|
|
|
g_news[0].type = CHAR;
|
|
|
|
|
g_news[0].value = 'n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
mes_symbols () ///((internal))
|
|
|
|
|
{
|
|
|
|
|
gc_init_cells ();
|
|
|
|
|
gc_init_news ();
|
2016-11-21 08:28:34 +00:00
|
|
|
|
|
|
|
|
|
#include "mes.symbols.i"
|
|
|
|
|
|
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 16:43:33 +00:00
|
|
|
|
|
2016-12-23 09:38:41 +00:00
|
|
|
|
#include "mes.symbol-names.i"
|
|
|
|
|
|
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);
|
|
|
|
|
|
2016-11-19 22:25:24 +00:00
|
|
|
|
#if BOOT
|
|
|
|
|
a = acons (cell_symbol_label, cell_t, a);
|
|
|
|
|
#endif
|
2016-12-23 16:02:23 +00:00
|
|
|
|
a = acons (cell_symbol_dot, cell_dot, a);
|
2016-11-19 22:25:24 +00:00
|
|
|
|
a = acons (cell_symbol_begin, cell_begin, a);
|
2016-12-28 21:04:57 +00:00
|
|
|
|
a = acons (cell_symbol_call_with_current_continuation, cell_call_with_current_continuation, a);
|
2016-12-23 16:02:23 +00:00
|
|
|
|
a = acons (cell_symbol_sc_expand, cell_f, a);
|
2016-11-19 22:25:24 +00:00
|
|
|
|
a = acons (cell_closure, a, a);
|
|
|
|
|
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
mes_builtins (SCM a)
|
|
|
|
|
{
|
|
|
|
|
#include "mes.i"
|
|
|
|
|
|
|
|
|
|
#include "lib.i"
|
|
|
|
|
#include "math.i"
|
|
|
|
|
#include "posix.i"
|
2016-11-21 08:36:32 +00:00
|
|
|
|
#include "reader.i"
|
2016-11-19 22:25:24 +00:00
|
|
|
|
|
2016-10-22 18:51:32 +00:00
|
|
|
|
#include "lib.environment.i"
|
2016-11-21 08:28:34 +00:00
|
|
|
|
#include "math.environment.i"
|
2016-10-21 20:44:50 +00: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"
|
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 16:42:03 +00:00
|
|
|
|
|
2016-11-19 22:25:24 +00:00
|
|
|
|
SCM
|
2016-12-26 08:00:43 +00:00
|
|
|
|
mes_g_stack (SCM a) ///((internal))
|
2016-11-19 22:25:24 +00:00
|
|
|
|
{
|
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 16:42:03 +00:00
|
|
|
|
r0 = a;
|
2016-12-23 15:26:00 +00:00
|
|
|
|
r1 = MAKE_CHAR (0);
|
|
|
|
|
r2 = MAKE_CHAR (0);
|
2017-01-04 08:07:11 +00:00
|
|
|
|
r3 = MAKE_CHAR (0);
|
2016-12-26 08:00:43 +00:00
|
|
|
|
g_stack = cons (cell_nil, cell_nil);
|
2016-11-19 22:25:24 +00:00
|
|
|
|
return r0;
|
|
|
|
|
}
|
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 16:42:03 +00:00
|
|
|
|
|
2016-11-19 22:25:24 +00:00
|
|
|
|
SCM
|
|
|
|
|
mes_environment () ///((internal))
|
|
|
|
|
{
|
|
|
|
|
SCM a = mes_symbols ();
|
2016-12-26 08:00:43 +00:00
|
|
|
|
return mes_g_stack (a);
|
2016-05-28 14:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
make_closure (SCM args, SCM body, SCM a)
|
2016-07-19 19:37:39 +00:00
|
|
|
|
{
|
2016-12-23 17:48:36 +00:00
|
|
|
|
return make_cell (tmp_num_ (CLOSURE), cell_f, cons (cons (cell_circular, a), cons (args, body)));
|
2016-07-19 19:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM
|
|
|
|
|
lookup_macro (SCM x, SCM a)
|
2016-10-20 17:19:32 +00:00
|
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
|
if (TYPE (x) != SYMBOL) return cell_f;
|
2016-11-21 08:28:34 +00:00
|
|
|
|
SCM m = assq_ref_cache (x, a);
|
2016-12-23 17:05:45 +00:00
|
|
|
|
if (TYPE (m) == MACRO) return MACRO (m);
|
2016-11-21 08:28:34 +00:00
|
|
|
|
return cell_f;
|
2016-07-08 16:02:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
core: Move reader and posix functions from mes.c
* mes.c (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte, write_byte, read_input_file_env_, read_input_file_env):
Remove.
* posix.c (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte, write_byte): Move from mes.c.
* reader (read_input_file_env_, read_input_file_env): Move from mes.c.
2016-12-24 10:28:25 +00:00
|
|
|
|
FILE *g_stdin;
|
2016-10-22 18:51:32 +00:00
|
|
|
|
#include "lib.c"
|
2016-10-22 18:18:03 +00:00
|
|
|
|
#include "math.c"
|
2016-11-02 19:22:02 +00:00
|
|
|
|
#include "posix.c"
|
2016-11-21 08:36:32 +00:00
|
|
|
|
#include "reader.c"
|
2016-10-22 18:18:03 +00:00
|
|
|
|
|
2016-07-16 20:43:13 +00:00
|
|
|
|
int
|
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
|
{
|
2017-01-04 07:16:14 +00:00
|
|
|
|
#if __GNUC__
|
2016-12-10 11:07:04 +00:00
|
|
|
|
g_debug = getenv ("MES_DEBUG");
|
2017-01-04 07:16:14 +00:00
|
|
|
|
#else
|
|
|
|
|
#endif
|
2016-12-13 18:58:34 +00:00
|
|
|
|
if (getenv ("MES_ARENA")) ARENA_SIZE = atoi (getenv ("MES_ARENA"));
|
2016-12-25 14:38:26 +00:00
|
|
|
|
if (argc > 1 && !strcmp (argv[1], "--help")) return puts ("Usage: mes [--dump|--load] < FILE");
|
2017-01-04 07:16:14 +00:00
|
|
|
|
if (argc > 1 && !strcmp (argv[1], "--version")) {puts ("Mes ");puts (VERSION);return 0;};
|
2016-11-02 17:25:18 +00:00
|
|
|
|
g_stdin = stdin;
|
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);
|
|
|
|
|
if (argc > 1 && !strcmp (argv[1], "--dump")) return dump ();
|
2017-01-03 22:41:11 +00:00
|
|
|
|
|
|
|
|
|
SCM lst = cell_nil;
|
|
|
|
|
for (int i=argc; i; i--) lst = cons (MAKE_STRING (cstring_to_list (argv[i-1])), lst);
|
|
|
|
|
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);
|
|
|
|
|
r3 = cell_vm_begin;
|
|
|
|
|
r1 = eval_apply ();
|
|
|
|
|
stderr_ (r1);
|
2016-08-12 12:17:20 +00:00
|
|
|
|
fputs ("", stderr);
|
2016-12-26 08:00:43 +00:00
|
|
|
|
gc (g_stack);
|
2017-01-04 07:16:14 +00:00
|
|
|
|
#if __GNUC__
|
|
|
|
|
if (g_debug) fprintf (stderr, "\nstats: [%d]\n", g_free);
|
|
|
|
|
#else
|
|
|
|
|
#endif
|
2016-07-16 20:43:13 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|