NaBytecode

Stores bytecode

Constructors

this
this(NaInstTable instructionTable)

constructor

Destructor

~this
~this()
Undocumented in source.

Members

Functions

append
bool append(Statement statement, string error)
bool append(Statement statement)
bool append(string statementStr, string error)
bool append(string statementStr)

Adds a statement at end of existing bytecode

argSize
uinteger argSize(uinteger argIndex)
clear
void clear()

Discards any existing bytecode

load
string[] load(Statement[] statements)
string[] load(string[] statementStrings)

Loads bytecode. Discards any existing bytecode

resolveArgs
bool resolveArgs()

Changes labels to label indexes, and resolves addresses, in arguments

verify
bool verify(string error)
bool verify()

Verifies a loaded bytecode, to make sure only valid instructions exist, and correct number of arguments and types are loaded No more statements should be added after this has been called

Properties

instArgTypes
NaInstArgType[] instArgTypes [@property getter]
instArgs
NaData[] instArgs [@property getter]
instCodes
ushort[] instCodes [@property getter]
instPtrs
void delegate()[] instPtrs [@property getter]
labelIndexes
uinteger[2][] labelIndexes [@property getter]
labelNames
string[] labelNames [@property getter]

Examples

string[] source = [
	"start: instA l2",
	"	instB 50 50.5",
	"	instC \"hello\" false",
	"l2: instd 'c' start"
];
NaInstTable iTable = new NaInstTable();
NaInst inst = NaInst("insta",[NaInstArgType.Label]);
iTable.addInstruction(inst);
inst = NaInst("instb", [NaInstArgType.Integer, NaInstArgType.Double]);
iTable.addInstruction(inst);
inst = NaInst("instc", [NaInstArgType.String, NaInstArgType.Boolean]);
iTable.addInstruction(inst);
inst = NaInst("instd", [NaInstArgType.Char, NaInstArgType.Label]);
iTable.addInstruction(inst);
NaBytecode bcode = new NaBytecode(iTable);
bcode.load(source);
assert(bcode.labelNames == ["start", "l2"]);
assert(bcode.labelIndexes == [[0, 0], [3, 5]]);
assert(bcode.instArgTypes == [NaInstArgType.Label, NaInstArgType.Integer, NaInstArgType.Double, NaInstArgType.String,
	NaInstArgType.Boolean, NaInstArgType.Char, NaInstArgType.Label]);
assert(bcode.verify == true);
.destroy(iTable);
.destroy(bcode);

Meta