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 import polemy.lex : LexPosition; 9 import polemy.lex : LexPosition;
10 import polemy.ast; 10 import polemy.ast;
11 import polemy.parse; 11 import polemy.parse;
12 import polemy.value; 12 import polemy.value;
13 import std.typecons; 13 import std.typecons;
14 import std.stdio; 14 import std.stdio;
15 15
> 16 ///
16 Table createGlobalContext() 17 Table createGlobalContext()
17 { 18 {
18 auto ctx = new Table; 19 auto ctx = new Table;
19 // [TODO] autogenerate these typechecks 20 // [TODO] autogenerate these typechecks
20 ctx.set("+", "@v", new FunValue(delegate Value(immutable LexPosition pos 21 ctx.set("+", "@v", new FunValue(delegate Value(immutable LexPosition pos
21 if( args.length != 2 ) 22 if( args.length != 2 )
22 throw genex!RuntimeException(pos, "+ takes two arguments 23 throw genex!RuntimeException(pos, "+ takes two arguments
................................................................................................................................................................................
85 86
86 /// Entry point of this module 87 /// Entry point of this module
87 88
88 Tuple!(Value,"val",Table,"ctx") evalString(S,T...)(S str, T fn_ln_cn) 89 Tuple!(Value,"val",Table,"ctx") evalString(S,T...)(S str, T fn_ln_cn)
89 { 90 {
90 return eval( polemy.parse.parseString(str, fn_ln_cn) ); 91 return eval( polemy.parse.parseString(str, fn_ln_cn) );
91 } 92 }
> 93
> 94 /// Entry point of this module
92 95
93 Tuple!(Value,"val",Table,"ctx") evalFile(S, T...)(S filename, T ln_cn) 96 Tuple!(Value,"val",Table,"ctx") evalFile(S, T...)(S filename, T ln_cn)
94 { 97 {
95 return eval( polemy.parse.parseFile(filename, ln_cn) ); 98 return eval( polemy.parse.parseFile(filename, ln_cn) );
96 } 99 }
> 100
> 101 /// Entry point of this module
97 102
98 Tuple!(Value,"val",Table,"ctx") eval(AST e) 103 Tuple!(Value,"val",Table,"ctx") eval(AST e)
99 { 104 {
100 Table ctx = createGlobalContext(); 105 Table ctx = createGlobalContext();
101 return typeof(return)(eval(e, ctx, false, "@v"), ctx); 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 Value eval(AST _e, Table ctx, bool splitCtx, Layer lay) 113 Value eval(AST _e, Table ctx, bool splitCtx, Layer lay)
105 { 114 {
106 if( auto e = cast(StrLiteral)_e ) 115 if( auto e = cast(StrLiteral)_e )
107 { 116 {
108 return new StrValue(e.data); 117 return new StrValue(e.data);
109 } 118 }
110 else 119 else