Prepare for more generic funcs, not just slices

This commit is contained in:
Nigel Tao committed 2018-05-04 09:31:52 +10:00
1 parent 33746151aa
commit a9d5adc3fc
3 files changed
+15 -14

No files matched your search

+11 -10
View File
@@ -134,18 +134,19 @@ var Funcs = []string{
"image_config.initialize!(pixfmt u32, pixsub u32, width u32, height u32, num_loops u32)()",
}
// The "T" types here are generic placeholders for every "slice U" type. After
// parsing these SliceFunc strings (e.g. in the lang/check package), replace
// "T" with the "◊" diamond to denote a generic slice method, to avoid
// ambiguity with a user-defined, non-generic "T" type.
const (
GenericReplaceFrom = t.IDSLICE
GenericReplaceTo = t.IDDiamond
PlaceholderOldName = t.IDCapitalT
PlaceholderNewName = t.IDDiamond
)
var SliceFuncs = []string{
// The "SLICE" types here are generic placeholders for every "slice T"
// type. After parsing these strings (e.g. in the lang/check package),
// replace "SLICE" with the "◊" diamond to denote a generic slice method,
// to avoid ambiguity with a user-defined, non-generic "SLICE" type.
"SLICE.copy_from_slice(s SLICE)(ret u64)",
"SLICE.length()(ret u64)",
"SLICE.prefix(up_to u64)(ret SLICE)",
"SLICE.suffix(up_to u64)(ret SLICE)",
"T.copy_from_slice(s T)(ret u64)",
"T.length()(ret u64)",
"T.prefix(up_to u64)(ret T)",
"T.suffix(up_to u64)(ret T)",
}
+2 -2
View File
@@ -110,8 +110,8 @@ func parseBuiltInFuncs(tm *t.Map, ss []string, generic bool) (map[t.QQID]*a.Func
}
if generic {
for i := range tokens {
if tokens[i].ID == builtin.GenericReplaceFrom {
tokens[i].ID = builtin.GenericReplaceTo
if tokens[i].ID == builtin.PlaceholderOldName {
tokens[i].ID = builtin.PlaceholderNewName
}
}
}
+2 -2
View File
@@ -404,7 +404,7 @@ const (
IDThis = ID(0xAB)
IDIn = ID(0xAC)
IDOut = ID(0xAD)
IDSLICE = ID(0xAE)
IDCapitalT = ID(0xAE)
IDBase = ID(0xAF)
IDMark = ID(0xB0)
@@ -588,7 +588,7 @@ var builtInsByID = [nBuiltInIDs]string{
IDThis: "this",
IDIn: "in",
IDOut: "out",
IDSLICE: "SLICE",
IDCapitalT: "T",
IDBase: "base",
IDMark: "mark",