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    150      Value ri = eval(e.init, lay, newCtx);
   151    151      if(e.name!="_")
   152    152       newCtx.set(e.name, e.layer.empty ? lay : e.layer, ri);
   153    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    166   private:
   158    167    // little little bit incremental macro defining version.
   159    168    // enables @macro foo(x)=... in ... foo ..., only at the top level of the
   160    169    // interpreter and functions. better than nothing :P
   161    170    Tuple!(Value,AST) macroAndEval( AST e_, Layer lay, Table ctx, bool overwriteCtx
   162    171     , ref AST[void*] mandeCache) // [TODO] avoid assuming non-moving GC
................................................................................
   479    488   main()
   480    489    `) );
   481    490   }
   482    491   unittest
   483    492   {
   484    493    auto e = new Evaluator;
   485    494    enrollRuntimeLibrary(e);
   486         - assert_nothrow( e.evalString(`case 1`) );
          495  + assert_throw!RuntimeException( e.evalString(`case 1`) );
   487    496    assert_nothrow( e.evalString(`case 1 when 1: 2`) );
   488    497   
   489    498    // this is a shorthand for
   490    499    //   @macro x = fun(){} in @macro(x)
   491    500    // so it is ok to fail, but it is really incovenient on REPL
   492    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  +}