ast

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: Apache-2.0, MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileExp

func CompileExp(c *ir.Compiler, e ExpNode) ir.Register

CompileExp compiles the given expression into a register and returns it.

func CompileExpInto

func CompileExpInto(c *ir.Compiler, e ExpNode, dst ir.Register)

CompileExpInto compiles the given expression into the given register

func CompileExpList

func CompileExpList(c *ir.Compiler, exps []ExpNode, dstRegs []ir.Register)

CompileExpList compiles the given expressions into free registers, which are recorded into dstRegs (hence exps and dstRegs must have the same length). Those registers are taken so need to be released by the caller when no longer needed.

func EmitInstr

func EmitInstr(c *ir.Compiler, l Locator, instr ir.Instruction)

func EmitJump

func EmitJump(c *ir.Compiler, l Locator, lbl ir.Name)

func EmitLoadConst

func EmitLoadConst(c *ir.Compiler, l Locator, k ir.Constant, reg ir.Register)

func EmitMove

func EmitMove(c *ir.Compiler, l Locator, dst, src ir.Register)

func IsNumber

func IsNumber(e ExpNode) bool

Types

type Assign

type Assign func(ir.Register)

type AssignStat

type AssignStat struct {
	Location
	Dest []Var
	Src  []ExpNode
}

func NewAssignStat

func NewAssignStat(dst []Var, src []ExpNode) AssignStat

func NewFunctionStat

func NewFunctionStat(fName Var, method Name, fx Function) AssignStat

func (AssignStat) CompileStat

func (s AssignStat) CompileStat(c *ir.Compiler)

func (AssignStat) HWrite

func (s AssignStat) HWrite(w HWriter)

type BFunctionCall

type BFunctionCall struct {
	Location
	// contains filtered or unexported fields
}

func (BFunctionCall) CompileCall

func (f BFunctionCall) CompileCall(c *ir.Compiler, tail bool)

func (BFunctionCall) CompileExp

func (f BFunctionCall) CompileExp(c *ir.Compiler, dst ir.Register) ir.Register

func (BFunctionCall) HWrite

func (f BFunctionCall) HWrite(w HWriter)

type BinOp

type BinOp struct {
	Location
	// contains filtered or unexported fields
}

func NewBinOp

func NewBinOp(left Locator, op ops.Op, right ExpNode) *BinOp

func (*BinOp) CompileExp

func (b *BinOp) CompileExp(c *ir.Compiler, dst ir.Register) ir.Register

func (*BinOp) HWrite

func (b *BinOp) HWrite(w HWriter)

type BlockStat

type BlockStat struct {
	Location
	Stats  []Stat
	Return []ExpNode
}

func NewBlockStat

func NewBlockStat(stats []Stat, rtn []ExpNode) BlockStat

func (BlockStat) CompileBlock

func (s BlockStat) CompileBlock(c *ir.Compiler)

func (BlockStat) CompileBlockNoPop

func (s BlockStat) CompileBlockNoPop(c *ir.Compiler) func()

func (BlockStat) CompileChunk

func (s BlockStat) CompileChunk(source string) *ir.Compiler

func (BlockStat) CompileStat

func (s BlockStat) CompileStat(c *ir.Compiler)

func (BlockStat) HWrite

func (s BlockStat) HWrite(w HWriter)

type Bool

type Bool struct {
	Location
	Val bool
}

func False

func False(tok *token.Token) Bool

func True

func True(tok *token.Token) Bool

func (Bool) CompileExp

func (b Bool) CompileExp(c *ir.Compiler, dst ir.Register) ir.Register

func (Bool) HWrite

func (b Bool) HWrite(w HWriter)

type BreakStat

type BreakStat struct {
	Location
}

func NewBreakStat

func NewBreakStat(tok *token.Token) BreakStat

func (BreakStat) CompileStat

func (s BreakStat) CompileStat(c *ir.Compiler)

func (BreakStat) HWrite

func (s BreakStat) HWrite(w HWriter)

type CondStat

type CondStat struct {
	Cond ExpNode
	Body BlockStat
}

CondStat is a conditional statement, used in e.g. if statements and while / repeat until loops.

func (CondStat) CompileCond

func (s CondStat) CompileCond(c *ir.Compiler, lbl ir.Label)

