mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Simplify token.builtInsByID
This commit is contained in:
1 parent
e2716e4365
commit
c9161bafaf
2 files changed
+142
-146
No files matched your search
+141
-145
@@ -381,111 +381,107 @@ const (
|
||||
IDIsMarked = ID(0xD1)
|
||||
)
|
||||
|
||||
// TODO: the struct{string, ID} can now just be a string.
|
||||
var builtInsByID = [nBuiltInIDs]struct {
|
||||
name string
|
||||
id ID
|
||||
}{
|
||||
IDOpenParen: {"(", IDOpenParen},
|
||||
IDCloseParen: {")", IDCloseParen},
|
||||
IDOpenBracket: {"[", IDOpenBracket},
|
||||
IDCloseBracket: {"]", IDCloseBracket},
|
||||
IDOpenCurly: {"{", IDOpenCurly},
|
||||
IDCloseCurly: {"}", IDCloseCurly},
|
||||
var builtInsByID = [nBuiltInIDs]string{
|
||||
IDOpenParen: "(",
|
||||
IDCloseParen: ")",
|
||||
IDOpenBracket: "[",
|
||||
IDCloseBracket: "]",
|
||||
IDOpenCurly: "{",
|
||||
IDCloseCurly: "}",
|
||||
|
||||
IDDot: {".", IDDot},
|
||||
IDDotDot: {"..", IDDotDot},
|
||||
IDComma: {",", IDComma},
|
||||
IDExclam: {"!", IDExclam},
|
||||
IDQuestion: {"?", IDQuestion},
|
||||
IDColon: {":", IDColon},
|
||||
IDSemicolon: {";", IDSemicolon},
|
||||
IDDollar: {"$", IDDollar},
|
||||
IDDot: ".",
|
||||
IDDotDot: "..",
|
||||
IDComma: ",",
|
||||
IDExclam: "!",
|
||||
IDQuestion: "?",
|
||||
IDColon: ":",
|
||||
IDSemicolon: ";",
|
||||
IDDollar: "$",
|
||||
|
||||
IDEq: {"=", IDEq},
|
||||
IDPlusEq: {"+=", IDPlusEq},
|
||||
IDMinusEq: {"-=", IDMinusEq},
|
||||
IDStarEq: {"*=", IDStarEq},
|
||||
IDSlashEq: {"/=", IDSlashEq},
|
||||
IDShiftLEq: {"<<=", IDShiftLEq},
|
||||
IDShiftREq: {">>=", IDShiftREq},
|
||||
IDAmpEq: {"&=", IDAmpEq},
|
||||
IDAmpHatEq: {"&^=", IDAmpHatEq},
|
||||
IDPipeEq: {"|=", IDPipeEq},
|
||||
IDHatEq: {"^=", IDHatEq},
|
||||
IDPercentEq: {"%=", IDPercentEq},
|
||||
IDTildePlusEq: {"~+=", IDTildePlusEq},
|
||||
IDEq: "=",
|
||||
IDPlusEq: "+=",
|
||||
IDMinusEq: "-=",
|
||||
IDStarEq: "*=",
|
||||
IDSlashEq: "/=",
|
||||
IDShiftLEq: "<<=",
|
||||
IDShiftREq: ">>=",
|
||||
IDAmpEq: "&=",
|
||||
IDAmpHatEq: "&^=",
|
||||
IDPipeEq: "|=",
|
||||
IDHatEq: "^=",
|
||||
IDPercentEq: "%=",
|
||||
IDTildePlusEq: "~+=",
|
||||
|
||||
IDPlus: {"+", IDPlus},
|
||||
IDMinus: {"-", IDMinus},
|
||||
IDStar: {"*", IDStar},
|
||||
IDSlash: {"/", IDSlash},
|
||||
IDShiftL: {"<<", IDShiftL},
|
||||
IDShiftR: {">>", IDShiftR},
|
||||
IDAmp: {"&", IDAmp},
|
||||
IDAmpHat: {"&^", IDAmpHat},
|
||||
IDPipe: {"|", IDPipe},
|
||||
IDHat: {"^", IDHat},
|
||||
IDPercent: {"%", IDPercent},
|
||||
IDTildePlus: {"~+", IDPercent},
|
||||
IDPlus: "+",
|
||||
IDMinus: "-",
|
||||
IDStar: "*",
|
||||
IDSlash: "/",
|
||||
IDShiftL: "<<",
|
||||
IDShiftR: ">>",
|
||||
IDAmp: "&",
|
||||
IDAmpHat: "&^",
|
||||
IDPipe: "|",
|
||||
IDHat: "^",
|
||||
IDPercent: "%",
|
||||
IDTildePlus: "~+",
|
||||
|
||||
IDNotEq: {"!=", IDNotEq},
|
||||
IDLessThan: {"<", IDLessThan},
|
||||
IDLessEq: {"<=", IDLessEq},
|
||||
IDEqEq: {"==", IDEqEq},
|
||||
IDGreaterEq: {">=", IDGreaterEq},
|
||||
IDGreaterThan: {">", IDGreaterThan},
|
||||
IDNotEq: "!=",
|
||||
IDLessThan: "<",
|
||||
IDLessEq: "<=",
|
||||
IDEqEq: "==",
|
||||
IDGreaterEq: ">=",
|
||||
IDGreaterThan: ">",
|
||||
|
||||
IDAnd: {"and", IDAnd},
|
||||
IDOr: {"or", IDOr},
|
||||
IDNot: {"not", IDNot},
|
||||
IDAs: {"as", IDAs},
|
||||
IDRef: {"ref", IDRef},
|
||||
IDDeref: {"deref", IDDeref},
|
||||
IDAnd: "and",
|
||||
IDOr: "or",
|
||||
IDNot: "not",
|
||||
IDAs: "as",
|
||||
IDRef: "ref",
|
||||
IDDeref: "deref",
|
||||
|
||||
IDFunc: {"func", IDFunc},
|
||||
IDAssert: {"assert", IDAssert},
|
||||
IDWhile: {"while", IDWhile},
|
||||
IDIf: {"if", IDIf},
|
||||
IDElse: {"else", IDElse},
|
||||
IDReturn: {"return", IDReturn},
|
||||
IDBreak: {"break", IDBreak},
|
||||
IDContinue: {"continue", IDContinue},
|
||||
IDStruct: {"struct", IDStruct},
|
||||
IDUse: {"use", IDUse},
|
||||
IDVar: {"var", IDVar},
|
||||
IDPre: {"pre", IDPre},
|
||||
IDInv: {"inv", IDInv},
|
||||
IDPost: {"post", IDPost},
|
||||
IDVia: {"via", IDVia},
|
||||
IDPub: {"pub", IDPub},
|
||||
IDPri: {"pri", IDPri},
|
||||
IDError: {"error", IDError},
|
||||
IDSuspension: {"suspension", IDSuspension},
|
||||
IDPackageID: {"packageid", IDPackageID},
|
||||
IDConst: {"const", IDConst},
|
||||
IDTry: {"try", IDTry},
|
||||
IDIterate: {"iterate", IDIterate},
|
||||
IDYield: {"yield", IDYield},
|
||||
IDFunc: "func",
|
||||
IDAssert: "assert",
|
||||
IDWhile: "while",
|
||||
IDIf: "if",
|
||||
IDElse: "else",
|
||||
IDReturn: "return",
|
||||
IDBreak: "break",
|
||||
IDContinue: "continue",
|
||||
IDStruct: "struct",
|
||||
IDUse: "use",
|
||||
IDVar: "var",
|
||||
IDPre: "pre",
|
||||
IDInv: "inv",
|
||||
IDPost: "post",
|
||||
IDVia: "via",
|
||||
IDPub: "pub",
|
||||
IDPri: "pri",
|
||||
IDError: "error",
|
||||
IDSuspension: "suspension",
|
||||
IDPackageID: "packageid",
|
||||
IDConst: "const",
|
||||
IDTry: "try",
|
||||
IDIterate: "iterate",
|
||||
IDYield: "yield",
|
||||
|
||||
IDArray: {"array", IDArray},
|
||||
IDNptr: {"nptr", IDNptr},
|
||||
IDPtr: {"ptr", IDPtr},
|
||||
IDSlice: {"slice", IDSlice},
|
||||
IDArray: "array",
|
||||
IDNptr: "nptr",
|
||||
IDPtr: "ptr",
|
||||
IDSlice: "slice",
|
||||
|
||||
IDFalse: {"false", IDFalse},
|
||||
IDTrue: {"true", IDTrue},
|
||||
IDZero: {"0", IDZero},
|
||||
IDFalse: "false",
|
||||
IDTrue: "true",
|
||||
IDZero: "0",
|
||||
|
||||
// Change MaxIntBits if a future update adds an i128 or u128 type.
|
||||
IDI8: {"i8", IDI8},
|
||||
IDI16: {"i16", IDI16},
|
||||
IDI32: {"i32", IDI32},
|
||||
IDI64: {"i64", IDI64},
|
||||
IDU8: {"u8", IDU8},
|
||||
IDU16: {"u16", IDU16},
|
||||
IDU32: {"u32", IDU32},
|
||||
IDU64: {"u64", IDU64},
|
||||
IDI8: "i8",
|
||||
IDI16: "i16",
|
||||
IDI32: "i32",
|
||||
IDI64: "i64",
|
||||
IDU8: "u8",
|
||||
IDU16: "u16",
|
||||
IDU32: "u32",
|
||||
IDU64: "u64",
|
||||
|
||||
// IDDoubleZ and IDDiamond are never returned by the tokenizer, as the
|
||||
// tokenizer rejects non-ASCII input.
|
||||
@@ -497,68 +493,68 @@ var builtInsByID = [nBuiltInIDs]struct {
|
||||
// represent an ideal integer type (in mathematical terms, the integer ring
|
||||
// ℤ), as opposed to a realized integer type whose range is restricted. For
|
||||
// example, the base.u16 type is restricted to [0x0000, 0xFFFF].
|
||||
IDDoubleZ: {"ℤ", IDDoubleZ}, // U+2124 DOUBLE-STRUCK CAPITAL Z
|
||||
IDDoubleZ: "ℤ", // U+2124 DOUBLE-STRUCK CAPITAL Z
|
||||
|
||||
// IDDiamond is used by the type checker as a dummy-valued built-in ID to
|
||||
// represent a generic type.
|
||||
IDDiamond: {"◊", IDDiamond}, // U+25C7 WHITE DIAMOND
|
||||
IDDiamond: "◊", // U+25C7 WHITE DIAMOND
|
||||
|
||||
IDUnderscore: {"_", IDUnderscore},
|
||||
IDThis: {"this", IDThis},
|
||||
IDIn: {"in", IDIn},
|
||||
IDOut: {"out", IDOut},
|
||||
IDSLICE: {"SLICE", IDSLICE},
|
||||
IDBase: {"base", IDBase},
|
||||
IDUnderscore: "_",
|
||||
IDThis: "this",
|
||||
IDIn: "in",
|
||||
IDOut: "out",
|
||||
IDSLICE: "SLICE",
|
||||
IDBase: "base",
|
||||
|
||||
IDBool: {"bool", IDBool},
|
||||
IDIOReader: {"io_reader", IDIOReader},
|
||||
IDIOWriter: {"io_writer", IDIOWriter},
|
||||
IDStatus: {"status", IDStatus},
|
||||
IDImageConfig: {"image_config", IDImageConfig},
|
||||
IDBool: "bool",
|
||||
IDIOReader: "io_reader",
|
||||
IDIOWriter: "io_writer",
|
||||
IDStatus: "status",
|
||||
IDImageConfig: "image_config",
|
||||
|
||||
IDMark: {"mark", IDMark},
|
||||
IDReadU8: {"read_u8", IDReadU8},
|
||||
IDReadU16BE: {"read_u16be", IDReadU16BE},
|
||||
IDReadU16LE: {"read_u16le", IDReadU16LE},
|
||||
IDReadU32BE: {"read_u32be", IDReadU32BE},
|
||||
IDReadU32LE: {"read_u32le", IDReadU32LE},
|
||||
IDReadU64BE: {"read_u64be", IDReadU64BE},
|
||||
IDReadU64LE: {"read_u64le", IDReadU64LE},
|
||||
IDSinceMark: {"since_mark", IDSinceMark},
|
||||
IDWriteU8: {"write_u8", IDWriteU8},
|
||||
IDWriteU16BE: {"write_u16be", IDWriteU16BE},
|
||||
IDWriteU16LE: {"write_u16le", IDWriteU16LE},
|
||||
IDWriteU32BE: {"write_u32be", IDWriteU32BE},
|
||||
IDWriteU32LE: {"write_u32le", IDWriteU32LE},
|
||||
IDWriteU64BE: {"write_u64be", IDWriteU64BE},
|
||||
IDWriteU64LE: {"write_u64le", IDWriteU64LE},
|
||||
IDMark: "mark",
|
||||
IDReadU8: "read_u8",
|
||||
IDReadU16BE: "read_u16be",
|
||||
IDReadU16LE: "read_u16le",
|
||||
IDReadU32BE: "read_u32be",
|
||||
IDReadU32LE: "read_u32le",
|
||||
IDReadU64BE: "read_u64be",
|
||||
IDReadU64LE: "read_u64le",
|
||||
IDSinceMark: "since_mark",
|
||||
IDWriteU8: "write_u8",
|
||||
IDWriteU16BE: "write_u16be",
|
||||
IDWriteU16LE: "write_u16le",
|
||||
IDWriteU32BE: "write_u32be",
|
||||
IDWriteU32LE: "write_u32le",
|
||||
IDWriteU64BE: "write_u64be",
|
||||
IDWriteU64LE: "write_u64le",
|
||||
|
||||
IDIsError: {"is_error", IDIsError},
|
||||
IDIsOK: {"is_ok", IDIsOK},
|
||||
IDIsSuspension: {"is_suspension", IDIsSuspension},
|
||||
IDCopyFromHistory32: {"copy_from_history32", IDCopyFromHistory32},
|
||||
IDCopyFromReader32: {"copy_from_reader32", IDCopyFromReader32},
|
||||
IDCopyFromSlice: {"copy_from_slice", IDCopyFromSlice},
|
||||
IDCopyFromSlice32: {"copy_from_slice32", IDCopyFromSlice32},
|
||||
IDSkip32: {"skip32", IDSkip32},
|
||||
IDSkip64: {"skip64", IDSkip64},
|
||||
IDLength: {"length", IDLength},
|
||||
IDAvailable: {"available", IDAvailable},
|
||||
IDPrefix: {"prefix", IDPrefix},
|
||||
IDSuffix: {"suffix", IDSuffix},
|
||||
IDLimit: {"limit", IDLimit},
|
||||
IDLowBits: {"low_bits", IDLowBits},
|
||||
IDHighBits: {"high_bits", IDHighBits},
|
||||
IDUnreadU8: {"unread_u8", IDUnreadU8},
|
||||
IDIsMarked: {"is_marked", IDIsMarked},
|
||||
IDIsError: "is_error",
|
||||
IDIsOK: "is_ok",
|
||||
IDIsSuspension: "is_suspension",
|
||||
IDCopyFromHistory32: "copy_from_history32",
|
||||
IDCopyFromReader32: "copy_from_reader32",
|
||||
IDCopyFromSlice: "copy_from_slice",
|
||||
IDCopyFromSlice32: "copy_from_slice32",
|
||||
IDSkip32: "skip32",
|
||||
IDSkip64: "skip64",
|
||||
IDLength: "length",
|
||||
IDAvailable: "available",
|
||||
IDPrefix: "prefix",
|
||||
IDSuffix: "suffix",
|
||||
IDLimit: "limit",
|
||||
IDLowBits: "low_bits",
|
||||
IDHighBits: "high_bits",
|
||||
IDUnreadU8: "unread_u8",
|
||||
IDIsMarked: "is_marked",
|
||||
}
|
||||
|
||||
var builtInsByName = map[string]ID{}
|
||||
|
||||
func init() {
|
||||
for _, x := range builtInsByID {
|
||||
if x.name != "" {
|
||||
builtInsByName[x.name] = x.id
|
||||
for i, name := range builtInsByID {
|
||||
if name != "" {
|
||||
builtInsByName[name] = ID(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ func (m *Map) ByName(name string) ID {
|
||||
|
||||
func (m *Map) ByID(x ID) string {
|
||||
if x < nBuiltInIDs {
|
||||
return builtInsByID[x].name
|
||||
return builtInsByID[x]
|
||||
}
|
||||
x -= nBuiltInIDs
|
||||
if uint(x) < uint(len(m.byID)) {
|
||||
|
||||
Reference in new issue
Block a user