]> gitweb.factorcode.org Git - factor.git/blob - basis/eval/eval.factor
eval: adding eval-with-stack
[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 -- output )
30     [
31         [
32             parser-quiet? on parse-string [
33                 output>array [
34                     nl "--- Data stack:" print stack.
35                 ] unless-empty
36             ] call( quot -- )
37         ] [ nip print-error ] recover
38     ] with-string-writer ;
39
40 : eval-with-stack ( str -- output )
41     [ (eval-with-stack) ] with-file-vocabs ;