typ

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

experimental simplified type system

Defintions:

  • A `byte` is the smallest addressable unit in the CPU, this does not need to be 8 bits, though it usually is. In rj32 it's 16 bits.
  • A `word` is the largest value that can fit in a register. This can be the the same as the word size, as it is in rj32 (16 bits)
  • A `pointer` can be larger than 1 word, if it is, generally an `int` will also be larger than 1 word. This is common on 8-bit systems.
  • In general, though, you will want `int` and `uint` to be the same size as a word, but at least 16 bits.

TinyGo uses a system to compactly represent types in a way that can be embedded for runtime reflection. We use a very similar system here to optimize code reuse.

There are less than 32 basic types (19? plus some compiler specific ones) which can fit in 5 bits. These are the BasicTypes in the types package.

Extended types come in 8 other flavours. 4 of those flavours just decorate another type (chan interface pointer slice). 4 of them are more complex (func, array, map, struct).

As much as possible is packed into the Type code itself including all the basic types as well as decorated basic types, as long as none of them are named types. After that, the Type simply contains an ID for further information to be looked up in side tables, and it's fundamental Kind.

T = type kind K = map key type kind, chan direction, array size D = type decoration I = type index in side tables

An unnamed basic type, inc: empty struct, empty interface, `func()` 0000 0000 00TT TTT0

A named basic type IIII IIII IITT TTT0

An unnamed decorated basic type

  • maps with basic types as both key and value have both specified
  • channels have their direction specified as K
  • if an array, and the array length fits in K bits

KKKK KKTT TTT0 DDD1

A named/extended decorated type IIII IIII III1 DDD1

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KindStrings

func KindStrings() []string

KindStrings returns a slice of all String values of the enum

Types

type ChanDir

type ChanDir uint8
const (
	SendRecv ChanDir = iota
	SendOnly
	RecvOnly
)

type Context

type Context struct {
	// contains filtered or unexported fields
}

func (*Context) Bytes

func (c *Context) Bytes(typ Type) int

func (*Context) Dir

func (c *Context) Dir(typ Type) ChanDir

func (*Context) Elem

func (c *Context) Elem(typ Type) Type

func (*Context) Key

func (c *Context) Key(typ Type) Type

func (*Context) Len

func (c *Context) Len(typ Type) int

func (*Context) Words

func (c *Context) Words(typ Type) int

type Kind

type Kind uint8
const (
	Invalid Kind = iota

	// basic types
	B // bool
	I // int
	I8
	I16
	I32
	I64
	U // uint
	U8
	U16
	U32
	U64
	Uptr // uintptr
	F32  // float
	F64
	Complex64
	Complex128
	Str       // string
	UnsafePtr // unsafe.Pointer

	// types for untyped (constant) values
	CB       // constant bool
	CI       // constant int
	CR       // constant rune
	CF       // constant float
	CComplex // constant complex
	CStr     // constant string
	CNil     // constant nil

	CSR // flags
	Mem // memory

	Blank // blank variable _

	// composite types
	Interface
	Struct
	Func
	Chan
	Ptr // pointer
	Slice
	Array
	Map

	NumTypes

	// aliases
	Byte = U8
	Rune = I32
)

func KindString

func KindString(s string) (Kind, error)

KindString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func KindValues

func KindValues() []Kind

KindValues returns all values of the enum

func (Kind) IsAKind

func (i Kind) IsAKind() bool

IsAKind returns "true" if the value is listed in the enum definition. "false" otherwise

func (Kind) String

func (i Kind) String() string

type Type

type Type uint16
const Unknown Type = 0

func SimpleTypeFor

func SimpleTypeFor(typ types.Type) Type

SimpleTypeFor attempts to fit the types.Type into a Type. If side tables are required for more information, Unknown is returned.

func (Type) Dir

func (t Type) Dir() ChanDir

func (Type) Elem

func (t Type) Elem() Type

func (Type) Key

func (t Type) Key() Type

func (Type) Kind

func (t Type) Kind() Kind

func (Type) Len

func (t Type) Len() int

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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