-
Notifications
You must be signed in to change notification settings - Fork 1
[spec] Syntax for descriptor types #99
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -116,8 +116,15 @@ syntax comptype hint(desc "composite type") hint(macro "%" "T%") = | |||||
| | ARRAY fieldtype | ||||||
| | FUNC resulttype -> resulttype | ||||||
|
|
||||||
| syntax describes hint(show DESCRIBES %) hint(macro "%" "T%") = DESCRIBES typeuse | ||||||
| syntax descriptor hint(show DESCRIPTOR %) hint(macro "%" "T%") = DESCRIPTOR typeuse | ||||||
|
|
||||||
| syntax desctype hint(desc "descriptor type") = | ||||||
| | describes? descriptor? comptype | ||||||
| hint(show % % %) | ||||||
|
Member
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. Same here. |
||||||
|
|
||||||
| syntax subtype hint(desc "sub type") hint(macro "%" "T%") = | ||||||
| | SUB final? typeuse* comptype | ||||||
| | SUB final? typeuse* desctype | ||||||
|
|
||||||
| syntax rectype hint(desc "recursive type") hint(macro "%" "T%") = | ||||||
| | REC list(subtype) | ||||||
|
|
@@ -162,6 +169,7 @@ var mt : memtype | |||||
| var nt : numtype | ||||||
| var pt : packtype | ||||||
| var rt : reftype | ||||||
| var dct : desctype | ||||||
| var st : subtype | ||||||
| var tt : tabletype | ||||||
| var vt : vectype | ||||||
|
|
@@ -347,8 +355,11 @@ def $subst_valtype(valtype, typevar*, typeuse*) : valtype hint(show | |||||
| def $subst_packtype(packtype, typevar*, typeuse*) : packtype hint(show %#`[%:=%]) hint(macro "%subst") | ||||||
| def $subst_storagetype(storagetype, typevar*, typeuse*) : storagetype hint(show %#`[%:=%]) hint(macro "%subst") | ||||||
| def $subst_fieldtype(fieldtype, typevar*, typeuse*) : fieldtype hint(show %#`[%:=%]) hint(macro "%subst") | ||||||
| def $subst_describes(describes, typevar*, typeuse*) : describes hint(show %#`[%:=%]) hint(macro "%subst") | ||||||
| def $subst_descriptor(descriptor, typevar*, typeuse*) : descriptor hint(show %#`[%:=%]) hint(macro "%subst") | ||||||
|
|
||||||
| def $subst_comptype(comptype, typevar*, typeuse*) : comptype hint(show %#`[%:=%]) hint(macro "%subst") | ||||||
| def $subst_desctype(desctype, typevar*, typeuse*) : desctype hint(show %#`[%:=%]) hint(macro "%subst") | ||||||
| def $subst_subtype(subtype, typevar*, typeuse*) : subtype hint(show %#`[%:=%]) hint(macro "%subst") | ||||||
| def $subst_rectype(rectype, typevar*, typeuse*) : rectype hint(show %#`[%:=%]) hint(macro "%subst") | ||||||
| def $subst_deftype(deftype, typevar*, typeuse*) : deftype hint(show %#`[%:=%]) hint(macro "%subst") | ||||||
|
|
@@ -395,8 +406,14 @@ def $subst_comptype((STRUCT ft*), tv*, tu*) = STRUCT $subst_fieldtype(ft, tv*, t | |||||
| def $subst_comptype((ARRAY ft), tv*, tu*) = ARRAY $subst_fieldtype(ft, tv*, tu*) | ||||||
| def $subst_comptype((FUNC t_1* -> t_2*), tv*, tu*) = FUNC $subst_valtype(t_1, tv*, tu*)* -> $subst_valtype(t_2, tv*, tu*)* | ||||||
|
|
||||||
| def $subst_subtype((SUB final? tu'* ct), tv*, tu*) = | ||||||
| SUB final? $subst_typeuse(tu', tv*, tu*)* $subst_comptype(ct, tv*, tu*) | ||||||
| def $subst_describes(DESCRIBES tu, tv*, tu*) = DESCRIBES $subst_typeuse(tu, tv*, tu*) | ||||||
| def $subst_descriptor(DESCRIPTOR tu, tv*, tu*) = DESCRIPTOR $subst_typeuse(tu, tv*, tu*) | ||||||
|
Comment on lines
+409
to
+410
Member
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. Need to rename one of the |
||||||
|
|
||||||
| def $subst_desctype(dc1? dc2? ct, tv*, tu*) = | ||||||
| $subst_describes(dc1, tv*, tu*)? $subst_descriptor(dc2, tv*, tu*)? $subst_comptype(ct, tv*, tu*) | ||||||
|
|
||||||
| def $subst_subtype((SUB final? tu'* dct), tv*, tu*) = | ||||||
| SUB final? $subst_typeuse(tu', tv*, tu*)* $subst_desctype(dct, tv*, tu*) | ||||||
|
|
||||||
| def $minus_recs(typevar*, typeuse*) : (typevar*, typeuse*) | ||||||
| def $minus_recs(eps, eps) = (eps, eps) | ||||||
|
|
@@ -459,6 +476,7 @@ def $rollrt(typeidx, rectype) : rectype hint(show $roll_(%, %)) hint(macro "r | |||||
| def $unrollrt(rectype) : rectype hint(show $unroll(%)) hint(macro "unrollrt") | ||||||
| def $rolldt(typeidx, rectype) : deftype* hint(show $roll_(%)*#((%))) hint(macro "rolldt") | ||||||
| def $unrolldt(deftype) : subtype hint(show $unroll(%)) hint(macro "unrolldt") | ||||||
| def $expanddt_to_desctype(deftype) : desctype hint(show $expand_desc(%)) | ||||||
| def $expanddt(deftype) : comptype hint(show $expand(%)) hint(macro "expanddt") | ||||||
|
|
||||||
| def $rollrt(x, rectype) = REC ($subst_subtype(subtype, ((_IDX $(x + i)))^(i<n), (REC i)^(i<n)))^n | ||||||
|
|
@@ -469,7 +487,8 @@ def $unrollrt(rectype) = REC ($subst_subtype(subtype, (REC i)^(i<n), (_DEF recty | |||||
| def $rolldt(x, rectype) = (_DEF (REC subtype^n) i)^(i<n) -- if $rollrt(x, rectype) = REC subtype^n | ||||||
| def $unrolldt(_DEF rectype i) = subtype*[i] -- if $unrollrt(rectype) = REC subtype* | ||||||
|
|
||||||
| def $expanddt(deftype) = comptype -- if $unrolldt(deftype) = SUB final? typeuse* comptype | ||||||
| def $expanddt_to_desctype(deftype) = dct -- if $unrolldt(deftype) = SUB final? typeuse* dct | ||||||
| def $expanddt(deftype) = ct -- if $expanddt_to_desctype(deftype) = dc1? dc2? ct | ||||||
|
|
||||||
|
|
||||||
| ;; Free indices | ||||||
|
|
@@ -491,6 +510,9 @@ def $free_resulttype(resulttype) : free | |||||
| def $free_storagetype(storagetype) : free | ||||||
| def $free_fieldtype(fieldtype) : free | ||||||
| def $free_comptype(comptype) : free | ||||||
| def $free_describes(describes) : free | ||||||
| def $free_descriptor(descriptor) : free | ||||||
| def $free_desctype(desctype) : free | ||||||
| def $free_subtype(subtype) : free | ||||||
| def $free_rectype(rectype) : free | ||||||
|
|
||||||
|
|
@@ -550,8 +572,14 @@ def $free_comptype(STRUCT fieldtype*) = $free_list($free_fieldtype(fieldtype)*) | |||||
| def $free_comptype(ARRAY fieldtype) = $free_fieldtype(fieldtype) | ||||||
| def $free_comptype(FUNC resulttype_1 -> resulttype_2) = $free_resulttype(resulttype_1) ++ $free_resulttype(resulttype_2) | ||||||
|
|
||||||
| def $free_subtype(SUB final? typeuse* comptype) = | ||||||
| $free_list($free_typeuse(typeuse)*) ++ $free_comptype(comptype) | ||||||
| def $free_describes(DESCRIBES tu) = $free_typeuse(tu) | ||||||
| def $free_descriptor(DESCRIPTOR tu) = $free_typeuse(tu) | ||||||
|
|
||||||
| def $free_desctype(dc1? dc2? ct) = | ||||||
| $free_list($free_describes(dc1)?) ++ $free_list($free_descriptor(dc2)?) ++ $free_comptype(ct) | ||||||
|
Member
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. Nit:
Suggested change
|
||||||
|
|
||||||
| def $free_subtype(SUB final? typeuse* dct) = | ||||||
| $free_list($free_typeuse(typeuse)*) ++ $free_desctype(dct) | ||||||
|
|
||||||
| def $free_rectype(REC subtype*) = $free_list($free_subtype(subtype)*) | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,7 @@ relation Packtype_ok: context |- packtype : OK hint(name "K-pack") h | |
| relation Fieldtype_ok: context |- fieldtype : OK hint(name "K-field") hint(macro "%fieldtype") | ||
| relation Storagetype_ok: context |- storagetype : OK hint(name "K-storage") hint(macro "%storagetype") | ||
| relation Comptype_ok: context |- comptype : OK hint(name "K-comp") hint(macro "%comptype") | ||
| relation Desctype_ok: context |- desctype : OK hint(name "K-desc") hint(macro "%desctype") | ||
| relation Subtype_ok: context |- subtype : oktypeidx hint(name "K-sub") hint(macro "%subtype") hint(prosepp "for") | ||
| relation Rectype_ok: context |- rectype : oktypeidx hint(name "K-rect") hint(macro "%rectype") hint(prosepp "for") | ||
| relation Subtype_ok2: context |- subtype : oktypeidxnat hint(name "K-sub2") hint(macro "%subtypeext") hint(prosepp "for") | ||
|
|
@@ -97,6 +98,7 @@ relation Deftype_ok: context |- deftype : OK hint(name "K-def") h | |
|
|
||
| ;; Forward declarations for validation.subtyping | ||
| relation Comptype_sub: context |- comptype <: comptype hint(name "S-comp") hint(macro "%comptypematch") | ||
| relation Desctype_sub: context |- desctype <: desctype hint(name "S-desc") hint(macro "%desctypematch") | ||
| relation Deftype_sub: context |- deftype <: deftype hint(name "S-def") hint(macro "%deftypematch") | ||
|
|
||
|
|
||
|
|
@@ -143,14 +145,21 @@ rule Comptype_ok/func: | |
| -- Resulttype_ok: C |- t_2* : OK | ||
|
|
||
|
|
||
| rule Desctype_ok: | ||
| C |- (DESCRIBES tu_1)? (DESCRIPTOR tu_2)? ct : OK | ||
| -- (Typeuse_ok: C |- tu_1 : OK)? | ||
| -- (Typeuse_ok: C |- tu_2 : OK)? | ||
| -- Comptype_ok: C |- ct : OK | ||
|
|
||
|
|
||
| rule Subtype_ok: | ||
| C |- SUB FINAL? (_IDX x)* comptype : OK(x_0) | ||
| C |- SUB FINAL? (_IDX x)* dct : OK(x_0) | ||
| -- if |x*| <= 1 | ||
| -- (if x < x_0)* | ||
| -- (if $unrolldt(C.TYPES[x]) = SUB (_IDX x')* comptype')* | ||
| -- (if $unrolldt(C.TYPES[x]) = SUB (_IDX x')* dct')* | ||
| ---- | ||
| -- Comptype_ok: C |- comptype : OK | ||
| -- (Comptype_sub: C |- comptype <: comptype')* | ||
| -- Desctype_ok: C |- dct : OK | ||
| -- (Desctype_sub: C |- dct <: dct')* | ||
|
Comment on lines
+156
to
+162
Member
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. Nit: s/dct/desctype/g, for consistency with below |
||
|
|
||
| def $before(typeuse, typeidx, nat) : bool hint(show % << %,%) hint(macro "before") | ||
| def $before(deftype, x, i) = true | ||
|
|
@@ -163,13 +172,13 @@ def $unrollht(C, _IDX typeidx) = $unrolldt(C.TYPES[typeidx]) | |
| def $unrollht(C, REC i) = C.RECS[i] | ||
|
|
||
| rule Subtype_ok2: | ||
| C |- SUB FINAL? typeuse* compttype : OK x i | ||
| C |- SUB FINAL? typeuse* desctype : OK x i | ||
| -- if |typeuse*| <= 1 | ||
| -- (if $before(typeuse, x, i))* | ||
| -- (if $unrollht(C, typeuse) = SUB typeuse'* comptype')* | ||
| -- (if $unrollht(C, typeuse) = SUB typeuse'* desctype')* | ||
| ---- | ||
| -- Comptype_ok: C |- comptype : OK | ||
| -- (Comptype_sub: C |- comptype <: comptype')* | ||
| -- Desctype_ok: C |- desctype : OK | ||
| -- (Desctype_sub: C |- desctype <: desctype')* | ||
|
|
||
|
|
||
| rule Rectype_ok/empty: | ||
|
|
||
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.
These show hints are redundant.