From 6b0bcc98a4681de3b046edce4710150781a19709 Mon Sep 17 00:00:00 2001 From: ESL Date: Fri, 5 Jul 2024 16:52:42 -0400 Subject: [PATCH] import works on top level --- src/t.scm | 9 ++++++++- t.c | 19 +++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/t.scm b/src/t.scm index 80f22dd..faa62e1 100644 --- a/src/t.scm +++ b/src/t.scm @@ -1052,7 +1052,7 @@ (define (xform-import head tail env appos?) ; non-internal (if (list? tail) (let ([ic&ex (preprocess-import-sets (cons head tail) env)]) - (list 'import lid (list 'quote ic&ex))) + (list 'import (list 'quote ic&ex))) (x-error "improper import form" (cons head tail)))) @@ -2048,6 +2048,13 @@ (x-error "identifier cannot be (re)defined as syntax in env:" (cadr core) env)) (when *verbose* (display "LIBRARY INSTALLED: ") (write (cadr core)) (newline)))] + [(eq? hval 'import) ; splice as definitions + (let* ([core (xform-import (car x) (cdr x) env #f)] ; core is (import (quote ic&ex)) + [ic&ex (cadadr core)] [code (car ic&ex)] [eal (cdr ic&ex)]) + (define (define-alias p) + (repl-eval-top-form (list define-syntax-id (car p) (list syntax-id (location-val (cdr p)))) env)) + (repl-compile-and-run-core-expr code) + (for-each define-alias eal))] [(procedure? hval) ; transformer: apply and loop (repl-eval-top-form (hval x env) env)] [(integrable? hval) ; integrable application diff --git a/t.c b/t.c index 2bbc31b..7d26b9a 100644 --- a/t.c +++ b/t.c @@ -594,8 +594,8 @@ char *t_code[] = { "P", "xform-import", "%4.1L0?{${.4,.4,.4c,@(y22:preprocess-import-sets)[02},.0,'(y5:quote),l" - "2,@(y3:lid),'(y6:import),l3]5}.1,.1c,'(s20:improper import form),@(y7:" - "x-error)[42", + "2,'(y6:import),l2]5}.1,.1c,'(s20:improper import form),@(y7:x-error)[4" + "2", "P", "write-serialized-char", "%2'(c%25),.1C=,.0?{.0}{'(c%22),.2C=,.0?{.0}{'(c%5c),.3C=,.0?{.0}{'(c )" @@ -1186,12 +1186,15 @@ char *t_code[] = { "xenv-lookup)[03},.0?{.1dda,.0,&1{%2:0,@(y9:syntax-id),l2]2},.0,.3sz_1_" "1}{${.6,.4da,'(s50:identifier cannot be (re)defined as syntax in env:)" ",@(y7:x-error)[03}}@(y9:*verbose*)?{Po,'(s19:LIBRARY INSTALLED: )W4Po," - ".2daW5PoW6]5}]5}.0K0?{.2,${.5,.5,.5[02},@(y18:repl-eval-top-form)[32}." - "0U0?{${.4,.4d,.4,@(y16:xform-integrable)[03},@(y30:repl-compile-and-ru" - "n-core-expr)[31}.0Y0?{${.4,.4,f,@(y5:xform)[03},@(y30:repl-compile-and" - "-run-core-expr)[31}${.4,.4d,.4,@(y10:xform-call)[03},@(y30:repl-compil" - "e-and-run-core-expr)[31}${.3,.3,f,@(y5:xform)[03},@(y30:repl-compile-a" - "nd-run-core-expr)[21", + ".2daW5PoW6]5}]5}'(y6:import),.1q?{${f,.5,.5d,.6a,@(y12:xform-import)[0" + "4},.0dada,.0a,.1d,,#0.7,&1{%1:0,.1dz,@(y9:syntax-id),l2,.2a,@(y16:defi" + "ne-syntax-id),l3,@(y18:repl-eval-top-form)[12}.!0${.4,@(y30:repl-compi" + "le-and-run-core-expr)[01}.1,.1^,@(y10:%25for-each1)[82}.0K0?{.2,${.5,." + "5,.5[02},@(y18:repl-eval-top-form)[32}.0U0?{${.4,.4d,.4,@(y16:xform-in" + "tegrable)[03},@(y30:repl-compile-and-run-core-expr)[31}.0Y0?{${.4,.4,f" + ",@(y5:xform)[03},@(y30:repl-compile-and-run-core-expr)[31}${.4,.4d,.4," + "@(y10:xform-call)[03},@(y30:repl-compile-and-run-core-expr)[31}${.3,.3" + ",f,@(y5:xform)[03},@(y30:repl-compile-and-run-core-expr)[21", "P", "repl-read", "%2.1?{PoW6Po,.2W4Po,'(s1: )W4}.0,@(y14:read-code-sexp)[21",