runtime

package
v0.0.0-...-dbeee19 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ErrPanic is an error caused by a panic within the interpreter.
	ErrPanic = iota
	// ErrUnknownVariable is raised when trying to resolve an unknown symbol.
	ErrUnknownVariable
)

Variables

This section is empty.

Functions

func Array

func Array(ctx *Context, args ...parser.Value) parser.Value

Array define single or multiple-dimension arrays using the make-array function

func Coerce

func Coerce(ctx *Context, args ...parser.Value) parser.Value

Coerce returns the value v converted to type t

func ConcatIdentifier

func ConcatIdentifier(funcPrefix parser.Identifier, funcName parser.Identifier) parser.Identifier

ConcatIdentifier ...

func Def

func Def(ctx *Context, args ...parser.Value) parser.Value

Def is a group of statements that together perform a task.

func Eval

func Eval(ctx *Context, raw ...parser.Value) parser.Value

Eval implements the eval function.

func For

func For(ctx *Context, args ...parser.Value) parser.Value

For implements for loop

func If

func If(ctx *Context, args ...parser.Value) parser.Value

If implements the 'if' builtin function. It has to be an Internal interface - otherwise, both true & false expressions would have been already evaluated.

func Import

func Import(ctx *Context, args ...parser.Value) (v parser.Value)

Import implements the import package feature.

func Invoke

func Invoke(ctx *Context, args ...parser.Value) parser.Value

Invoke call a method from native value

func Lambda

func Lambda(ctx *Context, args ...parser.Value) parser.Value

Lambda anonymous functions that are evaluated only when they are encountered in the program

func Length

func Length(elt []parser.Value) int64

Length implements the len function.

func Let

func Let(ctx *Context, args ...parser.Value) parser.Value

Let implements the let reserved word.

func MethodNameTransform

func MethodNameTransform(name string) (newName string)

MethodNameTransform ...

func OpAdd

func OpAdd(values ...interface{}) interface{}

OpAdd implements the '+' function. It tries to determine automatically the type based on the first argument.

func OpEqual

func OpEqual(values ...interface{}) interface{}

OpEqual implements the == comparaison operator. It can work on more than 2 arguments - it will return true only if they have all the same value.

func OpGreater

func OpGreater(values ...interface{}) interface{}

OpGreater implements the > comparaison operator.

func OpGreaterEqual

func OpGreaterEqual(values ...interface{}) interface{}

OpGreaterEqual implements the >= comparaison operator.

func OpLess

func OpLess(values ...interface{}) interface{}

OpLess implements the < comparaison operator.

func OpLessEqual

func OpLessEqual(values ...interface{}) interface{}

OpLessEqual implements the <= comparaison operator.

func OpMul

func OpMul(values ...interface{}) interface{}

OpMul implements the '*' function. It tries to determine automatically the type based on the first argument.

func OpNotEqual

func OpNotEqual(values ...interface{}) interface{}

OpNotEqual implements the != comparaison operator.

func OpPow

func OpPow(values ...float64) float64

OpPow implements exponentiation '**' function. returns x**y, the base-x exponential of y TODO: https://github.com/rumlang/rum/issues/139

func OpSub

func OpSub(values ...interface{}) interface{}

OpSub implements the '-' function. It tries to determine automatically the type based on the first argument.

func Package

func Package(name string, values ...interface{}) interface{}

Package implements the package reserved word.

func Panic

func Panic(v interface{})

Panic implements the panic function.

func Print

func Print(args ...interface{})

Print implements the print function.

func Println

func Println(args ...interface{})

Println implements the print function.

func Sprintf

func Sprintf(args ...interface{}) string

Sprintf implements the sprintf function.

func Type

func Type(v interface{}) string

Type implements the type function.

Types

type Adapter

type Adapter func(values ...interface{}) ([]interface{}, error)

Adapter is an function type can be used to change/check params to registred golang functions

func CheckArity

func CheckArity(n int) Adapter

CheckArity return an function to check if the arity of function call is n

func ParamToFloat64

func ParamToFloat64(p int) Adapter

ParamToFloat64 return an Adapter to convert the p nth param to float64 type

func ParamToInt64

func ParamToInt64(p int) Adapter

ParamToInt64 return an Adapter to convert the p nth param to int64 type

type CSVLib

type CSVLib struct{}

CSVLib struct

func (*CSVLib) LoadLib

func (l *CSVLib) LoadLib(ctx *Context, funcPrefix parser.Identifier)

LoadLib function to StringLib struct

type Context

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

Context contains details about the current execution frame.

func NewContext

func NewContext(parent *Context) *Context

NewContext create new runtime context instance and load default parser funcrions

func (*Context) Dump

func (c *Context) Dump()

Dump the context content

func (*Context) Get

func (c *Context) Get(id parser.Identifier) parser.Value

Get returns the content of the specified variable. It will automatically look up parent context if needed. Generate a panic with an Error object if the specified variable does not exists.

func (*Context) MustEval

func (c *Context) MustEval(input parser.Value) parser.Value

MustEval evaluates the provided value, generatic panics when something bad happens. Panics will be *Error instances, containing the call stack.

func (*Context) RegisterType

func (c *Context) RegisterType(typedNil interface{})

RegisterType register an new type in runtime. A nil or zero typed value must be the parameter

func (*Context) Set

Set an iten in parser function map

func (*Context) SetFn

func (c *Context) SetFn(id parser.Identifier, v interface{}, adapters ...Adapter)

SetFn an function in parser function map

func (*Context) TryEval

func (c *Context) TryEval(input parser.Value) (parser.Value, error)

TryEval evaluates the provided value and catch any panic, return an error instead.

type Error

type Error struct {
	Code ErrorCode
	Msg  string
	// Stack is the glop call stack corresponding to where the error was raised.
	// First value is inner-most eval'ed value.
	Stack []parser.Value

	PanicRecovered interface{}
	PanicStack     []byte
}

Error is sent through panic when something went wrong during the execution.

func (*Error) Error

func (e *Error) Error() string

func (*Error) String

func (e *Error) String() string

type ErrorCode

type ErrorCode int

ErrorCode type to parser errors

func (ErrorCode) String

func (c ErrorCode) String() string

type Internal

type Internal func(*Context, ...parser.Value) parser.Value

Internal is the type used to recognized internal functions (for which arguments are not evaluated automatically) from regular functions.

type StdLib

type StdLib interface {
	LoadLib(ctx *Context, funcPrefix parser.Identifier)
}

StdLib ...

type StringsLib

type StringsLib struct{}

StringsLib struct

func (*StringsLib) LoadLib

func (l *StringsLib) LoadLib(ctx *Context, funcPrefix parser.Identifier)

LoadLib function to StringLib struct

Jump to

Keyboard shortcuts

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