Differences From Artifact [c85d31e67d8ceb4b]:
- File
polemy/eval.d
- 2010-11-21 14:24:33 - part of checkin [3995a5eb6a] on branch trunk - added iikagen pattern match (user: kinaba) [annotate]
To Artifact [9a9618fb0277f966]:
- File
polemy/eval.d
- 2010-11-21 15:48:16 - part of checkin [f86026acb8] on branch trunk - macro cache and automemoization reloaded. auto re-run implemented. but automemo and autorerun is currently disabled. we need Table.opCmp... we also need to think more about the memoization (user: kinaba) [annotate]
105 105 return f.invoke(pos, lay, ctx);
106 106 }
107 107 throw genex!RuntimeException(pos, "tried to call non-function");
108 108 }
109 109
110 110 Value lift(in LexPosition pos, Value v, Layer lay, Table callerCtx)
111 111 {
112 + // functions are automatically lifterd
113 + if( cast(FunValue) v )
114 + return v;
115 +
112 116 // similar to invoke Function, but with only one argument bound to ValueLayer
113 117 Value _f = callerCtx.get(lay, SystemLayer, pos);
114 118 if(auto f = cast(FunValue)_f)
115 119 {
116 120 Table ctx = new Table(f.definitionContext(), Table.Kind.NotPropagateSet);
117 121 auto ps = f.params();
118 122 if( ps.length != 1 )
................................................................................
151 155 else // rise
152 156 return lift(e.pos,v,lay,ctx);
153 157 },
154 158 (VarExpression e)
155 159 {
156 160 if( lay == ValueLayer )
157 161 return ctx.get(e.name, lay, e.pos);
158 - try {
162 + if( ctx.has(e.name, lay, e.pos) )
159 163 return ctx.get(e.name, lay, e.pos);
160 - } catch( Throwable ) { // [TODO] more precise...
164 + else
161 165 return lift(e.pos, ctx.get(e.name, ValueLayer, e.pos), lay, ctx);
162 - }
163 166 },
164 167 (LayExpression e)
165 168 {
166 169 if( e.layer == MacroLayer )
167 170 return macroEval(e.expr, ctx, false);
168 171 else
169 172 return eval(e.expr, ctx, true, e.layer);
................................................................................
180 183 },
181 184 (FuncallExpression e)
182 185 {
183 186 return invokeFunction(e.pos, eval(e.fun, ctx, true, lay), e.args, ctx, lay);
184 187 },
185 188 (FunLiteral e)
186 189 {
187 - Value[Value[]][Layer] memo;
188 - AST macroMemo = null; // cache
189 -
190 - // funvalue need not be rised
191 - // no, need to be rised !! suppose @t(fib)("int")
192 190 return new UserDefinedFunValue(e, ctx);
193 191 },
194 192 delegate Value (AST e)
195 193 {
196 194 throw genex!RuntimeException(e.pos, sprintf!"Unknown Kind of Expression %s"(typeid(e)));
197 195 }
198 196 );
................................................................................
237 235 t.set("pos", theLayer, pos);
238 236 t.set("is", theLayer, new StrValue("int"));
239 237 t.set("data", theLayer, new IntValue(e.data));
240 238 return t;
241 239 },
242 240 (VarExpression e)
243 241 {
244 - try {
242 + if( ctx.has(e.name, MacroLayer, e.pos) )
245 243 return ctx.get(e.name, MacroLayer, e.pos);
246 - } catch( Throwable ) {// [TODO] more precies...
244 + else {
247 245 Table t = new Table;
248 246 t.set("pos", theLayer, pos);
249 247 t.set("is", theLayer, new StrValue("var"));
250 248 t.set("name", theLayer, new StrValue(e.name));
251 249 return cast(Value)t;
252 250 }
253 251 },