From 605bc65c59451b567bd64e750c1e659424759fe2 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sun, 22 Jul 2012 15:01:42 -0400 Subject: [PATCH] work on macro changes --- base/expr.jl | 2 ++ src/ast.c | 19 ++++++++++++++++--- src/toplevel.c | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/base/expr.jl b/base/expr.jl index e2c4524b2a28e..794f2c51f91a6 100644 --- a/base/expr.jl +++ b/base/expr.jl @@ -41,6 +41,8 @@ macro gensym(names...) return blk end +syntax_escape(e) = expr(:escape, {e}) + ## expressions ## expr(hd::Symbol, args::ANY...) = Expr(hd, {args...}, Any) diff --git a/src/ast.c b/src/ast.c index 7b850179e0ec0..e32623cb759c6 100644 --- a/src/ast.c +++ b/src/ast.c @@ -17,6 +17,7 @@ static char flisp_system_image[] = { }; extern fltype_t *iostreamtype; +static fltype_t *jvtype; static jl_value_t *scm_to_julia(value_t e); static value_t julia_to_scm(jl_value_t *v); @@ -71,8 +72,21 @@ value_t fl_invoke_julia_macro(value_t *args, uint32_t nargs) // so the preserved value stack is popped there. jl_gc_preserve(result); value_t scm = julia_to_scm(result); + fl_gc_handle(&scm); + value_t scmresult; + jl_module_t *defmod = f->linfo->module; + if (defmod == jl_current_module) { + scmresult = fl_cons(scm, FL_F); + } + else { + value_t opaque = cvalue(jvtype, sizeof(void*)); + *(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = (jl_value_t*)defmod; + scmresult = fl_cons(scm, opaque); + } + fl_free_gc_handles(1); + JL_GC_POP(); - return scm; + return scmresult; } static builtinspec_t julia_flisp_ast_ext[] = { @@ -81,8 +95,6 @@ static builtinspec_t julia_flisp_ast_ext[] = { { NULL, NULL } }; -static fltype_t *jvtype; - DLLEXPORT void jl_init_frontend(void) { fl_init(2*512*1024); @@ -433,6 +445,7 @@ jl_value_t *jl_parse_next(int *plineno) value_t a = car_(c); if (isfixnum(a)) { *plineno = numval(a); + //ios_printf(ios_stderr, " line %d\n", *plineno); return scm_to_julia(cdr_(c)); } } diff --git a/src/toplevel.c b/src/toplevel.c index 1a1adfff2d380..75c585293df2a 100644 --- a/src/toplevel.c +++ b/src/toplevel.c @@ -276,6 +276,7 @@ jl_value_t *jl_toplevel_eval(jl_value_t *v) // repeatedly call jl_parse_next and eval everything void jl_parse_eval_all(char *fname) { + //ios_printf(ios_stderr, "***** loading %s\n", fname); int lineno=0; jl_value_t *fn=NULL, *ln=NULL, *form=NULL; JL_GC_PUSH(&fn, &ln, &form);