ir

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Indent

func Indent(val string) string

Types

type AllocDynamic

type AllocDynamic struct {
	Val int
	Typ Type
}

Dynamic types

func (*AllocDynamic) String

func (a *AllocDynamic) String() string

func (*AllocDynamic) Type

func (a *AllocDynamic) Type() Type

type AllocStatic

type AllocStatic struct {
	Typ Type
}

Memory instructions

func (*AllocStatic) String

func (a *AllocStatic) String() string

func (*AllocStatic) Type

func (a *AllocStatic) Type() Type

type Array

type Array struct {
	Vals    []int
	ValType Type
}

func (*Array) String

func (a *Array) String() string

func (*Array) Type

func (a *Array) Type() Type

type ArrayIndex

type ArrayIndex struct {
	Array int
	Index int
	// contains filtered or unexported fields
}

NOTE: Index is an instruction index

func (*ArrayIndex) String

func (i *ArrayIndex) String() string

func (*ArrayIndex) Type

func (i *ArrayIndex) Type() Type

type ArrayLength

type ArrayLength struct {
	Val int
}

func (*ArrayLength) String

func (a *ArrayLength) String() string

func (*ArrayLength) Type

func (a *ArrayLength) Type() Type

type Cast

type Cast struct {
	Val int
	Typ Type
}

func (*Cast) String

func (c *Cast) String() string

func (*Cast) Type

func (c *Cast) Type() Type

type Compare

type Compare struct {
	Op   parser.Operator
	Val1 int
	Val2 int
	// contains filtered or unexported fields
}

func (*Compare) String

func (c *Compare) String() string

func (*Compare) Type

func (c *Compare) Type() Type

type Concat

type Concat struct {
	Vals []int
}

func (*Concat) String

func (c *Concat) String() string

func (*Concat) Type

func (c *Concat) Type() Type

type CondJmp

type CondJmp struct {
	Cond        int
	TargetTrue  int
	TargetFalse int
}

func (*CondJmp) String

func (j *CondJmp) String() string

func (*CondJmp) Type

func (j *CondJmp) Type() Type

type Const

type Const struct {
	Typ  Type
	Data interface{}
}

func (*Const) String

func (c *Const) String() string

func (*Const) Type

func (c *Const) Type() Type

type Function

type Function struct {
	ParTypes     []Type
	Ret          int
	Instructions []Instruction
}

type FunctionCall

type FunctionCall struct {
	Fn     int
	Params []int
	Typ    Type
}

func (*FunctionCall) String

func (f *FunctionCall) String() string

func (*FunctionCall) Type

func (f *FunctionCall) Type() Type

type GetArg

type GetArg struct {
	Index int
}

func (*GetArg) String

func (g *GetArg) String() string

func (*GetArg) Type

func (g *GetArg) Type() Type

type GetMemory

type GetMemory struct {
	Mem int

	Typ Type
}

func (*GetMemory) String

func (s *GetMemory) String() string

func (*GetMemory) Type

func (s *GetMemory) Type() Type

type GetMemoryDynamic

type GetMemoryDynamic struct {
	Mem int

	Typ Type
}

func (*GetMemoryDynamic) String

func (s *GetMemoryDynamic) String() string

func (*GetMemoryDynamic) Type

func (s *GetMemoryDynamic) Type() Type

type GetParam

type GetParam struct {
	Index int
	// contains filtered or unexported fields
}

func (*GetParam) String

func (g *GetParam) String() string

func (*GetParam) Type

func (g *GetParam) Type() Type

type IR

type IR struct {
	Instructions []Instruction
	Functions    []Function
	Fns          map[string]int
	// contains filtered or unexported fields
}

func CreateIR

func CreateIR(prog *parser.Program) (*IR, error)

func NewIR

func NewIR() *IR

func (*IR) AddFunction

func (i *IR) AddFunction(fn *parser.FunctionBlock) error

