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
|
|
|
|
* Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.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>
|
|
|
|
|
2016-05-15 22:07:44 +00:00
|
|
|
#define DEBUG 0
|
2016-10-22 17:26:12 +00:00
|
|
|
#define QUASIQUOTE 1
|
2016-10-30 15:01:34 +00:00
|
|
|
//#define QUASISYNTAX 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
|
|
|
|
2016-10-27 14:44:09 +00:00
|
|
|
#define GC 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
|
|
|
#define MES_FULL 1
|
|
|
|
#define MES_MINI 0 // 1 for gc-2a.test, gc-3.test
|
|
|
|
|
|
|
|
#if MES_FULL
|
2016-11-21 08:28:34 +00:00
|
|
|
int ARENA_SIZE = 400000000; // need this much for scripts/mescc.mes
|
|
|
|
//int ARENA_SIZE = 300000000; // need this much for tests/match.scm
|
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
|
|
|
//int ARENA_SIZE = 30000000; // need this much for tests/record.scm
|
|
|
|
//int ARENA_SIZE = 500000; // enough for tests/scm.test
|
|
|
|
//int ARENA_SIZE = 60000; // enough for tests/base.test
|
|
|
|
int GC_SAFETY = 10000;
|
|
|
|
int GC_FREE = 20000;
|
|
|
|
#else
|
2016-11-21 08:28:34 +00:00
|
|
|
//int ARENA_SIZE = 500; // MINI
|
|
|
|
int ARENA_SIZE = 4000; // MES_MINI, gc-3.test
|
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
|
|
|
//int ARENA_SIZE = 10000; // gc-2a.test
|
2016-11-21 08:28:34 +00:00
|
|
|
//int ARENA_SIZE = 18000; // gc-2.test -->KRAK
|
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
|
|
|
//int ARENA_SIZE = 23000; // gc-2.test OK
|
2016-11-21 08:28:34 +00:00
|
|
|
// int GC_SAFETY = 1000;
|
|
|
|
// int GC_FREE = 1000;
|
|
|
|
int GC_SAFETY = 10;
|
|
|
|
int GC_FREE = 10;
|
2016-10-27 18:46:29 +00:00
|
|
|
#endif
|
2016-05-15 22:07:44 +00:00
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
typedef long SCM;
|
|
|
|
enum type_t {CHAR, FUNCTION, MACRO, NUMBER, PAIR, SPECIAL, STRING, SYMBOL, REF, VALUES, VECTOR, BROKEN_HEART};
|
|
|
|
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);
|
2016-11-03 20:28:05 +00:00
|
|
|
typedef struct function_t {
|
|
|
|
union {
|
|
|
|
function0_t function0;
|
|
|
|
function1_t function1;
|
|
|
|
function2_t function2;
|
|
|
|
function3_t function3;
|
|
|
|
functionn_t functionn;
|
|
|
|
};
|
|
|
|
int arity;
|
|
|
|
} function;
|
|
|
|
struct scm_t;
|
2016-05-28 14:39:44 +00:00
|
|
|
typedef struct scm_t {
|
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;
|
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;
|
|
|
|
SCM macro;
|
|
|
|
SCM vector;
|
2016-10-26 17:44:36 +00:00
|
|
|
int hits;
|
2016-05-28 14:39:44 +00:00
|
|
|
};
|
|
|
|
} scm;
|
|
|
|
|
2016-11-19 21:31:30 +00:00
|
|
|
function functions[200];
|
|
|
|
int g_function = 0;
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
#include "mes.symbols.h"
|
|
|
|
#include "define.h"
|
|
|
|
#include "lib.h"
|
|
|
|
#include "math.h"
|
|
|
|
#include "mes.h"
|
|
|
|
#include "posix.h"
|
|
|
|
#include "quasiquote.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "type.h"
|
|
|
|
|
|
|
|
SCM display_ (FILE* f, SCM x);
|
|
|
|
SCM display_helper (FILE*, SCM , bool, char const*, bool);
|
|
|
|
|
|
|
|
SCM symbols = 0;
|
|
|
|
SCM stack = 0;
|
|
|
|
SCM r0 = 0; // a/env
|
|
|
|
SCM r1 = 0; // param 1
|
|
|
|
SCM r2 = 0; // param 2
|
|
|
|
SCM r3 = 0; // param 3
|
|
|
|
|
|
|
|
scm scm_nil = {SPECIAL, "()"};
|
|
|
|
scm scm_f = {SPECIAL, "#f"};
|
|
|
|
scm scm_t = {SPECIAL, "#t"};
|
|
|
|
scm scm_dot = {SPECIAL, "."};
|
|
|
|
scm scm_undefined = {SPECIAL, "*undefined*"};
|
|
|
|
scm scm_unspecified = {SPECIAL, "*unspecified*"};
|
|
|
|
scm scm_closure = {SPECIAL, "*closure*"};
|
|
|
|
scm scm_circular = {SPECIAL, "*circular*"};
|
2016-10-20 16:43:33 +00:00
|
|
|
#if BOOT
|
|
|
|
scm scm_label = {
|
2016-11-21 08:28:34 +00:00
|
|
|
SPECIAL, "label"};
|
2016-10-20 16:43:33 +00:00
|
|
|
#endif
|
2016-11-21 08:28:34 +00:00
|
|
|
scm scm_begin = {SPECIAL, "*begin*"};
|
|
|
|
|
|
|
|
scm scm_symbol_lambda = {SYMBOL, "lambda"};
|
|
|
|
scm scm_symbol_begin = {SYMBOL, "begin"};
|
|
|
|
scm scm_symbol_if = {SYMBOL, "if"};
|
|
|
|
scm scm_symbol_define = {SYMBOL, "define"};
|
|
|
|
scm scm_symbol_define_macro = {SYMBOL, "define-macro"};
|
|
|
|
scm scm_symbol_set_x = {SYMBOL, "set!"};
|
|
|
|
|
|
|
|
scm scm_symbol_quote = {SYMBOL, "quote"};
|
|
|
|
scm scm_symbol_quasiquote = {SYMBOL, "quasiquote"};
|
|
|
|
scm scm_symbol_unquote = {SYMBOL, "unquote"};
|
|
|
|
scm scm_symbol_unquote_splicing = {SYMBOL, "unquote-splicing"};
|
|
|
|
|
|
|
|
scm scm_symbol_sc_expand = {SYMBOL, "sc-expand"};
|
|
|
|
scm scm_symbol_expand_macro = {SYMBOL, "expand-macro"};
|
|
|
|
scm scm_symbol_sc_expander_alist = {SYMBOL, "*sc-expander-alist*"};
|
|
|
|
scm scm_symbol_noexpand = {SYMBOL, "noexpand"};
|
|
|
|
scm scm_symbol_syntax = {SYMBOL, "syntax"};
|
|
|
|
scm scm_symbol_quasisyntax = {SYMBOL, "quasisyntax"};
|
|
|
|
scm scm_symbol_unsyntax = {SYMBOL, "unsyntax"};
|
|
|
|
scm scm_symbol_unsyntax_splicing = {SYMBOL, "unsyntax-splicing"};
|
|
|
|
|
|
|
|
scm scm_symbol_call_with_values = {SYMBOL, "call-with-values"};
|
|
|
|
scm scm_symbol_current_module = {SYMBOL, "current-module"};
|
|
|
|
scm scm_symbol_primitive_load = {SYMBOL, "primitive-load"};
|
2016-05-28 14:39:44 +00:00
|
|
|
|
2016-07-24 21:41:16 +00:00
|
|
|
scm char_nul = {CHAR, .name="nul", .value=0};
|
|
|
|
scm char_backspace = {CHAR, .name="backspace", .value=8};
|
|
|
|
scm char_tab = {CHAR, .name="tab", .value=9};
|
|
|
|
scm char_newline = {CHAR, .name="newline", .value=10};
|
|
|
|
scm char_vt = {CHAR, .name="vt", .value=11};
|
|
|
|
scm char_page = {CHAR, .name="page", .value=12};
|
|
|
|
scm char_return = {CHAR, .name="return", .value=13};
|
|
|
|
scm char_space = {CHAR, .name="space", .value=32};
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
scm g_free = {NUMBER, .value=0};
|
|
|
|
scm *g_cells;
|
|
|
|
scm *g_news = 0;
|
2016-05-15 22:07:44 +00:00
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
#define CAR(x) g_cells[x].car
|
|
|
|
#define CDR(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
|
|
|
|
#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)))
|
|
|
|
#define CDADAR(x) CAR (CDR (CAR (CDR (x))))
|
|
|
|
#define CADR(x) CAR (CDR (x))
|
2016-05-28 14:39:44 +00:00
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
car (SCM x)
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
assert (TYPE (x) == PAIR);
|
|
|
|
return CAR (x);
|
2016-05-28 14:39:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
cdr (SCM x)
|
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
assert (TYPE (x) == PAIR);
|
|
|
|
return CDR (x);
|
2016-10-27 14:44:09 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
2016-10-27 14:44:09 +00:00
|
|
|
gc_alloc (int n)
|
|
|
|
{
|
|
|
|
assert (g_free.value + n < ARENA_SIZE);
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM x = g_free.value;
|
2016-10-27 14:44:09 +00:00
|
|
|
g_free.value += n;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM g_start;
|
2016-10-27 14:44:09 +00:00
|
|
|
scm *
|
2016-11-21 08:28:34 +00:00
|
|
|
gc_news ()
|
2016-10-27 14:44:09 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
g_news = (scm *)malloc (ARENA_SIZE*sizeof(scm));
|
|
|
|
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';
|
|
|
|
return g_news;
|
2016-10-27 14:44:09 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
gc ()
|
2016-10-27 14:44:09 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
fprintf (stderr, "***gc[%d]...", g_free.value);
|
|
|
|
g_free.value = 1;
|
|
|
|
if (!g_news)
|
|
|
|
gc_news ();
|
|
|
|
for (int i=g_free.value; i<g_start; i++)
|
|
|
|
gc_copy (i);
|
|
|
|
symbols = gc_copy (symbols);
|
|
|
|
SCM new = gc_copy (stack);
|
|
|
|
fprintf (stderr, "new=%d, start=%d\n", new, stack);
|
|
|
|
stack = new;
|
|
|
|
return gc_loop (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
gc_loop (SCM scan)
|
|
|
|
{
|
|
|
|
while (scan < g_free.value)
|
2016-10-27 14:44:09 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
if (NTYPE (scan) == MACRO
|
|
|
|
|| NTYPE (scan) == PAIR
|
|
|
|
|| NTYPE (scan) == REF
|
|
|
|
|| scan == 1
|
|
|
|
|| ((NTYPE (scan) == SPECIAL && TYPE (NCAR (scan)) == PAIR)
|
|
|
|
|| (NTYPE (scan) == STRING && TYPE (NCAR (scan)) == PAIR)
|
|
|
|
|| (NTYPE (scan) == SYMBOL && TYPE (NCAR (scan)) == PAIR)))
|
2016-10-27 14:44:09 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM car = gc_copy (g_news[scan].car);
|
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
|
|
|
gc_relocate_car (scan, car);
|
2016-10-27 14:44:09 +00:00
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
if ((NTYPE (scan) == MACRO
|
|
|
|
|| NTYPE (scan) == PAIR
|
|
|
|
|| NTYPE (scan) == VALUES)
|
|
|
|
&& g_news[scan].cdr) // allow for 0 terminated list of symbols
|
2016-10-27 14:44:09 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM cdr = gc_copy (g_news[scan].cdr);
|
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
|
|
|
gc_relocate_cdr (scan, cdr);
|
2016-10-27 14:44:09 +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
|
|
|
scan++;
|
2016-10-27 14:44:09 +00:00
|
|
|
}
|
|
|
|
return gc_flip ();
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
gc_copy (SCM old)
|
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
if (TYPE (old) == BROKEN_HEART) return g_cells[old].car;
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM new = g_free.value++;
|
|
|
|
g_news[new] = g_cells[old];
|
|
|
|
if (NTYPE (new) == VECTOR)
|
|
|
|
{
|
|
|
|
g_news[new].vector = g_free.value;
|
|
|
|
for (int i=0; i<LENGTH (old); i++)
|
|
|
|
g_news[g_free.value++] = g_cells[VECTOR (old)+i];
|
|
|
|
}
|
|
|
|
g_cells[old].type = BROKEN_HEART;
|
|
|
|
g_cells[old].car = new;
|
2016-10-27 14:44:09 +00:00
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
gc_relocate_car (SCM new, SCM car)
|
2016-10-27 14:44:09 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
g_news[new].car = car;
|
|
|
|
return cell_unspecified;
|
2016-10-27 14:44:09 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
gc_relocate_cdr (SCM new, SCM cdr)
|
2016-10-27 14:44:09 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
g_news[new].cdr = cdr;
|
|
|
|
return cell_unspecified;
|
2016-10-27 14:44:09 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
2016-10-27 14:44:09 +00:00
|
|
|
gc_flip ()
|
|
|
|
{
|
|
|
|
scm *cells = g_cells;
|
|
|
|
g_cells = g_news;
|
|
|
|
g_news = cells;
|
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
|
|
|
fprintf (stderr, " => jam[%d]\n", g_free.value);
|
2016-11-21 08:28:34 +00:00
|
|
|
return stack;
|
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
|
2016-10-27 14:44:09 +00:00
|
|
|
gc_show ()
|
|
|
|
{
|
|
|
|
fprintf (stderr, "cells: ");
|
2016-11-21 08:28:34 +00:00
|
|
|
scm *t = g_cells;
|
|
|
|
display_ (stderr, -1);
|
2016-10-27 14:44:09 +00:00
|
|
|
fprintf (stderr, "\n");
|
2016-11-21 08:28:34 +00:00
|
|
|
if (g_news)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "news: ");
|
|
|
|
g_cells = g_news;
|
|
|
|
display_ (stderr, -1);
|
|
|
|
fprintf (stderr, "\n");
|
|
|
|
}
|
|
|
|
g_cells = t;
|
|
|
|
return cell_unspecified;
|
2016-10-27 14:44:09 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM tmp;
|
|
|
|
SCM tmp_num;
|
|
|
|
SCM tmp_num2;
|
|
|
|
SCM tmp_num3;
|
|
|
|
SCM tmp_num4;
|
|
|
|
|
|
|
|
SCM
|
|
|
|
make_cell (SCM type, SCM car, SCM cdr)
|
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
SCM x = gc_alloc (1);
|
|
|
|
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:28:34 +00:00
|
|
|
SCM
|
|
|
|
eq_p (SCM x, SCM y)
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
Move optional type predicates to type.c.
* mes.c (char_p, macro_p, number_p, pair_p, string_p, symbol_p,
vector_p, builtin_p, boolean_p): Move to type.c
* type.c: New file.
* GNUmakefile (mes.o): Depend on type snarf output.
* module/mes/loop-0.mes (cond, map, let, or, and not, evlis-env,
apply-env, eval-expand, uquote, add-unquoters, eval,
expand-macro-env, eval-begin-env, eval-if-env, sexp:define,
env:define, env:macro): Move to mes-0.mes.
* module/mes/mes-0.mes: New file.
* module/mes/type-0.mes: New file.
* scripts/include.mes: If BOOT, also include mes-0.mes. If TYPE0,
also include type-0.mes.
2016-10-22 10:16:19 +00:00
|
|
|
return (x == y
|
2016-11-21 08:30:59 +00:00
|
|
|
|| (TYPE (x) == CHAR && TYPE (y) == CHAR
|
2016-11-21 08:28:34 +00:00
|
|
|
&& VALUE (x) == VALUE (y))
|
2016-11-21 08:30:59 +00:00
|
|
|
|| (TYPE (x) == NUMBER && TYPE (y) == NUMBER
|
2016-11-21 08:28:34 +00:00
|
|
|
&& VALUE (x) == VALUE (y)))
|
|
|
|
? cell_t : cell_f;
|
2016-05-28 14:39:44 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
assert (TYPE (x) == PAIR);
|
2016-11-21 08:28:34 +00:00
|
|
|
cache_invalidate (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-10-19 22:11:48 +00:00
|
|
|
cache_invalidate (x);
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM p = assert_defined (x, assq (x, a));
|
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
|
|
|
|
quote (SCM x)
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
return cons (cell_symbol_quote, x);
|
2016-05-28 14:39:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
quasiquote (SCM x)
|
2016-07-16 15:18:11 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
return cons (cell_symbol_quasiquote, x);
|
2016-07-16 15:18:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
quasisyntax (SCM x)
|
2016-10-21 20:44:50 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
return cons (cell_symbol_quasisyntax, x);
|
2016-10-21 20:44:50 +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-11-21 08:28:34 +00:00
|
|
|
if (pair_p (x) == cell_f)
|
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-11-21 08:28:34 +00:00
|
|
|
while (a != cell_nil && eq_p (x, CAAR (a)) == cell_f)
|
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:30:59 +00:00
|
|
|
if (TYPE (a) == BROKEN_HEART || TYPE (CAR (a)) == BROKEN_HEART)
|
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
|
|
|
fprintf (stderr, "oops, broken heart\n");
|
2016-11-21 08:30:59 +00:00
|
|
|
a = CDR (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-21 08:28:34 +00:00
|
|
|
return a != cell_nil ? car (a) : cell_f;
|
2016-10-19 22:11:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ENV_CACHE 1
|
2016-10-22 16:13:37 +00:00
|
|
|
#define CACHE_SIZE 30
|
2016-10-21 08:43:32 +00:00
|
|
|
#define ENV_HEAD 15
|
|
|
|
|
2016-10-19 22:11:48 +00:00
|
|
|
#if !ENV_CACHE
|
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 cache_invalidate (SCM x){}
|
|
|
|
SCM cache_invalidate_range (SCM p,SCM a){}
|
|
|
|
SCM cache_save (SCM p){}
|
|
|
|
SCM cache_lookup (SCM x){}
|
2016-10-19 22:11:48 +00:00
|
|
|
|
|
|
|
#else // ENV_CACHE
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM env_cache_cars[CACHE_SIZE];
|
|
|
|
SCM env_cache_cdrs[CACHE_SIZE];
|
2016-10-19 22:11:48 +00:00
|
|
|
int cache_threshold = 0;
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
cache_save (SCM p)
|
2016-10-19 22:11:48 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
int n = g_cells[car (p)].hits;
|
|
|
|
if (n < cache_threshold) return cell_unspecified;
|
2016-10-19 22:11:48 +00:00
|
|
|
int j = -1;
|
|
|
|
for (int i=0; i < CACHE_SIZE; i++) {
|
|
|
|
if (!env_cache_cars[i]) {
|
|
|
|
j = i;
|
|
|
|
break;
|
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
if (env_cache_cars[i] == car (p)) return cell_unspecified;
|
|
|
|
if (n > g_cells[env_cache_cars[i]].hits) {
|
|
|
|
n = g_cells[env_cache_cars[i]].hits;
|
2016-10-19 22:11:48 +00:00
|
|
|
j = i;
|
|
|
|
}
|
2016-10-12 19:14:06 +00:00
|
|
|
}
|
2016-10-19 22:11:48 +00:00
|
|
|
if (j >= 0) {
|
2016-11-21 08:28:34 +00:00
|
|
|
cache_threshold = g_cells[car (p)].hits;
|
|
|
|
env_cache_cars[j] = car (p);
|
|
|
|
env_cache_cdrs[j] = cdr (p);
|
2016-10-19 22:11:48 +00:00
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
return cell_unspecified;
|
2016-10-19 22:11:48 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
cache_lookup (SCM x)
|
2016-10-19 22:11:48 +00:00
|
|
|
{
|
|
|
|
for (int i=0; i < CACHE_SIZE; i++) {
|
|
|
|
if (!env_cache_cars[i]) break;
|
|
|
|
if (env_cache_cars[i] == x) return env_cache_cdrs[i];
|
2016-05-15 22:07:44 +00:00
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
return cell_undefined;
|
2016-10-19 22:11:48 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
cache_invalidate (SCM x)
|
2016-10-19 22:11:48 +00:00
|
|
|
{
|
|
|
|
for (int i=0; i < CACHE_SIZE; i++) {
|
|
|
|
if (env_cache_cars[i] == x) {
|
|
|
|
env_cache_cars[i] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
return cell_unspecified;
|
2016-05-28 14:39:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
cache_invalidate_range (SCM p, SCM a)
|
2016-10-19 22:11:48 +00:00
|
|
|
{
|
|
|
|
do {
|
2016-11-21 08:28:34 +00:00
|
|
|
cache_invalidate (caar (p));
|
|
|
|
p = cdr (p);
|
2016-10-19 22:11:48 +00:00
|
|
|
} while (p != a);
|
2016-11-21 08:28:34 +00:00
|
|
|
return cell_unspecified;
|
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
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
g_cells[x].hits++;
|
|
|
|
SCM c = cache_lookup (x);
|
|
|
|
if (c != cell_undefined) return c;
|
2016-10-19 22:21:06 +00:00
|
|
|
int i = 0;
|
2016-11-21 08:28:34 +00:00
|
|
|
while (a != cell_nil && x != CAAR (a)) {i++;a = cdr (a);}
|
|
|
|
if (a == cell_nil) return cell_undefined;
|
|
|
|
if (i>ENV_HEAD) cache_save (car (a));
|
|
|
|
return cdar (a);
|
2016-10-19 22:11:48 +00:00
|
|
|
}
|
|
|
|
#endif // ENV_CACHE
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
assert_defined (SCM x, SCM e)
|
2016-11-03 09:37:08 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
if (e == cell_undefined)
|
2016-11-03 09:37:08 +00:00
|
|
|
{
|
|
|
|
fprintf (stderr, "eval: unbound variable:");
|
2016-11-05 10:08:10 +00:00
|
|
|
display_ (stderr, x);
|
2016-11-03 09:37:08 +00:00
|
|
|
fprintf (stderr, "\n");
|
|
|
|
assert (!"unbound variable");
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
gc_frame (SCM stack)
|
|
|
|
{
|
|
|
|
SCM frame = car (stack);
|
|
|
|
r1 = car (frame);
|
|
|
|
r2 = cadr (frame);
|
|
|
|
r3 = caddr (frame);
|
|
|
|
r0 = cadddr (frame);
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
gc_stack (SCM a)
|
|
|
|
{
|
|
|
|
SCM frame = cons (r1, cons (r2, cons (r3, cons (r0, cell_nil))));
|
|
|
|
stack = cons (frame, stack);
|
|
|
|
stack = gc (stack);
|
|
|
|
gc_frame (stack);
|
|
|
|
stack = cdr (stack);
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
vm_call (function0_t f, SCM p1, SCM p2, SCM 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-21 08:28:34 +00:00
|
|
|
SCM frame = cons (r1, cons (r2, cons (r3, cons (r0, cell_nil))));
|
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
|
|
|
stack = cons (frame, stack);
|
|
|
|
r1 = p1;
|
|
|
|
r2 = p2;
|
|
|
|
r0 = a;
|
2016-11-21 08:28:34 +00:00
|
|
|
if (f == vm_if_env && g_free.value + GC_SAFETY > ARENA_SIZE)
|
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
|
|
|
cache_invalidate_range (r0, cell_nil);
|
|
|
|
gc_stack (stack);
|
|
|
|
frame = car (stack);
|
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 r = f ();
|
|
|
|
frame = gc_frame (stack);
|
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
|
|
|
stack = cdr (stack);
|
2016-11-21 08:28:34 +00:00
|
|
|
return r;
|
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
|
|
|
|
evlis_env (SCM m, SCM a)
|
2016-10-12 19:14:06 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
return vm_call (vm_evlis_env, m, cell_undefined, a);
|
2016-10-12 19:14:06 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
apply_env (SCM fn, SCM x, SCM a)
|
2016-05-28 14:39:44 +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
|
|
|
return vm_call (vm_apply_env, fn, x, a);
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
eval_env (SCM e, SCM 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-21 08:28:34 +00:00
|
|
|
return vm_call (vm_eval_env, e, cell_undefined, 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-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
expand_macro_env (SCM e, SCM 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-21 08:28:34 +00:00
|
|
|
return vm_call (vm_expand_macro_env, e, cell_undefined, 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-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
begin_env (SCM e, SCM 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-21 08:28:34 +00:00
|
|
|
return vm_call (vm_begin_env, e, cell_undefined, 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-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
if_env (SCM e, SCM 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-21 08:28:34 +00:00
|
|
|
return vm_call (vm_if_env, e, cell_undefined, 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-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;
|
|
|
|
r2 = a;
|
|
|
|
r3 = aa;
|
2016-11-21 08:30:59 +00:00
|
|
|
cache_invalidate_range (r0, CDR (r3));
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM r = vm_call_lambda ();
|
2016-11-21 08:30:59 +00:00
|
|
|
cache_invalidate_range (r0, CDR (r3));
|
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 r;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
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
|
|
|
vm_evlis_env ()
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
if (r1 == cell_nil) return cell_nil;
|
2016-11-21 08:30:59 +00:00
|
|
|
if (TYPE (r1) != PAIR) return eval_env (r1, 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
|
|
|
r2 = eval_env (car (r1), r0);
|
|
|
|
r1 = evlis_env (cdr (r1), r0);
|
|
|
|
return cons (r2, r1);
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
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
|
|
|
vm_call_lambda ()
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
return vm_call (vm_begin_env, r1, cell_undefined, 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-21 08:28:34 +00:00
|
|
|
SCM
|
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
|
|
|
vm_apply_env ()
|
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
if (TYPE (r1) != PAIR)
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
if (TYPE (r1) == FUNCTION) return call (r1, r2);
|
2016-11-21 08:28:34 +00:00
|
|
|
if (r1 == cell_symbol_call_with_values)
|
|
|
|
return call_with_values_env (car (r2), cadr (r2), r0);
|
|
|
|
if (r1 == cell_symbol_current_module) return r0;
|
2016-05-28 14:39:44 +00:00
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
else if (car (r1) == cell_symbol_lambda) {
|
|
|
|
SCM args = cadr (r1);
|
|
|
|
SCM body = cddr (r1);
|
|
|
|
SCM p = pairlis (args, r2, 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
|
|
|
return call_lambda (body, p, p, r0);
|
|
|
|
// r2 = p;
|
2016-11-21 08:28:34 +00:00
|
|
|
// cache_invalidate_range (r2, g_cells[r0].cdr);
|
|
|
|
// SCM r = begin_env (cddr (r1), cons (cons (cell_closure, p), p));
|
|
|
|
// cache_invalidate_range (r2, g_cells[r0].cdr);
|
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 r;
|
2016-07-23 22:01:31 +00:00
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
else if (car (r1) == cell_closure) {
|
|
|
|
SCM args = caddr (r1);
|
|
|
|
SCM body = cdddr (r1);
|
|
|
|
SCM aa = cdadr (r1);
|
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
|
|
|
aa = cdr (aa);
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM p = pairlis (args, r2, aa);
|
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 call_lambda (body, p, aa, r0);
|
|
|
|
// r2 = p;
|
|
|
|
// r3 = aa;
|
2016-11-21 08:28:34 +00:00
|
|
|
// cache_invalidate_range (r2, g_cells[r3].cdr);
|
|
|
|
// SCM r = begin_env (body, cons (cons (cell_closure, p), p));
|
|
|
|
// cache_invalidate_range (r2, g_cells[r3].cdr);
|
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 r;
|
2016-07-19 19:37:39 +00:00
|
|
|
}
|
2016-10-20 16:43:33 +00:00
|
|
|
#if BOOT
|
2016-11-21 08:28:34 +00:00
|
|
|
else if (car (r1) == cell_symbol_label)
|
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 apply_env (caddr (r1), r2, cons (cons (cadr (r1), caddr (r1)), r0));
|
2016-10-20 16:43:33 +00:00
|
|
|
#endif
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM e = eval_env (r1, r0);
|
2016-11-05 14:33:16 +00:00
|
|
|
char const* type = 0;
|
2016-11-21 08:28:34 +00:00
|
|
|
if (e == cell_f || e == cell_t) type = "bool";
|
2016-11-21 08:30:59 +00:00
|
|
|
if (TYPE (e) == CHAR) type = "char";
|
|
|
|
if (TYPE (e) == NUMBER) type = "number";
|
|
|
|
if (TYPE (e) == STRING) type = "string";
|
2016-11-21 08:28:34 +00:00
|
|
|
if (e == cell_unspecified) type = "*unspecified*";
|
|
|
|
if (e == cell_undefined) type = "*undefined*";
|
2016-11-05 14:33:16 +00:00
|
|
|
if (type)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "cannot apply: %s: ", type);
|
|
|
|
display_ (stderr, e);
|
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
|
|
|
fprintf (stderr, " [");
|
|
|
|
display_ (stderr, r1);
|
|
|
|
fprintf (stderr, "]\n");
|
2016-11-05 14:33:16 +00:00
|
|
|
assert (!"cannot 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
|
|
|
return apply_env (e, r2, r0);
|
2016-05-28 14:39:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM cstring_to_list (char const* s);
|
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
|
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
|
|
|
vm_eval_env ()
|
2016-07-24 11:27:05 +00:00
|
|
|
{
|
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-11-21 08:28:34 +00:00
|
|
|
if (car (r1) == cell_symbol_quote)
|
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 cadr (r1);
|
2016-10-30 15:01:34 +00:00
|
|
|
#if QUASISYNTAX
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (r1) == cell_symbol_syntax)
|
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 r1;
|
2016-10-30 15:01:34 +00:00
|
|
|
#endif
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (r1) == cell_symbol_begin)
|
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 begin_env (r1, r0);
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (r1) == cell_symbol_lambda)
|
|
|
|
return make_closure (cadr (r1), cddr (r1), assq (cell_closure, r0));
|
|
|
|
if (car (r1) == cell_closure)
|
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 r1;
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (r1) == cell_symbol_if)
|
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 if_env (cdr (r1), r0);
|
2016-10-20 16:43:33 +00:00
|
|
|
#if !BOOT
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (r1) == cell_symbol_define)
|
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 define_env (r1, r0);
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (r1) == cell_symbol_define_macro)
|
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 define_env (r1, r0);
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (r1) == cell_symbol_primitive_load)
|
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 load_env (r0);
|
2016-10-20 16:43:33 +00:00
|
|
|
#else
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (r1) == cell_symbol_define) {
|
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
|
|
|
fprintf (stderr, "C DEFINE: ");
|
|
|
|
display_ (stderr,
|
2016-11-21 08:30:59 +00:00
|
|
|
TYPE (cadr (r1)) == SYMBOL
|
|
|
|
? STRING (cadr (r1))
|
|
|
|
: STRING (caadr (r1)));
|
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
|
|
|
fprintf (stderr, "\n");
|
2016-10-20 16:43:33 +00:00
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
assert (car (r1) != cell_symbol_define);
|
|
|
|
assert (car (r1) != cell_symbol_define_macro);
|
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
|
|
|
#endif
|
|
|
|
#if 1 //!BOOT
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (r1) == cell_symbol_set_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
|
|
|
return set_env_x (cadr (r1), eval_env (caddr (r1), r0), r0);
|
|
|
|
#else
|
2016-11-21 08:28:34 +00:00
|
|
|
assert (car (r1) != cell_symbol_set_x);
|
2016-10-20 16:43:33 +00:00
|
|
|
#endif
|
2016-10-22 17:26:12 +00:00
|
|
|
#if QUASIQUOTE
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (r1) == cell_symbol_unquote)
|
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 eval_env (cadr (r1), r0);
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (r1) == cell_symbol_quasiquote)
|
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 eval_quasiquote (cadr (r1), add_unquoters (r0));
|
2016-10-30 15:01:34 +00:00
|
|
|
#endif //QUASIQUOTE
|
|
|
|
#if QUASISYNTAX
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (r1) == cell_symbol_unsyntax)
|
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 eval_env (cadr (r1), r0);
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (r1) == cell_symbol_quasisyntax)
|
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 eval_quasisyntax (cadr (r1), add_unsyntaxers (r0));
|
2016-10-30 15:01:34 +00:00
|
|
|
#endif //QUASISYNTAX
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM x = expand_macro_env (r1, 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
|
|
|
if (x != r1)
|
|
|
|
return eval_env (x, r0);
|
2016-11-21 08:30:59 +00:00
|
|
|
SCM m = evlis_env (CDR (r1), r0);
|
2016-11-21 08:28:34 +00:00
|
|
|
return apply_env (car (r1), m, r0);
|
2016-11-03 20:43:01 +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
|
|
|
case SYMBOL: return assert_defined (r1, assq_ref_cache (r1, r0));
|
|
|
|
default: return r1;
|
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
|
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
|
|
|
vm_expand_macro_env ()
|
2016-10-16 07:44:52 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
if (TYPE (CAR (r1)) == STRING && string_to_symbol (CAR (r1)) == cell_symbol_noexpand)
|
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 cadr (r1);
|
2016-11-03 09:39:22 +00:00
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM macro;
|
|
|
|
SCM expanders;
|
|
|
|
if (TYPE (r1) == PAIR
|
|
|
|
&& (macro = lookup_macro (car (r1), r0)) != cell_f)
|
|
|
|
return apply_env (macro, CDR (r1), r0);
|
|
|
|
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-11-21 08:28:34 +00:00
|
|
|
SCM sc_expand = assq_ref_cache (cell_symbol_expand_macro, r0);
|
|
|
|
if (sc_expand != cell_undefined && sc_expand != cell_f)
|
|
|
|
r1 = apply_env (sc_expand, cons (r1, cell_nil), r0);
|
2016-10-30 15:16:20 +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
|
|
|
return r1;
|
2016-10-30 15:16:20 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
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
|
|
|
vm_begin_env ()
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM r = cell_unspecified;
|
|
|
|
while (r1 != cell_nil) {
|
2016-11-21 08:30:59 +00:00
|
|
|
if (TYPE (r1) == PAIR && TYPE (CAR (r1)) == PAIR && caar (r1) == cell_symbol_begin)
|
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 = append2 (cdar (r1), cdr (r1));
|
2016-11-21 08:28:34 +00:00
|
|
|
r = eval_env (car (r1), r0);
|
2016-11-21 08:30:59 +00:00
|
|
|
r1 = CDR (r1);
|
2016-05-15 22:07:44 +00:00
|
|
|
}
|
2016-10-12 19:14:06 +00:00
|
|
|
return r;
|
2016-05-29 11:44:03 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
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
|
|
|
vm_if_env ()
|
2016-07-27 06:49:45 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM x = eval_env (car (r1), r0);
|
|
|
|
if (x != cell_f)
|
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 eval_env (cadr (r1), r0);
|
2016-11-21 08:28:34 +00:00
|
|
|
if (cddr (r1) != cell_nil)
|
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 eval_env (caddr (r1), r0);
|
2016-11-21 08:28:34 +00:00
|
|
|
return cell_unspecified;
|
2016-07-27 06:49:45 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
call (SCM fn, SCM x)
|
|
|
|
{
|
2016-11-19 21:31:30 +00:00
|
|
|
if ((FUNCTION (fn).arity > 0 || FUNCTION (fn).arity == -1)
|
2016-11-21 08:28:34 +00:00
|
|
|
&& x != cell_nil && TYPE (CAR (x)) == VALUES)
|
|
|
|
x = cons (CADAR (x), CDR (x));
|
2016-11-19 21:31:30 +00:00
|
|
|
if ((FUNCTION (fn).arity > 1 || FUNCTION (fn).arity == -1)
|
2016-11-21 08:28:34 +00:00
|
|
|
&& x != cell_nil && TYPE (CDR (x)) == PAIR && TYPE (CADR (x)) == VALUES)
|
|
|
|
x = cons (CAR (x), cons (CDADAR (x), CDR (x)));
|
2016-11-19 21:31:30 +00:00
|
|
|
switch (FUNCTION (fn).arity)
|
2016-11-03 20:28:05 +00:00
|
|
|
{
|
2016-11-19 21:31:30 +00:00
|
|
|
case 0: return FUNCTION (fn).function0 ();
|
|
|
|
case 1: return FUNCTION (fn).function1 (car (x));
|
|
|
|
case 2: return FUNCTION (fn).function2 (car (x), cadr (x));
|
|
|
|
case 3: return FUNCTION (fn).function3 (car (x), cadr (x), caddr (x));
|
|
|
|
case -1: return FUNCTION (fn).functionn (x);
|
2016-11-03 20:28:05 +00:00
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
return cell_unspecified;
|
2016-05-28 14:39:44 +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-07-11 19:50:59 +00:00
|
|
|
return append2 (car (x), append (cdr (x)));
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
2016-07-10 22:15:28 +00:00
|
|
|
make_char (int x)
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
g_cells[tmp_num].value = CHAR;
|
|
|
|
g_cells[tmp_num2].value = x;
|
|
|
|
return make_cell (tmp_num, tmp_num2, tmp_num2);
|
2016-07-10 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
2016-11-19 21:31:30 +00:00
|
|
|
SCM
|
|
|
|
make_function (SCM name, SCM id, SCM arity)
|
|
|
|
{
|
|
|
|
g_cells[tmp_num3].value = FUNCTION;
|
|
|
|
// function fun_read_byte = {.function0=&read_byte, .arity=0};
|
|
|
|
// scm scm_read_byte = {FUNCTION, .name="read-int", .function=&fun_read_byte};
|
|
|
|
// SCM cell_read_byte = 93;
|
|
|
|
function *f = (function*)malloc (sizeof (function));
|
|
|
|
f->arity = VALUE (arity);
|
|
|
|
g_cells[tmp_num4].value = (long)f;
|
|
|
|
return make_cell (tmp_num3, name, tmp_num4);
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
make_macro (SCM name, SCM x)
|
2016-07-22 15:13:51 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
g_cells[tmp_num].value = MACRO;
|
|
|
|
return make_cell (tmp_num, STRING (name), x);
|
2016-07-22 15:13:51 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
2016-07-10 20:43:23 +00:00
|
|
|
make_number (int x)
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
g_cells[tmp_num].value = NUMBER;
|
|
|
|
g_cells[tmp_num2].value = x;
|
|
|
|
return make_cell (tmp_num, tmp_num2, tmp_num2);
|
2016-07-10 20:43:23 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
make_ref (SCM 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
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
g_cells[tmp_num].value = REF;
|
|
|
|
return make_cell (tmp_num, x, 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
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
make_string (SCM x)
|
2016-07-10 20:43:23 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
g_cells[tmp_num].value = STRING;
|
|
|
|
return make_cell (tmp_num, x, 0);
|
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
|
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--)
|
|
|
|
p = cons (make_char (s[i]), p);
|
2016-05-28 14:39:44 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
list_of_char_equal_p (SCM a, SCM b)
|
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:30:59 +00:00
|
|
|
while (a != cell_nil && b != cell_nil && VALUE (car (a)) == VALUE (car (b))) {
|
|
|
|
assert (TYPE (car (a)) == CHAR);
|
|
|
|
assert (TYPE (car (b)) == CHAR);
|
2016-11-21 08:28:34 +00:00
|
|
|
a = cdr (a);
|
|
|
|
b = cdr (b);
|
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
|
|
|
return (a == cell_nil && b == cell_nil) ? cell_t : cell_f;
|
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
|
|
|
|
internal_lookup_symbol (SCM s)
|
2016-10-08 06:41:30 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM x = symbols;
|
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
|
|
|
while (x) {
|
2016-10-26 17:44:36 +00:00
|
|
|
// .string and .name is the same field; .name is used as a handy
|
|
|
|
// static field initializer. A string can only be mistaken for a
|
|
|
|
// cell with type == PAIR for the one character long, zero-padded
|
|
|
|
// #\etx.
|
2016-11-21 08:30:59 +00:00
|
|
|
SCM p = STRING (car (x));
|
|
|
|
if (p < 0 || p >= g_free.value || TYPE (p) != PAIR)
|
|
|
|
STRING (car (x)) = cstring_to_list (NAME (car (x)));
|
|
|
|
if (list_of_char_equal_p (STRING (car (x)), s) == cell_t) break;
|
2016-11-21 08:28:34 +00:00
|
|
|
x = cdr (x);
|
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
|
|
|
if (x) x = car (x);
|
2016-10-08 06:41:30 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
internal_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-10-08 06:41:30 +00:00
|
|
|
symbols = cons (x, symbols);
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
make_symbol (SCM s)
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM x = internal_lookup_symbol (s);
|
2016-10-08 06:41:30 +00:00
|
|
|
return x ? x : internal_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:30:59 +00:00
|
|
|
SCM v = gc_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-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
|
|
|
|
call_with_values_env (SCM producer, SCM consumer, SCM a)
|
2016-07-11 17:32:11 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM v = apply_env (producer, cell_nil, a);
|
2016-11-21 08:30:59 +00:00
|
|
|
if (TYPE (v) == VALUES)
|
|
|
|
v = CDR (v);
|
2016-07-18 20:43:16 +00:00
|
|
|
return apply_env (consumer, v, a);
|
2016-07-11 17:32:11 +00:00
|
|
|
}
|
|
|
|
|
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-11-21 08:28:34 +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;
|
|
|
|
if (TYPE (e) == CHAR) e = make_char (VALUE (e));
|
|
|
|
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-11-21 08:30:59 +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-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
lookup (SCM s, SCM a)
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
if (isdigit (VALUE (car (s))) || (VALUE (car (s)) == '-' && cdr (s) != cell_nil)) {
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM p = s;
|
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
|
|
|
int sign = 1;
|
2016-11-21 08:30:59 +00:00
|
|
|
if (VALUE (car (s)) == '-') {
|
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
|
|
|
sign = -1;
|
2016-11-21 08:28:34 +00:00
|
|
|
p = cdr (s);
|
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
|
|
|
}
|
|
|
|
int n = 0;
|
2016-11-21 08:30:59 +00:00
|
|
|
while (p != cell_nil && isdigit (VALUE (car (p)))) {
|
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
|
|
|
n *= 10;
|
2016-11-21 08:30:59 +00:00
|
|
|
n += VALUE (car (p)) - '0';
|
2016-11-21 08:28:34 +00:00
|
|
|
p = cdr (p);
|
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
|
|
|
if (p == cell_nil) return make_number (n * sign);
|
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 x = internal_lookup_symbol (s);
|
2016-10-08 06:41:30 +00:00
|
|
|
if (x) return x;
|
2016-07-23 22:40:37 +00:00
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
if (cdr (s) == cell_nil) {
|
2016-11-21 08:30:59 +00:00
|
|
|
if (VALUE (car (s)) == '\'') return cell_symbol_quote;
|
|
|
|
if (VALUE (car (s)) == '`') return cell_symbol_quasiquote;
|
|
|
|
if (VALUE (car (s)) == ',') return cell_symbol_unquote;
|
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
|
|
|
else if (cddr (s) == cell_nil) {
|
2016-11-21 08:30:59 +00:00
|
|
|
if (VALUE (car (s)) == ',' && VALUE (cadr (s)) == '@') return cell_symbol_unquote_splicing;
|
|
|
|
if (VALUE (car (s)) == '#' && VALUE (cadr (s)) == '\'') return cell_symbol_syntax;
|
|
|
|
if (VALUE (car (s)) == '#' && VALUE (cadr (s)) == '`') return cell_symbol_quasisyntax;
|
|
|
|
if (VALUE (car (s)) == '#' && VALUE (cadr (s)) == ',') return cell_symbol_unsyntax;
|
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
|
|
|
else if (cdddr (s) == cell_nil) {
|
2016-11-21 08:30:59 +00:00
|
|
|
if (VALUE (car (s)) == '#' && VALUE (cadr (s)) == ',' && VALUE (caddr (s)) == '@') return cell_symbol_unsyntax_splicing;
|
|
|
|
if (VALUE (car (s)) == 'E' && VALUE (cadr (s)) == 'O' && VALUE (caddr (s)) == 'F') {
|
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
|
|
|
fprintf (stderr, "mes: got EOF\n");
|
2016-11-21 08:28:34 +00:00
|
|
|
return cell_nil; // `EOF': eval program, which may read stdin
|
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-07-24 16:28:45 +00:00
|
|
|
}
|
2016-07-27 06:49:45 +00:00
|
|
|
|
2016-10-08 06:41:30 +00:00
|
|
|
return internal_make_symbol (s);
|
2016-05-29 11:44:03 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
lookup_char (int c, SCM a)
|
2016-07-09 12:29:39 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
return lookup (cons (make_char (c), cell_nil), a);
|
2016-07-09 12:29:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
list_to_vector (SCM x)
|
2016-07-11 08:38:02 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
g_cells[tmp_num].value = VALUE (length (x));
|
|
|
|
SCM v = make_vector (tmp_num);
|
|
|
|
SCM p = VECTOR (v);
|
|
|
|
while (x != cell_nil)
|
2016-07-11 08:38:02 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
g_cells[p++] = g_cells[vector_entry (car (x))];
|
2016-07-11 08:38:02 +00:00
|
|
|
x = cdr (x);
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
2016-11-21 08:30:59 +00:00
|
|
|
force_output (SCM p) ///((arity . n))
|
2016-05-15 22:07:44 +00:00
|
|
|
{
|
2016-08-12 12:17:20 +00:00
|
|
|
int fd = 1;
|
2016-11-21 08:30:59 +00:00
|
|
|
if (TYPE (p) == PAIR && TYPE (car (p)) == NUMBER) fd = VALUE (car (p));
|
2016-08-12 12:17:20 +00:00
|
|
|
FILE *f = fd == 1 ? stdout : stderr;
|
2016-11-21 08:30:59 +00:00
|
|
|
fflush (f);
|
2016-05-28 14:39:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
2016-11-21 08:30:59 +00:00
|
|
|
display_ (FILE* f, SCM x)
|
2016-10-16 07:44:52 +00:00
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
return display_helper (f, x, false, "", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
display (SCM x) ///((arity . n))
|
|
|
|
{
|
|
|
|
SCM e = car (x);
|
|
|
|
SCM p = cdr (x);
|
2016-10-16 07:44:52 +00:00
|
|
|
int fd = 1;
|
2016-11-21 08:30:59 +00:00
|
|
|
if (TYPE (p) == PAIR && TYPE (car (p)) == NUMBER) fd = HITS (car (p));
|
2016-10-16 07:44:52 +00:00
|
|
|
FILE *f = fd == 1 ? stdout : stderr;
|
2016-11-21 08:30:59 +00:00
|
|
|
return display_helper (f, e, false, "", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
newline (SCM p) ///((arity . n))
|
|
|
|
{
|
|
|
|
int fd = 1;
|
|
|
|
if (TYPE (p) == PAIR && TYPE (car (p)) == NUMBER) fd = VALUE (car (p));
|
|
|
|
FILE *f = fd == 1 ? stdout : stderr;
|
|
|
|
fputs ("\n", f);
|
|
|
|
return cell_unspecified;
|
2016-10-16 07:44:52 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
display_helper (FILE* f, SCM x, bool cont, char const *sep, bool quote)
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM r;
|
2016-08-12 12:17:20 +00:00
|
|
|
fprintf (f, "%s", sep);
|
2016-11-21 08:30:59 +00:00
|
|
|
switch (TYPE (x))
|
2016-11-03 21:11:18 +00:00
|
|
|
{
|
|
|
|
case CHAR:
|
|
|
|
{
|
|
|
|
char const *name = 0;
|
2016-11-21 08:30:59 +00:00
|
|
|
if (VALUE (x) == char_nul.value) name = char_nul.name;
|
|
|
|
else if (VALUE (x) == char_backspace.value) name = char_backspace.name;
|
|
|
|
else if (VALUE (x) == char_tab.value) name = char_tab.name;
|
|
|
|
else if (VALUE (x) == char_newline.value) name = char_newline.name;
|
|
|
|
else if (VALUE (x) == char_vt.value) name = char_vt.name;
|
|
|
|
else if (VALUE (x) == char_page.value) name = char_page.name;
|
|
|
|
else if (VALUE (x) == char_return.value) name = char_return.name;
|
|
|
|
else if (VALUE (x) == char_space.value) name = char_space.name;
|
2016-11-03 21:11:18 +00:00
|
|
|
if (name) fprintf (f, "#\\%s", name);
|
2016-11-21 08:30:59 +00:00
|
|
|
else fprintf (f, "#\\%c", VALUE (x));
|
2016-11-03 21:11:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MACRO:
|
|
|
|
fprintf (f, "(*macro* ");
|
2016-11-21 08:28:34 +00:00
|
|
|
display_helper (f, g_cells[x].macro, cont, sep, quote);
|
2016-11-03 21:11:18 +00:00
|
|
|
fprintf (f, ")");
|
|
|
|
break;
|
2016-11-21 08:30:59 +00:00
|
|
|
case NUMBER: fprintf (f, "%d", VALUE (x)); break;
|
2016-11-03 21:11:18 +00:00
|
|
|
case PAIR:
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (x) == cell_circular) {
|
2016-11-03 21:11:18 +00:00
|
|
|
fprintf (f, "(*circ* . #-1#)");
|
2016-11-21 08:28:34 +00:00
|
|
|
return cell_unspecified;
|
2016-11-03 21:11:18 +00:00
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (x) == cell_closure) {
|
2016-11-03 21:11:18 +00:00
|
|
|
fprintf (f, "(*closure* . #-1#)");
|
2016-11-21 08:28:34 +00:00
|
|
|
return cell_unspecified;
|
2016-11-03 21:11:18 +00:00
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
if (car (x) == cell_symbol_quote) {
|
2016-11-03 21:11:18 +00:00
|
|
|
fprintf (f, "'");
|
|
|
|
return display_helper (f, car (cdr (x)), cont, "", true);
|
|
|
|
}
|
|
|
|
if (!cont) fprintf (f, "(");
|
|
|
|
display_ (f, car (x));
|
2016-11-21 08:30:59 +00:00
|
|
|
if (cdr (x) && TYPE (cdr (x)) == PAIR)
|
2016-11-03 21:11:18 +00:00
|
|
|
display_helper (f, cdr (x), true, " ", false);
|
2016-11-21 08:28:34 +00:00
|
|
|
else if (cdr (x) != cell_nil) {
|
2016-11-03 21:11:18 +00:00
|
|
|
fprintf (f, " . ");
|
|
|
|
display_ (f, cdr (x));
|
|
|
|
}
|
|
|
|
if (!cont) fprintf (f, ")");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VECTOR:
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
fprintf (f, "#(");
|
|
|
|
for (int i = 0; i < LENGTH (x); i++) {
|
2016-11-21 08:30:59 +00:00
|
|
|
if (TYPE (VECTOR (x)+i) == VECTOR
|
|
|
|
|| (TYPE (VECTOR (x)+i) == REF
|
|
|
|
&& TYPE (REF (VECTOR (x)+i)) == VECTOR))
|
2016-11-03 21:11:18 +00:00
|
|
|
fprintf (f, "%s#(...)", i ? " " : "");
|
|
|
|
else
|
2016-11-21 08:28:34 +00:00
|
|
|
display_helper (f,VECTOR (x)+i, false, i ? " " : "", false);
|
2016-11-03 21:11:18 +00:00
|
|
|
}
|
|
|
|
fprintf (f, ")");
|
|
|
|
break;
|
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
case REF: display_helper (f, g_cells[x].ref, cont, "", true); break;
|
2016-11-19 21:31:30 +00:00
|
|
|
case FUNCTION:
|
|
|
|
{
|
|
|
|
fprintf (f, "#<procedure ");
|
2016-11-21 08:30:59 +00:00
|
|
|
SCM p = STRING (x);
|
|
|
|
if (p < 0 || p >= g_free.value || TYPE (p) != PAIR)
|
|
|
|
fprintf (f, "%s", NAME (x));
|
2016-11-19 21:31:30 +00:00
|
|
|
else
|
2016-11-21 08:30:59 +00:00
|
|
|
display_ (f, STRING (x));
|
2016-11-19 21:31:30 +00:00
|
|
|
fprintf (f, ">");
|
|
|
|
break;
|
|
|
|
}
|
2016-10-27 14:44:09 +00:00
|
|
|
case BROKEN_HEART: fprintf (f, "<3"); break;
|
2016-11-03 21:11:18 +00:00
|
|
|
default:
|
2016-11-21 08:28:34 +00:00
|
|
|
if (STRING (x))
|
2016-11-03 21:11:18 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM p = STRING (x);
|
2016-11-03 21:11:18 +00:00
|
|
|
assert (p);
|
2016-11-21 08:28:34 +00:00
|
|
|
while (p != cell_nil) {
|
2016-11-21 08:30:59 +00:00
|
|
|
assert (TYPE (car (p)) == CHAR);
|
|
|
|
fputc (VALUE (car (p)), f);
|
2016-11-21 08:28:34 +00:00
|
|
|
p = cdr (p);
|
2016-11-03 21:11:18 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-21 08:30:59 +00:00
|
|
|
else if (TYPE (x) != PAIR && NAME (x)) fprintf (f, "%s", NAME (x));
|
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
|
|
|
return cell_unspecified;
|
2016-05-28 14:39:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// READ
|
2016-05-29 11:44:03 +00:00
|
|
|
|
2016-11-02 17:25:18 +00:00
|
|
|
FILE *g_stdin;
|
|
|
|
int
|
|
|
|
getchar ()
|
|
|
|
{
|
|
|
|
return getc (g_stdin);
|
|
|
|
}
|
|
|
|
|
2016-05-28 14:39:44 +00:00
|
|
|
int
|
2016-10-21 20:44:50 +00:00
|
|
|
ungetchar (int c)
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-11-02 17:25:18 +00:00
|
|
|
return ungetc (c, g_stdin);
|
2016-05-28 14:39:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-10-21 20:44:50 +00:00
|
|
|
peekchar ()
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
|
|
|
int c = getchar ();
|
|
|
|
ungetchar (c);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
2016-10-20 17:19:32 +00:00
|
|
|
peek_char ()
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-10-20 17:19:32 +00:00
|
|
|
return make_char (peekchar ());
|
2016-05-28 14:39:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
2016-07-24 16:28:45 +00:00
|
|
|
read_char ()
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-07-24 15:35:31 +00:00
|
|
|
return make_char (getchar ());
|
2016-05-28 14:39:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
write_char (SCM x) ///((arity . n))
|
2016-08-12 12:17:20 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM c = car (x);
|
|
|
|
SCM p = cdr (x);
|
2016-08-12 12:17:20 +00:00
|
|
|
int fd = 1;
|
2016-11-21 08:30:59 +00:00
|
|
|
if (TYPE (p) == PAIR && TYPE (car (p)) == NUMBER) fd = VALUE (car (p));
|
2016-08-12 12:17:20 +00:00
|
|
|
FILE *f = fd == 1 ? stdout : stderr;
|
2016-11-21 08:30:59 +00:00
|
|
|
assert (TYPE (c) == NUMBER || TYPE (c) == CHAR);
|
|
|
|
fputc (VALUE (c), f);
|
2016-08-12 12:17:20 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
unget_char (SCM c)
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-11-21 08:30:59 +00:00
|
|
|
assert (TYPE (c) == NUMBER || TYPE (c) == CHAR);
|
|
|
|
ungetchar (VALUE (c));
|
2016-05-28 14:39:44 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:30:59 +00:00
|
|
|
SCM
|
|
|
|
symbol_to_list (SCM x)
|
|
|
|
{
|
|
|
|
assert (TYPE (x) == SYMBOL);
|
|
|
|
return STRING (x);
|
|
|
|
}
|
|
|
|
|
2016-05-28 14:39:44 +00:00
|
|
|
int
|
|
|
|
readcomment (int c)
|
|
|
|
{
|
|
|
|
if (c == '\n') return c;
|
|
|
|
return readcomment (getchar ());
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
readblock (int c)
|
|
|
|
{
|
2016-10-20 17:19:32 +00:00
|
|
|
if (c == '!' && peekchar () == '#') return getchar ();
|
2016-05-28 14:39:44 +00:00
|
|
|
return readblock (getchar ());
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
readword (int c, SCM w, SCM a)
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
if (c == EOF && w == cell_nil) return cell_nil;
|
|
|
|
if (c == '\n' && w == cell_nil) return readword (getchar (), w, a);
|
2016-11-21 08:30:59 +00:00
|
|
|
if (c == '\n' && VALUE (car (w)) == '.' && cdr (w) == cell_nil) return cell_dot;
|
2016-05-15 22:07:44 +00:00
|
|
|
if (c == EOF || c == '\n') return lookup (w, a);
|
2016-05-28 14:39:44 +00:00
|
|
|
if (c == ' ') return readword ('\n', w, a);
|
2016-11-21 08:28:34 +00:00
|
|
|
if (c == '"' && w == cell_nil) return readstring ();
|
2016-07-10 20:43:23 +00:00
|
|
|
if (c == '"') {ungetchar (c); return lookup (w, a);}
|
2016-11-21 08:28:34 +00:00
|
|
|
if (c == '(' && w == cell_nil) return readlist (a);
|
2016-05-15 22:07:44 +00:00
|
|
|
if (c == '(') {ungetchar (c); return lookup (w, a);}
|
2016-11-21 08:28:34 +00:00
|
|
|
if (c == ')' && w == cell_nil) {ungetchar (c); return cell_nil;}
|
2016-05-15 22:07:44 +00:00
|
|
|
if (c == ')') {ungetchar (c); return lookup (w, a);}
|
2016-11-21 08:30:59 +00:00
|
|
|
if (c == ',' && peekchar () == '@') {getchar (); return cons (lookup (STRING (cell_symbol_unquote_splicing), a),
|
2016-10-20 17:19:32 +00:00
|
|
|
cons (readword (getchar (), w, a),
|
2016-11-21 08:28:34 +00:00
|
|
|
cell_nil));}
|
2016-07-09 12:29:39 +00:00
|
|
|
if ((c == '\''
|
|
|
|
|| c == '`'
|
2016-07-19 16:18:27 +00:00
|
|
|
|| c == ',')
|
2016-11-21 08:28:34 +00:00
|
|
|
&& w == cell_nil) {return cons (lookup_char (c, a),
|
2016-05-28 14:39:44 +00:00
|
|
|
cons (readword (getchar (), w, a),
|
2016-11-21 08:28:34 +00:00
|
|
|
cell_nil));}
|
|
|
|
if (c == '#' && peekchar () == ',' && w == cell_nil) {
|
2016-07-23 22:40:37 +00:00
|
|
|
getchar ();
|
2016-11-21 08:30:59 +00:00
|
|
|
if (peekchar () == '@'){getchar (); return cons (lookup (STRING (cell_symbol_unsyntax_splicing), a),
|
2016-07-23 22:40:37 +00:00
|
|
|
cons (readword (getchar (), w, a),
|
2016-11-21 08:28:34 +00:00
|
|
|
cell_nil));}
|
2016-11-21 08:30:59 +00:00
|
|
|
return cons (lookup (STRING (cell_symbol_unsyntax), a), cons (readword (getchar (), w, a), cell_nil));
|
2016-07-23 22:40:37 +00:00
|
|
|
}
|
2016-11-21 08:28:34 +00:00
|
|
|
if (c == '#' && (peekchar () == '\'' || peekchar () == '`') && w == cell_nil) {
|
2016-10-30 22:30:22 +00:00
|
|
|
c = getchar ();
|
2016-11-21 08:28:34 +00:00
|
|
|
return cons (lookup (cons (make_char ('#'), cons (make_char (c), cell_nil)), a),
|
|
|
|
cons (readword (getchar (), w, a), cell_nil));}
|
2016-07-24 16:28:45 +00:00
|
|
|
if (c == ';') {readcomment (c); return readword ('\n', w, a);}
|
2016-10-20 17:19:32 +00:00
|
|
|
if (c == '#' && peekchar () == 'x') {getchar (); return read_hex ();}
|
|
|
|
if (c == '#' && peekchar () == '\\') {getchar (); return read_character ();}
|
2016-11-21 08:28:34 +00:00
|
|
|
if (c == '#' && w == cell_nil && peekchar () == '(') {getchar (); return list_to_vector (readlist (a));}
|
2016-10-20 17:19:32 +00:00
|
|
|
if (c == '#' && peekchar () == '(') {ungetchar (c); return lookup (w, a);}
|
|
|
|
if (c == '#' && peekchar () == '!') {getchar (); readblock (getchar ()); return readword (getchar (), w, a);}
|
2016-11-21 08:28:34 +00:00
|
|
|
return readword (getchar (), append2 (w, cons (make_char (c), cell_nil)), a);
|
2016-05-28 14:39:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
2016-08-12 12:17:20 +00:00
|
|
|
read_hex ()
|
|
|
|
{
|
|
|
|
int n = 0;
|
2016-10-20 17:19:32 +00:00
|
|
|
int c = peekchar ();
|
2016-08-12 12:17:20 +00:00
|
|
|
while ((c >= '0' && c <= '9')
|
|
|
|
|| (c >= 'A' && c <= 'F')
|
|
|
|
|| (c >= 'a' && c <= 'f')) {
|
|
|
|
n <<= 4;
|
|
|
|
if (c >= 'a') n += c - 'a' + 10;
|
|
|
|
else if (c >= 'A') n += c - 'A' + 10;
|
|
|
|
else n+= c - '0';
|
|
|
|
getchar ();
|
2016-10-20 17:19:32 +00:00
|
|
|
c = peekchar ();
|
2016-08-12 12:17:20 +00:00
|
|
|
}
|
|
|
|
return make_number (n);
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
2016-07-24 16:28:45 +00:00
|
|
|
read_character ()
|
2016-07-10 22:15:28 +00:00
|
|
|
{
|
|
|
|
int c = getchar ();
|
|
|
|
if (c >= '0' && c <= '7'
|
2016-10-20 17:19:32 +00:00
|
|
|
&& peekchar () >= '0' && peekchar () <= '7') {
|
2016-07-10 22:15:28 +00:00
|
|
|
c = c - '0';
|
2016-10-20 17:19:32 +00:00
|
|
|
while (peekchar () >= '0' && peekchar () <= '7') {
|
2016-07-10 22:15:28 +00:00
|
|
|
c <<= 3;
|
|
|
|
c += getchar () - '0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c >= 'a' && c <= 'z'
|
2016-10-20 17:19:32 +00:00
|
|
|
&& peekchar () >= 'a' && peekchar () <= 'z') {
|
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
|
|
|
char buf[10];
|
2016-07-10 22:15:28 +00:00
|
|
|
char *p = buf;
|
|
|
|
*p++ = c;
|
2016-10-20 17:19:32 +00:00
|
|
|
while (peekchar () >= 'a' && peekchar () <= 'z') {
|
2016-07-10 22:15:28 +00:00
|
|
|
*p++ = getchar ();
|
|
|
|
}
|
|
|
|
*p = 0;
|
2016-07-24 21:41:16 +00:00
|
|
|
if (!strcmp (buf, char_nul.name)) c = char_nul.value;
|
|
|
|
else if (!strcmp (buf, char_backspace.name)) c = char_backspace.value;
|
|
|
|
else if (!strcmp (buf, char_tab.name)) c = char_tab.value;
|
|
|
|
else if (!strcmp (buf, char_newline.name)) c = char_newline.value;
|
|
|
|
else if (!strcmp (buf, char_vt.name)) c = char_vt.value;
|
|
|
|
else if (!strcmp (buf, char_page.name)) c = char_page.value;
|
|
|
|
else if (!strcmp (buf, char_return.name)) c = char_return.value;
|
|
|
|
else if (!strcmp (buf, char_space.name)) c = char_space.value;
|
2016-07-10 22:15:28 +00:00
|
|
|
else {
|
2016-07-24 10:06:05 +00:00
|
|
|
fprintf (stderr, "char not supported: %s\n", buf);
|
2016-07-10 22:15:28 +00:00
|
|
|
assert (!"char not supported");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return make_char (c);
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
append_char (SCM x, int i)
|
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
|
|
|
return append2 (x, cons (make_char (i), cell_nil));
|
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-07-10 20:43:23 +00:00
|
|
|
readstring ()
|
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM p = cell_nil;
|
2016-07-10 20:43:23 +00:00
|
|
|
int c = getchar ();
|
|
|
|
while (true) {
|
|
|
|
if (c == '"') break;
|
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
|
|
|
if (c == '\\' && peekchar () == '"') p = append_char (p, getchar ());
|
|
|
|
else if (c == '\\' && peekchar () == 'n') {getchar (); p = append_char (p, '\n');}
|
2016-08-13 16:42:11 +00:00
|
|
|
else if (c == EOF) assert (!"EOF in string");
|
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
|
|
|
else p = append_char (p, c);
|
2016-07-10 20:43:23 +00:00
|
|
|
c = getchar ();
|
|
|
|
}
|
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
|
|
|
return make_string (p);
|
2016-07-10 20:43:23 +00:00
|
|
|
}
|
|
|
|
|
2016-07-09 16:56:59 +00:00
|
|
|
int
|
|
|
|
eat_whitespace (int c)
|
|
|
|
{
|
2016-07-24 10:06:05 +00:00
|
|
|
while (c == ' ' || c == '\t' || c == '\n') c = getchar ();
|
2016-07-09 16:56:59 +00:00
|
|
|
if (c == ';') return eat_whitespace (readcomment (c));
|
2016-10-20 17:19:32 +00:00
|
|
|
if (c == '#' && peekchar () == '!') {getchar (); readblock (getchar ()); return eat_whitespace (getchar ());}
|
2016-07-09 16:56:59 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
readlist (SCM a)
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
|
|
|
int c = getchar ();
|
2016-07-09 16:56:59 +00:00
|
|
|
c = eat_whitespace (c);
|
2016-11-21 08:28:34 +00:00
|
|
|
if (c == ')') return cell_nil;
|
|
|
|
SCM w = readword (c, cell_nil, a);
|
|
|
|
if (w == cell_dot)
|
2016-07-11 08:38:02 +00:00
|
|
|
return car (readlist (a));
|
|
|
|
return cons (w, readlist (a));
|
2016-05-28 14:39:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
read_env (SCM a)
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
return readword (getchar (), cell_nil, a);
|
2016-05-28 14:39:44 +00:00
|
|
|
}
|
2016-05-29 11:44:03 +00:00
|
|
|
|
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
|
|
|
|
add_environment (SCM a, char const *name, SCM x)
|
2016-05-15 22:07:44 +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
|
|
|
return acons (make_symbol (cstring_to_list (name)), x, a);
|
2016-05-15 22:07:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
2016-10-21 20:44:50 +00:00
|
|
|
mes_environment () ///((internal))
|
2016-05-15 22:07:44 +00:00
|
|
|
{
|
2016-10-27 14:44:09 +00:00
|
|
|
// setup GC
|
2016-11-21 08:28:34 +00:00
|
|
|
g_cells = (scm *)malloc (ARENA_SIZE*sizeof(scm));
|
2016-10-27 14:44:09 +00:00
|
|
|
g_cells[0].type = VECTOR;
|
|
|
|
g_cells[0].length = ARENA_SIZE - 1;
|
2016-11-21 08:28:34 +00:00
|
|
|
g_cells[0].length = 10;
|
|
|
|
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++;
|
|
|
|
// a = add_environment (a, "%free", &g_free); hihi, gets <3 moved
|
|
|
|
// a = add_environment (a, "%the-cells", g_cells);
|
|
|
|
// a = add_environment (a, "%new-cells", g_news);
|
2016-10-27 14:44:09 +00:00
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
//#include "mes.symbols.i"
|
|
|
|
|
|
|
|
g_cells[0].type = CHAR;
|
|
|
|
g_cells[0].value = 'c';
|
|
|
|
g_free.value = 1; // 0 is tricky
|
|
|
|
|
|
|
|
#if !MES_MINI
|
|
|
|
#include "mes.symbols.i"
|
|
|
|
#else // MES_MINI
|
|
|
|
cell_nil = g_free.value++;
|
|
|
|
g_cells[cell_nil] = scm_nil;
|
|
|
|
cell_f = g_free.value++;
|
|
|
|
g_cells[cell_f] = scm_f;
|
|
|
|
cell_t = g_free.value++;
|
|
|
|
g_cells[cell_t] = scm_t;
|
|
|
|
cell_undefined = g_free.value++;
|
|
|
|
g_cells[cell_undefined] = scm_undefined;
|
|
|
|
cell_unspecified = g_free.value++;
|
|
|
|
g_cells[cell_unspecified] = scm_unspecified;
|
|
|
|
cell_closure = g_free.value++;
|
|
|
|
g_cells[cell_closure] = scm_closure;
|
|
|
|
cell_begin = g_free.value++;
|
|
|
|
g_cells[cell_begin] = scm_begin;
|
|
|
|
|
|
|
|
cell_symbol_begin = g_free.value++;
|
|
|
|
g_cells[cell_symbol_begin] = scm_symbol_begin;
|
|
|
|
|
|
|
|
cell_symbol_sc_expander_alist = g_free.value++;
|
|
|
|
g_cells[cell_symbol_sc_expander_alist] = scm_symbol_sc_expander_alist;
|
|
|
|
cell_symbol_sc_expand = g_free.value++;
|
|
|
|
g_cells[cell_symbol_sc_expand] = scm_symbol_sc_expand;
|
|
|
|
|
|
|
|
// cell_dot = g_free.value++;
|
|
|
|
// g_cells[cell_dot] = scm_dot;
|
|
|
|
// cell_circular = g_free.value++;
|
|
|
|
// g_cells[cell_circular] = scm_circular;
|
|
|
|
// cell_symbol_lambda = g_free.value++;
|
|
|
|
// g_cells[cell_symbol_lambda] = scm_symbol_lambda;
|
|
|
|
// cell_symbol_if = g_free.value++;
|
|
|
|
// g_cells[cell_symbol_if] = scm_symbol_if;
|
|
|
|
// cell_symbol_define = g_free.value++;
|
|
|
|
// g_cells[cell_symbol_define] = scm_symbol_define;
|
|
|
|
// cell_symbol_define_macro = g_free.value++;
|
|
|
|
// g_cells[cell_symbol_define_macro] = scm_symbol_define_macro;
|
|
|
|
|
|
|
|
#endif // MES_MINI
|
|
|
|
|
|
|
|
SCM symbol_max = g_free.value;
|
|
|
|
|
|
|
|
#if MES_FULL
|
|
|
|
#include "define.i"
|
|
|
|
#include "lib.i"
|
|
|
|
#include "math.i"
|
|
|
|
#include "mes.i"
|
|
|
|
#include "posix.i"
|
|
|
|
#include "quasiquote.i"
|
|
|
|
#include "string.i"
|
|
|
|
#include "type.i"
|
|
|
|
#else
|
|
|
|
|
|
|
|
cell_cons = g_free.value++;
|
|
|
|
cell_display = g_free.value++;
|
|
|
|
cell_eq_p = g_free.value++;
|
|
|
|
cell_newline = g_free.value++;
|
|
|
|
|
|
|
|
g_cells[cell_cons] = scm_cons;
|
|
|
|
g_cells[cell_display] = scm_display;
|
|
|
|
g_cells[cell_eq_p] = scm_eq_p;
|
|
|
|
g_cells[cell_newline] = scm_newline;
|
|
|
|
|
|
|
|
cell_make_vector = g_free.value++;
|
|
|
|
g_cells[cell_make_vector] = scm_make_vector;
|
2016-10-08 06:41:30 +00:00
|
|
|
|
2016-10-20 16:43:33 +00:00
|
|
|
#endif
|
2016-11-21 08:28:34 +00:00
|
|
|
|
|
|
|
tmp = g_free.value++;
|
|
|
|
tmp_num = g_free.value++;
|
|
|
|
g_cells[tmp_num].type = NUMBER;
|
|
|
|
tmp_num2 = g_free.value++;
|
|
|
|
g_cells[tmp_num2].type = NUMBER;
|
|
|
|
|
|
|
|
g_start = g_free.value;
|
|
|
|
|
|
|
|
symbols = 0;
|
|
|
|
for (int i=1; i<symbol_max; i++)
|
|
|
|
symbols = cons (i, symbols);
|
|
|
|
|
|
|
|
SCM a = cell_nil;
|
2016-10-20 16:43:33 +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
|
|
|
#if MES_FULL
|
2016-11-21 08:28:34 +00:00
|
|
|
#include "define.environment.i"
|
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"
|
|
|
|
//#include "quasiquote.environment.i"
|
|
|
|
#include "string.environment.i"
|
Move optional type predicates to type.c.
* mes.c (char_p, macro_p, number_p, pair_p, string_p, symbol_p,
vector_p, builtin_p, boolean_p): Move to type.c
* type.c: New file.
* GNUmakefile (mes.o): Depend on type snarf output.
* module/mes/loop-0.mes (cond, map, let, or, and not, evlis-env,
apply-env, eval-expand, uquote, add-unquoters, eval,
expand-macro-env, eval-begin-env, eval-if-env, sexp:define,
env:define, env:macro): Move to mes-0.mes.
* module/mes/mes-0.mes: New file.
* module/mes/type-0.mes: New file.
* scripts/include.mes: If BOOT, also include mes-0.mes. If TYPE0,
also include type-0.mes.
2016-10-22 10:16:19 +00:00
|
|
|
#include "type.environment.i"
|
2016-11-21 08:28:34 +00:00
|
|
|
#else // !MES_FULL
|
|
|
|
|
|
|
|
a = add_environment (a, "cons", cell_cons);
|
|
|
|
a = add_environment (a, "display", cell_display);
|
|
|
|
a = add_environment (a, "eq?", cell_eq_p);
|
|
|
|
a = add_environment (a, "newline", cell_newline);
|
|
|
|
|
|
|
|
a = add_environment (a, "make-vector", cell_make_vector);
|
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
|
|
|
|
|
|
|
#if !MES_MINI
|
2016-11-21 08:28:34 +00:00
|
|
|
a = add_environment (a, "*", cell_multiply);
|
|
|
|
a = add_environment (a, "list", cell_list);
|
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
|
|
|
a = add_environment (a, "car", cell_car);
|
|
|
|
a = add_environment (a, "cdr", cell_cdr);
|
|
|
|
a = add_environment (a, "+", cell_plus);
|
|
|
|
a = add_environment (a, "quote", cell_quote);
|
|
|
|
a = add_environment (a, "null?", cell_null_p);
|
|
|
|
a = add_environment (a, "=", cell_is_p);
|
|
|
|
|
|
|
|
// a = add_environment (a, "gc", cell_gc);
|
|
|
|
// a = add_environment (a, "apply-env", cell_apply_env);
|
|
|
|
// a = add_environment (a, "eval-env", cell_eval_env);
|
|
|
|
// a = add_environment (a, "cadr", cell_cadr);
|
|
|
|
#endif // !MES_MINI
|
|
|
|
#endif // !MES_FULL
|
|
|
|
|
|
|
|
#if BOOT
|
|
|
|
////symbols = cons (cell_symbol_label, symbols);
|
|
|
|
a = cons (cons (cell_symbol_label, cell_t), 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
|
|
|
#endif
|
2016-11-21 08:28:34 +00:00
|
|
|
a = cons (cons (cell_symbol_begin, cell_begin), a);
|
2016-10-21 20:44:50 +00:00
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
a = add_environment (a, "sc-expand", cell_f);
|
2016-10-30 15:16:20 +00:00
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
a = cons (cons (cell_closure, a), 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-21 08:28:34 +00:00
|
|
|
internal_lookup_symbol (cell_nil);
|
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;
|
|
|
|
r1 = make_char (0);
|
|
|
|
r2 = make_char (0);
|
|
|
|
r3 = make_char (0);
|
2016-11-21 08:28:34 +00:00
|
|
|
stack = cons (cell_nil, cell_nil);
|
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-05-28 14:39:44 +00:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
make_lambda (SCM args, SCM body)
|
2016-05-15 22:07:44 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
return cons (cell_symbol_lambda, cons (args, body));
|
2016-05-15 22:07: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-11-21 08:28:34 +00:00
|
|
|
return cons (cell_closure, 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);
|
|
|
|
if (macro_p (m) == cell_t) return MACRO (m);
|
|
|
|
return cell_f;
|
2016-07-08 16:02:06 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
read_input_file_env (SCM e, SCM a)
|
2016-05-28 14:39:44 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
if (e == cell_nil) return e;
|
2016-11-02 19:22:02 +00:00
|
|
|
return cons (e, read_input_file_env (read_env (a), a));
|
2016-10-29 16:43:03 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM
|
|
|
|
load_env (SCM a)
|
2016-10-29 16:43:03 +00:00
|
|
|
{
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM p = read_input_file_env (read_env (a), a);
|
|
|
|
return begin_env (p, a);
|
2016-05-29 11:44:03 +00:00
|
|
|
}
|
|
|
|
|
2016-10-22 18:18:03 +00:00
|
|
|
#include "type.c"
|
|
|
|
#include "define.c"
|
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-10-22 18:18:03 +00:00
|
|
|
#include "quasiquote.c"
|
|
|
|
#include "string.c"
|
|
|
|
|
2016-07-16 20:43:13 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2016-10-16 11:45:24 +00:00
|
|
|
if (argc > 1 && !strcmp (argv[1], "--help")) return puts ("Usage: mes < FILE\n");
|
2016-11-21 13:18:01 +00:00
|
|
|
if (argc > 1 && !strcmp (argv[1], "--version")) return puts ("Mes 0.2\n");
|
2016-11-02 17:25:18 +00:00
|
|
|
g_stdin = stdin;
|
2016-11-21 08:28:34 +00:00
|
|
|
SCM a = mes_environment ();
|
2016-11-02 19:22:02 +00:00
|
|
|
display_ (stderr, load_env (a));
|
2016-08-12 12:17:20 +00:00
|
|
|
fputs ("", stderr);
|
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
|
|
|
fprintf (stderr, "\nstats: [%d]\n", g_free.value);
|
2016-07-16 20:43:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|