Diff
Not logged in

Differences From Artifact [6063476e92f43069]:

To Artifact [09f6f71388735bcb]:


415 MemokeyType memokey = new MemokeyType(cast(void* 415 MemokeyType memokey = new MemokeyType(cast(void* 416 if(auto p = memokey in memo) 416 if(auto p = memokey in memo) 417 { 417 { 418 (*p)[1] ++; 418 (*p)[1] ++; 419 return (*p)[0]; 419 return (*p)[0]; 420 } 420 } 421 else 421 else 422 memo[memokey] = tuple(evlay.lift(new Bot | 422 memo[memokey] = tuple(cast(Value)new Bot 423 423 424 Value r = nonMemoizedRun(); 424 Value r = nonMemoizedRun(); 425 425 426 int touched = memo[memokey][1]; 426 int touched = memo[memokey][1]; 427 memo[memokey] = tuple(r, 12345678); 427 memo[memokey] = tuple(r, 12345678); 428 return r; 428 return r; 429 } 429 } ................................................................................................................................................................................ 463 override Value invoke(Layer lay, Table ctx, LexPosition 463 override Value invoke(Layer lay, Table ctx, LexPosition 464 { 464 { 465 if( lay != defLay ) 465 if( lay != defLay ) 466 throw genex!RuntimeException(pos, 466 throw genex!RuntimeException(pos, 467 text("only ", defLay, " layer ca 467 text("only ", defLay, " layer ca 468 T typed_args; 468 T typed_args; 469 foreach(i, Ti; T) { 469 foreach(i, Ti; T) { 470 typed_args[i] = cast(Ti) ctx.get(text(i) | 470 Value vi = ctx.get(text(i), ValueLayer, > 471 typed_args[i] = cast(Ti) vi; 471 if( typed_args[i] is null ) 472 if( typed_args[i] is null ) 472 throw genex!RuntimeException(pos 473 throw genex!RuntimeException(pos 473 sprintf!"type mismatch o | 474 sprintf!"type mismatch o 474 } 475 } 475 try { 476 try { 476 return dg(typed_args); 477 return dg(typed_args); 477 } catch( RuntimeException e ) { 478 } catch( RuntimeException e ) { 478 throw e.pos is null ? new RuntimeExcepti 479 throw e.pos is null ? new RuntimeExcepti 479 } 480 } 480 } 481 } ................................................................................................................................................................................ 481 } 482 } 482 theContext.set(name, defLay, new NativeFunValue(dg)); 483 theContext.set(name, defLay, new NativeFunValue(dg)); 483 } 484 } 484 } 485 } 485 486 486 version(unittest) 487 version(unittest) 487 import polemy.runtime; 488 import polemy.runtime; > 489 > 490 unittest > 491 { > 492 auto e = new Evaluator; > 493 enrollRuntimeLibrary(e); > 494 assert_eq( e.evalString(` > 495 @@foo(x){x*2}; > 496 @foo "+" (x,y){x}; > 497 @foo(3+4) > 498 `), new IntValue(6) ); > 499 } 488 500 489 unittest 501 unittest 490 { 502 { 491 auto e = new Evaluator; 503 auto e = new Evaluator; 492 enrollRuntimeLibrary(e); 504 enrollRuntimeLibrary(e); 493 auto r = assert_nothrow( e.evalString(`var x = 21; x + x*x;`) ); 505 auto r = assert_nothrow( e.evalString(`var x = 21; x + x*x;`) ); 494 assert_eq( r, new IntValue(BigInt(21+21*21)) ); 506 assert_eq( r, new IntValue(BigInt(21+21*21)) );