Index: polemy/eval.d ================================================================== --- polemy/eval.d +++ polemy/eval.d @@ -30,11 +30,11 @@ T typed_args; foreach(i, Ti; T) { typed_args[i] = cast(Ti) args[i]; if( typed_args[i] is null ) - throw genex!RuntimeException(pos, sprintf!"type mismatch on the argument %d"(i)); + throw genex!RuntimeException(pos, sprintf!"type mismatch on the argument %d"(i+1)); } try { return dg(typed_args); } catch( RuntimeException e ) { throw e.pos is null ? new RuntimeException(pos, e.msg, e.file, e.line) : e; @@ -49,16 +49,18 @@ ctx.set("+", "@v", native( (IntValue lhs, IntValue rhs){return new IntValue(lhs.data + rhs.data);} )); ctx.set("-", "@v", native( (IntValue lhs, IntValue rhs){return new IntValue(lhs.data - rhs.data);} )); ctx.set("*", "@v", native( (IntValue lhs, IntValue rhs){return new IntValue(lhs.data * rhs.data);} )); ctx.set("/", "@v", native( (IntValue lhs, IntValue rhs){return new IntValue(lhs.data / rhs.data);} )); ctx.set("%", "@v", native( (IntValue lhs, IntValue rhs){return new IntValue(lhs.data % rhs.data);} )); - ctx.set("<", "@v", native( (IntValue lhs, IntValue rhs){return new IntValue(BigInt(lhs.data < rhs.data ? 1: 0));} )); - ctx.set(">", "@v", native( (IntValue lhs, IntValue rhs){return new IntValue(BigInt(lhs.data > rhs.data ? 1: 0));} )); - ctx.set("<=", "@v", native( (IntValue lhs, IntValue rhs){return new IntValue(BigInt(lhs.data <= rhs.data ? 1: 0));} )); - ctx.set(">=", "@v", native( (IntValue lhs, IntValue rhs){return new IntValue(BigInt(lhs.data >= rhs.data ? 1: 0));} )); - ctx.set("==", "@v", native( (IntValue lhs, IntValue rhs){return new IntValue(BigInt(lhs.data == rhs.data ? 1: 0));} )); - ctx.set("!=", "@v", native( (IntValue lhs, IntValue rhs){return new IntValue(BigInt(lhs.data != rhs.data ? 1: 0));} )); + ctx.set("||", "@v", native( (IntValue lhs, IntValue rhs){return new IntValue(BigInt((lhs.data!=0) || (rhs.data!=0) ? 1:0));} )); + ctx.set("&&", "@v", native( (IntValue lhs, IntValue rhs){return new IntValue(BigInt((lhs.data!=0) && (rhs.data!=0) ? 1:0));} )); + ctx.set("<", "@v", native( (Value lhs, Value rhs){return new IntValue(BigInt(lhs < rhs ? 1: 0));} )); + ctx.set(">", "@v", native( (Value lhs, Value rhs){return new IntValue(BigInt(lhs > rhs ? 1: 0));} )); + ctx.set("<=", "@v", native( (Value lhs, Value rhs){return new IntValue(BigInt(lhs <= rhs ? 1: 0));} )); + ctx.set(">=", "@v", native( (Value lhs, Value rhs){return new IntValue(BigInt(lhs >= rhs ? 1: 0));} )); + ctx.set("==", "@v", native( (Value lhs, Value rhs){return new IntValue(BigInt(lhs == rhs ? 1: 0));} )); + ctx.set("!=", "@v", native( (Value lhs, Value rhs){return new IntValue(BigInt(lhs != rhs ? 1: 0));} )); ctx.set("print", "@v", new FunValue(delegate Value(immutable LexPosition pos, Layer lay, Value[] args){ foreach(a; args) write(a); writeln(""); return new IntValue(BigInt(178)); @@ -123,13 +125,15 @@ else // rise return (cast(FunValue)ctx.get(lay, "(system)", e.pos)).call(e.pos, "@v", [v]); }, (VarExpression e) { + if( lay == "@v" ) + return ctx.get(e.var, lay, e.pos); try { return ctx.get(e.var, lay, e.pos); - } catch( RuntimeException ) { + } catch( Throwable ) { // [TODO] more precise... // rise from @v return (cast(FunValue)ctx.get(lay, "(system)", e.pos)).call(e.pos, "@v", [ctx.get(e.var, "@v", e.pos)] ); } @@ -203,11 +207,11 @@ unittest { assert_eq( evalString(`@a x=1; @b x=2; @a(x)`).val, new IntValue(BigInt(1)) ); assert_eq( evalString(`@a x=1; @b x=2; @b(x)`).val, new IntValue(BigInt(2)) ); assert_eq( evalString(`let x=1; let _ = (@a x=2;2); x`).val, new IntValue(BigInt(1)) ); - assert_throw!Error( evalString(`let x=1; let _ = (@a x=2;2); @a(x)`) ); + assert_throw!Throwable( evalString(`let x=1; let _ = (@a x=2;2); @a(x)`) ); } unittest { assert_eq( evalString(`var fac = fun(x){ Index: tricks/tricks.d ================================================================== --- tricks/tricks.d +++ tricks/tricks.d @@ -127,18 +127,25 @@ override int opCmp(Object rhs_) const /// member-by-member compare { if( auto rhs = cast(typeof(this))rhs_ ) { - foreach(i,_; this.tupleof) - if(auto c = typeid(_).compare(&this.tupleof[i],&rhs.tupleof[i])) - return c; + foreach(i,_; this.tupleof) + if( this.tupleof[i] != rhs.tupleof[i] ) { + auto a = this.tupleof[i]; + auto b = rhs.tupleof[i]; + return cast(SC_Unqual!(typeof(a)))a < b ? -1 : +1; + } +// if(auto c = typeid(_).compare(&this.tupleof[i],&rhs.tupleof[i])) +// return c; return 0; } assert(false, sprintf!"Cannot compare %s with %s"(typeid(this), typeid(rhs_))); } -} +} + +alias std.traits.Unqual SC_Unqual; unittest { class Temp {