diff --git a/.gitignore b/.gitignore index 76c911a8..237a4360 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.h *.i *.o +*.o-32 *.symbols.i *~ .#* @@ -33,6 +34,8 @@ /guile-t /guile-tiny-mes +/mes-mini-mes + /module/mes/tiny-0-32.mo #keep this: bootstrap #/module/mes/read-0-32.mo diff --git a/GNUmakefile b/GNUmakefile index f14c522d..af7a51bb 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -26,20 +26,21 @@ endif -include .local.make -all: mes module/mes/read-0.mo +all: mes module/mes/read-0.mo module/mes/read-0-32.mo -mes.o: GNUmakefile -mes.o: mes.c -mes.o: mes.c mes.h mes.i mes.environment.i mes.symbols.i -mes.o: lib.c lib.h lib.i lib.environment.i -mes.o: math.c math.h math.i math.environment.i -mes.o: posix.c posix.h posix.i posix.environment.i -mes.o: reader.c reader.h reader.i reader.environment.i -mes.o: gc.c gc.h gc.i gc.environment.i -mes.o: vector.c vector.h vector.i vector.environment.i +S:= +mes.o$(S): GNUmakefile +mes.o$(S): mes.c +mes.o$(S): mes.c mes.h mes.i mes.environment.i mes.symbols.i +mes.o$(S): lib.c lib.h lib.i lib.environment.i +mes.o$(S): math.c math.h math.i math.environment.i +mes.o$(S): posix.c posix.h posix.i posix.environment.i +mes.o$(S): reader.c reader.h reader.i reader.environment.i +mes.o$(S): gc.c gc.h gc.i gc.environment.i +mes.o$(S): vector.c vector.h vector.i vector.environment.i clean: - rm -f mes *.o *.environment.i *.symbols.i *.environment.h *.cat a.out + rm -f mes *.o *.o-32 *.environment.i *.symbols.i *.environment.h *.cat a.out rm -f mes-32 rm -f cons-mes m main micro-mes mini-mes t tiny-mes rm -f guile-cons-mes guile-m guile-main guile-micro-mes guile-mini-mes guile-t guile-tiny-mes @@ -90,23 +91,27 @@ MES_DEBUG:=1 mes-check: all set -e; for i in $(TESTS); do ./$$i; done -mes-check-nyacc: all - scripts/nyacc.mes - scripts/nyacc-calc.mes +mini-mes-check: all mini-mes + $(MAKE) mes-check MES=./mini-mes module/mes/read-0.mo: module/mes/read-0.mes mes ./mes --dump < $< > $@ dump: module/mes/read-0.mo -mes-32: gc.c lib.c math.c posix.c vector.c -mes-32: mes.c lib.c - rm -f mes mes.o - guix environment --system=i686-linux --ad-hoc gcc-toolchain -- bash -c 'make mes CC=i686-unknown-linux-gnu-gcc LIBRARY_PATH=$${PATH%%/bin:*}/lib' - rm -f mes.o - mv mes mes-32 +mes.o$(S): mes.c + $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< -module/mes/read-0-32.mo: module/mes/read-0.mes mes-32 +mes$(S): mes.o$(S) + $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ + +mes$(S)-32: GNUmakefile +mes$(S)-32: mes.c gc.c lib.c math.c posix.c vector.c + guix environment --system=i686-linux --ad-hoc gcc-toolchain -- bash -c 'make mes-32 S=-32 CC=i686-unknown-linux-gnu-gcc LIBRARY_PATH=$${PATH%%/bin:*}/lib' + +module/mes/read-0-32.mo: module/mes/read-0.mes +module/mes/read-0-32.mo: module/mes/read-0.mo +module/mes/read-0-32.mo: mes-32 MES_MINI=1 ./mes-32 --dump < $< > $@ module/mes/tiny-0-32.mo: module/mes/tiny-0.mes mes-32 @@ -116,7 +121,6 @@ guile-check: set -e; for i in $(TESTS); do\ $(GUILE) -s <(cat $(MES-0) module/mes/test.mes $$i);\ done - guile/nyacc-calc.scm t-check: t ./t @@ -127,33 +131,51 @@ mescc-check: t-check chmod +x a.out ./a.out -%.h %.i %.environment.i %.symbols.i: scaffold/%.c build-aux/mes-snarf.scm - build-aux/mes-snarf.scm $< +%.h %.i %.environment.i %.symbols.i: scaffold/%.c build-aux/mes-snarf.scm GNUmakefile + build-aux/mes-snarf.scm --mini $< + +mini-%.h mini-%.i mini-%.environment.i mini-%.symbols.i: %.c build-aux/mes-snarf.scm GNUmakefile + build-aux/mes-snarf.scm --mini $< + +mini-mes.h mini-mes.i mini-mes.environment.i mini-mes.symbols.i: scaffold/mini-mes.c build-aux/mes-snarf.scm GNUmakefile + build-aux/mes-snarf.scm --mini $< mini-mes: mini-mes.h mini-mes.i mini-mes.environment.i mini-mes.symbols.i -mini-mes: vector.c -mini-mes: gc.c +mini-mes: gc.c mini-gc.h mini-gc.i mini-gc.environment.i +mini-mes: vector.c mini-vector.h mini-vector.i mini-vector.environment.i mini-mes: mlibc.c mstart.c mini-mes: GNUmakefile mini-mes: module/mes/read-0-32.mo mini-mes: scaffold/mini-mes.c rm -f $@ - # gcc -nostdlib --std=gnu99 -m32 -g -o $@ '-DPREFIX=' '-DVERSION='"$(VERSION)"' $< - gcc -nostdlib -I. --std=gnu99 -m32 -g -I. -o $@ $(CPPFLAGS) $< + gcc -nostdlib --std=gnu99 -m32 -g -o $@ $(CPPFLAGS) $< rm -f mes.o chmod +x $@ guile-mini-mes: mini-mes.h mini-mes.i mini-mes.environment.i mini-mes.symbols.i -guile-mini-mes: vector.c +guile-mini-mes: gc.c mini-gc.h mini-gc.i mini-gc.environment.i +guile-mini-mes: vector.c mini-vector.h mini-vector.i mini-vector.environment.i +guile-mini-mes: mlibc.c mstart.c +guile-mini-mes: GNUmakefile guile-mini-mes: module/mes/read-0-32.mo guile-mini-mes: scaffold/mini-mes.c guile/mescc.scm $< > $@ || rm -f $@ chmod +x $@ +mes-mini-mes: mini-mes.h mini-mes.i mini-mes.environment.i mini-mes.symbols.i +mes-mini-mes: gc.c mini-gc.h mini-gc.i mini-gc.environment.i +mes-mini-mes: vector.c mini-vector.h mini-vector.i mini-vector.environment.i +mes-mini-mes: mlibc.c mstart.c +mes-mini-mes: GNUmakefile +mes-mini-mes: module/mes/read-0-32.mo +mes-mini-mes: scaffold/mini-mes.c + MES_FLAGS= MES_DEBUG=1 scripts/mescc.mes $< > $@ || rm -f $@ + chmod +x $@ + cons-mes: module/mes/tiny-0-32.mo cons-mes: scaffold/cons-mes.c GNUmakefile rm -f $@ - gcc -nostdlib -I. --std=gnu99 -m32 -g -o $@ '-DVERSION="0.4"' $< + gcc -nostdlib --std=gnu99 -m32 -g -o $@ $(CPPFLAGS) $< chmod +x $@ guile-cons-mes: module/mes/tiny-0-32.mo @@ -164,7 +186,7 @@ guile-cons-mes: scaffold/cons-mes.c tiny-mes: module/mes/tiny-0-32.mo tiny-mes: scaffold/tiny-mes.c GNUmakefile rm -f $@ - gcc -nostdlib -I. --std=gnu99 -m32 -g -o $@ '-DVERSION="0.4"' $< + gcc -nostdlib --std=gnu99 -m32 -g -o $@ $(CPPFLAGS) $< chmod +x $@ guile-tiny-mes: module/mes/tiny-0-32.mo @@ -174,8 +196,8 @@ guile-tiny-mes: scaffold/tiny-mes.c m: scaffold/m.c GNUmakefile rm -f $@ - gcc -nostdlib -I. --std=gnu99 -m32 -g -o $@ '-DVERSION="0.4"' $< -# gcc --std=gnu99 -g -o $@ '-DVERSION="0.4"' $< + gcc -nostdlib --std=gnu99 -m32 -g -o $@ $(CPPFLAGS) $< +# gcc --std=gnu99 -g -o $@ $(CPPFLAGS) $< chmod +x $@ guile-m: scaffold/m.c @@ -184,7 +206,7 @@ guile-m: scaffold/m.c malloc: scaffold/malloc.c GNUmakefile rm -f $@ - gcc -nostdlib -I. --std=gnu99 -m32 -g -o $@ '-DVERSION="0.4"' $< + gcc -nostdlib --std=gnu99 -m32 -g -o $@ $(CPPFLAGS) $< chmod +x $@ guile-malloc: scaffold/malloc.c @@ -193,7 +215,7 @@ guile-malloc: scaffold/malloc.c micro-mes: scaffold/micro-mes.c GNUmakefile rm -f $@ - gcc -nostdlib -I. --std=gnu99 -m32 -o $@ '-DVERSION="0.4"' $< + gcc -nostdlib --std=gnu99 -m32 -o $@ $(CPPFLAGS) $< chmod +x $@ guile-micro-mes: scaffold/micro-mes.c @@ -202,7 +224,7 @@ guile-micro-mes: scaffold/micro-mes.c main: doc/examples/main.c GNUmakefile rm -f $@ - gcc -nostdlib -I. --std=gnu99 -m32 -o $@ '-DVERSION="0.4"' $< + gcc -nostdlib --std=gnu99 -m32 -o $@ $(CPPFLAGS) $< chmod +x $@ guile-main: doc/examples/main.c @@ -212,7 +234,7 @@ guile-main: doc/examples/main.c t: mlibc.c t: scaffold/t.c GNUmakefile rm -f $@ - gcc -nostdlib -I. --std=gnu99 -m32 -g -o $@ '-DVERSION="0.4"' $< + gcc -nostdlib --std=gnu99 -m32 -g -o $@ $(CPPFLAGS) $< chmod +x $@ guile-t: scaffold/t.c @@ -231,9 +253,6 @@ guile-mescc: $(MAIN_C) chmod +x a.out ./a.out; r=$$?; [ $$r = 42 ] -paren: all - scripts/paren.mes - GUILE_GIT:=$(HOME)/src/guile-1.8 GUILE_COMMIT:=ba8a709 psyntax-import: module/mes/psyntax.ss module/mes/psyntax.pp diff --git a/build-aux/mes-snarf.scm b/build-aux/mes-snarf.scm index 05215a2a..9bebfa97 100755 --- a/build-aux/mes-snarf.scm +++ b/build-aux/mes-snarf.scm @@ -4,7 +4,7 @@ exec ${GUILE-guile} --no-auto-compile -L $HOME/src/mes/build-aux -L build-aux -e !# ;;; Mes --- Maxwell Equations of Software -;;; Copyright © 2016 Jan Nieuwenhuizen +;;; Copyright © 2016,2017 Jan Nieuwenhuizen ;;; ;;; mes-snarf.scm: This file is part of Mes. ;;; @@ -34,7 +34,7 @@ exec ${GUILE-guile} --no-auto-compile -L $HOME/src/mes/build-aux -L build-aux -e (cut regexp-substitute #f <> 'pre replace 'post)) string)) -(define GCC? #f) +(define %gcc? #t) ;; (define-record-type function (make-function name formals annotation) ;; function? ;; (name .name) @@ -84,7 +84,7 @@ exec ${GUILE-guile} --no-auto-compile -L $HOME/src/mes/build-aux -L build-aux -e (format #f "g_cells[cell_~a] = scm_~a;\n\n" s s))) (define (symbol->names s i) - (if GCC? + (if %gcc? (format #f "g_cells[cell_~a].car = cstring_to_list (scm_~a.name);\n" s s) (format #f "g_cells[cell_~a].car = cstring_to_list (scm_~a.car);\n" s s))) @@ -95,17 +95,17 @@ exec ${GUILE-guile} --no-auto-compile -L $HOME/src/mes/build-aux -L build-aux -e (n (if (eq? arity 'n) -1 arity))) (string-append (format #f "SCM ~a (~a);\n" (.name f) (.formals f)) - (if GCC? + (if %gcc? (format #f "struct function fun_~a = {.function~a=&~a, .arity=~a, .name=~s};\n" (.name f) arity (.name f) n (function-scm-name f)) (format #f "struct function fun_~a = {&~a, ~a, ~s};\n" (.name f) (.name f) n (function-scm-name f))) - (if GCC? + (if %gcc? (format #f "struct scm ~a = {TFUNCTION, .name=0, .function=0};\n" (function-builtin-name f)) (format #f "struct scm ~a = {TFUNCTION, 0, 0};\n" (function-builtin-name f))) (format #f "SCM cell_~a;\n\n" (.name f))))) (define (function->source f i) (string-append - (if GCC? + (if %gcc? (format #f "~a.function = g_function;\n" (function-builtin-name f)) (format #f "~a.cdr = g_function;\n" (function-builtin-name f))) (format #f "g_functions[g_function++] = fun_~a;\n" (.name f)) @@ -114,13 +114,13 @@ exec ${GUILE-guile} --no-auto-compile -L $HOME/src/mes/build-aux -L build-aux -e (define (function->environment f i) (string-append - (if GCC? + (if %gcc? (format #f "scm_~a.string = cstring_to_list (fun_~a.name);\n" (.name f) (.name f)) (format #f "scm_~a.car = cstring_to_list (fun_~a.name);\n" (.name f) (.name f))) - (if GCC? + (if %gcc? (format #f "g_cells[cell_~a].string = MAKE_STRING (scm_~a.string);\n" (.name f) (.name f)) (format #f "g_cells[cell_~a].car = MAKE_STRING (scm_~a.car);\n" (.name f) (.name f))) - (if GCC? + (if %gcc? (format #f "a = acons (lookup_symbol_ (scm_~a.string), ~a, a);\n\n" (.name f) (function-cell-name f)) (format #f "a = acons (lookup_symbol_ (scm_~a.car), ~a, a);\n\n" (.name f) (function-cell-name f))))) @@ -155,6 +155,8 @@ exec ${GUILE-guile} --no-auto-compile -L $HOME/src/mes/build-aux -L build-aux -e (functions (filter (negate internal?) functions)) (symbols (snarf-symbols string)) (base-name (basename file-name ".c")) + (base-name (if (or %gcc? (string-prefix? "mini-" base-name)) base-name + (string-append "mini-" base-name))) (header (make #:name (string-append base-name ".h") #:content (string-join (map function->header functions (iota (length functions) (+ %start (length symbols)))) ""))) @@ -179,7 +181,9 @@ exec ${GUILE-guile} --no-auto-compile -L $HOME/src/mes/build-aux -L build-aux -e (with-output-to-file (.name file) (lambda () (display (.content file))))) (define (main args) - (let* ((files (cdr args))) + (let* ((files (if (not (and (pair? (cdr args)) (equal? (cadr args) "--mini"))) (cdr args) + (begin (set! %gcc? #f) + (cddr args))))) (map file-write (filter content? (append-map generate-includes files))))) ;;(define string (with-input-from-file "../mes.c" read-string)) diff --git a/doc/examples/main.c b/doc/examples/main.c index 483496c6..8082efb6 100644 --- a/doc/examples/main.c +++ b/doc/examples/main.c @@ -18,19 +18,21 @@ * along with Mes. If not, see . */ -#if __GNUC__ -#include "mlibc.c" -#endif +#define GNU 0 +// #if __GNUC__ +// #include "mlibc.c" +// #endif int //main () main (int argc, char *argv[]) { - puts ("Hi Mes!\n"); - if (argc > 1 && !strcmp (argv[1], "--help")) return puts ("argc > 1 && --help\n"); + //puts ("Hi Mes!\n"); + //if (argc > 1 && !strcmp (argv[1], "--help")) return puts ("argc > 1 && --help\n"); + if (argc > 1) return argc; return 42; } -#if __GNUC__ -#include "mstart.c" -#endif +// #if __GNUC__ +// #include "mstart.c" +// #endif diff --git a/lib.c b/lib.c index b458e561..5d33bb87 100644 --- a/lib.c +++ b/lib.c @@ -54,7 +54,7 @@ display_helper (SCM x, int cont, char* sep, FILE *fd) case TFUNCTION: { fputs ("# 1 && !strcmp (argv[1], "--help")) return puts ("Usage: mes [--dump|--load] < FILE"); if (argc > 1 && !strcmp (argv[1], "--version")) {puts ("Mes ");puts (VERSION);return 0;}; - g_stdin = stdin; + g_stdin = STDIN; r0 = mes_environment (); SCM program = (argc > 1 && !strcmp (argv[1], "--load")) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 201c7793..02c6e28d 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -30,9 +30,9 @@ (set-port-encoding! (current-output-port) "ISO-8859-1")) (guile) (mes + (mes-use-module (mes pmatch)) (mes-use-module (nyacc lang c99 parser)) (mes-use-module (mes elf-util)) - (mes-use-module (mes pmatch)) (mes-use-module (mes elf)) (mes-use-module (mes as-i386)) (mes-use-module (mes libc)) @@ -46,8 +46,6 @@ (define (stderr string . rest) (apply logf (cons* (current-error-port) string rest))) -(define (gnuc-xdef? name mode) (if (equal? name "__GNUC__") #f (eq? mode 'code))) - (define (mescc) (parse-c99 #:inc-dirs (string-split (getenv "C_INCLUDE_PATH") #\:) @@ -67,9 +65,7 @@ "VERSION=\"0.4\"" "PREFIX=\"\"" ) - #:xdef? gnuc-xdef? - #:mode 'code - )) + #:mode 'code)) (define (write-any x) (write-char (cond ((char? x) x) @@ -661,8 +657,9 @@ (count (length fields)) (field-size 4) ;; FIXME:4, not fixed (rest (or (member field (reverse fields) (lambda (a b) (equal? a (cdr b)))) - barf - '())) + (begin + (stderr "no field:~a\n" field) + '()))) (offset (* field-size (1- (length rest)))) (text (.text info))) (clone info #:text @@ -1605,7 +1602,7 @@ ;; ++i ((expr-stmt (pre-inc (p-expr (ident ,name)))) - (or (assoc-ref locals name) barf) + (or (assoc-ref locals name) (begin (stderr "++i ~a\n" name) barf)) (clone info #:text (append text ((ident-add info) name 1) @@ -1617,7 +1614,7 @@ ;; i-- ((expr-stmt (post-dec (p-expr (ident ,name)))) - (or (assoc-ref locals name) barf) + (or (assoc-ref locals name) (begin (stderr "i-- ~a\n" name) barf)) (clone info #:text (append text ((ident->accu info) name) @@ -1629,7 +1626,7 @@ ;; --i ((expr-stmt (pre-dec (p-expr (ident ,name)))) - (or (assoc-ref locals name) barf) + (or (assoc-ref locals name) (begin (stderr "--i ~a\n" name) barf)) (clone info #:text (append text ((ident-add info) name -1) @@ -2451,13 +2448,14 @@ (define (function->info info) (lambda (o) - ;;(stderr "\n") - ;;(stderr "formals=~a\n" (.formals o)) + ;;(stderr "function->info o=~s\n" o) + ;;(stderr "formals=~s\n" (.formals o)) (let* ((name (.name o)) - (text (formals->text (.formals o))) - (locals (formals->locals (.formals o)))) - (format (current-error-port) "compiling ~a\n" name) - ;;(stderr "locals=~a\n" locals) + (formals (.formals o)) + (text (formals->text formals)) + (locals (formals->locals formals))) + (format (current-error-port) "compiling ~s\n" name) + ;;(stderr "locals=~s\n" locals) (let loop ((statements (.statements o)) (info (clone info #:locals locals #:function (.name o) #:text text))) (if (null? statements) (clone info @@ -2474,6 +2472,7 @@ (loop (cdr elements) ((ast->info info) (car elements))))))) (define (compile) + (stderr "COMPILE\n") (let* ((ast (mescc)) (info (make #:functions i386:libc diff --git a/module/mes/guile.mes b/module/mes/guile.mes index 55d2dd2a..a0e0ac0d 100644 --- a/module/mes/guile.mes +++ b/module/mes/guile.mes @@ -67,7 +67,7 @@ (define (with-input-from-file file thunk) (let ((port (open-input-file file))) (if (= port -1) - (begin (display "no such file:") (display file) (newline)) + (error 'no-such-file file) (let* ((save (current-input-port)) (foo (set-current-input-port port)) (r (thunk))) diff --git a/module/mes/libc.mes b/module/mes/libc.mes index 688a0f3b..c6c95015 100644 --- a/module/mes/libc.mes +++ b/module/mes/libc.mes @@ -56,18 +56,6 @@ strlen (char const* s) (define getchar (let* ((ast (with-input-from-string " -#if 0 -int -getchar () -{ - char c; - int r = read (g_stdin, &c, 1); - //int r = read (0, &c, 1); - if (r < 1) return -1; - return c; -} -#endif - int g_stdin = 0; int ungetc_char = -1; char ungetc_buf[2]; @@ -92,12 +80,6 @@ getchar () } if (i < 0) i += 256; -#if 0 - puts (\"get: \"); - putchar (i); - puts (\"\n\"); -#endif - return i; } " @@ -127,13 +109,13 @@ assert_fail (char* s) (define ungetc (let* ((ast (with-input-from-string " -#define assert(x) ((x) ? (void)0 : assert_fail (#x)) +//#define assert(x) ((x) ? (void)0 : assert_fail (#x)) int ungetc (int c, int fd) { //FIXME //assert (ungetc_char < 2); - assert (ungetc_char == -1 || ungetc_char < 2); + //assert (ungetc_char == -1 || ungetc_char < 2); //FIXME //ungetc_buf[++ungetc_char] = c; ungetc_char++; @@ -337,6 +319,7 @@ realloc (int *p, int size) puts strcmp itoa - isdigit - malloc - realloc)) + ;; isdigit + ;; malloc + ;; realloc + )) diff --git a/module/mes/loop-0.mes b/module/mes/loop-0.mes deleted file mode 100644 index 25912954..00000000 --- a/module/mes/loop-0.mes +++ /dev/null @@ -1,75 +0,0 @@ -;;; -*-scheme-*- - -;;; Mes --- Maxwell Equations of Software -;;; Copyright © 2016 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 . - -;;; Commentary: - -;;; loop-0.mes - bootstrap into Scheme from minimal -DBOOT=1 core. - -;;; When compiling mes.c with -DBOOT=1, eval/apply et al. are lacking -;;; features wrt the fat-c variant, e.g., define and define-macro are -;;; not available; instead label is supplied. Before loading -;;; boot-0.mes, loop-0.mes is loaded to provide a richer eval/apply. - -;;; This might enable moving more functionality from C to Scheme, -;;; making the entirely-from-source bootstrap process more feasible. -;;; However, currently performance is 400x worse. Also several tests -;;; in the test suite fail and the REPL does not work yet. - -;;; Code: - -((label loop-0 - (lambda (r e a) - ;; (display "***LOOP-0*** ... e=") (display e) (newline) - (if (null? e) (eval-env (cons 'begin (read-input-file-env (read-env a) a)) a) - (if (atom? e) (loop-0 (eval-env e a) (read-env a) a) - (if (eq? (car e) 'define) - ((lambda (aa) ; env:define - ;; (display "0DEFINE name=") (display (cadr e)) (newline) - (set-cdr! aa (cdr a)) - (set-cdr! a aa) - (set-cdr! (assq '*closure* a) a) - (loop-0 *unspecified* (read-env a) a)) - (cons ; sexp:define - (if (atom? (cadr e)) (cons (cadr e) (eval-env (caddr e) a)) - (cons (caadr e) (eval-env (cons 'lambda (cons (cdadr e) (cddr e))) a))) - '())) - (if (eq? (car e) 'define-macro) - ((lambda (name+entry) ; env:macro - ;; (display "0MACRO name=") (display (car name+entry)) (newline) - ((lambda (aa) ; env:define - (set-cdr! aa (cdr a)) - (set-cdr! a aa) - (set-cdr! (assq '*closure* a) a) - (loop-0 *unspecified* (read-env a) a)) - (cons - (cons (car name+entry) - (make-macro (car name+entry) - (cdr name+entry))) - '()))) - ; sexp:define - (if (atom? (cadr e)) (cons (cadr e) (eval-env (caddr e) a)) - (cons (caadr e) (eval-env (cons 'lambda (cons (cdadr e) (cddr e))) a))) - '()) - (loop-0 (eval-env e a) (read-env a) a))))))) - *unspecified* (read-env '()) (current-module)) - -() -;; enter reading loop-0 -(display "loop-0 ...\n") diff --git a/module/mes/mes-0.mes b/module/mes/mes-0.mes deleted file mode 100644 index 166fa9da..00000000 --- a/module/mes/mes-0.mes +++ /dev/null @@ -1,184 +0,0 @@ -;;; -*-scheme-*- - -;;; Mes --- Maxwell Equations of Software -;;; Copyright © 2016 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 . - -;;; Commentary: - -;;; mes-0.mes - bootstrap into Scheme, re - -;;; When compiling mes.c with -DBOOT=1, eval/apply et al. are lacking -;;; features wrt the fat-c variant, e.g., define and define-macro are -;;; not available; instead label is supplied. Before loading -;;; boot-0.mes, loop-0.mes is loaded to provide a richer eval/apply. - -;;; This might enable moving more functionality from C to Scheme, -;;; making the entirely-from-source bootstrap process more feasible. -;;; However, currently performance is 400x worse. Also several tests -;;; in the test suite fail and the REPL does not work yet. - -;;; Code: - -(define-macro (cond . clauses) - (list 'if (null? clauses) *unspecified* - (if (null? (cdr clauses)) - (list 'if (car (car clauses)) - (list (cons 'lambda (cons '() (cons (car (car clauses)) (cdr (car clauses)))))) - *unspecified*) - (if (eq? (car (cadr clauses)) 'else) - (list 'if (car (car clauses)) - (list (cons 'lambda (cons '() (car clauses)))) - (list (cons 'lambda (cons '() (cons *unspecified* (cdr (cadr clauses))))))) - (list 'if (car (car clauses)) - (list (cons 'lambda (cons '() (car clauses)))) - (cons 'cond (cdr clauses))))))) - -(define (map f l . r) - (if (null? l) '() - (if (null? r) (cons (f (car l)) (map f (cdr l))) - (if (null? (cdr r)) - (cons (f (car l) (caar r)) (map f (cdr l) (cdar r))))))) - -(define-macro (simple-let bindings . rest) - (cons (cons 'lambda (cons (map car bindings) rest)) - (map cadr bindings))) - -(define-macro (let bindings . rest) - (cons 'simple-let (cons bindings rest))) - -(define-macro (or . x) - (if (null? x) #f - (if (null? (cdr x)) (car x) - (list 'if (car x) (car x) - (cons 'or (cdr x)))))) - -(define-macro (and . x) - (if (null? x) #t - (if (null? (cdr x)) (car x) - (list 'if (car x) (cons 'and (cdr x)) - #f)))) - -(define (not x) - (if x #f #t)) - -(define (evlis-env m a) - (cond - ((null? m) '()) - ((not (pair? m)) (eval-env m a)) - (#t (cons (eval-env (car m) a) (evlis-env (cdr m) a))))) - -(define (apply-env fn x a) - (cond - ((atom? fn) - (cond - ((builtin? fn) (call fn x)) - ((eq? fn 'call-with-values) (call call-with-values-env (append x (cons a '())))) - ((eq? fn 'current-module) a) - (#t (apply-env (eval-env fn a) x a)))) - ((eq? (car fn) 'lambda) - (let ((p (pairlis (cadr fn) x a))) - (eval-begin-env (cddr fn) (cons (cons '*closure* p) p)))) - ((eq? (car fn) '*closure*) - (let ((args (caddr fn)) - (body (cdddr fn)) - (a (cddr (cadr fn)))) - (let ((p (pairlis args x a))) - (eval-begin-env body (cons (cons '*closure* p) p))))) - ;;((eq? (car fn) 'label) (apply-env (caddr fn) x (cons (cons (cadr fn) (caddr fn)) a))) - (#t (apply-env (eval-env fn a) x a)))) - -(define (eval-expand e a) - (cond - ((symbol? e) (assq-ref-env e a)) - ((atom? e) e) - ((atom? (car e)) - (cond - ((eq? (car e) 'quote) (cadr e)) - ((eq? (car e) 'syntax) (cadr e)) - ((eq? (car e) 'begin) (eval-begin-env e a)) - ((eq? (car e) 'lambda) (make-closure (cadr e) (cddr e) (assq '*closure* a))) - ((eq? (car e) '*closure*) e) - ((eq? (car e) 'if) (eval-if-env (cdr e) a)) - ((eq? (car e) 'define) (env:define (cons (sexp:define e a) '()) a)) - ((eq? (car e) 'define-macro) (env:define (env:macro (sexp:define e a)) a)) - ((eq? (car e) 'set!) (set-env! (cadr e) (eval-env (caddr e) a) a)) - ((eq? (car e) 'apply-env) (apply-env (eval-env (cadr e) a) (evlis-env (caddr e) a) a)) - ((eq? (car e) 'unquote) (eval-env (cadr e) a)) - ((eq? (car e) 'quasiquote) (eval-quasiquote (cadr e) (add-unquoters a))) - (#t (apply-env (car e) (evlis-env (cdr e) a) a)))) - (#t (apply-env (car e) (evlis-env (cdr e) a) a)))) - -(define (unquote x) (cons 'unquote x)) -(define (unquote-splicing x) (cons 'quasiquote x)) - -(define %the-unquoters - (cons - (cons 'unquote unquote) - (cons (cons 'unquote-splicing unquote-splicing) '()))) - -(define (add-unquoters a) - (cons %the-unquoters a)) - -(define (eval-env e a) - (eval-expand (macro-expand-env e a) a)) - -(define (macro-expand-env e a) - (if (pair? e) ((lambda (macro) - (if macro (macro-expand-env (apply-env macro (cdr e) a) a) - e)) - (lookup-macro (car e) a)) - e)) - -(define (eval-begin-env e a) - (if (null? e) *unspecified* - (if (null? (cdr e)) (eval-env (car e) a) - (begin - (eval-env (car e) a) - (eval-begin-env (cdr e) a))))) - -(define (eval-if-env e a) - (if (eval-env (car e) a) (eval-env (cadr e) a) - (if (pair? (cddr e)) (eval-env (caddr e) a)))) - -(define (eval-quasiquote e a) - (cond ((null? e) e) - ((atom? e) e) - ((eq? (car e) 'unquote) (eval-env (cadr e) a)) - ((and (pair? (car e)) - (eq? (caar e) 'unquote-splicing)) - (append2 (eval-env (cadar e) a) (eval-quasiquote (cdr e) a))) - (#t (cons (eval-quasiquote (car e) a) (eval-quasiquote (cdr e) a))))) - -(define (sexp:define e a) - (if (atom? (cadr e)) (cons (cadr e) (eval-env (caddr e) a)) - (cons (caadr e) (eval-env (cons 'lambda (cons (cdadr e) (cddr e))) a)))) - -(define (env:define a+ a) - (set-cdr! a+ (cdr a)) - (set-cdr! a a+) - (set-cdr! (assq '*closure* a) a)) - -(define (env:macro name+entry) - (cons - (cons (car name+entry) - (make-macro (car name+entry) - (cdr name+entry))) - '())) - -;; boot into loop-0 -() diff --git a/module/mes/repl.mes b/module/mes/repl.mes index 22a9acfb..3bb77785 100644 --- a/module/mes/repl.mes +++ b/module/mes/repl.mes @@ -28,7 +28,7 @@ (define welcome (string-append "Mes " %version " -Copyright (C) 2016 Jan Nieuwenhuizen +Copyright (C) 2016,2017 Jan Nieuwenhuizen Mes comes with ABSOLUTELY NO WARRANTY; for details type `,show w'. This program is free software, and you are welcome to redistribute it diff --git a/posix.c b/posix.c index 924b5a69..ea8a460c 100644 --- a/posix.c +++ b/posix.c @@ -18,21 +18,66 @@ * along with Mes. If not, see . */ -#if !MINI_MES +#if 0 #include - FILE *g_stdin; +#else + +#if _POSIX_SOURCE +int open (char const *s, int mode); +int read (int fd, void* buf, size_t n); +void write (int fd, char const* s, int n); +#endif + +int g_stdin; + +#define O_RDONLY 0 +#define STDIN 0 +#define STDOUT 1 +#define STDERR 2 + +int +putchar (int c) +{ + write (STDOUT, (char*)&c, 1); + return 0; +} + +int ungetc_char = -1; +char ungetc_buf[2]; + int getchar () { - return getc (g_stdin); + char c; + int i; + if (ungetc_char == -1) + { + int r = read (g_stdin, &c, 1); + if (r < 1) return -1; + i = c; + } + else + i = ungetc_buf[ungetc_char--]; + + if (i < 0) i += 256; + + return i; +} + +int +fd_ungetc (int c, int fd) +{ + assert (ungetc_char < 2); + ungetc_buf[++ungetc_char] = c; + return c; } #endif int ungetchar (int c) { - return ungetc (c, g_stdin); + return fd_ungetc (c, g_stdin); } int @@ -113,13 +158,13 @@ open_input_file (SCM file_name) SCM current_input_port () { - return MAKE_NUMBER (fileno (g_stdin)); + return MAKE_NUMBER (g_stdin); } SCM set_current_input_port (SCM port) { - g_stdin = VALUE (port) ? fdopen (VALUE (port), "r") : stdin; + g_stdin = VALUE (port); return current_input_port (); } @@ -128,7 +173,7 @@ force_output (SCM p) ///((arity . n)) { int fd = 1; if (TYPE (p) == TPAIR && TYPE (car (p)) == TNUMBER) fd = VALUE (car (p)); - FILE *f = fd == 1 ? stdout : stderr; - fflush (f); + // FILE *f = fd == 1 ? stdout : stderr; + // fflush (f); return cell_unspecified; } diff --git a/scaffold/mini-mes.c b/scaffold/mini-mes.c index e25e2c93..81c1e540 100644 --- a/scaffold/mini-mes.c +++ b/scaffold/mini-mes.c @@ -168,13 +168,13 @@ SCM tmp_num2; struct function g_functions[200]; int g_function = 0; -#include "gc.h" +#include "mini-gc.h" // #include "lib.h" // #include "math.h" #include "mini-mes.h" // #include "posix.h" // #include "reader.h" -#include "vector.h" +#include "mini-vector.h" #define TYPE(x) (g_cells[x].type) @@ -1589,17 +1589,17 @@ mes_builtins (SCM a) ///((internal)) // #include "lib.i" // #include "math.i" // #include "posix.i" -#include "vector.i" -#include "gc.i" +#include "mini-vector.i" +#include "mini-gc.i" // #include "reader.i" -#include "gc.environment.i" +#include "mini-gc.environment.i" // #include "lib.environment.i" // #include "math.environment.i" - #include "mini-mes.environment.i" +#include "mini-mes.environment.i" // #include "posix.environment.i" // #include "reader.environment.i" -#include "vector.environment.i" +#include "mini-vector.environment.i" return a; } @@ -1702,6 +1702,9 @@ main (int argc, char *argv[]) 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); + r0 = acons (cell_symbol_argv, lst, r0); push_cc (r2, cell_unspecified, r0, cell_unspecified); if (g_debug) { diff --git a/scaffold/tiny-mes.c b/scaffold/tiny-mes.c index 23a0a607..23efacfc 100644 --- a/scaffold/tiny-mes.c +++ b/scaffold/tiny-mes.c @@ -25,17 +25,6 @@ #define MES_MINI 1 -#if __GNUC__ -#define FIXME_NYACC 1 -#define __NYACC__ 0 -#define NYACC_CAR -#define NYACC_CDR -#else -#define __NYACC__ 1 -#define NYACC_CAR nyacc_car -#define NYACC_CDR nyacc_cdr -#endif - char arena[200]; typedef int SCM; @@ -53,11 +42,7 @@ SCM r1 = 0; // param 1 SCM r2 = 0; // save 2+load/dump SCM r3 = 0; // continuation -#if __NYACC__ || FIXME_NYACC -enum type_t {CHAR, CLOSURE, CONTINUATION, TFUNCTION, KEYWORD, MACRO, NUMBER, PAIR, REF, SPECIAL, TSTRING, SYMBOL, VALUES, TVECTOR, BROKEN_HEART}; -#else -enum type_t {CHAR, CLOSURE, CONTINUATION, FUNCTION, KEYWORD, MACRO, NUMBER, PAIR, REF, SPECIAL, STRING, SYMBOL, VALUES, VECTOR, BROKEN_HEART}; -#endif +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; @@ -142,7 +127,7 @@ fill () CAR (0) = 0x6a746f6f; CDR (0) = 0x00002165; - TYPE (1) = SYMBOL; + TYPE (1) = TSYMBOL; CAR (1) = 0x2d2d2d2d; CDR (1) = 0x3e3e3e3e; @@ -151,19 +136,19 @@ fill () CDR (9) = 0x3e3e3e3e; // (A(B)) - TYPE (10) = PAIR; + TYPE (10) = TPAIR; CAR (10) = 11; CDR (10) = 12; - TYPE (11) = CHAR; + TYPE (11) = TCHAR; CAR (11) = 0x58585858; CDR (11) = 89; - TYPE (12) = PAIR; + TYPE (12) = TPAIR; CAR (12) = 13; CDR (12) = 1; - TYPE (13) = CHAR; + TYPE (13) = TCHAR; CAR (11) = 0x58585858; CDR (13) = 90; @@ -187,7 +172,7 @@ display_ (SCM x) //puts ("\n"); switch (TYPE (x)) { - case CHAR: + case TCHAR: { //puts ("\n"); puts ("#\\"); @@ -207,7 +192,7 @@ display_ (SCM x) puts ("cdr"); break; } - case NUMBER: + case TNUMBER: { //puts ("\n"); #if __GNUC__ @@ -220,7 +205,7 @@ display_ (SCM x) #endif break; } - case PAIR: + case TPAIR: { //puts ("\n"); //if (cont != cell_f) puts "("); @@ -229,13 +214,13 @@ display_ (SCM x) if (CDR (x) && CDR (x) != cell_nil) { #if __GNUC__ - if (TYPE (CDR (x)) != PAIR) + if (TYPE (CDR (x)) != TPAIR) puts (" . "); #else int c; c = CDR (x); c = TYPE (c); - if (c != PAIR) + if (c != TPAIR) puts (" . "); #endif display_ (CDR (x)); @@ -244,7 +229,7 @@ display_ (SCM x) puts (")"); break; } - case SPECIAL: + case TSPECIAL: { switch (x) { @@ -264,7 +249,7 @@ display_ (SCM x) } break; } - case SYMBOL: + case TSYMBOL: { switch (x) { diff --git a/scripts/elf.mes b/scripts/elf.mes deleted file mode 100755 index 8c0d7455..00000000 --- a/scripts/elf.mes +++ /dev/null @@ -1,50 +0,0 @@ -#! /bin/sh -# -*-scheme-*- -prefix=module/ -cat $prefix/mes/base-0.mes $0 /dev/stdin | $(dirname $0)/mes $MES_FLAGS "$@" > a.out -#paredit:| -chmod +x a.out -exit $? -!# - -;;; Mes --- Maxwell Equations of Software -;;; Copyright © 2016 Jan Nieuwenhuizen -;;; -;;; elf.mes: 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 . - -(mes-use-module (mes base)) -(mes-use-module (mes quasiquote)) -(mes-use-module (mes let)) -(mes-use-module (mes scm)) -(mes-use-module (rnrs bytevectors)) -(mes-use-module (mes elf)) -(mes-use-module (mes libc-i386)) - -(define data - (string->list "Hello, world!\n")) - -(define (text d) - (append - (i386:puts d (length data)) - (i386:for 0 3 1 (i386:puts (+ d 6) (- (length data) 6))) - (i386:exit 0) - )) - -(define (write-any x) (write-char (if (char? x) x (integer->char x)))) - -(display "dumping to a.out:\n" (current-error-port)) -(map write-any (make-elf text data)) -() diff --git a/scripts/include.mes b/scripts/include.mes deleted file mode 100755 index 5030ba56..00000000 --- a/scripts/include.mes +++ /dev/null @@ -1,23 +0,0 @@ -#! /bin/sh - -if [ "$1" == "--help" ]; then - echo "Usage: include.mes FILE" - exit 0 -fi -for prefix in $(dirname $(dirname $0))/share/mes . $(dirname $(dirname $0)); do - if [ -d ${prefix}/module ]; then - break; - fi -done - -if [ -n "$BOOT" ]; then - echo $prefix/module/mes/loop-0.mes - if [ -n "$TYPE0" ]; then - echo $prefix/module/mes/type-0.mes - fi - echo $prefix/module/mes/mes-0.mes -fi -cat $@ \ - | grep -Eo '^\(mes-use-module \([^ ()]+ [^()]+))' \ - | grep -Eo ' \([^)]+\)' \ - | sed -e "s@^ *(@${prefix}/module/@" -e 's@ @/@g' -e 's@)@.mes@' diff --git a/scripts/mescc.mes b/scripts/mescc.mes index fac99d7d..c0995b24 100755 --- a/scripts/mescc.mes +++ b/scripts/mescc.mes @@ -4,8 +4,9 @@ MES=${MES-$(dirname $0)/mes} prefix=module/ echo '()' | cat $prefix/mes/base-0.mes $0 /dev/stdin | $MES $MES_FLAGS "$@" #paredit:|| -chmod +x a.out -exit $? +r=$? +([ -f a.out ] && chmod +x a.out) +exit $r !# ;;; Mes --- Maxwell Equations of Software diff --git a/scripts/nyacc-calc.mes b/scripts/nyacc-calc.mes deleted file mode 100755 index 428223b8..00000000 --- a/scripts/nyacc-calc.mes +++ /dev/null @@ -1,95 +0,0 @@ -#! /bin/sh -# -*-scheme-*- -MES_ARENA=${MES_ARENA-50000000} -export MES_ARENA -prefix=module/ -cat $prefix/mes/base-0.mes $0 | $(dirname $0)/mes $MES_FLAGS "$@" -# | -exit $? -!# - -;;; Mes --- Maxwell Equations of Software -;;; Copyright © 2016 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 . - -;;; Commentary: - -;;; nyacc-calc.mes -;;; -;;; Run with Guile: -;;; guile/nyacc-calc.scm - -;;; Code: - -(mes-use-module (mes scm)) -(mes-use-module (srfi srfi-9-psyntax)) -(mes-use-module (mes optargs)) -(mes-use-module (mes fluids)) -(mes-use-module (mes catch)) - -(mes-use-module (mes guile)) -(mes-use-module (mes pretty-print)) - -(mes-use-module (nyacc lalr)) -(mes-use-module (nyacc lex)) -(mes-use-module (nyacc parse)) - -;; (define-module (nyacc) -;; #:use-module (nyacc lalr) -;; #:use-module (nyacc lex) -;; #:use-module (nyacc parse) -;; #:use-module (ice-9 rdelim) -;; #:use-module (ice-9 pretty-print) -;; #:export (main)) - -(define simple-spec - (lalr-spec - (prec< (left "+" "-") (left "*" "/")) - (start expr) - (grammar - (expr - (expr "+" expr ($$ (+ $1 $3))) - (expr "-" expr ($$ (- $1 $3))) - (expr "*" expr ($$ (* $1 $3))) - (expr "/" expr ($$ (/ $1 $3))) - ("*" $error) - ($fixed ($$ (string->number $1))) - ($float ($$ (string->number $1))) - ("(" expr ")" ($$ $2)))))) - -(define simple-mach (make-lalr-machine simple-spec)) - -;; OR -;; (use-modules (nyacc bison)) -;; (define simple-mach (make-lalr-machine/bison simple-spec)) - -(define match-table (assq-ref simple-mach 'mtab)) - -(define gen-lexer (make-lexer-generator match-table)) - -(define parse (make-lalr-parser simple-mach)) - -(define demo-string "2 + 2") - -(define (main arguments) - (display demo-string) - (display " => ") - (display (with-input-from-string demo-string - (lambda () (parse (gen-lexer))))) - (newline)) -(main #f) -() diff --git a/scripts/nyacc.mes b/scripts/nyacc.mes deleted file mode 100755 index d7b640b3..00000000 --- a/scripts/nyacc.mes +++ /dev/null @@ -1,58 +0,0 @@ -#! /bin/sh -# -*-scheme-*- -MES_ARENA=${MES_ARENA-50000000} -export MES_ARENA -prefix=module/ -cat $prefix/mes/base-0.mes $0 | $(dirname $0)/mes $MES_FLAGS "$@" -# | -exit $? -!# - -;;; Mes --- Maxwell Equations of Software -;;; Copyright © 2016 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 . - -;;; Commentary: - -;;; nyacc.mes -;;; -;;; Run with Guile: -;;; guile/nyacc.scm - -;;; Code: - -(mes-use-module (mes scm)) -(mes-use-module (srfi srfi-9-psyntax)) -(mes-use-module (mes optargs)) -(mes-use-module (mes fluids)) -(mes-use-module (mes catch)) - -(mes-use-module (mes guile)) -(mes-use-module (mes pretty-print)) - -(mes-use-module (nyacc lang c99 parser)) - -;;(open-input-file "doc/examples/main.c") -(define (main arguments) - (let* ((file (if (> (length arguments) 1) (cadr arguments) - "doc/examples/main.c")) - (ast (with-input-from-file file - (lambda () (parse-c99 #:inc-dirs '()))))) - (pretty-print ast) - (newline))) -(main '()) -() diff --git a/scripts/paren.mes b/scripts/paren.mes deleted file mode 100755 index 2c124260..00000000 --- a/scripts/paren.mes +++ /dev/null @@ -1,40 +0,0 @@ -#! /bin/sh -# -*-scheme-*- -prefix=module/ -echo -e 'EOF\n___P((()))' | cat $prefix/mes/base-0.mes $0 /dev/stdin | $(dirname $0)/mes $MES_FLAGS "$@" -chmod +x a.out -exit $? -!# - -;;; Mes --- Maxwell Equations of Software -;;; Copyright © 2016 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 . - -;;; Commentary: - -;;; paren.mes is a simple yet full lalr test for Mes taken from the -;;; Gambit wiki. -;;; -;;; Run with Guile: -;;; echo '___P((()))' | guile -s <(echo '(paren-depth)' | cat module/language/paren.mes -) - -;;; Code: - -(mes-use-module (language paren)) - -(paren-depth) -() diff --git a/scripts/repl.mes b/scripts/repl.mes index f1465588..4c4b07a0 100755 --- a/scripts/repl.mes +++ b/scripts/repl.mes @@ -10,7 +10,7 @@ exit $? !# ;;; Mes --- Maxwell Equations of Software -;;; Copyright © 2016 Jan Nieuwenhuizen +;;; Copyright © 2016,2017 Jan Nieuwenhuizen ;;; ;;; This file is part of Mes. ;;;