CompileCond compiles a conditional statement.

func (CondStat) HWrite

func (s CondStat) HWrite(w HWriter)

type EmptyStat

type EmptyStat struct {
	Location
}

func NewEmptyStat

func NewEmptyStat(tok *token.Token) EmptyStat

func (EmptyStat) CompileStat

func (s EmptyStat) CompileStat(c *ir.Compiler)

func (EmptyStat) HWrite

func (s EmptyStat) HWrite(w HWriter)

type EtcType

type EtcType struct {
	Location
}

func Etc

func Etc(tok *token.Token) EtcType

func (EtcType) CompileEtcExp

func (e EtcType) CompileEtcExp(c *ir.Compiler, dst ir.Register) ir.Register

func (EtcType) CompileExp

func (e EtcType) CompileExp(c *ir.Compiler, dst ir.Register) ir.Register

func (EtcType) CompileTailExp

func (e EtcType) CompileTailExp(c *ir.Compiler, dstRegs []ir.Register)

func (EtcType) HWrite

func (e EtcType) HWrite(w HWriter)

type ExpNode

type ExpNode interface {
	Node
	CompileExp(*ir.Compiler, ir.Register) ir.Register
}

ExpNode is an expression

func NewNumber

func NewNumber(id *token.Token) (ExpNode, error)

func NewStringArgs

func NewStringArgs(id *token.Token) ([]ExpNode, error)

type Float

type Float struct {
	Location
	// contains filtered or unexported fields
}

func NewFloat

func NewFloat(x float64) Float

func (Float) CompileExp

func (f Float) CompileExp(c *ir.Compiler, dst ir.Register) ir.Register

func (Float) HWrite

func (f Float) HWrite(w HWriter)

func (Float) Val

func (f Float) Val() float64

type ForInStat

type ForInStat struct {
	Location
	Vars   []Name
	Params []ExpNode
	Body   BlockStat
}

func NewForInStat

func NewForInStat(startTok, endTok *token.Token, itervars []Name, params []ExpNode, body BlockStat) *ForInStat

func (ForInStat) CompileStat

func (s ForInStat) CompileStat(c *ir.Compiler)

func (*ForInStat) HWrite

func (s *ForInStat) HWrite(w HWriter)

type ForStat

type ForStat struct {
	Location
	Var   Name
	Start ExpNode
	Stop  ExpNode
	Step  ExpNode
	Body  BlockStat
}

func NewForStat

func NewForStat(startTok, endTok *token.Token, itervar Name, params []ExpNode, body BlockStat) *ForStat

func (ForStat) CompileStat

func (s ForStat) CompileStat(c *ir.Compiler)

func (*ForStat) HWrite

func (s *ForStat) HWrite(w HWriter)

type Function

type Function struct {
	Location
	ParList
	Body BlockStat
	Name string
}

func NewFunction

func NewFunction(startTok, endTok *token.Token, parList ParList, body BlockStat) Function

func (Function) CompileBody

func (f Function) CompileBody(c *ir.Compiler)

func (Function) CompileExp

func (f Function) CompileExp(c *ir.Compiler, dst ir.Register) ir.Register

func (Function) HWrite

func (f Function) HWrite(w HWriter)

type FunctionCall

type FunctionCall struct {
	*BFunctionCall
}

func NewFunctionCall

func NewFunctionCall(target ExpNode, method Name, args []ExpNode) FunctionCall

func (FunctionCall) CompileEtcExp

func (f FunctionCall) CompileEtcExp(c *ir.Compiler, dst ir.Register) ir.Register

func (FunctionCall) CompileStat

func (f FunctionCall) CompileStat(c *ir.Compiler)

func (FunctionCall) CompileTailExp

func (f FunctionCall) CompileTailExp(c *ir.Compiler, dstRegs []ir.Register)

func (FunctionCall) InBrackets

func (f FunctionCall) InBrackets() *BFunctionCall

type GotoStat

type GotoStat struct {
	Location
	Label Name
}

func NewGotoStat

func NewGotoStat(gotoTok *token.Token, lbl Name) GotoStat

func (GotoStat) CompileStat

func (s GotoStat) CompileStat(c *ir.Compiler)

func (GotoStat) HWrite

