constructor
Reads binary bytecode. Any existing bytecode is clear()ed
Prepares binary bytecode. **call .verify() before this**
the ByteStream storing bytecode. Be aware that this will be destroyed when NaBytecodeBinary is destroyed
postfix for magic number
postfix for magic number If the newVal is too long, the first bytes are used. If too short, 0x00 is used to fill
the metadata stored alongside
Changes labels to label indexes, and resolves addresses, in arguments
Discards any existing bytecode
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
Adds a statement at end of existing bytecode
Loads bytecode. Discards any existing bytecode
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);
same as NaBytecode, but also works with binary bytecode (see spec/binarybytecode.md)