Overview
SHA1 Hash: | 8e3db9ef20d81211722691f1f65d705a8adcd5d4 |
---|---|
Date: | 2010-11-20 23:04:44 |
User: | kinaba |
Comment: | macro worked! |
Timelines: | family | ancestors | descendants | both | trunk |
Downloads: | Tarball | ZIP archive |
Other Links: | files | file ages | manifest |
Tags And Properties
- branch=trunk inherited from [f65680e1d2]
- sym-trunk inherited from [f65680e1d2]
Changes
Modified .poseidon from [706faeb501e0d2d1] to [c60d98a3acceffca].
7 <filter>*.d</filter> 7 <filter>*.d</filter> 8 <showemptyfolder>0</showemptyfolder> 8 <showemptyfolder>0</showemptyfolder> 9 <buildSpec> 9 <buildSpec> 10 <buildType>0</buildType> 10 <buildType>0</buildType> 11 <mainFile>main.d</mainFile> 11 <mainFile>main.d</mainFile> 12 <Args /> 12 <Args /> 13 <options> 13 <options> 14 <dmd> -cov -g -unittest </dmd> | 14 <dmd> -g -unittest </dmd> 15 <tool /> 15 <tool /> 16 <lib /> 16 <lib /> 17 <implib /> 17 <implib /> 18 <extra /> 18 <extra /> 19 <toolextra /> 19 <toolextra /> 20 <merge>0</merge> 20 <merge>0</merge> 21 <nonfiles>0</nonfiles> 21 <nonfiles>0</nonfiles>
Modified d2stacktrace/stacktrace.d from [9e66870b7d120c42] to [e1d39624d6c41174].
244 244 245 StackTrace trace = new StackTrace(); 245 StackTrace trace = new StackTrace(); 246 return trace.GetCallstack(); 246 return trace.GetCallstack(); 247 } 247 } 248 248 249 public: 249 public: 250 static this(){ 250 static this(){ 251 Runtime.traceHandler(&TraceHandler); | 251 // Runtime.traceHandler(&TraceHandler); 252 SetUnhandledExceptionFilter(&UnhandeledExceptionFilterHandler); | 252 // SetUnhandledExceptionFilter(&UnhandeledExceptionFilterHandler); 253 } 253 } 254 254 255 this(){ 255 this(){ 256 if(isInit) 256 if(isInit) 257 return; 257 return; 258 HANDLE hProcess = GetCurrentProcess(); 258 HANDLE hProcess = GetCurrentProcess(); 259 DWORD pid = GetCurrentProcessId(); 259 DWORD pid = GetCurrentProcessId();
Modified polemy/eval.d from [4f24d3bd11889ec1] to [84ee94a6f293fac0].
123 return (cast(FunValue)ctx.get(lay, "(system)", e 123 return (cast(FunValue)ctx.get(lay, "(system)", e 124 [ctx.get(e.var, "@v", e.pos)] 124 [ctx.get(e.var, "@v", e.pos)] 125 ); 125 ); 126 } 126 } 127 }, 127 }, 128 (LayeredExpression e) 128 (LayeredExpression e) 129 { 129 { > 130 if( e.lay == "@macro" ) > 131 return macroEval(e.expr, ctx, false); > 132 else 130 return eval(e.expr, ctx, false, e.lay); | 133 return eval(e.expr, ctx, false, e.lay); 131 }, 134 }, 132 (LetExpression e) 135 (LetExpression e) 133 { 136 { 134 // for letrec, we need this, but should avoid overwritin 137 // for letrec, we need this, but should avoid overwritin 135 // ctx.set(e.var, "@v", new UndefinedValue, e.pos); 138 // ctx.set(e.var, "@v", new UndefinedValue, e.pos); 136 Value v = eval(e.init, ctx, true, lay); 139 Value v = eval(e.init, ctx, true, lay); 137 if(splitCtx) 140 if(splitCtx) ................................................................................................................................................................................ 149 return f.call(e.pos, lay, args); 152 return f.call(e.pos, lay, args); 150 } 153 } 151 throw genex!RuntimeException(e.pos, "Non-funcion is appl 154 throw genex!RuntimeException(e.pos, "Non-funcion is appl 152 }, 155 }, 153 (FunLiteral e) 156 (FunLiteral e) 154 { 157 { 155 Value[Value[]][Layer] memo; 158 Value[Value[]][Layer] memo; > 159 AST macroMemo = null; // cache 156 160 157 // funvalue need not be rised 161 // funvalue need not be rised 158 // no, need to be rised !! suppose @t(fib)("int") 162 // no, need to be rised !! suppose @t(fib)("int") 159 return new FunValue(delegate Value(immutable LexPosition 163 return new FunValue(delegate Value(immutable LexPosition 160 // TODO: only auto raised ones need memo? no? 164 // TODO: only auto raised ones need memo? no? 161 // auto memoization 165 // auto memoization 162 if( lay != "@v" ) | 166 if( lay != "@v" && lay != "@macro" ) 163 { 167 { 164 if( auto memolay = lay in memo ) 168 if( auto memolay = lay in memo ) 165 if( auto pv = args in *memolay ) 169 if( auto pv = args in *memolay ) 166 return *pv; 170 return *pv; 167 memo[lay][args] = (cast(FunValue)ctx.get 171 memo[lay][args] = (cast(FunValue)ctx.get 168 [new UndValue] 172 [new UndValue] 169 ); 173 ); ................................................................................................................................................................................ 171 175 172 if( e.params.length != args.length ) 176 if( e.params.length != args.length ) 173 throw genex!RuntimeException(e.pos, spri 177 throw genex!RuntimeException(e.pos, spri 174 (e.params.length, args.length)); 178 (e.params.length, args.length)); 175 Table ctxNeo = new Table(ctx, Table.Kind.NotProp 179 Table ctxNeo = new Table(ctx, Table.Kind.NotProp 176 foreach(i,p; e.params) 180 foreach(i,p; e.params) 177 ctxNeo.set(p.name, lay, args[i]); 181 ctxNeo.set(p.name, lay, args[i]); > 182 > 183 // @macro run!!! > 184 if( lay == "@macro" ) > 185 return macroEval(e.funbody, ctxNeo, fals > 186 if( macroMemo is null ) > 187 macroMemo = tableToAST("@v",macroEval(e. > 188 auto v = eval(macroMemo, ctxNeo, true, lay); > 189 178 auto v = eval(e.funbody, ctxNeo, true, lay); | 190 //auto v = eval(e.funbody, ctxNeo, true, lay); 179 // auto memoization 191 // auto memoization 180 if( lay != "@v" ) | 192 if( lay != "@v" && lay != "@macro" ) 181 memo[lay][args] = v; 193 memo[lay][args] = v; 182 return v; 194 return v; 183 }); 195 }); 184 }, 196 }, 185 delegate Value (AST e) 197 delegate Value (AST e) 186 { 198 { 187 throw genex!RuntimeException(e.pos, sprintf!"Unknown Kin 199 throw genex!RuntimeException(e.pos, sprintf!"Unknown Kin ................................................................................................................................................................................ 213 t.set("pos", theLayer, pos); 225 t.set("pos", theLayer, pos); 214 t.set("is", theLayer, new StrValue("int")); 226 t.set("is", theLayer, new StrValue("int")); 215 t.set("data", theLayer, new IntValue(e.data)); 227 t.set("data", theLayer, new IntValue(e.data)); 216 return t; 228 return t; 217 }, 229 }, 218 (VarExpression e) 230 (VarExpression e) 219 { 231 { > 232 try { > 233 return ctx.get(e.var, "@macro", e.pos); > 234 } catch( Throwable ) {// [TODO] more precies... 220 Table t = new Table; | 235 Table t = new Table; 221 t.set("pos", theLayer, pos); | 236 t.set("pos", theLayer, pos); 222 t.set("is", theLayer, new StrValue("var")); | 237 t.set("is", theLayer, new StrValue("var")); 223 t.set("name", theLayer, new StrValue(e.var)); | 238 t.set("name", theLayer, new StrValue(e.var)); 224 return t; | 239 return cast(Value)t; > 240 } 225 }, 241 }, 226 (LayeredExpression e) 242 (LayeredExpression e) 227 { 243 { 228 if( AlwaysMacro ) 244 if( AlwaysMacro ) 229 { 245 { 230 Table t = new Table; 246 Table t = new Table; 231 t.set("pos", theLayer, pos); 247 t.set("pos", theLayer, pos); 232 t.set("is", theLayer, new StrValue("lay")); 248 t.set("is", theLayer, new StrValue("lay")); > 249 t.set("layer", theLayer, new StrValue(e.lay)); 233 t.set("expr", theLayer, macroEval(e.expr,ctx,Alw 250 t.set("expr", theLayer, macroEval(e.expr,ctx,Alw 234 return cast(Value)t; 251 return cast(Value)t; 235 } 252 } 236 else 253 else 237 { 254 { 238 return eval(e.expr, ctx, true, e.lay); 255 return eval(e.expr, ctx, true, e.lay); 239 } 256 } ................................................................................................................................................................................ 246 t.set("name", theLayer, new StrValue(e.var)); 263 t.set("name", theLayer, new StrValue(e.var)); 247 t.set("init", theLayer, macroEval(e.init,ctx,AlwaysMacro 264 t.set("init", theLayer, macroEval(e.init,ctx,AlwaysMacro 248 t.set("expr", theLayer, macroEval(e.expr,ctx,AlwaysMacro 265 t.set("expr", theLayer, macroEval(e.expr,ctx,AlwaysMacro 249 return t; 266 return t; 250 }, 267 }, 251 (FuncallExpression e) 268 (FuncallExpression e) 252 { 269 { 253 // [TODO] @macro invokation!!!! | 270 Value _f = macroEval(e.fun,ctx,AlwaysMacro); 254 // if e.fun is varname and its ctx[@macro] is set, sw < > 271 > 272 // copy & pase from normal eval > 273 // [TODO] sync with @layerd parameters. > 274 if( auto f = cast(FunValue)_f ) { > 275 Value[] args; > 276 foreach(a; e.args) > 277 args ~= macroEval(a, ctx, AlwaysMacro); > 278 return f.call(e.pos, "@macro", args); // explici > 279 } > 280 255 Table t = new Table; 281 Table t = new Table; 256 t.set("pos", theLayer, pos); 282 t.set("pos", theLayer, pos); 257 t.set("is", theLayer, new StrValue("app")); 283 t.set("is", theLayer, new StrValue("app")); 258 t.set("fun", theLayer, macroEval(e.fun,ctx,AlwaysMacro)) | 284 t.set("fun", theLayer, _f); 259 Table args = new Table; 285 Table args = new Table; 260 foreach_reverse(a; e.args) { 286 foreach_reverse(a; e.args) { 261 Table cons = new Table; 287 Table cons = new Table; 262 cons.set("car",theLayer,macroEval(a,ctx,AlwaysMa 288 cons.set("car",theLayer,macroEval(a,ctx,AlwaysMa 263 cons.set("cdr",theLayer,args); 289 cons.set("cdr",theLayer,args); 264 args = cons; 290 args = cons; 265 } 291 } 266 t.set("arg", theLayer, args); 292 t.set("arg", theLayer, args); 267 return t; | 293 return cast(Value)t; 268 }, 294 }, 269 (FunLiteral e) 295 (FunLiteral e) 270 { 296 { 271 Table t = new Table; 297 Table t = new Table; 272 t.set("pos", theLayer, pos); 298 t.set("pos", theLayer, pos); 273 t.set("is", theLayer, new StrValue("fun")); 299 t.set("is", theLayer, new StrValue("fun")); 274 t.set("body", theLayer, macroEval(e.funbody,ctx,AlwaysM 300 t.set("body", theLayer, macroEval(e.funbody,ctx,AlwaysM ................................................................................................................................................................................ 339 fac(10);`).val, new IntValue(BigInt(10*9*8*5040))); 365 fac(10);`).val, new IntValue(BigInt(10*9*8*5040))); 340 assert_eq( evalString(`var fib = fun(x){ 366 assert_eq( evalString(`var fib = fun(x){ 341 if(x<2) 367 if(x<2) 342 { 1; } 368 { 1; } 343 else 369 else 344 { fib(x-1) + fib(x-2); }; 370 { fib(x-1) + fib(x-2); }; 345 }; 371 }; 346 fib(10);`).val, new IntValue(BigInt(89))); | 372 fib(5);`).val, new IntValue(BigInt(8))); 347 } 373 } 348 374 349 unittest 375 unittest 350 { 376 { 351 assert_throw!Throwable( evalString(`@@s(x){x}; @s "+"=fun(x,y){x-y};@s(1 377 assert_throw!Throwable( evalString(`@@s(x){x}; @s "+"=fun(x,y){x-y};@s(1 352 assert_eq( evalString(`@@s(x){x}; @s "+"=fun(x,y){x-y};1+2`).val, new In 378 assert_eq( evalString(`@@s(x){x}; @s "+"=fun(x,y){x-y};1+2`).val, new In 353 assert_eq( evalString(`@@s(x){x}; @s "+"=fun(x,y){@v(@s(x)-@s(y))};1+2`) 379 assert_eq( evalString(`@@s(x){x}; @s "+"=fun(x,y){@v(@s(x)-@s(y))};1+2`)
Modified polemy/value.d from [10fa9090c50cdaf9] to [ff42bce4fb7dc674].
145 else 145 else 146 { 146 { 147 if(auto next = this.access!Table(lay,path)) 147 if(auto next = this.access!Table(lay,path)) 148 return next.access!T(lay,rest); 148 return next.access!T(lay,rest); 149 } 149 } 150 return null; 150 return null; 151 } 151 } > 152 > 153 string toStringWithoutParen() const > 154 { > 155 string result; > 156 bool first = true; > 157 foreach(k, l2d; data) > 158 foreach(l,d; l2d) > 159 { > 160 if(first) first=false; else result~=", "; > 161 result ~= k; > 162 result ~= l; > 163 result ~= ":"; > 164 result ~= text(cast(Value)d); > 165 } > 166 if( prototype !is null ) > 167 { > 168 result ~= " / "; > 169 result ~= prototype.toStringWithoutParen(); > 170 } > 171 return result; > 172 } > 173 > 174 string toString() const > 175 { > 176 return "{" ~ toStringWithoutParen() ~ "}"; > 177 } 152 178 153 private: 179 private: 154 Table prototype; 180 Table prototype; 155 Kind kind; 181 Kind kind; 156 Value[Layer][string] data; 182 Value[Layer][string] data; 157 183 158 bool setIfExist(string i, Layer lay, Value v) 184 bool setIfExist(string i, Layer lay, Value v) ................................................................................................................................................................................ 242 if(auto t = cast(Table)v) 268 if(auto t = cast(Table)v) 243 result ~= tableToAST(theLayer,t); 269 result ~= tableToAST(theLayer,t); 244 else 270 else 245 throw genex!RuntimeException(cast(LexPosition)null, "Inv 271 throw genex!RuntimeException(cast(LexPosition)null, "Inv 246 return result; 272 return result; 247 } 273 } 248 274 249 AST tableToAST( Layer theLayer, Table t ) | 275 AST tableToAST( Layer theLayer, Value vvvv ) 250 { 276 { > 277 Table t = cast(Table)vvvv; > 278 if( t is null ) > 279 throw genex!RuntimeException(cast(LexPosition)null, "Invalid AST > 280 251 auto nodeType = t.access!StrValue(theLayer, "is"); 281 auto nodeType = t.access!StrValue(theLayer, "is"); 252 if( nodeType is null ) 282 if( nodeType is null ) 253 throw genex!RuntimeException(cast(LexPosition)null, "Invalid AST 283 throw genex!RuntimeException(cast(LexPosition)null, "Invalid AST 254 auto pos = extractPos(t); 284 auto pos = extractPos(t); 255 switch(nodeType.data) 285 switch(nodeType.data) 256 { 286 { 257 case "int": 287 case "int": ................................................................................................................................................................................ 304 if(auto ll = tt.access!Table(theLayer, "layer")) 334 if(auto ll = tt.access!Table(theLayer, "layer")) 305 { 335 { 306 Layer[] ls; 336 Layer[] ls; 307 foreach(lll; tableAsConsList(theLayer, l 337 foreach(lll; tableAsConsList(theLayer, l 308 if(auto l = cast(StrValue)lll) 338 if(auto l = cast(StrValue)lll) 309 ls ~= l.data; 339 ls ~= l.data; 310 else 340 else 311 throw genex!RuntimeExcep | 341 throw genex!RuntimeExcep 312 ps ~= new Parameter(ss.data, ls); 342 ps ~= new Parameter(ss.data, ls); 313 continue; 343 continue; 314 } 344 } 315 else 345 else 316 { 346 { 317 Layer[] emp; 347 Layer[] emp; 318 ps ~= new Parameter(ss.data, emp); 348 ps ~= new Parameter(ss.data, emp); > 349 continue; 319 } 350 } 320 throw genex!RuntimeException(cast(LexPosition)nu | 351 throw genex!RuntimeException(cast(LexPosition)nu 321 } 352 } 322 auto bb = tableToAST(theLayer, b); 353 auto bb = tableToAST(theLayer, b); 323 return new FunLiteral(pos,ps,bb); 354 return new FunLiteral(pos,ps,bb); 324 } 355 } 325 throw genex!RuntimeException(cast(LexPosition)null, `Invalid AST 356 throw genex!RuntimeException(cast(LexPosition)null, `Invalid AST 326 default: 357 default: 327 throw genex!RuntimeException(cast(LexPosition)null, sprintf!`Inv 358 throw genex!RuntimeException(cast(LexPosition)null, sprintf!`Inv 328 } 359 } 329 } 360 }
Modified sample/plusminus.pmy from [5278c04aa82ef1ff] to [2f68238d12815ac3].