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

module system #1020

Open
wants to merge 105 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
1135c5c
copy module from let
gensofubi May 17, 2023
46cbc73
a try on module
gensofubi May 19, 2023
27c2d02
minor changes
gensofubi May 19, 2023
1c66f50
keyword module done
gensofubi May 19, 2023
e07aed2
formatted
gensofubi May 19, 2023
9845316
concrete module typing (but no typeann yet) and dot access operator
gensofubi May 21, 2023
29a4ffe
change the expected def pattern in module to Tag
gensofubi May 24, 2023
b261e45
change dot form to fit submodule
gensofubi May 24, 2023
2bb2e3f
detailed typing information for modules and auto hole-insert fixed
gensofubi May 31, 2023
e8ca644
type annotation for module
gensofubi Jun 1, 2023
4aba625
fit for module with 1 or 0 members
gensofubi Jun 2, 2023
85fa3bd
unsuccessful trial on fixing a bug
gensofubi Jun 7, 2023
3d26edd
partially solve
gensofubi Jun 7, 2023
e1563a6
adjust behavior when module typeann is not consistent with member typ…
gensofubi Jun 7, 2023
0a727c2
adjust the behavior when member names are not consistent with module …
gensofubi Jun 7, 2023
9c8d63e
Merge branch 'adt-defs-after' into haz3l-module
gensofubi Jun 10, 2023
403eac5
again change the expected def pattern in module to Tag
gensofubi Jun 11, 2023
3620771
basic type members
gensofubi Jun 14, 2023
e97369c
add comments
gensofubi Jun 15, 2023
3f7db25
basic type alias in module's annotation
gensofubi Jun 16, 2023
b1c3b6d
change precedence for sum type alias in module annotation
gensofubi Jun 17, 2023
9377765
fix for Tags in module
gensofubi Jun 17, 2023
fc8a9d5
in analitic mode, use constructors without prefix
gensofubi Jun 17, 2023
0a11c6f
differ module type member with type variable with same name
gensofubi Jun 18, 2023
9bb1796
fix minor problems
gensofubi Jun 18, 2023
0f11919
adjust typing information display for module type members
gensofubi Jun 18, 2023
45b8c80
Providing warnings for using type members that are not defined, and i…
gensofubi Jun 21, 2023
c9cbf2a
Merge remote-tracking branch 'origin/dev' into haz3l-module
gensofubi Jun 21, 2023
a6691dc
module langdoc copied from let
gensofubi Jun 28, 2023
09384db
module def langdoc
gensofubi Jun 29, 2023
477650a
Merge remote-tracking branch 'origin/adt-defs-after' into haz3l-module
gensofubi Jun 29, 2023
658e4f5
tyalias pat langdoc
gensofubi Jun 30, 2023
f097644
dot expression langdoc
gensofubi Jun 30, 2023
0f25baa
module type langdoc
gensofubi Jun 30, 2023
e247813
dot type langdoc
gensofubi Jul 1, 2023
449ac63
fit the problem on using member variable with member type
gensofubi Jul 2, 2023
a02f806
adjust type view: remove trailing comma, let the earlier definitions …
gensofubi Jul 2, 2023
9373f44
add tyalias for module having member type with same name
gensofubi Jul 2, 2023
d2034ba
change dot type to be a Typ postfix
gensofubi Jul 5, 2023
a57da2b
type view adjusted
gensofubi Jul 5, 2023
24f6748
Merge remote-tracking branch 'origin/adt-defs-after' into haz3l-module
gensofubi Jul 7, 2023
1513e98
fix exception when Applying Constructors defined in modules
gensofubi Jul 7, 2023
d8108d6
add comments in Statics.re and Module.re, remove unused function in C…
gensofubi Jul 10, 2023
14d5025
change error message for an invalid module name
gensofubi Jul 11, 2023
9285692
detailed member value in DHDoc_Exp
gensofubi Jul 12, 2023
c4c61b9
change dot to infix
gensofubi Jul 13, 2023
660d88b
Merge remote-tracking branch 'origin/adt-defs-after' into haz3l-module
gensofubi Jul 14, 2023
888ac62
rec type mem consistency
gensofubi Jul 14, 2023
1dc51e7
type member bug fix
gensofubi Jul 14, 2023
8aaa894
Merge remote-tracking branch 'origin/adt-defs-after' into haz3l-module
gensofubi Jul 31, 2023
483fc79
Merge remote-tracking branch 'origin/dev' into haz3l-module
gensofubi Aug 7, 2023
cc51001
change the cursor inspector print
gensofubi Aug 15, 2023
09aae62
langdoc modify
gensofubi Aug 15, 2023
4efc2e6
fix about ctrs in ana mode
gensofubi Aug 16, 2023
5f76744
change cls for capitalized var standing for modules
gensofubi Aug 16, 2023
abfe6db
langdoc for module vars(exp,pat,typ)
gensofubi Aug 17, 2023
c148a98
Merge remote-tracking branch 'origin/dev' into haz3l-module
gensofubi Aug 27, 2023
d23540d
Merge branch 'dev' into haz3l-module
gensofubi Aug 31, 2023
0c421f2
Merge branch 'dev' into haz3l-module
gensofubi Sep 10, 2023
b41f68c
Merge remote-tracking branch 'origin/dev' into haz3l-module
gensofubi Sep 17, 2023
bf5b462
Merge branch 'dev' into haz3l-module
gensofubi Oct 14, 2023
d64aaed
fix double casting on dot accessing
gensofubi Nov 9, 2023
e5b514a
Merge remote-tracking branch 'origin/dev' into haz3l-module
gensofubi Nov 27, 2023
024dabe
change ModuleVal type to ClosureEnvironment
gensofubi Dec 4, 2023
4a084be
fix modules annotated with typevars
gensofubi Dec 4, 2023
b92bc48
Merge remote-tracking branch 'origin/dev' into haz3l-module
gensofubi Dec 24, 2023
11e3b27
basic module alias
gensofubi Jan 8, 2024
4da0991
fix curly bracket problem
gensofubi Jan 8, 2024
82c8f61
fix dot parsing problem
gensofubi Jan 8, 2024
b371fbc
Merge branch 'haz3l-module' into module-alias
gensofubi Jan 8, 2024
715b677
evaluator merged
gensofubi Feb 17, 2024
fe99078
merged without stepper for module
gensofubi Feb 23, 2024
d0ad37c
Merge branch 'dev' into haz3l-module
gensofubi Feb 23, 2024
70688dc
Module alias (#1156)
cyrus- Mar 1, 2024
ff1ad0b
Merge remote-tracking branch 'origin/dev' into haz3l-module
gensofubi Mar 1, 2024
baca0d2
stepper partly done with a bug
gensofubi Mar 2, 2024
5684b0a
fix incorrect use of Mark
gensofubi Mar 2, 2024
3cd13bc
fix nested module bug
gensofubi Mar 2, 2024
bb29147
remove redundant evaluator for module
gensofubi Mar 4, 2024
78661a9
signature correction
gensofubi Mar 4, 2024
6b57f29
cursor inspector message correction
gensofubi Mar 4, 2024
f7bdc10
context inspector of projections updated
gensofubi Mar 4, 2024
946242b
fix documentation bugs
gensofubi Mar 18, 2024
c4a746c
Merge remote-tracking branch 'origin/dev' into haz3l-module
gensofubi Mar 18, 2024
73ca90a
fix type inconsistency warning on module patterns
gensofubi Mar 20, 2024
314111c
fixing alignment and linebreak use in cell-result
gensofubi Mar 21, 2024
c3408cd
Do not show members not included in the signature
gensofubi Mar 21, 2024
1ae0263
fix invalid module exception
gensofubi Mar 22, 2024
e5ad167
Merge remote-tracking branch 'origin/dev' into haz3l-module
gensofubi Mar 22, 2024
40c1aa7
modules documentation page
gensofubi Mar 22, 2024
2a243b4
module types and nested member types inspector correction
gensofubi Mar 31, 2024
9c95134
Merge remote-tracking branch 'origin/dev' into haz3l-module
gensofubi Apr 4, 2024
61ae8bb
merge
gensofubi Apr 4, 2024
5c4b189
basic casting issues
gensofubi Apr 12, 2024
a9dd6e7
fix alignment
gensofubi Apr 12, 2024
5b00e37
bug fix
gensofubi Apr 14, 2024
0678bcf
add holes to undefined but declared members
gensofubi Apr 14, 2024
b77204f
final refine of modules with signatures
gensofubi Apr 14, 2024
c356d29
Merge remote-tracking branch 'origin/dev' into haz3l-module
gensofubi Apr 14, 2024
87320ca
Cast for modules with Unknown type
gensofubi Apr 19, 2024
9e42970
Merge remote-tracking branch 'origin/dev' into haz3l-module
gensofubi May 4, 2024
450701b
hole type casting fix
gensofubi May 4, 2024
5e567bf
incomplete module type created for dot analyzing
gensofubi May 20, 2024
42f59bb
Merge remote-tracking branch 'origin/dev' into haz3l-module
gensofubi May 20, 2024
67986f0
Merge remote-tracking branch 'origin/dev' into haz3l-module
gensofubi May 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/haz3lcore/dynamics/DH.re
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module rec DHExp: {
| BoundVar(Var.t)
| Sequence(t, t)
| Let(DHPat.t, t, t)
| Module(DHPat.t, t, t)
| Dot(t, t)
| FixF(Var.t, Typ.t, t)
| Fun(DHPat.t, Typ.t, t, option(Var.t))
| Ap(t, t)
Expand All @@ -36,6 +38,7 @@ module rec DHExp: {
| Cast(t, Typ.t, Typ.t)
| FailedCast(t, Typ.t, Typ.t)
| InvalidOperation(t, InvalidOperationError.t)
| ModuleVal(Environment.t)
gensofubi marked this conversation as resolved.
Show resolved Hide resolved
and case =
| Case(t, list(rule), int)
and rule =
Expand Down Expand Up @@ -67,6 +70,8 @@ module rec DHExp: {
| BoundVar(Var.t)
| Sequence(t, t)
| Let(DHPat.t, t, t)
| Module(DHPat.t, t, t)
| Dot(t, t)
| FixF(Var.t, Typ.t, t)
| Fun(DHPat.t, Typ.t, t, option(Var.t))
| Ap(t, t)
Expand All @@ -90,6 +95,7 @@ module rec DHExp: {
| Cast(t, Typ.t, Typ.t)
| FailedCast(t, Typ.t, Typ.t)
| InvalidOperation(t, InvalidOperationError.t)
| ModuleVal(Environment.t)
and case =
| Case(t, list(rule), int)
and rule =
Expand All @@ -105,6 +111,8 @@ module rec DHExp: {
| BoundVar(_) => "BoundVar"
| Sequence(_, _) => "Sequence"
| Let(_, _, _) => "Let"
| Module(_, _, _) => "Module"
| Dot(_, _) => "DotMember"
| FixF(_, _, _) => "FixF"
| Fun(_, _, _, _) => "Fun"
| Closure(_, _) => "Closure"
Expand All @@ -130,6 +138,7 @@ module rec DHExp: {
| Cast(_, _, _) => "Cast"
| FailedCast(_, _, _) => "FailedCast"
| InvalidOperation(_) => "InvalidOperation"
| ModuleVal(_) => "ModuleVal"
};

let mk_tuple: list(t) => t =
Expand Down Expand Up @@ -161,6 +170,8 @@ module rec DHExp: {
| NonEmptyHole(err, u, i, d) => NonEmptyHole(err, u, i, strip_casts(d))
| Sequence(a, b) => Sequence(strip_casts(a), strip_casts(b))
| Let(dp, b, c) => Let(dp, strip_casts(b), strip_casts(c))
| Module(dp, b, c) => Module(dp, strip_casts(b), strip_casts(c))
| Dot(a, b) => Dot(strip_casts(a), strip_casts(b))
| FixF(a, b, c) => FixF(a, b, strip_casts(c))
| Fun(a, b, c, d) => Fun(a, b, strip_casts(c), d)
| Ap(a, b) => Ap(strip_casts(a), strip_casts(b))
Expand Down Expand Up @@ -191,6 +202,7 @@ module rec DHExp: {
| FloatLit(_) as d
| StringLit(_) as d
| Constructor(_) as d
| ModuleVal(_) as d
| InvalidOperation(_) as d => d
and strip_casts_rule = (Rule(a, d)) => Rule(a, strip_casts(d));

Expand All @@ -212,6 +224,10 @@ module rec DHExp: {
fast_equal(d11, d12) && fast_equal(d21, d22)
| (Let(dp1, d11, d21), Let(dp2, d12, d22)) =>
dp1 == dp2 && fast_equal(d11, d12) && fast_equal(d21, d22)
| (Module(dp1, d11, d21), Module(dp2, d12, d22)) =>
dp1 == dp2 && fast_equal(d11, d12) && fast_equal(d21, d22)
| (Dot(d11, d21), Dot(d12, d22)) =>
fast_equal(d11, d12) && fast_equal(d21, d22)
| (FixF(f1, ty1, d1), FixF(f2, ty2, d2)) =>
f1 == f2 && ty1 == ty2 && fast_equal(d1, d2)
| (Fun(dp1, ty1, d1, s1), Fun(dp2, ty2, d2, s2)) =>
Expand Down Expand Up @@ -244,10 +260,13 @@ module rec DHExp: {
fast_equal(d1, d2) && reason1 == reason2
| (ConsistentCase(case1), ConsistentCase(case2)) =>
fast_equal_case(case1, case2)
| (ModuleVal(mv1), ModuleVal(mv2)) => mv1 == mv2
/* We can group these all into a `_ => false` clause; separating
these so that we get exhaustiveness checking. */
| (Sequence(_), _)
| (Let(_), _)
| (Module(_), _)
| (Dot(_), _)
| (FixF(_), _)
| (Fun(_), _)
| (Ap(_), _)
Expand All @@ -264,7 +283,8 @@ module rec DHExp: {
| (Cast(_), _)
| (FailedCast(_), _)
| (InvalidOperation(_), _)
| (ConsistentCase(_), _) => false
| (ConsistentCase(_), _)
| (ModuleVal(_), _) => false

/* Hole forms: when checking environments, only check that
environment ID's are equal, don't check structural equality.
Expand Down
49 changes: 49 additions & 0 deletions src/haz3lcore/dynamics/Elaborator.re
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ let cast = (ctx: Ctx.t, mode: Mode.t, self_ty: Typ.t, d: DHExp.t) =>
| InconsistentBranches(_)
| Sequence(_)
| Let(_)
| Module(_)
| FixF(_) => d
/* Hole-like forms: Don't cast */
| InvalidText(_)
Expand All @@ -86,6 +87,8 @@ let cast = (ctx: Ctx.t, mode: Mode.t, self_ty: Typ.t, d: DHExp.t) =>
| InvalidOperation(_) => d
/* Normal cases: wrap */
| BoundVar(_)
| Dot(_)
| ModuleVal(_)
| Ap(_)
| ApBuiltin(_)
| Prj(_)
Expand Down Expand Up @@ -237,6 +240,51 @@ let rec dhexp_of_uexp =
);
Let(dp, FixF(self_id, ty_body, substituted_def), dbody);
};
| Module(p, def, body) =>
let add_name: (option(string), DHExp.t) => DHExp.t = (
name =>
fun
| Fun(p, ty, e, _) => DHExp.Fun(p, ty, e, name)
| d => d
);
let* dp = dhpat_of_upat(m, p);
let* ddef = dhexp_of_uexp(m, def);
let* dbody = dhexp_of_uexp(m, body);
let+ ty_body = fixed_exp_typ(m, body);
switch (Term.UPat.get_recursive_bindings(p)) {
| None =>
/* not recursive */
DHExp.Module(dp, ddef, dbody)
| Some([f]) =>
/* simple recursion */
Module(dp, FixF(f, ty_body, add_name(Some(f), ddef)), dbody)
| Some(fs) =>
/* mutual recursion */
let ddef =
switch (ddef) {
| Tuple(a) =>
DHExp.Tuple(List.map2(s => add_name(Some(s)), fs, a))
| _ => ddef
};
let uniq_id = List.nth(def.ids, 0);
let self_id = "__mutual__" ++ string_of_int(uniq_id);
let self_var = DHExp.BoundVar(self_id);
let (_, substituted_def) =
fs
|> List.fold_left(
((i, ddef), f) => {
let ddef =
Substitution.subst_var(DHExp.Prj(self_var, i), f, ddef);
(i + 1, ddef);
},
(0, ddef),
);
Module(dp, FixF(self_id, ty_body, substituted_def), dbody);
};
| Dot(e_mod, e_mem) =>
let* e_mod = dhexp_of_uexp(m, e_mod);
let+ e_mem = dhexp_of_uexp(m, e_mem);
DHExp.Dot(e_mod, e_mem);
| Ap(fn, arg) =>
let* c_fn = dhexp_of_uexp(m, fn);
let+ c_arg = dhexp_of_uexp(m, arg);
Expand Down Expand Up @@ -331,6 +379,7 @@ and dhpat_of_upat = (m: Statics.Map.t, upat: Term.UPat.t): option(DHPat.t) => {
| TypeAnn(p, _ty) =>
let* dp = dhpat_of_upat(m, p);
wrap(dp);
| TyAlias(_, _) => Some(DHPat.InvalidText(u, 0, ""))
};
| Some(InfoExp(_) | InfoTyp(_) | InfoTPat(_))
| None => None
Expand Down
109 changes: 105 additions & 4 deletions src/haz3lcore/dynamics/Evaluator.re
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ let rec ground_cases_of = (ty: Typ.t): ground_cases => {
| Int
| Float
| String
| Module(_)
| Var(_)
| Rec(_)
| Arrow(Unknown(_), Unknown(_))
Expand All @@ -62,6 +63,7 @@ let rec ground_cases_of = (ty: Typ.t): ground_cases => {
sm |> ConstructorMap.is_ground(is_ground_arg) ? Ground : grounded_Sum(sm)
| Arrow(_, _) => grounded_Arrow
| List(_) => grounded_List
| Member(_, ty) => ground_cases_of(ty)
};
};

Expand Down Expand Up @@ -94,6 +96,10 @@ let rec matches = (dp: DHPat.t, d: DHExp.t): match_result =>
| (Wild, _) => Matches(Environment.empty)
| (ExpandingKeyword(_), _) => DoesNotMatch
| (InvalidText(_), _) => IndetMatch
| (Var(_), ModuleVal(_)) => DoesNotMatch
| (Constructor(x), ModuleVal(_)) =>
let env = Environment.extend(Environment.empty, (x, d));
Matches(env);
| (BadConstructor(_), _) => IndetMatch
| (Var(x), _) =>
let env = Environment.extend(Environment.empty, (x, d));
Expand Down Expand Up @@ -297,6 +303,7 @@ and matches_cast_Sum =
| ExpandingKeyword(_)
| InvalidText(_)
| Let(_)
| Module(_)
| Ap(_)
| ApBuiltin(_)
| BinBoolOp(_)
Expand All @@ -310,6 +317,8 @@ and matches_cast_Sum =
| InvalidOperation(_) => IndetMatch
| Cast(_)
| BoundVar(_)
| Dot(_)
| ModuleVal(_)
| FixF(_)
| Fun(_)
| BoolLit(_)
Expand Down Expand Up @@ -387,6 +396,8 @@ and matches_cast_Tuple =
| InvalidText(_) => IndetMatch
| ExpandingKeyword(_) => IndetMatch
| Let(_, _, _) => IndetMatch
| Module(_, _, _) => IndetMatch
| Dot(_, _) => IndetMatch
| FixF(_, _, _) => DoesNotMatch
| Fun(_, _, _, _) => DoesNotMatch
| Closure(_, Fun(_)) => DoesNotMatch
Expand All @@ -399,6 +410,7 @@ and matches_cast_Tuple =
| BinStringOp(_)
| BoolLit(_) => DoesNotMatch
| IntLit(_) => DoesNotMatch
| ModuleVal(_) => DoesNotMatch
| Sequence(_)
| TestLit(_) => DoesNotMatch
| FloatLit(_) => DoesNotMatch
Expand Down Expand Up @@ -524,6 +536,8 @@ and matches_cast_Cons =
| InvalidText(_) => IndetMatch
| ExpandingKeyword(_) => IndetMatch
| Let(_, _, _) => IndetMatch
| Module(_, _, _) => IndetMatch
| Dot(_, _) => IndetMatch
| FixF(_, _, _) => DoesNotMatch
| Fun(_, _, _, _) => DoesNotMatch
| Closure(_, d') => matches_cast_Cons(dp, d', elt_casts)
Expand All @@ -536,6 +550,7 @@ and matches_cast_Cons =
| ListConcat(_)
| BoolLit(_) => DoesNotMatch
| IntLit(_) => DoesNotMatch
| ModuleVal(_) => DoesNotMatch
| Sequence(_)
| TestLit(_) => DoesNotMatch
| FloatLit(_) => DoesNotMatch
Expand Down Expand Up @@ -624,7 +639,6 @@ let rec evaluate: (ClosureEnvironment.t, DHExp.t) => m(EvaluatorResult.t) =
(env, d) => {
/* Increment number of evaluation steps (calls to `evaluate`). */
let* () = take_step;

switch (d) {
| BoundVar(x) =>
let d =
Expand Down Expand Up @@ -667,6 +681,42 @@ let rec evaluate: (ClosureEnvironment.t, DHExp.t) => m(EvaluatorResult.t) =
}
};

| Module(dp, d1, d2) =>
let empty_env = Environment.empty;
let* r1 = module_evaluate(env, empty_env, d1);
switch (r1) {
| BoxedValue(d1)
| Indet(d1) =>
switch (matches(dp, d1)) {
| IndetMatch
| DoesNotMatch => Indet(Closure(env, Module(dp, d1, d2))) |> return
| Matches(env') =>
let* env = evaluate_extend_env(env', env);
evaluate(env, d2);
}
};

| Dot(d1, d2) =>
let* r1 = evaluate(env, d1);
switch (r1) {
| BoxedValue(ModuleVal(inner_env)) =>
let* inner_env =
inner_env |> ClosureEnvironment.of_environment |> with_eig;
let* r2 = evaluate(inner_env, d2);
switch (r2) {
| BoxedValue(_) => r2 |> return
| Indet(d2') => Indet(Dot(d1, d2')) |> return
};
| BoxedValue(d1') =>
print_endline("InvalidModule");
raise(EvaluatorError.Exception(InvalidBoxedFun(d1')));
| Indet(d1') =>
let* r2 = evaluate(env, d2);
switch (r2) {
| BoxedValue(d2')
| Indet(d2') => Indet(Dot(d1', d2')) |> return
};
};
| FixF(f, _, d') =>
let* env' = evaluate_extend_env(Environment.singleton((f, d)), env);
evaluate(env', d');
Expand All @@ -677,7 +727,9 @@ let rec evaluate: (ClosureEnvironment.t, DHExp.t) => m(EvaluatorResult.t) =
let* r1 = evaluate(env, d1);
switch (r1) {
| BoxedValue(TestLit(id)) => evaluate_test(env, id, d2)
| BoxedValue(Constructor(_)) =>
// Now Constructors are also introduced by accessing from a module.
// So I'm using the evaluated result as d1 in final result.
| BoxedValue(Constructor(_) as d1) =>
let* r2 = evaluate(env, d2);
switch (r2) {
| BoxedValue(d2) => BoxedValue(Ap(d1, d2)) |> return
Expand Down Expand Up @@ -725,7 +777,12 @@ let rec evaluate: (ClosureEnvironment.t, DHExp.t) => m(EvaluatorResult.t) =
| IntLit(_)
| FloatLit(_)
| StringLit(_)
| Constructor(_) => BoxedValue(d) |> return
| ModuleVal(_) => BoxedValue(d) |> return
| Constructor(x) =>
switch (ClosureEnvironment.lookup(env, x)) {
| None => return(BoxedValue(d))
| Some(d) => evaluate(env, d)
}

| BinBoolOp(op, d1, d2) =>
let* r1 = evaluate(env, d1);
Expand Down Expand Up @@ -1270,7 +1327,51 @@ and evaluate_test_eq =
let* arg_result = evaluate(env, arg_show);

(arg_show, arg_result) |> return;
};
}
and module_evaluate:
(ClosureEnvironment.t, Environment.t, DHExp.t) => m(EvaluatorResult.t) =
(env, env_in, d) => {
switch (d) {
| Let(dp, d1, d2) =>
let* r1 = evaluate(env, d1);
switch (r1) {
| BoxedValue(d1)
| Indet(d1) =>
switch (matches(dp, d1)) {
| IndetMatch
| DoesNotMatch => Indet(Closure(env, Let(dp, d1, d2))) |> return
| Matches(env') =>
let* env = evaluate_extend_env(env', env);
let* env_in =
Environment.union(env', env_in)
|> ClosureEnvironment.of_environment
|> with_eig;
let env_in = ClosureEnvironment.map_of(env_in);
module_evaluate(env, env_in, d2);
}
};
| Module(dp, d1, d2) =>
let empty_env = Environment.empty;
let* r1 = module_evaluate(env, empty_env, d1);
switch (r1) {
| BoxedValue(d1)
| Indet(d1) =>
switch (matches(dp, d1)) {
| IndetMatch
| DoesNotMatch => Indet(Closure(env, Module(dp, d1, d2))) |> return
| Matches(env') =>
let* env = evaluate_extend_env(env', env);
let* env_in =
Environment.union(env', env_in)
|> ClosureEnvironment.of_environment
|> with_eig;
let env_in = ClosureEnvironment.map_of(env_in);
module_evaluate(env, env_in, d2);
}
};
| _ => BoxedValue(ModuleVal(env_in)) |> return
};
};

let evaluate = (env, d) => {
let es = EvaluatorState.init;
Expand Down
Loading