Check-in [f8684f4d69]
Not logged in
Overview
SHA1 Hash:f8684f4d697f07463bbd6f1dcc9721d928b2cad6
Date: 2010-11-26 14:29:24
User: kinaba
Comment:changed the desugaring of >>@macro x=e from >>@macro x=e in x to >>@macro x=e in "(macro definition)" for convenience during REPL interaction
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified polemy/eval.d from [74dd93745d781116] to [56f0a662740b0906].

135 135 136 136 Value eval( Let e, Layer lay, Table ctx, bool overwriteCtx=CascadeCtx ) 137 137 { 138 138 Table newCtx = overwriteCtx ? ctx : new Table(ctx, Table.Kind.NotPropagateSet); 139 139 if( isASTLayer(lay) ) 140 140 return ast2table(e, (AST ee){ 141 141 // need this for correct scoping (outer scope macro variables must be hidden!) 142 - if(ee is e.expr) 142 + if(e.name!="_" && ee is e.expr) 143 143 newCtx.set(e.name, NoopLayer, null); 144 144 return eval(ee,lay,newCtx); 145 145 }); 146 146 else 147 147 { 148 148 Value ri = eval(e.init, lay, newCtx); 149 - newCtx.set(e.name, e.layer.empty ? lay : e.layer, ri); 149 + if(e.name!="_") 150 + newCtx.set(e.name, e.layer.empty ? lay : e.layer, ri); 150 151 return eval(e.expr, lay, newCtx, OverwriteCtx); 151 152 } 152 153 } 153 154 154 155 private: 155 156 // little little bit incremental macro defining version. 156 157 // enables @macro foo(x)=... in ... foo ..., only at the top level of the ................................................................................ 459 460 } 460 461 unittest 461 462 { 462 463 auto e = new Evaluator; 463 464 enrollRuntimeLibrary(e); 464 465 assert_nothrow( e.evalString(`case 1`) ); 465 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 475 unittest 470 476 { 471 477 assert_eq( evalString(`var fac = fun(x){ 472 478 if(x)

Modified polemy/parse.d from [9aca36046bea5df8] to [3ad9850246d5111f].

118 118 string var = eatId("after "~kwd, AllowQuoted); // name of the declared variable 119 119 120 120 auto e = tryEat("(") 121 121 ? parseLambdaAfterOpenParen(pos) // let var ( ... 122 122 : (eat("=", "after "~kwd), E(0)); // let var = ... 123 123 if( moreDeclarationExists() ) 124 124 return new Let(pos, var, layer, e, Body()); 125 - else 126 - return new Let(pos, var, layer, e, new Var(varpos, var)); 125 + else { 126 + if( layer.empty ) 127 + return new Let(pos, var, layer, e, new Var(varpos, var)); 128 + else if( isMacroLayer(layer) ) 129 + return new Let(pos, var, layer, e, new Str(varpos, "(macro definition)")); 130 + else 131 + return new Let(pos, var, layer, e, new Lay(varpos, layer, new Var(varpos, var))); 132 + } 127 133 } 128 134 } 129 135 130 136 AST TopLevelExpression() 131 137 { 132 138 /// TopLevelExpression ::= Expression ([";"|"in"] Body?)? 133 139 ................................................................................ 567 573 mixin EasyAST; 568 574 569 575 assert_eq(parseString(`123`), intl(123)); 570 576 assert_eq(parseString(`"foo"`), strl("foo")); 571 577 assert_eq(parseString(`fun(){1}`), fun([],intl(1))); 572 578 assert_eq(parseString(`fun(x){1}`), fun(["x"],intl(1))); 573 579 assert_eq(parseString("\u03BB(){1}"), fun([],intl(1))); 574 - assert_eq(parseString("\u03BB(x){1}"), fun(["x"],intl(1))); 580 + assert_eq(parseString("\u03BB(x,y){1}"), fun(["x","y"],intl(1))); 575 581 assert_eq(parseString(`1;2`), let("_","",intl(1),intl(2))); 576 582 assert_eq(parseString(`1;2;`), let("_","",intl(1),intl(2))); 577 583 assert_eq(parseString(`let x=1 in 2`), let("x","",intl(1),intl(2))); 578 584 assert_eq(parseString(`var x=1;2;`), let("x","",intl(1),intl(2))); 579 585 assert_eq(parseString(`def x=1`), let("x","",intl(1),var("x"))); 580 - assert_eq(parseString(`@val x=1;`), let("x","@val",intl(1),var("x"))); 581 - assert_eq(parseString(`@typ x="#int";`), let("x","@typ",strl("#int"),var("x"))); 586 + assert_eq(parseString(`@val x=1;`), let("x","@val",intl(1),lay("@val",var("x")))); 587 + assert_eq(parseString(`@typ x="#int";`), let("x","@typ",strl("#int"),lay("@typ",var("x")))); 588 + assert_eq(parseString(`@macro x=1`), let("x","@macro",intl(1),strl("(macro definition)"))); 582 589 assert_eq(parseString(`f(1,2)`), call(var("f"),intl(1),intl(2))); 583 590 assert_eq(parseString(`if 1 then 2`), call(var("if"),intl(1),fun([],intl(2)),fun([],strl("(empty function body)")))); 584 591 assert_eq(parseString(`if 1 then: 2 else(3)`), call(var("if"),intl(1),fun([],intl(2)),fun([],intl(3)))); 585 592 assert_eq(parseString(`(if 1 then () else 3)()()`), 586 593 call(call(call(var("if"),intl(1),fun([],strl("(empty function body)")),fun([],intl(3)))))); 587 594 assert_eq(parseString(`1+2*3`), call(var("+"),intl(1),call(var("*"),intl(2),intl(3)))); 588 595 assert_eq(parseString(`(1+2)*3`), call(var("*"),call(var("+"),intl(1),intl(2)),intl(3)));