Add "string" command

This commit is contained in:
bʰedoh₂ swé 2024-06-17 17:48:53 +05:00
parent fddedb7828
commit 065df34eb1
2 changed files with 9 additions and 0 deletions

View File

@ -70,6 +70,7 @@ pub fn execute(stack: &mut Stack, mut origin_stack: Option<&mut Stack>, mod_name
"dup" => instructions::stack_manage::dup(&mut stack.memory), "dup" => instructions::stack_manage::dup(&mut stack.memory),
"swap" => instructions::stack_manage::swap(&mut stack.memory), "swap" => instructions::stack_manage::swap(&mut stack.memory),
"pick" => instructions::stack_manage::pick(&mut stack.memory, instruction.data), "pick" => instructions::stack_manage::pick(&mut stack.memory, instruction.data),
"string" => instructions::stack_manage::string(&mut stack.memory, instruction.arg.clone()),
// Math operations // Math operations
"add" => instructions::math::add(&mut stack.memory), "add" => instructions::math::add(&mut stack.memory),

View File

@ -34,3 +34,11 @@ pub fn pick(memory: &mut StackVec, data: u16) {
.expect(&format!("{}", RunError::PickOutOfBounds)), .expect(&format!("{}", RunError::PickOutOfBounds)),
); );
} }
pub fn string(memory: &mut StackVec, arg: String) {
for i in arg.chars() {
memory.push(i as u16);
}
memory.push(arg.len() as u16);
}