Check-in [a795c97dc3]
Not logged in
Overview
SHA1 Hash:a795c97dc3ce71a1e91c65ad8d530c8954bc3573
Date: 2010-11-27 21:49:03
User: kinaba
Comment:changed Let.init to Let.vdef. IT IS VERY DANGEROUS TO USE .init MEMBER NAME in D!!!!!!!!
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified doc/ast.html from [30cfc60d3ceb137f] to [32b42592d934edb1].

241 241 242 242 243 <dd><br><br> 243 <dd><br><br> 244 </dd> 244 </dd> 245 245 246 <script>explorer.outline.writeEnabled = true;</script> 246 <script>explorer.outline.writeEnabled = true;</script> 247 <dt><span class="decl">AST 247 <dt><span class="decl">AST 248 <span class="currsymbol">init</span> | 248 <span class="currsymbol">vdef</span> 249 <script>explorer.outline.addDecl('init');</script> | 249 <script>explorer.outline.addDecl('vdef');</script> 250 250 251 ; 251 ; 252 </span></dt> 252 </span></dt> 253 <script>explorer.outline.writeEnabled = false;</script> 253 <script>explorer.outline.writeEnabled = false;</script> 254 254 255 255 256 <dd><br><br> 256 <dd><br><br> ................................................................................................................................................................................ 590 <script>explorer.outline.decSymbolLevel();</script> 590 <script>explorer.outline.decSymbolLevel();</script> 591 591 592 592 593 </td></tr> 593 </td></tr> 594 <tr><td id="docfooter"> 594 <tr><td id="docfooter"> 595 Page was generated with 595 Page was generated with 596 <img src="candydoc/img/candydoc.gif" style="vertical-ali 596 <img src="candydoc/img/candydoc.gif" style="vertical-ali 597 on Sat Nov 27 01:17:56 2010 | 597 on Sat Nov 27 21:45:06 2010 598 598 599 </td></tr> 599 </td></tr> 600 </table> 600 </table> 601 </div> 601 </div> 602 <script> 602 <script> 603 explorer.packageExplorer.addModule("index"); 603 explorer.packageExplorer.addModule("index"); 604 explorer.packageExplorer.addModule("main"); 604 explorer.packageExplorer.addModule("main");

Modified doc/eval.html from [8d466c06bd23cd95] to [e2cd33ac962dedb5].

128 <script>explorer.outline.decSymbolLevel();</script> 128 <script>explorer.outline.decSymbolLevel();</script> 129 129 130 130 131 </td></tr> 131 </td></tr> 132 <tr><td id="docfooter"> 132 <tr><td id="docfooter"> 133 Page was generated with 133 Page was generated with 134 <img src="candydoc/img/candydoc.gif" style="vertical-ali 134 <img src="candydoc/img/candydoc.gif" style="vertical-ali 135 on Sat Nov 27 01:17:57 2010 | 135 on Sat Nov 27 21:45:07 2010 136 136 137 </td></tr> 137 </td></tr> 138 </table> 138 </table> 139 </div> 139 </div> 140 <script> 140 <script> 141 explorer.packageExplorer.addModule("index"); 141 explorer.packageExplorer.addModule("index"); 142 explorer.packageExplorer.addModule("main"); 142 explorer.packageExplorer.addModule("main");

Modified doc/index.html from [a076bfb1003e4c62] to [bdbfe9ee7589f910].

