Diff
Not logged in

Differences From Artifact [6db0ce492da06d00]:

To Artifact [4f24d3bd11889ec1]:


177 ctxNeo.set(p.name, lay, args[i]); 177 ctxNeo.set(p.name, lay, args[i]); 178 auto v = eval(e.funbody, ctxNeo, true, lay); 178 auto v = eval(e.funbody, ctxNeo, true, lay); 179 // auto memoization 179 // auto memoization 180 if( lay != "@v" ) 180 if( lay != "@v" ) 181 memo[lay][args] = v; 181 memo[lay][args] = v; 182 return v; 182 return v; 183 }); 183 }); > 184 }, > 185 delegate Value (AST e) > 186 { > 187 throw genex!RuntimeException(e.pos, sprintf!"Unknown Kin > 188 } > 189 ); > 190 } > 191 > 192 // [TODO] Optimization > 193 Value macroEval(AST e, Table ctx, bool AlwaysMacro) > 194 { > 195 Layer theLayer = "@v"; > 196 > 197 Table pos = new Table; > 198 pos.set("filename", theLayer, new StrValue(e.pos.filename)); > 199 pos.set("lineno", theLayer, new IntValue(BigInt(e.pos.lineno))); > 200 pos.set("column", theLayer, new IntValue(BigInt(e.pos.column))); > 201 return e.match( > 202 (StrLiteral e) > 203 { > 204 Table t = new Table; > 205 t.set("pos", theLayer, pos); > 206 t.set("is", theLayer, new StrValue("str")); > 207 t.set("data", theLayer, new StrValue(e.data)); > 208 return t; > 209 }, > 210 (IntLiteral e) > 211 { > 212 Table t = new Table; > 213 t.set("pos", theLayer, pos); > 214 t.set("is", theLayer, new StrValue("int")); > 215 t.set("data", theLayer, new IntValue(e.data)); > 216 return t; > 217 }, > 218 (VarExpression e) > 219 { > 220 Table t = new Table; > 221 t.set("pos", theLayer, pos); > 222 t.set("is", theLayer, new StrValue("var")); > 223 t.set("name", theLayer, new StrValue(e.var)); > 224 return t; > 225 }, > 226 (LayeredExpression e) > 227 { > 228 if( AlwaysMacro ) > 229 { > 230 Table t = new Table; > 231 t.set("pos", theLayer, pos); > 232 t.set("is", theLayer, new StrValue("lay")); > 233 t.set("expr", theLayer, macroEval(e.expr,ctx,Alw > 234 return cast(Value)t; > 235 } > 236 else > 237 { > 238 return eval(e.expr, ctx, true, e.lay); > 239 } > 240 }, > 241 (LetExpression e) > 242 { > 243 Table t = new Table; > 244 t.set("pos", theLayer, pos); > 245 t.set("is", theLayer, new StrValue("let")); > 246 t.set("name", theLayer, new StrValue(e.var)); > 247 t.set("init", theLayer, macroEval(e.init,ctx,AlwaysMacro > 248 t.set("expr", theLayer, macroEval(e.expr,ctx,AlwaysMacro > 249 return t; > 250 }, > 251 (FuncallExpression e) > 252 { > 253 // [TODO] @macro invokation!!!! > 254 // if e.fun is varname and its ctx[@macro] is set, sw > 255 Table t = new Table; > 256 t.set("pos", theLayer, pos); > 257 t.set("is", theLayer, new StrValue("app")); > 258 t.set("fun", theLayer, macroEval(e.fun,ctx,AlwaysMacro)) > 259 Table args = new Table; > 260 foreach_reverse(a; e.args) { > 261 Table cons = new Table; > 262 cons.set("car",theLayer,macroEval(a,ctx,AlwaysMa > 263 cons.set("cdr",theLayer,args); > 264 args = cons; > 265 } > 266 t.set("arg", theLayer, args); > 267 return t; > 268 }, > 269 (FunLiteral e) > 270 { > 271 Table t = new Table; > 272 t.set("pos", theLayer, pos); > 273 t.set("is", theLayer, new StrValue("fun")); > 274 t.set("body", theLayer, macroEval(e.funbody,ctx,AlwaysM > 275 Table param = new Table; > 276 foreach_reverse(p; e.params) > 277 { > 278 Table cons = new Table; > 279 Table kv = new Table; > 280 kv.set("name", theLayer, new StrValue(p.name)); > 281 foreach_reverse(lay; p.layers) > 282 { > 283 Table cons2 = new Table; > 284 cons2.set("car", theLayer, new StrValue( > 285 cons2.set("cdr", theLayer, kv); > 286 kv = cons2; > 287 } > 288 cons.set("car", theLayer, kv); > 289 cons.set("cdr", theLayer, param); > 290 param = cons; > 291 } > 292 t.set("param", theLayer, param); > 293 return t; 184 }, 294 }, 185 delegate Value (AST e) 295 delegate Value (AST e) 186 { 296 { 187 throw genex!RuntimeException(e.pos, sprintf!"Unknown Kin 297 throw genex!RuntimeException(e.pos, sprintf!"Unknown Kin 188 } 298 } 189 ); 299 ); 190 } 300 }