Documentation
¶
Index ¶
- Constants
- Variables
- func AddTopFunc(k string, f func(*Env))
- func AddTopValue(k string, v Value)
- func DeepEqual(a, b Value) bool
- func Fprint(w io.Writer, values ...Value)
- func Fprintf(w io.Writer, format string, args ...Value)
- func Fprintln(w io.Writer, values ...Value)
- func GetTopIndex(v Value) int
- func NewShape(s string) func(v Value) error
- func TestShapeFast(v Value, shape string) (err error)
- func Write(w io.Writer, v Value) (int, error)
- type Env
- func (env *Env) Bool(idx int) bool
- func (env *Env) Caller() *Object
- func (e *Env) Copy() *Env
- func (env *Env) CopyStack() []Value
- func (env *Env) Float64(idx int) float64
- func (env *Env) Get(index int) Value
- func (env *Env) Int(idx int) int
- func (env *Env) Int64(idx int) int64
- func (env *Env) IntDefault(idx int, defaultValue int) int
- func (env *Env) Interface(idx int) interface{}
- func (e *Env) Jump(label string)
- func (e *Env) MustProgram() *Program
- func (env *Env) Native(idx int) *Native
- func (env *Env) Num(idx int) Value
- func (env *Env) Object(idx int) *Object
- func (env *Env) Self() *Object
- func (env *Env) Set(index int, value Value)
- func (env *Env) SetA(a Value) bool
- func (env *Env) SetError(err error) bool
- func (env *Env) Shape(idx int, s string) Value
- func (env *Env) Size() int
- func (env *Env) Stack() []Value
- func (env *Env) Str(idx int) string
- func (env *Env) StrDefault(idx int, defaultValue string, minLen int) (res string)
- func (env *Env) String() string
- func (env *Env) This() Value
- type ExecError
- type Map
- func (m Map) Cap() int
- func (m *Map) Clear()
- func (m Map) Contains(k Value) bool
- func (m Map) Copy() Map
- func (m Map) DebugString() string
- func (m *Map) Delete(k Value) (prev Value)
- func (m Map) FindNext(k Value) (Value, Value)
- func (m Map) Foreach(f func(Value, *Value) bool)
- func (m Map) Get(k Value) (v Value, exists bool)
- func (m *Map) Init(count int) *Map
- func (m Map) Len() int
- func (m *Map) Merge(src *Map) *Map
- func (m *Map) Set(k, v Value) (prev Value)
- func (m Map) String() string
- func (m Map) ToObject() *Object
- type Native
- func (a *Native) Append(v ...Value)
- func (a *Native) Cap() int
- func (a *Native) Clear()
- func (a *Native) Concat(b *Native)
- func (a *Native) Copy(start, end int, from *Native)
- func (a *Native) Get(v int) Value
- func (a *Native) GetKey(k Value) (Value, bool)
- func (a *Native) HasPrototype(p *Object) bool
- func (a *Native) IsTypedArray() bool
- func (a *Native) IsUntypedArray() bool
- func (a *Native) Len() int
- func (a *Native) Marshal(w io.Writer, mt typ.MarshalType)
- func (a *Native) Prototype() *Object
- func (a *Native) Set(idx int, v Value)
- func (a *Native) SetKey(k, v Value)
- func (a *Native) Slice(start, end int) *Native
- func (a *Native) SliceInplace(start, end int)
- func (a *Native) ToValue() Value
- func (a *Native) Unwrap() interface{}
- func (a *Native) UnwrapFunc(f func(interface{}) interface{})
- func (a *Native) Values() []Value
- type NativeMeta
- type Object
- func (m *Object) AddMethod(name string, fun func(*Env)) *Object
- func (m *Object) Apply(e *Env, this Value, args ...Value) Value
- func (m *Object) Call(e *Env, args ...Value) (res Value)
- func (m *Object) Cap() int
- func (m *Object) Clear()
- func (m *Object) Contains(name Value) bool
- func (m *Object) Copy() *Object
- func (m *Object) Delete(name Value) (prev Value)
- func (m *Object) Find(name Value) (v Value, exists bool)
- func (m *Object) Foreach(f func(Value, *Value) bool)
- func (m *Object) Get(name Value) (v Value)
- func (m *Object) GetDefault(name, defaultValue Value) (v Value)
- func (obj *Object) GoString() string
- func (m *Object) HasOwnProperty(name Value) bool
- func (m *Object) HasPrototype(proto *Object) bool
- func (m *Object) Len() int
- func (m *Object) Merge(src *Object) *Object
- func (m *Object) Name() string
- func (m *Object) Prototype() *Object
- func (m *Object) Set(name, v Value) (prev Value)
- func (m *Object) SetProp(name string, v Value) *Object
- func (m *Object) SetPrototype(m2 *Object) *Object
- func (m *Object) String() string
- func (m *Object) ToMap() Map
- func (m *Object) ToValue() Value
- func (m *Object) TryApply(e *Env, this Value, args ...Value) (res Value)
- func (m *Object) TryCall(e *Env, args ...Value) (res Value)
- type Program
- type Stacktrace
- type Value
- func Array(v ...Value) Value
- func Bool(v bool) Value
- func Byte(s byte) Value
- func Bytes(b []byte) Value
- func Error(e *Env, err interface{}) Value
- func Float64(f float64) Value
- func Func(name string, f func(*Env)) Value
- func Int(i int) Value
- func Int64(i int64) Value
- func Rune(r rune) Value
- func Str(s string) Value
- func UnsafeStr(b []byte) Value
- func ValueOf(i interface{}) Value
- func (v Value) AssertNumber(msg string) Value
- func (v Value) AssertObject(msg string) *Object
- func (v Value) AssertShape(shape, msg string) Value
- func (v Value) AssertString(msg string) string
- func (v Value) Bool() bool
- func (v Value) Bytes() []byte
- func (v Value) Closer() io.Closer
- func (v Value) Duration() time.Duration
- func (v Value) Equal(r Value) bool
- func (v Value) Error() *ExecError
- func (v Value) Float64() float64
- func (a Value) HasPrototype(p *Object) bool
- func (v Value) HashCode() uint32
- func (v Value) Int() int
- func (v Value) Int64() int64
- func (v Value) Interface() interface{}
- func (v Value) IsArray() bool
- func (v Value) IsBytes() bool
- func (v Value) IsError() bool
- func (v Value) IsFalse() bool
- func (v Value) IsInt64() bool
- func (v Value) IsNil() bool
- func (v Value) IsNumber() bool
- func (v Value) IsObject() bool
- func (v Value) IsPanic() bool
- func (v Value) IsString() bool
- func (v Value) IsTrue() bool
- func (v Value) JSONString() string
- func (v Value) Len() int
- func (a Value) Less(b Value) bool
- func (v Value) MarshalJSON() ([]byte, error)
- func (v Value) Native() *Native
- func (v Value) Object() *Object
- func (v Value) Reader() io.Reader
- func (v Value) Str() string
- func (v Value) String() string
- func (v Value) Stringify(p io.Writer, j typ.MarshalType)
- func (v Value) ToType(t reflect.Type) reflect.Value
- func (v Value) Type() typ.ValueType
- func (v Value) UnsafeFloat64() float64
- func (v Value) UnsafeInt64() int64
- func (v Value) Writer() io.Writer
Constants ¶
const (
ValueSize = unsafe.Sizeof(Value{})
)
const Version int64 = 499
Variables ¶
var ( Nil = Value{} Zero = Int64(0) NullStr = Str("") False = Value{0, falseMarker} True = Value{1, trueMarker} )
var Proto struct { Object, Bool, Str, Int, Float, Func, Native, Bytes, Array, Error, Panic Object NativeMap, NativePtr, NativeIntf, Channel Object Reader, Writer, Closer, ReadWriter, ReadCloser, WriteCloser, ReadWriteCloser NativeMeta WrapperMeta, ReadlinesMeta, ArrayMeta, VarargMeta, BytesMeta, StringsMeta NativeMeta ErrorMeta, PanicMeta NativeMeta }
Functions ¶
func AddTopFunc ¶
func AddTopValue ¶
func GetTopIndex ¶
func TestShapeFast ¶
Types ¶
type Env ¶
type Env struct { A Value // contains filtered or unexported fields }
Env is the environment for a function to run within. 'stack' represents the global stack, a running function use 'stack[stackOffset:]' as its local stack. 'A' stores the result of the execution. 'global' is the topmost function scope, a.k.a. Program.
func (*Env) Bool ¶
Bool returns value at 'idx' in current stack and asserts its Type() to be a boolean.
func (*Env) Float64 ¶
Float64 returns value at 'idx' in current stack and asserts its Type() to be a number.
func (*Env) Int ¶
Int returns value at 'idx' in current stack and asserts its Type() to be a number.
func (*Env) Int64 ¶
Int64 returns value at 'idx' in current stack and asserts its Type() to be a number.
func (*Env) IntDefault ¶
IntDefault returns value at 'idx' in current stack and asserts its Type() to be a number. If value is Nil, then 'defaultValue' will be returned.
func (*Env) MustProgram ¶
func (*Env) Native ¶
Native returns value at 'idx' in current stack and asserts its Type() to be a Native.
func (*Env) Num ¶
Num returns value at 'idx' in current stack and asserts its Type() to be a number.
func (*Env) Object ¶
Object returns value at 'idx' in current stack and asserts its Type() to be an Object.
func (*Env) Str ¶
Str returns value at 'idx' in current stack and asserts its Type() to be a string.
func (*Env) StrDefault ¶
type ExecError ¶
type ExecError struct {
// contains filtered or unexported fields
}
ExecError represents the runtime error/panic.
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
func TopSymbols ¶
func TopSymbols() Map
func (Map) Cap ¶
Cap returns the capacity of the map in terms of key-value pairs, one pair is (ValueSize * 2 + 8) bytes.
func (*Map) Clear ¶
func (m *Map) Clear()
Clear clears all keys in the map, where already allocated memory will be reused.
func (Map) DebugString ¶
func (Map) FindNext ¶
FindNext finds the next key after 'k', returns nil if not found. The output is stable between map changes (e.g. Delete).
func (Map) Foreach ¶
Foreach iterates all keys in the map, for each of them, 'f(key, &value)' will be called. Values are passed by pointers and it is legal to manipulate them directly in 'f'. Deletions are allowed during Foreach(), but the iteration may be incomplete therefore.
type Native ¶
type Native struct {
// contains filtered or unexported fields
}
func NewNativeWithMeta ¶
func NewNativeWithMeta(any interface{}, meta *NativeMeta) *Native
func (*Native) HasPrototype ¶
func (*Native) IsTypedArray ¶
func (*Native) IsUntypedArray ¶
func (*Native) SliceInplace ¶
func (*Native) UnwrapFunc ¶
func (a *Native) UnwrapFunc(f func(interface{}) interface{})
type NativeMeta ¶
type NativeMeta struct { Name string Proto *Object Len func(*Native) int Cap func(*Native) int Clear func(*Native) Values func(*Native) []Value Get func(*Native, int) Value Set func(*Native, int, Value) GetKey func(*Native, Value) (Value, bool) SetKey func(*Native, Value, Value) Append func(*Native, ...Value) Slice func(*Native, int, int) *Native SliceInplace func(*Native, int, int) Copy func(*Native, int, int, *Native) Concat func(*Native, *Native) Marshal func(*Native, io.Writer, typ.MarshalType) Next func(*Native, Value) Value }
func NewEmptyNativeMeta ¶
func NewEmptyNativeMeta(name string, proto *Object) *NativeMeta
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
func NewBareFunc ¶
func NewNamedObject ¶
func (*Object) AddMethod ¶
AddMethod binds function 'fun' to property 'name' in the object, making 'fun' a method of the object. This differs from 'Set(name, Func(name, fun))' because the latter one, as not being a method, can't use 'this' argument when called.
func (*Object) Apply ¶
Apply calls the object with provided 'this' value, 'e' is for stacktracing and is optional.
func (*Object) Contains ¶
Contains returns true if object contains property 'name', inherited properties will also be checked.
func (*Object) Delete ¶
Delete deletes a local property from the object. Inherited properties are omitted and never deleted.
func (*Object) Find ¶
Find retrieves the property by 'name', returns false as the second argument if not found.
func (*Object) Foreach ¶
Foreach iterates all local properties in the object, refer to 'Map.Foreach' for more helps.
func (*Object) GetDefault ¶
GetDefault retrieves the property by 'name', returns 'defaultValue' if not found.
func (*Object) HasOwnProperty ¶
HasOwnProperty returns true if 'name' is a local property in the object.
func (*Object) HasPrototype ¶
func (*Object) Set ¶
Set sets a local property in the object. Inherited property with the same name will be shadowed.
func (*Object) SetProp ¶
SetProp sets property by string 'name', which is short for Set(Str(name), v).
func (*Object) SetPrototype ¶
type Program ¶
type Program struct { File string Source string MaxStackSize int64 Globals Map Stdout io.Writer Stderr io.Writer Stdin io.Reader // contains filtered or unexported fields }
func NewBareProgram ¶
func (*Program) LocalsObject ¶
type Stacktrace ¶
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is the basic data type used by the intepreter, an empty Value naturally represent nil.
func Error ¶
Error creates an error, 'e' can be nil, indicating that the returned error has no stacktrace.
func UnsafeStr ¶
UnsafeStr creates a string value from []byte, its content may change if []byte changed.
func (Value) AssertNumber ¶
func (Value) AssertObject ¶
func (Value) AssertShape ¶
func (Value) AssertString ¶
func (Value) Closer ¶
Closer creates an io.Closer from value, Close() may fail if value doesn't support closing.
func (Value) Duration ¶
Duration returns the number value as a time.Duration, it assumes the number represents the Unix timestamp in seconds.
func (Value) Float64 ¶
Float64 returns value as a float (integers will be promoted to floats), Type() should be checked beforehand.
func (Value) HasPrototype ¶
func (Value) Int64 ¶
Int64 returns value as an int64 (floats will be truncated to integers), Type() should be checked beforehand.
func (Value) Interface ¶
func (v Value) Interface() interface{}
Interface returns value as an interface{}
func (Value) JSONString ¶
func (Value) MarshalJSON ¶
func (Value) Reader ¶
Reader creates an io.Reader from value, Read() may fail if value doesn't support reading.
func (Value) ToType ¶
ToType converts value to reflect.Value based on reflect.Type. The result, even not being Zero, may be illegal to use in certain calls.