Compare commits

..

3 Commits

3 changed files with 65 additions and 21 deletions

View File

@@ -155,7 +155,10 @@ impl fmt::Display for MarkedForm {
MarkedForm::PrimComb { name, wrap_level, .. } => write!(f, "<{}{}>", name, wrap_level),
//MarkedForm::DeriComb { ids, se, de, id, wrap_level, sequence_params, rest_params, body } => write!(f, "{:?}#[{}/{:?}/{:?}/{}/{:?}/{:?}/{}]", ids, se, de, id, wrap_level, sequence_params, rest_params, body),
MarkedForm::DeriComb { hash, lookup_name, ids, se, de, id, wrap_level, sequence_params, rest_params, body } => write!(f, "{:?}#[{:?}/{:?}/{:?}/{}/{:?}/{:?}/{}]", ids, lookup_name, de, id, wrap_level, sequence_params, rest_params, body),
MarkedForm::DeriComb { hash, lookup_name, ids, se, de, id, wrap_level, sequence_params, rest_params, body } => {
//let env_form = format!("{}", se);
write!(f, "{:?}#[{:?}/{:?}/{:?}/{}/{:?}/{:?}/{}]", ids, lookup_name, de, id, wrap_level, sequence_params, rest_params, body)
},
MarkedForm::SuspendedPair{ hash, ids, attempted, car, cdr } => {
//write!(f, "{:?}{:?}#{{{}", ids, attempted, car)?;
@@ -439,6 +442,13 @@ impl NeededIds {
NeededIds::Some(set,under) => false,
}
}
fn is_true(&self) -> bool {
match self {
NeededIds::True( under) => true,
NeededIds::None( under) => false,
NeededIds::Some(set,under) => false,
}
}
fn under(&self) -> &BTreeSet<EnvID> {
match self {
NeededIds::True(under) => under,
@@ -1207,6 +1217,7 @@ fn partial_eval_step(x: &Rc<MarkedForm>, forced: bool, bctx: BCtx, dctx: &mut DC
//match dctx.copy_push_hash(new_if_hash.clone()) {
//Ok(dctx) => {
//println!("SIF hash fine, doing both subs");
let dctx = dctx.copy_push_fake_if();
let (bctx, t) = partial_eval(bctx, dctx.clone(), Rc::clone(t));
let (bctx, e) = partial_eval(bctx, dctx.clone(), Rc::clone(e));
Ok((bctx, false, MarkedForm::new_suspended_if(c,t,e, None)))
@@ -1221,6 +1232,7 @@ fn partial_eval_step(x: &Rc<MarkedForm>, forced: bool, bctx: BCtx, dctx: &mut DC
MarkedForm::DeriComb { hash, lookup_name, ids, se, de, id, wrap_level, sequence_params, rest_params, body } => {
// TODO: figure out wrap level, sequence params, etc
if forced || !se.ids().needs_nothing() {
//if ids.is_true() || !se.ids().needs_nothing() {
let old_se_ids = se.ids();
let se = if !se.ids().needs_nothing() {
// the current env is our new se
@@ -1233,13 +1245,15 @@ fn partial_eval_step(x: &Rc<MarkedForm>, forced: bool, bctx: BCtx, dctx: &mut DC
match dctx.copy_push_frame(id.clone(), &se, &de, None, &rest_params, None, body) {
Ok(inner_dctx) => {
//println!("{:ident$}Doing a body deri for {:?} because ({} || {:?}) which is {}", "", lookup_name, forced, old_se_ids, x, ident=ident_amount);
println!("{:ident$}Doing a body deri for {:?} because ({} || {:?}) which is {}", "", lookup_name, forced, old_se_ids, x, ident=ident_amount);
println!("{:ident$}and also body ids is {:?}", "", body.ids(), ident=ident_amount);
//println!("{:ident$}and fake is {:?} and fake_if is {:?}", "", , ident=ident_amount);
let (bctx, body) = partial_eval(bctx, inner_dctx, Rc::clone(&body));
//println!("{:ident$}result was {}", "", body, ident=ident_amount);
println!("{:ident$}result was {}", "", body, ident=ident_amount);
Ok((bctx, false, MarkedForm::new_deri_comb(se, lookup_name.clone(), de.clone(), id.clone(), *wrap_level, sequence_params.clone(), rest_params.clone(), body, None)))
},
Err(rec_stop_under) => {
//println!("{:ident$}call of {:?} failed b/c rec_stop_hash", "", lookup_name, ident=dctx.ident*4);
println!("{:ident$}call of {:?} failed b/c rec_stop_under", "", lookup_name, ident=dctx.ident*4);
//maybe_rec_hash = Some(rec_stop_hash);
// TODO: should this mark the hash on DeriComb?
//Err("recursion stopped in dericomb".to_owned())
@@ -1298,6 +1312,7 @@ fn partial_eval_step(x: &Rc<MarkedForm>, forced: bool, bctx: BCtx, dctx: &mut DC
Ok((bctxp, r)) => {
// force true b/c might be a tail call
return Ok((bctx, true, r));
//return Ok((bctx, name == "eval" || name == "if", r));
},
Err(msg) => {
println!("{:ident$} call to {} failed {:?}", "", name, msg, ident=ident_amount);

View File

@@ -390,19 +390,19 @@ static BVAU: Lazy<String> = Lazy::new(|| {
#[test]
fn bvau_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
eval_test(true, &g, &e, &format!("{} ((bvau _ (a b c) (+ a (- b c))) 10 2 3)", *BVAU), 9);
eval_test(true, &g, &e, &format!("{} ((bvau (a b c) (+ a (- b c))) 10 2 3)", *BVAU), 9);
//eval_test(true, &g, &e, &format!("{} ((bvau (a b c) (+ a (- b c))) 10 2 3)", *BVAU), 9);
eval_test(true, &g, &e, &format!("{} ((bvau (a b . c) c) 10 2 3)", *BVAU), (3, Form::Nil));
eval_test(true, &g, &e, &format!("{} ((bvau (a b . c) c) 10 2)", *BVAU), Form::Nil);
eval_test(true, &g, &e, &format!("{} ((bvau (a b . c) c) 10 2 3 4 5)", *BVAU), (3, (4, (5, Form::Nil))));
eval_test(true, &g, &e, &format!("{} ((bvau c c) 3 4 5)", *BVAU), (3, (4, (5, Form::Nil))));
eval_test(true, &g, &e, &format!("{} ((bvau c c))", *BVAU), Form::Nil);
eval_test(true, &g, &e, &format!("{} ((bvau ((a b) . c) c) (10 2) 3 4 5)", *BVAU), (3, (4, (5, Form::Nil))));
eval_test(true, &g, &e, &format!("{} ((bvau ((a b) . c) a) (10 2) 3 4 5)", *BVAU), 10);
eval_test(true, &g, &e, &format!("{} ((bvau ((a b) . c) b) (10 2) 3 4 5)", *BVAU), 2);
//eval_test(true, &g, &e, &format!("{} ((bvau (a b . c) c) 10 2 3)", *BVAU), (3, Form::Nil));
//eval_test(true, &g, &e, &format!("{} ((bvau (a b . c) c) 10 2)", *BVAU), Form::Nil);
//eval_test(true, &g, &e, &format!("{} ((bvau (a b . c) c) 10 2 3 4 5)", *BVAU), (3, (4, (5, Form::Nil))));
//eval_test(true, &g, &e, &format!("{} ((bvau c c) 3 4 5)", *BVAU), (3, (4, (5, Form::Nil))));
//eval_test(true, &g, &e, &format!("{} ((bvau c c))", *BVAU), Form::Nil);
//eval_test(true, &g, &e, &format!("{} ((bvau ((a b) . c) c) (10 2) 3 4 5)", *BVAU), (3, (4, (5, Form::Nil))));
//eval_test(true, &g, &e, &format!("{} ((bvau ((a b) . c) a) (10 2) 3 4 5)", *BVAU), 10);
//eval_test(true, &g, &e, &format!("{} ((bvau ((a b) . c) b) (10 2) 3 4 5)", *BVAU), 2);
eval_test(true, &g, &e, &format!("{} ((wrap (bvau _ (a b c) (+ a (- b c)))) (+ 10 1) (+ 2 2) (+ 5 3))", *BVAU), 7);
eval_test(true, &g, &e, &format!("{} ((wrap (bvau (a b c) (+ a (- b c)))) (+ 10 1) (+ 2 2) (+ 5 3))", *BVAU), 7);
//eval_test(true, &g, &e, &format!("{} ((wrap (bvau _ (a b c) (+ a (- b c)))) (+ 10 1) (+ 2 2) (+ 5 3))", *BVAU), 7);
//eval_test(true, &g, &e, &format!("{} ((wrap (bvau (a b c) (+ a (- b c)))) (+ 10 1) (+ 2 2) (+ 5 3))", *BVAU), 7);
}
static LAMBDA: Lazy<String> = Lazy::new(|| {

View File

@@ -677,8 +677,7 @@
(drop_redundent_veval (rec-lambda drop_redundent_veval (partial_eval_helper x de env_stack pectx indent) (dlet (
(env_id (.marked_env_id de))
(r (if
(and (marked_array? x)
(not (.marked_array_is_val x)))
(and (marked_array? x) (not (.marked_array_is_val x)))
(if (and (prim_comb? (idx (.marked_array_values x) 0))
(= 'veval (.prim_comb_sym (idx (.marked_array_values x) 0)))
(= 3 (len (.marked_array_values x)))
@@ -1863,6 +1862,10 @@
(global '$num_sbrks '(mut i32) (i32.const 0))
(global '$num_frees '(mut i32) (i32.const 0))
(global '$num_evals '(mut i32) (i32.const 0))
(global '$num_compiled_dzero '(mut i32) (i32.const 0))
(global '$num_compiled_done '(mut i32) (i32.const 0))
(global '$num_array_innerdrops '(mut i32) (i32.const 0))
(global '$num_env_innerdrops '(mut i32) (i32.const 0))
(global '$num_array_subdrops '(mut i32) (i32.const 0))
@@ -4166,6 +4169,7 @@
((k_eval func_idx funcs) (array func_idx (+ 1 func_idx) (concat funcs (func '$eval '(param $p i64) '(param $d i64) '(param $s i64) '(result i64) '(local $len i32) '(local $ptr i32) '(local $rc_bytes i64) '(local $rc_ptr i32) '(local $rc_tmp i32)
(ensure_not_op_n_params_set_ptr_len i32.lt_u 1)
(global.set '$num_evals (i32.add (i32.const 1) (global.get '$num_evals)))
(_if '$using_d_env '(result i64)
(i32.eq (i32.const 1) (local.get '$len))
(then
@@ -5671,11 +5675,17 @@
(local.tee '$tmp)
(_if '$is_wrap_0
(is_wrap_code 0 (local.get '$tmp))
(then wrap_0_param_code)
(then
(global.set '$num_compiled_dzero (i32.add (i32.const 1) (global.get '$num_compiled_dzero)))
wrap_0_param_code
)
(else
(_if '$is_wrap_1
(is_wrap_code 1 (local.get '$tmp))
(then wrap_1_param_code)
(then
(global.set '$num_compiled_done (i32.add (i32.const 1) (global.get '$num_compiled_done)))
wrap_1_param_code
)
(else wrap_x_param_code)
)
)
@@ -6371,6 +6381,25 @@
(mk_int_code_i32s (global.get '$num_mallocs))
(mk_int_code_i32s (global.get '$num_sbrks))
(mk_int_code_i32s (global.get '$num_compiled_dzero))
(mk_int_code_i32s (global.get '$num_compiled_done))
(mk_int_code_i32s (global.get '$num_evals))
(call '$print (i64.const newline_msg_val))
(call '$print (i64.const newline_msg_val))
(call '$print (i64.const newline_msg_val))
(call '$print (i64.const newline_msg_val))
(call '$print )
(call '$print (i64.const newline_msg_val))
(call '$print )
(call '$print (i64.const newline_msg_val))
(call '$print )
(call '$print (i64.const newline_msg_val))
(call '$print (i64.const newline_msg_val))
(call '$print (i64.const newline_msg_val))
(call '$print (i64.const newline_msg_val))
(call '$print (i64.const newline_msg_val))
(call '$print )
(call '$print (i64.const newline_msg_val))