mirror of
https://github.com/false-schemers/skint.git
synced 2025-01-13 20:03:30 +01:00
top-level idless define fix (eval)
This commit is contained in:
parent
8964bbdab5
commit
21e470522d
2 changed files with 48 additions and 44 deletions
63
src/t.scm
63
src/t.scm
|
@ -1834,44 +1834,47 @@
|
|||
(let ([hval (xform #t (car x) env)])
|
||||
(cond
|
||||
[(eq? hval 'begin)
|
||||
; splice
|
||||
(let loop ([x* (cdr x)])
|
||||
(when (pair? x*)
|
||||
(repl-eval-top-form (car x*) env)
|
||||
(loop (cdr x*))))]
|
||||
; splice
|
||||
(let loop ([x* (cdr x)])
|
||||
(when (pair? x*)
|
||||
(repl-eval-top-form (car x*) env)
|
||||
(loop (cdr x*))))]
|
||||
[(and (eq? hval 'define) (null? (cadr x)))
|
||||
; special idless define
|
||||
(repl-eval-top-form (caddr x) env)]
|
||||
[(eq? hval 'define)
|
||||
; use new protocol for top-level envs
|
||||
(let* ([core (xform-define (cdr x) env)]
|
||||
; use new protocol for top-level envs
|
||||
(let* ([core (xform-define (cdr x) env)]
|
||||
[loc (xenv-lookup env (cadr core) 'define)])
|
||||
(if (and loc (sexp-match? '(ref *) (location-val loc)))
|
||||
(repl-compile-and-run-core-expr
|
||||
(list 'set! (cadr (location-val loc)) (caddr core)))
|
||||
(x-error "identifier cannot be (re)defined in env:"
|
||||
(cadr core) env)))]
|
||||
(if (and loc (sexp-match? '(ref *) (location-val loc)))
|
||||
(repl-compile-and-run-core-expr
|
||||
(list 'set! (cadr (location-val loc)) (caddr core)))
|
||||
(x-error "identifier cannot be (re)defined in env:"
|
||||
(cadr core) env)))]
|
||||
[(eq? hval 'define-syntax)
|
||||
; use new protocol for top-level envs
|
||||
(let* ([core (xform-define-syntax (cdr x) env)]
|
||||
; use new protocol for top-level envs
|
||||
(let* ([core (xform-define-syntax (cdr x) env)]
|
||||
[loc (xenv-lookup env (cadr core) 'define-syntax)])
|
||||
(if loc ; location or #f
|
||||
(location-set-val! loc (caddr core))
|
||||
(x-error "identifier cannot be (re)defined as syntax in env:"
|
||||
(cadr core) env))
|
||||
(when *verbose* (display "SYNTAX INSTALLED: ") (write (cadr core)) (newline)))]
|
||||
(if loc ; location or #f
|
||||
(location-set-val! loc (caddr core))
|
||||
(x-error "identifier cannot be (re)defined as syntax in env:"
|
||||
(cadr core) env))
|
||||
(when *verbose* (display "SYNTAX INSTALLED: ") (write (cadr core)) (newline)))]
|
||||
[(procedure? hval)
|
||||
; transformer: apply and loop
|
||||
(repl-eval-top-form (hval x env) env)]
|
||||
; transformer: apply and loop
|
||||
(repl-eval-top-form (hval x env) env)]
|
||||
[(integrable? hval)
|
||||
; integrable application
|
||||
(repl-compile-and-run-core-expr
|
||||
(xform-integrable hval (cdr x) env))]
|
||||
; integrable application
|
||||
(repl-compile-and-run-core-expr
|
||||
(xform-integrable hval (cdr x) env))]
|
||||
[(symbol? hval)
|
||||
; other specials
|
||||
(repl-compile-and-run-core-expr
|
||||
(xform #f x env))]
|
||||
; other specials
|
||||
(repl-compile-and-run-core-expr
|
||||
(xform #f x env))]
|
||||
[else
|
||||
; regular call
|
||||
(repl-compile-and-run-core-expr
|
||||
(xform-call hval (cdr x) env))]))
|
||||
; regular call
|
||||
(repl-compile-and-run-core-expr
|
||||
(xform-call hval (cdr x) env))]))
|
||||
; var refs and literals
|
||||
(repl-compile-and-run-core-expr
|
||||
(xform #f x env))))
|
||||
|
|
29
t.c
29
t.c
|
@ -1033,20 +1033,21 @@ char *t_code[] = {
|
|||
"P", "repl-eval-top-form",
|
||||
"%2.0p?{${.3,.3a,t,@(y5:xform)[03},'(y5:begin),.1q?{.1d,,#0.4,.1,&2{%1."
|
||||
"0p?{${:1,.3a,@(y18:repl-eval-top-form)[02}.0d,:0^[11}]1}.!0.0^_1[31}'("
|
||||
"y6:define),.1q?{${.4,.4d,@(y12:xform-define)[02},${'(y6:define),.3da,."
|
||||
"7,@(y11:xenv-lookup)[03},.0?{${.2z,'(l2:y3:ref;y1:*;),@(y11:sexp-match"
|
||||
"?)[02}}{f}?{.1dda,.1zda,'(y4:set!),l3,@(y30:repl-compile-and-run-core-"
|
||||
"expr)[51}.4,.2da,'(s40:identifier cannot be (re)defined in env:),@(y7:"
|
||||
"x-error)[53}'(y13:define-syntax),.1q?{${.4,.4d,@(y19:xform-define-synt"
|
||||
"ax)[02},${'(y13:define-syntax),.3da,.7,@(y11:xenv-lookup)[03},.0?{.1dd"
|
||||
"a,.1sz}{${.6,.4da,'(s50:identifier cannot be (re)defined as syntax in "
|
||||
"env:),@(y7:x-error)[03}}@(y9:*verbose*)?{Po,'(s18:SYNTAX INSTALLED: )W"
|
||||
"4Po,.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-an"
|
||||
"d-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-co"
|
||||
"mpile-and-run-core-expr)[31}${.3,.3,f,@(y5:xform)[03},@(y30:repl-compi"
|
||||
"le-and-run-core-expr)[21",
|
||||
"y6:define),.1q?{.1dau}{f}?{.2,.2dda,@(y18:repl-eval-top-form)[32}'(y6:"
|
||||
"define),.1q?{${.4,.4d,@(y12:xform-define)[02},${'(y6:define),.3da,.7,@"
|
||||
"(y11:xenv-lookup)[03},.0?{${.2z,'(l2:y3:ref;y1:*;),@(y11:sexp-match?)["
|
||||
"02}}{f}?{.1dda,.1zda,'(y4:set!),l3,@(y30:repl-compile-and-run-core-exp"
|
||||
"r)[51}.4,.2da,'(s40:identifier cannot be (re)defined in env:),@(y7:x-e"
|
||||
"rror)[53}'(y13:define-syntax),.1q?{${.4,.4d,@(y19:xform-define-syntax)"
|
||||
"[02},${'(y13:define-syntax),.3da,.7,@(y11:xenv-lookup)[03},.0?{.1dda,."
|
||||
"1sz}{${.6,.4da,'(s50:identifier cannot be (re)defined as syntax in env"
|
||||
":),@(y7:x-error)[03}}@(y9:*verbose*)?{Po,'(s18:SYNTAX 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-r"
|
||||
"un-core-expr)[31}.0Y0?{${.4,.4,f,@(y5:xform)[03},@(y30:repl-compile-an"
|
||||
"d-run-core-expr)[31}${.4,.4d,.4,@(y10:xform-call)[03},@(y30:repl-compi"
|
||||
"le-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",
|
||||
|
|
Loading…
Reference in a new issue