From cbb969221a83f7d460990a5e7eea31595ac0468f Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 5 Aug 2015 22:01:43 -0400 Subject: [PATCH] WIP - eval/lambda --- Makefile | 5 +++++ TODO | 2 ++ runtime.c | 13 +++++++++++-- test2.scm | 48 +++++++++++++++++++++++++++--------------------- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 20189b6c..941665dc 100644 --- a/Makefile +++ b/Makefile @@ -108,6 +108,11 @@ install-libs: $(MKDIR) $(DESTDIR)$(LIBDIR) $(INSTALL) -m0644 libcyclone.a $(DESTDIR)$(LIBDIR)/ +install-bin: + $(MKDIR) $(DESTDIR)$(BINDIR) + $(INSTALL) -m0755 cyclone $(DESTDIR)$(BINDIR)/ + $(INSTALL) -m0755 icyc $(DESTDIR)$(BINDIR)/ + # TODO: rewrite install to be in terms of incremental steps above. # also want to propagate this change to cyclone-bootstrap install: diff --git a/TODO b/TODO index d6e8f18d..47a6e471 100644 --- a/TODO +++ b/TODO @@ -15,6 +15,8 @@ Working TODO list. should start creating issues for these to get them out of her need to think about how macros from sld's will end up being loaded though. do we need to emit .meta files or such? + problem right now in that built-in macros work because they become compiled functions, but macros loaded at compile time may be just scheme objects (and eventually, compiled functions from libs). + - profile cyclone code, see if there are any bottlenecks we can reduce EG: prof cyclone transforms.sld diff --git a/runtime.c b/runtime.c index 1f7a8ad7..8b6fe92b 100644 --- a/runtime.c +++ b/runtime.c @@ -1867,14 +1867,23 @@ object apply(object cont, object func, object args){ case cons_tag: { // TODO: should add more error checking here, make sure car(func) is a symbol + object fobj = car(func); + + if (!is_object_type(fobj) || type_of(fobj) != symbol_tag) { + Cyc_rt_raise2("Call of non-procedure: ", func); + } else if (strncmp(((symbol)fobj)->pname, "lambda", 7) == 0) { + make_cons(c, func, args); + printf("JAE DEBUG, sending to eval: "); + Cyc_display(&c, stderr); + ((closure)__glo_eval)->fn(3, __glo_eval, cont, &c, nil); // TODO: would be better to compare directly against symbols here, // but need a way of looking them up ahead of time. // maybe a libinit() or such is required. - if (strncmp(((symbol)car(func))->pname, "primitive", 10) == 0) { + } else if (strncmp(((symbol)fobj)->pname, "primitive", 10) == 0) { make_cons(c, cadr(func), args); ((closure)__glo_eval)->fn(3, __glo_eval, cont, &c, nil); - } else if (strncmp(((symbol)car(func))->pname, "procedure", 10) == 0) { + } else if (strncmp(((symbol)fobj)->pname, "procedure", 10) == 0) { make_cons(c, func, args); ((closure)__glo_eval)->fn(3, __glo_eval, cont, &c, nil); } else { diff --git a/test2.scm b/test2.scm index 32b92a26..d066bf1c 100644 --- a/test2.scm +++ b/test2.scm @@ -1,24 +1,30 @@ -(import (scheme base) - (scheme write)) +(import (scheme eval)) -;(define-syntax test +(eval '((lambda (expr rename compare) (cond ((null? (cdr expr))) ((null? (cddr expr)) (cadr expr)) (else (list (rename (quote if)) (cadr expr) (cons (rename (quote and)) (cddr expr)) #f)))) (test 1 2 3) (lambda (x) x) '())) +;(eval '((lambda (x) x) 1)) + + +;(import (scheme base) +; (scheme write)) +; +;;(define-syntax test +;; (er-macro-transformer +;; (lambda (expr rename compare) +;; `((lambda () +;; (write "testing") +;; (write (quote ,(cdr expr)))))))) +;; +;; WTF is the macro unable to be evaluated when the same code works as part of *defined-macros*??? +;; +;(define-syntax test ; (er-macro-transformer -; (lambda (expr rename compare) -; `((lambda () -; (write "testing") -; (write (quote ,(cdr expr)))))))) +; (lambda (expr rename compare) +; (cond ((null? (cdr expr))) +; ((null? (cddr expr)) (cadr expr)) +; (else (list (rename 'if) (cadr expr) +; (cons (rename 'and) (cddr expr)) +; #f)))))) ; -; WTF is the macro unable to be evaluated when the same code works as part of *defined-macros*??? -; -(define-syntax test - (er-macro-transformer - (lambda (expr rename compare) - (cond ((null? (cdr expr))) - ((null? (cddr expr)) (cadr expr)) - (else (list (rename 'if) (cadr expr) - (cons (rename 'and) (cddr expr)) - #f)))))) - -(test 1 2 3) -;(test 'done) -'done +;(test 1 2 3) +;;(test 'done) +;'done