exprvm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownExpression  = errors.New("Unknown Expression")
	ErrUnknownOperandType = errors.New("Unknown Operand Type")
)

Functions

This section is empty.

Types

type Chunk

type Chunk struct {
	Commands []Command
}

func Compile

func Compile(src string) (*Chunk, error)

func (*Chunk) AddCode

func (self *Chunk) AddCode(t Opcode)

func (*Chunk) AddCodeOperand

func (self *Chunk) AddCodeOperand(t Opcode, operand ...interface{})

func (*Chunk) String

func (self *Chunk) String() string

type Command

type Command struct {
	Type Opcode

	Operand []interface{}
}

func (*Command) String

func (self *Command) String() string

type Machine

type Machine struct {
	DataStack *Stack
}

func NewMachine

func NewMachine() *Machine

func (*Machine) Run

func (self *Machine) Run(chunk *Chunk)

type Opcode

type Opcode int
const (
	Opcode_Nop Opcode = iota
	Opcode_Push
	Opcode_Add
	Opcode_Sub
	Opcode_Mul
	Opcode_Div
	Opcode_Minus
	Opcode_Exit
)

func (Opcode) String

func (self Opcode) String() string

type Stack

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

func NewStack

func NewStack() *Stack

Create a new stack

func (*Stack) Len

func (this *Stack) Len() int

Return the number of items in the stack

func (*Stack) Peek

func (this *Stack) Peek() interface{}

View the top item on the stack

func (*Stack) Pop

func (this *Stack) Pop() interface{}

Pop the top item of the stack and return it

func (*Stack) Push

func (this *Stack) Push(value interface{})

Push a value onto the top of the stack

func (*Stack) String

func (self *Stack) String() string

Jump to

Keyboard shortcuts

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