public class Memory
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
addrBase
The location of the
BASE special variable. |
static int |
addrIn
The location of the
>IN special variable. |
static int |
addrState
The location of the
STATE special variable. |
int |
here
The location of the next free location within the data space.
|
Constructor and Description |
---|
Memory(VM machine,
int size)
Initialise the data space for the current virtual machine.
|
Modifier and Type | Method and Description |
---|---|
int |
addCell(java.lang.Object cell)
Add a cell to the data space.
|
int |
addChar(int ch)
Add a character at the data space.
|
int |
addString(java.lang.String text)
Place a counted string in memory and return its address.
|
static int |
align(int value)
Return the next cell aligned value for a given value.
|
void |
allot(int count)
Add/Remove a given number of bytes to the memory.
|
int |
getBase()
Return the current input/output base value.
|
int |
getBufferedInput(int addr)
Read a character from a given location within the input
buffer.
|
java.lang.Object |
getCell(int addr)
Return the Cell at the given address within the memory.
|
int |
getChar(int addr)
Read a character from a given address in the memory.
|
int |
getInputPosition()
Return the current position in the input buffer, converted into
an address.
|
int |
getState()
Return the current value of the state variable.
|
java.lang.String |
getString(int addr)
Read a counted string from the given address, returning a
String.
|
java.lang.String |
getString(int addr,
int count)
Read a string of count characters from memory starting
at the given address.
|
void |
setBase(int n)
Change the base of the input/output.
|
void |
setCell(int addr,
java.lang.Object item)
Set an cell aligned location in the memory to a given item.
|
void |
setChar(int addr,
int ch)
Set the character at the character aligned address in memory
to the character given.
|
void |
setState(int state)
Change the state of the compiler, to interpreting (zero) or
compiling (non-zero).
|
int |
size()
Return the number of cells in the memory.
|
public int here
public static final int addrIn
>IN
special variable.public static final int addrState
STATE
special variable.public static final int addrBase
BASE
special variable.public Memory(VM machine, int size)
machine
- the current virtual machine.size
- the initial size of the memory.public int size()
public void setBase(int n)
n
- the new base value.public int getBase()
public int getState()
public void setState(int state)
state
- the value to place in the state variable.public static int align(int value)
value
- the value to be alignedpublic void allot(int count)
count
- the number of bytes to add/remove from memory.public int addCell(java.lang.Object cell)
cell
- The Cell (Object Reference) to add into the global
data store.public java.lang.Object getCell(int addr) throws ForthException
addr
- the address of the cell in the memory.ForthException
- if the address is not cell aligned, or
is outside the memory range.public void setCell(int addr, java.lang.Object item) throws ForthException
addr
- the address in the memory to place the item.item
- the item to be placed in memory.ForthException
- if the address is not aligned.public int addChar(int ch)
ch
- The character to place into memory.public int getChar(int addr) throws ForthException
hashCode
for the object is split.addr
- the address in memory to locate the character.ForthException
- if the address is not Character aligned.public void setChar(int addr, int ch) throws ForthException
addr
- the address in memory to place the character.ch
- the character to be placed into memory.ForthException
- if an attempt is made to write to the read only
area (including the input buffer);
the address is not character aligned;
the item at the address can not be split.public java.lang.String getString(int addr)
addr
- the location in memory to read the counted string
from.public java.lang.String getString(int addr, int count)
addr
- the address in memory to find the character
stringcount
- the number of characters in the stringpublic int addString(java.lang.String text)
text
- the string to be placed into the virtual memory.public int getInputPosition()
public int getBufferedInput(int addr) throws ForthException
addr
- the location to read the character from.ForthException
- if the location is outside of the input buffer.