Skip to content
This repository was archived by the owner on Jan 21, 2023. It is now read-only.

Commit 33032a2

Browse files
committed
add uncompile & op_3
1 parent 1ea15e4 commit 33032a2

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/main.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ impl Compiler {
1414
opcode_list.insert("OP_0", 0x00);
1515
opcode_list.insert("OP_1", 0x51);
1616
opcode_list.insert("OP_2", 0x52);
17+
opcode_list.insert("OP_3", 0x53);
1718
opcode_list.insert("OP_NOP", 0x61);
1819
opcode_list.insert("OP_DUP", 0x76);
1920
opcode_list.insert("OP_IF", 0x63);
@@ -31,7 +32,6 @@ impl Compiler {
3132
};
3233
}
3334
fn compile_single(&self, code: &str) -> i32 {
34-
let mut codes_unalias: &str = "";
3535
let alias_opcode: &str = match self.opcode_alias_list.get_by_left(&code) {
3636
Some(&value) => value,
3737
None => code,
@@ -52,6 +52,23 @@ impl Compiler {
5252

5353
return bytecode;
5454
}
55+
fn uncompile_single(&self, hex: i32) -> &str {
56+
let code: &str = match self.opcode_list.get_by_right(&hex) {
57+
Some(&value) => value,
58+
None => panic!("[Compiler] opcode not found."),
59+
};
60+
return code;
61+
}
62+
fn uncompile(&self, hexs: Vec<i32>) -> Vec<&str> {
63+
let mut codes: Vec<&str> = vec![];
64+
65+
for hex in hexs {
66+
let code = self.uncompile_single(hex);
67+
codes.push(code);
68+
}
69+
70+
return codes;
71+
}
5572

5673
}
5774
struct VM {
@@ -77,8 +94,8 @@ impl VM {
7794
println!("]");
7895

7996
print!("codes: [");
80-
for code in self.codes {
81-
print!("{:#x}, ",code);
97+
for code in Compiler::new().uncompile(self.codes) {
98+
print!("{}, ",code);
8299
}
83100
println!("]");
84101
}

0 commit comments

Comments
 (0)