1 ! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays continuations debugger fry fuel.pprint io
4 io.streams.string kernel listener namespaces parser.notes
5 prettyprint.config sequences sets vocabs.parser ;
9 V{ } clone restarts-stack set-global
12 t eval-res-flag set-global
14 : eval-restartable? ( -- ? )
15 eval-res-flag get-global ;
18 restarts get-global clone restarts-stack get push ;
20 : pop-restarts ( restarts -- )
21 eval-restartable? [ drop ] [ clone restarts set-global ] if ;
24 restarts-stack get [ pop pop-restarts ] unless-empty ;
26 : send-retort ( error result output -- )
27 3array [ fuel-pprint ] without-limits flush nl
28 "<~FUEL~>" write nl flush ;
33 : end-eval ( result error/f output -- )
34 swapd send-retort pop-status ;
36 : eval ( lines -- result error/f )
37 '[ _ parse-lines-interactive call( -- x ) f ]
38 [ dup print-error f swap ] recover ;
40 : eval-usings ( usings -- )
41 [ [ use-vocab ] curry ignore-errors ] each ;
44 [ set-current-vocab ] when* ;
46 : eval-in-context ( lines in usings/f -- )
51 ! The idea is that a correct usings list should always be
52 ! specified. But a lot of code in FUEL sends empty usings
53 ! lists so then we have to use the current manifests
55 manifest get search-vocab-names>> members
57 ! These vocabs are always needed in the manifest. syntax for
58 ! obvious reasons, fuel for FUEL stuff and debugger for the :N
60 { "fuel" "syntax" "debugger" } prepend
62 <manifest> manifest namespaces:set
63 [ eval-usings eval-in eval ] with-string-writer
64 ] with-scope end-eval ;