Check-in [0f02103885]
Not logged in
Overview
SHA1 Hash:0f02103885bdb17f3e5c15aa69c4c308e37f8157
Date: 2010-11-09 16:27:21
User: kinaba
Comment:let, var, def became layer-neutral definition (not @val). scope splitting (let x=1;let x=2;let y=(let x=3);x is 1) is correctly implemented now.
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 [c3d65954914654a5] to [73d121b46bcd4718].

97 97 98 Tuple!(Value,"val",Table,"ctx") eval(AST e) 98 Tuple!(Value,"val",Table,"ctx") eval(AST e) 99 { 99 { 100 Table ctx = createGlobalContext(); 100 Table ctx = createGlobalContext(); 101 return typeof(return)(eval(e, ctx), ctx); 101 return typeof(return)(eval(e, ctx), ctx); 102 } 102 } 103 103 104 Value eval(AST _e, Table ctx, bool splitCtx = true) | 104 Value eval(AST _e, Table ctx, bool splitCtx = false) 105 { 105 { 106 if( auto e = cast(StrLiteral)_e ) 106 if( auto e = cast(StrLiteral)_e ) 107 { 107 { 108 return new StrValue(e.data); 108 return new StrValue(e.data); 109 } 109 } 110 else 110 else 111 if( auto e = cast(IntLiteral)_e ) 111 if( auto e = cast(IntLiteral)_e ) ................................................................................................................................................................................ 119 } 119 } 120 else 120 else 121 if( auto e = cast(LetExpression)_e ) 121 if( auto e = cast(LetExpression)_e ) 122 { 122 { 123 // for letrec, we need this, but should avoid overwriting???? 123 // for letrec, we need this, but should avoid overwriting???? 124 // ctx.set(e.var, "@val", new UndefinedValue, e.pos); 124 // ctx.set(e.var, "@val", new UndefinedValue, e.pos); 125 Value v = eval(e.init, ctx, true); 125 Value v = eval(e.init, ctx, true); > 126 if(splitCtx) > 127 ctx = new Table(ctx, Table.Kind.NotPropagateSet); 126 ctx.set(e.var, "@val", v, e.pos); 128 ctx.set(e.var, "@val", v, e.pos); 127 return eval(e.expr, ctx); 129 return eval(e.expr, ctx); 128 } 130 } 129 else 131 else 130 if( auto e = cast(FuncallExpression)_e ) 132 if( auto e = cast(FuncallExpression)_e ) 131 { 133 { 132 Value _f = eval(e.fun, ctx); 134 Value _f = eval(e.fun, ctx); ................................................................................................................................................................................ 171 assert_throw!RuntimeException( r.ctx.get("y","@val") ); 173 assert_throw!RuntimeException( r.ctx.get("y","@val") ); 172 } 174 } 173 unittest 175 unittest 174 { 176 { 175 assert_nothrow( evalString(`print("Hello, world!");`) ); 177 assert_nothrow( evalString(`print("Hello, world!");`) ); 176 assert_nothrow( evalString(`print(fun(){});`) ); 178 assert_nothrow( evalString(`print(fun(){});`) ); 177 } 179 } > 180 unittest > 181 { > 182 assert_eq( evalString(`let x=1; let y=(let x=2); x`).val, new IntValue(B > 183 assert_eq( evalString(`let x=1; let y=(let x=2;fun(){x}); y()`).val, new > 184 } 178 unittest 185 unittest 179 { 186 { 180 assert_nothrow( evalString(`var fac = fun(x){ 187 assert_nothrow( evalString(`var fac = fun(x){ 181 1; 188 1; 182 }; 189 }; 183 print(fac(3));`)); 190 print(fac(3));`)); 184 assert_nothrow( evalString(`var fac = fun(x){ 191 assert_nothrow( evalString(`var fac = fun(x){

Modified polemy/parse.d from [5f90478aa23ae726] to [e14df84da140adf3].

64 if( tryEat("let") || tryEat("var") || tryEat("def") || tryEat("@ 64 if( tryEat("let") || tryEat("var") || tryEat("def") || tryEat("@ 65 { 65 { 66 if( kwd == "@" ) 66 if( kwd == "@" ) 67 kwd ~= eatId("after @"); 67 kwd ~= eatId("after @"); 68 immutable LexPosition varpos = (lex.empty ? null : lex.f 68 immutable LexPosition varpos = (lex.empty ? null : lex.f 69 string var = eatId("after "~kwd); 69 string var = eatId("after "~kwd); 70 eat("=", "after "~kwd); 70 eat("=", "after "~kwd); 71 kwd = (kwd[0]=='@' ? kwd : "@val"); | 71 kwd = (kwd[0]=='@' ? kwd : ""); // "let, var, def ==> ne 72 auto e = E(0); 72 auto e = E(0); 73 if( tryEat(";") && !lex.empty && (lex.front.quoted || (l 73 if( tryEat(";") && !lex.empty && (lex.front.quoted || (l 74 return new LetExpression(pos, var, kwd, e, Body( 74 return new LetExpression(pos, var, kwd, e, Body( 75 else 75 else 76 return new LetExpression(pos, var, kwd, e, new V 76 return new LetExpression(pos, var, kwd, e, new V 77 } 77 } 78 else 78 else ................................................................................................................................................................................ 259 assert_eq(parseString(`"foo"`), strl("foo")); 259 assert_eq(parseString(`"foo"`), strl("foo")); 260 assert_eq(parseString(`fun(){1}`), fun([],intl(1))); 260 assert_eq(parseString(`fun(){1}`), fun([],intl(1))); 261 assert_eq(parseString(`fun(x){1}`), fun(["x"],intl(1))); 261 assert_eq(parseString(`fun(x){1}`), fun(["x"],intl(1))); 262 assert_eq(parseString("\u03BB(){1}"), fun([],intl(1))); 262 assert_eq(parseString("\u03BB(){1}"), fun([],intl(1))); 263 assert_eq(parseString("\u03BB(x){1}"), fun(["x"],intl(1))); 263 assert_eq(parseString("\u03BB(x){1}"), fun(["x"],intl(1))); 264 assert_eq(parseString(`1;2`), let("_","@val",intl(1),intl(2))); 264 assert_eq(parseString(`1;2`), let("_","@val",intl(1),intl(2))); 265 assert_eq(parseString(`1;2;`), let("_","@val",intl(1),intl(2))); 265 assert_eq(parseString(`1;2;`), let("_","@val",intl(1),intl(2))); 266 assert_eq(parseString(`let x=1;2`), let("x","@val",intl(1),intl(2))); | 266 assert_eq(parseString(`let x=1;2`), let("x","",intl(1),intl(2))); 267 assert_eq(parseString(`var x=1;2;`), let("x","@val",intl(1),intl(2))); | 267 assert_eq(parseString(`var x=1;2;`), let("x","",intl(1),intl(2))); 268 assert_eq(parseString(`def x=1`), let("x","@val",intl(1),var("x"))); | 268 assert_eq(parseString(`def x=1`), let("x","",intl(1),var("x"))); 269 assert_eq(parseString(`@val x=1;`), let("x","@val",intl(1),var("x"))); 269 assert_eq(parseString(`@val x=1;`), let("x","@val",intl(1),var("x"))); 270 assert_eq(parseString(`@typ x="#int";`), let("x","@typ",strl("#int"),var 270 assert_eq(parseString(`@typ x="#int";`), let("x","@typ",strl("#int"),var 271 assert_eq(parseString(`f(1,2)`), call(var("f"),intl(1),intl(2))); 271 assert_eq(parseString(`f(1,2)`), call(var("f"),intl(1),intl(2))); 272 assert_eq(parseString(`if(1){2}`), call(var("if"),intl(1),fun([],intl(2) 272 assert_eq(parseString(`if(1){2}`), call(var("if"),intl(1),fun([],intl(2) 273 assert_eq(parseString(`if(1){2}else{3}`), call(var("if"),intl(1),fun([], 273 assert_eq(parseString(`if(1){2}else{3}`), call(var("if"),intl(1),fun([], 274 assert_eq(parseString(`if(1){}else{3}()()`), 274 assert_eq(parseString(`if(1){}else{3}()()`), 275 call(call(call(var("if"),intl(1),fun([],intl(178)),fun([],intl(3 275 call(call(call(var("if"),intl(1),fun([],intl(178)),fun([],intl(3 ................................................................................................................................................................................ 279 assert_eq(parseString(`1*2+3`), call(var("+"),call(var("*"),intl(1),intl 279 assert_eq(parseString(`1*2+3`), call(var("+"),call(var("*"),intl(1),intl 280 280 281 assert_eq(parseString(` 281 assert_eq(parseString(` 282 let x = 100; #comment 282 let x = 100; #comment 283 let y = 200; #comment!!!!! 283 let y = 200; #comment!!!!! 284 x+y 284 x+y 285 `), 285 `), 286 let("x", "@val", intl(100), let("y", "@val", intl(200), call(var | 286 let("x", "", intl(100), let("y", "", intl(200), call(var("+"), v 287 ); 287 ); 288 288 289 assert_eq(parseString(` 289 assert_eq(parseString(` 290 var fac = fun(x){ if(x <= 1) {1} else {x*fac(x-1)} }; 290 var fac = fun(x){ if(x <= 1) {1} else {x*fac(x-1)} }; 291 fac(10) 291 fac(10) 292 `), 292 `), 293 let("fac", "@val", fun(["x"], | 293 let("fac", "", fun(["x"], 294 call(var("if"), 294 call(var("if"), 295 call(var("<="), var("x"), intl(1)), 295 call(var("<="), var("x"), intl(1)), 296 fun([], intl(1)), 296 fun([], intl(1)), 297 fun([], call(var("*"), var("x"), call(var("fac") 297 fun([], call(var("*"), var("x"), call(var("fac") 298 )), 298 )), 299 call(var("fac"),intl(10)) 299 call(var("fac"),intl(10)) 300 ) 300 )

Modified tricks/test.d from [de7560f1ecccee67] to [314aad0104b85557].

54 { 54 { 55 void assertOp(A, B, string fn=__FILE__, size_t ln=__LINE__)(A a, B b, st 55 void assertOp(A, B, string fn=__FILE__, size_t ln=__LINE__)(A a, B b, st 56 { 56 { 57 try 57 try 58 { if( mixin("a"~op~"b") ) return; } 58 { if( mixin("a"~op~"b") ) return; } 59 catch(Throwable e) 59 catch(Throwable e) 60 { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception 60 { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception 61 onAssertErrorMsg(fn, ln, msg.length ? msg : to!string(a)~" !"~op | 61 onAssertErrorMsg(fn, ln, msg.length ? msg : to!string(a)~" !"~op 62 } 62 } 63 } 63 } 64 64 65 alias assertOp!(`==`) assert_eq; 65 alias assertOp!(`==`) assert_eq; 66 alias assertOp!(`!=`) assert_ne; 66 alias assertOp!(`!=`) assert_ne; 67 alias assertOp!(`<`) assert_lt; 67 alias assertOp!(`<`) assert_lt; 68 alias assertOp!(`<=`) assert_le; 68 alias assertOp!(`<=`) assert_le;