runtime

package
v1.0.0-early-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GoFuncClass = MakeClassFromSuper("Native Function", NumericClass, NotCallable, goFuncIns)
View Source
var NotCallable = func(self BaseObject, args ...BaseObject) (BaseObject, error) {
	return nil, fmt.Errorf(fmt.Sprintf("'%s' is not callable", self.ToString()))
}
View Source
var Null = &Object{
	RClass:        NullClass,
	InternalValue: nil,
	ToStringFunc: func(self *Object) string {
		return "null"
	},
	InspectFunc: func(self *Object) string {
		return "null"
	},
	IsTruthyFunc: func(self *Object) bool {
		return false
	},
	EqualToFunc: func(self *Object, other BaseObject) bool {
		v, o := other.(*Object)
		if !o {
			return false
		}
		return self == v
	},
	CallFunc:  NotCallable,
	ParentObj: nil,
}
View Source
var NullClass = MakeClassFromSuper("Null", NumericClass,
	func(self BaseObject, args ...BaseObject) (BaseObject, error) {
		return nil, fmt.Errorf("cannot convert %s to null", args[0].Class().Name)
	}, nullIns)
View Source
var NumericClass = MakeClass("Numeric", NotCallable, NewEnvironment())
View Source
var ReservedKW = []string{
	"null",
	"print",
}

Functions

This section is empty.

Types

type BaseObject

type BaseObject interface {
	Class() *RClass
	Value() interface{}
	ToString() string
	Inspect() string
	InstanceVariableGet(string) (BaseObject, bool)
	InstanceVariables() *Environment

	IsTruthy() bool
	EqualTo(BaseObject) bool

	Call(self BaseObject, args ...BaseObject) (BaseObject, error)

	Parent() BaseObject
	SetParent(object BaseObject)
}

Every Gorilla Object and Class inherits from this

type CallFuncType

type CallFuncType func(self BaseObject, args ...BaseObject) (BaseObject, error)

type ConvertFuncType

type ConvertFuncType func(x BaseObject) (*Object, error)
var GorillaToInteger ConvertFuncType
var GorillaToString ConvertFuncType

type Environment

type Environment struct {
	Store storeType
}

Environment storage of Gorilla

var Global *Environment

Global is the global runtime storage

func NewEnvironment

func NewEnvironment() *Environment

func NewEnvironmentWithStore

func NewEnvironmentWithStore(store storeType) *Environment

func (*Environment) Copy

func (e *Environment) Copy() *Environment

func (*Environment) Get

func (e *Environment) Get(name string) (BaseObject, bool)

func (*Environment) Names

func (e *Environment) Names() []string

func (*Environment) Set

func (e *Environment) Set(name string, val BaseObject) BaseObject

type Object

type Object struct {
	RClass        *RClass
	InternalValue interface{}
	ToStringFunc  func(self *Object) string
	InspectFunc   func(self *Object) string
	IsTruthyFunc  func(self *Object) bool
	EqualToFunc   func(self *Object, other BaseObject) bool
	CallFunc      CallFuncType
	ParentObj     BaseObject
}

Object struct holds a normal object

func NewGoFunc

func NewGoFunc(function CallFuncType) *Object

func NewInteger

func NewInteger(value int64) *Object

func NewString

func NewString(value string) *Object

func (*Object) Call

func (o *Object) Call(self BaseObject, args ...BaseObject) (BaseObject, error)

func (*Object) Class

func (o *Object) Class() *RClass

func (*Object) EqualTo

func (o *Object) EqualTo(object BaseObject) bool

func (*Object) Inspect

func (o *Object) Inspect() string

func (*Object) InstanceVariableGet

func (o *Object) InstanceVariableGet(s string) (BaseObject, bool)

func (*Object) InstanceVariables

func (o *Object) InstanceVariables() *Environment

func (*Object) IsTruthy

func (o *Object) IsTruthy() bool

func (*Object) Parent

func (o *Object) Parent() BaseObject

func (*Object) SetParent

func (o *Object) SetParent(parent BaseObject)

func (*Object) ToString

func (o *Object) ToString() string

func (*Object) Value

func (o *Object) Value() interface{}

type RClass

type RClass struct {
	Name      string
	Instances *Environment

	// For children
	InstanceVars *Environment

	NewFunc CallFuncType
	// contains filtered or unexported fields
}

Defines a Class, or Type

var IntegerClass *RClass
var StringClass *RClass

func MakeClass

func MakeClass(
	Name string,
	NewFunc CallFuncType,
	InstanceVars *Environment,
) *RClass

func MakeClassFromSuper

func MakeClassFromSuper(
	Name string,
	super *RClass,
	NewFunc CallFuncType,
	InstanceVars *Environment,
) *RClass

func (*RClass) Call

func (R *RClass) Call(a BaseObject, b ...BaseObject) (BaseObject, error)

func (*RClass) Class

func (R *RClass) Class() *RClass

func (*RClass) EqualTo

func (R *RClass) EqualTo(object BaseObject) bool

func (*RClass) GetInstance

func (R *RClass) GetInstance(s string) (BaseObject, bool)

GetInstance gets instance variables for its children

func (*RClass) Inspect

func (R *RClass) Inspect() string

func (*RClass) InstanceVariableGet

func (R *RClass) InstanceVariableGet(s string) (BaseObject, bool)

func (*RClass) InstanceVariables

func (R *RClass) InstanceVariables() *Environment

func (*RClass) IsTruthy

func (R *RClass) IsTruthy() bool

func (*RClass) Parent

func (R *RClass) Parent() BaseObject

func (*RClass) SetParent

func (R *RClass) SetParent(_ BaseObject)

func (*RClass) ToString

func (R *RClass) ToString() string

func (*RClass) Value

func (R *RClass) Value() interface{}

type VM

type VM struct {
	Error *errors.VMERROR

	LastPopped BaseObject

	Environment *Environment
	// contains filtered or unexported fields
}

The Base VM struct

func NewVM

func NewVM(source []byte) *VM

NewVM creates a new vm from array of bytes

func NewVMWithStore

func NewVMWithStore(source []byte, env *Environment) *VM

NewVMWithStore is NewVM but with set environment

func (*VM) MakeError

func (vm *VM) MakeError(why string)

MakeError panics a VM error

func (*VM) Run

func (vm *VM) Run()

Run runs the bytecode

func (*VM) RunStatement

func (vm *VM) RunStatement()

RunStatement runs a single statement/opcode

Jump to

Keyboard shortcuts

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