Differences From Artifact [47affa2343c633ca]:
- File
polemy/eval.d
- 2010-11-26 07:14:27 - part of checkin [94f0382499] on branch trunk - changed the semantics of def foo(x @macro) {}, the @macro-layered parameter. - in @macro( foo(e) ), e is run in @macro (this is ok) - in @value( foo(e) ), e is run in (rawmacro)!! - in @rawmacro( foo(e) ), e is run in (rawmacro)!! (user: kinaba) [annotate]
To Artifact [8d6e708eceba536a]:
- File
polemy/eval.d
- 2010-11-26 07:42:38 - part of checkin [f7e9e77316] on branch trunk - introduced "..." expression, and replaced the pattern match failure with this. (user: kinaba) [annotate]
149 { 149 {
150 Value ri = eval(e.init, lay, newCtx); 150 Value ri = eval(e.init, lay, newCtx);
151 if(e.name!="_") 151 if(e.name!="_")
152 newCtx.set(e.name, e.layer.empty ? lay : e.layer 152 newCtx.set(e.name, e.layer.empty ? lay : e.layer
153 return eval(e.expr, lay, newCtx, OverwriteCtx); 153 return eval(e.expr, lay, newCtx, OverwriteCtx);
154 } 154 }
155 } 155 }
> 156
> 157 Value eval( Die e, Layer lay, Table ctx, bool overwriteCtx=CascadeCtx )
> 158 {
> 159 if( isMacroLayer(lay) )
> 160 return ast2table(e, (AST e){return eval(e,lay,ctx);});
> 161 if( isUserDefinedLayer(lay) )
> 162 return new UndefinedValue;
> 163 throw genex!RuntimeException(e.pos, "undefined case");
> 164 }
156 165
157 private: 166 private:
158 // little little bit incremental macro defining version. 167 // little little bit incremental macro defining version.
159 // enables @macro foo(x)=... in ... foo ..., only at the top level of th 168 // enables @macro foo(x)=... in ... foo ..., only at the top level of th
160 // interpreter and functions. better than nothing :P 169 // interpreter and functions. better than nothing :P
161 Tuple!(Value,AST) macroAndEval( AST e_, Layer lay, Table ctx, bool overw 170 Tuple!(Value,AST) macroAndEval( AST e_, Layer lay, Table ctx, bool overw
162 , ref AST[void*] mandeCache) // [TODO] avoid assuming non-moving 171 , ref AST[void*] mandeCache) // [TODO] avoid assuming non-moving
................................................................................................................................................................................
479 main() 488 main()
480 `) ); 489 `) );
481 } 490 }
482 unittest 491 unittest
483 { 492 {
484 auto e = new Evaluator; 493 auto e = new Evaluator;
485 enrollRuntimeLibrary(e); 494 enrollRuntimeLibrary(e);
486 assert_nothrow( e.evalString(`case 1`) ); | 495 assert_throw!RuntimeException( e.evalString(`case 1`) );
487 assert_nothrow( e.evalString(`case 1 when 1: 2`) ); 496 assert_nothrow( e.evalString(`case 1 when 1: 2`) );
488 497
489 // this is a shorthand for 498 // this is a shorthand for
490 // @macro x = fun(){} in @macro(x) 499 // @macro x = fun(){} in @macro(x)
491 // so it is ok to fail, but it is really incovenient on REPL 500 // so it is ok to fail, but it is really incovenient on REPL
492 assert_nothrow( e.evalString(`@macro x=fun(){}`) ); 501 assert_nothrow( e.evalString(`@macro x=fun(){}`) );
493 } 502 }
> 503
> 504 unittest
> 505 {
> 506 auto e = new Evaluator;
> 507 enrollRuntimeLibrary(e);
> 508 assert_throw!RuntimeException( e.evalString(`...`) );
> 509 assert_eq( e.evalString(`@@foo(x){x}; @foo(...)`), new UndefinedValue );
> 510 }