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

Create a new input syntax for function. #1254

Draft
wants to merge 22 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7280a28
For draft PR
DavidFangWJ Mar 25, 2024
1077ddc
Could not compile for now
DavidFangWJ Apr 10, 2024
948cbc7
Confused on how to write it.
DavidFangWJ Apr 14, 2024
b741422
Can compile now. Not sure about the part to determine IDs.
DavidFangWJ Apr 14, 2024
8fac38a
Reconstructed the code to avoid most of the repetitions.
DavidFangWJ Apr 21, 2024
3ba68df
Removes the check for arguent's syntax.
DavidFangWJ Apr 22, 2024
e851b7f
Merge branch 'dev' into haz3l-new-func-syntax
DavidFangWJ Apr 22, 2024
50b95f4
Change the determination of input type into a recursive function.
DavidFangWJ Apr 22, 2024
e7eaab5
Merge branch 'haz3l-new-func-syntax' of https://github.com/hazelgrove…
DavidFangWJ Apr 22, 2024
e434fa8
Merge branch 'dev' into haz3l-new-func-syntax
DavidFangWJ Apr 24, 2024
81d039f
Merge branch 'dev' into haz3l-new-func-syntax
DavidFangWJ May 13, 2024
206531c
Move the code to check annotated functions.
DavidFangWJ May 13, 2024
a7de72c
Added checks for annotated functions into the process.
DavidFangWJ May 14, 2024
7dec214
Fix p_syn in Statics.re.
DavidFangWJ Jul 21, 2024
67a0c84
Makes the program work. Probably needs more changes.
DavidFangWJ Aug 11, 2024
a38b124
Merge branch 'dev' into haz3l-new-func-syntax
DavidFangWJ Sep 2, 2024
54e0338
Tried my best to change the code. Could not fix the last bugs on Line…
DavidFangWJ Sep 15, 2024
8be885d
Preliminary change. Fails.
DavidFangWJ Sep 30, 2024
0e350d2
Aligns with `dev` except for two files I changed.
DavidFangWJ Sep 30, 2024
9b060d8
Merge branch 'dev' into haz3l-new-func-syntax
DavidFangWJ Oct 7, 2024
2a7c517
Add debugging statement.
DavidFangWJ Nov 2, 2024
8bab67e
Minimal change.
DavidFangWJ Nov 22, 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
1 change: 1 addition & 0 deletions src/haz3lcore/lang/Form.re
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ let forms: list((string, t)) = [
("ap_typ", mk(ii, ["(", ")"], mk_post(P.ap, Typ, [Typ]))),
("case", mk(ds, ["case", "end"], mk_op(Exp, [Rul]))),
("test", mk(ds, ["test", "end"], mk_op(Exp, [Exp]))),
// This is a potential place for modification
("fun_", mk(ds, ["fun", "->"], mk_pre(P.fun_, Exp, [Pat]))),
(
"rule",
Expand Down
60 changes: 60 additions & 0 deletions src/haz3lcore/statics/Statics.re
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,63 @@ let collect_errors = (map: Map.t): list((Id.t, Info.error)) =>
map,
[],
);

/*
* Unwrap the input funtion's args (more than 1) into format check and types
*/
let caf_argtrans = (args: list(UPat.t)): option(list(UTyp.t)) =>
List.fold_right(
DavidFangWJ marked this conversation as resolved.
Show resolved Hide resolved
(item: UPat.t, partial: option(list(UTyp.t))) =>
switch (partial) {
| Some(lst_typ) =>
switch (item.term) {
| TypeAnn({ids: _, term: Var(_)}, t) => Some([t, ...lst_typ])
| Var(_) => Some([{ids: item.ids, term: EmptyHole}, ...lst_typ])
| _ => None
}
| _ => None
},
args,
Some([]),
);

let check_annotated_function_helper =
(pat: UPat.t, ret_type: UTyp.t): option((Var.t, UPat.t, UTyp.t)) =>
switch (pat.term) {
| Ap({ids: _, term: Var(func_name)}, args) =>
let in_type_opt: option(UTyp.t) =
DavidFangWJ marked this conversation as resolved.
Show resolved Hide resolved
switch (args.term) {
| Var(_) => Some({ids: args.ids, term: EmptyHole})
| TypeAnn({ids: _, term: Var(_)}, t) => Some(t)
| Tuple(ps) =>
switch (caf_argtrans(ps)) {
| None => None
| Some(in_type) => Some({ids: args.ids, term: Tuple(in_type)})
}
| _ => None
};
switch (in_type_opt) {
| None => None
| Some(in_type) =>
Some((
func_name,
args,
{ids: pat.ids, term: Arrow(in_type, ret_type)},
))
};
| _ => None
};

/*
* Check whether a particular let binding is an annotated function under the new syntax.
* It is parsed as a constructor syntax.
* I am not sure what is the top-level pattern; the only thing similar seems to be UPat.Ap.
*/
let check_annotated_function =
(pat: UPat.t): option((Var.t, UPat.t, UTyp.t)) =>
switch (pat.term) {
| TypeAnn(inner_pat, ret_type) =>
check_annotated_function_helper(inner_pat, ret_type)
| _ =>
check_annotated_function_helper(pat, {ids: pat.ids, term: EmptyHole})
};
Loading