-
Notifications
You must be signed in to change notification settings - Fork 107
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
feat: generalized imports supporting pattern matching and selective field import #3076
Changes from 18 commits
b46e72a
e6e9915
67500bf
2d40582
1556274
3b120ee
bcf3fcb
59efd68
957f912
a1ee29c
91c3708
8d7fb3c
8fe6866
ddcef0f
f581947
0eff5af
999d654
c32448f
58c629c
ad314b7
2e9df25
7293902
93dcc88
1a0a069
e72ce22
d43c7ab
3669465
6efb5f6
b109d6d
4c94e00
1eef8dc
e3ee5f1
968cadc
9c911ca
2c3f4aa
2503343
0e0b65a
656b48c
9dc287a
c59e85a
a2aeae4
d0dff31
2d9b797
37b2838
c763ff8
feec77b
988c27f
c98c798
a3ac786
2ae3cbb
3e8226c
b5ed7d0
1ddcf93
95a93a8
ca01c14
af6941a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,15 +23,16 @@ let comp_unit_of_prog as_lib (prog : prog) : comp_unit = | |
let open Source in | ||
let f = prog.note in | ||
|
||
let finish imports u = { it = { imports; body = u }; note = f; at = no_region } in | ||
let finish imports u = | ||
{ it = { imports = List.rev imports; body = u }; note = f; at = no_region } in | ||
let prog_typ_note = { empty_typ_note with note_typ = Type.unit } in | ||
|
||
let rec go imports ds : comp_unit = | ||
match ds with | ||
(* imports *) | ||
| {it = LetD ({it = VarP n; _}, ({it = ImportE (url, ri); _} as e)); _} :: ds' -> | ||
let i : import = { it = (n, url, ri); note = e.note.note_typ; at = e.at } in | ||
go (imports @ [i]) ds' | ||
| {it = LetD (p, ({it = ImportE (url, ri); _} as e)); _} :: ds' -> | ||
let i : import = { it = (p, url, ri); note = e.note.note_typ; at = e.at } in | ||
go (i :: imports) ds' | ||
|
||
(* terminal expressions *) | ||
| [{it = ExpD ({it = ObjBlockE ({it = Type.Module; _}, fields); _} as e); _}] when as_lib -> | ||
|
@@ -88,14 +89,15 @@ let obj_decs obj_sort at note id_opt fields = | |
let decs_of_lib (cu : comp_unit) = | ||
let open Source in | ||
let { imports; body = cub; _ } = cu.it in | ||
let import_decs = List.map (fun { it = (id, fp, ri); at; note} -> | ||
{ it = LetD ( | ||
{ it = VarP id; at; note; }, | ||
{ it = ImportE (fp, ri); | ||
at; | ||
note = { note_typ = note; note_eff = Type.Triv} }); | ||
at; | ||
note = { note_typ = note; note_eff = Type.Triv } }) imports | ||
let import_decs = | ||
List.map (fun { it = (pat, fp, ri); at; note} -> | ||
{ it = LetD (pat, | ||
{ it = ImportE (fp, ri); | ||
at; | ||
note = { note_typ = note; note_eff = Type.Triv} }); | ||
at; | ||
note = { note_typ = note; note_eff = Type.Triv } } | ||
) imports | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the identation style on the left - I think that's what Andreas was advocating... (at least my understanding of it). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
in | ||
import_decs, | ||
match cub.it with | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { cons; nil } = "lib/ListM"; | ||
|
||
//type stack = List<Int>; | ||
let s = cons(1, nil()); | ||
let u = cons<Int>(2, nil<Int>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason this isn't just
<pat>
as forlet
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want
(?(#foo))
here, do we?<pat>
just doesn't have any sensible use-case in this place.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I don't think we should enforce typing properties using the grammar.
Also, it keeps the grammar closer to the informal language reference.
Plus, you might want a type annotation on the pattern without having to parenthesize it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I do this tomorrow in a new PR? I am totally burnt out, sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tomorrow is saturday. Monday!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't work: #3076 (comment)