From 8516575d9a62abb130668a87bf46f1e27a4df5f8 Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane Date: Mon, 7 Apr 2025 16:13:26 -0500 Subject: [PATCH] this is broken --- src/instructions/code.rs | 36 ++++++++++++++++++------------------ src/instructions/mod.rs | 6 +++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/instructions/code.rs b/src/instructions/code.rs index 2462ca9..f12ebbe 100644 --- a/src/instructions/code.rs +++ b/src/instructions/code.rs @@ -3,31 +3,31 @@ use std::ops::Not; use crate::push::state::{Gene, PushState}; /// Checks to see if a single gene is a block. -fn _is_block(vals: Vec) -> Option { +fn _is_block(vals: &Vec<&Gene>) -> Option { Some(match vals[0] { Gene::Block(_) => true, _ => false, }) } -make_instruction_clone!(code, boolean, _is_block, Gene, 1); +make_instruction_ref!(code, boolean, _is_block, Gene, 1); /// Checks to see if a single gene is not a block. -fn _is_singular(vals: Vec) -> Option { - Some(_is_block(vals)?.not()) +fn _is_singular(vals: &Vec<&Gene>) -> Option { + Some(_is_block(&vals)?.not()) } -make_instruction_clone!(code, boolean, _is_singular, Gene, 1); +make_instruction_ref!(code, boolean, _is_singular, Gene, 1); /// Returns the length of a block, else 1 if not a block -fn _length(vals: Vec) -> Option { +fn _length(vals: &Vec<&Gene>) -> Option { Some(match &vals[0] { Gene::Block(x) => x.len() as i128, _ => 1, }) } -make_instruction_clone!(code, int, _length, Gene, 1); +make_instruction_ref!(code, int, _length, Gene, 1); /// Returns the first item in a block if doable, else None -fn _first(vals: Vec) -> Option { +fn _first(vals: &Vec<&Gene>) -> Option { match &vals[0] { Gene::Block(x) => { if x.len() > 1 { @@ -39,10 +39,10 @@ fn _first(vals: Vec) -> Option { _ => None, } } -make_instruction_clone!(code, code, _first, Gene, 1); +make_instruction_ref!(code, code, _first, Gene, 1); /// Returns the first item in a block if applicable, else None -fn _last(vals: Vec) -> Option { +fn _last(vals: &Vec<&Gene>) -> Option { match &vals[0] { Gene::Block(x) => { if x.len() > 1 { @@ -54,10 +54,10 @@ fn _last(vals: Vec) -> Option { _ => None, } } -make_instruction_clone!(code, code, _last, Gene, 1); +make_instruction_ref!(code, code, _last, Gene, 1); /// Returns all but the first code item in a block if applicable, else None -fn _rest(vals: Vec) -> Option { +fn _rest(vals: &Vec<&Gene>) -> Option { match &vals[0] { Gene::Block(x) => { if x.len() > 1 { @@ -69,10 +69,10 @@ fn _rest(vals: Vec) -> Option { _ => None, } } -make_instruction_clone!(code, code, _rest, Gene, 1); +make_instruction_ref!(code, code, _rest, Gene, 1); /// Returns all but the first code item in a block if applicable, else None -fn _but_last(vals: Vec) -> Option { +fn _but_last(vals: &Vec<&Gene>) -> Option { match &vals[0] { Gene::Block(x) => { let x_len = x.len(); @@ -85,13 +85,13 @@ fn _but_last(vals: Vec) -> Option { _ => None, } } -make_instruction_clone!(code, code, _but_last, Gene, 1); +make_instruction_ref!(code, code, _but_last, Gene, 1); /// Returns all of the vals wrapped in a code block -fn _wrap_block(vals: Vec) -> Option { - Some(Gene::Block(Box::new(vals))) +fn _wrap_block(vals: &Vec<&Gene>) -> Option { + Some(Gene::Block(Box::new(*vals))) } -make_instruction_clone!(code, code, _wrap_block, Gene, 1); +make_instruction_ref!(code, code, _wrap_block, Gene, 1); /// Combines two genes into one. Accounts for blocks. /// If the second gene is a block and the first one isn't, diff --git a/src/instructions/mod.rs b/src/instructions/mod.rs index b28db2e..8fae745 100644 --- a/src/instructions/mod.rs +++ b/src/instructions/mod.rs @@ -114,11 +114,11 @@ pub mod macros { if in_stack_len < $fn_arity { return; } - let mut inputs: Vec<$fn_type> = Vec::with_capacity($fn_arity); + let inputs: &mut Vec<&$fn_type> = &mut Vec::with_capacity($fn_arity); for n in 1..=$fn_arity { - inputs.push(state.$in_stack[in_stack_len - n]); + inputs.push(&state.$in_stack[in_stack_len - n]); } - if let Some(result) = $fn_name(&inputs) { + if let Some(result) = $fn_name(inputs) { for _ in 0..$fn_arity { state.$in_stack.pop(); }