2009-01-11 18:52:31 -05:00
|
|
|
! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2017-06-25 19:39:28 -04:00
|
|
|
USING: arrays continuations debugger fuel.pprint io io.streams.string
|
2017-06-25 20:03:41 -04:00
|
|
|
kernel listener namespaces parser.notes prettyprint.config sequences
|
|
|
|
vocabs.parser ;
|
2009-01-11 18:52:31 -05:00
|
|
|
IN: fuel.eval
|
|
|
|
|
2017-06-25 19:39:28 -04:00
|
|
|
SYMBOL: restarts-stack
|
|
|
|
V{ } clone restarts-stack set-global
|
2009-01-11 18:52:31 -05:00
|
|
|
|
2017-01-08 07:18:50 -05:00
|
|
|
SYMBOL: eval-result
|
|
|
|
f eval-result set-global
|
2009-01-11 18:52:31 -05:00
|
|
|
|
2017-01-08 07:18:50 -05:00
|
|
|
SYMBOL: eval-res-flag
|
|
|
|
t eval-res-flag set-global
|
2009-01-11 18:52:31 -05:00
|
|
|
|
2017-01-08 07:18:50 -05:00
|
|
|
: eval-restartable? ( -- ? )
|
|
|
|
eval-res-flag get-global ;
|
2009-01-11 18:52:31 -05:00
|
|
|
|
2017-01-08 07:18:50 -05:00
|
|
|
: push-status ( -- )
|
2017-06-25 19:39:28 -04:00
|
|
|
restarts get-global clone restarts-stack get push ;
|
2009-01-11 18:52:31 -05:00
|
|
|
|
2017-01-08 07:18:50 -05:00
|
|
|
: pop-restarts ( restarts -- )
|
|
|
|
eval-restartable? [ drop ] [ clone restarts set-global ] if ;
|
2009-01-11 18:52:31 -05:00
|
|
|
|
2017-01-08 07:18:50 -05:00
|
|
|
: pop-status ( -- )
|
2017-06-25 19:39:28 -04:00
|
|
|
restarts-stack get [ pop pop-restarts ] unless-empty ;
|
2009-01-11 18:52:31 -05:00
|
|
|
|
2017-06-25 20:03:41 -04:00
|
|
|
: send-retort ( error result output -- )
|
|
|
|
3array [ fuel-pprint ] without-limits flush nl
|
|
|
|
"<~FUEL~>" write nl flush ;
|
2009-01-11 18:52:31 -05:00
|
|
|
|
2017-01-08 07:18:50 -05:00
|
|
|
: begin-eval ( -- )
|
2017-06-25 20:03:41 -04:00
|
|
|
f eval-result set-global push-status ;
|
2009-01-11 18:52:31 -05:00
|
|
|
|
2017-06-25 20:03:41 -04:00
|
|
|
: end-eval ( error/f output -- )
|
|
|
|
eval-result get-global swap send-retort pop-status ;
|
2009-01-11 18:52:31 -05:00
|
|
|
|
2017-06-25 20:03:41 -04:00
|
|
|
: eval ( lines -- error/f )
|
|
|
|
[ parse-lines-interactive call( -- ) f ] curry
|
|
|
|
[ dup print-error ] recover ;
|
2009-01-11 18:52:31 -05:00
|
|
|
|
2017-01-08 07:18:50 -05:00
|
|
|
: eval-usings ( usings -- )
|
2017-02-09 18:50:33 -05:00
|
|
|
[ [ use-vocab ] curry ignore-errors ] each ;
|
2009-01-11 18:52:31 -05:00
|
|
|
|
2017-01-08 07:18:50 -05:00
|
|
|
: eval-in ( in -- )
|
2009-05-15 00:23:06 -04:00
|
|
|
[ set-current-vocab ] when* ;
|
2009-01-11 18:52:31 -05:00
|
|
|
|
2017-01-08 07:18:50 -05:00
|
|
|
: eval-in-context ( lines in usings -- )
|
|
|
|
begin-eval
|
2017-06-25 19:39:28 -04:00
|
|
|
[
|
2017-06-25 20:03:41 -04:00
|
|
|
parser-quiet? on
|
|
|
|
! These vocabs are always needed in the manifest. syntax for
|
|
|
|
! obvious reasons, fuel for FUEL stuff and debugger for the :N
|
|
|
|
! words.
|
|
|
|
{ "fuel" "syntax" "debugger" } prepend
|
2017-06-25 19:39:28 -04:00
|
|
|
<manifest> manifest set
|
|
|
|
[ eval-usings eval-in eval ] with-string-writer
|
|
|
|
] with-scope end-eval ;
|