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

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

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

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

387 387 <dt><span class="decl"> 388 388 <span class="currsymbol">Layers</span> 389 389 <script>explorer.outline.addDecl('Layers');</script> 390 390 391 391 </span></dt> 392 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 408 <dd><pre> 395 409 [Layers :: Overview] 396 410 397 411 Polemy's runtime environment has many "layer"s. 398 412 Usual execution run in the @value layer. 399 413 400 414 &gt;&gt; 1 + 2 ................................................................................ 537 551 /fst@value:3 538 552 /} 539 553 540 554 its corresponding arguments are evaluated in the layer and passed to it. 541 555 If you specify multiple layers, the argument expression is run multiple times. 542 556 If you do not specify any layer for a parameter, it works in the neutral layer. 543 557 </pre> 558 +</dd> 559 +</dl> 560 +<script>explorer.outline.decSymbolLevel();</script> 561 + 562 + 544 563 </dd> 545 564 546 565 547 566 548 567 <script>explorer.outline.writeEnabled = true;</script> 549 568 <dt><span class="decl"> 550 569 <span class="currsymbol">Macro Layers</span> ................................................................................ 933 952 <script>explorer.outline.decSymbolLevel();</script> 934 953 935 954 936 955 </td></tr> 937 956 <tr><td id="docfooter"> 938 957 Page was generated with 939 958 <img src="candydoc/img/candydoc.gif" style="vertical-align:middle; position:relative; top:-1px"> 940 - on Sat Nov 27 01:54:49 2010 959 + on Sat Nov 27 20:49:57 2010 941 960 942 961 </td></tr> 943 962 </table> 944 963 </div> 945 964 <script> 946 965 explorer.packageExplorer.addModule("index"); 947 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 289 $(SECTION Layers, $(SECBODY 290 +<p> 291 +この言語の唯一の特徴的な部分は、「レイヤ」機能です。 292 +</p> 293 +$(DDOC_MEMBERS 294 +$(SECTION Layers, $(SECBODY 290 295 <pre> 291 296 [Layers :: Overview] 292 297 293 298 Polemy's runtime environment has many "layer"s. 294 299 Usual execution run in the @value layer. 295 300 296 301 >> 1 + 2 ................................................................................ 433 438 /fst@value:3 434 439 /} 435 440 436 441 its corresponding arguments are evaluated in the layer and passed to it. 437 442 If you specify multiple layers, the argument expression is run multiple times. 438 443 If you do not specify any layer for a parameter, it works in the neutral layer. 439 444 </pre> 445 +)) 446 +) 440 447 )) 441 448 442 449 443 450 $(SECTION Macro Layers, $(SECBODY 444 451 <p> 445 452 Polemy 言語組み込みのレイヤは <code>@value</code> と <code>@macro</code> の二つです。 446 453 (内部的にはもういくつかありますが、ユーザから直接は使えません。)

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

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

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

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

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

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