add variable cloning

This commit is contained in:
abbie 2024-08-14 12:42:37 +01:00
parent 1f020ecdb2
commit e258f6208d
Signed by: threeoh6000
GPG key ID: 801FE4AD456E922C
3 changed files with 11 additions and 2 deletions

2
Cargo.lock generated
View file

@ -99,7 +99,7 @@ checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
[[package]]
name = "granite"
version = "1.0.0"
version = "1.1.0"
dependencies = [
"clap",
]

View file

@ -1,6 +1,6 @@
[package]
name = "granite"
version = "1.0.0"
version = "1.1.0"
edition = "2021"
[dependencies]

View file

@ -280,6 +280,14 @@ fn execute(program: Program) {
println!("Missing variable on int check.");
exit(1);
}
} else if statement.operator == "%" {
if vars.contains_key(&statement.arguments[0]) {
let value = vars.get(&statement.arguments[0]).unwrap();
vars.insert(statement.arguments[1].clone(), value.clone());
} else {
println!("Missing variable on clone.");
exit(1);
}
} else if statement.operator == "$" {
vars.remove(&statement.arguments[0]);
}
@ -392,6 +400,7 @@ fn operator_to_arglength(operator: char) -> Option<i32> {
'0' => Some(1),
'&' => Some(2),
'$' => Some(1),
'%' => Some(2),
_ => None,
}
}