this is broken

This commit is contained in:
Rowan Torbitzky-Lane 2025-04-07 16:13:26 -05:00
parent 0cbe372b98
commit 8516575d9a
2 changed files with 21 additions and 21 deletions

View File

@ -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<Gene>) -> Option<bool> {
fn _is_block(vals: &Vec<&Gene>) -> Option<bool> {
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<Gene>) -> Option<bool> {
Some(_is_block(vals)?.not())
fn _is_singular(vals: &Vec<&Gene>) -> Option<bool> {
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<Gene>) -> Option<i128> {
fn _length(vals: &Vec<&Gene>) -> Option<i128> {
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<Gene>) -> Option<Gene> {
fn _first(vals: &Vec<&Gene>) -> Option<Gene> {
match &vals[0] {
Gene::Block(x) => {
if x.len() > 1 {
@ -39,10 +39,10 @@ fn _first(vals: Vec<Gene>) -> Option<Gene> {
_ => 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<Gene>) -> Option<Gene> {
fn _last(vals: &Vec<&Gene>) -> Option<Gene> {
match &vals[0] {
Gene::Block(x) => {
if x.len() > 1 {
@ -54,10 +54,10 @@ fn _last(vals: Vec<Gene>) -> Option<Gene> {
_ => 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<Gene>) -> Option<Gene> {
fn _rest(vals: &Vec<&Gene>) -> Option<Gene> {
match &vals[0] {
Gene::Block(x) => {
if x.len() > 1 {
@ -69,10 +69,10 @@ fn _rest(vals: Vec<Gene>) -> Option<Gene> {
_ => 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<Gene>) -> Option<Gene> {
fn _but_last(vals: &Vec<&Gene>) -> Option<Gene> {
match &vals[0] {
Gene::Block(x) => {
let x_len = x.len();
@ -85,13 +85,13 @@ fn _but_last(vals: Vec<Gene>) -> Option<Gene> {
_ => 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<Gene>) -> Option<Gene> {
Some(Gene::Block(Box::new(vals)))
fn _wrap_block(vals: &Vec<&Gene>) -> Option<Gene> {
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,

View File

@ -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();
}