]> gitweb.factorcode.org Git - factor.git/blob - basis/eval/eval.factor
1accb66c994c0ff0b6e65e180270095a3c27c8dc
[factor.git] / basis / eval / eval.factor
1 ! Copyright (C) 2008, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators combinators.smart compiler.units
4 continuations debugger effects.parser io io.streams.string
5 kernel namespaces parser parser.notes prettyprint sequences
6 splitting ;
7 IN: eval
8
9 : parse-string ( str -- quot )
10     [ split-lines parse-lines ] with-compilation-unit ;
11
12 : (eval) ( str effect -- )
13     [ parse-string ] dip call-effect ; inline
14
15 : eval ( str effect -- )
16     [ (eval) ] with-file-vocabs ; inline
17
18 SYNTAX: eval( \ eval parse-call-paren ;
19
20 : (eval>string) ( str -- output )
21     [
22         parser-quiet? on
23         '[ _ ( -- ) (eval) ] [ print-error ] recover
24     ] with-string-writer ;
25
26 : eval>string ( str -- output )
27     [ (eval>string) ] with-file-vocabs ;
28
29 : (eval-with-stack) ( str -- )
30     parse-string [ output>array datastack. ] call( quot -- ) ;
31
32 : eval-with-stack ( str -- )
33     [ (eval-with-stack) ] with-file-vocabs ;
34
35 : (eval-with-stack>string) ( str -- output )
36     [
37         parser-quiet? on
38         [ (eval-with-stack) ] [ nip print-error ] recover
39     ] with-string-writer ;
40
41 : eval-with-stack>string ( str -- output )
42     [ (eval-with-stack>string) ] with-file-vocabs ;