387 <dt><span class="decl"> 387 <dt><span class="decl"> 388 <span class="currsymbol">Layers</span> 388 <span class="currsymbol">Layers</span> 389 <script>explorer.outline.addDecl('Layers');</script> 389 <script>explorer.outline.addDecl('Layers');</script> 390 390 391 </span></dt> 391 </span></dt> 392 <script>explorer.outline.writeEnabled = false;</script> 392 <script>explorer.outline.writeEnabled = false;</script> 393 393 > 394 <dd><p> > 395 この言語の唯一の特徴的な部分は、「レイヤ」機能です。 > 396 </p> > 397 > 398 <script>explorer.outline.incSymbolLevel();</script> > 399 <dl> > 400 <script>explorer.outline.writeEnabled = true;</script> > 401 <dt><span class="decl"> > 402 <span class="currsymbol">Layers</span> > 403 <script>explorer.outline.addDecl('Layers');</script> > 404 > 405 </span></dt> > 406 <script>explorer.outline.writeEnabled = false;</script> > 407 394 <dd><pre> 408 <dd><pre> 395 [Layers :: Overview] 409 [Layers :: Overview] 396 410 397 Polemy's runtime environment has many "layer"s. 411 Polemy's runtime environment has many "layer"s. 398 Usual execution run in the @value layer. 412 Usual execution run in the @value layer. 399 413 400 &gt;&gt; 1 + 2 414 &gt;&gt; 1 + 2 ................................................................................................................................................................................ 537 /fst@value:3 551 /fst@value:3 538 /} 552 /} 539 553 540 its corresponding arguments are evaluated in the layer and passed to it. 554 its corresponding arguments are evaluated in the layer and passed to it. 541 If you specify multiple layers, the argument expression is run multiple times. 555 If you specify multiple layers, the argument expression is run multiple times. 542 If you do not specify any layer for a parameter, it works in the neutral layer 556 If you do not specify any layer for a parameter, it works in the neutral layer 543 </pre> 557 </pre> > 558 </dd> > 559 </dl> > 560 <script>explorer.outline.decSymbolLevel();</script> > 561 > 562 544 </dd> 563 </dd> 545 564 546 565 547 566 548 <script>explorer.outline.writeEnabled = true;</script> 567 <script>explorer.outline.writeEnabled = true;</script> 549 <dt><span class="decl"> 568 <dt><span class="decl"> 550 <span class="currsymbol">Macro Layers</span> 569 <span class="currsymbol">Macro Layers</span> ................................................................................................................................................................................ 933 <script>explorer.outline.decSymbolLevel();</script> 952 <script>explorer.outline.decSymbolLevel();</script> 934 953 935 954 936 </td></tr> 955 </td></tr> 937 <tr><td id="docfooter"> 956 <tr><td id="docfooter"> 938 Page was generated with 957 Page was generated with 939 <img src="candydoc/img/candydoc.gif" style="vertical-ali 958 <img src="candydoc/img/candydoc.gif" style="vertical-ali 940 on Sat Nov 27 01:54:49 2010 | 959 on Sat Nov 27 20:49:57 2010 941 960 942 </td></tr> 961 </td></tr> 943 </table> 962 </table> 944 </div> 963 </div> 945 <script> 964 <script> 946 explorer.packageExplorer.addModule("index"); 965 explorer.packageExplorer.addModule("index"); 947 explorer.packageExplorer.addModule("main"); 966 explorer.packageExplorer.addModule("main");

Modified index.dd from [d2cf6de49dcafd42] to [a3c506d4caf580c9].

