saving remaining before

This commit is contained in:
2023-02-28 01:14:03 -05:00
parent 4752dde4af
commit af2fb537c7
2 changed files with 30 additions and 15 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(|| {