From 2ce058bf12ca68f4dd1770601b9a74e20bf71101 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 21 May 2015 01:19:39 -0400 Subject: [PATCH] Call into lib "top-level" for init's --- cgen.scm | 26 ++++++++++++++------------ runtime.c | 2 +- trans.scm | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/cgen.scm b/cgen.scm index 65e62294..4346ebbc 100644 --- a/cgen.scm +++ b/cgen.scm @@ -10,6 +10,10 @@ (display line) (newline)) +(define (emit* . strs) + (for-each emits strs) + (newline)) + (define (emits str) (display str)) @@ -972,12 +976,12 @@ (emit "static void c_entry_pt_first_lambda();") (for-each (lambda (lib-name) - (emit (string-append "extern void c_" (lib:name->string lib-name) "_entry_pt(int argc, closure env, closure cont);"))) + (emit (string-append "extern void c_" (lib:name->string lib-name) "_entry_pt(int argc, closure cont, object value);"))) required-libs) (emit "static void c_entry_pt(argc, env,cont) int argc; closure env,cont; { ")) (else - (emit (string-append "void c_" (lib:name->string lib-name) "_entry_pt(argc, env,cont) int argc; closure env,cont; { ")) - ;DEBUG: (emit (string-append "printf(\"init " (lib:name->string lib-name) "\\n\");")) + (emit (string-append "void c_" (lib:name->string lib-name) "_entry_pt(argc, cont,value) int argc; closure cont; object value;{ ")) + (emit (string-append "printf(\"init " (lib:name->string lib-name) "\\n\");")) )) ;; Initialize global table @@ -1077,19 +1081,17 @@ ;; Start cont chain, but do not assume funcall1 macro was defined (string-append "(" this-clo ".fn)(0, &" this-clo ", &" this-clo ");")) (emit "}") - (emit "static void c_entry_pt_first_lambda(int argc, closure env, closure cont) {") - ;DEBUG: (emit (string-append "printf(\"init first lambda\\n\");")) + (emit "static void c_entry_pt_first_lambda(int argc, closure cont, object value) {") + (emit (string-append "printf(\"init first lambda\\n\");")) (emit compiled-program))) (else ;; Do not use funcall1 macro as it might not have been defined (emit "cont = ((closure1_type *)cont)->elt1;") - (emit "((cont)->fn)(1, cont, cont);") - ;; TODO: - ; need to call into computed func, EG: __glo_lib_91init_117schemeread - ; using cont->elt1 as k. -; (emit "}") -; (emit (string-append "static void c_" (lib:name->string lib-name) "_entry_pt_inits(int argc, closure " -; (emit compiled-program) + ;(emit "((cont)->fn)(1, cont, cont);") + (emit* + "(((closure)" + (mangle-global (lib:name->symbol lib-name)) + ")->fn)(1, cont, cont);") )) (emit "}") diff --git a/runtime.c b/runtime.c index 3bb2a8b2..a9342eed 100644 --- a/runtime.c +++ b/runtime.c @@ -425,7 +425,7 @@ list assoc(x,l) object x; list l; printf("JAE DEBUG, assoc received: "); Cyc_display(l); printf("\n"); - if (type_of(l) != cons_tag) return boolean_f; + if (nullp(l) || is_value_type(l) || type_of(l) != cons_tag) return boolean_f; for (; !nullp(l); l = cdr(l)) {register list la = car(l); if (boolean_f != equalp(x,car(la))) return la;} return boolean_f;} diff --git a/trans.scm b/trans.scm index 5bb42278..f512f026 100644 --- a/trans.scm +++ b/trans.scm @@ -1569,7 +1569,7 @@ (define (lib:name->symbol name) (string->symbol (string-append - "lib-init:" + "lib-init:" ;; Maybe make this an optional param? Trying to ensure uniqueness (lib:name->string name)))) ;; Helper function that returns an empty list as a default value (define (lib:result result)