Class Cells
java.lang.Object
io.github.lukebemish.brainfrick.lang.runtime.Cells
Holds the structure used to store data during a brainfrick method execution. A method will hold a reference to one of
these, as its first non-argument local variable, as well as an integer that points to a location within it as the
second such local variable.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
asInt
(int idx) Gets an integer representation of the object at a given index, to be used during the ':' or ',' operations.void
decr
(int idx, int amount) Decrements the object at the given cell the provided number of times.get
(int idx) Gets the object at a given index in the structure; used during the '.' operation.void
incr
(int idx, int amount) Increments the object at the given cell the provided number of times.boolean
isZero
(int idx) Determines whether the element at a given index is zero-like.void
Replaces the object at a given index in the structure.
-
Constructor Details
-
Cells
public Cells()Creates a new cell structure. Should be called once at the beginning of each method or constructor in compiled brainfrick. Each location in the structure is initialized as null.
-
-
Method Details
-
get
Gets the object at a given index in the structure; used during the '.' operation.- Parameters:
idx
- The index of the element to return. Can be a positive or negative value.- Returns:
- The object at that index of the structure, or null if no element is stored there.
-
set
Replaces the object at a given index in the structure.- Parameters:
idx
- The index of the element to replace. Can be a positive or negative value.obj
- The object to place at that index in the structure, or null to clear that index.
-
asInt
public int asInt(int idx) Gets an integer representation of the object at a given index, to be used during the ':' or ',' operations.- Parameters:
idx
- The index to get an integer representation of.- Returns:
- An integer representation of the element at the given index.
- Throws:
ImproperTypeException
- if the value cannot be unboxed or converted to an int- See Also:
-
isZero
public boolean isZero(int idx) Determines whether the element at a given index is zero-like. Used during the '[' and ']' operations.- Parameters:
idx
- The index of the object to be checked.- Returns:
- true if the object is zero-like, false otherwise.
- See Also:
-
incr
public void incr(int idx, int amount) Increments the object at the given cell the provided number of times. Used during the '+' operation.- Parameters:
idx
- The index of the object to be incremented.amount
- The number of times to increment the object.- Throws:
UnsupportedCellOperationException
- if the object cannot be incremented.- See Also:
-
decr
public void decr(int idx, int amount) Decrements the object at the given cell the provided number of times. Used during the '-' operation.- Parameters:
idx
- The index of the object to be decremented.amount
- The number of times to decrement the object.- Throws:
UnsupportedCellOperationException
- if the object cannot be decremented.- See Also:
-