Interface InternalInterpreter

All Known Subinterfaces:
Interpreter
All Known Implementing Classes:
BasicInterpreter

public interface InternalInterpreter
An interpreter instance executes a program.
Author:
Peter Verhas
  • Method Summary

    Modifier and Type
    Method
    Description
    getJavaMethod(Class<?> klass, String methodName)
    Get the method named from the klass based on the declaration given in a previously executed METHOD basic command.
    Since the Command objects should not contain runtime information there is a need sometime to store information that is runtime.
     
    Programs can access Java static methods from different packages.
    pop()
    Pop the command from the top of the stack and also drop the last local variables frame.
    void
    Same as push(Command) and pushes the currently executing command on the stack.
    void
    push(Command command)
    Push a command to the stack.
    void
    setNextCommand(Command nextCommand)
    Tell the interpreter that the next command to call is not the one that follows the actual command but rather the one specified by the argument.
    void
    setProgram(BuildableProgram buildableProgram)
    Set the program to execute.
  • Method Details

    • getProgram

      BuildableProgram getProgram()
      Returns:
      the program that the interpreter is executing.
    • setProgram

      void setProgram(BuildableProgram buildableProgram)
      Set the program to execute.
      Parameters:
      buildableProgram - parameter
    • push

      void push(Command command)
      Push a command to the stack. This is called before a subroutine call is executed. Even though the actual stack is NOT maintained here but rather in the JVM call stack, since function call is implemented using recursive calls to the interpreter the call to this push and pop is vital to keep track the stack trace for debugging purposes and to have a mean to limit the stack size.

      Calling this method also starts a new local variable frame, thus evaluation of the actual argument values in a function call has to be executed before calling this method.

      Parameters:
      command - the command from which a subroutine call was executed.
    • push

      void push()
      Same as push(Command) and pushes the currently executing command on the stack.
    • pop

      Command pop()
      Pop the command from the top of the stack and also drop the last local variables frame.
      Returns:
      the value
    • setNextCommand

      void setNextCommand(Command nextCommand)
      Tell the interpreter that the next command to call is not the one that follows the actual command but rather the one specified by the argument.
      Parameters:
      nextCommand - is the next command to execute after the current command
    • getMap

      Map<String,Object> getMap()
      Since the Command objects should not contain runtime information there is a need sometime to store information that is runtime. This method returns a map that is unique to the currently executing Command and is also unique to the Interpreter. Thus if two interpreters simultaneously execute the same command they will return two different maps.

      The interpreter initializes the map when the command asks for it the first time. The life time of the map is the same as the life time of the interpreter. Thus when a program finishes the map is still available to the command when the Interface 'call' method is called or the interpreter is restarted.

      The interpreter does not alter the map in any other way than initializing it to some map implementation containing initially no element.

      Returns:
      the map
    • getUseMap

      Map<String,Class<?>> getUseMap()
      Programs can access Java static methods from different packages. To do that the programs have to recognize when the call 'out' to Java instead of looking for an internal function implemented in the program. For example the BASIC program has to declare the use of these packages using the command USE. For example
       use Math from java.lang as m
       
      (the part following the keyword 'as' is optional, in which case the Java name of the class is used). After this statement is executed the use map will contain the class javal.lang.Math for the key m.
      Returns:
      the use map itself.
    • getJavaMethod

      Method getJavaMethod(Class<?> klass, String methodName)
      Get the method named from the klass based on the declaration given in a previously executed METHOD basic command. The basic command METHOD has the form (example follows):
       method sin from java.lang.Math is (double)
       
      that defines that the method sin is in the class java.lang.Math and accepts one argument, which is double
      Parameters:
      klass - parameter
      methodName - parameter
      Returns:
      return value