NaBytecodeBinary

same as NaBytecode, but also works with binary bytecode (see spec/binarybytecode.md)

Constructors

this
this(NaInstTable instructionTable, ubyte[] magicNumberPost)

constructor

Destructor

~this
~this()
Undocumented in source.

Members

Functions

readBinCode
bool readBinCode()

Reads binary bytecode. Any existing bytecode is clear()ed

writeBinCode
void writeBinCode()

Prepares binary bytecode. **call .verify() before this**

Properties

binCode
ByteStream binCode [@property getter]

the ByteStream storing bytecode. Be aware that this will be destroyed when NaBytecodeBinary is destroyed

magicNumberPost
ubyte[] magicNumberPost [@property getter]

postfix for magic number

magicNumberPost
ubyte[] magicNumberPost [@property setter]

postfix for magic number If the newVal is too long, the first bytes are used. If too short, 0x00 is used to fill

metadata
ubyte[] metadata [@property getter]
ubyte[] metadata [@property setter]

the metadata stored alongside

Inherited Members

From NaBytecode

argSize
uinteger argSize(uinteger argIndex)
resolveArgs
bool resolveArgs()

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

~this
~this()
Undocumented in source.
instCodes
ushort[] instCodes [@property getter]
instPtrs
void delegate()[] instPtrs [@property getter]
instArgs
NaData[] instArgs [@property getter]
instArgTypes
NaInstArgType[] instArgTypes [@property getter]
labelIndexes
uinteger[2][] labelIndexes [@property getter]
labelNames
string[] labelNames [@property getter]
clear
void clear()

Discards any existing bytecode

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

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

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

Loads bytecode. Discards any existing bytecode

Examples

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);
NaBytecodeBinary binCode = new NaBytecodeBinary(iTable, cast(ubyte[])"test");
bool status = true;
status = status && binCode.append("start: instA end");
status = status && binCode.append("instB 1025 1025.5");
status = status && binCode.append("instc \"tab:\\tnewline:\\n\" true");
status = status && binCode.append("end: instD 'c' start");
assert(status == true); // all those functions returned true

binCode.metadata = cast(ubyte[])"METADATA-metadata-0123456789";
assert(binCode.verify());
binCode.writeBinCode();
binCode.binCode.toFile("tempcode");
binCode.binCode.size = 0;
binCode.metadata = [];
binCode.binCode.fromFile("tempcode");
assert(binCode.readBinCode() == true);
assert(binCode.metadata == cast(ubyte[])"METADATA-metadata-0123456789");
assert(binCode.instCodes == [1,2,3,4]);
assert(binCode.instArgTypes == [NaInstArgType.Label, NaInstArgType.Integer, NaInstArgType.Double,
		NaInstArgType.String, NaInstArgType.Boolean, NaInstArgType.Char, NaInstArgType.Label]);
assert(binCode.instArgs[0].value!integer == binCode.labelNames.indexOf("end"));
assert(binCode.instArgs[1].value!integer == 1025);
assert(binCode.instArgs[2].value!double == 1025.5);
assert(binCode.instArgs[3].value!string == "tab:\tnewline:\n");
assert(binCode.instArgs[4].value!bool == true);
assert(binCode.instArgs[5].value!char == 'c');
assert(binCode.instArgs[6].value!integer == binCode.labelNames.indexOf("start"));
assert(binCode.labelNames == ["start", "end"]);
.destroy(binCode);
.destroy(iTable);

Meta