In the middle of getting rid of warnings
This commit is contained in:
parent
748e96639a
commit
708a66c5cc
@ -9,6 +9,12 @@ fn _noop<T>(_: Vec<T>) -> Option<T> {
|
||||
make_instruction_clone!(code, code, _noop, Gene, 0);
|
||||
make_instruction_clone!(exec, exec, _noop, Gene, 0);
|
||||
|
||||
fn _noop_block<T>(_: Vec<T>) -> Option<T> {
|
||||
None
|
||||
}
|
||||
make_instruction_clone!(code, code, _noop_block, Gene, 0);
|
||||
make_instruction_clone!(exec, exec, _noop_block, Gene, 0);
|
||||
|
||||
/// Pops the top value from the stack
|
||||
fn _pop<T>(vals: Vec<T>) -> Option<T>
|
||||
where
|
||||
|
@ -76,19 +76,6 @@ where
|
||||
}
|
||||
make_instruction_out!(float, boolean, _from_float, Decimal, 1);
|
||||
|
||||
pub fn boolean_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
boolean_and,
|
||||
boolean_or,
|
||||
boolean_not,
|
||||
boolean_xor,
|
||||
boolean_invert_first_then_and,
|
||||
boolean_invert_second_then_and,
|
||||
boolean_from_int,
|
||||
boolean_from_float,
|
||||
]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -1,3 +1,10 @@
|
||||
use crate::instructions::code::*;
|
||||
use crate::instructions::common::*;
|
||||
use crate::instructions::logical::*;
|
||||
use crate::instructions::numeric::*;
|
||||
use crate::instructions::vector::*;
|
||||
use crate::push::state::PushState;
|
||||
|
||||
#[macro_use]
|
||||
pub mod macros {
|
||||
/// A macro that makes a push instruction given: the name of the input stack to use,
|
||||
@ -82,7 +89,7 @@ pub mod macros {
|
||||
paste::item! {
|
||||
/// Runs the $fn_name function on the top $fn_arity items from
|
||||
/// the $in_stack and places the calculated value on the $out_stack.
|
||||
#[allow(clippy::reversed_empty_ranges)]
|
||||
#[allow(clippy::reversed_empty_ranges, unused_comparisons)]
|
||||
pub fn [< $in_stack $fn_name >] (state: &mut PushState) {
|
||||
let in_stack_len = state.$in_stack.len();
|
||||
if in_stack_len < $fn_arity {
|
||||
@ -137,6 +144,7 @@ pub mod macros {
|
||||
paste::item! {
|
||||
/// Runs the $fn_name function on the top $fn_arity items from
|
||||
/// the $in_stack and places the calculated value on the $out_stack.
|
||||
#[allow(unused_comparisons)]
|
||||
pub fn [< $in_stack $fn_name >] (state: &mut PushState) {
|
||||
let in_stack_len = state.$in_stack.len();
|
||||
if in_stack_len < $fn_arity {
|
||||
@ -264,3 +272,359 @@ pub mod logical;
|
||||
pub mod numeric;
|
||||
pub mod utils;
|
||||
pub mod vector;
|
||||
|
||||
// unsure how to procedurally read a file and put all functions
|
||||
// into a vector. Probably need to use procedural macros, but I'm not there yet.
|
||||
pub fn int_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
// numeric.rs
|
||||
int_add,
|
||||
int_sub,
|
||||
int_mult,
|
||||
int_div,
|
||||
int_rem,
|
||||
int_max,
|
||||
int_min,
|
||||
int_inc,
|
||||
int_dec,
|
||||
int_lt,
|
||||
int_gt,
|
||||
int_lte,
|
||||
int_gte,
|
||||
int_sin,
|
||||
int_arcsin,
|
||||
int_cos,
|
||||
int_arccos,
|
||||
int_tan,
|
||||
int_arctan,
|
||||
int_from_float,
|
||||
int_from_boolean,
|
||||
int_log,
|
||||
int_exp,
|
||||
int_sqrt,
|
||||
int_inv,
|
||||
int_abs,
|
||||
int_sign_reverse,
|
||||
int_square,
|
||||
// common.rs
|
||||
int_pop,
|
||||
]
|
||||
}
|
||||
pub fn float_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
// numeric
|
||||
float_add,
|
||||
float_sub,
|
||||
float_mult,
|
||||
float_div,
|
||||
float_rem,
|
||||
float_max,
|
||||
float_min,
|
||||
float_inc,
|
||||
float_dec,
|
||||
float_lt,
|
||||
float_gt,
|
||||
float_lte,
|
||||
float_gte,
|
||||
float_sin,
|
||||
float_arcsin,
|
||||
float_cos,
|
||||
float_arccos,
|
||||
float_tan,
|
||||
float_arctan,
|
||||
float_from_int,
|
||||
float_from_boolean,
|
||||
float_log,
|
||||
float_exp,
|
||||
float_sqrt,
|
||||
float_inv,
|
||||
float_abs,
|
||||
float_sign_reverse,
|
||||
float_square,
|
||||
// common.rs
|
||||
float_pop,
|
||||
]
|
||||
}
|
||||
pub fn string_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
// numeric.rs
|
||||
string_concat,
|
||||
string_conj,
|
||||
string_conj_end,
|
||||
string_take_n,
|
||||
string_take_last_n,
|
||||
string_sub,
|
||||
string_first,
|
||||
string_from_first_prim,
|
||||
string_from_prim,
|
||||
string_last,
|
||||
string_from_last_prim,
|
||||
string_nth,
|
||||
string_from_nth_prim,
|
||||
string_rest,
|
||||
string_but_last,
|
||||
string_drop,
|
||||
string_length,
|
||||
string_reverse,
|
||||
string_push_all,
|
||||
string_make_empty,
|
||||
string_is_empty,
|
||||
string_contains,
|
||||
string_index_of,
|
||||
string_occurrences_of,
|
||||
string_set_nth,
|
||||
string_replace,
|
||||
// common.rs
|
||||
string_pop,
|
||||
]
|
||||
}
|
||||
pub fn boolean_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
// logical.rs
|
||||
boolean_and,
|
||||
boolean_or,
|
||||
boolean_not,
|
||||
boolean_xor,
|
||||
boolean_invert_first_then_and,
|
||||
boolean_invert_second_then_and,
|
||||
boolean_from_int,
|
||||
boolean_from_float,
|
||||
// common.rs
|
||||
boolean_pop,
|
||||
]
|
||||
}
|
||||
pub fn char_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
// common.rs
|
||||
char_pop,
|
||||
]
|
||||
}
|
||||
pub fn vector_int_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
// vector.rs
|
||||
vector_int_concat,
|
||||
vector_int_conj,
|
||||
vector_int_conj_end,
|
||||
vector_int_take_n,
|
||||
vector_int_take_last_n,
|
||||
vector_int_sub,
|
||||
vector_int_first,
|
||||
vector_int_from_first_prim,
|
||||
vector_int_from_prim,
|
||||
vector_int_last,
|
||||
vector_int_from_last_prim,
|
||||
vector_int_nth,
|
||||
vector_int_from_nth_prim,
|
||||
vector_int_rest,
|
||||
vector_int_but_last,
|
||||
vector_int_drop,
|
||||
vector_int_length,
|
||||
vector_int_reverse,
|
||||
vector_int_push_all,
|
||||
vector_int_make_empty,
|
||||
vector_int_is_empty,
|
||||
vector_int_contains,
|
||||
vector_int_index_of,
|
||||
vector_int_occurrences_of,
|
||||
vector_int_set_nth,
|
||||
vector_int_replace,
|
||||
// common.rs
|
||||
vector_int_pop,
|
||||
]
|
||||
}
|
||||
pub fn vector_float_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
// vector.rs
|
||||
vector_float_concat,
|
||||
vector_float_conj,
|
||||
vector_float_conj_end,
|
||||
vector_float_take_n,
|
||||
vector_float_take_last_n,
|
||||
vector_float_sub,
|
||||
vector_float_first,
|
||||
vector_float_from_first_prim,
|
||||
vector_float_from_prim,
|
||||
vector_float_last,
|
||||
vector_float_from_last_prim,
|
||||
vector_float_nth,
|
||||
vector_float_from_nth_prim,
|
||||
vector_float_rest,
|
||||
vector_float_but_last,
|
||||
vector_float_drop,
|
||||
vector_float_length,
|
||||
vector_float_reverse,
|
||||
vector_float_push_all,
|
||||
vector_float_make_empty,
|
||||
vector_float_is_empty,
|
||||
vector_float_contains,
|
||||
vector_float_index_of,
|
||||
vector_float_occurrences_of,
|
||||
vector_float_set_nth,
|
||||
vector_float_replace,
|
||||
// common.rs
|
||||
vector_float_pop,
|
||||
]
|
||||
}
|
||||
pub fn vector_string_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
// vector.rs
|
||||
vector_string_concat,
|
||||
vector_string_conj,
|
||||
vector_string_conj_end,
|
||||
vector_string_take_n,
|
||||
vector_string_take_last_n,
|
||||
vector_string_sub,
|
||||
vector_string_first,
|
||||
vector_string_from_first_prim,
|
||||
vector_string_from_prim,
|
||||
vector_string_last,
|
||||
vector_string_from_last_prim,
|
||||
vector_string_nth,
|
||||
vector_string_from_nth_prim,
|
||||
vector_string_rest,
|
||||
vector_string_but_last,
|
||||
vector_string_drop,
|
||||
vector_string_length,
|
||||
vector_string_reverse,
|
||||
vector_string_make_empty,
|
||||
vector_string_is_empty,
|
||||
vector_string_contains,
|
||||
vector_string_index_of,
|
||||
vector_string_occurrences_of,
|
||||
vector_string_set_nth,
|
||||
vector_string_replace,
|
||||
// common.rs
|
||||
vector_string_pop,
|
||||
]
|
||||
}
|
||||
pub fn vector_boolean_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
// vector.rs
|
||||
vector_boolean_concat,
|
||||
vector_boolean_conj,
|
||||
vector_boolean_conj_end,
|
||||
vector_boolean_take_n,
|
||||
vector_boolean_take_last_n,
|
||||
vector_boolean_sub,
|
||||
vector_boolean_first,
|
||||
vector_boolean_from_first_prim,
|
||||
vector_boolean_from_prim,
|
||||
vector_boolean_last,
|
||||
vector_boolean_from_last_prim,
|
||||
vector_boolean_nth,
|
||||
vector_boolean_from_nth_prim,
|
||||
vector_boolean_rest,
|
||||
vector_boolean_but_last,
|
||||
vector_boolean_drop,
|
||||
vector_boolean_length,
|
||||
vector_boolean_reverse,
|
||||
vector_boolean_push_all,
|
||||
vector_boolean_make_empty,
|
||||
vector_boolean_is_empty,
|
||||
vector_boolean_contains,
|
||||
vector_boolean_index_of,
|
||||
vector_boolean_occurrences_of,
|
||||
vector_boolean_set_nth,
|
||||
vector_boolean_replace,
|
||||
// common.rs
|
||||
vector_boolean_pop,
|
||||
]
|
||||
}
|
||||
pub fn vector_char_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
// vector.rs
|
||||
vector_char_concat,
|
||||
vector_char_conj,
|
||||
vector_char_conj_end,
|
||||
vector_char_take_n,
|
||||
vector_char_take_last_n,
|
||||
vector_char_sub,
|
||||
vector_char_first,
|
||||
vector_char_from_first_prim,
|
||||
vector_char_from_prim,
|
||||
vector_char_last,
|
||||
vector_char_from_last_prim,
|
||||
vector_char_nth,
|
||||
vector_char_from_nth_prim,
|
||||
vector_char_rest,
|
||||
vector_char_but_last,
|
||||
vector_char_drop,
|
||||
vector_char_length,
|
||||
vector_char_reverse,
|
||||
vector_char_push_all,
|
||||
vector_char_make_empty,
|
||||
vector_char_is_empty,
|
||||
vector_char_contains,
|
||||
vector_char_index_of,
|
||||
vector_char_occurrences_of,
|
||||
vector_char_set_nth,
|
||||
vector_char_replace,
|
||||
// common.rs
|
||||
vector_char_pop,
|
||||
]
|
||||
}
|
||||
pub fn exec_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
// code.rs
|
||||
exec_do_range,
|
||||
exec_do_count,
|
||||
exec_do_times,
|
||||
exec_while,
|
||||
exec_do_while,
|
||||
exec_if,
|
||||
exec_when,
|
||||
exec_make_empty_block,
|
||||
exec_is_empty_block,
|
||||
exec_size,
|
||||
// common.rs
|
||||
exec_noop,
|
||||
exec_noop_block,
|
||||
exec_pop,
|
||||
]
|
||||
}
|
||||
pub fn code_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
// code.rs
|
||||
code_is_block,
|
||||
code_is_singular,
|
||||
code_length,
|
||||
code_first,
|
||||
code_last,
|
||||
code_rest,
|
||||
code_but_last,
|
||||
code_wrap_block,
|
||||
code_combine,
|
||||
code_do_then_pop,
|
||||
code_do_range,
|
||||
code_do_count,
|
||||
code_do_times,
|
||||
code_map,
|
||||
code_if,
|
||||
code_when,
|
||||
code_member,
|
||||
code_nth,
|
||||
code_make_empty_block,
|
||||
code_is_empty_block,
|
||||
code_size,
|
||||
code_extract,
|
||||
code_insert,
|
||||
code_insert,
|
||||
code_first_position,
|
||||
code_reverse,
|
||||
// common.rs
|
||||
code_noop,
|
||||
code_noop_block,
|
||||
code_pop,
|
||||
code_from_int,
|
||||
code_from_float,
|
||||
code_from_string,
|
||||
code_from_boolean,
|
||||
code_from_char,
|
||||
code_from_vector_int,
|
||||
code_from_vector_float,
|
||||
code_from_vector_string,
|
||||
code_from_vector_boolean,
|
||||
code_from_vector_char,
|
||||
code_from_exec,
|
||||
]
|
||||
}
|
||||
|
@ -303,75 +303,6 @@ where
|
||||
make_instruction!(int, int, _square, i128, 1);
|
||||
make_instruction!(float, float, _square, Decimal, 1);
|
||||
|
||||
/// A list of all of the defined int functions in this file.
|
||||
/// Must manually register functions in this list if added.
|
||||
pub fn int_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
int_add,
|
||||
int_sub,
|
||||
int_mult,
|
||||
int_div,
|
||||
int_rem,
|
||||
int_max,
|
||||
int_min,
|
||||
int_inc,
|
||||
int_dec,
|
||||
int_lt,
|
||||
int_gt,
|
||||
int_lte,
|
||||
int_gte,
|
||||
int_sin,
|
||||
int_arcsin,
|
||||
int_cos,
|
||||
int_arccos,
|
||||
int_tan,
|
||||
int_arctan,
|
||||
int_from_float,
|
||||
int_from_boolean,
|
||||
int_log,
|
||||
int_exp,
|
||||
int_sqrt,
|
||||
int_inv,
|
||||
int_abs,
|
||||
int_sign_reverse,
|
||||
int_square,
|
||||
]
|
||||
}
|
||||
|
||||
/// All of the float instructions declared in this file.
|
||||
pub fn float_instructions() -> Vec<fn(&mut PushState)> {
|
||||
vec![
|
||||
float_add,
|
||||
float_sub,
|
||||
float_mult,
|
||||
float_div,
|
||||
float_rem,
|
||||
float_max,
|
||||
float_min,
|
||||
float_inc,
|
||||
float_dec,
|
||||
float_lt,
|
||||
float_gt,
|
||||
float_lte,
|
||||
float_gte,
|
||||
float_sin,
|
||||
float_arcsin,
|
||||
float_cos,
|
||||
float_arccos,
|
||||
float_tan,
|
||||
float_arctan,
|
||||
float_from_int,
|
||||
float_from_boolean,
|
||||
float_log,
|
||||
float_exp,
|
||||
float_sqrt,
|
||||
float_inv,
|
||||
float_abs,
|
||||
float_sign_reverse,
|
||||
float_square,
|
||||
]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
67
src/main.rs
67
src/main.rs
@ -1,57 +1,22 @@
|
||||
use crate::instructions::vector::_replace;
|
||||
use crate::push::state::{EMPTY_STATE, PushState};
|
||||
use instructions::utils::NumericTrait;
|
||||
use rust_decimal::MathematicalOps;
|
||||
use rust_decimal::prelude::*;
|
||||
use crate::instructions::*;
|
||||
use crate::push::state::EMPTY_STATE;
|
||||
|
||||
mod instructions;
|
||||
mod push;
|
||||
|
||||
fn test_func() {}
|
||||
fn another_test_func() {}
|
||||
|
||||
fn main() {
|
||||
// let sixth_pi = Decimal::PI / dec!(6.0);
|
||||
// let result = dec!(1).sin();
|
||||
// let result = Decimal::PI.sin().checked_div(Decimal::PI.cos());
|
||||
// let result = dec!(1.0) / Decimal::HALF_PI.sin();
|
||||
// let result = sixth_pi.sin();
|
||||
// let result = Decimal::HALF_PI.cos();
|
||||
// let result = Decimal::PI.sin();
|
||||
// let result = Decimal::PI.tan();
|
||||
// let result = dec!(1.0) / Decimal::QUARTER_PI.tan();
|
||||
// let result = dec!(1.0) / Decimal::QUARTER_PI.cos();
|
||||
// let result = dec!(1.2).checked_exp();
|
||||
// let result = dec!(2).log10();
|
||||
/*let result = vec![0, 1, 2];
|
||||
let r_len = result.len();
|
||||
let fin_result = &result[..r_len - 1];
|
||||
println!("{fin_result:?}");*/
|
||||
|
||||
// println!("{result:?}");
|
||||
// println!("{sixth_pi}");
|
||||
|
||||
// casting a function call to a usize is a way to
|
||||
// test for function equality.
|
||||
// let test_func_result = test_func as usize == test_func as usize;
|
||||
// println!("{test_func_result}");
|
||||
|
||||
//let temp_vec = vec![0, 1, 2, 3];
|
||||
//temp_vec[0..9].to_vec();
|
||||
|
||||
//let res = 3 % 2;
|
||||
//println!("res is {res}");
|
||||
|
||||
//let mut test_vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
//test_vec.drain(..15);
|
||||
//println!("{:?}", test_vec);
|
||||
|
||||
//let test_state = EMPTY_STATE;
|
||||
//println!("{}", test_state.int == test_state.boolean);
|
||||
/*println!(
|
||||
"{}",
|
||||
std::any::type_name::<PushState>() == std::any::type_name::<PushState>()
|
||||
);*/
|
||||
|
||||
let temp: Option<Vec<i128>> = _replace(vec![vec![1, 2, 3]], vec![1, 2]);
|
||||
// These need to stay so linter doesn't go crazy.
|
||||
int_instructions();
|
||||
float_instructions();
|
||||
string_instructions();
|
||||
boolean_instructions();
|
||||
char_instructions();
|
||||
vector_int_instructions();
|
||||
vector_float_instructions();
|
||||
vector_string_instructions();
|
||||
vector_boolean_instructions();
|
||||
vector_char_instructions();
|
||||
exec_instructions();
|
||||
code_instructions();
|
||||
let _empty_state = EMPTY_STATE;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ pub fn gene_to_stack(state: &mut PushState, gene: Gene) {
|
||||
/// TODO: Decide where to place loading in a push program.
|
||||
pub fn interpret_program(state: &mut PushState, step_limit: usize, max_stack_size: usize) {
|
||||
let mut steps: usize = 0;
|
||||
while state.exec.len() > 0 && steps < step_limit {
|
||||
while !state.exec.is_empty() && steps < step_limit {
|
||||
if let Some(gene) = state.exec.pop() {
|
||||
gene_to_stack(state, gene);
|
||||
steps += 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user