next up previous
Next: Implementing VCODE vector operations Up: Implementing VCODE in Java Previous: Implementing VCODE in Java

Emulating the VCODE vector stack

The basic VCODE data structure is a vector of a primitive type. We represent this by a Java array: a first-class object with a length attribute. Java also supplies a vector class, java.util.Vector, which is essentially a dynamically-sized array capable of storing heterogeneous types. However, because VCODE vectors are both homogeneous and of a fixed length once created, there is no need for the extra generality and overhead of the Vector class. The VCODE types are mapped to Java types as shown in Table 1.  

VCODE Java Bits
INT int 32 
FLOAT double 64 
BOOL boolean
CHAR char 16 
Table 1: Mapping of VCODE types to their Java equivalents.

The VCODE interpreter allocates space for vectors when they are created, and uses reference counting to reclaim the space when they are no longer used. In Java, we create arrays corresponding to VCODE vectors with the new() method, and rely on them being reclaimed by the Java garbage collector when they are no longer used.

VCODE operations receive all their arguments, and return all their results, via the vector stack. In a typical implementation, the stack contains pointers to vectors rather than the vectors themselves. This approach permits fast stack operations (especially when popping, copying, or moving more than one element) and enables multiple copies of the same vector to be represented by identical pointers to the same piece of data. In Java, we achieve the same effect by storing references to arrays in an instance of the standard Java stack class, java.util.Stack.


next up previous
Next: Implementing VCODE vector operations Up: Implementing VCODE in Java Previous: Implementing VCODE in Java

Jonathan Hardwick