vm

package
v0.0.0-...-5e4a643 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ICONST
	SCONST
	FCONST
	IADD
	ISUB
	IMUL
	IDIV
	JMP
	JMPT
	JMPF
	ILT
	IEQ
	COPY
	GLOAD
	GSTORE
	LOAD
	STORE
	CALL
	RET
	// Use to print value from stack
	PRINT
	// Use to print value from constant pool which value is
	// identified by an index from stack
	PRINTC
	HALT
)

Instructions of assembly

Variables

This section is empty.

Functions

This section is empty.

Types

type Frame

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

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

Stack is a representation of the stack data structure

func NewStack

func NewStack[T any]() *Stack[T]

NewStack returns an initialized stack of integers

func (*Stack[T]) AtIndex

func (s *Stack[T]) AtIndex(index int) T

AtIndex returns a value which is at provided index

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() T

Peek returns the top element in stack

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() T

Pop removes the top element and returns its value

func (*Stack[T]) Push

func (s *Stack[T]) Push(value T)

Push adds new element on top of the stack

func (*Stack[T]) Size

func (s *Stack[T]) Size() int

Size returns the number of elements in the stack

func (*Stack[T]) ToString

func (s *Stack[T]) ToString() string

type VM

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

VM contains properties of CPU

func NewVM

func NewVM(program []int, constantPool map[int]interface{}) *VM

NewVM initializes the virtual machine

func (*VM) Run

func (vm *VM) Run(w io.Writer)

Run runs the virtual machine and interprets its program by executing instruction after instruction

func (*VM) SetFlags

func (vm *VM) SetFlags(flags map[string]interface{})

SetFlags sets the flags for virtual machine

Jump to

Keyboard shortcuts

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