typesys

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeInfo_TypeBits_Unit               uint16 = 1 << 0
	TypeInfo_TypeBits_Pointer            uint16 = 1 << 1
	TypeInfo_TypeBits_Ref                uint16 = 1 << 2
	TypeInfo_TypeBits_Function           uint16 = 1 << 3
	TypeInfo_TypeBits_NativeFn           uint16 = 1 << 4
	TypeInfo_TypeBits_Maybe              uint16 = 1 << 5
	TypeInfo_TypeBits_Array              uint16 = 1 << 6
	TypeInfo_TypeBits_Slice              uint16 = 1 << 7
	TypeInfo_TypeBits_Object             uint16 = 1 << 8
	TypeInfo_TypeBits_Struct             uint16 = 1 << 9
	TypeInfo_TypeBits_Enum               uint16 = 1 << 10 // std::option::Option use with Maybe
	TypeInfo_TypeBits_NamedItem          uint16 = 1 << 11 // use with Object,Struct,Enum
	TypeInfo_TypeBits_Tuple              uint16 = 1 << 12
	TypeInfo_TypeBits_Trait              uint16 = 1 << 13
	TypeInfo_TypeBits_GenericType        uint16 = 1 << 14
	TypeInfo_TypeBits_GenericPlaceholder uint16 = 1 << 15
)

Variables

View Source
var TypeIdInitialMax uint32
View Source
var TypeInfoInitialMap map[string]TypeInfo
View Source
var TypeInfo_Primitive_Any = TypeInfo{
	Name: "any",
	Id:   0,
}
View Source
var TypeInfo_Primitive_Bool = TypeInfo{
	Name:      "bool",
	Flags:     12<<mnem.TypeIdOffset | mnem.ReturnBool,
	Id:        12,
	Primitive: uint16(mnem.ReturnBool),
}
View Source
var TypeInfo_Primitive_F32 = TypeInfo{
	Name:      "f32",
	Flags:     11<<mnem.TypeIdOffset | mnem.ReturnFloat | mnem.Bits32,
	Id:        11,
	Primitive: uint16(mnem.ReturnFloat | mnem.Bits32),
}
View Source
var TypeInfo_Primitive_F64 = TypeInfo{
	Name:      "f64",
	Flags:     10<<mnem.TypeIdOffset | mnem.ReturnFloat,
	Id:        10,
	Primitive: uint16(mnem.ReturnFloat),
}
View Source
var TypeInfo_Primitive_I16 = TypeInfo{
	Name:      "i16",
	Flags:     4<<mnem.TypeIdOffset | mnem.ReturnInt | mnem.Bits16,
	Id:        4,
	Primitive: uint16(mnem.ReturnInt | mnem.Bits16),
}
View Source
var TypeInfo_Primitive_I32 = TypeInfo{
	Name:      "i32",
	Flags:     3<<mnem.TypeIdOffset | mnem.ReturnInt | mnem.Bits32,
	Id:        3,
	Primitive: uint16(mnem.ReturnInt | mnem.Bits32),
}
View Source
var TypeInfo_Primitive_I64 = TypeInfo{
	Name:      "i64",
	Flags:     2<<mnem.TypeIdOffset | mnem.ReturnInt,
	Id:        2,
	Primitive: uint16(mnem.ReturnInt),
}
View Source
var TypeInfo_Primitive_I8 = TypeInfo{
	Name:      "i8",
	Flags:     5<<mnem.TypeIdOffset | mnem.ReturnInt | mnem.Bits8,
	Id:        5,
	Primitive: uint16(mnem.ReturnInt | mnem.Bits8),
}
View Source
var TypeInfo_Primitive_String = TypeInfo{
	Name:      "String",
	Flags:     13<<mnem.TypeIdOffset | mnem.ReturnString,
	Id:        13,
	Primitive: uint16(mnem.ReturnString),
}
View Source
var TypeInfo_Primitive_U16 = TypeInfo{
	Name:      "u16",
	Flags:     8<<mnem.TypeIdOffset | mnem.ReturnUint | mnem.Bits16,
	Id:        8,
	Primitive: uint16(mnem.ReturnUint | mnem.Bits16),
}
View Source
var TypeInfo_Primitive_U32 = TypeInfo{
	Name:      "u32",
	Flags:     7<<mnem.TypeIdOffset | mnem.ReturnUint | mnem.Bits32,
	Id:        7,
	Primitive: uint16(mnem.ReturnUint | mnem.Bits32),
}
View Source
var TypeInfo_Primitive_U64 = TypeInfo{
	Name:      "u64",
	Flags:     6<<mnem.TypeIdOffset | mnem.ReturnUint,
	Id:        6,
	Primitive: uint16(mnem.ReturnUint),
}
View Source
var TypeInfo_Primitive_U8 = TypeInfo{
	Name:      "u8",
	Flags:     9<<mnem.TypeIdOffset | mnem.ReturnUint | mnem.Bits8,
	Id:        9,
	Primitive: uint16(mnem.ReturnUint | mnem.Bits8),
}
View Source
var TypeInfo_Primitive_Unit = TypeInfo{
	Name:     "()",
	Flags:    1 << mnem.TypeIdOffset,
	Id:       1,
	TypeBits: TypeInfo_TypeBits_Unit,
}

Functions

func ExtractReturnTypeAndFlags

func ExtractReturnTypeAndFlags(
	ctx TypeManagerContext,
	getCallResultType bool, getMaybeResultType bool, getIndexResultType bool, flags AstOpCodeType) (AstOpCodeType, bool, error)

Types

type TypeInfo

type TypeInfo struct {
	Name      string        `json:"-"`
	ElName    string        `json:"n,omitempty"`
	Flags     AstOpCodeType `json:"-"` // masked by MetaInfoMask (include type id)
	Id        uint32        `json:"-"` // type id
	TypeBits  uint16        `json:"t,omitempty"`
	Primitive uint16        `json:"p,omitempty"` // AstOpCodeType compatible rune/int/uint/float/bool/string and bits. masked by (ReturnTypeMask|BitLenMask)
	LenIdx    uint          `json:"l,omitempty"` // array length/arg|tuple|enum item index
	Of        []TypeInfo    `json:"o,omitempty"` // ret[0]+arguments[1:]/members/enum/generic type[0]+params[1:]
}

TODO:

var TypeInfo_Generic_Enum_Option TypeInfo

It is initialized in the init() function.

func GetTypeInfo

func GetTypeInfo(name string) (TypeInfo, error)

func (TypeInfo) Option

func (s TypeInfo) Option(genId func() uint32) TypeInfo

func (TypeInfo) Slice

func (s TypeInfo) Slice(genId func() uint32) TypeInfo

func (TypeInfo) Specialize

func (s TypeInfo) Specialize(genId func() uint32, actualParams []TypeInfo) TypeInfo

func (TypeInfo) Unwrap

func (s TypeInfo) Unwrap() TypeInfo

type TypeManagerContext

type TypeManagerContext interface {
	NewTypeId() uint32
	GetTypeInfoByName(name string) (TypeInfo, error)
	GetTypeInfoById(id uint32) (TypeInfo, error)
	GetRegisteredTypeInfo(ty TypeInfo) (TypeInfo, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL