runtime

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StringId = iota
	NumberId
	BoolId
	DictId
	FuncId
	ArrayId
	NilId
	AnyId
)

Variables

View Source
var (
	STRING = PrimitiveType{StringId, "string"}
	NUMBER = PrimitiveType{NumberId, "number"}
	BOOL   = PrimitiveType{BoolId, "bool"}
	DICT   = PrimitiveType{DictId, "dict"}
	FUNC   = PrimitiveType{FuncId, "func"}
	ARRAY  = PrimitiveType{ArrayId, "array"}
	NIL    = PrimitiveType{NilId, "nil"}
	ANY    = PrimitiveType{AnyId, "any"}
)

Functions

func AssertValidSymbolName

func AssertValidSymbolName(name string)

func DecodeDict

func DecodeDict[T any](dict RTDict) (T, error)

func DecodeMap

func DecodeMap[T any](mp map[interface{}]interface{}) (T, error)

func TypeName

func TypeName(t Type) string

func ValidSymbolName

func ValidSymbolName(name string) error

Types

type ArgDef

type ArgDef struct {
	Type Type
	Name string
	Desc string
}

type Arguments

type Arguments struct {
	R Runtime
	// contains filtered or unexported fields
}

func NewArguments

func NewArguments(R Runtime, data []RTValue) *Arguments

func (*Arguments) CheckBool

func (args *Arguments) CheckBool(i int) (RTBool, error)

func (*Arguments) CheckDict

func (args *Arguments) CheckDict(i int) (RTDict, error)

func (*Arguments) CheckFunction

func (args *Arguments) CheckFunction(i int) (RTFunction, error)

func (*Arguments) CheckNumber

func (args *Arguments) CheckNumber(i int) (RTNumber, error)

func (*Arguments) CheckString

func (args *Arguments) CheckString(i int) (RTString, error)

func (*Arguments) EnsureBool

func (args *Arguments) EnsureBool(i int) RTBool

func (*Arguments) EnsureDict

func (args *Arguments) EnsureDict(i int) RTDict

func (*Arguments) EnsureFunction

func (args *Arguments) EnsureFunction(i int) RTFunction

func (*Arguments) EnsureNumber

func (args *Arguments) EnsureNumber(i int) RTNumber

func (*Arguments) EnsureString

func (args *Arguments) EnsureString(i int) RTString

func (*Arguments) Get

func (args *Arguments) Get(i int) RTValue

func (*Arguments) Len

func (args *Arguments) Len() int

type CustomFunc

type CustomFunc func(runtime Runtime, args *Arguments) RTValue

type CustomFunctionType

type CustomFunctionType struct {
	Type
	Args []ArgDef
}

type CustomStructType

type CustomStructType struct {
	Type
	Fields []Field
}

func Custom

func Custom(name string, fields []Field) CustomStructType

func CustomStruct

func CustomStruct(name string, fields []Field) CustomStructType

type DescribableType

type DescribableType struct {
	Type
	// contains filtered or unexported fields
}

func TypeWithDesc

func TypeWithDesc(t Type, desc string) DescribableType

func (DescribableType) Describe

func (t DescribableType) Describe() string

type Field

type Field struct {
	Name     string
	Type     Type
	Desc     string
	Optional bool
}

func NewField

func NewField(name string, typ Type, desc string) Field

type PrimitiveType

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

func (PrimitiveType) Id

func (typ PrimitiveType) Id() int

func (PrimitiveType) Is

func (typ PrimitiveType) Is(other Type) bool

func (PrimitiveType) Name

func (typ PrimitiveType) Name() string

type RTArray

type RTArray interface {
	RTValue
	Map() []interface{}
}

type RTBool

type RTBool interface {
	RTValue
	Value() bool
}

type RTDict

type RTDict interface {
	RTValue
	Map() map[interface{}]interface{}
}

type RTFunction

type RTFunction interface {
	RTValue
}

type RTNil

type RTNil interface {
	RTValue
}

type RTNumber

type RTNumber interface {
	RTValue
}

type RTString

type RTString interface {
	RTValue
}

type RTValue

type RTValue interface {
	String() string
	Type() Type
}

type Runtime

type Runtime interface {
	Lang() string
	ExecFile(path string) error
	ExecString(source string) error
	String(str string) RTString
	Close()
	RaiseError(format string, args ...interface{})
	CheckString(v RTValue) (RTString, error)
	CheckNumber(v RTValue) (RTNumber, error)
	CheckDict(v RTValue) (RTDict, error)
	CheckBool(v RTValue) (RTBool, error)
	CheckFunction(v RTValue) (RTFunction, error)
	CheckArray(v RTValue) (RTArray, error)
	EnsureString(v RTValue) RTString
	EnsureNumber(v RTValue) RTNumber
	EnsureDict(v RTValue) RTDict
	EnsureBool(v RTValue) RTBool
	EnsureFunction(v RTValue) RTFunction
	EnsureArray(v RTValue) RTArray
	InvokeFunction(fn RTFunction, params ...RTValue) error
	InvokeFunctionSafe(fn RTFunction, params ...RTValue) error
	SetGlobal(name string, val RTValue) ([]string, error)
	SetFunction(
		name string,
		desc string,
		args []ArgDef,
		fn CustomFunc,
	) error
}

type Type

type Type interface {
	Is(other Type) bool
	Id() int
	Name() string
}

type TypedArrayType

type TypedArrayType struct {
	Type
	ItemType Type
}

func TypedArray

func TypedArray(itemType Type) TypedArrayType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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