283 )) 283 )) 284 284 285 285 286 286 287 287 288 288 289 $(SECTION Layers, $(SECBODY 289 $(SECTION Layers, $(SECBODY > 290 <p> > 291 この言語の唯一の特徴的な部分は、「レイヤ」機能です。 > 292 </p> > 293 $(DDOC_MEMBERS > 294 $(SECTION Layers, $(SECBODY 290 <pre> 295 <pre> 291 [Layers :: Overview] 296 [Layers :: Overview] 292 297 293 Polemy's runtime environment has many "layer"s. 298 Polemy's runtime environment has many "layer"s. 294 Usual execution run in the @value layer. 299 Usual execution run in the @value layer. 295 300 296 >> 1 + 2 301 >> 1 + 2 ................................................................................................................................................................................ 433 /fst@value:3 438 /fst@value:3 434 /} 439 /} 435 440 436 its corresponding arguments are evaluated in the layer and passed to it. 441 its corresponding arguments are evaluated in the layer and passed to it. 437 If you specify multiple layers, the argument expression is run multiple times. 442 If you specify multiple layers, the argument expression is run multiple times. 438 If you do not specify any layer for a parameter, it works in the neutral layer 443 If you do not specify any layer for a parameter, it works in the neutral layer 439 </pre> 444 </pre> > 445 )) > 446 ) 440 )) 447 )) 441 448 442 449 443 $(SECTION Macro Layers, $(SECBODY 450 $(SECTION Macro Layers, $(SECBODY 444 <p> 451 <p> 445 Polemy 言語組み込みのレイヤは <code>@value</code> と <code>@macro</code> の二つです。 452 Polemy 言語組み込みのレイヤは <code>@value</code> と <code>@macro</code> の二つです。 446 (内部的にはもういくつかありますが、ユーザから直接は使えません。) 453 (内部的にはもういくつかありますが、ユーザから直接は使えません。)

Modified polemy/ast.d from [8ec2df800d3eb579] to [17cd075ee7ebe8fb].

56 } 56 } 57 57 58 /// AST node for variable declaration 58 /// AST node for variable declaration 59 class Let : AST 59 class Let : AST 60 { 60 { 61 string name; /// 61 string name; /// 62 Layer layer; /// 62 Layer layer; /// 63 AST init; /// | 63 AST vdef; /// 64 AST expr; /// 64 AST expr; /// 65 65 66 mixin SimpleClass; 66 mixin SimpleClass; 67 } 67 } 68 68 69 /// AST node for function application 69 /// AST node for function application 70 class App : AST 70 class App : AST

Modified polemy/eval.d from [9460508c714f0a1b] to [6063476e92f43069].

181 { 181 { 182 return getLayerEval(e.layer).evalToNonNull(e.expr, ctx); 182 return getLayerEval(e.layer).evalToNonNull(e.expr, ctx); 183 } 183 } 184 override Value eval_( Let e, Table ctx, bool ctxMod ) 184 override Value eval_( Let e, Table ctx, bool ctxMod ) 185 { 185 { 186 if( !ctxMod ) 186 if( !ctxMod ) 187 ctx = new Table(ctx, Table.Kind.NotPropagateSet) 187 ctx = new Table(ctx, Table.Kind.NotPropagateSet) 188 Value ri = this.eval(e.init, ctx); | 188 Value ri = this.eval(e.vdef, ctx); 189 ctx.set(e.name, e.layer.empty ? layerID(): e.layer, ri); 189 ctx.set(e.name, e.layer.empty ? layerID(): e.layer, ri); 190 return this.eval(e.expr, ctx, OverwriteCtx); 190 return this.eval(e.expr, ctx, OverwriteCtx); 191 } 191 } 192 override Value eval_( App e, Table ctx, bool ctxMod ) 192 override Value eval_( App e, Table ctx, bool ctxMod ) 193 { 193 { 194 Value f = this.eval( e.fun, ctx, CascadeCtx ); 194 Value f = this.eval( e.fun, ctx, CascadeCtx ); 195 return this.invokeFunction(f, e.args, ctx, e.pos, getNam 195 return this.invokeFunction(f, e.args, ctx, e.pos, getNam ................................................................................................................................................................................ 199 return createNewFunction(e, ctx); 199 return createNewFunction(e, ctx); 200 } 200 } 201 override Value macroAndEval( AST e, Table ctx, bool ctxMod ) 201 override Value macroAndEval( AST e, Table ctx, bool ctxMod ) 202 { 202 { 203 // incremental execution of let-expressions 203 // incremental execution of let-expressions 204 if(auto le = cast(Let)e) 204 if(auto le = cast(Let)e) 205 { 205 { 206 AST ai = runMacro(le.init, ctx); | 206 AST ai = runMacro(le.vdef, ctx); 207 207 208 if( !ctxMod ) 208 if( !ctxMod ) 209 ctx = new Table(ctx, Table.Kind.NotPropa 209 ctx = new Table(ctx, Table.Kind.NotPropa 210 210 211 Value vi = this.eval(ai, ctx); 211 Value vi = this.eval(ai, ctx); 212 ctx.set(le.name, le.layer.empty ? layerID() : le 212 ctx.set(le.name, le.layer.empty ? layerID() : le 213 return this.macroAndEval(le.expr, ctx, Overwrite 213 return this.macroAndEval(le.expr, ctx, Overwrite ................................................................................................................................................................................ 239 { 239 { 240 return this.lift(super.eval_(e,ctx,ctxMod), ctx, e.pos); 240 return this.lift(super.eval_(e,ctx,ctxMod), ctx, e.pos); 241 } 241 } 242 override Value eval_( Var e, Table ctx, bool ctxMod ) 242 override Value eval_( Var e, Table ctx, bool ctxMod ) 243 { 243 { 244 if( ctx.has(e.name, layerID()) ) 244 if( ctx.has(e.name, layerID()) ) 245 return ctx.get(e.name, layerID()); 245 return ctx.get(e.name, layerID()); > 246 Value v; 246 return this.lift(ctx.get(e.name, ValueLayer, e.pos), ctx | 247 try { v = ctx.get(e.name, ValueLayer, e.pos); } > 248 catch ( RuntimeException ) { > 249 throw genex!RuntimeException(e.pos, e.name~" not > 250 } > 251 return this.lift(v, ctx, e.pos); 247 } 252 } 248 } 253 } 249 254 250 // Macro layer. For optimization, if AST didn't change it returns null 255 // Macro layer. For optimization, if AST didn't change it returns null 251 class MacroLayerEval : LayerEval 256 class MacroLayerEval : LayerEval 252 { 257 { 253 override Layer layerID() 258 override Layer layerID() ................................................................................................................................................................................ 282 return getLayerEval(e.layer).eval(e.expr,ctx); 287 return getLayerEval(e.layer).eval(e.expr,ctx); 283 } 288 } 284 override Value eval_( Let e, Table ctx, bool ctxMod ) 289 override Value eval_( Let e, Table ctx, bool ctxMod ) 285 { 290 { 286 if( !ctxMod ) 291 if( !ctxMod ) 287 ctx = new Table(ctx, Table.Kind.NotPropagateSet) 292 ctx = new Table(ctx, Table.Kind.NotPropagateSet) 288 293 289 Value ai = this.eval(e.init, ctx); | 294 Value ai = this.eval(e.vdef, ctx); 290 ctx.set(e.name, NoopLayer, null); 295 ctx.set(e.name, NoopLayer, null); 291 Value ae = this.eval(e.expr, ctx, OverwriteCtx); 296 Value ae = this.eval(e.expr, ctx, OverwriteCtx); 292 297 293 if( ai is null && ae is null ) return null; 298 if( ai is null && ae is null ) return null; 294 if( ai is null ) ai = ast2table(e.init); | 299 if( ai is null ) ai = ast2table(e.vdef); 295 if( ae is null ) ae = ast2table(e.expr); 300 if( ae is null ) ae = ast2table(e.expr); 296 301 297 return ast2table(e, delegate Value (AST _){ 302 return ast2table(e, delegate Value (AST _){ 298 if(_ is e.init) { return ai; } | 303 if(_ is e.vdef) { return ai; } 299 if(_ is e.expr) { return ae; } 304 if(_ is e.expr) { return ae; } 300 assert(false); 305 assert(false); 301 }); 306 }); 302 } 307 } 303 override Value eval_( App e, Table ctx, bool ctxMod ) 308 override Value eval_( App e, Table ctx, bool ctxMod ) 304 { 309 { 305 Value f = this.eval( e.fun, ctx ); 310 Value f = this.eval( e.fun, ctx );

Modified sample/macro.pmy from [99466484fdc29835] to [fe180b545227dcde].

19 if x<y then y else x 19 if x<y then y else x 20 }; 20 }; 21 @macro maxGreat(x,y){@value( 21 @macro maxGreat(x,y){@value( 22 var nx = gensym(); # generate fresh symbol 22 var nx = gensym(); # generate fresh symbol 23 var ny = gensym(); 23 var ny = gensym(); 24 @macro _x = @macro(nx) {name: nx}; # cheating to create {is:"Var" .. } 24 @macro _x = @macro(nx) {name: nx}; # cheating to create {is:"Var" .. } 25 @macro _y = @macro(ny) {name: ny}; # at macro layer 25 @macro _y = @macro(ny) {name: ny}; # at macro layer 26 {is: "Let", name: nx, layer: "", init: @macro(x), expr: | 26 {is: "Let", name: nx, layer: "", vdef: @macro(x), expr: 27 {is: "Let", name: ny, layer: "", init: @macro(y), expr: | 27 {is: "Let", name: ny, layer: "", vdef: @macro(y), expr: 28 @macro(if _x < _y then _y else _x)}} # the expression 28 @macro(if _x < _y then _y else _x)}} # the expression 29 )}; 29 )}; 30 30 31 print( maxGood(print(1), print(2)) ); # 1 2 2 31 print( maxGood(print(1), print(2)) ); # 1 2 2 32 print( maxBad(print(1), print(2)) ); # 1 2 2 2 32 print( maxBad(print(1), print(2)) ); # 1 2 2 2 33 print( maxFun(print(1), print(2)) ); # 1 2 2 33 print( maxFun(print(1), print(2)) ); # 1 2 2 34 print( maxGreat(print(1), print(2)) ); # 1 2 2 34 print( maxGreat(print(1), print(2)) ); # 1 2 2