MCPcopy Create free account
hub / github.com/aiscriptdev/aiscript / disassemble_instruction

Method disassemble_instruction

aiscript-vm/src/chunk.rs:224–375  ·  view source on GitHub ↗
(&self, offset: usize)

Source from the content-addressed store, hash-verified

222 }
223
224 pub fn disassemble_instruction(&self, offset: usize) -> usize {
225 static ONCE_TITLE: Once = Once::new();
226 ONCE_TITLE.call_once(|| {
227 println!("{:4} {:4} {:16} CIndex Constvalue", "IP", "Line", "OPCode",);
228 });
229
230 print!("{:04} ", offset);
231 if offset > 0 && self.lines[offset] == self.lines[offset - 1] {
232 print!(" | ");
233 } else {
234 print!("{:4} ", self.lines[offset]);
235 }
236
237 if let Some(code) = self.code.get(offset) {
238 match *code {
239 OpCode::Return => simple_instruction("RETURN"),
240 OpCode::Constant(c) => self.constant_instruction("CONSTANT", c),
241 OpCode::Add => simple_instruction("ADD"),
242 OpCode::Subtract => simple_instruction("SUBTRACT"),
243 OpCode::Multiply => simple_instruction("MULTIPLY"),
244 OpCode::Divide => simple_instruction("DIVIDE"),
245 OpCode::Modulo => simple_instruction("MODULO"),
246 OpCode::Power => simple_instruction("POWER"),
247 OpCode::Negate => simple_instruction("NEGATE"),
248 OpCode::Nil => simple_instruction("NIL"),
249 OpCode::Bool(b) => simple_instruction(if b { "TRUE" } else { "FALSE" }),
250 OpCode::Not => simple_instruction("NOT"),
251 OpCode::Equal => simple_instruction("EQUAL"),
252 OpCode::EqualInplace => simple_instruction("EQUAL_INPLACE"),
253 OpCode::NotEqual => simple_instruction("NOT_EQUAL"),
254 OpCode::Greater => simple_instruction("GREATER"),
255 OpCode::GreaterEqual => simple_instruction("GREATER_EQUAL"),
256 OpCode::Less => simple_instruction("LESS"),
257 OpCode::LessEqual => simple_instruction("LESS_EQUAL"),
258 OpCode::BuildString(c) => self.constant_instruction("BUILD_STRING", c),
259 OpCode::Dup => simple_instruction("DUP"),
260 OpCode::Pop(count) => println!("{:-16} {:4}", "OP_POP", count),
261 OpCode::DefineGlobal { name_constant, .. } => {
262 self.constant_instruction("DEFINE_GLOBAL", name_constant)
263 }
264 OpCode::GetGlobal(c) => self.constant_instruction("GET_GLOBAL", c),
265 OpCode::SetGlobal(c) => self.constant_instruction("SET_GLOBAL", c),
266 OpCode::GetLocal(byte) => self.byte_instruction("GET_LOCAL", byte),
267 OpCode::SetLocal(c) => self.byte_instruction("SET_LOCAL", c),
268 OpCode::JumpIfFalse(jump) => {
269 self.jump_instruction("JUMP_IF_FALSE", 1, offset, jump)
270 }
271 OpCode::JumpPopIfFalse(jump) => {
272 self.jump_instruction("JUMP_POP_IF_FALSE", 1, offset, jump)
273 }
274 OpCode::Jump(jump) => self.jump_instruction("JUMP", 1, offset, jump),
275 OpCode::Loop(jump) => self.jump_instruction("LOOP", -1, offset, jump),
276 OpCode::Constructor {
277 positional_count,
278 keyword_count,
279 validate,
280 } => {
281 println!(

Callers 1

disassembleMethod · 0.45

Calls 6

simple_instructionFunction · 0.85
constant_instructionMethod · 0.80
byte_instructionMethod · 0.80
jump_instructionMethod · 0.80
invoke_instructionMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected