public interface ExtendedInterpreter extends Interpreter
Modifier and Type | Method and Description |
---|---|
void |
disableHook()
Temporarily disable the hooks.
|
void |
enableHook()
Enable the hook calls.
|
void |
execute(Command startCommand)
Execute the program starting at the command
startCommand |
Configuration |
getConfiguration() |
Command |
getCurrentCommand()
Get the command that is currently executing.
|
Writer |
getErrorWriter()
|
InterpreterHook |
getHook()
Get the hook object the interpreter has.
|
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. |
Map<String,Object> |
getMap()
Since the Command objects should not contain runtime information there is
a need sometime to store information that is runtime.
|
BuildableProgram |
getProgram() |
Reader |
getReader()
|
RightValue |
getReturnValue()
Get the return value that was set by the execution of the subroutine.
|
CommandSub |
getSubroutine(String name)
Get a subroutine by its name.
|
Map<String,Class<?>> |
getUseMap()
Programs can access Java static methods from different packages.
|
HierarchicalVariableMap |
getVariables()
Get the global variables of the program.
|
Writer |
getWriter()
|
Command |
pop()
Pop the command from the top of the stack and also drop the last local
variables frame.
|
void |
push()
Same as
push(Command) and pushes the currently executing command
on the stack. |
void |
push(Command command)
Push a command to the stack.
|
void |
registerJavaMethod(String alias,
Class<?> klass,
String methodName,
Class<?>[] argumentTypes)
Register a BASIC function as Java method.
|
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 |
setReturnValue(RightValue returnValue)
Register the return value.
|
call, execute, getVariable, registerFunctions, registerHook, setErrorWriter, setProgram, setReader, setVariable, setWriter
setFactory
Configuration getConfiguration()
BuildableProgram getProgram()
void execute(Command startCommand) throws ExecutionException
startCommand
ExecutionException
CommandSub getSubroutine(String name)
name
- the name of the subroutinevoid setReturnValue(RightValue returnValue)
returnValue
- the value that the subroutine will returnRightValue getReturnValue()
void push(Command command)
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.
command
- the command from which a subroutine call was executed.void push()
push(Command)
and pushes the currently executing command
on the stack.Command pop()
void setNextCommand(Command nextCommand)
nextCommand
- is the next command to execute after the current commandCommand getCurrentCommand()
HierarchicalVariableMap getVariables()
Map<String,Object> getMap()
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.
Map<String,Class<?>> getUseMap()
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
.void registerJavaMethod(String alias, Class<?> klass, String methodName, Class<?>[] argumentTypes) throws BasicRuntimeException
use class from package as basicClassReferencefor example
use Math from java.lang as mwhen the method
sin
is used, foe example
a = m.sin(1.0)the BASIC interpreter has to find the method
java.lang.Math.sin(Double x)
. The problem is that the method does
not exist because the argument is not Double
but rather
double
.
To help with this situation the BASIC program should declare the Java signature of the method using the BASIC command METHOD. For example:
method sin from java.lang.Math is (double) use as sinus(Note that the part
use as ...
is optional.)
After this command is executed the interpreter will use the defined signature to locate the method. You can write in the BASIC program
a = m.sinus(1.0)
registerJavaMethod()
registers the basic function alias, class,
java method name and the argument types so that later call to getJavaMethod(Class, String)
can find the appropriate method.klass
- methodName
- argumentTypes
- BasicRuntimeException
Method getJavaMethod(Class<?> klass, String methodName) throws ExecutionException
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
klass
- mehodName
- ExecutionException
Reader getReader()
Writer getWriter()
Writer getErrorWriter()
void disableHook()
enableHook()
is called.
Hook disabling was designed with the special case in mind when a hook
wants to alter the return value returned from a subroutine. To do so the
hook method has to invoke the setReturnValue(RightValue)
method, which was
actually calling the hook. To avoid the infinite loop and not to confuse
the other hook methods that are in the list sooner the hook method InterpreterHook.setReturnValue(RightValue)
should first disable the hook
mechanism, call back to the interpreter object and the enable the hook
mechanism again.
void enableHook()
disableHook()
to enable again the calling mechanism.InterpreterHook getHook()
Copyright © 2013 Verhas and Verhas Software Craftsmen. All Rights Reserved.