Diff
Not logged in

Differences From Artifact [232a7f3469a1ed88]:

To Artifact [2bd159f2e71889e8]:


28 if( T.length != args.length ) 28 if( T.length != args.length ) 29 throw genex!RuntimeException(pos, "argument number misma 29 throw genex!RuntimeException(pos, "argument number misma 30 T typed_args; 30 T typed_args; 31 foreach(i, Ti; T) 31 foreach(i, Ti; T) 32 { 32 { 33 typed_args[i] = cast(Ti) args[i]; 33 typed_args[i] = cast(Ti) args[i]; 34 if( typed_args[i] is null ) 34 if( typed_args[i] is null ) 35 throw genex!RuntimeException(pos, sprintf!"type | 35 throw genex!RuntimeException(pos, sprintf!"type 36 } 36 } 37 try { 37 try { 38 return dg(typed_args); 38 return dg(typed_args); 39 } catch( RuntimeException e ) { 39 } catch( RuntimeException e ) { 40 throw e.pos is null ? new RuntimeException(pos, e.msg, e 40 throw e.pos is null ? new RuntimeException(pos, e.msg, e 41 } 41 } 42 }); 42 }); ................................................................................................................................................................................ 47 { 47 { 48 auto ctx = new Table; 48 auto ctx = new Table; 49 ctx.set("+", "@v", native( (IntValue lhs, IntValue rhs){return new IntVa 49 ctx.set("+", "@v", native( (IntValue lhs, IntValue rhs){return new IntVa 50 ctx.set("-", "@v", native( (IntValue lhs, IntValue rhs){return new IntVa 50 ctx.set("-", "@v", native( (IntValue lhs, IntValue rhs){return new IntVa 51 ctx.set("*", "@v", native( (IntValue lhs, IntValue rhs){return new IntVa 51 ctx.set("*", "@v", native( (IntValue lhs, IntValue rhs){return new IntVa 52 ctx.set("/", "@v", native( (IntValue lhs, IntValue rhs){return new IntVa 52 ctx.set("/", "@v", native( (IntValue lhs, IntValue rhs){return new IntVa 53 ctx.set("%", "@v", native( (IntValue lhs, IntValue rhs){return new IntVa 53 ctx.set("%", "@v", native( (IntValue lhs, IntValue rhs){return new IntVa 54 ctx.set("<", "@v", native( (IntValue lhs, IntValue rhs){return new IntVa | 54 ctx.set("||", "@v", native( (IntValue lhs, IntValue rhs){return new IntV 55 ctx.set(">", "@v", native( (IntValue lhs, IntValue rhs){return new IntVa | 55 ctx.set("&&", "@v", native( (IntValue lhs, IntValue rhs){return new IntV 56 ctx.set("<=", "@v", native( (IntValue lhs, IntValue rhs){return new IntV | 56 ctx.set("<", "@v", native( (Value lhs, Value rhs){return new IntValue(Bi 57 ctx.set(">=", "@v", native( (IntValue lhs, IntValue rhs){return new IntV | 57 ctx.set(">", "@v", native( (Value lhs, Value rhs){return new IntValue(Bi 58 ctx.set("==", "@v", native( (IntValue lhs, IntValue rhs){return new IntV | 58 ctx.set("<=", "@v", native( (Value lhs, Value rhs){return new IntValue(B 59 ctx.set("!=", "@v", native( (IntValue lhs, IntValue rhs){return new IntV | 59 ctx.set(">=", "@v", native( (Value lhs, Value rhs){return new IntValue(B > 60 ctx.set("==", "@v", native( (Value lhs, Value rhs){return new IntValue(B > 61 ctx.set("!=", "@v", native( (Value lhs, Value rhs){return new IntValue(B 60 ctx.set("print", "@v", new FunValue(delegate Value(immutable LexPosition 62 ctx.set("print", "@v", new FunValue(delegate Value(immutable LexPosition 61 foreach(a; args) 63 foreach(a; args) 62 write(a); 64 write(a); 63 writeln(""); 65 writeln(""); 64 return new IntValue(BigInt(178)); 66 return new IntValue(BigInt(178)); 65 })); 67 })); 66 ctx.set("if", "@v", new FunValue(delegate Value(immutable LexPosition po 68 ctx.set("if", "@v", new FunValue(delegate Value(immutable LexPosition po ................................................................................................................................................................................ 121 if( lay == "@v" ) 123 if( lay == "@v" ) 122 return v; 124 return v; 123 else // rise 125 else // rise 124 return (cast(FunValue)ctx.get(lay, "(system)", e 126 return (cast(FunValue)ctx.get(lay, "(system)", e 125 }, 127 }, 126 (VarExpression e) 128 (VarExpression e) 127 { 129 { > 130 if( lay == "@v" ) > 131 return ctx.get(e.var, lay, e.pos); 128 try { 132 try { 129 return ctx.get(e.var, lay, e.pos); 133 return ctx.get(e.var, lay, e.pos); 130 } catch( RuntimeException ) { | 134 } catch( Throwable ) { // [TODO] more precise... 131 // rise from @v 135 // rise from @v 132 return (cast(FunValue)ctx.get(lay, "(system)", e 136 return (cast(FunValue)ctx.get(lay, "(system)", e 133 [ctx.get(e.var, "@v", e.pos)] 137 [ctx.get(e.var, "@v", e.pos)] 134 ); 138 ); 135 } 139 } 136 }, 140 }, 137 (LayeredExpression e) 141 (LayeredExpression e) ................................................................................................................................................................................ 201 assert_eq( evalString(`let x=1; let y=(let x=2;fun(){x}); y()`).val, new 205 assert_eq( evalString(`let x=1; let y=(let x=2;fun(){x}); y()`).val, new 202 } 206 } 203 unittest 207 unittest 204 { 208 { 205 assert_eq( evalString(`@a x=1; @b x=2; @a(x)`).val, new IntValue(BigInt( 209 assert_eq( evalString(`@a x=1; @b x=2; @a(x)`).val, new IntValue(BigInt( 206 assert_eq( evalString(`@a x=1; @b x=2; @b(x)`).val, new IntValue(BigInt( 210 assert_eq( evalString(`@a x=1; @b x=2; @b(x)`).val, new IntValue(BigInt( 207 assert_eq( evalString(`let x=1; let _ = (@a x=2;2); x`).val, new IntValu 211 assert_eq( evalString(`let x=1; let _ = (@a x=2;2); x`).val, new IntValu 208 assert_throw!Error( evalString(`let x=1; let _ = (@a x=2;2); @a(x)`) ); | 212 assert_throw!Throwable( evalString(`let x=1; let _ = (@a x=2;2); @a(x)`) 209 } 213 } 210 214 211 unittest 215 unittest 212 { 216 { 213 assert_eq( evalString(`var fac = fun(x){ 217 assert_eq( evalString(`var fac = fun(x){ 214 if(x) 218 if(x) 215 { x*fac(x-1); } 219 { x*fac(x-1); }