public class VM
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
java.util.ArrayList<java.lang.String> |
arguments
An array of command line arguments.
|
org.rigwit.stack.Stack |
call
The Forth return stack.
|
static int |
CELL
The size of a cell in the memory store.
|
static int |
CHAR
The size of a character in the memory store.
|
TypedStack |
data
The Forth Data (Parameter) Stack.
|
Dictionary |
dictionary
A Forth System consists of a collection of words, which are
collected together into a word list.
|
static int |
FALSE
The Forth FALSE value.
|
Kernel |
kernel
The inner interpreter for this Virtual Machine.
|
XT |
lastXT
A reference to the most recent user definition.
|
Memory |
memory
The user memory space.
|
ForthReader |
reader
The input stream reader.
|
static int |
TRUE
The Forth TRUE value.
|
java.util.ArrayList<WordList> |
wordlists
A list of every word list, named or anonymous, in the order
they are defined.
|
ForthWriter |
writer
The output stream writer.
|
Constructor and Description |
---|
VM()
Construct the basic forth environment.
|
Modifier and Type | Method and Description |
---|---|
XT |
create()
Parses the name from the input stream and create a new user
definition XT adding it to the current word list.
|
java.lang.String |
createName()
Parses the name from the input stream and create a new user
definition XT, but does not add the definition to the current
word list.
|
void |
dumpForthStacks()
Report the contents of the forth data and return stacks to
the output stream as part of an error report.
|
void |
dumpJavaStack(java.lang.Throwable ex,
int max)
Report the Java call stack to the output stream as part of
an error report.
|
void |
echoOff()
Disable the input echo.
|
void |
echoOn()
Enable input echo.
|
void |
execute(XT xt,
java.lang.String name)
Execute an XT and recover from any error it may report.
|
boolean |
getEcho()
Return the current setting of the echo flag.
|
void |
interpret()
Main text interpreter loop.
|
boolean |
interpreting()
Return true if the system is interpreting and false if
it is compiling.
|
int |
nextChar()
Read the next character from the input stream.
|
java.lang.String |
parse(char delim)
Parse text from the input stream until a delimiter
character is reached, or the end of the buffer.
|
java.lang.String |
parseName()
Read the name of a Forth word from the current input stream.
|
java.lang.Number |
parseNumber(java.lang.String text)
Parse a string and attempt to convert it into a number.
|
java.lang.String |
readableStackItem(java.lang.Object item)
Return a stack item as a human readable string.
|
void |
reportThrowCode(ForthException ex)
Generate an error report, sending it to the current output
stream.
|
void |
reset()
Reset the virtual machine after an error.
|
public static final int CELL
public static final int CHAR
public static final int FALSE
public static final int TRUE
public Dictionary dictionary
public java.util.ArrayList<WordList> wordlists
public java.util.ArrayList<java.lang.String> arguments
public Kernel kernel
public org.rigwit.stack.Stack call
public TypedStack data
public Memory memory
public ForthReader reader
reader
must provide a concrete implement the
ForthReader
abstract class. A number of
Forth Readers have been defined:
ForthStreamReader
ForthStringReader
EVALUATE
word.ForthStandardReader
ForthTerminalReader
public ForthWriter writer
ForthWriter
.
It keeps track of newlines, so that the output can be
formatted in a more user friendly manner.public XT lastXT
public void reset() throws java.io.IOException
java.io.IOException
public void echoOn()
public void echoOff()
public boolean getEcho()
public int nextChar() throws java.io.IOException
echo
flag is true. If the character is the end of
a line, the current line number is output. If the input
stream has been exhausted, a -1 is returned.java.io.IOException
- when there is a problem reading the input stream.public java.lang.String parse(char delim) throws java.io.IOException
delim
- the delimiting character at which to stop reading.java.io.IOException
- when there has been a problem reading from
the input stream.public java.lang.String parseName() throws java.io.IOException
java.io.IOException
- when there has been a problem reading from
the input stream.public java.lang.Number parseNumber(java.lang.String text) throws java.io.IOException
%
Binary#
Decimal$
Hexadecimal'
a character literaltext
- the string to be parsed.null
if the text could not be parsed as a number.java.io.IOException
public boolean interpreting()
public void interpret() throws java.io.IOException, ForthException
java.io.IOException
- should there be a problem reading the input buffer.ForthException
- should there be a problem interpreting the Forth
source code.public void execute(XT xt, java.lang.String name) throws java.io.IOException
xt
- the XT to be executedname
- the name of the Forth word for the XTjava.io.IOException
public void reportThrowCode(ForthException ex)
ex
- the ForthException to report on.public java.lang.String readableStackItem(java.lang.Object item)
item
- the item to be rendered readable.public void dumpForthStacks()
public void dumpJavaStack(java.lang.Throwable ex, int max)
ex
- the exception that caused the error.max
- the maximum number of exceptions to be shown.public java.lang.String createName() throws ForthException, java.io.IOException, java.lang.NoSuchMethodException
lastXT
is updated to refer to this definition.ForthException
- if the name is either too long or too shortjava.io.IOException
- if there is an error reading the input streamjava.lang.NoSuchMethodException
- should the definition
method be missing
from the kernel
objectpublic XT create() throws ForthException, java.io.IOException, java.lang.NoSuchMethodException
variable
,
(Kernel.variableDef()
).
This can be overridden by setting a new handler in XT returned
by the method.
The replacement handler must be of the form:
xxxDef
and must process the address of the
next cell after the definition on the top of the stack.
The lastXT
is updated to refer to this definition.ForthException
- if the name is either too long or too shortjava.io.IOException
- if there is an error reading the input streamjava.lang.NoSuchMethodException
- should the definition
or variableDef
methods be missing from the kernel
object