Make requeueing an operation instead of an intrinsic
This commit is contained in:
parent
d9e7f18049
commit
abfb3d2f3d
19
src/main.rs
19
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<Operation>, Option<Vec<Operation>>, 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<String> = env::args().collect();
|
||||
if args.len() < 2
|
||||
@ -139,6 +139,7 @@ fn typecheck_block(operations: &Vec<Operation>, ins: &Vec<Datatype>, 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<Operation>, ins: &Vec<Datatype>, 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<Operation>, functions: &Vec<Func
|
||||
{
|
||||
match operation
|
||||
{
|
||||
Operation::Intrinsic(_, _, _) | Operation::Enqueue(_, _, _, _) | Operation::Dequeue(_, _) => {},
|
||||
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<std::slice::Iter<Token>>, 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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user