]> gitweb.factorcode.org Git - factor.git/commitdiff
eval: adding eval-with-stack
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 4 Feb 2022 05:51:56 +0000 (21:51 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 4 Feb 2022 05:51:56 +0000 (21:51 -0800)
basis/eval/eval-docs.factor
basis/eval/eval.factor
basis/help/lint/checks/checks.factor

index e4dcfcebda02b7989282b5f792dd62cc2fd34c62..a90e82bfee2b29a3ecd7dec227a49b0834743e43 100644 (file)
@@ -26,6 +26,10 @@ HELP: eval(
 }
 { $errors "Throws an error if the input is malformed, or if the evaluation itself throws an error." } ;
 
+HELP: eval-with-stack
+{ $values { "str" string } { "output" string } }
+{ $description "Parses Factor source code from " { $snippet "str" } ", and then calls the resulting quotation, and then prints the data stack if any objects are left." } ;
+
 HELP: eval>string
 { $values { "str" string } { "output" string } }
 { $description "Evaluates the Factor code in " { $snippet "str" } " with " { $link output-stream } " rebound to a string output stream, then outputs the resulting string. The code in the string must not take or leave any values on the stack." }
index cdf249349e1f4476138844a334590d16ce26c87a..9f3d8f138823c323342dde819b7db99a554e0fe3 100644 (file)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2008, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: combinators compiler.units continuations debugger
-effects.parser io.streams.string kernel namespaces parser
-parser.notes splitting ;
+USING: combinators combinators.smart compiler.units
+continuations debugger effects.parser io io.streams.string
+kernel namespaces parser parser.notes prettyprint sequences
+splitting ;
 IN: eval
 
 : parse-string ( str -- quot )
@@ -24,3 +25,17 @@ SYNTAX: eval( \ eval parse-call-paren ;
 
 : eval>string ( str -- output )
     [ (eval>string) ] with-file-vocabs ;
+
+: (eval-with-stack) ( str -- output )
+    [
+        [
+            parser-quiet? on parse-string [
+                output>array [
+                    nl "--- Data stack:" print stack.
+                ] unless-empty
+            ] call( quot -- )
+        ] [ nip print-error ] recover
+    ] with-string-writer ;
+
+: eval-with-stack ( str -- output )
+    [ (eval-with-stack) ] with-file-vocabs ;
index 6c73369f36b9083c88cc3d036424e8f75d68663b..42f657819d43f9037cee3dc32a8f34ab7746356f 100644 (file)
@@ -1,13 +1,12 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs classes classes.struct
-classes.tuple combinators combinators.short-circuit
-combinators.smart continuations debugger definitions effects
-eval formatting fry grouping help help.markup help.topics io
-io.streams.string kernel macros math math.statistics namespaces
-parser.notes prettyprint sequences sequences.deep sets splitting
-strings summary tools.destructors unicode vocabs vocabs.loader
-words words.constant words.symbol ;
+classes.tuple combinators combinators.short-circuit debugger
+definitions effects eval formatting grouping help help.markup
+help.topics io io.streams.string kernel macros math
+math.statistics namespaces prettyprint sequences sequences.deep
+sets splitting strings summary tools.destructors unicode vocabs
+vocabs.loader words words.constant words.symbol ;
 IN: help.lint.checks
 
 ERROR: simple-lint-error message ;
@@ -36,17 +35,6 @@ SYMBOL: vocab-articles
         } member?
     ] reject ;
 
-: eval-with-stack ( str -- output )
-    [
-        [
-            parser-quiet? on parse-string [
-                output>array [
-                    nl "--- Data stack:" print stack.
-                ] unless-empty
-            ] call( quot -- )
-        ] [ nip print-error ] recover
-    ] with-string-writer ;
-
 : check-example ( element -- )
     [
         '[