From 143173f046d8429deb993f04ce4340a5b7e81ff1 Mon Sep 17 00:00:00 2001 From: Ava Affine Date: Wed, 12 Jun 2024 11:13:34 -0700 Subject: [PATCH] start accounting for pure/impure builtins Signed-off-by: Ava Affine --- src/stl/append.rs | 8 ++++++++ src/stl/boolean.rs | 5 +++++ src/stl/control.rs | 3 +++ src/stl/math.rs | 12 ++++++++++++ src/stl/strings.rs | 5 +++++ src/sym.rs | 5 +++++ 6 files changed, 38 insertions(+) diff --git a/src/stl/append.rs b/src/stl/append.rs index c6fe64d..bc9f188 100644 --- a/src/stl/append.rs +++ b/src/stl/append.rs @@ -199,6 +199,7 @@ pub fn add_list_lib(syms: &mut SymTable) { conditional_branches: false, docs: CONS_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(cons_callback)), + optimizable: true, ..Default::default() }, ); @@ -211,6 +212,7 @@ pub fn add_list_lib(syms: &mut SymTable) { conditional_branches: false, docs: LEN_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(len_callback)), + optimizable: true, ..Default::default() }, ); @@ -223,6 +225,7 @@ pub fn add_list_lib(syms: &mut SymTable) { conditional_branches: false, docs: CAR_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(car_callback)), + optimizable: true, ..Default::default() }, ); @@ -235,6 +238,7 @@ pub fn add_list_lib(syms: &mut SymTable) { conditional_branches: false, docs: CDR_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(cdr_callback)), + optimizable: true, ..Default::default() }, ); @@ -247,6 +251,7 @@ pub fn add_list_lib(syms: &mut SymTable) { conditional_branches: false, docs: POP_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(pop_callback)), + optimizable: true, ..Default::default() }, ); @@ -259,6 +264,7 @@ pub fn add_list_lib(syms: &mut SymTable) { conditional_branches: false, docs: DEQUEUE_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(dequeue_callback)), + optimizable: true, ..Default::default() }, ); @@ -271,6 +277,7 @@ pub fn add_list_lib(syms: &mut SymTable) { conditional_branches: false, docs: REVERSE_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(reverse_callback)), + optimizable: true, ..Default::default() }, ); @@ -283,6 +290,7 @@ pub fn add_list_lib(syms: &mut SymTable) { conditional_branches: false, docs: ISLIST_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(islist_callback)), + optimizable: true, ..Default::default() }, ); diff --git a/src/stl/boolean.rs b/src/stl/boolean.rs index 62437db..a448f14 100644 --- a/src/stl/boolean.rs +++ b/src/stl/boolean.rs @@ -150,6 +150,7 @@ pub fn add_bool_lib(syms: &mut SymTable) { conditional_branches: false, docs: AND_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(and_callback)), + optimizable: true, ..Default::default() }, ); @@ -162,6 +163,7 @@ pub fn add_bool_lib(syms: &mut SymTable) { conditional_branches: false, docs: BOOLCAST_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(boolcast_callback)), + optimizable: true, ..Default::default() }, ); @@ -174,6 +176,7 @@ pub fn add_bool_lib(syms: &mut SymTable) { conditional_branches: false, docs: OR_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(or_callback)), + optimizable: true, ..Default::default() }, ); @@ -186,6 +189,7 @@ pub fn add_bool_lib(syms: &mut SymTable) { conditional_branches: false, docs: NOT_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(not_callback)), + optimizable: true, ..Default::default() }, ); @@ -198,6 +202,7 @@ pub fn add_bool_lib(syms: &mut SymTable) { conditional_branches: false, docs: ISEQ_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(iseq_callback)), + optimizable: true, ..Default::default() }, ); diff --git a/src/stl/control.rs b/src/stl/control.rs index 0d45cce..3db0644 100644 --- a/src/stl/control.rs +++ b/src/stl/control.rs @@ -432,6 +432,7 @@ pub fn add_control_lib(syms: &mut SymTable) { conditional_branches: false, docs: ASSERT_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(assert_callback)), + optimizable: true, ..Default::default() }, ); @@ -444,6 +445,7 @@ pub fn add_control_lib(syms: &mut SymTable) { conditional_branches: true, docs: IF_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(if_callback)), + optimizable: true, ..Default::default() }, ); @@ -480,6 +482,7 @@ pub fn add_control_lib(syms: &mut SymTable) { conditional_branches: true, docs: CIRCUIT_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(circuit_callback)), + optimizable: true, ..Default::default() }, ); diff --git a/src/stl/math.rs b/src/stl/math.rs index ecd491b..193d62f 100644 --- a/src/stl/math.rs +++ b/src/stl/math.rs @@ -532,6 +532,7 @@ pub fn add_math_lib(syms: &mut SymTable) { conditional_branches: false, docs: ADD_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(add_callback)), + optimizable: true, ..Default::default() }, ); @@ -544,6 +545,7 @@ pub fn add_math_lib(syms: &mut SymTable) { conditional_branches: false, docs: SUB_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(sub_callback)), + optimizable: true, ..Default::default() }, ); @@ -556,6 +558,7 @@ pub fn add_math_lib(syms: &mut SymTable) { conditional_branches: false, docs: DIV_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(div_callback)), + optimizable: true, ..Default::default() }, ); @@ -568,6 +571,7 @@ pub fn add_math_lib(syms: &mut SymTable) { conditional_branches: false, docs: MUL_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(mul_callback)), + optimizable: true, ..Default::default() }, ); @@ -580,6 +584,7 @@ pub fn add_math_lib(syms: &mut SymTable) { conditional_branches: false, docs: INTCAST_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(intcast_callback)), + optimizable: true, ..Default::default() }, ); @@ -592,6 +597,7 @@ pub fn add_math_lib(syms: &mut SymTable) { conditional_branches: false, docs: FLOATCAST_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(floatcast_callback)), + optimizable: true, ..Default::default() }, ); @@ -603,6 +609,7 @@ pub fn add_math_lib(syms: &mut SymTable) { args: Args::Lazy(2), conditional_branches: false, docs: EXP_DOCSTRING.to_string(), + optimizable: true, value: ValueType::Internal(Rc::new(exp_callback)), ..Default::default() }, @@ -616,6 +623,7 @@ pub fn add_math_lib(syms: &mut SymTable) { conditional_branches: false, docs: MOD_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(mod_callback)), + optimizable: true, ..Default::default() }, ); @@ -628,6 +636,7 @@ pub fn add_math_lib(syms: &mut SymTable) { conditional_branches: false, docs: ISGT_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(isgt_callback)), + optimizable: true, ..Default::default() }, ); @@ -640,6 +649,7 @@ pub fn add_math_lib(syms: &mut SymTable) { conditional_branches: false, docs: ISLT_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(islt_callback)), + optimizable: true, ..Default::default() }, ); @@ -652,6 +662,7 @@ pub fn add_math_lib(syms: &mut SymTable) { conditional_branches: false, docs: ISGTE_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(isgte_callback)), + optimizable: true, ..Default::default() }, ); @@ -664,6 +675,7 @@ pub fn add_math_lib(syms: &mut SymTable) { conditional_branches: false, docs: ISLTE_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(islte_callback)), + optimizable: true, ..Default::default() }, ); diff --git a/src/stl/strings.rs b/src/stl/strings.rs index 3fe370a..b0fb109 100644 --- a/src/stl/strings.rs +++ b/src/stl/strings.rs @@ -201,6 +201,7 @@ pub fn add_string_lib(syms: &mut SymTable) { conditional_branches: false, docs: CONCAT_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(concat_callback)), + optimizable: true, ..Default::default() }, ); @@ -213,6 +214,7 @@ pub fn add_string_lib(syms: &mut SymTable) { conditional_branches: false, docs: SUBSTR_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(substr_callback)), + optimizable: true, ..Default::default() }, ); @@ -225,6 +227,7 @@ pub fn add_string_lib(syms: &mut SymTable) { conditional_branches: false, docs: SPLIT_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(split_callback)), + optimizable: true, ..Default::default() }, ); @@ -237,6 +240,7 @@ pub fn add_string_lib(syms: &mut SymTable) { conditional_branches: false, docs: STRLEN_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(strlen_callback)), + optimizable: true, ..Default::default() }, ); @@ -249,6 +253,7 @@ pub fn add_string_lib(syms: &mut SymTable) { conditional_branches: false, docs: STRCAST_DOCSTRING.to_string(), value: ValueType::Internal(Rc::new(strcast_callback)), + optimizable: true, ..Default::default() }, ); diff --git a/src/sym.rs b/src/sym.rs index 6d015f4..6a2d968 100644 --- a/src/sym.rs +++ b/src/sym.rs @@ -70,6 +70,10 @@ pub struct Symbol { // see SymTable::Insert // (only pub begrudgingly) pub __generation: usize, + // here this means either that + // a variable is constant or that + // a function is pure. + pub optimizable: bool, } impl SymTable { @@ -545,6 +549,7 @@ impl Default for Symbol { args: Args::None, conditional_branches: false, __generation: 0, + optimizable: false } } }