| 56 | } |
| 57 | |
| 58 | pub fn read_opcode(&mut self) -> DecodeResult<Opcode> { |
| 59 | let next = match self.read_u8() { |
| 60 | Ok(next) => next, |
| 61 | Err(err) => match err { |
| 62 | DecodeError::EndOfStream => { |
| 63 | return Err(DecodeError::EndOfStream); |
| 64 | } |
| 65 | DecodeError::InsufficientData => { |
| 66 | return Err(DecodeError::EndOfStream); |
| 67 | } |
| 68 | DecodeError::UnknownOpcode(x) => { |
| 69 | return Err(DecodeError::UnknownOpcode(x)); |
| 70 | } |
| 71 | }, |
| 72 | }; |
| 73 | match next { |
| 74 | haxby_opcodes::OPCODE_NOP => Ok(Opcode::Nop), |
| 75 | haxby_opcodes::OPCODE_PUSH => self |
| 76 | .read_u16() |
| 77 | .map_or(Err(DecodeError::InsufficientData), |b| Ok(Opcode::Push(b))), |
| 78 | haxby_opcodes::OPCODE_PUSH_0 => Ok(Opcode::Push0), |
| 79 | haxby_opcodes::OPCODE_PUSH_1 => Ok(Opcode::Push1), |
| 80 | haxby_opcodes::OPCODE_PUSH_TRUE => Ok(Opcode::PushTrue), |
| 81 | haxby_opcodes::OPCODE_PUSH_FALSE => Ok(Opcode::PushFalse), |
| 82 | haxby_opcodes::OPCODE_PUSH_BUILTIN_TYPE => self |
| 83 | .read_u8() |
| 84 | .map_or(Err(DecodeError::InsufficientData), |b| { |
| 85 | Ok(Opcode::PushBuiltinTy(b)) |
| 86 | }), |
| 87 | haxby_opcodes::OPCODE_PUSH_RUNTIME_VALUE => self |
| 88 | .read_u8() |
| 89 | .map_or(Err(DecodeError::InsufficientData), |b| { |
| 90 | Ok(Opcode::PushRuntimeValue(b)) |
| 91 | }), |
| 92 | haxby_opcodes::OPCODE_POP => Ok(Opcode::Pop), |
| 93 | haxby_opcodes::OPCODE_DUP => Ok(Opcode::Dup), |
| 94 | haxby_opcodes::OPCODE_SWAP => Ok(Opcode::Swap), |
| 95 | haxby_opcodes::OPCODE_COPY => self |
| 96 | .read_u8() |
| 97 | .map_or(Err(DecodeError::InsufficientData), |b| Ok(Opcode::Copy(b))), |
| 98 | haxby_opcodes::OPCODE_ADD => Ok(Opcode::Add), |
| 99 | haxby_opcodes::OPCODE_SUB => Ok(Opcode::Sub), |
| 100 | haxby_opcodes::OPCODE_MUL => Ok(Opcode::Mul), |
| 101 | haxby_opcodes::OPCODE_DIV => Ok(Opcode::Div), |
| 102 | haxby_opcodes::OPCODE_REM => Ok(Opcode::Rem), |
| 103 | haxby_opcodes::OPCODE_EQ => Ok(Opcode::Equal), |
| 104 | haxby_opcodes::OPCODE_GT => Ok(Opcode::GreaterThan), |
| 105 | haxby_opcodes::OPCODE_LT => Ok(Opcode::LessThan), |
| 106 | haxby_opcodes::OPCODE_GTE => Ok(Opcode::GreaterThanEqual), |
| 107 | haxby_opcodes::OPCODE_LTE => Ok(Opcode::LessThanEqual), |
| 108 | haxby_opcodes::OPCODE_NEG => Ok(Opcode::Neg), |
| 109 | haxby_opcodes::OPCODE_SHL => Ok(Opcode::ShiftLeft), |
| 110 | haxby_opcodes::OPCODE_SHR => Ok(Opcode::ShiftRight), |
| 111 | haxby_opcodes::OPCODE_NOT => Ok(Opcode::Not), |
| 112 | haxby_opcodes::OPCODE_READ_LOCAL => self |
| 113 | .read_u8() |
| 114 | .map_or(Err(DecodeError::InsufficientData), |b| { |
| 115 | Ok(Opcode::ReadLocal(b)) |