From e258f6208d7d4bc88e59f4304aa6391d7f66f6db Mon Sep 17 00:00:00 2001 From: threeoh6000 Date: Wed, 14 Aug 2024 12:42:37 +0100 Subject: [PATCH] add variable cloning --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 214d526..1411232 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,7 +99,7 @@ checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "granite" -version = "1.0.0" +version = "1.1.0" dependencies = [ "clap", ] diff --git a/Cargo.toml b/Cargo.toml index 6b4033e..f757059 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "granite" -version = "1.0.0" +version = "1.1.0" edition = "2021" [dependencies] diff --git a/src/main.rs b/src/main.rs index 21455d7..eb87f03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 { '0' => Some(1), '&' => Some(2), '$' => Some(1), + '%' => Some(2), _ => None, } }