Check-in [078444a806]
Not logged in
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
Changes

Modified polemy/eval.d from [232a7f3469a1ed88] to [2bd159f2e71889e8].

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

Modified tricks/tricks.d from [c96de2738d81e418] to [d1500d1519df592c].

126 126 } 127 127 128 128 override int opCmp(Object rhs_) const /// member-by-member compare 129 129 { 130 130 if( auto rhs = cast(typeof(this))rhs_ ) 131 131 { 132 132 foreach(i,_; this.tupleof) 133 - if(auto c = typeid(_).compare(&this.tupleof[i],&rhs.tupleof[i])) 134 - return c; 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 ? -1 : +1; 137 + } 138 +// if(auto c = typeid(_).compare(&this.tupleof[i],&rhs.tupleof[i])) 139 +// return c; 135 140 return 0; 136 141 } 137 142 assert(false, sprintf!"Cannot compare %s with %s"(typeid(this), typeid(rhs_))); 138 143 } 139 144 } 145 + 146 +alias std.traits.Unqual SC_Unqual; 140 147 141 148 unittest 142 149 { 143 150 class Temp 144 151 { 145 152 int x; 146 153 string y;