Add more intrinsics
This commit is contained in:
parent
5682ee708c
commit
23c6ec8dad
32
src/main.rs
32
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<String> = env::args().collect();
|
||||
|
@ -301,12 +304,24 @@ fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, funct
|
|||
let addend2 = queue.remove(0).parse::<i64>().unwrap();
|
||||
queue.push((addend1 + addend2).to_string());
|
||||
}
|
||||
"*" =>
|
||||
{
|
||||
let multiplicant1 = queue.remove(0).parse::<i64>().unwrap();
|
||||
let multiplicant2 = queue.remove(0).parse::<i64>().unwrap();
|
||||
queue.push((multiplicant1 * multiplicant2).to_string());
|
||||
}
|
||||
">" =>
|
||||
{
|
||||
let first = queue.remove(0).parse::<i64>().unwrap();
|
||||
let second = queue.remove(0).parse::<i64>().unwrap();
|
||||
queue.push((first > second).to_string());
|
||||
}
|
||||
">=" =>
|
||||
{
|
||||
let first = queue.remove(0).parse::<i64>().unwrap();
|
||||
let second = queue.remove(0).parse::<i64>().unwrap();
|
||||
queue.push((first >= second).to_string());
|
||||
}
|
||||
"<" =>
|
||||
{
|
||||
let first = queue.remove(0).parse::<i64>().unwrap();
|
||||
|
@ -325,6 +340,12 @@ fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, funct
|
|||
let second = queue.remove(0).parse::<i64>().unwrap();
|
||||
queue.push((first != second).to_string());
|
||||
}
|
||||
"&&" =>
|
||||
{
|
||||
let first = queue.remove(0).parse::<bool>().unwrap();
|
||||
let second = queue.remove(0).parse::<bool>().unwrap();
|
||||
queue.push((first && second).to_string());
|
||||
}
|
||||
"decrease" =>
|
||||
{
|
||||
let val = queue.remove(0).parse::<i64>().unwrap();
|
||||
|
@ -356,7 +377,16 @@ fn interpret_program(operations: &Vec<Operation>, queue: &mut Vec<String>, 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" =>
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue