search

package
v0.0.0-...-2eeea8d Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ISN_NOP = iota
	ISN_PUSH
	ISN_POP
	ISN_AND
	ISN_OR
	ISN_NOT
	ISN_FIND
	ISN_JZ
	ISN_JNZ
	ISN_CLEAR
	ISN_RET
	ISN_MAX
)
View Source
const (
	EOF = iota
	TOK_ILLEGAL

	TOK_AND
	TOK_OR
	TOK_NOT

	TOK_TERM
	TOK_STRING

	TOK_LPAREN
	TOK_RPAREN
	TOK_COLON
)
View Source
const (
	OPERAND_INVALID = iota
	OPERAND_INTEGER
	OPERAND_LABEL
	OPERAND_TERM
)
View Source
const (
	PROGRAM_CAPACITY = 512
)
View Source
const (
	STACK_CAPACITY = 512
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BySyntax

type BySyntax []*Syntax

func (BySyntax) Len

func (a BySyntax) Len() int

func (BySyntax) Less

func (a BySyntax) Less(i, j int) bool

func (BySyntax) Swap

func (a BySyntax) Swap(i, j int)

type ByToken

type ByToken []element

func (ByToken) Len

func (t ByToken) Len() int

func (ByToken) Less

func (t ByToken) Less(i, j int) bool

func (ByToken) Swap

func (t ByToken) Swap(i, j int)

type IOperand

type IOperand interface {
	String() string
	Bytecode() string
	Type() OperandType
	TypeString() string
}

type Inst

type Inst struct {
	Label       *Label
	Instruction Isn
	Operand     IOperand
}

func NewInst

func NewInst(isn Isn, op IOperand) *Inst

func (*Inst) Bytecode

func (i *Inst) Bytecode() string

func (*Inst) String

func (i *Inst) String() string

type Integer

type Integer struct {
	Operand
	Literal int
}

func MakeInteger

func MakeInteger(val int) *Integer

func (Integer) Bytecode

func (i Integer) Bytecode() string

func (Integer) String

func (i Integer) String() string

type Isn

type Isn int

func (Isn) Bytecode

func (i Isn) Bytecode() string

func (Isn) String

func (i Isn) String() string

type Label

type Label struct {
	Operand
	Target string
	Offset int
}

func MakeLabel

func MakeLabel(target string) *Label

func (Label) Bytecode

func (o Label) Bytecode() string

func (Label) String

func (o Label) String() string

type LabelTable

type LabelTable struct {
	// contains filtered or unexported fields
}
var (
	LabelOnce sync.Once
	LabelInst *LabelTable
)

func GetLabelTable

func GetLabelTable() *LabelTable

func (*LabelTable) Lookup

func (lt *LabelTable) Lookup(sym string) *Label

func (*LabelTable) MakeLabel

func (lt *LabelTable) MakeLabel() *Label

type Lexer

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

func NewLexer

func NewLexer(reader io.Reader) *Lexer

func (*Lexer) Lex

func (l *Lexer) Lex() (Position, Token, string)

type MapFn

type MapFn func(*Syntax)

type Operand

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

func (*Operand) Type

func (o *Operand) Type() OperandType

func (*Operand) TypeString

func (o *Operand) TypeString() string

type OperandType

type OperandType int

type Optimiser

type Optimiser struct {
	Unoptimised []*Inst
	Optimised   []*Inst
}

func NewOptimiser

func NewOptimiser(isns []*Inst) *Optimiser

func (*Optimiser) Optimise

func (o *Optimiser) Optimise()

func (*Optimiser) Pretty

func (o *Optimiser) Pretty() string

func (*Optimiser) PrettyBytecode

func (o *Optimiser) PrettyBytecode() string

type Parser

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

func NewParser

func NewParser() *Parser

func (*Parser) Parse

func (p *Parser) Parse(source string) (*Optimiser, error)

func (*Parser) PrintSyntax

func (p *Parser) PrintSyntax()

func (*Parser) PrintTokens

func (p *Parser) PrintTokens()

type Position

type Position struct {
	Line   int
	Column int
}

type Program

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

func NewProgram

func NewProgram() Program

func (*Program) Dump

func (s *Program) Dump()

func (*Program) Len

func (s *Program) Len() int

func (*Program) Pop

func (s *Program) Pop() (*Inst, bool)

func (*Program) Push

func (s *Program) Push(val *Inst) bool

type ProgramType

type ProgramType [PROGRAM_CAPACITY]*Inst

type Stack

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

func NewStack

func NewStack() Stack

func (*Stack) Clear

func (s *Stack) Clear()

func (*Stack) Dump

func (s *Stack) Dump()

func (*Stack) Len

func (s *Stack) Len() int

func (*Stack) Pop

func (s *Stack) Pop() (interface{}, bool)

func (*Stack) Push

func (s *Stack) Push(val interface{}) bool

type StackType

type StackType [STACK_CAPACITY]interface{}

type Syntax

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

func MakeAST

func MakeAST() *Syntax

func (*Syntax) AddChild

func (s *Syntax) AddChild(node *Syntax)

func (*Syntax) Build

func (s *Syntax) Build() []*Inst

func (*Syntax) Map

func (s *Syntax) Map(fn MapFn)

func (*Syntax) MapChildren

func (s *Syntax) MapChildren(fn MapFn)

func (*Syntax) RemoveChild

func (s *Syntax) RemoveChild(node *Syntax) bool

func (*Syntax) Sort

func (s *Syntax) Sort()

func (*Syntax) String

func (s *Syntax) String() string

type Term

type Term struct {
	Operand
	Field    string
	Pattern  string
	Compiled *regexp.Regexp
}

func MakeTerm

func MakeTerm(field, pattern string) *Term

func (Term) Bytecode

func (o Term) Bytecode() string

func (Term) String

func (o Term) String() string

type Token

type Token int

func (Token) String

func (t Token) String() string

type VM

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

func NewVM

func NewVM() *VM

func (*VM) Debug

func (vm *VM) Debug(format string, args ...interface{})

func (*VM) LoadCode

func (vm *VM) LoadCode(code []*Inst) error

func (*VM) Result

func (vm *VM) Result() int

func (*VM) Run

func (vm *VM) Run()

func (*VM) SetBuffer

func (vm *VM) SetBuffer(buf string) error

func (*VM) SetDebug

func (vm *VM) SetDebug(val bool)

func (*VM) String

func (vm *VM) String() string

Jump to

Keyboard shortcuts

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