Index: main.d ================================================================== --- main.d +++ main.d @@ -5,17 +5,17 @@ * Entry point for Polemy interpreter. */ import std.stdio; import polemy.eval; + +version(unittest) static ~this() +{ + writeln( "***********************" ); + writeln( "* All Tests Passed <3 *" ); + writeln( "*********************** (Press Enter to finish)" ); + readln(); +} void main( string[] args ) { - version(unittest) - { - writeln( "***********************" ); - writeln( "* All Tests Passed <3 *" ); - writeln( "*********************** (Press Enter to finish)" ); - readln(); - return; - } } Index: polemy/ast.d ================================================================== --- polemy/ast.d +++ polemy/ast.d @@ -19,67 +19,67 @@ class DeclStatement : Statement { string var; Expression expr; mixin SimpleConstructor; - mixin SimpleCompare; // do not take "pos" into account + mixin SimpleCompare; } class ExprStatement : Statement { Expression expr; mixin SimpleConstructor; - mixin SimpleCompare; // do not take "pos" into account + mixin SimpleCompare; } abstract class Expression { immutable LexPosition pos; mixin SimpleConstructor; - mixin SimpleCompare; // do not take "pos" into account + mixin SimpleCompare; } class StrLiteralExpression : Expression { string data; mixin SimpleConstructor; - mixin SimpleCompare; // do not take "pos" into account + mixin SimpleCompare; } class IntLiteralExpression : Expression { BigInt data; mixin SimpleConstructor; - mixin SimpleCompare; // do not take "pos" into account + mixin SimpleCompare; } class VarExpression : Expression { string var; mixin SimpleConstructor; - mixin SimpleCompare; // do not take "pos" into account + mixin SimpleCompare; } class AssignExpression : Expression { Expression lhs; Expression rhs; mixin SimpleConstructor; - mixin SimpleCompare; // do not take "pos" into account + mixin SimpleCompare; } class FuncallExpression : Expression { Expression fun; Expression[] args; this(immutable LexPosition pos, Expression fun, Expression[] args...) { super(pos); this.fun=fun; this.args=args.dup; } - mixin SimpleCompare; // do not take "pos" into account + mixin SimpleCompare; } class FunLiteralExpression : Expression { string[] params; Program funbody; mixin SimpleConstructor; - mixin SimpleCompare; // do not take "pos" into account + mixin SimpleCompare; } Index: polemy/tricks.d ================================================================== --- polemy/tricks.d +++ polemy/tricks.d @@ -115,11 +115,11 @@ /* [Todo] is there any way to clearnly implement "assert_compiles" and "assert_not_compile"? */ /// Mixing-in the bean constructor for a class -template SimpleConstructor() +/*mixin*/ template SimpleConstructor() { static if( is(typeof(super) == Object) || super.tupleof.length==0 ) this( typeof(this.tupleof) params ) { static if(this.tupleof.length>0) @@ -171,11 +171,11 @@ }) ); } /// Mixing-in the MOST-DERIVED-member-wise comparator for a class -template SimpleCompare() +/*mixin*/ template SimpleCompare() { override bool opEquals(Object rhs_) const { if( auto rhs = cast(typeof(this))rhs_ ) { @@ -233,5 +233,38 @@ mixin SimpleCompare; } assert_throw!AssertError( new Temp(1,"foo") == new TempDummy(1,"foo") ); assert_throw!AssertError( new Temp(1,"foo") <= new TempDummy(1,"foo") ); } + +/// Mixing-in a simple toString method + +/*mixin*/ template SimpleToString() +{ + override string toString() + { + string str = sprintf!"%s("(typeof(this).stringof); + foreach(i,mem; this.tupleof) + { + if(i) str ~= ","; + static if( is(typeof(mem) == std.bigint.BigInt) ) + str ~= std.bigint.toDecimalString(mem); + else + str ~= sprintf!"%s"(mem); + } + return str ~ ")"; + } +} + +version(unittest) import std.bigint; +unittest +{ + class Temp + { + int x; + string y; + BigInt z; + mixin SimpleConstructor; + mixin SimpleToString; + } + assert_eq( (new Temp(1,"foo",BigInt(42))).toString(), "Temp(1,foo,42)" ); +}