fuel.eval: better manifest handling in eval-in-context
parent
fff7bc72a4
commit
e020369b13
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
|
! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: continuations fuel fuel.eval io.streams.string kernel math
|
USING: continuations fuel fuel.eval io.streams.string kernel math
|
||||||
namespaces random.data sequences strings tools.test vocabs.parser ;
|
namespaces random.data sequences tools.test vocabs.parser ;
|
||||||
IN: fuel.eval.tests
|
IN: fuel.eval.tests
|
||||||
|
|
||||||
! pop-restarts
|
! pop-restarts
|
||||||
|
@ -37,3 +37,12 @@ IN: fuel.eval.tests
|
||||||
f eval-result set-global
|
f eval-result set-global
|
||||||
] with-manifest
|
] with-manifest
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
{
|
||||||
|
"(nil nil \"9\\n\")\n<~FUEL~>\n"
|
||||||
|
} [
|
||||||
|
[
|
||||||
|
{ "3 sq . " } "hi99"
|
||||||
|
{ "math" "prettyprint" "kernel" } eval-in-context
|
||||||
|
] with-string-writer
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
|
! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays continuations debugger fuel.pprint io
|
USING: arrays continuations debugger fuel.pprint io io.streams.string
|
||||||
io.streams.string kernel listener namespaces prettyprint.config sequences
|
kernel listener namespaces prettyprint.config sequences vocabs.parser
|
||||||
vocabs.parser ;
|
;
|
||||||
IN: fuel.eval
|
IN: fuel.eval
|
||||||
|
|
||||||
TUPLE: status manifest restarts ;
|
SYMBOL: restarts-stack
|
||||||
|
V{ } clone restarts-stack set-global
|
||||||
SYMBOL: status-stack
|
|
||||||
V{ } clone status-stack set-global
|
|
||||||
|
|
||||||
SYMBOL: eval-error
|
SYMBOL: eval-error
|
||||||
f eval-error set-global
|
f eval-error set-global
|
||||||
|
@ -26,24 +24,13 @@ t eval-res-flag set-global
|
||||||
eval-res-flag get-global ;
|
eval-res-flag get-global ;
|
||||||
|
|
||||||
: push-status ( -- )
|
: push-status ( -- )
|
||||||
manifest get clone restarts get-global clone status boa
|
restarts get-global clone restarts-stack get push ;
|
||||||
status-stack get push ;
|
|
||||||
|
|
||||||
: pop-restarts ( restarts -- )
|
: pop-restarts ( restarts -- )
|
||||||
eval-restartable? [ drop ] [ clone restarts set-global ] if ;
|
eval-restartable? [ drop ] [ clone restarts set-global ] if ;
|
||||||
|
|
||||||
: pop-status ( -- )
|
: pop-status ( -- )
|
||||||
status-stack get [
|
restarts-stack get [ pop pop-restarts ] unless-empty ;
|
||||||
pop
|
|
||||||
[ manifest>> clone manifest set ]
|
|
||||||
[ restarts>> pop-restarts ]
|
|
||||||
bi
|
|
||||||
] unless-empty ;
|
|
||||||
|
|
||||||
: forget-status ( -- )
|
|
||||||
f eval-error set-global
|
|
||||||
f eval-result set-global
|
|
||||||
f eval-output set-global ;
|
|
||||||
|
|
||||||
: send-retort ( -- )
|
: send-retort ( -- )
|
||||||
eval-error get-global
|
eval-error get-global
|
||||||
|
@ -53,7 +40,10 @@ t eval-res-flag set-global
|
||||||
flush nl "<~FUEL~>" write nl flush ;
|
flush nl "<~FUEL~>" write nl flush ;
|
||||||
|
|
||||||
: begin-eval ( -- )
|
: begin-eval ( -- )
|
||||||
push-status forget-status ;
|
push-status
|
||||||
|
f eval-error set-global
|
||||||
|
f eval-result set-global
|
||||||
|
f eval-output set-global ;
|
||||||
|
|
||||||
: end-eval ( output -- )
|
: end-eval ( output -- )
|
||||||
eval-output set-global send-retort pop-status ;
|
eval-output set-global send-retort pop-status ;
|
||||||
|
@ -70,5 +60,8 @@ t eval-res-flag set-global
|
||||||
|
|
||||||
: eval-in-context ( lines in usings -- )
|
: eval-in-context ( lines in usings -- )
|
||||||
begin-eval
|
begin-eval
|
||||||
[ eval-usings eval-in eval ] with-string-writer
|
[
|
||||||
end-eval ;
|
{ "fuel" "syntax" } prepend
|
||||||
|
<manifest> manifest set
|
||||||
|
[ eval-usings eval-in eval ] with-string-writer
|
||||||
|
] with-scope end-eval ;
|
||||||
|
|
Loading…
Reference in New Issue