From e69c21eb16fc3892c4c2dae5ae3ec15fa4884899 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 11 Aug 2015 22:50:30 -0400 Subject: [PATCH] Compile macros as the macro_type --- scheme/cyclone/cgen.sld | 35 +++++++++++++++++++++++------------ test2.scm | 2 +- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/scheme/cyclone/cgen.sld b/scheme/cyclone/cgen.sld index 44dc922c..cde6ddc0 100644 --- a/scheme/cyclone/cgen.sld +++ b/scheme/cyclone/cgen.sld @@ -182,6 +182,8 @@ "\");\n" ))) +(define (st:->var trace) + (cdr trace)) ;; END st helpers ;;; Compilation routines. @@ -987,6 +989,7 @@ (closure->fv exp))) ; Note these are not necessarily symbols, but in cc form (cv-name (mangle (gensym 'c))) (lid (allocate-lambda (c-compile-lambda lam trace))) + (macro? (assoc (st:->var trace) (get-macros))) (create-nclosure (lambda () (string-append "closureN_type " cv-name ";\n" @@ -1005,18 +1008,26 @@ (car vars) ";\n" (loop (+ i 1) (cdr vars)))))))) (create-mclosure (lambda () - (string-append - "mclosure" (number->string (length free-vars)) "(" cv-name ", " - ;; NOTE: - ;; Hopefully will not cause issues with varargs when casting to - ;; generic function type below. Works fine in gcc, not sure if - ;; this is portable to other compilers though - "(function_type)__lambda_" (number->string lid) - (if (> (length free-vars) 0) "," "") - (string-join free-vars ", ") - ");" - cv-name ".num_args = " (number->string (compute-num-args lam)) ";" - )))) + (let ((prefix + (if macro? + "mmacro" + (string-append + "mclosure" + (number->string (length free-vars)))))) + (string-append + prefix + "(" cv-name ", " + ;; NOTE: + ;; Hopefully will not cause issues with varargs when casting to + ;; generic function type below. Works fine in gcc, not sure if + ;; this is portable to other compilers though + "(function_type)__lambda_" (number->string lid) + (if (> (length free-vars) 0) "," "") + (string-join free-vars ", ") + ");" + cv-name ".num_args = " (number->string (compute-num-args lam)) ";" + ))))) + ;(trace:info (list 'JAE-DEBUG trace macro?)) (c-code/vars (string-append "&" cv-name) (list diff --git a/test2.scm b/test2.scm index ba36d55e..ab035a47 100644 --- a/test2.scm +++ b/test2.scm @@ -47,4 +47,4 @@ (define x 1) (write x) (write - (eval 'x)) + (eval '(or 1 2 x)))