1 ! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays continuations debugger 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 f eval-result set-global
15 t eval-res-flag set-global
17 : eval-restartable? ( -- ? )
18 eval-res-flag get-global ;
21 restarts get-global clone restarts-stack get push ;
23 : pop-restarts ( restarts -- )
24 eval-restartable? [ drop ] [ clone restarts set-global ] if ;
27 restarts-stack get [ pop pop-restarts ] unless-empty ;
29 : send-retort ( error result output -- )
30 3array [ fuel-pprint ] without-limits flush nl
31 "<~FUEL~>" write nl flush ;
34 f eval-result set-global push-status ;
36 : end-eval ( error/f output -- )
37 eval-result get-global swap send-retort pop-status ;
39 : eval ( lines -- error/f )
40 [ parse-lines-interactive call( -- ) f ] curry
41 [ dup print-error ] recover ;
43 : eval-usings ( usings -- )
44 [ [ use-vocab ] curry ignore-errors ] each ;
47 [ set-current-vocab ] when* ;
49 : eval-in-context ( lines in usings/f -- )
54 ! The idea is that a correct usings list should always be
55 ! specified. But a lot of code in FUEL sends empty usings
56 ! lists so then we have to use the current manifests
58 manifest get search-vocab-names>> members
60 ! These vocabs are always needed in the manifest. syntax for
61 ! obvious reasons, fuel for FUEL stuff and debugger for the :N
63 { "fuel" "syntax" "debugger" } prepend
65 <manifest> manifest namespaces:set
66 [ eval-usings eval-in eval ] with-string-writer
67 ] with-scope end-eval ;