runtime

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ValueTypeNil  = "nil"
	ValueTypeInt  = "int"
	ValueTypeStr  = "str"
	ValueTypeList = "list"
	ValueTypeMap  = "map"
)

Value Types ..

Variables

This section is empty.

Functions

func Tokenize

func Tokenize(src string) [][]string

Tokenize ..

Types

type Env

type Env struct {
	Labels map[string]int
	Vars   map[string]*Value // global vars
	Funcs  map[string]*funcDetail

	Pc  int
	Out func(interface{}, string)
	In  func() string
	// contains filtered or unexported fields
}

Env ..

func Evaluate

func Evaluate(program [][]string, env *Env) *Env

Evaluate ..

func Parse

func Parse(program [][]string) *Env

Parse ..

func (*Env) AdvancePc

func (env *Env) AdvancePc()

AdvancePc ..

func (*Env) AssignReturnedVal

func (env *Env) AssignReturnedVal(val *Value)

AssignReturnedVal ..

func (*Env) AssignVar

func (env *Env) AssignVar(varName string, val *Value)

AssignVar ..

func (*Env) Express

func (env *Env) Express(expr string) *Value

Express ..

func (*Env) GetFrame

func (env *Env) GetFrame() *Frame

GetFrame ..

func (*Env) GetVarVal

func (env *Env) GetVarVal(varName string) *Value

GetVarVal ..

func (*Env) GotoLabelByName

func (env *Env) GotoLabelByName(name string)

GotoLabelByName ..

func (*Env) NewFrame

func (env *Env) NewFrame(funcName string, args []*Value) *Frame

NewFrame ..

func (*Env) PopFrame

func (env *Env) PopFrame() *Frame

PopFrame ..

func (*Env) PushFrame

func (env *Env) PushFrame(funcName string, args []*Value)

PushFrame ..

type Frame

type Frame struct {
	FuncName string
	Pc       int
	Vars     map[string]*Value //local vars
}

Frame ..

func (*Frame) String

func (f *Frame) String() string

type List

type List struct {
	Head    *ListNode
	Tail    *ListNode
	Length  int
	HeadIdx int
	IdxMap  map[int]*ListNode
}

List ..

func ConstructList

func ConstructList(nums []interface{}) *List

ConstructList ..

func (*List) GetByIndex

func (list *List) GetByIndex(idx int) *Value

GetByIndex ..

func (*List) Len

func (list *List) Len() *Value

Len returns the length of the list

func (*List) Poll

func (list *List) Poll() *Value

Poll extrats an element from the left side of the list

func (*List) Pop

func (list *List) Pop() *Value

Pop extrats an element from the right side of the list

func (*List) Push

func (list *List) Push(val *Value)

Push adds an element to the right side of the list

func (*List) SetByIndex

func (list *List) SetByIndex(idx int, val *Value)

SetByIndex ..

func (List) String

func (list List) String() string

func (*List) ToValueArray

func (list *List) ToValueArray() []*Value

ToValueArray ..

type ListNode

type ListNode struct {
	Data *Value
	Prev *ListNode
	Next *ListNode
}

ListNode ..

type Map

type Map struct {
	Data map[string]*Value
}

Map ..

func (*Map) Delete

func (m *Map) Delete(key string)

Delete removes a key-value from the map

func (*Map) Get

func (m *Map) Get(key string) *Value

Get returns the value by key

func (*Map) GetKeys

func (m *Map) GetKeys() *List

GetKeys returns a list of all keys in the map

func (*Map) Put

func (m *Map) Put(key string, val *Value)

Put adds new values to the map

func (Map) String

func (m Map) String() string

type Value

type Value struct {
	Type    string
	Val     string
	ListPtr *List
	MapPtr  *Map
}

Value ..

func NewValue

func NewValue(val interface{}) *Value

NewValue ..

func ParseJSON

func ParseJSON(str string) *Value

ParseJSON ..

func (*Value) Equals

func (val *Value) Equals(val2 *Value) bool

Equals ..

func (*Value) GetValue

func (val *Value) GetValue() interface{}

GetValue returns the real value of the Value

func (*Value) IsGreaterThan

func (val *Value) IsGreaterThan(val2 *Value) bool

IsGreaterThan ..

func (*Value) MakeCopy

func (val *Value) MakeCopy() *Value

MakeCopy .. only available for str, list, nil

func (*Value) String

func (val *Value) String() string

func (*Value) StringWithType added in v0.1.2

func (val *Value) StringWithType() string

StringWithType ...

Jump to

Keyboard shortcuts

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