From f3f744c3487c03de4070e154485aff9640555dfe Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 8 Sep 2022 12:59:49 -0400 Subject: [PATCH] Producing more data structures --- analyzer/accessors.go | 11 +++++++++++ analyzer/primitives.go | 24 ++++++++++++++++++++++++ analyzer/table.go | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 analyzer/accessors.go create mode 100644 analyzer/primitives.go diff --git a/analyzer/accessors.go b/analyzer/accessors.go new file mode 100644 index 0000000..12cd52d --- /dev/null +++ b/analyzer/accessors.go @@ -0,0 +1,11 @@ +package analyzer + +func (section TypeSection) Kind () (kind SectionKind) { + kind = SectionKindType + return +} + +func (section TypeSection) Name () (name string) { + name = section.name + return +} diff --git a/analyzer/primitives.go b/analyzer/primitives.go new file mode 100644 index 0000000..92ffc26 --- /dev/null +++ b/analyzer/primitives.go @@ -0,0 +1,24 @@ +package analyzer + +// This is a global, cannonical list of primitive and built-in types. + +var PrimitiveInt = TypeSection { name: "Int" } +var PrimitiveUInt = TypeSection { name: "UInt" } +var PrimitiveI8 = TypeSection { name: "I8" } +var PrimitiveI16 = TypeSection { name: "I16" } +var PrimitiveI32 = TypeSection { name: "I32" } +var PrimitiveI64 = TypeSection { name: "I64" } +var PrimitiveU8 = TypeSection { name: "U8" } +var PrimitiveU16 = TypeSection { name: "U16" } +var PrimitiveU32 = TypeSection { name: "U32" } +var PrimitiveU64 = TypeSection { name: "U64" } + +var PrimitiveObjt = TypeSection { name: "Objt" } +var PrimitiveFace = TypeSection { name: "Face" } + +var BuiltInString = TypeSection { + inherits: Type { + actual: PrimitiveU8, + kind: TypeKindVariableArray, + }, +} diff --git a/analyzer/table.go b/analyzer/table.go index 4a6a72c..ac6b521 100644 --- a/analyzer/table.go +++ b/analyzer/table.go @@ -14,7 +14,7 @@ type SectionTable map[locator] Section type SectionKind int const ( - SectionKindType = iota + SectionKindType SectionKind = iota SectionKindObjt SectionKindEnum SectionKindFace @@ -27,3 +27,34 @@ type Section interface { Kind () (kind SectionKind) Name () (name string) } + +// TypeKind represents what kind of type a type is. +type TypeKind int + +const ( + // TypeKindBasic means it's a single value, or a fixed length array. + TypeKindBasic TypeKind = iota + + // TypeKindPointer means it's a pointer + TypeKindPointer + + // TypeKindVariableArray means it's an array of variable length. + TypeKindVariableArray +) + +// Type represents a description of a type. It must eventually point to a +// TypeSection. +type Type struct { + actual Section + points *Type + + mutable bool + kind TypeKind + length uint64 +} + +// TypeSection represents a type definition section. +type TypeSection struct { + name string + inherits Type +}