-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce custom annotation on grammar
- Loading branch information
Showing
17 changed files
with
818 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,52 @@ | ||
open Util; | ||
|
||
[@deriving (show({with_path: false}), sexp, yojson)] | ||
type t('a) = { | ||
[@show.opaque] | ||
ids: list(Id.t), | ||
[@show.opaque] | ||
/* Exp invariant: copied should always be false, and the id should be unique | ||
DHExp invariant: if copied is true, then this term and its children may not | ||
have unique ids. The flag is used to avoid deep-copying expressions during | ||
evaluation, while keeping track of where we will need to replace the ids | ||
at the end of evaluation to keep them unique.*/ | ||
copied: bool, | ||
term: 'a, | ||
}; | ||
type t('a) = Grammar.Annotated.t('a, Grammar.IdTag.t); | ||
|
||
// To be used if you want to remove the id from the debug output | ||
// let pp: ((Format.formatter, 'a) => unit, Format.formatter, t('a)) => unit = | ||
// (fmt_a, formatter, ta) => { | ||
// fmt_a(formatter, ta.term); | ||
// }; | ||
let fresh = term => { | ||
{ids: [Id.mk()], copied: false, term}; | ||
let fresh = (term: 'a): Grammar.Annotated.t('a, Grammar.IdTag.t) => { | ||
{ | ||
term, | ||
annotation: { | ||
ids: [Id.mk()], | ||
copied: false, | ||
}, | ||
}; | ||
}; | ||
let fresh_deterministic = (prev_id, term): t('a) => { | ||
{ | ||
term, | ||
annotation: { | ||
ids: [Id.next(prev_id)], | ||
copied: false, | ||
}, | ||
}; | ||
}; | ||
|
||
let term_of = (x: Grammar.Annotated.t('a, 'b)) => x.term; | ||
let unwrap = (x: t('a)) => (x.term, term' => {...x, term: term'}); | ||
let rep_id = | ||
({annotation: {ids, _}, _}: Grammar.Annotated.t('a, Grammar.IdTag.t)) => | ||
List.hd(ids); | ||
|
||
let fast_copy = (id, {term, _}: t('a)): t('a) => { | ||
term, | ||
annotation: { | ||
copied: true, | ||
ids: [id], | ||
}, | ||
}; | ||
let fresh_deterministic = (prev_id, term) => { | ||
{ids: [Id.next(prev_id)], copied: false, term}; | ||
let new_ids = ({term, annotation: {ids: _, copied}}: t('a)): t('a) => { | ||
term, | ||
annotation: { | ||
ids: [Id.mk()], | ||
copied, | ||
}, | ||
}; | ||
|
||
let term_of = x => x.term; | ||
let unwrap = x => (x.term, term' => {...x, term: term'}); | ||
let rep_id = ({ids, _}) => List.hd(ids); | ||
let fast_copy = (id, {term, _}) => {ids: [id], term, copied: true}; | ||
let new_ids = | ||
fun | ||
| {ids: _, term, copied} => {ids: [Id.mk()], term, copied}; | ||
let ids = ({annotation: {ids, _}, _}: t('a)) => ids; | ||
let copied = ({annotation: {copied, _}, _}: t('a)) => copied; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.