diff --git a/src/main.rs b/src/main.rs index 5f77163..da0decf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,6 +54,7 @@ enum Operation { Enqueue(Datatype, String, i32, i32), Dequeue(i32, i32), + Requeue(i32, i32), Intrinsic(String, i32, i32), FunctionCall(String, i32, i32), If(Vec, Option>, i32, i32), @@ -66,7 +67,6 @@ fn main() [ ("print", (Vec::from([Datatype::Any]), Vec::new())), ("-", (Vec::from([Datatype::Int, Datatype::Int]), Vec::from([Datatype::Int]))), - ("req", (Vec::from([Datatype::Any]), Vec::from([Datatype::Any]))), ]); let args: Vec = env::args().collect(); if args.len() < 2 @@ -139,6 +139,7 @@ fn typecheck_block(operations: &Vec, ins: &Vec, outs: &Vec< match operation { Operation::Enqueue(_, _, line, col) | + Operation::Requeue(line, col) | Operation::FunctionCall(_, line, col) | Operation::If(_, _, line, col) | Operation::Intrinsic(_, line, col) | @@ -177,6 +178,15 @@ fn get_return_type(operations: &Vec, ins: &Vec, functions: { type_queue.push(*datatype); } + Operation::Requeue(line, col) => + { + if type_queue.is_empty() + { + panic!("Attempted to requeue an element while the queue was empty at {}:{}", line, col); + } + let typ = type_queue.remove(0); + type_queue.push(typ); + } Operation::FunctionCall(function_name, line, col) => { let function = functions.iter().find(|x| &x.name == function_name).unwrap(); @@ -296,7 +306,7 @@ fn validate_function_calls_in_block(block: &Vec, functions: &Vec {}, + Operation::Intrinsic(_, _, _) | Operation::Enqueue(_, _, _, _) | Operation::Dequeue(_, _) | Operation::Requeue(_, _) => {}, Operation::FunctionCall(function_name, line, col) => { if !functions.iter().any(|x| &x.name == function_name) @@ -503,6 +513,11 @@ fn parse_until_delimiter(tokens_iter: &mut Peekable>, in { operations.push(Operation::Dequeue(*line, *col)); } + else if word == "req" + { + + operations.push(Operation::Requeue(*line, *col)); + } else if Some(word.as_str()) == delimiter { return operations;