From: Tim Vaughan Date: Tue, 4 Jul 2017 12:52:32 +0000 (+1000) Subject: Factored apply out of application-executor X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=7173757033eb0681ee1c7ed5df7936e5860345a6;p=scheme.forth.jl.git Factored apply out of application-executor --- diff --git a/src/scheme-primitives.4th b/src/scheme-primitives.4th index 183efec..21a0440 100644 --- a/src/scheme-primitives.4th +++ b/src/scheme-primitives.4th @@ -592,13 +592,13 @@ defer display \ ==== Evaluation ==== {{{ -\ :noname ( args -- result ) -\ 2dup car 2swap cdr -\ -\ nil? false = if car then ( proc argvals ) -\ -\ apply -\ ; make-primitive apply +:noname ( args -- result ) + 2dup car 2swap cdr + + nil? false = if car then ( proc argvals ) + + 2swap apply +; make-primitive apply \ }}} diff --git a/src/scheme.4th b/src/scheme.4th index 7b1da05..af4157f 100644 --- a/src/scheme.4th +++ b/src/scheme.4th @@ -1273,6 +1273,11 @@ parse-idx-stack parse-idx-sp ! exit then + nextchar [char] ) = if + inc-parse-idx + except-message: ." unmatched closing parenthesis." recoverable-exception throw + then + \ Anything else is parsed as a symbol readsymbol charlist>symbol @@ -1286,7 +1291,7 @@ parse-idx-stack parse-idx-sp ! \ }}} -\ ---- Eval ---- {{{ +\ ---- Syntax ---- {{{ : self-evaluating? ( obj -- obj bool ) boolean-type istype? if true exit then @@ -1449,7 +1454,7 @@ parse-idx-stack parse-idx-sp ! \ }}} -\ ---- Analyze ---- +\ ---- Analyze ---- {{{ : evaluate-eproc ( eproc env --- res ) @@ -1636,15 +1641,7 @@ parse-idx-stack parse-idx-sp ! then ; -: application-executor ( operator-proc arg-procs env -- res ) - 2rot 2over ( aprocs env fproc env ) - evaluate-eproc ( aprocs env proc ) - - -2rot 2swap ( proc env aprocs ) - evaluate-operand-eprocs ( proc vals ) - - 2swap ( vals proc ) - +: apply ( vals proc ) dup case primitive-proc-type of drop execute @@ -1668,6 +1665,18 @@ parse-idx-stack parse-idx-sp ! endcase ; +: application-executor ( operator-proc arg-procs env -- res ) + 2rot 2over ( aprocs env fproc env ) + evaluate-eproc ( aprocs env proc ) + + -2rot 2swap ( proc env aprocs ) + evaluate-operand-eprocs ( proc vals ) + + 2swap ( vals proc ) + + ['] apply goto +; + : analyze-application ( exp -- eproc ) 2dup operator analyze 2swap operands operand-eproc-list @@ -1700,6 +1709,7 @@ parse-idx-stack parse-idx-sp ! ; is analyze +\ }}} \ ---- Macro Expansion ---- {{{