From 23c6ec8dad51eb74fbe54fef1240fff523669f3c Mon Sep 17 00:00:00 2001 From: 0x4261756D <–38735823+0x4261756D@users.noreply.github.com> Date: Thu, 22 Dec 2022 10:29:25 +0100 Subject: [PATCH] Add more intrinsics --- src/main.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 6f367d3..0555950 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,10 +87,13 @@ fn main() ("println", (Vec::from([Datatype::Any]), Vec::new())), ("-", (Vec::from([Datatype::Int, Datatype::Int]), Vec::from([Datatype::Int]))), ("+", (Vec::from([Datatype::Int, Datatype::Int]), Vec::from([Datatype::Int]))), + ("*", (Vec::from([Datatype::Int, Datatype::Int]), Vec::from([Datatype::Int]))), ("<", (Vec::from([Datatype::Int, Datatype::Int]), Vec::from([Datatype::Bool]))), (">", (Vec::from([Datatype::Int, Datatype::Int]), Vec::from([Datatype::Bool]))), + (">=", (Vec::from([Datatype::Int, Datatype::Int]), Vec::from([Datatype::Bool]))), ("==", (Vec::from([Datatype::Int, Datatype::Int]), Vec::from([Datatype::Bool]))), ("!=", (Vec::from([Datatype::Int, Datatype::Int]), Vec::from([Datatype::Bool]))), + ("&&", (Vec::from([Datatype::Bool, Datatype::Bool]), Vec::from([Datatype::Bool]))), ("decrease", (Vec::from([Datatype::Int]), Vec::from([Datatype::Int]))), ]); let args: Vec = env::args().collect(); @@ -301,12 +304,24 @@ fn interpret_program(operations: &Vec, queue: &mut Vec, funct let addend2 = queue.remove(0).parse::().unwrap(); queue.push((addend1 + addend2).to_string()); } + "*" => + { + let multiplicant1 = queue.remove(0).parse::().unwrap(); + let multiplicant2 = queue.remove(0).parse::().unwrap(); + queue.push((multiplicant1 * multiplicant2).to_string()); + } ">" => { let first = queue.remove(0).parse::().unwrap(); let second = queue.remove(0).parse::().unwrap(); queue.push((first > second).to_string()); } + ">=" => + { + let first = queue.remove(0).parse::().unwrap(); + let second = queue.remove(0).parse::().unwrap(); + queue.push((first >= second).to_string()); + } "<" => { let first = queue.remove(0).parse::().unwrap(); @@ -325,6 +340,12 @@ fn interpret_program(operations: &Vec, queue: &mut Vec, funct let second = queue.remove(0).parse::().unwrap(); queue.push((first != second).to_string()); } + "&&" => + { + let first = queue.remove(0).parse::().unwrap(); + let second = queue.remove(0).parse::().unwrap(); + queue.push((first && second).to_string()); + } "decrease" => { let val = queue.remove(0).parse::().unwrap(); @@ -356,7 +377,16 @@ fn interpret_program(operations: &Vec, queue: &mut Vec, funct { return Err(format!("Attempted an out of bounds write for array {} ({} < 0) at {}:{}", arr.name, position, line, col)); } - arr.data[position as usize] = queue.remove(0); + let data = queue.remove(0); + if debug + { + println!("write before: {} {} {:?}", position, data, arr); + } + arr.data[position as usize] = data; + if debug + { + println!("write after: {:?}", arr); + } } "read" => {