| 625 | */ |
| 626 | |
| 627 | public Object eval( |
| 628 | Reader in, NameSpace nameSpace, String sourceFileInfo |
| 629 | /*, CallStack callstack */ ) |
| 630 | throws EvalError |
| 631 | { |
| 632 | Object retVal = null; |
| 633 | if ( Interpreter.DEBUG ) debug("eval: nameSpace = "+nameSpace); |
| 634 | |
| 635 | /* |
| 636 | Create non-interactive local interpreter for this namespace |
| 637 | with source from the input stream and out/err same as |
| 638 | this interpreter. |
| 639 | */ |
| 640 | Interpreter localInterpreter = |
| 641 | new Interpreter( |
| 642 | in, out, err, false, nameSpace, this, sourceFileInfo ); |
| 643 | |
| 644 | CallStack callstack = new CallStack( nameSpace ); |
| 645 | |
| 646 | SimpleNode node = null; |
| 647 | boolean eof = false; |
| 648 | while(!eof) |
| 649 | { |
| 650 | try |
| 651 | { |
| 652 | eof = localInterpreter.Line(); |
| 653 | if (localInterpreter.get_jjtree().nodeArity() > 0) |
| 654 | { |
| 655 | if( node != null ) |
| 656 | node.lastToken.next = null; // prevent OutOfMemoryError |
| 657 | |
| 658 | node = (SimpleNode)localInterpreter.get_jjtree().rootNode(); |
| 659 | // quick filter for when we're running as a compiler only |
| 660 | if ( getSaveClasses() |
| 661 | && !(node instanceof BSHClassDeclaration) |
| 662 | && !(node instanceof BSHImportDeclaration ) |
| 663 | && !(node instanceof BSHPackageDeclaration ) |
| 664 | ) |
| 665 | continue; |
| 666 | |
| 667 | // nodes remember from where they were sourced |
| 668 | node.setSourceFile( sourceFileInfo ); |
| 669 | |
| 670 | if ( TRACE ) |
| 671 | println( "// " +node.getText() ); |
| 672 | |
| 673 | retVal = node.eval( callstack, localInterpreter ); |
| 674 | |
| 675 | // sanity check during development |
| 676 | if ( callstack.depth() > 1 ) |
| 677 | throw new InterpreterError( |
| 678 | "Callstack growing: "+callstack); |
| 679 | |
| 680 | if ( retVal instanceof ReturnControl ) { |
| 681 | retVal = ((ReturnControl)retVal).value; |
| 682 | break; // non-interactive, return control now |
| 683 | } |
| 684 | |