From 9f56b8b102d8599441884bf43b92f1007d82a138 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 28 May 2017 16:03:45 +0200 Subject: [PATCH] core: Always include reader.c, drop binary read-0-32.mo dependency. * module/language/c99/compiler.mes (c99-input->full-ast): Remove obsolete __NYACC__ and MES_FULL defines. * src/mes.c [!MES_FULL]: Include reader-mes.h. (mes_builtins) [!MES_FULL]: Include reader.mes.i, reader.me.environment.i. [!MES_FULL]: Include reader.c. (main) [!MES_FULL]: By default call load_env, only call bload_env when --load is supplied. WAS: Always bload read-0-32.mo. * src/reader.c (__end_of__mes_): Remove. (dump): Remove option of dumping tiny test program. * make/mescc-mes.make ($(OUT)/$(TARGET), mescc.mes-ccompile, mescc.mes.c-compile-E): Depend on $(OUT)/mes, scripts/mes. * src/src.make (mes.guile): Remove module/mes/read-32-0 dependency. Do not build $(OUT)/mes.mes. * module/module.make (module/mes/read-0.mo, module/mes/read-0-32.mo, module/mes/tiny-0-32.mo): Remove targets. (CLEAN): Do not add them. Neither install $(OUT)/mes.mes. * .gitignore: Remove exceptions for them. * make/install.make (install): Do not install them. * HACKING: Update info about creating module/mes/read-32-0.mo. * scaffold/mini-mes.c: Remove. * scaffold/tiny-mes.c: Remove. * scaffold/cons-mes.c: Remove. * scaffold/scaffold.make (tiny-mes.libc, tiny-mes.guile, tiny-mes.mes, mini-mes.libc, mini-mes.guile, mini-mes.mes): Reemove targets. --- .gitignore | 4 - HACKING | 6 +- make/install.make | 6 +- make/mescc-mes.make | 8 +- module/language/c99/compiler.mes | 4 +- module/module.make | 32 - scaffold/cons-mes.c | 876 --------------------- scaffold/mini-mes.c | 1233 ------------------------------ scaffold/scaffold.make | 77 -- scaffold/tiny-mes.c | 341 --------- scripts/mes | 1 - src/mes.c | 12 - src/reader.c | 50 +- src/src.make | 5 +- 14 files changed, 19 insertions(+), 2636 deletions(-) delete mode 100644 scaffold/cons-mes.c delete mode 100644 scaffold/mini-mes.c delete mode 100644 scaffold/tiny-mes.c delete mode 120000 scripts/mes diff --git a/.gitignore b/.gitignore index 88e3f89a..3aaec58a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,10 +10,6 @@ #keep this: bootstrap #/mes.mes -/module/mes/tiny-0-32.mo -#keep this: bootstrap -#/module/mes/read-0-32.mo -/module/mes/read-0.mo /out ? ?.mes diff --git a/HACKING b/HACKING index d0d76e4c..c4c971ff 100644 --- a/HACKING +++ b/HACKING @@ -108,10 +108,8 @@ set disassemble-next-line gdb-display-disassembly-buffer b *0x804a79d ** Create memory dump with 32 bit Gcc compiled Mes -guix environment --ad-hoc --system=i686-linux gcc-toolchain -- bash -c 'make mes CC=i686-unknown-linux-gnu-gcc LIBRARY_PATH=${PATH%%/bin:*}/lib' -mv mes mes-32 -MES_TINY=1 ./mes-32 --dump < module/mes/tiny-0.mes > module/mes/tiny-0-32.mo -./mes-32 --dump < module/mes/read-0.mes > module/mes/read-0-32.mo +make out/i686-unknown-linux-gnu-mes +out/i686-unknown-linux-gnu-mes --dump < module/mes/read-0.mes > module/mes/read-0-32.mo ** C parser/compiler *** [[https://savannah.gnu.org/projects/nyacc][nyacc]] *** PEG: [[http://piumarta.com/software/peg/][parse C using PEG]] diff --git a/make/install.make b/make/install.make index a048086b..65c64cab 100644 --- a/make/install.make +++ b/make/install.make @@ -62,7 +62,9 @@ INSTALL_GO_FILES:= install: $(CLEAN) ChangeLog mkdir -p $(DESTDIR)$(PREFIX)/bin install $(OUT)/mes $(DESTDIR)$(PREFIX)/bin/mes - install mes.mes $(DESTDIR)$(PREFIX)/bin/mes.mes +ifeq (0,1) # No bootstrap mes.mes ATM + install $(OUT)/mes.mes $(DESTDIR)$(PREFIX)/bin/mes.mes +endif install scripts/mescc.mes $(DESTDIR)$(PREFIX)/bin/mescc.mes install scripts/repl.mes $(DESTDIR)$(PREFIX)/bin/repl.mes install guile/mescc.scm $(DESTDIR)$(PREFIX)/bin/mescc.scm @@ -85,8 +87,6 @@ install: $(CLEAN) ChangeLog $(DESTDIR)$(PREFIX)/bin/mescc.mes \ $(DESTDIR)$(PREFIX)/bin/mescc.scm \ $(DESTDIR)$(PREFIX)/bin/repl.mes - cp module/mes/read-0.mo $(DESTDIR)$(DATADIR)/module/mes - cp module/mes/read-0-32.mo $(DESTDIR)$(DATADIR)/module/mes mkdir -p $(DESTDIR)$(DOCDIR) $(GIT_ARCHIVE_HEAD) $(READMES) \ | tar -C $(DESTDIR)$(DOCDIR) -xf- diff --git a/make/mescc-mes.make b/make/mescc-mes.make index 5213f409..06022400 100644 --- a/make/mescc-mes.make +++ b/make/mescc-mes.make @@ -35,7 +35,9 @@ $(OUT)/$(1:.c=.$(CROSS)o): CC:=$(MESCC.mes) $(OUT)/$(1:.c=.$(CROSS)o): COMPILE.c:=$(MESCC.mes) -c $(OUT)/$(1:.c=.$(CROSS)o): CPPFLAGS:=$(2:%=-D %) $(3:%=-I %) $(OUT)/$(1:.c=.$(CROSS)o): COMPILE.c:=$(MESCC.mes) -c $(CPPFLAGS) +$(OUT)/$(1:.c=.$(CROSS)o): OUT:=$(OUT) $(OUT)/$(1:.c=.$(CROSS)o): $(MAKEFILE_LIST) +$(OUT)/$(1:.c=.$(CROSS)o): $(OUT)/mes $(OUT)/$(1:.c=.$(CROSS)o): scripts/mes $(OUT)/$(1:.c=.$(CROSS)o): $(INSTALL_MES_FILES) $(OUT)/$(1:.c=.$(CROSS)o): $(1) @@ -49,9 +51,11 @@ $(OUT)/$(1:.c=.$(CROSS)E): CROSS:=$(CROSS) $(OUT)/$(1:.c=.$(CROSS)E): cc:=MESCC.mes $(OUT)/$(1:.c=.$(CROSS)E): CC:=$(MESCC.mes) $(OUT)/$(1:.c=.$(CROSS)E): CPPFLAGS:=$(2:%=-D %) $(3:%=-I %) +$(OUT)/$(1:.c=.$(CROSS)E): OUT:=$(OUT) $(OUT)/$(1:.c=.$(CROSS)E): PREPROCESS.c:=$(MESCC.mes) -E $(CPPFLAGS) $(OUT)/$(1:.c=.$(CROSS)E): $(MAKEFILE_LIST) -$(OUT)/$(1:.c=.$(CROSS)o): scripts/mes +$(OUT)/$(1:.c=.$(CROSS)E): $(OUT)/mes +$(OUT)/$(1:.c=.$(CROSS)E): scripts/mes $(OUT)/$(1:.c=.$(CROSS)E): $(INSTALL_MES_FILES) $(OUT)/$(1:.c=.$(CROSS)E): $(1) @echo " $$(cc) $$(notdir $(1)) -> $$(notdir $$@)" @@ -65,7 +69,9 @@ $(1:.$(CROSS)E=.$(CROSS)o): cc:=MESCC.mes $(1:.$(CROSS)E=.$(CROSS)o): CC:=$(MESCC.mes) $(1:.$(CROSS)E=.$(CROSS)o): CPPFLAGS:=$(2:%=-D %) $(3:%=-I %) $(1:.$(CROSS)E=.$(CROSS)o): COMPILE.c:=$(MESCC.mes) -c $(CPPFLAGS) +$(1:.$(CROSS)E=.$(CROSS)o): OUT:=$(OUT) $(1:.$(CROSS)E=.$(CROSS)o): $(MAKEFILE_LIST) +$(1:.$(CROSS)E=.$(CROSS)o): $(OUT)/mes $(1:.$(CROSS)E=.$(CROSS)o): scripts/mes $(1:.$(CROSS)E=.$(CROSS)o): $(INSTALL_MES_FILES) $(1:.$(CROSS)E=.$(CROSS)o): $(1) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 50295e11..49899b5d 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -60,9 +60,8 @@ #:cpp-defs `( "POSIX=0" "_POSIX_SOURCE=0" - "__GNUC__=0" + "__GNUC__=0" ;; FIXME: TCC uses #ifdef __GNUC__, but NYACC needs it for #if __GNUC__ "__MESC__=1" - "__NYACC__=1" ;; REMOVEME "EOF=-1" "STDIN=0" "STDOUT=1" @@ -71,7 +70,6 @@ "INT_MIN=-2147483648" "INT_MAX=2147483647" - "MES_FULL=0" "FIXED_PRIMITIVES=1" ,(if mes? "__MESC_MES__=1" "__MESC_MES__=0") diff --git a/module/module.make b/module/module.make index 54df55ae..71665e2f 100644 --- a/module/module.make +++ b/module/module.make @@ -1,35 +1,3 @@ -CLEAN+=module/mes/read-0.mo -module/mes/read-0.mo: module/mes/read-0.mes $(OUT)/mes - @rm -f $@ - @echo " DUMP $(notdir $^) -> $(notdir $@)" - $(QUIET)$(OUT)/mes --dump < $< > $@ - -CLEAN+=module/mes/read-0-32.mo -CROSS:=$(CC32:%gcc=%) -module/mes/read-0-32.mo: CROSS:=$(CROSS) -module/mes/read-0-32.mo: module/mes/read-0.mes -module/mes/read-0-32.mo: $(OUT)/$(CROSS)mes - @rm -f $@ - @echo " DUMP $(notdir $^) -> $(notdir $@)" - $(QUIET)MES_MINI=1 $(OUT)/$(CROSS)mes --dump < $< > $@ - -CLEAN+=module/mes/tiny-0-32.mo -module/mes/tiny-0-32.mo: CROSS:=$(CROSS) -module/mes/tiny-0-32.mo: $(OUT)/$(CROSS)mes - @rm -f $@ - @echo " DUMP $(notdir $^) -> $(notdir $@)" - $(QUIET) MES_TINY=1 $(OUT)/$(CROSS)mes --dump --tiny < $< > $@ - -MO_FILES:=\ - module/mes/read-0.mo\ - module/mes/read-0-32.mo\ - module/mes/tiny-0-32.mo\ -# -all-mo: $(MO_FILES) -clean-mo: MO_FILES:=$(MO_FILES) -clean-mo: - @$(QUIET)rm -f $(MO_FILES) - MES_FILES:=$(shell $(GIT_LS_FILES) module/*.mes) SCM_FILES:=$(shell $(GIT_LS_FILES) module/language/ module/nyacc/ module/mes/) SCM_FILES:=$(filter %.scm, $(SCM_FILES)) diff --git a/scaffold/cons-mes.c b/scaffold/cons-mes.c deleted file mode 100644 index 093db77e..00000000 --- a/scaffold/cons-mes.c +++ /dev/null @@ -1,876 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * Mes --- Maxwell Equations of Software - * Copyright © 2016,2017 Jan Nieuwenhuizen - * - * 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 . - */ - -#if POSIX -#error "POSIX not supported" -#endif - -#include -#include -#include -#include -#include - -char arena[2000]; - -typedef int SCM; - -int g_debug = 0; -int g_free = 0; - -SCM g_continuations = 0; -SCM g_symbols = 0; -SCM g_stack = 0; -SCM r0 = 0; // a/env -SCM r1 = 0; // param 1 -SCM r2 = 0; // save 2+load/dump -SCM r3 = 0; // continuation - -enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART}; - -struct scm { - enum type_t type; - SCM car; - SCM cdr; -}; - -struct function { - int (*function) (void); - int arity; - char *name; -}; - -#if __MESC__ -struct scm *g_cells = arena; -#else -struct scm *g_cells = (struct scm*)arena; -#endif - -#define cell_nil 1 -#define cell_f 2 -#define cell_t 3 -#define cell_dot 4 -// #define cell_arrow 5 -#define cell_undefined 6 -#define cell_unspecified 7 -#define cell_closure 8 -#define cell_circular 9 -#define cell_begin 10 -#define cell_symbol_dot 11 -#define cell_symbol_lambda 12 -#define cell_symbol_begin 13 -#define cell_symbol_if 14 -#define cell_symbol_quote 15 -#define cell_symbol_set_x 16 - -#define cell_vm_apply 45 -#define cell_vm_apply2 46 - -#define cell_vm_eval 47 - -#define cell_vm_begin 56 -//#define cell_vm_begin_read_input_file 57 -#define cell_vm_begin2 58 - -#define cell_vm_return 63 - -SCM tmp; -SCM tmp_num; -SCM tmp_num2; - -int ARENA_SIZE = 200; -struct function g_functions[5]; -int g_function = 0; - - -SCM make_cell_ (SCM type, SCM car, SCM cdr); -struct function fun_make_cell_ = {&make_cell_,3,"core:make-cell"}; -struct scm scm_make_cell_ = {TFUNCTION,0,0}; - //, "core:make-cell", 0}; -SCM cell_make_cell_; - -SCM cons (SCM x, SCM y); -struct function fun_cons = {&cons,2,"cons"}; -struct scm scm_cons = {TFUNCTION,0,0}; - // "cons", 0}; -SCM cell_cons; - -SCM car (SCM x); -struct function fun_car = {&car,1,"car"}; -struct scm scm_car = {TFUNCTION,0,0}; - // "car", 0}; -SCM cell_car; - -SCM cdr (SCM x); -struct function fun_cdr = {&cdr,1,"cdr"}; -struct scm scm_cdr = {TFUNCTION,0,0}; -// "cdr", 0}; -SCM cell_cdr; - -// SCM eq_p (SCM x, SCM y); -// struct function fun_eq_p = {&eq_p,2,"eq?"}; -// scm scm_eq_p = {TFUNCTION,0,0}; -// SCM cell_eq_p; - -#define TYPE(x) (g_cells[x].type) - -#define CAR(x) g_cells[x].car -#define LENGTH(x) g_cells[x].car -#define STRING(x) g_cells[x].car - -#define CDR(x) g_cells[x].cdr -#define CONTINUATION(x) g_cells[x].cdr - -#define FUNCTION(x) g_functions[g_cells[x].cdr] -#define VALUE(x) g_cells[x].cdr -#define VECTOR(x) g_cells[x].cdr - -#define MAKE_CHAR(n) make_cell_ (tmp_num_ (TCHAR), 0, tmp_num2_ (n)) -#define MAKE_NUMBER(n) make_cell_ (tmp_num_ (TNUMBER), 0, tmp_num2_ (n)) - -#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)) - -#define MAKE_STRING(x) make_cell_ (tmp_num_ (TSTRING), x, 0) - -SCM -alloc (int n) -{ - assert (g_free + n < ARENA_SIZE); - SCM x = g_free; - g_free += n; - return x; -} - -SCM -make_cell_ (SCM type, SCM car, SCM cdr) -{ - SCM x = alloc (1); - assert (TYPE (type) == TNUMBER); - TYPE (x) = VALUE (type); - if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER) { - if (car) CAR (x) = CAR (car); - if (cdr) CDR(x) = CDR(cdr); - } - else if (VALUE (type) == TFUNCTION) { - if (car) CAR (x) = car; - if (cdr) CDR(x) = CDR(cdr); - } - else { - CAR (x) = car; - CDR(x) = cdr; - } - return x; -} - -SCM -tmp_num_ (int x) -{ - VALUE (tmp_num) = x; - return tmp_num; -} - -SCM -tmp_num2_ (int x) -{ - VALUE (tmp_num2) = x; - return tmp_num2; -} - -SCM -cons (SCM x, SCM y) -{ - VALUE (tmp_num) = TPAIR; - return make_cell_ (tmp_num, x, y); -} - -SCM -car (SCM x) -{ - return CAR (x); -} - -SCM -cdr (SCM x) -{ - return CDR(x); -} - -SCM -gc_push_frame () -{ - SCM frame = cons (r1, cons (r2, cons (r3, cons (r0, cell_nil)))); - g_stack = cons (frame, g_stack); - return g_stack; -} - -SCM -append2 (SCM x, SCM y) -{ - if (x == cell_nil) return y; - assert (TYPE (x) == TPAIR); - return cons (car (x), append2 (cdr (x), y)); -} - -SCM -pairlis (SCM x, SCM y, SCM a) -{ - if (x == cell_nil) - return a; - if (TYPE (x) != TPAIR) - return cons (cons (x, y), a); - return cons (cons (car (x), car (y)), - pairlis (cdr (x), cdr (y), a)); -} - -SCM -assq (SCM x, SCM a) -{ - while (a != cell_nil && x == CAAR (a)) a = CDR (a); - return a != cell_nil ? car (a) : cell_f; -} - -SCM -push_cc (SCM p1, SCM p2, SCM a, SCM c) ///((internal)) -{ - puts ("push cc\n"); - SCM x = r3; - r3 = c; - r2 = p2; - gc_push_frame (); - r1 = p1; - r0 = a; - r3 = x; - return cell_unspecified; -} - -SCM caar (SCM x) {return car (car (x));} -SCM cadr (SCM x) {return car (cdr (x));} -SCM cdar (SCM x) {return cdr (car (x));} -SCM cddr (SCM x) {return cdr (cdr (x));} - -#if __GNUC__ -//FIXME -SCM call (SCM,SCM); -SCM gc_pop_frame (); -#endif - -SCM -eval_apply () -{ - eval_apply: - switch (r3) - { - case cell_vm_apply: {goto apply;} - case cell_unspecified: {return r1;} - } - - SCM x = cell_nil; - SCM y = cell_nil; - - apply: - switch (TYPE (car (r1))) - { - case TFUNCTION: { - puts ("apply.function\n"); - r1 = call (car (r1), cdr (r1)); - goto vm_return; - } - } - vm_return: - x = r1; - gc_pop_frame (); - r1 = x; - goto eval_apply; -} - -SCM -call (SCM fn, SCM x) -{ - puts ("call\n"); - if ((FUNCTION (fn).arity > 0 || FUNCTION (fn).arity == -1) - && x != cell_nil && TYPE (CAR (x)) == TVALUES) - x = cons (CADAR (x), CDR (x)); - if ((FUNCTION (fn).arity > 1 || FUNCTION (fn).arity == -1) - && x != cell_nil && TYPE (CDR (x)) == TPAIR && TYPE (CADR (x)) == TVALUES) - x = cons (CAR (x), cons (CDADAR (x), CDR (x))); - switch (FUNCTION (fn).arity) - { - case 0: {return (FUNCTION (fn).function) ();} - case 1: {return ((SCM(*)(SCM))(FUNCTION (fn).function)) (car (x));} - case 2: {return ((SCM(*)(SCM,SCM))(FUNCTION (fn).function)) (car (x), cadr (x));} - case 3: {return ((SCM(*)(SCM,SCM,SCM))(FUNCTION (fn).function)) (car (x), cadr (x), car (cddr (x)));} - case -1: {return ((SCM(*)(SCM))(FUNCTION (fn).function)) (x);} - } - return cell_unspecified; -} - -SCM -gc_peek_frame () -{ - SCM frame = car (g_stack); - r1 = car (frame); - r2 = cadr (frame); - r3 = car (cddr (frame)); - r0 = cadr (cddr (frame)); - return frame; -} - -SCM -gc_pop_frame () -{ - SCM frame = gc_peek_frame (g_stack); - g_stack = cdr (g_stack); - return frame; -} - -SCM -mes_g_stack (SCM a) ///((internal)) -{ - r0 = a; - r1 = MAKE_CHAR (0); - r2 = MAKE_CHAR (0); - r3 = MAKE_CHAR (0); - g_stack = cons (cell_nil, cell_nil); - return r0; -} - -// Environment setup -SCM -make_tmps (struct scm* cells) -{ - tmp = g_free++; - cells[tmp].type = TCHAR; - tmp_num = g_free++; - cells[tmp_num].type = TNUMBER; - tmp_num2 = g_free++; - cells[tmp_num2].type = TNUMBER; - return 0; -} - -SCM -make_symbol_ (SCM s) -{ - VALUE (tmp_num) = TSYMBOL; - SCM x = make_cell_ (tmp_num, s, 0); - g_symbols = cons (x, g_symbols); - return x; -} - -SCM -make_symbol (SCM s) -{ - SCM x = 0; - return x ? x : make_symbol_ (s); -} - -SCM -acons (SCM key, SCM value, SCM alist) -{ - return cons (cons (key, value), alist); -} - -// Jam Collector -SCM g_symbol_max; - -SCM -gc_init_cells () -{ - return 0; -} - -// INIT NEWS - -SCM -mes_symbols () ///((internal)) -{ - gc_init_cells (); - // gc_init_news (); - -#if __GNUC__ && 0 - //#include "mes.symbols.i" -#else -g_free++; -// g_cells[cell_nil] = scm_nil; - -g_free++; -// g_cells[cell_f] = scm_f; - -g_free++; -// g_cells[cell_t] = scm_t; - -g_free++; -// g_cells[cell_dot] = scm_dot; - -g_free++; -// g_cells[cell_arrow] = scm_arrow; - -g_free++; -// g_cells[cell_undefined] = scm_undefined; - -g_free++; -// g_cells[cell_unspecified] = scm_unspecified; - -g_free++; -// g_cells[cell_closure] = scm_closure; - -g_free++; -// g_cells[cell_circular] = scm_circular; - -g_free++; -// g_cells[cell_begin] = scm_begin; - -/// -g_free = 44; -g_free++; -// g_cells[cell_vm_apply] = scm_vm_apply; - -g_free++; -// g_cells[cell_vm_apply2] = scm_vm_apply2; - -g_free++; -// g_cells[cell_vm_eval] = scm_vm_eval; - -/// -g_free = 55; -g_free++; -// g_cells[cell_vm_begin] = scm_vm_begin; - -g_free++; -// g_cells[cell_vm_begin_read_input_file] = scm_vm_begin_read_input_file; - -g_free++; -// g_cells[cell_vm_begin2] = scm_vm_begin2; - -/// -g_free = 62; -g_free++; -// g_cells[cell_vm_return] = scm_vm_return; - -#endif - - g_symbol_max = g_free; - make_tmps (g_cells); - - g_symbols = 0; - for (int i=1; i\n"); - switch (TYPE (x)) - { - case TCHAR: - { - //puts ("\n"); - puts ("#\\"); - putchar (VALUE (x)); - break; - } - case TFUNCTION: - { - //puts ("\n"); - if (VALUE (x) == 0) - puts ("core:make-cell"); - if (VALUE (x) == 1) - puts ("cons"); - if (VALUE (x) == 2) - puts ("car"); - if (VALUE (x) == 3) - puts ("cdr"); - break; - } - case TNUMBER: - { - //puts ("\n"); -#if __GNUC__ - puts (itoa (VALUE (x))); -#else - int i; - i = VALUE (x); - i = i + 48; - putchar (i); -#endif - break; - } - case TPAIR: - { - //puts ("\n"); - //if (cont != cell_f) puts "("); - puts ("("); - if (x && x != cell_nil) display_ (CAR (x)); - if (CDR (x) && CDR (x) != cell_nil) - { -#if __GNUC__ - if (TYPE (CDR (x)) != TPAIR) - puts (" . "); -#else - int c; - c = CDR (x); - c = TYPE (c); - if (c != TPAIR) - puts (" . "); -#endif - display_ (CDR (x)); - } - //if (cont != cell_f) puts (")"); - puts (")"); - break; - } - case TSPECIAL: - { - switch (x) - { - case 1: {puts ("()"); break;} - case 2: {puts ("#f"); break;} - case 3: {puts ("#t"); break;} - default: - { -#if __GNUC__ - puts (""); -#else - puts (""); -#endif - } - } - break; - } - case TSYMBOL: - { - switch (x) - { - case 11: {puts (" . "); break;} - case 12: {puts ("lambda"); break;} - case 13: {puts ("begin"); break;} - case 14: {puts ("if"); break;} - case 15: {puts ("quote"); break;} - case 37: {puts ("car"); break;} - case 38: {puts ("cdr"); break;} - case 39: {puts ("null?"); break;} - case 40: {puts ("eq?"); break;} - case 41: {puts ("cons"); break;} - default: - { -#if __GNUC__ - puts (""); -#else - puts (""); -#endif - } - } - break; - } - default: - { - //puts ("\n"); -#if __GNUC__ - puts ("<"); - puts (itoa (TYPE (x))); - puts (":"); - puts (itoa (x)); - puts (">"); -#else - puts ("_"); -#endif - break; - } - } - return 0; -} - -SCM -simple_bload_env (SCM a) ///((internal)) -{ - puts ("reading: "); - char *mo = "module/mes/tiny-0-32.mo"; - puts (mo); - puts ("\n"); - g_stdin = open (mo, 0); - if (g_stdin < 0) {eputs ("no such file: module/mes/tiny-0-32.mo\n");return 1;} - - char *p = (char*)g_cells; - int c; - - assert (getchar () == 'M'); - assert (getchar () == 'E'); - assert (getchar () == 'S'); - puts (" *GOT MES*\n"); - - g_stack = getchar () << 8; - g_stack += getchar (); - - puts ("stack: "); - puts (itoa (g_stack)); - puts ("\n"); - - c = getchar (); - while (c != -1) - { - *p++ = c; - c = getchar (); - } - - puts ("read done\n"); - - g_free = (p-(char*)g_cells) / sizeof (struct scm); - - if (g_free != 15) exit (33); - - g_symbols = 1; - - g_stdin = STDIN; - r0 = mes_builtins (r0); - - if (g_free != 19) exit (34); - - puts ("cells read: "); - puts (itoa (g_free)); - puts ("\n"); - - puts ("symbols: "); - puts (itoa (g_symbols)); - puts ("\n"); - // display_ (g_symbols); - // puts ("\n"); - - display_ (10); - puts ("\n"); - - fill (); - r2 = 10; - - if (TYPE (12) != TPAIR) - exit (33); - - puts ("program["); - puts (itoa (r2)); - puts ("]: "); - - display_ (r2); - //display_ (14); - puts ("\n"); - - r0 = 1; - //r2 = 10; - return r2; -} - -int -main (int argc, char *argv[]) -{ - puts ("Hello cons-mes!\n"); - if (argc > 1 && !strcmp (argv[1], "--help")) return eputs ("Usage: mes [--dump|--load] < FILE"); -#if __GNUC__ - if (argc > 1 && !strcmp (argv[1], "--version")) {eputs ("Mes ");return eputs (VERSION);}; -#else - if (argc > 1 && !strcmp (argv[1], "--version")) {eputs ("Mes ");return eputs ("0.4");}; -#endif - g_stdin = STDIN; - - r0 = mes_environment (); - - SCM program = simple_bload_env (r0); - - puts ("g_free="); - puts (itoa(g_free)); - puts ("\n"); - - push_cc (r2, cell_unspecified, r0, cell_unspecified); - - puts ("g_free="); - puts (itoa(g_free)); - puts ("\n"); - - puts ("g_stack="); - puts (itoa(g_stack)); - puts ("\n"); - - puts ("r0="); - puts (itoa(r0)); - puts ("\n"); - - puts ("r1="); - puts (itoa(r1)); - puts ("\n"); - - puts ("r2="); - puts (itoa(r2)); - puts ("\n"); - - puts ("r3="); - puts (itoa(r3)); - puts ("\n"); - - r3 = cell_vm_apply; - r1 = eval_apply (); - display_ (r1); - - eputs ("\n"); - return 0; -} - diff --git a/scaffold/mini-mes.c b/scaffold/mini-mes.c deleted file mode 100644 index 7c33fe9f..00000000 --- a/scaffold/mini-mes.c +++ /dev/null @@ -1,1233 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * Mes --- Maxwell Equations of Software - * Copyright © 2016,2017 Jan Nieuwenhuizen - * - * 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 . - */ - -#if POSIX -#error "POSIX not supported" -#endif - -#include -#include -#include -#include -#include - -int ARENA_SIZE = 100000; -int MAX_ARENA_SIZE = 40000000; -int GC_SAFETY = 10000; - -char *g_arena = 0; -typedef int SCM; - -int g_debug = 0; -int g_free = 0; - -SCM g_continuations = 0; -SCM g_symbols = 0; -SCM g_stack = 0; -// a/env -SCM r0 = 0; -// param 1 -SCM r1 = 0; -// save 2+load/dump -SCM r2 = 0; -// continuation -SCM r3 = 0; - -enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART}; - -struct scm { - enum type_t type; - SCM car; - SCM cdr; -}; -struct function { - int (*function) (void); - int arity; - char *name; -}; - -#if __MESC__ -//FIXME -char *foobar = 0; -struct scm *g_cells = foobar; -struct scm *g_news = foobar; -#else -struct scm *g_cells = 0; -struct scm *g_news = 0; -#endif - -struct scm scm_nil = {TSPECIAL, "()",0}; -struct scm scm_f = {TSPECIAL, "#f",0}; -struct scm scm_t = {TSPECIAL, "#t",0}; -struct scm scm_dot = {TSPECIAL, ".",0}; -struct scm scm_arrow = {TSPECIAL, "=>",0}; -struct scm scm_undefined = {TSPECIAL, "*undefined*",0}; -struct scm scm_unspecified = {TSPECIAL, "*unspecified*",0}; -struct scm scm_closure = {TSPECIAL, "*closure*",0}; -struct scm scm_circular = {TSPECIAL, "*circular*",0}; -struct scm scm_begin = {TSPECIAL, "*begin*",0}; - -struct scm scm_symbol_dot = {TSYMBOL, "*dot*",0}; -struct scm scm_symbol_lambda = {TSYMBOL, "lambda",0}; -struct scm scm_symbol_begin = {TSYMBOL, "begin",0}; -struct scm scm_symbol_if = {TSYMBOL, "if",0}; -struct scm scm_symbol_quote = {TSYMBOL, "quote",0}; -struct scm scm_symbol_set_x = {TSYMBOL, "set!",0}; - -struct scm scm_symbol_sc_expand = {TSYMBOL, "sc-expand",0}; -struct scm scm_symbol_macro_expand = {TSYMBOL, "macro-expand",0}; -struct scm scm_symbol_sc_expander_alist = {TSYMBOL, "*sc-expander-alist*",0}; - -struct scm scm_symbol_call_with_values = {TSYMBOL, "call-with-values",0}; -struct scm scm_call_with_current_continuation = {TSPECIAL, "*call/cc*",0}; -struct scm scm_symbol_call_with_current_continuation = {TSYMBOL, "call-with-current-continuation",0}; -struct scm scm_symbol_current_module = {TSYMBOL, "current-module",0}; -struct scm scm_symbol_primitive_load = {TSYMBOL, "primitive-load",0}; -struct scm scm_symbol_read_input_file = {TSYMBOL, "read-input-file",0}; -struct scm scm_symbol_write = {TSYMBOL, "write",0}; -struct scm scm_symbol_display = {TSYMBOL, "display",0}; - -struct scm scm_symbol_throw = {TSYMBOL, "throw",0}; -struct scm scm_symbol_not_a_pair = {TSYMBOL, "not-a-pair",0}; -struct scm scm_symbol_system_error = {TSYMBOL, "system-error",0}; -struct scm scm_symbol_wrong_number_of_args = {TSYMBOL, "wrong-number-of-args",0}; -struct scm scm_symbol_wrong_type_arg = {TSYMBOL, "wrong-type-arg",0}; -struct scm scm_symbol_unbound_variable = {TSYMBOL, "unbound-variable",0}; - -struct scm scm_symbol_argv = {TSYMBOL, "%argv",0}; -struct scm scm_symbol_mes_prefix = {TSYMBOL, "%prefix",0}; -struct scm scm_symbol_mes_version = {TSYMBOL, "%version",0}; - -struct scm scm_symbol_car = {TSYMBOL, "car",0}; -struct scm scm_symbol_cdr = {TSYMBOL, "cdr",0}; -struct scm scm_symbol_null_p = {TSYMBOL, "null?",0}; -struct scm scm_symbol_eq_p = {TSYMBOL, "eq?",0}; -struct scm scm_symbol_cons = {TSYMBOL, "cons",0}; - -struct scm scm_vm_evlis = {TSPECIAL, "*vm-evlis*",0}; -struct scm scm_vm_evlis2 = {TSPECIAL, "*vm-evlis2*",0}; -struct scm scm_vm_evlis3 = {TSPECIAL, "*vm-evlis3*",0}; -struct scm scm_vm_apply = {TSPECIAL, "core:apply",0}; -struct scm scm_vm_apply2 = {TSPECIAL, "*vm-apply2*",0}; -struct scm scm_vm_eval = {TSPECIAL, "core:eval",0}; - -//FIXED_PRIMITIVES -struct scm scm_vm_eval_car = {TSPECIAL, "*vm-eval-car*",0}; -struct scm scm_vm_eval_cdr = {TSPECIAL, "*vm-eval-cdr*",0}; -struct scm scm_vm_eval_cons = {TSPECIAL, "*vm-eval-cons*",0}; -struct scm scm_vm_eval_null_p = {TSPECIAL, "*vm-eval-null-p*",0}; - -struct scm scm_vm_eval_set_x = {TSPECIAL, "*vm-eval-set!*",0}; -struct scm scm_vm_eval_macro = {TSPECIAL, "*vm-eval-macro*",0}; -struct scm scm_vm_eval_check_func = {TSPECIAL, "*vm-eval-check-func*",0}; -struct scm scm_vm_eval2 = {TSPECIAL, "*vm-eval2*",0}; -struct scm scm_vm_macro_expand = {TSPECIAL, "core:macro-expand",0}; -struct scm scm_vm_begin = {TSPECIAL, "*vm-begin*",0}; -struct scm scm_vm_begin_read_input_file = {TSPECIAL, "*vm-begin-read-input-file*",0}; -struct scm scm_vm_begin2 = {TSPECIAL, "*vm-begin2*",0}; -struct scm scm_vm_if = {TSPECIAL, "*vm-if*",0}; -struct scm scm_vm_if_expr = {TSPECIAL, "*vm-if-expr*",0}; -struct scm scm_vm_call_with_values2 = {TSPECIAL, "*vm-call-with-values2*",0}; -struct scm scm_vm_call_with_current_continuation2 = {TSPECIAL, "*vm-call-with-current-continuation2*",0}; -struct scm scm_vm_return = {TSPECIAL, "*vm-return*",0}; - -struct scm scm_symbol_gnuc = {TSYMBOL, "%gnuc",0}; -struct scm scm_symbol_mesc = {TSYMBOL, "%mesc",0}; - -struct scm scm_test = {TSYMBOL, "test",0}; - -#include "mes.mes.symbols.h" - -SCM tmp; -SCM tmp_num; -SCM tmp_num2; - -struct function g_functions[200]; -int g_function = 0; - -#include "gc.mes.h" -#include "lib.mes.h" -#include "math.mes.h" -#include "mes.mes.h" -#include "posix.mes.h" -// #include "reader.mes.h" -#include "vector.mes.h" - -#define TYPE(x) g_cells[x].type -#define CAR(x) g_cells[x].car -#define CDR(x) g_cells[x].cdr - -#define NTYPE(x) g_news[x].type -#define NCAR(x) g_news[x].car -#define NCDR(x) g_news[x].cdr - -#define LENGTH(x) g_cells[x].car -#define REF(x) g_cells[x].car -#define STRING(x) g_cells[x].car - -#define CLOSURE(x) g_cells[x].cdr -#define CONTINUATION(x) g_cells[x].cdr - -#define FUNCTION(x) g_functions[g_cells[x].cdr] -#define MACRO(x) g_cells[x].cdr -#define VALUE(x) g_cells[x].cdr -#define VECTOR(x) g_cells[x].cdr - -#define NLENGTH(x) g_news[x].car - -#define NVALUE(x) g_news[x].cdr -#define NVECTOR(x) g_news[x].cdr - -#define MAKE_CHAR(n) make_cell_ (tmp_num_ (TCHAR), 0, tmp_num2_ (n)) -#define MAKE_CONTINUATION(n) make_cell_ (tmp_num_ (TCONTINUATION), n, g_stack) -#define MAKE_NUMBER(n) make_cell_ (tmp_num_ (TNUMBER), 0, tmp_num2_ (n)) -#define MAKE_REF(n) make_cell_ (tmp_num_ (TREF), n, 0) -#define MAKE_STRING(x) make_cell_ (tmp_num_ (TSTRING), x, 0) - -#define CAAR(x) CAR (CAR (x)) -#define CADR(x) CAR (CDR (x)) -#define CDAR(x) CDR (CAR (x)) -#define CDDR(x) CDR (CDR (x)) -#define CADAR(x) CAR (CDR (CAR (x))) -#define CADDR(x) CAR (CDR (CDR (x))) -#define CDADAR(x) CAR (CDR (CAR (CDR (x)))) - -SCM -alloc (int n) -{ - assert (g_free + n < ARENA_SIZE); - SCM x = g_free; - g_free += n; - return x; -} - -SCM -tmp_num_ (int x) -{ - VALUE (tmp_num) = x; - return tmp_num; -} - -SCM -tmp_num2_ (int x) -{ - VALUE (tmp_num2) = x; - return tmp_num2; -} - -SCM -make_cell_ (SCM type, SCM car, SCM cdr) -{ - SCM x = alloc (1); - assert (TYPE (type) == TNUMBER); - TYPE (x) = VALUE (type); - if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER) { - if (car) CAR (x) = CAR (car); - if (cdr) CDR(x) = CDR(cdr); - } - else if (VALUE (type) == TFUNCTION) { - if (car) CAR (x) = car; - if (cdr) CDR(x) = CDR(cdr); - } - else { - CAR (x) = car; - CDR(x) = cdr; - } - return x; -} - -SCM -make_symbol_ (SCM s) ///((internal)) -{ - VALUE (tmp_num) = TSYMBOL; - SCM x = make_cell_ (tmp_num, s, 0); - g_symbols = cons (x, g_symbols); - return x; -} - -SCM -list_of_char_equal_p (SCM a, SCM b) ///((internal)) -{ - while (a != cell_nil && b != cell_nil && VALUE (CAR (a)) == VALUE (CAR (b))) { - assert (TYPE (CAR (a)) == TCHAR); - assert (TYPE (CAR (b)) == TCHAR); - a = CDR (a); - b = CDR (b); - } - return (a == cell_nil && b == cell_nil) ? cell_t : cell_f; -} - -SCM -lookup_symbol_ (SCM s) -{ - SCM x = g_symbols; - while (x) { - if (list_of_char_equal_p (STRING (CAR (x)), s) == cell_t) break; - x = CDR (x); - } - if (x) x = CAR (x); - if (!x) x = make_symbol_ (s); - return x; -} - -SCM -type_ (SCM x) -{ - return MAKE_NUMBER (TYPE (x)); -} - -SCM -car_ (SCM x) -{ - return (TYPE (x) != TCONTINUATION - && (TYPE (CAR (x)) == TPAIR // FIXME: this is weird - || TYPE (CAR (x)) == TREF - || TYPE (CAR (x)) == TSPECIAL - || TYPE (CAR (x)) == TSYMBOL - || TYPE (CAR (x)) == TSTRING)) ? CAR (x) : MAKE_NUMBER (CAR (x)); -} - -SCM -cdr_ (SCM x) -{ - return (TYPE (CDR (x)) == TPAIR - || TYPE (CDR (x)) == TREF - || TYPE (CAR (x)) == TSPECIAL - || TYPE (CDR (x)) == TSYMBOL - || TYPE (CDR (x)) == TSTRING) ? CDR (x) : MAKE_NUMBER (CDR (x)); -} - -SCM -arity_ (SCM x) -{ - assert (TYPE (x) == TFUNCTION); - return MAKE_NUMBER (FUNCTION (x).arity); -} - -SCM -cons (SCM x, SCM y) -{ - VALUE (tmp_num) = TPAIR; - return make_cell_ (tmp_num, x, y); -} - -SCM -car (SCM x) -{ - if (TYPE (x) != TPAIR) error (cell_symbol_not_a_pair, cons (x, cell_symbol_car)); - return CAR (x); -} - -SCM -cdr (SCM x) -{ - if (TYPE (x) != TPAIR) error (cell_symbol_not_a_pair, cons (x, cell_symbol_cdr)); - return CDR (x); -} - -SCM -list (SCM x) ///((arity . n)) -{ - return x; -} - -SCM -null_p (SCM x) -{ - return x == cell_nil ? cell_t : cell_f; -} - -SCM -eq_p (SCM x, SCM y) -{ - return (x == y - || ((TYPE (x) == TKEYWORD && TYPE (y) == TKEYWORD - && STRING (x) == STRING (y))) - || (TYPE (x) == TCHAR && TYPE (y) == TCHAR - && VALUE (x) == VALUE (y)) - || (TYPE (x) == TNUMBER && TYPE (y) == TNUMBER - && VALUE (x) == VALUE (y))) - ? cell_t : cell_f; -} - -SCM -values (SCM x) ///((arity . n)) -{ - SCM v = cons (0, x); - TYPE (v) = TVALUES; - return v; -} - -SCM -acons (SCM key, SCM value, SCM alist) -{ - return cons (cons (key, value), alist); -} - -SCM -length (SCM x) -{ - int n = 0; - while (x != cell_nil) - { - n++; - if (TYPE (x) != TPAIR) return MAKE_NUMBER (-1); - x = CDR (x); - } - return MAKE_NUMBER (n); -} - -SCM apply (SCM, SCM, SCM); - -SCM -error (SCM key, SCM x) -{ - SCM throw; - if ((throw = assq_ref_env (cell_symbol_throw, r0)) != cell_undefined) - return apply (throw, cons (key, cons (x, cell_nil)), r0); - display_error_ (key); - eputs (": "); - display_error_ (x); - eputs ("\n"); - exit (1); -} - -SCM -cstring_to_list (char const* s) -{ - SCM p = cell_nil; - int i = strlen (s); - while (i--) - p = cons (MAKE_CHAR (s[i]), p); - return p; -} - -// extra lib -SCM -assert_defined (SCM x, SCM e) ///((internal)) -{ - if (e == cell_undefined) return error (cell_symbol_unbound_variable, x); - return e; -} - -SCM -check_formals (SCM f, SCM formals, SCM args) ///((internal)) -{ - int flen = (TYPE (formals) == TNUMBER) ? VALUE (formals) : VALUE (length (formals)); - int alen = VALUE (length (args)); - if (alen != flen && alen != -1 && flen != -1) - { - char *s = "apply: wrong number of arguments; expected: "; - eputs (s); - eputs (itoa (flen)); - eputs (", got: "); - eputs (itoa (alen)); - eputs ("\n"); - display_error_ (f); - SCM e = MAKE_STRING (cstring_to_list (s)); - return error (cell_symbol_wrong_number_of_args, cons (e, f)); - } - return cell_unspecified; -} - -SCM -check_apply (SCM f, SCM e) ///((internal)) -{ - char* type = 0; - if (f == cell_f || f == cell_t) type = "bool"; - if (f == cell_nil) type = "nil"; - if (f == cell_unspecified) type = "*unspecified*"; - if (f == cell_undefined) type = "*undefined*"; - if (TYPE (f) == TCHAR) type = "char"; - if (TYPE (f) == TNUMBER) type = "number"; - if (TYPE (f) == TSTRING) type = "string"; - - if (type) - { - char *s = "cannot apply: "; - eputs (s); - eputs (type); - eputs ("["); - display_error_ (e); - eputs ("]\n"); - SCM e = MAKE_STRING (cstring_to_list (s)); - return error (cell_symbol_wrong_type_arg, cons (e, f)); - } - return cell_unspecified; -} - -SCM -gc_push_frame () ///((internal)) -{ - SCM frame = cons (r1, cons (r2, cons (r3, cons (r0, cell_nil)))); - g_stack = cons (frame, g_stack); - return g_stack; -} - -SCM -append2 (SCM x, SCM y) -{ - if (x == cell_nil) return y; - assert (TYPE (x) == TPAIR); - return cons (car (x), append2 (cdr (x), y)); -} - -SCM -pairlis (SCM x, SCM y, SCM a) -{ - if (x == cell_nil) - return a; - if (TYPE (x) != TPAIR) - return cons (cons (x, y), a); - return cons (cons (car (x), car (y)), - pairlis (cdr (x), cdr (y), a)); -} - -SCM -call (SCM fn, SCM x) -{ - if ((FUNCTION (fn).arity > 0 || FUNCTION (fn).arity == -1) - && x != cell_nil && TYPE (CAR (x)) == TVALUES) - x = cons (CADAR (x), CDR (x)); - if ((FUNCTION (fn).arity > 1 || FUNCTION (fn).arity == -1) - && x != cell_nil && TYPE (CDR (x)) == TPAIR && TYPE (CADR (x)) == TVALUES) - x = cons (CAR (x), cons (CDADAR (x), CDR (x))); - switch (FUNCTION (fn).arity) - { -#if __MESC__ || !_POSIX_SOURCE - case 0: return (FUNCTION (fn).function) (); - case 1: return ((SCM(*)(SCM))(FUNCTION (fn).function)) (CAR (x)); - case 2: return ((SCM(*)(SCM,SCM))(FUNCTION (fn).function)) (CAR (x), CADR (x)); - case 3: return ((SCM(*)(SCM,SCM,SCM))(FUNCTION (fn).function)) (CAR (x), CADR (x), CAR (CDDR (x))); - case -1: return ((SCM(*)(SCM))(FUNCTION (fn).function)) (x); - default: return ((SCM(*)(SCM))(FUNCTION (fn).function)) (x); -#else - 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), CAR (CDDR (x))); - case -1: return FUNCTION (fn).functionn (x); -#endif - } - - return cell_unspecified; -} - -SCM -assq (SCM x, SCM a) -{ - //FIXME: move into fast-non eq_p-ing assq core:assq? - //while (a != cell_nil && x != CAAR (a)) a = CDR (a); - while (a != cell_nil && eq_p (x, CAAR (a)) == cell_f) a = CDR (a); - return a != cell_nil ? CAR (a) : cell_f; -} - -SCM -assq_ref_env (SCM x, SCM a) -{ - x = assq (x, a); - if (x == cell_f) return cell_undefined; - return CDR (x); -} - -SCM -set_car_x (SCM x, SCM e) -{ - assert (TYPE (x) == TPAIR); - CAR (x) = e; - return cell_unspecified; -} - -SCM -set_cdr_x (SCM x, SCM e) -{ - if (TYPE (x) != TPAIR) error (cell_symbol_not_a_pair, cons (x, cell_set_cdr_x)); - CDR (x) = e; - return cell_unspecified; -} - -SCM -set_env_x (SCM x, SCM e, SCM a) -{ - SCM p = assert_defined (x, assq (x, a)); - if (TYPE (p) != TPAIR) error (cell_symbol_not_a_pair, cons (p, x)); - return set_cdr_x (p, e); -} - -SCM -call_lambda (SCM e, SCM x, SCM aa, SCM a) ///((internal)) -{ - SCM cl = cons (cons (cell_closure, x), x); - r1 = e; - r0 = cl; - return cell_unspecified; -} - -SCM -make_closure_ (SCM args, SCM body, SCM a) ///((internal)) -{ - return make_cell_ (tmp_num_ (TCLOSURE), cell_f, cons (cons (cell_circular, a), cons (args, body))); -} - -SCM -lookup_macro_ (SCM x, SCM a) ///((internal)) -{ - if (TYPE (x) != TSYMBOL) return cell_f; - SCM m = assq_ref_env (x, a); - if (TYPE (m) == TMACRO) return MACRO (m); - return cell_f; -} - -SCM -push_cc (SCM p1, SCM p2, SCM a, SCM c) ///((internal)) -{ - SCM x = r3; - r3 = c; - r2 = p2; - gc_push_frame (); - r1 = p1; - r0 = a; - r3 = x; - return cell_unspecified; -} - -SCM -gc_peek_frame () ///((internal)) -{ - SCM frame = CAR (g_stack); - r1 = CAR (frame); - r2 = CADR (frame); - r3 = CAR (CDDR (frame)); - r0 = CADR (CDDR (frame)); - return frame; -} - -SCM -gc_pop_frame () ///((internal)) -{ - SCM frame = gc_peek_frame (g_stack); - g_stack = CDR (g_stack); - return frame; -} - -SCM -eval_apply () -{ - eval_apply: - gc_check (); - switch (r3) - { - case cell_vm_evlis: goto evlis; - case cell_vm_evlis2: goto evlis2; - case cell_vm_evlis3: goto evlis3; - case cell_vm_apply: goto apply; - case cell_vm_apply2: goto apply2; - case cell_vm_eval: goto eval; -#if FIXED_PRIMITIVES - case cell_vm_eval_car: goto eval_car; - case cell_vm_eval_cdr: goto eval_cdr; - case cell_vm_eval_cons: goto eval_cons; - case cell_vm_eval_null_p: goto eval_null_p; -#endif - case cell_vm_eval_set_x: goto eval_set_x; - case cell_vm_eval_macro: goto eval_macro; - case cell_vm_eval_check_func: goto eval_check_func; - case cell_vm_eval2: goto eval2; - case cell_vm_macro_expand: goto macro_expand; - case cell_vm_begin: goto begin; - case cell_vm_begin_read_input_file: goto begin_read_input_file; - case cell_vm_begin2: goto begin2; - case cell_vm_if: goto vm_if; - case cell_vm_if_expr: goto if_expr; - case cell_vm_call_with_current_continuation2: goto call_with_current_continuation2; - case cell_vm_call_with_values2: goto call_with_values2; - case cell_vm_return: goto vm_return; - case cell_unspecified: return r1; - default: - assert (0); - } - - SCM x = cell_nil; - evlis: - gc_check (); - if (r1 == cell_nil) goto vm_return; - if (TYPE (r1) != TPAIR) goto eval; - push_cc (CAR (r1), r1, r0, cell_vm_evlis2); - goto eval; - evlis2: - push_cc (CDR (r2), r1, r0, cell_vm_evlis3); - goto evlis; - evlis3: - r1 = cons (r2, r1); - goto vm_return; - - apply: - gc_check (); - switch (TYPE (CAR (r1))) - { - case TFUNCTION: { - check_formals (CAR (r1), MAKE_NUMBER (FUNCTION (CAR (r1)).arity), CDR (r1)); - r1 = call (CAR (r1), CDR (r1)); /// FIXME: move into eval_apply - goto vm_return; - } - case TCLOSURE: - { - SCM cl = CLOSURE (CAR (r1)); - SCM formals = CADR (cl); - SCM body = CDDR (cl); - SCM aa = CDAR (cl); - aa = CDR (aa); - check_formals (CAR (r1), formals, CDR (r1)); - SCM p = pairlis (formals, CDR (r1), aa); - call_lambda (body, p, aa, r0); - goto begin; - } - case TCONTINUATION: - { - x = r1; - g_stack = CONTINUATION (CAR (r1)); - gc_pop_frame (); - r1 = CADR (x); - goto eval_apply; - } - case TSPECIAL: - { - switch (CAR (r1)) - { - case cell_vm_apply: - { - push_cc (cons (CADR (r1), CADDR (r1)), r1, r0, cell_vm_return); - goto apply; - } - case cell_vm_eval: - { - push_cc (CADR (r1), r1, CADDR (r1), cell_vm_return); - goto eval; - } - case cell_call_with_current_continuation: - { - r1 = CDR (r1); - goto call_with_current_continuation; - } - default: check_apply (cell_f, CAR (r1)); - } - } - case TSYMBOL: - { - if (CAR (r1) == cell_symbol_call_with_values) - { - r1 = CDR (r1); - goto call_with_values; - } - if (CAR (r1) == cell_symbol_current_module) - { - r1 = r0; - goto vm_return; - } - break; - } - case TPAIR: - { - switch (CAAR (r1)) - { - case cell_symbol_lambda: - { - SCM formals = CADR (CAR (r1)); - SCM body = CDDR (CAR (r1)); - SCM p = pairlis (formals, CDR (r1), r0); - check_formals (r1, formals, CDR (r1)); - call_lambda (body, p, p, r0); - goto begin; - } - } - } - } - push_cc (CAR (r1), r1, r0, cell_vm_apply2); - goto eval; - apply2: - check_apply (r1, CAR (r2)); - r1 = cons (r1, CDR (r2)); - goto apply; - - eval: - gc_check (); - switch (TYPE (r1)) - { - case TPAIR: - { - switch (CAR (r1)) - { -#if FIXED_PRIMITIVES - case cell_symbol_car: - { - push_cc (CADR (r1), r1, r0, cell_vm_eval_car); goto eval; - eval_car: - x = r1; gc_pop_frame (); r1 = CAR (x); goto eval_apply; - } - case cell_symbol_cdr: - { - push_cc (CADR (r1), r1, r0, cell_vm_eval_cdr); goto eval; - eval_cdr: - x = r1; gc_pop_frame (); r1 = CDR (x); goto eval_apply; - } - case cell_symbol_cons: { - push_cc (CDR (r1), r1, r0, cell_vm_eval_cons); goto evlis; - eval_cons: - x = r1; - gc_pop_frame (); - r1 = cons (CAR (x), CADR (x)); - goto eval_apply; - } - case cell_symbol_null_p: - { - push_cc (CADR (r1), r1, r0, cell_vm_eval_null_p); - goto eval; - eval_null_p: - x = r1; gc_pop_frame (); r1 = null_p (x); goto eval_apply; - } -#endif // FIXED_PRIMITIVES - case cell_symbol_quote: - { - x = r1; gc_pop_frame (); r1 = CADR (x); goto eval_apply; - } - case cell_symbol_begin: goto begin; - case cell_symbol_lambda: - { - r1 = make_closure_ (CADR (r1), CDDR (r1), assq (cell_closure, r0)); - goto vm_return; - } - case cell_symbol_if: {r1=CDR (r1); goto vm_if;} - case cell_symbol_set_x: - { - push_cc (CAR (CDDR (r1)), r1, r0, cell_vm_eval_set_x); - goto eval; - eval_set_x: - x = r2; - r1 = set_env_x (CADR (x), r1, r0); - goto vm_return; - } - case cell_vm_macro_expand: - { - push_cc (CADR (r1), r1, r0, cell_vm_return); - goto macro_expand; - } - default: { - push_cc (r1, r1, r0, cell_vm_eval_macro); - goto macro_expand; - eval_macro: - if (r1 != r2) - { - if (TYPE (r1) == TPAIR) - { - set_cdr_x (r2, CDR (r1)); - set_car_x (r2, CAR (r1)); - } - goto eval; - } - push_cc (CAR (r1), r1, r0, cell_vm_eval_check_func); goto eval; - eval_check_func: - push_cc (CDR (r2), r2, r0, cell_vm_eval2); goto evlis; - eval2: - r1 = cons (CAR (r2), r1); - goto apply; - } - } - } - case TSYMBOL: - { - r1 = assert_defined (r1, assq_ref_env (r1, r0)); - goto vm_return; - } - default: goto vm_return; - } - - SCM macro; - SCM expanders; - macro_expand: - if (TYPE (r1) == TPAIR - && (macro = lookup_macro_ (CAR (r1), r0)) != cell_f) - { - r1 = cons (macro, CDR (r1)); - goto apply; - } - else if (TYPE (r1) == TPAIR - && TYPE (CAR (r1)) == TSYMBOL - && ((expanders = assq_ref_env (cell_symbol_sc_expander_alist, r0)) != cell_undefined) - && ((macro = assq (CAR (r1), expanders)) != cell_f)) - { - SCM sc_expand = assq_ref_env (cell_symbol_macro_expand, r0); - if (sc_expand != cell_undefined && sc_expand != cell_f) - { - r1 = cons (sc_expand, cons (r1, cell_nil)); - goto apply; - } - } - goto vm_return; - - begin: - x = cell_unspecified; - while (r1 != cell_nil) { - gc_check (); - if (TYPE (r1) == TPAIR && TYPE (CAR (r1)) == TPAIR) - { - if (CAAR (r1) == cell_symbol_begin) - r1 = append2 (CDAR (r1), CDR (r1)); - else if (CAAR (r1) == cell_symbol_primitive_load) - { - push_cc (cons (cell_symbol_read_input_file, cell_nil), r1, r0, cell_vm_begin_read_input_file); - goto apply; - begin_read_input_file: - r1 = append2 (r1, CDR (r2)); - } - } - if (CDR (r1) == cell_nil) - { - r1 = CAR (r1); - goto eval; - } - push_cc (CAR (r1), r1, r0, cell_vm_begin2); - goto eval; - begin2: - x = r1; - r1 = CDR (r2); - } - r1 = x; - goto vm_return; - - vm_if: - push_cc (CAR (r1), r1, r0, cell_vm_if_expr); - goto eval; - if_expr: - x = r1; - r1 = r2; - if (x != cell_f) - { - r1 = CADR (r1); - goto eval; - } - if (CDDR (r1) != cell_nil) - { - r1 = CAR (CDDR (r1)); - goto eval; - } - r1 = cell_unspecified; - goto vm_return; - - call_with_current_continuation: - gc_push_frame (); - x = MAKE_CONTINUATION (g_continuations++); - gc_pop_frame (); - push_cc (cons (CAR (r1), cons (x, cell_nil)), x, r0, cell_vm_call_with_current_continuation2); - goto apply; - call_with_current_continuation2: - CONTINUATION (r2) = g_stack; - goto vm_return; - - call_with_values: - push_cc (cons (CAR (r1), cell_nil), r1, r0, cell_vm_call_with_values2); - goto apply; - call_with_values2: - if (TYPE (r1) == TVALUES) - r1 = CDR (r1); - r1 = cons (CADR (r2), r1); - goto apply; - - vm_return: - x = r1; - gc_pop_frame (); - r1 = x; - goto eval_apply; -} - -SCM -apply (SCM f, SCM x, SCM a) ///((internal)) -{ - push_cc (cons (f, x), cell_unspecified, r0, cell_unspecified); - r3 = cell_vm_apply; - return eval_apply (); -} - -SCM -mes_g_stack (SCM a) ///((internal)) -{ - r0 = a; - r1 = MAKE_CHAR (0); - r2 = MAKE_CHAR (0); - r3 = MAKE_CHAR (0); - g_stack = cons (cell_nil, cell_nil); - return r0; -} - -// Environment setup - -SCM -make_tmps (struct scm* cells) -{ - tmp = g_free++; - cells[tmp].type = TCHAR; - tmp_num = g_free++; - cells[tmp_num].type = TNUMBER; - tmp_num2 = g_free++; - cells[tmp_num2].type = TNUMBER; - return 0; -} - -#include "posix.c" -#include "math.c" -#include "lib.c" - -// Jam Collector -SCM g_symbol_max; - -SCM -gc_init_cells () ///((internal)) -{ - int size = ARENA_SIZE * 12; - size = size * 2; -#if __GNUC__ - g_arena = (char*)malloc (size); -#else - char *p = 0; - p = malloc (size); - g_arena = p; -#endif - g_cells = g_arena; - return 0; - //g_cells = (scm *)malloc (2*ARENA_SIZE*sizeof(scm)); - - TYPE (0) = TVECTOR; - LENGTH (0) = 1000; - VECTOR (0) = 0; - g_cells++; - TYPE (0) = TCHAR; - VALUE (0) = 'c'; - return 0; -} - -SCM -gc_init_news () ///((internal)) -{ - eputs ("gc_init_news\n"); - ///g_news = g_cells-1 + ARENA_SIZE; - //g_news = g_cells + ARENA_SIZE * 12 + GC_SAFETY * 6; - char *p = g_cells; - // g_news = g_cells; - int halfway = ARENA_SIZE * 12; - int safety = GC_SAFETY * 12; - safety = safety / 2; - halfway = halfway + safety; - // g_news = g_news + halfway; - p = p + halfway; - g_news = p; - eputs ("g_cells="); - eputs (itoa (g_cells)); - eputs (" size="); - eputs (itoa (halfway)); - eputs (" news="); - eputs (itoa (g_news)); - eputs (" news - cells="); - char * c = g_cells; - eputs (itoa (p - c)); - eputs ("\n"); - - - NTYPE (0) = TVECTOR; - NLENGTH (0) = 1000; - NVECTOR (0) = 0; - g_news++; - NTYPE (0) = TCHAR; - NVALUE (0) = 'n'; - return 0; -} - -SCM -mes_symbols () ///((internal)) -{ - gc_init_cells (); - gc_init_news (); - -#include "mes.mes.symbols.i" - - g_symbol_max = g_free; - make_tmps (g_cells); - - g_symbols = 0; - for (int i=1; i 1 && !strcmp (argv[1], "--help")) return puts ("Usage: mes [--dump|--load] < FILE\n"); - if (argc > 1 && !strcmp (argv[1], "--version")) {puts ("Mes ");puts (VERSION);puts ("\n");return 0;}; - g_stdout = STDOUT; - r0 = mes_environment (); - - SCM program = bload_env (r0); - SCM lst = cell_nil; - for (int i=argc-1; i>=0; i--) lst = cons (MAKE_STRING (cstring_to_list (argv[i])), lst); - r0 = acons (cell_symbol_argv, lst, r0); - push_cc (r2, cell_unspecified, r0, cell_unspecified); - if (g_debug) - { - eputs ("program: "); - display_error_ (r1); - eputs ("\n"); - } - r3 = cell_vm_begin; - r1 = eval_apply (); - display_error_ (r1); - eputs ("\n"); - gc (g_stack); - if (g_debug) - { - eputs ("\nstats: ["); - eputs (itoa (g_free)); - eputs ("]\n"); - } - return 0; -} diff --git a/scaffold/scaffold.make b/scaffold/scaffold.make index f273ae18..fbc215d7 100644 --- a/scaffold/scaffold.make +++ b/scaffold/scaffold.make @@ -52,21 +52,6 @@ $(TEST): $(OUT)/micro-mes.mlibc $< 2 3; r=$$?; [ $$r = 3 ] include make/check.make -TARGET:=tiny-mes.mlibc -C_FILES:=$(DIR)/tiny-mes.c -include make/bin-mlibc.make - -TARGET:=tiny-mes.mlibc -include make/check.make - -TARGET:=cons-mes.mlibc -C_FILES:=$(DIR)/cons-mes.c -DEFINES:=VERSION='"$(VERSION)"' -include make/bin-mlibc.make - -TARGET:=cons-mes.mlibc -include make/check.make - TARGET:=t.mlibc C_FILES:=$(DIR)/t.c include make/bin-mlibc.make @@ -74,21 +59,6 @@ include make/bin-mlibc.make TARGET:=t.mlibc include make/check.make -CROSS:=$(CC32:%gcc=%) -#$(OUT)/$(DIR)/mini-mes.$(CROSS)o: $(SNARF.MES) -$(OUT)/mini-mes: $(SNARF.MES) - -TARGET:=mini-mes.mlibc -C_FILES:=$(DIR)/mini-mes.c -DEFINES:=FIXED_PRIMITIVES=1 VERSION='"$(VERSION)"' MODULEDIR='"$(MODULEDIR)"' PREFIX='"$(PREFIX)"' -INCLUDES:=src $(OUT)/src -include make/bin-mlibc.make - -TEST:=mini-mes.mlibc-check -$(TEST): $(OUT)/mini-mes.mlibc - echo 0 | $< -include make/check.make - # guile/mescc.scm TARGET:=m.guile @@ -116,21 +86,6 @@ $(TEST): $(OUT)/micro-mes.guile $< 2 3; r=$$?; [ $$r = 3 ] include make/check.make -$(OUT)/tiny-mes.mes: module/mes/tiny-0-32.mo -TARGET:=tiny-mes.guile -C_FILES:=$(DIR)/tiny-mes.c -include make/mescc-guile.make - -TARGET:=tiny-mes.guile -include make/check.make - -TARGET:=cons-mes.guile -C_FILES:=$(DIR)/cons-mes.c -include make/mescc-guile.make - -TARGET:=cons-mes.guile -include make/check.make - TARGET:=t.guile C_FILES:=$(DIR)/t.c include make/mescc-guile.make @@ -138,16 +93,6 @@ include make/mescc-guile.make TARGET:=t.guile include make/check.make -$(OUT)/mini-mes.guile: module/mes/read-0-32.mo -TARGET:=mini-mes.guile -C_FILES:=$(DIR)/mini-mes.c -include make/mescc-guile.make - -TEST:=mini-mes.guile-check -$(TEST): $(OUT)/mini-mes.guile - echo 0 | $< -include make/check.make - # scripts/mescc.mes ifeq ($(MES_SKIP_MES),) TARGET:=m.mes @@ -175,21 +120,6 @@ TEST:=micro-mes.mes-check $(TEST): $(OUT)/micro-mes.mes $< 2 3; r=$$?; [ $$r = 3 ] include make/check.make - -$(OUT)/tiny-mes.mes: module/mes/tiny-0-32.mo -TARGET:=tiny-mes.mes -C_FILES:=$(DIR)/tiny-mes.c -include make/mescc-mes.make - -TARGET:=tiny-mes.mes -include make/check.make - -TARGET:=cons-mes.mes -C_FILES:=$(DIR)/cons-mes.c -include make/mescc-mes.make - -TARGET:=cons-mes.mes -include make/check.make endif # !SCAFFOLD TARGET:=t.mes @@ -199,10 +129,3 @@ include make/mescc-mes.make TARGET:=t.mes include make/check.make endif - -ifneq ($(BOOTSTRAP),) -$(OUT)/mini-mes.mes: module/mes/read-0-32.mo -TARGET:=mini-mes.mes -C_FILES:=$(DIR)/mini-mes.c -include make/mescc-mes.make -endif diff --git a/scaffold/tiny-mes.c b/scaffold/tiny-mes.c deleted file mode 100644 index bef6acd6..00000000 --- a/scaffold/tiny-mes.c +++ /dev/null @@ -1,341 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * Mes --- Maxwell Equations of Software - * Copyright © 2016,2017 Jan Nieuwenhuizen - * - * 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 . - */ - -#if POSIX -#error "POSIX not supported" -#endif - -#include -#include - -char arena[300]; - -typedef int SCM; - -SCM g_stack = 0; -SCM r0 = 0; // a/env -SCM r1 = 0; // param 1 -SCM r2 = 0; // save 2+load/dump -SCM r3 = 0; // continuation - -enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART}; - -struct scm { - enum type_t type; - SCM car; - SCM cdr; -}; - -#if __MESC__ -struct scm *g_cells = arena; -#else -struct scm *g_cells = (struct scm*)arena; -#endif - -#define cell_nil 1 -#define cell_f 2 -#define cell_t 3 - -#define TYPE(x) (g_cells[x].type) - -#define CAR(x) g_cells[x].car - -#define CDR(x) g_cells[x].cdr -#define VALUE(x) g_cells[x].cdr - -SCM -car (SCM x) -{ - return CAR (x); -} - -SCM -cdr (SCM x) -{ - return CDR (x); -} - -SCM caar (SCM x) {return car (car (x));} -SCM cadr (SCM x) {return car (cdr (x));} -SCM cdar (SCM x) {return cdr (car (x));} -SCM cddr (SCM x) {return cdr (cdr (x));} - -SCM -gc_peek_frame () -{ - SCM frame = car (g_stack); - r1 = car (frame); - r2 = cadr (frame); - r3 = car (cddr (frame)); - r0 = cadr (cddr (frame)); - return frame; -} - -// Environment setup - -SCM -mes_environment () -{ - return 0; -} - -SCM -mes_builtins (SCM a) -{ - return a; -} - -SCM -fill () -{ - TYPE (0) = 0x6c6c6168; - CAR (0) = 0x6a746f6f; - CDR (0) = 0x00002165; - - TYPE (1) = TSYMBOL; - CAR (1) = 0x2d2d2d2d; - CDR (1) = 0x3e3e3e3e; - - TYPE (9) = 0x2d2d2d2d; - CAR (9) = 0x2d2d2d2d; - CDR (9) = 0x3e3e3e3e; - - // (A(B)) - TYPE (10) = TPAIR; - CAR (10) = 11; - CDR (10) = 12; - - TYPE (11) = TCHAR; - CAR (11) = 0x58585858; - CDR (11) = 89; - - TYPE (12) = TPAIR; - CAR (12) = 13; - CDR (12) = 1; - - TYPE (13) = TCHAR; - CAR (11) = 0x58585858; - CDR (13) = 90; - - TYPE (14) = 0x58585858; - CAR (14) = 0x58585858; - CDR (14) = 0x58585858; - - TYPE (14) = 0x58585858; - CAR (14) = 0x58585858; - CDR (14) = 0x58585858; - - TYPE (16) = 0x3c3c3c3c; - CAR (16) = 0x2d2d2d2d; - CDR (16) = 0x2d2d2d2d; - return 0; -} - -SCM -display_ (SCM x) -{ - //puts ("\n"); - switch (TYPE (x)) - { - case TCHAR: - { - //puts ("\n"); - puts ("#\\"); - putchar (VALUE (x)); - break; - } - case TFUNCTION: - { - //puts ("\n"); - if (VALUE (x) == 0) - puts ("core:make-cell"); - if (VALUE (x) == 1) - puts ("cons"); - if (VALUE (x) == 2) - puts ("car"); - if (VALUE (x) == 3) - puts ("cdr"); - break; - } - case TNUMBER: - { - //puts ("\n"); -#if __GNUC__ - puts (itoa (VALUE (x))); -#else - int i; - i = VALUE (x); - i = i + 48; - putchar (i); -#endif - break; - } - case TPAIR: - { - //puts ("\n"); - //if (cont != cell_f) puts "("); - puts ("("); - if (x && x != cell_nil) display_ (CAR (x)); - if (CDR (x) && CDR (x) != cell_nil) - { -#if __GNUC__ - if (TYPE (CDR (x)) != TPAIR) - puts (" . "); -#else - int c; - c = CDR (x); - c = TYPE (c); - if (c != TPAIR) - puts (" . "); -#endif - display_ (CDR (x)); - } - //if (cont != cell_f) puts (")"); - puts (")"); - break; - } - case TSPECIAL: - { - switch (x) - { - case 1: {puts ("()"); break;} - case 2: {puts ("#f"); break;} - case 3: {puts ("#t"); break;} - default: - { -#if __GNUC__ - puts (""); -#else - puts (""); -#endif - } - } - break; - } - case TSYMBOL: - { - switch (x) - { - case 11: {puts (" . "); break;} - case 12: {puts ("lambda"); break;} - case 13: {puts ("begin"); break;} - case 14: {puts ("if"); break;} - case 15: {puts ("quote"); break;} - case 37: {puts ("car"); break;} - case 38: {puts ("cdr"); break;} - case 39: {puts ("null?"); break;} - case 40: {puts ("eq?"); break;} - case 41: {puts ("cons"); break;} - default: - { -#if __GNUC__ - puts (""); -#else - puts (""); -#endif - } - } - break; - } - default: - { - //puts ("\n"); -#if __GNUC__ - puts ("<"); - puts (itoa (TYPE (x))); - puts (":"); - puts (itoa (x)); - puts (">"); -#else - puts ("_"); -#endif - break; - } - } - return 0; -} - -SCM -bload_env (SCM a) ///((internal)) -{ - puts ("reading: "); - char *mo = "module/mes/tiny-0-32.mo"; - puts (mo); - puts ("\n"); - g_stdin = open (mo, 0); - if (g_stdin < 0) {eputs ("no such file: module/mes/tiny-0-32.mo\n");return 1;} - - // BOOM - //char *p = arena; - char *p = (char*)g_cells; - int c; - - c = getchar (); - putchar (c); - if (c != 'M') exit (10); - c = getchar (); - putchar (c); - if (c != 'E') exit (11); - c = getchar (); - putchar (c); - if (c != 'S') exit (12); - puts (" *GOT MES*\n"); - - // skip stack - getchar (); - getchar (); - - int i = 0; - c = getchar (); - while (c != -1) - { - i++; - eputs (itoa (i)); - eputs (": "); - eputs (itoa (c)); - eputs ("\n"); - *p++ = c; - c = getchar (); - } - - puts ("read done\n"); - display_ (10); - - puts ("\n"); - return r2; -} - -int -main (int argc, char *argv[]) -{ - fill (); - char *p = arena; - puts (p); - puts ("\n"); - display_ (10); - puts ("\n"); - SCM program = bload_env (r0); - - return 0; -} diff --git a/scripts/mes b/scripts/mes deleted file mode 120000 index 4e5ce6ef..00000000 --- a/scripts/mes +++ /dev/null @@ -1 +0,0 @@ -../out/mes \ No newline at end of file diff --git a/src/mes.c b/src/mes.c index c43d4662..bdac87be 100644 --- a/src/mes.c +++ b/src/mes.c @@ -209,9 +209,7 @@ int g_function = 0; #include "math.mes.h" #include "mes.mes.h" #include "posix.mes.h" -#if MES_FULL #include "reader.mes.h" -#endif #include "vector.mes.h" #else #include "gc.h" @@ -1187,18 +1185,14 @@ mes_builtins (SCM a) ///((internal)) #include "lib.mes.i" #include "vector.mes.i" #include "gc.mes.i" -#if MES_FULL #include "reader.mes.i" -#endif #include "gc.mes.environment.i" #include "lib.mes.environment.i" #include "math.mes.environment.i" #include "mes.mes.environment.i" #include "posix.mes.environment.i" -#if MES_FULL #include "reader.mes.environment.i" -#endif #include "vector.mes.environment.i" #else #include "mes.i" @@ -1325,9 +1319,7 @@ bload_env (SCM a) ///((internal)) #include "vector.c" #include "gc.c" -#if _POSIX_SOURCE || MES_FULL #include "reader.c" -#endif int main (int argc, char *argv[]) @@ -1343,14 +1335,10 @@ main (int argc, char *argv[]) g_stdout = STDOUT; r0 = mes_environment (); -#if __MESC__ - SCM program = bload_env (r0); -#else SCM program = (argc > 1 && !strcmp (argv[1], "--load")) ? bload_env (r0) : load_env (r0); g_tiny = argc > 2 && !strcmp (argv[2], "--tiny"); if (argc > 1 && !strcmp (argv[1], "--dump")) return dump (); -#endif SCM lst = cell_nil; for (int i=argc-1; i>=0; i--) lst = cons (MAKE_STRING (cstring_to_list (argv[i])), lst); diff --git a/src/reader.c b/src/reader.c index 8883398f..6d52e0d8 100644 --- a/src/reader.c +++ b/src/reader.c @@ -20,12 +20,6 @@ #include -SCM -___end_of_mes___ () -{ - return 0; -} - SCM read_input_file_env_ (SCM e, SCM a) { @@ -130,46 +124,12 @@ dump () putchar ('S'); putchar (g_stack >> 8); putchar (g_stack % 256); - // See HACKING, simple crafted dump for tiny-mes.c - if (g_tiny || getenv ("MES_TINY")) + eputs ("dumping\n"); + if (g_debug > 1) { - eputs ("dumping TINY\n"); - - TYPE (9) = 0x2d2d2d2d; - CAR (9) = 0x2d2d2d2d; - CDR (9) = 0x3e3e3e3e; - - TYPE (10) = TPAIR; - CAR (10) = 11; - CDR (10) = 12; - - TYPE (11) = TCHAR; - CAR (11) = 0x58585858; - CDR (11) = 65; - - TYPE (12) = TPAIR; - CAR (12) = 13; - CDR (12) = 1; - - TYPE (13) = TCHAR; - CAR (11) = 0x58585858; - CDR (13) = 66; - - TYPE (14) = 0x3c3c3c3c; - CAR (14) = 0x2d2d2d2d; - CDR (14) = 0x2d2d2d2d; - - g_free = 15; - } - else - { - eputs ("dumping FULL\n"); - if (g_debug > 1) - { - eputs ("program r2="); - display_error_ (r2); - eputs ("\n"); - } + eputs ("program r2="); + display_error_ (r2); + eputs ("\n"); } for (int i=0; i