Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New application #959

Merged
merged 10 commits into from
Dec 20, 2023
2 changes: 1 addition & 1 deletion examples/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn fib_expr<F: LurkField>(store: &Store<F>) -> Ptr {
// The env output in the `fib_frame`th frame of the above, infinite Fibonacci computation contains a binding of the
// nth Fibonacci number to `a`.
fn fib_frame(n: usize) -> usize {
11 + 16 * n
11 + 10 * n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the fibonacci benchmark needs to be updated to reflect this change also.

}

// Set the limit so the last step will be filled exactly, since Lurk currently only pads terminal/error continuations.
Expand Down
266 changes: 104 additions & 162 deletions src/lem/eval.rs

Large diffs are not rendered by default.

32 changes: 10 additions & 22 deletions src/lem/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ impl<F: LurkField> Store<F> {

#[inline]
pub fn intern_fun(&self, arg: Ptr, body: Ptr, env: Ptr) -> Ptr {
self.intern_3_ptrs(Tag::Expr(Fun), arg, body, env)
self.intern_4_ptrs(Tag::Expr(Fun), arg, body, env, self.dummy())
}

#[inline]
Expand Down Expand Up @@ -1007,32 +1007,20 @@ impl Ptr {
"<Malformed U64>".into()
}
}
Fun => match self.get_index3() {
Fun => match self.get_index4() {
None => "<Malformed Fun>".into(),
Some(idx) => {
if let Some((arg, bod, _)) = store.fetch_3_ptrs(idx) {
match bod.tag() {
if let Some((vars, body, ..)) = store.fetch_4_ptrs(idx) {
match vars.tag() {
Tag::Expr(Nil) => {
format!(
"<FUNCTION ({}) {}>",
arg.fmt_to_string(store, state),
bod.fmt_to_string(store, state)
)
format!("<FUNCTION () {}>", body.fmt_to_string(store, state))
}
Tag::Expr(Cons) => {
if let Some(idx) = bod.get_index2() {
if let Some((bod, _)) = store.fetch_2_ptrs(idx) {
format!(
"<FUNCTION ({}) {}>",
arg.fmt_to_string(store, state),
bod.fmt_to_string(store, state)
)
} else {
"<Opaque Fun>".into()
}
} else {
"<Malformed Fun>".into()
}
format!(
"<FUNCTION {} {}>",
vars.fmt_to_string(store, state),
body.fmt_to_string(store, state)
)
}
_ => "<Malformed Fun>".into(),
}
Expand Down
75 changes: 37 additions & 38 deletions src/lem/tests/eval_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ fn evaluate_lambda2() {
None,
Some(terminal),
None,
&expect!["9"],
&expect!["8"],
&None,
);
}
Expand Down Expand Up @@ -339,7 +339,7 @@ fn evaluate_lambda5() {
None,
Some(terminal),
None,
&expect!["13"],
&expect!["11"],
&None,
);
}
Expand Down Expand Up @@ -481,7 +481,7 @@ fn evaluate_adder1() {
None,
Some(terminal),
None,
&expect!["13"],
&expect!["10"],
&None,
);
}
Expand All @@ -502,7 +502,7 @@ fn evaluate_adder2() {
None,
Some(terminal),
None,
&expect!["15"],
&expect!["12"],
&None,
);
}
Expand Down Expand Up @@ -561,7 +561,7 @@ fn evaluate_let() {
None,
Some(terminal),
None,
&expect!["10"],
&expect!["8"],
&None,
);
}
Expand Down Expand Up @@ -658,7 +658,7 @@ fn evaluate_arithmetic_let() {
Some(new_env),
Some(terminal),
None,
&expect!["18"],
&expect!["15"],
&None,
);
}
Expand Down Expand Up @@ -689,7 +689,7 @@ fn evaluate_fundamental_conditional() {
None,
Some(terminal),
None,
&expect!["35"],
&expect!["28"],
&None,
);
}
Expand All @@ -716,7 +716,7 @@ fn evaluate_fundamental_conditional() {
None,
Some(terminal),
None,
&expect!["32"],
&expect!["26"],
&None,
);
}
Expand Down Expand Up @@ -800,7 +800,7 @@ fn evaluate_recursion1() {
None,
Some(terminal),
None,
&expect!["91"],
&expect!["76"],
&None,
);
}
Expand All @@ -825,7 +825,7 @@ fn evaluate_recursion2() {
None,
Some(terminal),
None,
&expect!["201"],
&expect!["163"],
&None,
);
}
Expand All @@ -848,7 +848,7 @@ fn evaluate_recursion_multiarg() {
None,
Some(terminal),
None,
&expect!["95"],
&expect!["68"],
&None,
);
}
Expand All @@ -874,7 +874,7 @@ fn evaluate_recursion_optimized() {
None,
Some(terminal),
None,
&expect!["75"],
&expect!["66"],
&None,
);
}
Expand All @@ -899,7 +899,7 @@ fn evaluate_tail_recursion() {
None,
Some(terminal),
None,
&expect!["129"],
&expect!["105"],
&None,
);
}
Expand Down Expand Up @@ -927,7 +927,7 @@ fn evaluate_tail_recursion_somewhat_optimized() {
None,
Some(terminal),
None,
&expect!["110"],
&expect!["92"],
&None,
);
}
Expand All @@ -948,7 +948,7 @@ fn evaluate_multiple_letrec_bindings() {
None,
Some(terminal),
None,
&expect!["22"],
&expect!["20"],
&None,
);
}
Expand All @@ -969,7 +969,7 @@ fn evaluate_multiple_letrec_bindings_referencing() {
None,
Some(terminal),
None,
&expect!["31"],
&expect!["28"],
&None,
);
}
Expand Down Expand Up @@ -1001,7 +1001,7 @@ fn evaluate_multiple_letrec_bindings_recursive() {
None,
Some(terminal),
None,
&expect!["242"],
&expect!["175"],
&None,
);
}
Expand All @@ -1025,7 +1025,7 @@ fn nested_let_closure_regression() {
None,
Some(terminal),
None,
&expect!["13"],
&expect!["11"],
&None,
);
}
Expand All @@ -1042,7 +1042,7 @@ fn nested_let_closure_regression() {
None,
Some(terminal),
None,
&expect!["14"],
&expect!["11"],
&None,
);
}
Expand Down Expand Up @@ -1142,11 +1142,10 @@ fn evaluate_zero_arg_lambda() {
}
{
let expected = {
let arg = s.intern_user_symbol("x");
let args = s.list(vec![s.intern_user_symbol("x")]);
let num = s.num_u64(123);
let body = s.list(vec![num]);
let env = s.intern_nil();
s.intern_fun(arg, body, env)
s.intern_fun(args, num, env)
};

// One arg expected but zero supplied.
Expand All @@ -1173,7 +1172,7 @@ fn evaluate_zero_arg_lambda() {
None,
Some(terminal),
None,
&expect!["12"],
&expect!["10"],
&None,
);
}
Expand All @@ -1186,7 +1185,7 @@ fn evaluate_zero_arg_lambda_variants() {
let expr = "((lambda () 123) 1)";

let error = s.cont_error();
test_aux::<Coproc<Fr>>(s, expr, None, None, Some(error), None, &expect!["3"], &None);
test_aux::<Coproc<Fr>>(s, expr, None, None, Some(error), None, &expect!["2"], &None);
}
{
let s = &Store::<Fr>::default();
Expand Down Expand Up @@ -1236,7 +1235,7 @@ fn evaluate_make_tree() {
None,
Some(terminal),
None,
&expect!["493"],
&expect!["445"],
&None,
);
}
Expand Down Expand Up @@ -1282,7 +1281,7 @@ fn evaluate_map_tree_bug() {
None,
Some(terminal),
None,
&expect!["170"],
&expect!["125"],
&None,
);
}
Expand All @@ -1309,7 +1308,7 @@ fn evaluate_map_tree_numequal_bug() {
None,
Some(error),
None,
&expect!["169"],
&expect!["125"],
&None,
);
}
Expand Down Expand Up @@ -1344,7 +1343,7 @@ fn env_lost_bug() {
None,
Some(terminal),
None,
&expect!["25"],
&expect!["22"],
&None,
);
}
Expand All @@ -1369,7 +1368,7 @@ fn dont_discard_rest_env() {
None,
Some(terminal),
None,
&expect!["22"],
&expect!["20"],
&None,
);
}
Expand Down Expand Up @@ -1675,7 +1674,7 @@ fn go_translate() {
None,
None,
None,
&expect!["1114"],
&expect!["840"],
&None,
);
}
Expand Down Expand Up @@ -2389,7 +2388,7 @@ fn test_relational_edge_case_identity() {
None,
Some(terminal),
None,
&expect!["19"],
&expect!["17"],
&None,
);
}
Expand All @@ -2408,7 +2407,7 @@ fn test_relational_edge_case_identity() {
None,
Some(terminal),
None,
&expect!["24"],
&expect!["22"],
&None,
);
}
Expand All @@ -2432,7 +2431,7 @@ fn test_num_syntax_implications() {
None,
Some(terminal),
None,
&expect!["10"],
&expect!["8"],
&None,
);
}
Expand Down Expand Up @@ -2565,7 +2564,7 @@ fn test_quoted_symbols() {
None,
Some(terminal),
None,
&expect!["13"],
&expect!["11"],
&None,
);
}
Expand Down Expand Up @@ -3338,7 +3337,7 @@ fn test_fold_cons_regression() {
None,
Some(terminal),
None,
&expect!["152"],
&expect!["92"],
&None,
);
}
Expand Down Expand Up @@ -3551,7 +3550,7 @@ fn test_eval_lambda_body_syntax() {
None,
Some(error),
None,
&expect!["3"],
&expect!["2"],
&None,
);
test_aux::<Coproc<Fr>>(
Expand All @@ -3561,7 +3560,7 @@ fn test_eval_lambda_body_syntax() {
None,
Some(error),
None,
&expect!["3"],
&expect!["2"],
&None,
);
}
Expand Down Expand Up @@ -3671,7 +3670,7 @@ fn test_dumb_lang() {
None,
Some(terminal),
None,
&expect!["6"],
&expect!["5"],
&Some(&lang),
);
test_aux(
Expand Down
Loading
Loading