Diff
Not logged in

Differences From Artifact [74dd93745d781116]:

To Artifact [56f0a662740b0906]:


135 135 136 Value eval( Let e, Layer lay, Table ctx, bool overwriteCtx=CascadeCtx ) 136 Value eval( Let e, Layer lay, Table ctx, bool overwriteCtx=CascadeCtx ) 137 { 137 { 138 Table newCtx = overwriteCtx ? ctx : new Table(ctx, Table.Kind.No 138 Table newCtx = overwriteCtx ? ctx : new Table(ctx, Table.Kind.No 139 if( isASTLayer(lay) ) 139 if( isASTLayer(lay) ) 140 return ast2table(e, (AST ee){ 140 return ast2table(e, (AST ee){ 141 // need this for correct scoping (outer scope ma 141 // need this for correct scoping (outer scope ma 142 if(ee is e.expr) | 142 if(e.name!="_" && ee is e.expr) 143 newCtx.set(e.name, NoopLayer, null); 143 newCtx.set(e.name, NoopLayer, null); 144 return eval(ee,lay,newCtx); 144 return eval(ee,lay,newCtx); 145 }); 145 }); 146 else 146 else 147 { 147 { 148 Value ri = eval(e.init, lay, newCtx); 148 Value ri = eval(e.init, lay, newCtx); > 149 if(e.name!="_") 149 newCtx.set(e.name, e.layer.empty ? lay : e.layer, ri); | 150 newCtx.set(e.name, e.layer.empty ? lay : e.layer 150 return eval(e.expr, lay, newCtx, OverwriteCtx); 151 return eval(e.expr, lay, newCtx, OverwriteCtx); 151 } 152 } 152 } 153 } 153 154 154 private: 155 private: 155 // little little bit incremental macro defining version. 156 // little little bit incremental macro defining version. 156 // enables @macro foo(x)=... in ... foo ..., only at the top level of th 157 // enables @macro foo(x)=... in ... foo ..., only at the top level of th ................................................................................................................................................................................ 459 } 460 } 460 unittest 461 unittest 461 { 462 { 462 auto e = new Evaluator; 463 auto e = new Evaluator; 463 enrollRuntimeLibrary(e); 464 enrollRuntimeLibrary(e); 464 assert_nothrow( e.evalString(`case 1`) ); 465 assert_nothrow( e.evalString(`case 1`) ); 465 assert_nothrow( e.evalString(`case 1 when 1: 2`) ); 466 assert_nothrow( e.evalString(`case 1 when 1: 2`) ); > 467 > 468 // this is a shorthand for > 469 // @macro x = fun(){} in @macro(x) > 470 // so it is ok to fail, but it is really incovenient on REPL > 471 assert_nothrow( e.evalString(`@macro x=fun(){}`) ); 466 } 472 } 467 473 468 /* 474 /* 469 unittest 475 unittest 470 { 476 { 471 assert_eq( evalString(`var fac = fun(x){ 477 assert_eq( evalString(`var fac = fun(x){ 472 if(x) 478 if(x)