ir

package
v0.0.0-...-67b6ef9 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppendNode

type AppendNode struct {
	NullCall

	Array Node
	Value Node
}

func (*AppendNode) Args

func (a *AppendNode) Args() []Node

type ArrayNode

type ArrayNode struct {
	Values []Node
	// contains filtered or unexported fields
}

func NewArrayNode

func NewArrayNode(vals []Node, typ types.Type) *ArrayNode

func (*ArrayNode) Args

func (a *ArrayNode) Args() []Node

func (*ArrayNode) Type

func (a *ArrayNode) Type() types.Type

type Block

type Block interface{} // TODO: Have something in this to make sure its a block

type BlockNode

type BlockNode struct {
	Block Block
	// contains filtered or unexported fields
}

func NewBlockNode

func NewBlockNode(blk Block, pos *tokens.Pos) *BlockNode

func (*BlockNode) Pos

func (b *BlockNode) Pos() *tokens.Pos

func (*BlockNode) Type

func (b *BlockNode) Type() types.Type

type BodyBlock

type BodyBlock interface {
	Block

	Block() []Node
	ScopeInfo() *ScopeInfo
}

type Builder

type Builder struct {
	Scope *Scope
	Funcs map[string]*Function
	Body  []Node

	Errors []*Error
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder() *Builder

func (*Builder) AddExtension

func (b *Builder) AddExtension(e *Extension)

func (*Builder) Build

func (b *Builder) Build(p *parser.Parser, fs FS) error

func (*Builder) Error

func (b *Builder) Error(level ErrorLevel, pos *tokens.Pos, format string, args ...interface{})

func (*Builder) FixTypes

func (b *Builder) FixTypes(args *[]Node, typs []types.Type, pos *tokens.Pos)

func (*Builder) IR

func (b *Builder) IR() *IR

func (*Builder) MatchTypes

func (b *Builder) MatchTypes(pos *tokens.Pos, args []Node, typs []types.Type) bool

type BuiltinFn

type BuiltinFn struct {
	Name   string
	Params []types.Type // nil if block builder
}

func BuiltinFns

func BuiltinFns() []*BuiltinFn

type Call

type Call interface {
	Type() types.Type
	Args() []Node
}

func NewTypedValue

func NewTypedValue(typ types.Type) Call

type CallNode

type CallNode struct {
	Call Call
	// contains filtered or unexported fields
}

func NewCallNode

func NewCallNode(call Call, pos *tokens.Pos) *CallNode

func (*CallNode) Pos

func (c *CallNode) Pos() *tokens.Pos

func (*CallNode) Type

func (c *CallNode) Type() types.Type

type CanCastNode

type CanCastNode struct {
	Value Node
	Typ   types.Type
	// contains filtered or unexported fields
}

func (*CanCastNode) Args

func (c *CanCastNode) Args() []Node

func (*CanCastNode) Type

func (c *CanCastNode) Type() types.Type

type Case

type Case struct {
	Value *Const
	Body  []Node
	Scope *ScopeInfo
}

func (*Case) Block

func (c *Case) Block() []Node

func (*Case) ScopeInfo

func (c *Case) ScopeInfo() *ScopeInfo

type CastNode

type CastNode struct {
	Value Node
	// contains filtered or unexported fields
}

func NewCastNode

func NewCastNode(val Node, typ types.Type) *CastNode

func (*CastNode) Args

func (c *CastNode) Args() []Node

func (*CastNode) Pos

func (c *CastNode) Pos() *tokens.Pos

func (*CastNode) Type

func (c *CastNode) Type() types.Type

type CompareNode

type CompareNode struct {
	Op CompareOperation

	Lhs Node
	Rhs Node
	// contains filtered or unexported fields
}

func (*CompareNode) Args

func (c *CompareNode) Args() []Node

func (*CompareNode) Type

func (c *CompareNode) Type() types.Type

type CompareOperation

type CompareOperation int
const (
	CompareOperationEqual CompareOperation = iota
	CompareOperationNotEqual
	CompareOperationLess
	CompareOperationGreater
	CompareOperationLessEqual
	CompareOperationGreaterEqual
)

func (CompareOperation) String

func (c CompareOperation) String() string

type ConcatNode

type ConcatNode struct {
	Values []Node
}

func (*ConcatNode) Args

func (c *ConcatNode) Args() []Node

func (*ConcatNode) Type

func (c *ConcatNode) Type() types.Type

type Const

type Const struct {
	Value any
	// contains filtered or unexported fields
}

func NewConst

func NewConst(typ types.Type, pos *tokens.Pos, val any) *Const

func (*Const) Pos

func (c *Const) Pos() *tokens.Pos

func (*Const) Type

func (c *Const) Type() types.Type

type Default

type Default struct {
	Body  []Node
	Scope *ScopeInfo
}

func (*Default) Block

func (d *Default) Block() []Node

func (*Default) ScopeInfo

func (d *Default) ScopeInfo() *ScopeInfo

type DefineNode

type DefineNode struct {
	NullCall
	Var     int
	Value   Node
	InScope bool // Check if accessing var outside of function (helps with recursion)
	// contains filtered or unexported fields
}

func (*DefineNode) Args

func (d *DefineNode) Args() []Node

type Error

type Error struct {
	Level   ErrorLevel
	Pos     *tokens.Pos
	Message string
}

type ErrorLevel

type ErrorLevel int
const (
	ErrorLevelError   ErrorLevel = iota
	ErrorLevelWarning            // TODO: Use this
)

type ExistsNode

type ExistsNode struct {
	Map Node
	Key Node
}

func (*ExistsNode) Args

func (g *ExistsNode) Args() []Node

func (*ExistsNode) Type

func (g *ExistsNode) Type() types.Type

type Extension

type Extension struct {
	Name    string
	Params  []types.Type
	RetType types.Type
}

type ExtensionCall

type ExtensionCall struct {
	Name string
	Args []Node
	// contains filtered or unexported fields
}

func (*ExtensionCall) Pos

func (e *ExtensionCall) Pos() *tokens.Pos

func (*ExtensionCall) Type

func (e *ExtensionCall) Type() types.Type

type FS

type FS interface {
	Parse(src string) (*parser.Parser, error)
}

type FnCallNode

type FnCallNode struct {
	Fn     Node
	Params []Node
	// contains filtered or unexported fields
}

func NewFnCallNode

func NewFnCallNode(fn Node, args []Node, typ types.Type, pos *tokens.Pos) *FnCallNode

func (*FnCallNode) Args

func (c *FnCallNode) Args() []Node

func (*FnCallNode) Pos

func (c *FnCallNode) Pos() *tokens.Pos

func (*FnCallNode) Type

func (c *FnCallNode) Type() types.Type

type FnNode

type FnNode struct {
	Name string
	// contains filtered or unexported fields
}

func (*FnNode) Args

func (f *FnNode) Args() []Node

func (*FnNode) Type

func (f *FnNode) Type() types.Type

type Function

type Function struct {
	Name    string
	Params  []*Param
	RetType types.Type
	Body    []Node

	Scope *ScopeInfo
	// contains filtered or unexported fields
}

func (*Function) Pos

func (f *Function) Pos() *tokens.Pos

type GetNode

type GetNode struct {
	Map Node
	Key Node
	// contains filtered or unexported fields
}

func NewGetNode

func NewGetNode(m, k Node) *GetNode

func (*GetNode) Args

func (g *GetNode) Args() []Node

func (*GetNode) Type

func (g *GetNode) Type() types.Type

type GetStructNode

type GetStructNode struct {
	Struct Node
	Field  int
	// contains filtered or unexported fields
}

func (*GetStructNode) Args

func (g *GetStructNode) Args() []Node

func (*GetStructNode) Type

func (g *GetStructNode) Type() types.Type

type IR

type IR struct {
	Funcs       map[string]*Function
	Variables   []*Variable
	Body        []Node
	GlobalScope *ScopeInfo
}

type IfNode

type IfNode struct {
	Condition Node
	Body      []Node
	Scope     *ScopeInfo

	Else      []Node // nil if no else
	ElseScope *ScopeInfo
}

type IndexNode

type IndexNode struct {
	Value Node
	Index Node
	// contains filtered or unexported fields
}

func NewIndexNode

func NewIndexNode(val, index Node) *IndexNode

func (*IndexNode) Args

func (i *IndexNode) Args() []Node

func (*IndexNode) Type

func (i *IndexNode) Type() types.Type

type KeysNode

type KeysNode struct {
	Map Node
	// contains filtered or unexported fields
}

func (*KeysNode) Args

func (k *KeysNode) Args() []Node

func (*KeysNode) Type

func (k *KeysNode) Type() types.Type

type LengthNode

type LengthNode struct {
	Value Node
}

func (*LengthNode) Args

func (l *LengthNode) Args() []Node

func (*LengthNode) Type

func (l *LengthNode) Type() types.Type

type LogicalOp

type LogicalOp int
const (
	LogicalOpAnd LogicalOp = iota
	LogicalOpOr
	LogicalOpNot
)

func (LogicalOp) String

func (l LogicalOp) String() string

type LogicalOpNode

type LogicalOpNode struct {
	Op  LogicalOp
	Val Node
	Rhs Node // nil in NOT
}

func (*LogicalOpNode) Args

func (l *LogicalOpNode) Args() []Node

func (*LogicalOpNode) Type

func (l *LogicalOpNode) Type() types.Type

type MakeNode

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

func (*MakeNode) Args

func (m *MakeNode) Args() []Node

func (*MakeNode) Type

func (m *MakeNode) Type() types.Type

type MathNode

type MathNode struct {
	Op  MathOperation
	Lhs Node
	Rhs Node
	// contains filtered or unexported fields
}

func NewMathNode

func NewMathNode(op MathOperation, lhs, rhs Node, typ types.Type) *MathNode

func (*MathNode) Args

func (m *MathNode) Args() []Node

func (*MathNode) Type

func (m *MathNode) Type() types.Type

type MathOperation

type MathOperation int
const (
	MathOperationAdd MathOperation = iota
	MathOperationSub
	MathOperationMul
	MathOperationDiv
	MathOperationPow
	MathOperationMod
)

func (MathOperation) String

func (m MathOperation) String() string

type Node

type Node interface {
	Type() types.Type
	Pos() *tokens.Pos
}

func NewTypedNode

func NewTypedNode(typ types.Type, pos *tokens.Pos) Node

type NullCall

type NullCall struct{}

func (NullCall) Type

func (n NullCall) Type() types.Type

type PanicNode

type PanicNode struct {
	NullCall
	Arg Node
}

func (*PanicNode) Args

func (p *PanicNode) Args() []Node

type Param

type Param struct {
	ID   int
	Name string
	Type types.Type
	Pos  *tokens.Pos
}

type PrintNode

type PrintNode struct {
	NullCall
	Arg Node
}

func (*PrintNode) Args

func (p *PrintNode) Args() []Node

type ReturnNode

type ReturnNode struct {
	NullCall
	Value Node
}

func (*ReturnNode) Args

func (r *ReturnNode) Args() []Node

type Scope

type Scope struct {
	Variables []*Variable
	// contains filtered or unexported fields
}

func NewScope

func NewScope() *Scope

func (*Scope) AddVariable

func (s *Scope) AddVariable(name string, typ types.Type, pos *tokens.Pos) int

func (*Scope) CurrScopeGetVar

func (s *Scope) CurrScopeGetVar(name string) (int, bool)

func (*Scope) CurrScopeInfo

func (s *Scope) CurrScopeInfo() *ScopeInfo

func (*Scope) CurrType

func (s *Scope) CurrType() ScopeType

func (*Scope) GetVar

func (s *Scope) GetVar(name string) (int, bool)

func (*Scope) HasType

func (s *Scope) HasType(typ ScopeType) bool

func (*Scope) Pop

func (s *Scope) Pop()

func (*Scope) Push

func (s *Scope) Push(typ ScopeType)

func (*Scope) Variable

func (s *Scope) Variable(id int) *Variable

type ScopeFrame

type ScopeFrame struct {
	Type      ScopeType
	Variables []int
}

type ScopeInfo

type ScopeInfo struct {
	Frames []ScopeFrame // Top frame is last
}

type ScopeType

type ScopeType int
const (
	ScopeTypeGlobal ScopeType = iota
	ScopeTypeFunction
	ScopeTypeIf
	ScopeTypeWhile
	ScopeTypeSwitch
	ScopeTypeCase
)

type SetIndexNode

type SetIndexNode struct {
	NullCall

	Array Node
	Index Node
	Value Node
}

func (*SetIndexNode) Args

func (s *SetIndexNode) Args() []Node

type SetNode

type SetNode struct {
	NullCall

	Map   Node
	Key   Node
	Value Node
}

func (*SetNode) Args

func (s *SetNode) Args() []Node

type SetStructNode

type SetStructNode struct {
	NullCall

	Struct Node
	Field  int
	Value  Node
	// contains filtered or unexported fields
}

func (*SetStructNode) Args

func (s *SetStructNode) Args() []Node

type SliceNode

type SliceNode struct {
	Value Node
	Start Node
	End   Node
}

func (*SliceNode) Args

func (s *SliceNode) Args() []Node

func (*SliceNode) Type

func (s *SliceNode) Type() types.Type

type SwitchNode

type SwitchNode struct {
	Value   Node
	Cases   []*BlockNode // *Case is Block
	Default *BlockNode   // if nil, no default
}

type TimeMode

type TimeMode int
const (
	TimeModeSeconds TimeMode = iota
	TimeModeMicro
	TimeModeMilli
	TimeModeNano
)

func (TimeMode) String

func (t TimeMode) String() string

type TimeNode

type TimeNode struct {
	Mode TimeMode
	// contains filtered or unexported fields
}

func (*TimeNode) Args

func (t *TimeNode) Args() []Node

func (*TimeNode) Type

func (t *TimeNode) Type() types.Type

type TypedNode

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

func (*TypedNode) Pos

func (t *TypedNode) Pos() *tokens.Pos

func (*TypedNode) Type

func (t *TypedNode) Type() types.Type

type TypedValue

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

func (*TypedValue) Args

func (t *TypedValue) Args() []Node

func (*TypedValue) Type

func (t *TypedValue) Type() types.Type

type VarNode

type VarNode struct {
	ID int
	// contains filtered or unexported fields
}

func (*VarNode) Args

func (v *VarNode) Args() []Node

func (*VarNode) Type

func (v *VarNode) Type() types.Type

type Variable

type Variable struct {
	Type        types.Type
	Name        string
	ID          int
	Pos         *tokens.Pos
	ScopeType   ScopeType
	NeedsGlobal bool // Useful for backends for which global code is placed inside a function, can allow backends to reduce global variable usage
}

type WhileNode

type WhileNode struct {
	Condition Node
	Body      []Node
	Scope     *ScopeInfo
}

func (*WhileNode) Block

func (w *WhileNode) Block() []Node

func (*WhileNode) ScopeInfo

func (w *WhileNode) ScopeInfo() *ScopeInfo

Jump to

Keyboard shortcuts

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