Check-in [7465fcdd7f]
Not logged in
Overview
SHA1 Hash:7465fcdd7f2f7407f2e88bc6fde115bfaff3660b
Date: 2010-11-09 23:59:36
User: kinaba
Comment:layered function invocation
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified main.d from [b29be17d733aa309] to [667427a12e5e3b09].

26 { 26 { 27 scope(failure) 27 scope(failure) 28 { buf = ""; lineno = nextlineno; } 28 { buf = ""; lineno = nextlineno; } 29 29 30 buf ~= s; 30 buf ~= s; 31 nextlineno ++; 31 nextlineno ++; 32 try 32 try 33 { lastVal = eval(parseString(buf, "<REPL>", lineno), ctx | 33 { lastVal = eval(parseString(buf, "<REPL>", lineno), ctx 34 catch( UnexpectedEOF ) 34 catch( UnexpectedEOF ) 35 { return false; } // wait 35 { return false; } // wait 36 buf = ""; 36 buf = ""; 37 lineno = nextlineno; 37 lineno = nextlineno; 38 return true; 38 return true; 39 } 39 } 40 40

Modified polemy/eval.d from [62b3543f769fc9c9] to [050eab1743a45f8b].

13 import std.typecons; 13 import std.typecons; 14 import std.stdio; 14 import std.stdio; 15 15 16 Table createGlobalContext() 16 Table createGlobalContext() 17 { 17 { 18 auto ctx = new Table; 18 auto ctx = new Table; 19 // [TODO] autogenerate these typechecks 19 // [TODO] autogenerate these typechecks 20 ctx.set("+", "@val", new FunValue(delegate Value(immutable LexPosition p | 20 ctx.set("+", "@v", new FunValue(delegate Value(immutable LexPosition pos 21 if( args.length != 2 ) 21 if( args.length != 2 ) 22 throw new RuntimeException(pos, "+ takes two arguments!! | 22 throw genex!RuntimeException(pos, "+ takes two arguments 23 if( auto x = cast(IntValue)args[0] ) 23 if( auto x = cast(IntValue)args[0] ) 24 if( auto y = cast(IntValue)args[1] ) 24 if( auto y = cast(IntValue)args[1] ) 25 return new IntValue(x.data+y.data); 25 return new IntValue(x.data+y.data); 26 throw new RuntimeException(pos, "cannot add non-integers"); | 26 throw genex!RuntimeException(pos, "cannot add non-integers"); 27 })); 27 })); 28 ctx.set("-", "@val", new FunValue(delegate Value(immutable LexPosition p | 28 ctx.set("-", "@v", new FunValue(delegate Value(immutable LexPosition pos 29 if( args.length != 2 ) 29 if( args.length != 2 ) 30 throw new RuntimeException(pos, "- takes two arguments!! | 30 throw genex!RuntimeException(pos, "- takes two arguments 31 if( auto x = cast(IntValue)args[0] ) 31 if( auto x = cast(IntValue)args[0] ) 32 if( auto y = cast(IntValue)args[1] ) 32 if( auto y = cast(IntValue)args[1] ) 33 return new IntValue(x.data-y.data); 33 return new IntValue(x.data-y.data); 34 throw new RuntimeException(pos, "cannot subtract non-integers"); | 34 throw genex!RuntimeException(pos, "cannot subtract non-integers" 35 })); 35 })); 36 ctx.set("*", "@val", new FunValue(delegate Value(immutable LexPosition p | 36 ctx.set("*", "@v", new FunValue(delegate Value(immutable LexPosition pos 37 if( args.length != 2 ) 37 if( args.length != 2 ) 38 throw new RuntimeException(pos, "* takes two arguments!! | 38 throw genex!RuntimeException(pos, "* takes two arguments 39 if( auto x = cast(IntValue)args[0] ) 39 if( auto x = cast(IntValue)args[0] ) 40 if( auto y = cast(IntValue)args[1] ) 40 if( auto y = cast(IntValue)args[1] ) 41 return new IntValue(x.data*y.data); 41 return new IntValue(x.data*y.data); 42 throw new RuntimeException(pos, "cannot multiply non-integers"); | 42 throw genex!RuntimeException(pos, "cannot multiply non-integers" 43 })); 43 })); 44 ctx.set("/", "@val", new FunValue(delegate Value(immutable LexPosition p | 44 ctx.set("/", "@v", new FunValue(delegate Value(immutable LexPosition pos 45 if( args.length != 2 ) 45 if( args.length != 2 ) 46 throw new RuntimeException(pos, "/ takes two arguments!! | 46 throw genex!RuntimeException(pos, "/ takes two arguments 47 if( auto x = cast(IntValue)args[0] ) 47 if( auto x = cast(IntValue)args[0] ) 48 if( auto y = cast(IntValue)args[1] ) 48 if( auto y = cast(IntValue)args[1] ) 49 return new IntValue(x.data/y.data); 49 return new IntValue(x.data/y.data); 50 throw new RuntimeException(pos, "cannot divide non-integers"); | 50 throw genex!RuntimeException(pos, "cannot divide non-integers"); 51 })); 51 })); 52 ctx.set("<", "@val", new FunValue(delegate Value(immutable LexPosition p | 52 ctx.set("<", "@v", new FunValue(delegate Value(immutable LexPosition pos 53 if( args.length != 2 ) 53 if( args.length != 2 ) 54 throw new RuntimeException(pos, "< takes two arguments!! | 54 throw genex!RuntimeException(pos, "< takes two arguments 55 if( auto x = cast(IntValue)args[0] ) 55 if( auto x = cast(IntValue)args[0] ) 56 if( auto y = cast(IntValue)args[1] ) 56 if( auto y = cast(IntValue)args[1] ) 57 return new IntValue(BigInt(to!int(x.data < y.dat 57 return new IntValue(BigInt(to!int(x.data < y.dat 58 throw new RuntimeException(pos, "cannot compare non-integers"); | 58 throw genex!RuntimeException(pos, "cannot compare non-integers") 59 })); 59 })); 60 ctx.set(">", "@val", new FunValue(delegate Value(immutable LexPosition p | 60 ctx.set(">", "@v", new FunValue(delegate Value(immutable LexPosition pos 61 if( args.length != 2 ) 61 if( args.length != 2 ) 62 throw new RuntimeException(pos, "> takes two arguments!! | 62 throw genex!RuntimeException(pos, "> takes two arguments 63 if( auto x = cast(IntValue)args[0] ) 63 if( auto x = cast(IntValue)args[0] ) 64 if( auto y = cast(IntValue)args[1] ) 64 if( auto y = cast(IntValue)args[1] ) 65 return new IntValue(BigInt(to!int(x.data>y.data) 65 return new IntValue(BigInt(to!int(x.data>y.data) 66 throw new RuntimeException(pos, "cannot compare non-integers"); | 66 throw genex!RuntimeException(pos, "cannot compare non-integers") 67 })); 67 })); 68 ctx.set("print", "@val", new FunValue(delegate Value(immutable LexPositi | 68 ctx.set("print", "@v", new FunValue(delegate Value(immutable LexPosition 69 foreach(a; args) 69 foreach(a; args) 70 write(a); 70 write(a); 71 writeln(""); 71 writeln(""); 72 return new IntValue(BigInt(178)); 72 return new IntValue(BigInt(178)); 73 })); 73 })); 74 ctx.set("if", "@val", new FunValue(delegate Value(immutable LexPosition | 74 ctx.set("if", "@v", new FunValue(delegate Value(immutable LexPosition po 75 if( args.length != 3 ) 75 if( args.length != 3 ) 76 throw new RuntimeException(pos, "if takes three argument | 76 throw genex!RuntimeException(pos, "if takes three argume 77 if( auto x = cast(IntValue)args[0] ) 77 if( auto x = cast(IntValue)args[0] ) 78 if( auto ft = cast(FunValue)args[1] ) 78 if( auto ft = cast(FunValue)args[1] ) 79 if( auto fe = cast(FunValue)args[2] ) 79 if( auto fe = cast(FunValue)args[2] ) 80 return (x.data == 0 ? fe : ft).call(pos,[]); | 80 return (x.data == 0 ? fe : ft).call(pos,lay,[]); 81 throw new RuntimeException(pos, "type mismatch in if"); | 81 throw genex!RuntimeException(pos, "type mismatch in if"); 82 })); 82 })); 83 return ctx; 83 return ctx; 84 } 84 } 85 85 86 /// Entry point of this module 86 /// Entry point of this module 87 87 88 Tuple!(Value,"val",Table,"ctx") evalString(S,T...)(S str, T fn_ln_cn) 88 Tuple!(Value,"val",Table,"ctx") evalString(S,T...)(S str, T fn_ln_cn) ................................................................................................................................................................................ 94 { 94 { 95 return eval( polemy.parse.parseFile(filename, ln_cn) ); 95 return eval( polemy.parse.parseFile(filename, ln_cn) ); 96 } 96 } 97 97 98 Tuple!(Value,"val",Table,"ctx") eval(AST e) 98 Tuple!(Value,"val",Table,"ctx") eval(AST e) 99 { 99 { 100 Table ctx = createGlobalContext(); 100 Table ctx = createGlobalContext(); 101 return typeof(return)(eval(e, ctx), ctx); | 101 return typeof(return)(eval(e, ctx, false, "@v"), ctx); 102 } 102 } 103 103 104 Value eval(AST _e, Table ctx, bool splitCtx = false, Layer lay="@val") | 104 Value eval(AST _e, Table ctx, bool splitCtx, Layer lay) 105 { 105 { 106 if( auto e = cast(StrLiteral)_e ) 106 if( auto e = cast(StrLiteral)_e ) 107 { 107 { 108 return new StrValue(e.data); 108 return new StrValue(e.data); 109 } 109 } 110 else 110 else 111 if( auto e = cast(IntLiteral)_e ) 111 if( auto e = cast(IntLiteral)_e ) ................................................................................................................................................................................ 122 { 122 { 123 return eval(e.expr, ctx, false, e.lay); 123 return eval(e.expr, ctx, false, e.lay); 124 } 124 } 125 else 125 else 126 if( auto e = cast(LetExpression)_e ) 126 if( auto e = cast(LetExpression)_e ) 127 { 127 { 128 // for letrec, we need this, but should avoid overwriting???? 128 // for letrec, we need this, but should avoid overwriting???? 129 // ctx.set(e.var, "@val", new UndefinedValue, e.pos); | 129 // ctx.set(e.var, "@v", new UndefinedValue, e.pos); 130 Value v = eval(e.init, ctx, true); | 130 Value v = eval(e.init, ctx, true, lay); 131 if(splitCtx) 131 if(splitCtx) 132 ctx = new Table(ctx, Table.Kind.NotPropagateSet); 132 ctx = new Table(ctx, Table.Kind.NotPropagateSet); 133 ctx.set(e.var, (e.layer.length ? e.layer : lay), v, e.pos); 133 ctx.set(e.var, (e.layer.length ? e.layer : lay), v, e.pos); 134 return eval(e.expr, ctx); | 134 return eval(e.expr, ctx, false, lay); 135 } 135 } 136 else 136 else 137 if( auto e = cast(FuncallExpression)_e ) 137 if( auto e = cast(FuncallExpression)_e ) 138 { 138 { 139 Value _f = eval(e.fun, ctx); | 139 Value _f = eval(e.fun, ctx, true, lay); 140 if( auto f = cast(FunValue)_f ) { 140 if( auto f = cast(FunValue)_f ) { 141 Value[] args; 141 Value[] args; 142 foreach(a; e.args) 142 foreach(a; e.args) 143 args ~= eval(a, ctx); | 143 args ~= eval(a, ctx, true, lay); 144 return f.call(e.pos, args); | 144 return f.call(e.pos, lay, args); 145 } else 145 } else 146 throw new RuntimeException(e.pos, "Non-funcion is applie | 146 throw genex!RuntimeException(e.pos, "Non-funcion is appl 147 } 147 } 148 else 148 else 149 if( auto e = cast(FunLiteral)_e ) 149 if( auto e = cast(FunLiteral)_e ) 150 { 150 { 151 return new FunValue(delegate Value(immutable LexPosition pos, Va | 151 return new FunValue(delegate Value(immutable LexPosition pos, st 152 if( e.params.length != args.length ) 152 if( e.params.length != args.length ) 153 throw new RuntimeException(e.pos, sprintf!"Argum | 153 throw genex!RuntimeException(e.pos, sprintf!"Arg 154 (e.params.length, args.length)); 154 (e.params.length, args.length)); 155 Table ctxNeo = new Table(ctx, Table.Kind.NotPropagateSet 155 Table ctxNeo = new Table(ctx, Table.Kind.NotPropagateSet 156 foreach(i,p; e.params) 156 foreach(i,p; e.params) 157 ctxNeo.set(p, "@val", args[i]); | 157 ctxNeo.set(p, lay, args[i]); 158 return eval(e.funbody, ctxNeo); | 158 return eval(e.funbody, ctxNeo, true, lay); 159 }); 159 }); 160 } 160 } 161 throw new RuntimeException(_e.pos, sprintf!"Unknown Kind of Expression % | 161 throw genex!RuntimeException(_e.pos, sprintf!"Unknown Kind of Expression 162 } 162 } 163 163 164 unittest 164 unittest 165 { 165 { 166 auto r = assert_nothrow( evalString(`var x = 21; x + x*x;`) ); 166 auto r = assert_nothrow( evalString(`var x = 21; x + x*x;`) ); 167 assert_eq( r.val, new IntValue(BigInt(21+21*21)) ); 167 assert_eq( r.val, new IntValue(BigInt(21+21*21)) ); 168 assert_eq( r.ctx.get("x","@val"), new IntValue(BigInt(21)) ); | 168 assert_eq( r.ctx.get("x","@v"), new IntValue(BigInt(21)) ); 169 assert_nothrow( r.ctx.get("x","@val") ); | 169 assert_nothrow( r.ctx.get("x","@v") ); 170 assert_throw!RuntimeException( r.ctx.get("y","@val") ); | 170 assert_throw!RuntimeException( r.ctx.get("y","@v") ); 171 } 171 } 172 unittest 172 unittest 173 { 173 { 174 auto r = assert_nothrow( evalString(`var x = 21; var x = x + x*x;`) ); 174 auto r = assert_nothrow( evalString(`var x = 21; var x = x + x*x;`) ); 175 assert_eq( r.val, new IntValue(BigInt(21+21*21)) ); 175 assert_eq( r.val, new IntValue(BigInt(21+21*21)) ); 176 assert_eq( r.ctx.get("x","@val"), new IntValue(BigInt(21+21*21)) ); | 176 assert_eq( r.ctx.get("x","@v"), new IntValue(BigInt(21+21*21)) ); 177 assert_nothrow( r.ctx.get("x","@val") ); | 177 assert_nothrow( r.ctx.get("x","@v") ); 178 assert_throw!RuntimeException( r.ctx.get("y","@val") ); | 178 assert_throw!RuntimeException( r.ctx.get("y","@v") ); 179 } 179 } 180 unittest 180 unittest 181 { 181 { 182 assert_eq( evalString(`let x=1; let y=(let x=2); x`).val, new IntValue(B 182 assert_eq( evalString(`let x=1; let y=(let x=2); x`).val, new IntValue(B 183 assert_eq( evalString(`let x=1; let y=(let x=2;fun(){x}); y()`).val, new 183 assert_eq( evalString(`let x=1; let y=(let x=2;fun(){x}); y()`).val, new 184 } 184 } 185 unittest 185 unittest ................................................................................................................................................................................ 203 if(x<2) 203 if(x<2) 204 { 1; } 204 { 1; } 205 else 205 else 206 { fib(x-1) + fib(x-2); }; 206 { fib(x-1) + fib(x-2); }; 207 }; 207 }; 208 fib(10);`).val, new IntValue(BigInt(89))); 208 fib(10);`).val, new IntValue(BigInt(89))); 209 } 209 } > 210 > 211 unittest > 212 { > 213 assert_throw!Throwable( evalString(`@s "+"=fun(x,y){x-y};@s(1+2)`) ); > 214 assert_eq( evalString(`@s "+"=fun(x,y){x-y};1+2`).val, new IntValue(BigI > 215 assert_eq( evalString(`@s "+"=fun(x,y){@v(@s(x)-@s(y))};1+2`).val, new I > 216 assert_eq( evalString(`@s "+"=fun(x,y){@v(@s(x)-@s(y))};@s(1+2)`).val, n > 217 }

Modified polemy/lex.d from [1725bdb3bf054565] to [caf474d107a1f8cb].

159 readWhile!isSpace(); 159 readWhile!isSpace(); 160 this.current = (current is null ? readNext() : current); 160 this.current = (current is null ? readNext() : current); 161 } 161 } 162 162 163 public static { 163 public static { 164 bool isSpace (dchar c) { return std.ctype.isspace(c)!=0; } 164 bool isSpace (dchar c) { return std.ctype.isspace(c)!=0; } 165 bool isSymbol (dchar c) { return 0x21<=c && c<=0x7f && !std.cty 165 bool isSymbol (dchar c) { return 0x21<=c && c<=0x7f && !std.cty 166 bool isSSymbol (dchar c) { return !find("()[]{};", c).empty; } | 166 bool isSSymbol (dchar c) { return "()[]{};@".canFind(c); } 167 bool isMSymbol (dchar c) { return isSymbol(c) && !isSSymbol(c) & 167 bool isMSymbol (dchar c) { return isSymbol(c) && !isSSymbol(c) & 168 bool isLetter (dchar c) { return !isSpace(c) && !isSymbol(c); } 168 bool isLetter (dchar c) { return !isSpace(c) && !isSymbol(c); } 169 } 169 } 170 170 171 string readQuoted(const LexPosition pos){char[] buf; return readQuoted(p 171 string readQuoted(const LexPosition pos){char[] buf; return readQuoted(p 172 string readQuoted(const LexPosition pos, ref char[] buf) 172 string readQuoted(const LexPosition pos, ref char[] buf) 173 { 173 { ................................................................................................................................................................................ 269 assert_eq( ts[4].pos.lineno, 2 ); 269 assert_eq( ts[4].pos.lineno, 2 ); 270 assert_eq( ts[4].pos.column, 6 ); 270 assert_eq( ts[4].pos.column, 6 ); 271 assert_eq( ts[4].str, ":-" ); 271 assert_eq( ts[4].str, ":-" ); 272 272 273 assert_eq( ts[5].pos.lineno, 2 ); 273 assert_eq( ts[5].pos.lineno, 2 ); 274 assert_eq( ts[5].pos.column, 8 ); 274 assert_eq( ts[5].pos.column, 8 ); 275 assert_eq( ts[5].str, "(" ); 275 assert_eq( ts[5].str, "(" ); 276 assert_eq( ts[6].str, "@@" ); | 276 assert_eq( ts[6].str, "@" ); > 277 assert_eq( ts[7].str, "@" ); 277 assert_eq( ts[7].str, ";" ); // paren and simicolons are split | 278 assert_eq( ts[8].str, ";" ); // paren and simicolons, atmarks are split 278 279 279 assert_eq( ts.length, 8 ); | 280 assert_eq( ts.length, 9 ); 280 } 281 } 281 282 282 unittest 283 unittest 283 { 284 { 284 // !! be sure to run the unittest on the root of the source directory 285 // !! be sure to run the unittest on the root of the source directory 285 auto lexf = lexerFromFile("polemy/lex.d"); 286 auto lexf = lexerFromFile("polemy/lex.d"); 286 lexf = find!`a.str == "module"`(lexf); 287 lexf = find!`a.str == "module"`(lexf); ................................................................................................................................................................................ 364 365 365 unittest 366 unittest 366 { 367 { 367 auto lex = lexerFromString(`=""`); 368 auto lex = lexerFromString(`=""`); 368 assert_eq(lex.front.str, "="); lex.popFront; 369 assert_eq(lex.front.str, "="); lex.popFront; 369 assert_eq(lex.front.str, ""); lex.popFront; 370 assert_eq(lex.front.str, ""); lex.popFront; 370 assert( lex.empty ); 371 assert( lex.empty ); > 372 assert_eq( lexerFromString(`-@`).front.str, "-" ); 371 } 373 } 372 374 373 /// Forward range for reader character by character, 375 /// Forward range for reader character by character, 374 /// keeping track of position information and caring \r\n -> \n conversion. 376 /// keeping track of position information and caring \r\n -> \n conversion. 375 377 376 private 378 private 377 struct PositionedReader(CharSeq) 379 struct PositionedReader(CharSeq)

Modified polemy/value.d from [737774791c82ade1] to [01c119756ed23ca5].

8 import polemy._common; 8 import polemy._common; 9 import polemy.lex; 9 import polemy.lex; 10 10 11 /// Raised when something went wrong in runtime 11 /// Raised when something went wrong in runtime 12 12 13 class RuntimeException : Exception 13 class RuntimeException : Exception 14 { 14 { 15 const LexPosition pos; | 15 mixin ExceptionWithPosition; 16 < 17 this( const LexPosition pos, string msg, string file=null, size_t line=0 < 18 { super(sprintf!"[%s] %s"(pos, msg), file, line, next); this.pos < 19 } 16 } 20 17 21 /// Runtime values of Polemy 18 /// Runtime values of Polemy 22 19 23 abstract class Value 20 abstract class Value 24 { 21 { 25 } 22 } 26 23 27 class IntValue : Value 24 class IntValue : Value 28 { 25 { 29 BigInt data; 26 BigInt data; 30 27 31 mixin SimpleConstructor; < 32 mixin SimpleCompare; | 28 mixin SimpleClass; 33 override string toString() const { return std.bigint.toDecimalString(cas 29 override string toString() const { return std.bigint.toDecimalString(cas 34 } 30 } 35 31 36 class StrValue : Value 32 class StrValue : Value 37 { 33 { 38 string data; 34 string data; 39 35 40 mixin SimpleConstructor; < 41 mixin SimpleCompare; | 36 mixin SimpleClass; 42 override string toString() const { return data; } 37 override string toString() const { return data; } 43 } 38 } 44 39 45 class FunValue : Value 40 class FunValue : Value 46 { 41 { 47 Value delegate(immutable LexPosition pos, Value[]) data; | 42 Value delegate(immutable LexPosition pos, string lay, Value[]) data; 48 43 49 mixin SimpleConstructor; 44 mixin SimpleConstructor; 50 alias data call; 45 alias data call; 51 override string toString() const { return sprintf!"(function:%s:%s)"(dat 46 override string toString() const { return sprintf!"(function:%s:%s)"(dat 52 } 47 } 53 48 54 /// Layer ID 49 /// Layer ID ................................................................................................................................................................................ 103 unittest 98 unittest 104 { 99 { 105 Table c0 = new Table; 100 Table c0 = new Table; 106 Table c01 = new Table(c0, Table.Kind.NotPropagateSet); 101 Table c01 = new Table(c0, Table.Kind.NotPropagateSet); 107 Table c012 = new Table(c01, Table.Kind.PropagateSet); 102 Table c012 = new Table(c01, Table.Kind.PropagateSet); 108 Table c013 = new Table(c01, Table.Kind.PropagateSet); 103 Table c013 = new Table(c01, Table.Kind.PropagateSet); 109 104 110 assert_nothrow( c012.set("x", "@val", new IntValue(BigInt(12))) ); | 105 assert_nothrow( c012.set("x", "@v", new IntValue(BigInt(12))) ); 111 assert_throw!RuntimeException( c013.get("x", "@val") ); | 106 assert_throw!RuntimeException( c013.get("x", "@v") ); 112 assert_nothrow( c013.set("x", "@val", new IntValue(BigInt(13))) ); | 107 assert_nothrow( c013.set("x", "@v", new IntValue(BigInt(13))) ); 113 assert_eq( c013.get("x", "@val"), new IntValue(BigInt(13)) ); | 108 assert_eq( c013.get("x", "@v"), new IntValue(BigInt(13)) ); 114 assert_eq( c012.get("x", "@val"), new IntValue(BigInt(12)) ); | 109 assert_eq( c012.get("x", "@v"), new IntValue(BigInt(12)) ); 115 assert_throw!RuntimeException( c01.get("x", "@val") ); | 110 assert_throw!RuntimeException( c01.get("x", "@v") ); > 111 > 112 assert_nothrow( c01.set("y", "@v", new IntValue(BigInt(1))) ); > 113 assert_eq( c013.get("y", "@v"), new IntValue(BigInt(1)) ); > 114 assert_eq( c012.get("y", "@v"), new IntValue(BigInt(1)) ); > 115 assert_eq( c01.get("y", "@v"), new IntValue(BigInt(1)) ); 116 116 117 assert_nothrow( c01.set("y", "@val", new IntValue(BigInt(1))) ); | 117 assert_nothrow( c0.set("z", "@v", new IntValue(BigInt(0))) ); 118 assert_eq( c013.get("y", "@val"), new IntValue(BigInt(1)) ); | 118 assert_eq( c013.get("z", "@v"), new IntValue(BigInt(0)) ); > 119 assert_eq( c012.get("z", "@v"), new IntValue(BigInt(0)) ); 119 assert_eq( c012.get("y", "@val"), new IntValue(BigInt(1)) ); | 120 assert_eq( c01.get("z", "@v"), new IntValue(BigInt(0)) ); 120 assert_eq( c01.get("y", "@val"), new IntValue(BigInt(1)) ); | 121 assert_eq( c0.get("z", "@v"), new IntValue(BigInt(0)) ); 121 122 122 assert_nothrow( c0.set("z", "@val", new IntValue(BigInt(0))) ); | 123 assert_nothrow( c012.set("y", "@v", new IntValue(BigInt(444))) ); 123 assert_eq( c013.get("z", "@val"), new IntValue(BigInt(0)) ); | 124 assert_eq( c013.get("y", "@v"), new IntValue(BigInt(444)) ); 124 assert_eq( c012.get("z", "@val"), new IntValue(BigInt(0)) ); < 125 assert_eq( c01.get("z", "@val"), new IntValue(BigInt(0)) ); | 125 assert_eq( c012.get("y", "@v"), new IntValue(BigInt(444)) ); 126 assert_eq( c0.get("z", "@val"), new IntValue(BigInt(0)) ); | 126 assert_eq( c01.get("y", "@v"), new IntValue(BigInt(444)) ); 127 127 128 assert_nothrow( c012.set("y", "@val", new IntValue(BigInt(444))) ); < 129 assert_eq( c013.get("y", "@val"), new IntValue(BigInt(444)) ); < 130 assert_eq( c012.get("y", "@val"), new IntValue(BigInt(444)) ); < 131 assert_eq( c01.get("y", "@val"), new IntValue(BigInt(444)) ); < 132 < 133 assert_nothrow( c012.set("z", "@val", new IntValue(BigInt(555))) ); | 128 assert_nothrow( c012.set("z", "@v", new IntValue(BigInt(555))) ); 134 assert_eq( c013.get("z", "@val"), new IntValue(BigInt(0)) ); | 129 assert_eq( c013.get("z", "@v"), new IntValue(BigInt(0)) ); 135 assert_eq( c012.get("z", "@val"), new IntValue(BigInt(555)) ); | 130 assert_eq( c012.get("z", "@v"), new IntValue(BigInt(555)) ); 136 assert_eq( c01.get("z", "@val"), new IntValue(BigInt(0)) ); | 131 assert_eq( c01.get("z", "@v"), new IntValue(BigInt(0)) ); 137 assert_eq( c0.get("z", "@val"), new IntValue(BigInt(0)) ); | 132 assert_eq( c0.get("z", "@v"), new IntValue(BigInt(0)) ); 138 133 139 // [TODO] define the semantics and test @layers 134 // [TODO] define the semantics and test @layers 140 } 135 }

Modified tricks/test.d from [09cc57fcd7c969ca] to [7c50b0e91b8919b8].

6 */ 6 */ 7 module tricks.test; 7 module tricks.test; 8 import std.conv : to; 8 import std.conv : to; 9 import core.exception; 9 import core.exception; 10 10 11 /// Unittest helper that asserts an expression must throw something 11 /// Unittest helper that asserts an expression must throw something 12 12 > 13 void assert_throw(ExceptionType=Throwable, 13 void assert_throw(ExceptionType, T, string fn=__FILE__, size_t ln=__LINE__)(lazy | 14 T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string msg="") 14 { 15 { > 16 static if( is(ExceptionType == Throwable) ) 15 try | 17 try 16 { t(); } | 18 { t(); } 17 catch(ExceptionType) | 19 catch(ExceptionType) 18 { return; } | 20 { return; } > 21 else > 22 try > 23 { t(); } > 24 catch(ExceptionType) > 25 { return; } 19 catch(Throwable e) | 26 catch(Throwable e) 20 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad exception\n > | 27 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad excep 21 onAssertErrorMsg(fn, ln, msg.length ? msg : "not thrown"); 28 onAssertErrorMsg(fn, ln, msg.length ? msg : "not thrown"); 22 } 29 } 23 30 24 /// Unittest helper that asserts an expression must not throw anything 31 /// Unittest helper that asserts an expression must not throw anything 25 32 26 auto assert_nothrow(T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string 33 auto assert_nothrow(T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string 27 { 34 {