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
- branch=trunk inherited from [f65680e1d2]
- sym-trunk inherited from [f65680e1d2]
Changes
Modified polemy/eval.d from [74dd93745d781116] to [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)
Modified polemy/parse.d from [9aca36046bea5df8] to [3ad9850246d5111f].
118 string var = eatId("after "~kwd, AllowQuoted); // name o 118 string var = eatId("after "~kwd, AllowQuoted); // name o 119 119 120 auto e = tryEat("(") 120 auto e = tryEat("(") 121 ? parseLambdaAfterOpenParen(pos) // let var ( . 121 ? parseLambdaAfterOpenParen(pos) // let var ( . 122 : (eat("=", "after "~kwd), E(0)); // let var = . 122 : (eat("=", "after "~kwd), E(0)); // let var = . 123 if( moreDeclarationExists() ) 123 if( moreDeclarationExists() ) 124 return new Let(pos, var, layer, e, Body()); 124 return new Let(pos, var, layer, e, Body()); 125 else | 125 else { > 126 if( layer.empty ) 126 return new Let(pos, var, layer, e, new Var(varpo | 127 return new Let(pos, var, layer, e, new V > 128 else if( isMacroLayer(layer) ) > 129 return new Let(pos, var, layer, e, new S > 130 else > 131 return new Let(pos, var, layer, e, new L > 132 } 127 } 133 } 128 } 134 } 129 135 130 AST TopLevelExpression() 136 AST TopLevelExpression() 131 { 137 { 132 /// TopLevelExpression ::= Expression ([";"|"in"] Body?)? 138 /// TopLevelExpression ::= Expression ([";"|"in"] Body?)? 133 139 ................................................................................................................................................................................ 567 mixin EasyAST; 573 mixin EasyAST; 568 574 569 assert_eq(parseString(`123`), intl(123)); 575 assert_eq(parseString(`123`), intl(123)); 570 assert_eq(parseString(`"foo"`), strl("foo")); 576 assert_eq(parseString(`"foo"`), strl("foo")); 571 assert_eq(parseString(`fun(){1}`), fun([],intl(1))); 577 assert_eq(parseString(`fun(){1}`), fun([],intl(1))); 572 assert_eq(parseString(`fun(x){1}`), fun(["x"],intl(1))); 578 assert_eq(parseString(`fun(x){1}`), fun(["x"],intl(1))); 573 assert_eq(parseString("\u03BB(){1}"), fun([],intl(1))); 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 assert_eq(parseString(`1;2`), let("_","",intl(1),intl(2))); 581 assert_eq(parseString(`1;2`), let("_","",intl(1),intl(2))); 576 assert_eq(parseString(`1;2;`), let("_","",intl(1),intl(2))); 582 assert_eq(parseString(`1;2;`), let("_","",intl(1),intl(2))); 577 assert_eq(parseString(`let x=1 in 2`), let("x","",intl(1),intl(2))); 583 assert_eq(parseString(`let x=1 in 2`), let("x","",intl(1),intl(2))); 578 assert_eq(parseString(`var x=1;2;`), let("x","",intl(1),intl(2))); 584 assert_eq(parseString(`var x=1;2;`), let("x","",intl(1),intl(2))); 579 assert_eq(parseString(`def x=1`), let("x","",intl(1),var("x"))); 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"))); | 586 assert_eq(parseString(`@val x=1;`), let("x","@val",intl(1),lay("@val",va 581 assert_eq(parseString(`@typ x="#int";`), let("x","@typ",strl("#int"),var | 587 assert_eq(parseString(`@typ x="#int";`), let("x","@typ",strl("#int"),lay > 588 assert_eq(parseString(`@macro x=1`), let("x","@macro",intl(1),strl("(mac 582 assert_eq(parseString(`f(1,2)`), call(var("f"),intl(1),intl(2))); 589 assert_eq(parseString(`f(1,2)`), call(var("f"),intl(1),intl(2))); 583 assert_eq(parseString(`if 1 then 2`), call(var("if"),intl(1),fun([],intl 590 assert_eq(parseString(`if 1 then 2`), call(var("if"),intl(1),fun([],intl 584 assert_eq(parseString(`if 1 then: 2 else(3)`), call(var("if"),intl(1),fu 591 assert_eq(parseString(`if 1 then: 2 else(3)`), call(var("if"),intl(1),fu 585 assert_eq(parseString(`(if 1 then () else 3)()()`), 592 assert_eq(parseString(`(if 1 then () else 3)()()`), 586 call(call(call(var("if"),intl(1),fun([],strl("(empty function bo 593 call(call(call(var("if"),intl(1),fun([],strl("(empty function bo 587 assert_eq(parseString(`1+2*3`), call(var("+"),intl(1),call(var("*"),intl 594 assert_eq(parseString(`1+2*3`), call(var("+"),intl(1),call(var("*"),intl 588 assert_eq(parseString(`(1+2)*3`), call(var("*"),call(var("+"),intl(1),in 595 assert_eq(parseString(`(1+2)*3`), call(var("*"),call(var("+"),intl(1),in