From 9e7620db823d0cbbbdbf7bb50d014899c18d4c68 Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane Date: Mon, 21 Apr 2025 12:12:00 -0500 Subject: [PATCH] stuck on how to put these functions into a list --- rush_macro/src/lib.rs | 2 +- rush_macro/src/utils/instructionlist.rs | 2 ++ rush_macro/src/utils/mod.rs | 1 + src/instructions/code.rs | 11 +++-------- src/instructions/common.rs | 3 +-- src/instructions/mod.rs | 3 --- tests/instruction_test.rs | 3 +++ 7 files changed, 11 insertions(+), 14 deletions(-) create mode 100644 rush_macro/src/utils/instructionlist.rs diff --git a/rush_macro/src/lib.rs b/rush_macro/src/lib.rs index fbe64cd..8a5fc50 100644 --- a/rush_macro/src/lib.rs +++ b/rush_macro/src/lib.rs @@ -30,7 +30,7 @@ mod utils; /// Some(vec![x + y, x - y]) /// } /// -/// run_instruction!(aux_iadd, int, state, int, int;); +/// // rush_macro::run_instruction!(aux_iadd, int, _state, int, int;); /// ``` /// would have the ; placed at the end of the instruction. Check rush's `tests/instruction_test.rs` /// file for an example using this code. diff --git a/rush_macro/src/utils/instructionlist.rs b/rush_macro/src/utils/instructionlist.rs new file mode 100644 index 0000000..3d89baf --- /dev/null +++ b/rush_macro/src/utils/instructionlist.rs @@ -0,0 +1,2 @@ +//! This file implements the proc macro implementation for creating a list of instructions +//! from a set of passed function declarations. diff --git a/rush_macro/src/utils/mod.rs b/rush_macro/src/utils/mod.rs index 28504b1..b911aaf 100644 --- a/rush_macro/src/utils/mod.rs +++ b/rush_macro/src/utils/mod.rs @@ -1,6 +1,7 @@ use syn::parse::{Parse, ParseStream}; pub mod instruction; +pub mod instructionlist; fn parse_zero_or_more(input: ParseStream) -> Vec { let mut result = Vec::new(); diff --git a/src/instructions/code.rs b/src/instructions/code.rs index 7931c9c..f7cf606 100644 --- a/src/instructions/code.rs +++ b/src/instructions/code.rs @@ -1,15 +1,10 @@ -use std::ops::Not; - -use crate::push::state::{Gene, PushState}; - use super::common::{code_from_exec, code_pop, int_pop}; +use crate::push::state::{Gene, PushState}; +use std::ops::Not; /// Checks to see if a single gene is a block. fn _is_block(a: Gene) -> Option { - Some(match a { - Gene::Block(_) => true, - _ => false, - }) + Some(matches!(a, Gene::Block(_))) } /// Checks to see if a single gene is not a block. diff --git a/src/instructions/common.rs b/src/instructions/common.rs index 0b1da25..9bb8696 100644 --- a/src/instructions/common.rs +++ b/src/instructions/common.rs @@ -1,6 +1,5 @@ -use std::cmp::{max, min}; - use crate::push::state::{Gene, PushState}; +use std::cmp::{max, min}; fn min_max_bounds(ndx: i128, length: usize) -> usize { max(0, min(ndx.unsigned_abs() as usize, length - 1)) diff --git a/src/instructions/mod.rs b/src/instructions/mod.rs index 5648569..f09221d 100644 --- a/src/instructions/mod.rs +++ b/src/instructions/mod.rs @@ -1,6 +1,3 @@ -use crate::instructions::common::{int_dup, int_yank}; -use crate::push::state::PushState; - #[macro_use] pub mod macros { /// Runs a function and ensures the necessary variables are extracted from a state without error diff --git a/tests/instruction_test.rs b/tests/instruction_test.rs index f1d5b61..68d5083 100644 --- a/tests/instruction_test.rs +++ b/tests/instruction_test.rs @@ -43,3 +43,6 @@ fn run_extract_test() { run_instruction!(aux_char, char, test_state, vector_char;); assert_eq!(vec!['a', 'b'], test_state.char); } + +#[test] +fn instruction_list_test() {}