7 code.push_back(instruction);
11 constants.push_back(constant);
12 return constants.size() - 1;
16 std::cout <<
"== " << name <<
" ==" << std::endl;
17 for (
unsigned index = 0; index < code.size();) {
18 index = DisassembleInstruction(index);
28 uint16_t jump = ((uint16_t)jumpa) << 8;
31 std::cout << name <<
" " << index <<
" " << (index + 3 + sign * jump) << std::endl;
36 std::cout << name <<
" " << (unsigned)constant <<
" ";
43 std::cout << name <<
" " << (unsigned)slot << std::endl;
49 uint8_t instruction = code[index];
50 switch (instruction) {
82 return jumpInstruction(
"OP_LOOP", -1, index, code[index+1], code[index+2]);
84 return jumpInstruction(
"OP_JUMP", 1, index, code[index+1], code[index+2]);
86 return jumpInstruction(
"OP_JUMP_IF_FALSE", 1, index, code[index+1], code[index+2]);
88 return constantInstruction(
"OP_GET_PROPERTY", index, code[index+1], constants[code[index+1]]);
98 return constantInstruction(
"OP_DEFINE_GLOBAL", index, code[index+1], constants[code[index+1]]);
100 return constantInstruction(
"OP_GET_GLOBAL", index, code[index+1], constants[code[index+1]]);
102 return constantInstruction(
"OP_SET_GLOBAL", index, code[index+1], constants[code[index+1]]);
110 std::cout <<
"Unknown Instruction: " << instruction << std::endl;
unsigned jumpInstruction(const char *name, int sign, unsigned index, uint8_t jumpa, uint8_t jumpb)
unsigned simpleInstruction(const char *name, unsigned index)
unsigned constantInstruction(const char *name, unsigned index, uint8_t constant, const uscript::Value &value)
void Write(uint8_t instruction)
std::vector< uint8_t > code
unsigned AddConstant(Value constant)
void Disassemble(const std::string &name) const
unsigned DisassembleInstruction(unsigned index) const
BEGIN_PROLOG could also be cout
unsigned byteInstruction(const char *name, unsigned index, uint8_t slot)