okay shift some shit around this is now the actual 1.0.0 :3
This commit is contained in:
parent
ae9634fee6
commit
a8dc83924b
3 changed files with 9 additions and 6 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -99,7 +99,7 @@ checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "granite"
|
name = "granite"
|
||||||
version = "1.2.0"
|
version = "1.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "granite"
|
name = "granite"
|
||||||
version = "1.2.0"
|
version = "1.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -50,6 +50,7 @@ fn execute(program: Program) {
|
||||||
let statements = program.statements;
|
let statements = program.statements;
|
||||||
let mut vars: HashMap<String, String> = HashMap::new();
|
let mut vars: HashMap<String, String> = HashMap::new();
|
||||||
let mut current_statement: usize = 0;
|
let mut current_statement: usize = 0;
|
||||||
|
let mut stack: Vec<usize> = vec![];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if current_statement >= statements.len() { break; }
|
if current_statement >= statements.len() { break; }
|
||||||
|
@ -183,13 +184,9 @@ fn execute(program: Program) {
|
||||||
let label_loc = labels.get(&statement.arguments[0]).unwrap();
|
let label_loc = labels.get(&statement.arguments[0]).unwrap();
|
||||||
current_statement = label_loc.clone();
|
current_statement = label_loc.clone();
|
||||||
} else {
|
} else {
|
||||||
let binding = statement.arguments[0].clone().parse::<usize>();
|
|
||||||
if binding.is_ok() { current_statement = binding.unwrap(); }
|
|
||||||
else {
|
|
||||||
println!("Numerical type issues.");
|
println!("Numerical type issues.");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if statement.operator == "a" {
|
} else if statement.operator == "a" {
|
||||||
if vars.contains_key(&statement.arguments[0]) && vars.contains_key(&statement.arguments[1]) {
|
if vars.contains_key(&statement.arguments[0]) && vars.contains_key(&statement.arguments[1]) {
|
||||||
let value = vars.get(&statement.arguments[0]).unwrap();
|
let value = vars.get(&statement.arguments[0]).unwrap();
|
||||||
|
@ -294,6 +291,10 @@ fn execute(program: Program) {
|
||||||
}
|
}
|
||||||
} else if statement.operator == "$" {
|
} else if statement.operator == "$" {
|
||||||
vars.remove(&statement.arguments[0]);
|
vars.remove(&statement.arguments[0]);
|
||||||
|
} else if statement.operator == "#" {
|
||||||
|
stack.push(current_statement);
|
||||||
|
} else if statement.operator == "|" {
|
||||||
|
current_statement = stack.pop().expect("Stack underflow.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -405,6 +406,8 @@ fn operator_to_arglength(operator: char) -> Option<i32> {
|
||||||
'&' => Some(2),
|
'&' => Some(2),
|
||||||
'$' => Some(1),
|
'$' => Some(1),
|
||||||
'%' => Some(2),
|
'%' => Some(2),
|
||||||
|
'#' => Some(0),
|
||||||
|
'|' => Some(0),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue