]> gitweb.factorcode.org Git - factor.git/blob - extra/fuel/eval/eval.factor
fuel.eval: better manifest handling in eval-in-context
[factor.git] / extra / fuel / eval / eval.factor
1 ! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays continuations debugger fuel.pprint io io.streams.string
4 kernel listener namespaces prettyprint.config sequences vocabs.parser
5 ;
6 IN: fuel.eval
7
8 SYMBOL: restarts-stack
9 V{ } clone restarts-stack set-global
10
11 SYMBOL: eval-error
12 f eval-error set-global
13
14 SYMBOL: eval-result
15 f eval-result set-global
16
17 SYMBOL: eval-output
18 f eval-output set-global
19
20 SYMBOL: eval-res-flag
21 t eval-res-flag set-global
22
23 : eval-restartable? ( -- ? )
24     eval-res-flag get-global ;
25
26 : push-status ( -- )
27     restarts get-global clone restarts-stack get push ;
28
29 : pop-restarts ( restarts -- )
30     eval-restartable? [ drop ] [ clone restarts set-global ] if ;
31
32 : pop-status ( -- )
33     restarts-stack get [ pop pop-restarts ] unless-empty ;
34
35 : send-retort ( -- )
36     eval-error get-global
37     eval-result get-global
38     eval-output get-global 3array
39     [ fuel-pprint ] without-limits
40     flush nl "<~FUEL~>" write nl flush ;
41
42 : begin-eval ( -- )
43     push-status
44     f eval-error set-global
45     f eval-result set-global
46     f eval-output set-global ;
47
48 : end-eval ( output -- )
49     eval-output set-global send-retort pop-status ;
50
51 : eval ( lines -- )
52     [ parse-lines-interactive call( -- ) ] curry
53     [ [ eval-error set-global ] [ print-error ] bi ] recover ;
54
55 : eval-usings ( usings -- )
56     [ [ use-vocab ] curry ignore-errors ] each ;
57
58 : eval-in ( in -- )
59     [ set-current-vocab ] when* ;
60
61 : eval-in-context ( lines in usings -- )
62     begin-eval
63     [
64         { "fuel" "syntax" } prepend
65         <manifest> manifest set
66         [ eval-usings eval-in eval ] with-string-writer
67     ] with-scope end-eval ;