Overview
SHA1 Hash: | 078444a806d1464b6f6af4b4fe48c938501e6bb5 |
---|---|
Date: | 2010-11-13 14:38:21 |
User: | kinaba |
Comment: | additional primitives for doing typechecking |
Timelines: | family | ancestors | descendants | both | trunk |
Downloads: | Tarball | ZIP archive |
Other Links: | files | file ages | manifest |
Tags And Properties
- branch=trunk inherited from [f65680e1d2]
- sym-trunk inherited from [f65680e1d2]
Changes
Modified polemy/eval.d from [232a7f3469a1ed88] to [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); }
Modified tricks/tricks.d from [c96de2738d81e418] to [d1500d1519df592c].
126 } 126 } 127 127 128 override int opCmp(Object rhs_) const /// member-by-member compare 128 override int opCmp(Object rhs_) const /// member-by-member compare 129 { 129 { 130 if( auto rhs = cast(typeof(this))rhs_ ) 130 if( auto rhs = cast(typeof(this))rhs_ ) 131 { 131 { 132 foreach(i,_; this.tupleof) 132 foreach(i,_; this.tupleof) > 133 if( this.tupleof[i] != rhs.tupleof[i] ) { > 134 auto a = this.tupleof[i]; > 135 auto b = rhs.tupleof[i]; > 136 return cast(SC_Unqual!(typeof(a)))a < b > 137 } 133 if(auto c = typeid(_).compare(&this.tupleof[i],& | 138 // if(auto c = typeid(_).compare(&this.tupleof[i],& 134 return c; | 139 // return c; 135 return 0; 140 return 0; 136 } 141 } 137 assert(false, sprintf!"Cannot compare %s with %s"(typeid(this), 142 assert(false, sprintf!"Cannot compare %s with %s"(typeid(this), 138 } 143 } 139 } 144 } > 145 > 146 alias std.traits.Unqual SC_Unqual; 140 147 141 unittest 148 unittest 142 { 149 { 143 class Temp 150 class Temp 144 { 151 { 145 int x; 152 int x; 146 string y; 153 string y;