summaryrefslogtreecommitdiffstats
path: root/bytecode/src/encoding.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bytecode/src/encoding.rs')
-rw-r--r--bytecode/src/encoding.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/bytecode/src/encoding.rs b/bytecode/src/encoding.rs
index 8bec753..80fcc58 100644
--- a/bytecode/src/encoding.rs
+++ b/bytecode/src/encoding.rs
@@ -68,6 +68,26 @@ pub struct Div {
}
#[derive(Debug, Clone, Copy)]
+pub struct Less {
+ pub out: u8,
+ pub val1: Arg,
+ pub val2: Arg,
+}
+
+#[derive(Debug, Clone, Copy)]
+pub struct Eq {
+ pub out: u8,
+ pub val1: Arg,
+ pub val2: Arg,
+}
+
+#[derive(Debug, Clone, Copy)]
+pub struct If {
+ pub test: Arg,
+ pub target: usize,
+}
+
+#[derive(Debug, Clone, Copy)]
pub enum Op {
Alloc(Alloc),
Call,
@@ -79,6 +99,9 @@ pub enum Op {
Sub(Sub),
Mul(Mul),
Div(Div),
+ Less(Less),
+ Eq(Eq),
+ If(If),
}
struct Reader<'a> {
@@ -198,6 +221,26 @@ impl Op {
let val2 = r.parse_arg(arg2_const)?;
Op::Div(Div { out, val1, val2 })
}
+ 11 => {
+ let out = r.parse_local()?;
+ let val1 = r.parse_arg(arg1_const)?;
+ let val2 = r.parse_arg(arg2_const)?;
+ Op::Less(Less { out, val1, val2 })
+ }
+ 12 => {
+ let out = r.parse_local()?;
+ let val1 = r.parse_arg(arg1_const)?;
+ let val2 = r.parse_arg(arg2_const)?;
+ Op::Eq(Eq { out, val1, val2 })
+ }
+ 13 => {
+ let test = r.parse_arg(arg1_const)?;
+ let Some(itarget) = r.parse_value()?.to_int() else {
+ return Err(Box::from("invalid target"));
+ };
+ let target = usize::try_from(itarget)?;
+ Op::If(If { test, target })
+ }
_ => {
return Err(Box::from(format!("invalid code {}", code)));
}