Differences From Artifact [050eab1743a45f8b]:
- File
polemy/eval.d
- 2010-11-09 14:59:36 - part of checkin [7465fcdd7f] on branch trunk - layered function invocation (user: kinaba) [annotate]
To Artifact [ab3a0c217b77981b]:
- File
polemy/eval.d
- 2010-11-10 12:38:54 - part of checkin [38fcc662be] on branch trunk - cleaned up documentation comments (user: kinaba) [annotate]
9 9 import polemy.lex : LexPosition;
10 10 import polemy.ast;
11 11 import polemy.parse;
12 12 import polemy.value;
13 13 import std.typecons;
14 14 import std.stdio;
15 15
16 +///
16 17 Table createGlobalContext()
17 18 {
18 19 auto ctx = new Table;
19 20 // [TODO] autogenerate these typechecks
20 21 ctx.set("+", "@v", new FunValue(delegate Value(immutable LexPosition pos, Layer lay, Value[] args){
21 22 if( args.length != 2 )
22 23 throw genex!RuntimeException(pos, "+ takes two arguments!!");
................................................................................
85 86
86 87 /// Entry point of this module
87 88
88 89 Tuple!(Value,"val",Table,"ctx") evalString(S,T...)(S str, T fn_ln_cn)
89 90 {
90 91 return eval( polemy.parse.parseString(str, fn_ln_cn) );
91 92 }
93 +
94 +/// Entry point of this module
92 95
93 96 Tuple!(Value,"val",Table,"ctx") evalFile(S, T...)(S filename, T ln_cn)
94 97 {
95 98 return eval( polemy.parse.parseFile(filename, ln_cn) );
96 99 }
100 +
101 +/// Entry point of this module
97 102
98 103 Tuple!(Value,"val",Table,"ctx") eval(AST e)
99 104 {
100 105 Table ctx = createGlobalContext();
101 106 return typeof(return)(eval(e, ctx, false, "@v"), ctx);
102 107 }
103 108
109 +/// Entry point of this module
110 +/// If splitCtx = true, then inner variable declaration do not overwrite ctx.
111 +/// lay is the layer ID for evaluation (standard value semantics uses "@v").
112 +
104 113 Value eval(AST _e, Table ctx, bool splitCtx, Layer lay)
105 114 {
106 115 if( auto e = cast(StrLiteral)_e )
107 116 {
108 117 return new StrValue(e.data);
109 118 }
110 119 else