func (*IR) AddInstruction

func (i *IR) AddInstruction(instr Instruction) int

func (*IR) AddStmt

func (i *IR) AddStmt(stmt parser.Statement) (int, error)

func (*IR) AddStmtTop

func (i *IR) AddStmtTop(stmt parser.Statement) (int, error)

func (*IR) GetInstruction

func (i *IR) GetInstruction(index int) Instruction

func (*IR) Index

func (i *IR) Index() int

func (*IR) Load

func (i *IR) Load(f io.Reader) error

func (*IR) Save

func (i *IR) Save(f io.Writer) error

func (*IR) SetCondJmpPoint

func (i *IR) SetCondJmpPoint(index int, targetTrue int, targetFalse int)

func (*IR) SetJmpPoint

func (i *IR) SetJmpPoint(index int, target int)

func (*IR) String

func (i *IR) String() string

type Instruction

type Instruction interface {
	fmt.Stringer

	Type() Type
}

type Jmp

type Jmp struct {
	Target int
}

func (*Jmp) String

func (j *Jmp) String() string

func (*Jmp) Type

func (j *Jmp) Type() Type

type JmpPoint

type JmpPoint struct{}

func (*JmpPoint) String

func (j *JmpPoint) String() string

func (*JmpPoint) Type

func (j *JmpPoint) Type() Type

type Math

type Math struct {
	Op   parser.Operator
	Val1 int
	Val2 int
	// contains filtered or unexported fields
}

func (*Math) String

func (m *Math) String() string

func (*Math) Type

func (m *Math) Type() Type

type MathFunction

type MathFunction struct {
	Op  MathFunctionType
	Val int
	Typ Type
}

func (*MathFunction) String

func (m *MathFunction) String() string

func (*MathFunction) Type

func (m *MathFunction) Type() Type

type MathFunctionType

type MathFunctionType int
const (
	FLOOR MathFunctionType = iota
	CEIL
	ROUND
)

func (MathFunctionType) String

func (m MathFunctionType) String() string

type PHI

type PHI struct {
	Cond     int
	ValTrue  int
	ValFalse int
	// contains filtered or unexported fields
}

func (*PHI) String

func (p *PHI) String() string

func (*PHI) Type

func (p *PHI) Type() Type

type Print

type Print struct {
	Val int
}

func (*Print) String

func (p *Print) String() string

func (*Print) Type

func (p *Print) Type() Type

type RandFloat

type RandFloat struct {
	Min int
	Max int
}

func (*RandFloat) String

func (r *RandFloat) String() string

func (*RandFloat) Type

func (r *RandFloat) Type() Type

type RandInt

type RandInt struct {
	Min int
	Max int
}

func (*RandInt) String

func (r *RandInt) String() string

func (*RandInt) Type

func (r *RandInt) Type() Type

type SetMemory

type SetMemory struct {
	Mem   int
	Value int

	Typ Type
}

func (*SetMemory) String

func (s *SetMemory) String() string

func (*SetMemory) Type

func (s *SetMemory) Type() Type

type SetMemoryDynamic

type SetMemoryDynamic struct {
	Mem   int
	Value int

	Typ Type
}

func (*SetMemoryDynamic) String

func (s *SetMemoryDynamic) String() string

func (*SetMemoryDynamic) Type

func (s *SetMemoryDynamic) Type() Type

type StringIndex

type StringIndex struct {
	Array int
	Index int
}

NOTE: Index is an instruction index

func (*StringIndex) String

func (i *StringIndex) String() string

func (*StringIndex) Type

func (i *StringIndex) Type() Type

type StringLength

type StringLength struct {
	Val int
}

func (*StringLength) String

func (a *StringLength) String() string

func (*StringLength) Type

func (a *StringLength) Type() Type

type Type

type Type int
const (
	INT Type = iota
	FLOAT
	STRING
	ARRAY
	NULL
)

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