Diff
Not logged in

Differences From Artifact [c85d31e67d8ceb4b]:

To Artifact [9a9618fb0277f966]:


105 return f.invoke(pos, lay, ctx); 105 return f.invoke(pos, lay, ctx); 106 } 106 } 107 throw genex!RuntimeException(pos, "tried to call non-function"); 107 throw genex!RuntimeException(pos, "tried to call non-function"); 108 } 108 } 109 109 110 Value lift(in LexPosition pos, Value v, Layer lay, Table callerCtx) 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 // similar to invoke Function, but with only one argument bound to Value 116 // similar to invoke Function, but with only one argument bound to Value 113 Value _f = callerCtx.get(lay, SystemLayer, pos); 117 Value _f = callerCtx.get(lay, SystemLayer, pos); 114 if(auto f = cast(FunValue)_f) 118 if(auto f = cast(FunValue)_f) 115 { 119 { 116 Table ctx = new Table(f.definitionContext(), Table.Kind.NotPropa 120 Table ctx = new Table(f.definitionContext(), Table.Kind.NotPropa 117 auto ps = f.params(); 121 auto ps = f.params(); 118 if( ps.length != 1 ) 122 if( ps.length != 1 ) ................................................................................................................................................................................ 151 else // rise 155 else // rise 152 return lift(e.pos,v,lay,ctx); 156 return lift(e.pos,v,lay,ctx); 153 }, 157 }, 154 (VarExpression e) 158 (VarExpression e) 155 { 159 { 156 if( lay == ValueLayer ) 160 if( lay == ValueLayer ) 157 return ctx.get(e.name, lay, e.pos); 161 return ctx.get(e.name, lay, e.pos); 158 try { | 162 if( ctx.has(e.name, lay, e.pos) ) 159 return ctx.get(e.name, lay, e.pos); 163 return ctx.get(e.name, lay, e.pos); 160 } catch( Throwable ) { // [TODO] more precise... | 164 else 161 return lift(e.pos, ctx.get(e.name, ValueLayer, e 165 return lift(e.pos, ctx.get(e.name, ValueLayer, e 162 } < 163 }, 166 }, 164 (LayExpression e) 167 (LayExpression e) 165 { 168 { 166 if( e.layer == MacroLayer ) 169 if( e.layer == MacroLayer ) 167 return macroEval(e.expr, ctx, false); 170 return macroEval(e.expr, ctx, false); 168 else 171 else 169 return eval(e.expr, ctx, true, e.layer); 172 return eval(e.expr, ctx, true, e.layer); ................................................................................................................................................................................ 180 }, 183 }, 181 (FuncallExpression e) 184 (FuncallExpression e) 182 { 185 { 183 return invokeFunction(e.pos, eval(e.fun, ctx, true, lay) 186 return invokeFunction(e.pos, eval(e.fun, ctx, true, lay) 184 }, 187 }, 185 (FunLiteral e) 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 return new UserDefinedFunValue(e, ctx); 190 return new UserDefinedFunValue(e, ctx); 193 }, 191 }, 194 delegate Value (AST e) 192 delegate Value (AST e) 195 { 193 { 196 throw genex!RuntimeException(e.pos, sprintf!"Unknown Kin 194 throw genex!RuntimeException(e.pos, sprintf!"Unknown Kin 197 } 195 } 198 ); 196 ); ................................................................................................................................................................................ 237 t.set("pos", theLayer, pos); 235 t.set("pos", theLayer, pos); 238 t.set("is", theLayer, new StrValue("int")); 236 t.set("is", theLayer, new StrValue("int")); 239 t.set("data", theLayer, new IntValue(e.data)); 237 t.set("data", theLayer, new IntValue(e.data)); 240 return t; 238 return t; 241 }, 239 }, 242 (VarExpression e) 240 (VarExpression e) 243 { 241 { 244 try { | 242 if( ctx.has(e.name, MacroLayer, e.pos) ) 245 return ctx.get(e.name, MacroLayer, e.pos); 243 return ctx.get(e.name, MacroLayer, e.pos); 246 } catch( Throwable ) {// [TODO] more precies... | 244 else { 247 Table t = new Table; 245 Table t = new Table; 248 t.set("pos", theLayer, pos); 246 t.set("pos", theLayer, pos); 249 t.set("is", theLayer, new StrValue("var")); 247 t.set("is", theLayer, new StrValue("var")); 250 t.set("name", theLayer, new StrValue(e.name)); 248 t.set("name", theLayer, new StrValue(e.name)); 251 return cast(Value)t; 249 return cast(Value)t; 252 } 250 } 253 }, 251 },