]> gitweb.factorcode.org Git - factor.git/commitdiff
fuel.eval: better manifest handling in eval-in-context
authorBjörn Lindqvist <bjourne@gmail.com>
Sun, 25 Jun 2017 23:39:28 +0000 (01:39 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Mon, 26 Jun 2017 03:44:51 +0000 (05:44 +0200)
extra/fuel/eval/eval-tests.factor
extra/fuel/eval/eval.factor

index c6d149aee61d1afa5f6903fb1383f0718ef6e534..ea8430f0b2d8ed126fd8fce2cc654bc25c4733d3 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
 ! See http://factorcode.org/license.txt for BSD license.
 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
 
 ! pop-restarts
@@ -37,3 +37,12 @@ IN: fuel.eval.tests
         f eval-result set-global
     ] with-manifest
 ] unit-test
+
+{
+    "(nil nil \"9\\n\")\n<~FUEL~>\n"
+} [
+    [
+        { "3 sq . " } "hi99"
+        { "math" "prettyprint" "kernel" } eval-in-context
+    ] with-string-writer
+] unit-test
index 85006e908969951031604527a8063af791eefe04..5ac7faff445d1d85061515cf2b45a4a30d697359 100644 (file)
@@ -1,14 +1,12 @@
 ! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays continuations debugger fuel.pprint io
-io.streams.string kernel listener namespaces prettyprint.config sequences
-vocabs.parser ;
+USING: arrays continuations debugger fuel.pprint io io.streams.string
+kernel listener namespaces prettyprint.config sequences vocabs.parser
+;
 IN: fuel.eval
 
-TUPLE: status manifest restarts ;
-
-SYMBOL: status-stack
-V{ } clone status-stack set-global
+SYMBOL: restarts-stack
+V{ } clone restarts-stack set-global
 
 SYMBOL: eval-error
 f eval-error set-global
@@ -26,24 +24,13 @@ t eval-res-flag set-global
     eval-res-flag get-global ;
 
 : push-status ( -- )
-    manifest get clone restarts get-global clone status boa
-    status-stack get push ;
+    restarts get-global clone restarts-stack get push ;
 
 : pop-restarts ( restarts -- )
     eval-restartable? [ drop ] [ clone restarts set-global ] if ;
 
 : pop-status ( -- )
-    status-stack get [
-        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 ;
+    restarts-stack get [ pop pop-restarts ] unless-empty ;
 
 : send-retort ( -- )
     eval-error get-global
@@ -53,7 +40,10 @@ t eval-res-flag set-global
     flush nl "<~FUEL~>" write nl flush ;
 
 : 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 -- )
     eval-output set-global send-retort pop-status ;
@@ -70,5 +60,8 @@ t eval-res-flag set-global
 
 : eval-in-context ( lines in usings -- )
     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 ;