Differences From Artifact [84ee94a6f293fac0]:
- File
polemy/eval.d
- 2010-11-20 14:04:44 - part of checkin [8e3db9ef20] on branch trunk - macro worked! (user: kinaba) [annotate]
To Artifact [360da420d41dfbbf]:
- File
polemy/eval.d
- 2010-11-20 14:29:49 - part of checkin [060f267779] on branch trunk - fixed the bug that the first declaration inside a function cannt be recursive: def foo() { def bar() { bar() }; bar() }; foo() # bar cannot be found (user: kinaba) [annotate]
126 126 }
127 127 },
128 128 (LayeredExpression e)
129 129 {
130 130 if( e.lay == "@macro" )
131 131 return macroEval(e.expr, ctx, false);
132 132 else
133 - return eval(e.expr, ctx, false, e.lay);
133 + return eval(e.expr, ctx, true, e.lay);
134 134 },
135 135 (LetExpression e)
136 136 {
137 137 // for letrec, we need this, but should avoid overwriting????
138 138 // ctx.set(e.var, "@v", new UndefinedValue, e.pos);
139 - Value v = eval(e.init, ctx, true, lay);
140 139 if(splitCtx)
141 140 ctx = new Table(ctx, Table.Kind.NotPropagateSet);
141 + Value v = eval(e.init, ctx, true, lay);
142 142 ctx.set(e.var, (e.layer.length ? e.layer : lay), v, e.pos);
143 143 return eval(e.expr, ctx, false, lay);
144 144 },
145 145 (FuncallExpression e)
146 146 {
147 147 Value _f = eval(e.fun, ctx, true, lay);
148 148 if( auto f = cast(FunValue)_f ) {
................................................................................
379 379 assert_eq( evalString(`@@s(x){x}; @s "+"=fun(x,y){@v(@s(x)-@s(y))};1+2`).val, new IntValue(BigInt(3)) );
380 380 assert_eq( evalString(`@@s(x){x}; @s "+"=fun(x,y){@v(@s(x)-@s(y))};@s(1+2)`).val, new IntValue(BigInt(-1)) );
381 381 }
382 382
383 383 unittest
384 384 {
385 385 assert_eq( evalString(`@@t = fun(x){x+1}; @t(123)`).val, new IntValue(BigInt(124)) );
386 + // there was a bug that declaration in the first line of function definition
387 + // cannot be recursive
388 + assert_nothrow( evalString(`def foo() {
389 + def bar(y) { if(y<1) {0} else {bar(0)} };
390 + bar(1)
391 +}; foo()`) );
386 392 }