-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: splitting parser compiler.units kernel namespaces
-debugger io.streams.string ;
+USING: combinators combinators.smart compiler.units
+continuations debugger effects.parser io.streams.string
+kernel namespaces parser parser.notes prettyprint splitting ;
IN: eval
-: eval ( str -- )
- [ string-lines parse-fresh ] with-compilation-unit call ;
+: parse-string ( str -- quot )
+ [ split-lines parse-lines ] with-compilation-unit ;
+
+: (eval) ( str effect -- )
+ [ parse-string ] dip call-effect ; inline
+
+: eval ( str effect -- )
+ [ (eval) ] with-file-vocabs ; inline
+
+SYNTAX: eval( \ eval parse-call-paren ;
+
+: (eval>string) ( str -- output )
+ [
+ parser-quiet? on
+ '[ _ ( -- ) (eval) ] [ print-error ] recover
+ ] with-string-writer ;
: eval>string ( str -- output )
+ [ (eval>string) ] with-file-vocabs ;
+
+: (eval-with-stack) ( str -- )
+ parse-string [ output>array datastack. ] call( quot -- ) ;
+
+: eval-with-stack ( str -- )
+ [ (eval-with-stack) ] with-file-vocabs ;
+
+: (eval-with-stack>string) ( str -- output )
[
- parser-notes off
- [ [ eval ] keep ] try drop
+ parser-quiet? on
+ [ (eval-with-stack) ] [ nip print-error ] recover
] with-string-writer ;
+
+: eval-with-stack>string ( str -- output )
+ [ (eval-with-stack>string) ] with-file-vocabs ;