start accounting for pure/impure builtins

Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
Ava Apples Affine 2024-06-12 11:13:34 -07:00
parent 2809569c35
commit 143173f046
6 changed files with 38 additions and 0 deletions

View file

@ -199,6 +199,7 @@ pub fn add_list_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: CONS_DOCSTRING.to_string(), docs: CONS_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(cons_callback)), value: ValueType::Internal(Rc::new(cons_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -211,6 +212,7 @@ pub fn add_list_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: LEN_DOCSTRING.to_string(), docs: LEN_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(len_callback)), value: ValueType::Internal(Rc::new(len_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -223,6 +225,7 @@ pub fn add_list_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: CAR_DOCSTRING.to_string(), docs: CAR_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(car_callback)), value: ValueType::Internal(Rc::new(car_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -235,6 +238,7 @@ pub fn add_list_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: CDR_DOCSTRING.to_string(), docs: CDR_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(cdr_callback)), value: ValueType::Internal(Rc::new(cdr_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -247,6 +251,7 @@ pub fn add_list_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: POP_DOCSTRING.to_string(), docs: POP_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(pop_callback)), value: ValueType::Internal(Rc::new(pop_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -259,6 +264,7 @@ pub fn add_list_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: DEQUEUE_DOCSTRING.to_string(), docs: DEQUEUE_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(dequeue_callback)), value: ValueType::Internal(Rc::new(dequeue_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -271,6 +277,7 @@ pub fn add_list_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: REVERSE_DOCSTRING.to_string(), docs: REVERSE_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(reverse_callback)), value: ValueType::Internal(Rc::new(reverse_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -283,6 +290,7 @@ pub fn add_list_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: ISLIST_DOCSTRING.to_string(), docs: ISLIST_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(islist_callback)), value: ValueType::Internal(Rc::new(islist_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );

View file

@ -150,6 +150,7 @@ pub fn add_bool_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: AND_DOCSTRING.to_string(), docs: AND_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(and_callback)), value: ValueType::Internal(Rc::new(and_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -162,6 +163,7 @@ pub fn add_bool_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: BOOLCAST_DOCSTRING.to_string(), docs: BOOLCAST_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(boolcast_callback)), value: ValueType::Internal(Rc::new(boolcast_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -174,6 +176,7 @@ pub fn add_bool_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: OR_DOCSTRING.to_string(), docs: OR_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(or_callback)), value: ValueType::Internal(Rc::new(or_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -186,6 +189,7 @@ pub fn add_bool_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: NOT_DOCSTRING.to_string(), docs: NOT_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(not_callback)), value: ValueType::Internal(Rc::new(not_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -198,6 +202,7 @@ pub fn add_bool_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: ISEQ_DOCSTRING.to_string(), docs: ISEQ_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(iseq_callback)), value: ValueType::Internal(Rc::new(iseq_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );

View file

@ -432,6 +432,7 @@ pub fn add_control_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: ASSERT_DOCSTRING.to_string(), docs: ASSERT_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(assert_callback)), value: ValueType::Internal(Rc::new(assert_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -444,6 +445,7 @@ pub fn add_control_lib(syms: &mut SymTable) {
conditional_branches: true, conditional_branches: true,
docs: IF_DOCSTRING.to_string(), docs: IF_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(if_callback)), value: ValueType::Internal(Rc::new(if_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -480,6 +482,7 @@ pub fn add_control_lib(syms: &mut SymTable) {
conditional_branches: true, conditional_branches: true,
docs: CIRCUIT_DOCSTRING.to_string(), docs: CIRCUIT_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(circuit_callback)), value: ValueType::Internal(Rc::new(circuit_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );

View file

@ -532,6 +532,7 @@ pub fn add_math_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: ADD_DOCSTRING.to_string(), docs: ADD_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(add_callback)), value: ValueType::Internal(Rc::new(add_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -544,6 +545,7 @@ pub fn add_math_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: SUB_DOCSTRING.to_string(), docs: SUB_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(sub_callback)), value: ValueType::Internal(Rc::new(sub_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -556,6 +558,7 @@ pub fn add_math_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: DIV_DOCSTRING.to_string(), docs: DIV_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(div_callback)), value: ValueType::Internal(Rc::new(div_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -568,6 +571,7 @@ pub fn add_math_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: MUL_DOCSTRING.to_string(), docs: MUL_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(mul_callback)), value: ValueType::Internal(Rc::new(mul_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -580,6 +584,7 @@ pub fn add_math_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: INTCAST_DOCSTRING.to_string(), docs: INTCAST_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(intcast_callback)), value: ValueType::Internal(Rc::new(intcast_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -592,6 +597,7 @@ pub fn add_math_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: FLOATCAST_DOCSTRING.to_string(), docs: FLOATCAST_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(floatcast_callback)), value: ValueType::Internal(Rc::new(floatcast_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -603,6 +609,7 @@ pub fn add_math_lib(syms: &mut SymTable) {
args: Args::Lazy(2), args: Args::Lazy(2),
conditional_branches: false, conditional_branches: false,
docs: EXP_DOCSTRING.to_string(), docs: EXP_DOCSTRING.to_string(),
optimizable: true,
value: ValueType::Internal(Rc::new(exp_callback)), value: ValueType::Internal(Rc::new(exp_callback)),
..Default::default() ..Default::default()
}, },
@ -616,6 +623,7 @@ pub fn add_math_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: MOD_DOCSTRING.to_string(), docs: MOD_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(mod_callback)), value: ValueType::Internal(Rc::new(mod_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -628,6 +636,7 @@ pub fn add_math_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: ISGT_DOCSTRING.to_string(), docs: ISGT_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(isgt_callback)), value: ValueType::Internal(Rc::new(isgt_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -640,6 +649,7 @@ pub fn add_math_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: ISLT_DOCSTRING.to_string(), docs: ISLT_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(islt_callback)), value: ValueType::Internal(Rc::new(islt_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -652,6 +662,7 @@ pub fn add_math_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: ISGTE_DOCSTRING.to_string(), docs: ISGTE_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(isgte_callback)), value: ValueType::Internal(Rc::new(isgte_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -664,6 +675,7 @@ pub fn add_math_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: ISLTE_DOCSTRING.to_string(), docs: ISLTE_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(islte_callback)), value: ValueType::Internal(Rc::new(islte_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );

View file

@ -201,6 +201,7 @@ pub fn add_string_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: CONCAT_DOCSTRING.to_string(), docs: CONCAT_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(concat_callback)), value: ValueType::Internal(Rc::new(concat_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -213,6 +214,7 @@ pub fn add_string_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: SUBSTR_DOCSTRING.to_string(), docs: SUBSTR_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(substr_callback)), value: ValueType::Internal(Rc::new(substr_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -225,6 +227,7 @@ pub fn add_string_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: SPLIT_DOCSTRING.to_string(), docs: SPLIT_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(split_callback)), value: ValueType::Internal(Rc::new(split_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -237,6 +240,7 @@ pub fn add_string_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: STRLEN_DOCSTRING.to_string(), docs: STRLEN_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(strlen_callback)), value: ValueType::Internal(Rc::new(strlen_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );
@ -249,6 +253,7 @@ pub fn add_string_lib(syms: &mut SymTable) {
conditional_branches: false, conditional_branches: false,
docs: STRCAST_DOCSTRING.to_string(), docs: STRCAST_DOCSTRING.to_string(),
value: ValueType::Internal(Rc::new(strcast_callback)), value: ValueType::Internal(Rc::new(strcast_callback)),
optimizable: true,
..Default::default() ..Default::default()
}, },
); );

View file

@ -70,6 +70,10 @@ pub struct Symbol {
// see SymTable::Insert // see SymTable::Insert
// (only pub begrudgingly) // (only pub begrudgingly)
pub __generation: usize, pub __generation: usize,
// here this means either that
// a variable is constant or that
// a function is pure.
pub optimizable: bool,
} }
impl SymTable { impl SymTable {
@ -545,6 +549,7 @@ impl Default for Symbol {
args: Args::None, args: Args::None,
conditional_branches: false, conditional_branches: false,
__generation: 0, __generation: 0,
optimizable: false
} }
} }
} }