func (s GotoStat) HWrite(w HWriter)

type HWriter

type HWriter interface {
	Writef(string, ...interface{})
	Indent()
	Dedent()
	Next()
}

HWriter is an interface for printing nodes

type IfStat

type IfStat struct {
	Location
	If      CondStat
	ElseIfs []CondStat
	Else    *BlockStat
}

func NewIfStat

func NewIfStat(endTok *token.Token) IfStat

func (IfStat) AddElse

func (s IfStat) AddElse(endTok *token.Token, body BlockStat) IfStat

func (IfStat) AddElseIf

func (s IfStat) AddElseIf(cond ExpNode, body BlockStat) IfStat

func (IfStat) AddIf

func (s IfStat) AddIf(ifTok *token.Token, cond ExpNode, body BlockStat) IfStat

func (IfStat) CompileStat

func (s IfStat) CompileStat(c *ir.Compiler)

func (IfStat) HWrite

func (s IfStat) HWrite(w HWriter)

type IndentWriter

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

func NewIndentWriter

func NewIndentWriter(w io.Writer) *IndentWriter

func (*IndentWriter) Dedent

func (w *IndentWriter) Dedent()

func (*IndentWriter) Indent

func (w *IndentWriter) Indent()

func (*IndentWriter) Next

func (w *IndentWriter) Next()

func (*IndentWriter) Writef

func (w *IndentWriter) Writef(f string, args ...interface{})

type IndexExp

type IndexExp struct {
	Location
	Coll ExpNode
	Idx  ExpNode
}

func NewIndexExp

func NewIndexExp(coll ExpNode, idx ExpNode) IndexExp

func (IndexExp) CompileAssign

func (e IndexExp) CompileAssign(c *ir.Compiler) Assign

func (IndexExp) CompileExp

func (e IndexExp) CompileExp(c *ir.Compiler, dst ir.Register) ir.Register

func (IndexExp) FunctionName

func (e IndexExp) FunctionName() string

func (IndexExp) HWrite

func (e IndexExp) HWrite(w HWriter)

type Int

type Int struct {
	Location
	// contains filtered or unexported fields
}

func NewInt

func NewInt(val uint64) Int

func (Int) CompileExp

func (n Int) CompileExp(c *ir.Compiler, dst ir.Register) ir.Register

func (Int) HWrite

func (n Int) HWrite(w HWriter)

func (Int) Val

func (n Int) Val() uint64

type LabelStat

type LabelStat struct {
	Location
	Name
}

func NewLabelStat

func NewLabelStat(label Name) LabelStat

func (LabelStat) CompileStat

func (s LabelStat) CompileStat(c *ir.Compiler)

func (LabelStat) HWrite

func (s LabelStat) HWrite(w HWriter)

type LocalFunctionStat

type LocalFunctionStat struct {
	Location
	Function
	Name Name
}

func NewLocalFunctionStat

func NewLocalFunctionStat(name Name, fx Function) LocalFunctionStat

func (LocalFunctionStat) CompileStat

func (s LocalFunctionStat) CompileStat(c *ir.Compiler)

func (LocalFunctionStat) HWrite

func (s LocalFunctionStat) HWrite(w HWriter)

type LocalStat

type LocalStat struct {
	Location
	Names  []Name
	Values []ExpNode
}

func NewLocalStat

func NewLocalStat(names []Name, values []ExpNode) LocalStat

func (LocalStat) CompileStat

func (s LocalStat) CompileStat(c *ir.Compiler)

func (LocalStat) HWrite

func (s LocalStat) HWrite(w HWriter)

type Location

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

func LocFromToken

func LocFromToken(tok *token.Token) Location

func LocFromTokens

func LocFromTokens(t1, t2 *token.Token) Location

func MergeLocations

func MergeLocations(l1, l2 Locator) Location

func (Location) EndPos

func (l Location) EndPos() *token.Pos

func (Location) Locate

func (l Location) Locate() Location

func (Location) StartPos

func (l Location) StartPos() *token.Pos

type Locator

type Locator interface {
	Locate() Location
}

type Name

type Name struct {
	Location
	Val string
}

func NewName

func NewName(id *token.Token) Name

func (Name) AstString

func (n Name) AstString() String

func (Name) CompileAssign

