Differences From Artifact [6063476e92f43069]:
- File
polemy/eval.d
- 2010-11-27 12:49:03 - part of checkin [a795c97dc3] on branch trunk - changed Let.init to Let.vdef. IT IS VERY DANGEROUS TO USE .init MEMBER NAME in D!!!!!!!! (user: kinaba) [annotate]
To Artifact [09f6f71388735bcb]:
- File
polemy/eval.d
- 2010-11-27 14:23:54 - part of checkin [005474ba5b] on branch trunk - changed: not to lift _|_ (user: kinaba) [annotate]
415 415 MemokeyType memokey = new MemokeyType(cast(void*)ast, lay, ctx);
416 416 if(auto p = memokey in memo)
417 417 {
418 418 (*p)[1] ++;
419 419 return (*p)[0];
420 420 }
421 421 else
422 - memo[memokey] = tuple(evlay.lift(new BottomValue, ctx, pos), 0);
422 + memo[memokey] = tuple(cast(Value)new BottomValue, 0);
423 423
424 424 Value r = nonMemoizedRun();
425 425
426 426 int touched = memo[memokey][1];
427 427 memo[memokey] = tuple(r, 12345678);
428 428 return r;
429 429 }
................................................................................
463 463 override Value invoke(Layer lay, Table ctx, LexPosition pos)
464 464 {
465 465 if( lay != defLay )
466 466 throw genex!RuntimeException(pos,
467 467 text("only ", defLay, " layer can call native function: ", name));
468 468 T typed_args;
469 469 foreach(i, Ti; T) {
470 - typed_args[i] = cast(Ti) ctx.get(text(i), ValueLayer, pos);
470 + Value vi = ctx.get(text(i), ValueLayer, pos);
471 + typed_args[i] = cast(Ti) vi;
471 472 if( typed_args[i] is null )
472 473 throw genex!RuntimeException(pos,
473 - sprintf!"type mismatch on the argument %d of native function: %s"(i+1,name));
474 + sprintf!"type mismatch on the argument %d of native function %s. %s required but %s passed."(i+1,name,typeid(Ti),vi));
474 475 }
475 476 try {
476 477 return dg(typed_args);
477 478 } catch( RuntimeException e ) {
478 479 throw e.pos is null ? new RuntimeException(pos, e.msg, e.file, e.line) : e;
479 480 }
480 481 }
................................................................................
481 482 }
482 483 theContext.set(name, defLay, new NativeFunValue(dg));
483 484 }
484 485 }
485 486
486 487 version(unittest)
487 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 501 unittest
490 502 {
491 503 auto e = new Evaluator;
492 504 enrollRuntimeLibrary(e);
493 505 auto r = assert_nothrow( e.evalString(`var x = 21; x + x*x;`) );
494 506 assert_eq( r, new IntValue(BigInt(21+21*21)) );