Check-in [077506b38c]
Not logged in
Overview
SHA1 Hash:077506b38c9bda04d09545b8921b5b5af670a9ef
Date: 2010-11-08 20:57:48
User: kinaba
Comment:Generic toString utility added.
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified main.d from [36044e05d28ff416] to [e01d02a22ae40e90].

3 * License: NYSL 0.9982 (http://www.kmonos.net/nysl/ 3 * License: NYSL 0.9982 (http://www.kmonos.net/nysl/ 4 * 4 * 5 * Entry point for Polemy interpreter. 5 * Entry point for Polemy interpreter. 6 */ 6 */ 7 7 8 import std.stdio; 8 import std.stdio; 9 import polemy.eval; 9 import polemy.eval; > 10 > 11 version(unittest) static ~this() > 12 { > 13 writeln( "***********************" ); > 14 writeln( "* All Tests Passed <3 *" ); > 15 writeln( "*********************** (Press Enter to finish)" ); > 16 readln(); > 17 } 10 18 11 void main( string[] args ) 19 void main( string[] args ) 12 { 20 { 13 version(unittest) < 14 { < 15 writeln( "***********************" ); < 16 writeln( "* All Tests Passed <3 *" ); < 17 writeln( "*********************** (Press Enter to finish)" ); < 18 readln(); < 19 return; < 20 } < 21 } 21 }

Modified polemy/ast.d from [79741a3186611288] to [9b22488b3393157f].

17 } 17 } 18 18 19 class DeclStatement : Statement 19 class DeclStatement : Statement 20 { 20 { 21 string var; 21 string var; 22 Expression expr; 22 Expression expr; 23 mixin SimpleConstructor; 23 mixin SimpleConstructor; 24 mixin SimpleCompare; // do not take "pos" into account | 24 mixin SimpleCompare; 25 } 25 } 26 26 27 class ExprStatement : Statement 27 class ExprStatement : Statement 28 { 28 { 29 Expression expr; 29 Expression expr; 30 mixin SimpleConstructor; 30 mixin SimpleConstructor; 31 mixin SimpleCompare; // do not take "pos" into account | 31 mixin SimpleCompare; 32 } 32 } 33 33 34 abstract class Expression 34 abstract class Expression 35 { 35 { 36 immutable LexPosition pos; 36 immutable LexPosition pos; 37 mixin SimpleConstructor; 37 mixin SimpleConstructor; 38 mixin SimpleCompare; // do not take "pos" into account | 38 mixin SimpleCompare; 39 } 39 } 40 40 41 class StrLiteralExpression : Expression 41 class StrLiteralExpression : Expression 42 { 42 { 43 string data; 43 string data; 44 mixin SimpleConstructor; 44 mixin SimpleConstructor; 45 mixin SimpleCompare; // do not take "pos" into account | 45 mixin SimpleCompare; 46 } 46 } 47 47 48 class IntLiteralExpression : Expression 48 class IntLiteralExpression : Expression 49 { 49 { 50 BigInt data; 50 BigInt data; 51 mixin SimpleConstructor; 51 mixin SimpleConstructor; 52 mixin SimpleCompare; // do not take "pos" into account | 52 mixin SimpleCompare; 53 } 53 } 54 54 55 class VarExpression : Expression 55 class VarExpression : Expression 56 { 56 { 57 string var; 57 string var; 58 mixin SimpleConstructor; 58 mixin SimpleConstructor; 59 mixin SimpleCompare; // do not take "pos" into account | 59 mixin SimpleCompare; 60 } 60 } 61 61 62 class AssignExpression : Expression 62 class AssignExpression : Expression 63 { 63 { 64 Expression lhs; 64 Expression lhs; 65 Expression rhs; 65 Expression rhs; 66 mixin SimpleConstructor; 66 mixin SimpleConstructor; 67 mixin SimpleCompare; // do not take "pos" into account | 67 mixin SimpleCompare; 68 } 68 } 69 69 70 class FuncallExpression : Expression 70 class FuncallExpression : Expression 71 { 71 { 72 Expression fun; 72 Expression fun; 73 Expression[] args; 73 Expression[] args; 74 this(immutable LexPosition pos, Expression fun, Expression[] args...) 74 this(immutable LexPosition pos, Expression fun, Expression[] args...) 75 { super(pos); this.fun=fun; this.args=args.dup; } 75 { super(pos); this.fun=fun; this.args=args.dup; } 76 mixin SimpleCompare; // do not take "pos" into account | 76 mixin SimpleCompare; 77 } 77 } 78 78 79 class FunLiteralExpression : Expression 79 class FunLiteralExpression : Expression 80 { 80 { 81 string[] params; 81 string[] params; 82 Program funbody; 82 Program funbody; 83 mixin SimpleConstructor; 83 mixin SimpleConstructor; 84 mixin SimpleCompare; // do not take "pos" into account | 84 mixin SimpleCompare; 85 } 85 }

Modified polemy/tricks.d from [e911a30d1f923777] to [fcea1bf69fccc37f].

113 assert_throw!AssertError( assert_eq(new Temp, 2) ); 113 assert_throw!AssertError( assert_eq(new Temp, 2) ); 114 } 114 } 115 115 116 /* [Todo] is there any way to clearnly implement "assert_compiles" and "assert_n 116 /* [Todo] is there any way to clearnly implement "assert_compiles" and "assert_n 117 117 118 /// Mixing-in the bean constructor for a class 118 /// Mixing-in the bean constructor for a class 119 119 120 template SimpleConstructor() | 120 /*mixin*/ template SimpleConstructor() 121 { 121 { 122 static if( is(typeof(super) == Object) || super.tupleof.length==0 ) 122 static if( is(typeof(super) == Object) || super.tupleof.length==0 ) 123 this( typeof(this.tupleof) params ) 123 this( typeof(this.tupleof) params ) 124 { 124 { 125 static if(this.tupleof.length>0) 125 static if(this.tupleof.length>0) 126 this.tupleof = params; 126 this.tupleof = params; 127 } 127 } ................................................................................................................................................................................ 169 mixin SimpleConstructor; 169 mixin SimpleConstructor; 170 } 170 } 171 }) ); 171 }) ); 172 } 172 } 173 173 174 /// Mixing-in the MOST-DERIVED-member-wise comparator for a class 174 /// Mixing-in the MOST-DERIVED-member-wise comparator for a class 175 175 176 template SimpleCompare() | 176 /*mixin*/ template SimpleCompare() 177 { 177 { 178 override bool opEquals(Object rhs_) const 178 override bool opEquals(Object rhs_) const 179 { 179 { 180 if( auto rhs = cast(typeof(this))rhs_ ) 180 if( auto rhs = cast(typeof(this))rhs_ ) 181 { 181 { 182 foreach(i,_; this.tupleof) 182 foreach(i,_; this.tupleof) 183 if( this.tupleof[i] != rhs.tupleof[i] ) 183 if( this.tupleof[i] != rhs.tupleof[i] ) ................................................................................................................................................................................ 231 string y; 231 string y; 232 mixin SimpleConstructor; 232 mixin SimpleConstructor; 233 mixin SimpleCompare; 233 mixin SimpleCompare; 234 } 234 } 235 assert_throw!AssertError( new Temp(1,"foo") == new TempDummy(1,"foo") ); 235 assert_throw!AssertError( new Temp(1,"foo") == new TempDummy(1,"foo") ); 236 assert_throw!AssertError( new Temp(1,"foo") <= new TempDummy(1,"foo") ); 236 assert_throw!AssertError( new Temp(1,"foo") <= new TempDummy(1,"foo") ); 237 } 237 } > 238 > 239 /// Mixing-in a simple toString method > 240 > 241 /*mixin*/ template SimpleToString() > 242 { > 243 override string toString() > 244 { > 245 string str = sprintf!"%s("(typeof(this).stringof); > 246 foreach(i,mem; this.tupleof) > 247 { > 248 if(i) str ~= ","; > 249 static if( is(typeof(mem) == std.bigint.BigInt) ) > 250 str ~= std.bigint.toDecimalString(mem); > 251 else > 252 str ~= sprintf!"%s"(mem); > 253 } > 254 return str ~ ")"; > 255 } > 256 } > 257 > 258 version(unittest) import std.bigint; > 259 unittest > 260 { > 261 class Temp > 262 { > 263 int x; > 264 string y; > 265 BigInt z; > 266 mixin SimpleConstructor; > 267 mixin SimpleToString; > 268 } > 269 assert_eq( (new Temp(1,"foo",BigInt(42))).toString(), "Temp(1,foo,42)" ) > 270 }