func (n Name) CompileAssign(c *ir.Compiler) Assign

func (Name) CompileExp

func (n Name) CompileExp(c *ir.Compiler, dst ir.Register) ir.Register

func (Name) FunctionName

func (n Name) FunctionName() string

func (Name) HWrite

func (n Name) HWrite(w HWriter)

type NilType

type NilType struct {
	Location
}

func Nil

func Nil(tok *token.Token) NilType

func (NilType) CompileExp

func (n NilType) CompileExp(c *ir.Compiler, dst ir.Register) ir.Register

func (NilType) HWrite

func (n NilType) HWrite(w HWriter)

type NoTableKey

type NoTableKey struct {
	Location
}

func (NoTableKey) CompileExp

func (k NoTableKey) CompileExp(c *ir.Compiler, dst ir.Register) ir.Register

func (NoTableKey) HWrite

func (k NoTableKey) HWrite(w HWriter)

type Node

type Node interface {
	Locator
	HWrite(w HWriter)
}

Node is a node in the AST

type NumberOracle

type NumberOracle interface {
	IsNumber() bool
}

type ParList

type ParList struct {
	Params  []Name
	HasDots bool
}

func NewParList

func NewParList(params []Name, hasDots bool) ParList

type RepeatStat

type RepeatStat struct {
	Location
	CondStat
}

RepeatStat represents a repeat / until statement.

func NewRepeatStat

func NewRepeatStat(repTok *token.Token, body BlockStat, cond ExpNode) RepeatStat

func (RepeatStat) CompileStat

func (s RepeatStat) CompileStat(c *ir.Compiler)

CompileStat implements Stat.CompileStat.

func (RepeatStat) HWrite

func (s RepeatStat) HWrite(w HWriter)

type Stat

type Stat interface {
	Node
	CompileStat(c *ir.Compiler)
}

Stat is a statement

type String

type String struct {
	Location
	Val []byte
}

String is a string literal.

func NewLongString

func NewLongString(id *token.Token) String

func NewString

func NewString(id *token.Token) (ss String, err error)

NewString returns a String from a string token, or an error if it couln't.

func (String) CompileExp

func (s String) CompileExp(c *ir.Compiler, dst ir.Register) ir.Register

func (String) HWrite

func (s String) HWrite(w HWriter)

type TableConstructor

type TableConstructor struct {
	Location
	Fields []TableField
}

func NewTableConstructor

func NewTableConstructor(opTok, clTok *token.Token, fields []TableField) TableConstructor

func (TableConstructor) CompileExp

func (t TableConstructor) CompileExp(c *ir.Compiler, dst ir.Register) ir.Register

func (TableConstructor) HWrite

func (t TableConstructor) HWrite(w HWriter)

type TableField

type TableField struct {
	Location
	Key   ExpNode
	Value ExpNode
}

func NewTableField

func NewTableField(key ExpNode, value ExpNode) TableField

type TailExpNode

type TailExpNode interface {
	Node
	CompileTailExp(*ir.Compiler, []ir.Register)
	CompileEtcExp(*ir.Compiler, ir.Register) ir.Register
}

TailExpNode is an expression which can be the tail of an exp list

type UnOp

type UnOp struct {
	Location
	Op      ops.Op
	Operand ExpNode
}

func NewUnOp

func NewUnOp(opTok *token.Token, op ops.Op, exp ExpNode) *UnOp

func (*UnOp) CompileExp

func (u *UnOp) CompileExp(c *ir.Compiler, dst ir.Register) ir.Register

func (*UnOp) HWrite

func (u *UnOp) HWrite(w HWriter)

type Var

type Var interface {
	ExpNode
	CompileAssign(*ir.Compiler) Assign
	FunctionName() string
}

Var is an l-value

type WhileStat

type WhileStat struct {
	Location
	CondStat
}

WhileStat represents a while / end statement

func NewWhileStat

func NewWhileStat(whileTok, endTok *token.Token, cond ExpNode, body BlockStat) WhileStat

func (WhileStat) CompileStat

func (s WhileStat) CompileStat(c *ir.Compiler)

CompileStat implements Stat.CompileStat.

func (WhileStat) HWrite

func (s WhileStat) HWrite(w HWriter)

Jump to

Keyboard shortcuts

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