org.hecl
Class Interp
- java.lang.Object
-
- java.lang.Thread
-
- org.hecl.Interp
-
- All Implemented Interfaces:
- java.lang.Runnable
public class Interp extends java.lang.ThreadInterpis the Hecl interpreter, the class responsible for knowing what variables and commands are available.
-
-
Field Summary
Fields Modifier and Type Field and Description static intALL_EVENTSstatic java.lang.StringASYNCPREFIXSome string constants used to generate names for internal events.longcacheversionThingcurrentFilestatic intDONT_WAITFlags for the event loop.static char[]eoleolis the end-of-line character or characters.static java.lang.Stringfileseparatorfileseparatoris the file separator, such as "/".static intIDLE_EVENTSstatic java.lang.StringIDLEPREFIXstatic java.lang.StringMODULE_CLASS_PACKAGEPackage name prefix of the module classes.java.lang.StringPROMPTThe prompt for thereadEvalPrintloop.java.lang.StringPROMPT2The prompt for continued lines in thereadEvalPrintloop.static intTIMER_EVENTSstatic java.lang.StringTIMERPREFIX
-
Constructor Summary
Constructors Constructor and Description Interp()Creates a newInterpinstance, initializing command and variable hashtables, a stack, and an error stack.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddClassCmd(java.lang.Class clazz, ClassCommand cmd)Add a new class command to anInterp.java.lang.StringaddCommand(java.lang.String name, Command c)Add a new command to anInterp.voidaddError(Thing err)addErroradds a Thing as an error message.HeclTaskaddTimer(Thing timerThing, int millisecs)voidbackgroundError(java.lang.String errorMessage)ThebackgroundErrormethod can be called to dispatch a bgerror command.voidcancelAsync(java.lang.String name)voidcancelIdle(HeclTask idletask)voidcancelIdle(java.lang.String name)voidcancelTimer(java.lang.String name)static voidcheckArgCount(Thing[] argv, int minargs, int maxargs)checkArgCountchecks to see whether the command actually has the required number of arguments.voidclearError()clearErrorclears the error stack.voidcmdAlias(java.lang.String oldname, java.lang.String newname)voidcmdRename(java.lang.String oldname, java.lang.String newname)ThecmdRenamemethod renames a command, or throws an error if the original command didn't exist.booleancommandExists(java.lang.String name)ThecommandExistsmethod returns true if a command exists, otherwise false.booleandoOneEvent(int flags)Thingeval(Thing in)Theevalmethod evaluates some Hecl code passed to it.Thingeval(Thing in, int level)This version ofevaltakes a 'level' argument that tells Hecl what level to run the code at.HeclTaskevalAsync(Thing asyncThing)ThingevalAsyncAndWait(Thing in)HeclTaskevalIdle(Thing idleThing)booleanexistsVar(java.lang.String varname)existsVarreturnstrueif the given variable exists in the current variable stack frame,falseif it does not.booleanexistsVar(java.lang.String varname, int level)existsVarreturnstrueif the given variable exists in the variable stack frame given bylevel,falseif it does not.booleanexistsVar(Thing varname)existsVarreturnstrueif the given variable exists in the current variable stack frame,falseif it does not.java.util.VectorgetAllEvents()java.lang.ObjectgetAuxData(java.lang.String key)Retrieve auxiliary data from anInterp.HeclTaskgetEvent(java.lang.String name)ThinggetVar(java.lang.String varname)getVarreturns the value of a variable given its name.ThinggetVar(java.lang.String varname, int level)getVarreturns the value of a variable given its name and level.ThinggetVar(Thing varname)getVarreturns the value of a variable given its name.booleanhasIdleTasks()voidnotifyToken(java.lang.String tokenname)voidremoveAuxData(java.lang.String key)Remove auxiliary data from anInterp.voidremoveClassCmd(java.lang.Class clazz)Remove a command for a specific class from anInterp.voidremoveCommand(java.lang.String name)Remove a command from anInterp.voidrun()voidsetAuxData(java.lang.String key, java.lang.Object value)Attach auxiliary data to anInterp.voidsetVar(java.lang.String varname, Thing value)setVarsets a variable in the innermost variable stack frame to a value.voidsetVar(java.lang.String varname, Thing value, int level)setVarsets a variable to a value in the variable stack frame specified bylevel.voidsetVar(Thing varname, Thing value)setVarsets a variable in the innermost variable stack frame to a value.java.util.HashtablestackDecr()stackDecrpops the stack frame, returning it so that commands like upeval can save it.voidstackIncr()ThestackIncrmethod creates a new stack frame.voidstackPush(java.util.Hashtable vars)stackDecrpushes a new variable hashtable (probably saved via upeval) onto the stack frame.voidterminate()Theterminatemethod terminates the Hecl interpreter thread in a graceful manner.voidunSetVar(java.lang.String varname)voidunSetVar(java.lang.String varname, int level)voidunSetVar(Thing varname)unSetVarunsets a variable in the current stack frame.voidwaitForToken(java.lang.String tokenname)-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
MODULE_CLASS_PACKAGE
public static final java.lang.String MODULE_CLASS_PACKAGE
Package name prefix of the module classes.- See Also:
- Constant Field Values
-
DONT_WAIT
public static final int DONT_WAIT
Flags for the event loop.- See Also:
- Constant Field Values
-
IDLE_EVENTS
public static final int IDLE_EVENTS
- See Also:
- Constant Field Values
-
TIMER_EVENTS
public static final int TIMER_EVENTS
- See Also:
- Constant Field Values
-
ALL_EVENTS
public static final int ALL_EVENTS
- See Also:
- Constant Field Values
-
ASYNCPREFIX
public static final java.lang.String ASYNCPREFIX
Some string constants used to generate names for internal events.- See Also:
- Constant Field Values
-
IDLEPREFIX
public static final java.lang.String IDLEPREFIX
- See Also:
- Constant Field Values
-
TIMERPREFIX
public static final java.lang.String TIMERPREFIX
- See Also:
- Constant Field Values
-
PROMPT
public final java.lang.String PROMPT
The prompt for thereadEvalPrintloop.- See Also:
- Constant Field Values
-
PROMPT2
public final java.lang.String PROMPT2
The prompt for continued lines in thereadEvalPrintloop.- See Also:
- Constant Field Values
-
cacheversion
public long cacheversion
-
eol
public static final char[] eol
eolis the end-of-line character or characters.
-
fileseparator
public static final java.lang.String fileseparator
fileseparatoris the file separator, such as "/".
-
currentFile
public Thing currentFile
-
-
Constructor Detail
-
Interp
public Interp() throws HeclExceptionCreates a newInterpinstance, initializing command and variable hashtables, a stack, and an error stack.- Throws:
HeclException- if an error occurs
-
-
Method Detail
-
addClassCmd
public void addClassCmd(java.lang.Class clazz, ClassCommand cmd)Add a new class command to anInterp.- Parameters:
clazz- The Java class the command should operate on.cmd- The command to add. When this paramter isnull, an existing command is removed.
-
removeClassCmd
public void removeClassCmd(java.lang.Class clazz)
Remove a command for a specific class from anInterp.- Parameters:
clazz- The class to remove the command for.
-
addCommand
public java.lang.String addCommand(java.lang.String name, Command c)Add a new command to anInterp.- Parameters:
name- the name of the command to add.c- the command to add.
-
removeCommand
public void removeCommand(java.lang.String name)
Remove a command from anInterp.- Parameters:
name- the name of the command to add.
-
commandExists
public boolean commandExists(java.lang.String name)
ThecommandExistsmethod returns true if a command exists, otherwise false.- Parameters:
name- aStringvalue- Returns:
- a
booleanvalue
-
setAuxData
public void setAuxData(java.lang.String key, java.lang.Object value)Attach auxiliary data to anInterp.
-
getAuxData
public java.lang.Object getAuxData(java.lang.String key)
Retrieve auxiliary data from anInterp.- Returns:
- a
Objectvalue ornullwhen no auxiliary data under the given key is attached to the interpreter.
-
removeAuxData
public void removeAuxData(java.lang.String key)
Remove auxiliary data from anInterp.
-
eval
public Thing eval(Thing in) throws HeclException
Theevalmethod evaluates some Hecl code passed to it.- Returns:
- a
Thingvalue - the result of the evaluation. - Throws:
HeclException- if an error occurs.
-
evalAsyncAndWait
public Thing evalAsyncAndWait(Thing in) throws HeclException
- Throws:
HeclException
-
eval
public Thing eval(Thing in, int level) throws HeclException
This version ofevaltakes a 'level' argument that tells Hecl what level to run the code at. Level 0 means global, negative numbers indicate relative levels down from the current stackframe, and positive numbers mean absolute stack frames counting up from 0.- Parameters:
in- aThingvaluelevel- anintvalue- Returns:
- a
Thingvalue - Throws:
HeclException- if an error occurs
-
hasIdleTasks
public boolean hasIdleTasks()
-
getEvent
public HeclTask getEvent(java.lang.String name)
-
getAllEvents
public java.util.Vector getAllEvents()
-
cancelTimer
public void cancelTimer(java.lang.String name)
-
cancelIdle
public void cancelIdle(java.lang.String name)
-
cancelAsync
public void cancelAsync(java.lang.String name)
-
cancelIdle
public void cancelIdle(HeclTask idletask)
-
doOneEvent
public boolean doOneEvent(int flags)
-
waitForToken
public void waitForToken(java.lang.String tokenname) throws HeclException- Throws:
HeclException
-
notifyToken
public void notifyToken(java.lang.String tokenname) throws HeclException- Throws:
HeclException
-
terminate
public void terminate()
Theterminatemethod terminates the Hecl interpreter thread in a graceful manner. The thread will eventually finish its run-method.
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread
-
cmdRename
public void cmdRename(java.lang.String oldname, java.lang.String newname) throws HeclExceptionThecmdRenamemethod renames a command, or throws an error if the original command didn't exist.- Parameters:
oldname- aStringvaluenewname- aStringvalue- Throws:
HeclException- if an error occurs
-
cmdAlias
public void cmdAlias(java.lang.String oldname, java.lang.String newname) throws HeclException- Throws:
HeclException
-
stackIncr
public void stackIncr()
ThestackIncrmethod creates a new stack frame. Used in the Proc class.
-
stackDecr
public java.util.Hashtable stackDecr()
stackDecrpops the stack frame, returning it so that commands like upeval can save it. If it's not saved, it's gone.
-
stackPush
public void stackPush(java.util.Hashtable vars)
stackDecrpushes a new variable hashtable (probably saved via upeval) onto the stack frame.
-
getVar
public Thing getVar(Thing varname) throws HeclException
getVarreturns the value of a variable given its name.- Parameters:
varname- aThingvalue- Returns:
- a
Thingvalue - Throws:
HeclException- if an error occurs
-
getVar
public Thing getVar(java.lang.String varname) throws HeclException
getVarreturns the value of a variable given its name.- Parameters:
varname- aStringvalue- Returns:
- a
Thingvalue - Throws:
HeclException- if an error occurs
-
getVar
public Thing getVar(java.lang.String varname, int level) throws HeclException
getVarreturns the value of a variable given its name and level.- Parameters:
varname- aStringvaluelevel- anintvalue- Returns:
- a
Thingvalue - Throws:
HeclException- if an error occurs
-
setVar
public void setVar(Thing varname, Thing value) throws HeclException
setVarsets a variable in the innermost variable stack frame to a value.- Parameters:
varname- aThingvaluevalue- aThingvalue- Throws:
HeclException
-
setVar
public void setVar(java.lang.String varname, Thing value)setVarsets a variable in the innermost variable stack frame to a value.- Parameters:
varname- aStringvaluevalue- aThingvalue
-
setVar
public void setVar(java.lang.String varname, Thing value, int level)setVarsets a variable to a value in the variable stack frame specified bylevel.- Parameters:
varname- aStringvaluevalue- aThingvaluelevel- anintvalue
-
unSetVar
public void unSetVar(Thing varname) throws HeclException
unSetVarunsets a variable in the current stack frame.- Parameters:
varname- aThingvalue- Throws:
HeclException
-
unSetVar
public void unSetVar(java.lang.String varname) throws HeclException- Throws:
HeclException
-
unSetVar
public void unSetVar(java.lang.String varname, int level) throws HeclException- Throws:
HeclException
-
existsVar
public boolean existsVar(Thing varname) throws HeclException
existsVarreturnstrueif the given variable exists in the current variable stack frame,falseif it does not.- Parameters:
varname- aThingvalue- Returns:
- a
booleanvalue - Throws:
HeclException
-
existsVar
public boolean existsVar(java.lang.String varname)
existsVarreturnstrueif the given variable exists in the current variable stack frame,falseif it does not.- Parameters:
varname- aStringvalue- Returns:
- a
booleanvalue
-
existsVar
public boolean existsVar(java.lang.String varname, int level)existsVarreturnstrueif the given variable exists in the variable stack frame given bylevel,falseif it does not.- Parameters:
varname- aStringvaluelevel- anintvalue- Returns:
- a
booleanvalue
-
addError
public void addError(Thing err)
addErroradds a Thing as an error message.- Parameters:
err- aThingvalue
-
clearError
public void clearError()
clearErrorclears the error stack.
-
checkArgCount
public static void checkArgCount(Thing[] argv, int minargs, int maxargs) throws HeclException
checkArgCountchecks to see whether the command actually has the required number of arguments. The first element of the parameter arrayargvis not counted as argument!- Parameters:
argv- AThing[]parameter array.minargs- The minimal number of arguments or -1 if no check is required.maxargs- The maximal number of arguments or -1 if no check is required.- Throws:
HeclException- if an error occurs
-
backgroundError
public void backgroundError(java.lang.String errorMessage)
ThebackgroundErrormethod can be called to dispatch a bgerror command.- Parameters:
errorMessage- aStringvalue
-
-
DataMelt 3.0 © DataMelt by jWork.ORG