X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=scheme.4th;h=5d3b778738808d3238b3226d068aaa20a6ffc25e;hb=af8e47216da60326dec6e0fb6e666bf36ac134a6;hp=4ccf7d83049a0816dd1ac71b7d7a5a17a7da69f4;hpb=f81ffb05496dc3490c0c7469017d9c7ba7c0113a;p=scheme.forth.jl.git diff --git a/scheme.4th b/scheme.4th index 4ccf7d8..5d3b778 100644 --- a/scheme.4th +++ b/scheme.4th @@ -52,7 +52,7 @@ variable nextexception make-exception recoverable-exception make-exception unrecoverable-exception -: display-warning ( addr count -- ) +: display-exception-msg ( addr count -- ) bold fg red ." Exception: " type @@ -65,7 +65,7 @@ make-exception unrecoverable-exception [compile] if ['] -rot , - ['] display-warning , + ['] display-exception-msg , [compile] then ['] throw , @@ -1060,6 +1060,70 @@ parse-idx-stack parse-idx-sp ! : quote-body ( quote-obj -- quote-body-obj ) cadr ; +: quasiquote? ( obj -- obj bool ) + quasiquote-symbol tagged-list? ; + +: unquote? ( obj -- obj bool ) + unquote-symbol tagged-list? +; + +: eval-unquote ( env obj -- res ) + cdr ( env args ) + + nil? if + recoverable-exception throw" no arguments to unquote." + then + + 2dup cdr + nil? false = if + recoverable-exception throw" too many arguments to unquote." + then + + 2drop car 2swap eval +; + +: (eval-quasiquote) ( env obj -- res ) + nil? if + 2swap 2drop exit + then + + 2over 2over car ( env obj env obj-car ) + + unquote? if + eval-unquote + else + 2swap 2drop + then + + -2rot cdr ( caritem env cdr ) + recurse ( caritem cdritems ) + cons +; + +: eval-quasiquote ( obj env -- res ) + 2swap cdr ( env args ) + + nil? if + recoverable-exception throw" no arguments to quasiquote." + then + + 2dup cdr ( env args args-cdr ) + nil? false = if + recoverable-exception throw" too many arguments to quasiquote." + then + + 2drop car ( env arg ) + + unquote? if + eval-unquote exit + then + + pair-type istype? if + (eval-quasiquote) exit + then + + 2swap 2drop ; + : variable? ( obj -- obj bool ) symbol-type istype? ; @@ -1346,6 +1410,11 @@ hide env exit then + quasiquote? if + 2swap eval-quasiquote + exit + then + variable? if 2swap lookup-var exit @@ -1456,7 +1525,7 @@ hide env ; : (printstring) ( stringobj -- ) - nil-type istype? if 2drop exit then + nil? if 2drop exit then 2dup car drop dup case @@ -1709,11 +1778,7 @@ variable gc-stack-depth recoverable-exception of false endof unrecoverable-exception of true endof - \ Rethrow anything else: - throw - - \ If we're still here, loop again - false + throw false endcase until ;