Documentation ¶
Index ¶
- Constants
- Variables
- func DumpCode(w io.Writer, m *Machine)
- func DumpStack(w io.Writer, m *Machine)
- func ImportGlobal(m *Machine, name string, item interface{}) error
- func IsUInt32(s string) (uint32, bool)
- func ToUInt32(val MachineValue) uint32
- func TypeOf(m MachineValue) string
- type Array
- func (a *Array) Append(val MachineValue)
- func (a *Array) GetProperty(prop string) (MachineValue, *MachineException)
- func (a *Array) GetUInt32Property(prop uint32) (MachineValue, *MachineException)
- func (a *Array) Push(val MachineValue)
- func (a *Array) SetProperty(prop string, val MachineValue) *MachineException
- func (a *Array) SetUInt32Property(prop uint32, val MachineValue) *MachineException
- func (a *Array) ToJSON() string
- func (a *Array) ToString() string
- func (a *Array) Type() MachineType
- type Boolean
- func (b *Boolean) GetProperty(prop string) (MachineValue, *MachineException)
- func (b *Boolean) SetProperty(prop string, val MachineValue) *MachineException
- func (b *Boolean) ToBoolean() bool
- func (b *Boolean) ToJSON() string
- func (b *Boolean) ToNumber() float64
- func (b *Boolean) ToString() string
- func (b *Boolean) Type() MachineType
- type Expression
- type ExpressionList
- type Function
- type JSFunction
- type Machine
- func (m *Machine) AddConst(c MachineValue) int
- func (m *Machine) AddI(i byte) *Machine
- func (m *Machine) AddIParam(i byte, p int) *Machine
- func (m *Machine) Call(pc int) *MachineException
- func (m *Machine) DebugMode(debug bool)
- func (m *Machine) Execute() (MachineValue, *MachineException)
- func (m *Machine) Get(pos int) MachineValue
- func (m *Machine) GetConst(pos int) MachineValue
- func (m *Machine) GetIParam() int
- func (m *Machine) GetIParamAt(index int) int
- func (m *Machine) GlobalObject() *Object
- func (m *Machine) Pop(count int) int
- func (m *Machine) Push(e MachineValue) int
- func (m *Machine) Top() int
- type MachineException
- func ArrayMax(m *Machine, fn *Function, paramCount int) (int, *MachineException)
- func ArrayMin(m *Machine, fn *Function, paramCount int) (int, *MachineException)
- func MatchRegexp(m *Machine, fn *Function, paramCount int) (int, *MachineException)
- func NewMachineException(format string, args ...interface{}) *MachineException
- func Select(m *Machine, fn *Function, paramCount int) (int, *MachineException)
- func TimeUTC(m *Machine, fn *Function, paramCount int) (int, *MachineException)
- func ToArray(m *Machine, fn *Function, paramCount int) (int, *MachineException)
- func ToBoolean(m *Machine, fn *Function, paramCount int) (int, *MachineException)
- func ToJSON(m *Machine, fn *Function, paramCount int) (int, *MachineException)
- func ToNumber(m *Machine, fn *Function, paramCount int) (int, *MachineException)
- func ToString(m *Machine, fn *Function, paramCount int) (int, *MachineException)
- type MachineType
- type MachineValue
- type Null
- func (u *Null) GetProperty(prop string) (MachineValue, *MachineException)
- func (u *Null) SetProperty(prop string, val MachineValue) *MachineException
- func (u *Null) ToBoolean() bool
- func (u *Null) ToJSON() string
- func (u *Null) ToNumber() float64
- func (u *Null) ToString() string
- func (u *Null) Type() MachineType
- type Number
- func (n *Number) GetProperty(prop string) (MachineValue, *MachineException)
- func (n *Number) SetProperty(prop string, val MachineValue) *MachineException
- func (n *Number) ToBoolean() bool
- func (n *Number) ToJSON() string
- func (n *Number) ToNumber() float64
- func (n *Number) ToString() string
- func (n *Number) Type() MachineType
- type Object
- func (o *Object) GetProperty(prop string) (MachineValue, *MachineException)
- func (o *Object) SetProperty(prop string, val MachineValue) *MachineException
- func (o *Object) ToBoolean() bool
- func (o *Object) ToJSON() string
- func (o *Object) ToNumber() float64
- func (o *Object) ToString() string
- func (o *Object) Type() MachineType
- type Op
- type ParseError
- type String
- func (s *String) GetProperty(prop string) (MachineValue, *MachineException)
- func (s *String) SetProperty(prop string, val MachineValue) *MachineException
- func (s *String) ToBoolean() bool
- func (s *String) ToJSON() string
- func (s *String) ToNumber() float64
- func (s *String) ToString() string
- func (s *String) Type() MachineType
Constants ¶
View Source
const (
/**/
I_COUNT
)
View Source
const (
TAG = "jsmm"
)
View Source
const UNARY = 57362
Variables ¶
View Source
var NullConst = &Null{}
View Source
var Ops = [I_COUNT]Op{ {"load_const", 4, func(m *Machine) *MachineException { m.Push(m.GetConst(m.GetIParam())) return nil }}, {"get_global", 1, func(m *Machine) *MachineException { m.Push(&m.context) return nil }}, {"get_index", 1, func(m *Machine) *MachineException { objectref := m.Get(-2) key := m.Get(-1).ToString() m.Pop(2) r, err := objectref.GetProperty(key) if err != nil { return err } m.Push(r) return nil }}, {"set_index", 1, func(m *Machine) *MachineException { objectref := m.Get(-3) key := m.Get(-2).ToString() val := m.Get(-1) m.Pop(2) return objectref.SetProperty(key, val) }}, {"array_append", 1, func(m *Machine) *MachineException { arrayref := m.Get(-2) val := m.Get(-1) m.Pop(1) if array, ok := arrayref.(*Array); ok { array.Append(val) return nil } return NewMachineException("array_append called on something not a table") }}, {"add", 1, func(m *Machine) *MachineException { a := m.Get(-2) b := m.Get(-1) m.Pop(2) if a.Type() == TypeString || b.Type() == TypeString { m.Push(NewString(a.ToString() + b.ToString())) } else { m.Push(NewNumber(a.ToNumber() + b.ToNumber())) } return nil }}, {"sub", 1, func(m *Machine) *MachineException { a := m.Get(-2).ToNumber() b := m.Get(-1).ToNumber() m.Pop(2) m.Push(NewNumber(a - b)) return nil }}, {"mul", 1, func(m *Machine) *MachineException { a := m.Get(-2).ToNumber() b := m.Get(-1).ToNumber() m.Pop(2) m.Push(NewNumber(a * b)) return nil }}, {"div", 1, func(m *Machine) *MachineException { a := m.Get(-2).ToNumber() b := m.Get(-1).ToNumber() m.Pop(2) if b == 0 { if a == 0 { m.Push(NewNumber(math.NaN())) } else { m.Push(NewNumber(math.Inf(int(a)))) } } else { m.Push(NewNumber(a / b)) } return nil }}, {"mod", 1, func(m *Machine) *MachineException { a := m.Get(-2).ToNumber() b := m.Get(-1).ToNumber() m.Pop(2) m.Push(NewNumber(math.Mod(a, b))) return nil }}, {"equ", 1, func(m *Machine) *MachineException { a := m.Get(-2) b := m.Get(-1) m.Pop(2) m.Push(NewBoolean(equal(a, b))) return nil }}, {"neq", 1, func(m *Machine) *MachineException { a := m.Get(-2) b := m.Get(-1) m.Pop(2) m.Push(NewBoolean(!equal(a, b))) return nil }}, {"lt", 1, func(m *Machine) *MachineException { a := m.Get(-2) b := m.Get(-1) m.Pop(2) m.Push(NewBoolean(lessThan(a, b))) return nil }}, {"gt", 1, func(m *Machine) *MachineException { a := m.Get(-2) b := m.Get(-1) m.Pop(2) m.Push(NewBoolean(!equal(a, b) && !lessThan(a, b))) return nil }}, {"lte", 1, func(m *Machine) *MachineException { a := m.Get(-2) b := m.Get(-1) m.Pop(2) m.Push(NewBoolean(lessThan(a, b) || equal(a, b))) return nil }}, {"gte", 1, func(m *Machine) *MachineException { a := m.Get(-2) b := m.Get(-1) m.Pop(2) m.Push(NewBoolean(!lessThan(a, b))) return nil }}, {"and", 1, func(m *Machine) *MachineException { a := m.Get(-2) b := m.Get(-1) m.Pop(2) if a.ToBoolean() == false { m.Push(a) } else { m.Push(b) } return nil }}, {"or", 1, func(m *Machine) *MachineException { a := m.Get(-2) b := m.Get(-1) m.Pop(2) if a.ToBoolean() == true { m.Push(a) } else { m.Push(b) } return nil }}, {"not", 1, func(m *Machine) *MachineException { a := m.Get(-1).ToBoolean() m.Pop(1) m.Push(NewBoolean(!a)) return nil }}, {"neg", 1, func(m *Machine) *MachineException { a := m.Get(-1).ToNumber() m.Pop(1) m.Push(NewNumber(-a)) return nil }}, {"call", 4, func(m *Machine) *MachineException { objectref := m.Get(-2) key := m.Get(-1).ToString() paramcount := m.GetIParam() m.Pop(1) functionref, err := objectref.GetProperty(key) if err != nil { return err } if functionref.Type() == TypeFunction { if function, ok := functionref.(*Function); ok { result_len, merror := function.Call(m, paramcount) if merror == nil { if result_len == 1 { result := m.Get(-1) m.Pop(paramcount + 1) m.Push(result) } else { m.Pop(paramcount) } } return merror } } return NewMachineException("TypeError: '%s' is not a function", key) }}, {"newarray", 1, func(m *Machine) *MachineException { array := NewArray() m.Push(array) return nil }}, {"newobject", 1, func(m *Machine) *MachineException { object := NewObject() m.Push(object) return nil }}, }
Functions ¶
func ImportGlobal ¶
func ToUInt32 ¶
func ToUInt32(val MachineValue) uint32
func TypeOf ¶
func TypeOf(m MachineValue) string
Types ¶
type Array ¶
type Array struct { Object // contains filtered or unexported fields }
func NewArray ¶
func NewArray(init ...MachineValue) *Array
func (*Array) Append ¶
func (a *Array) Append(val MachineValue)
func (*Array) GetProperty ¶
func (a *Array) GetProperty(prop string) (MachineValue, *MachineException)
func (*Array) GetUInt32Property ¶
func (a *Array) GetUInt32Property(prop uint32) (MachineValue, *MachineException)
func (*Array) Push ¶
func (a *Array) Push(val MachineValue)
func (*Array) SetProperty ¶
func (a *Array) SetProperty(prop string, val MachineValue) *MachineException
func (*Array) SetUInt32Property ¶
func (a *Array) SetUInt32Property(prop uint32, val MachineValue) *MachineException
func (*Array) Type ¶
func (a *Array) Type() MachineType
type Boolean ¶
type Boolean struct {
// contains filtered or unexported fields
}
The Boolean type
func (*Boolean) GetProperty ¶
func (b *Boolean) GetProperty(prop string) (MachineValue, *MachineException)
func (*Boolean) SetProperty ¶
func (b *Boolean) SetProperty(prop string, val MachineValue) *MachineException
func (*Boolean) Type ¶
func (b *Boolean) Type() MachineType
type Expression ¶
func Parse ¶
func Parse(s string) (Expression, error)
type ExpressionList ¶
type ExpressionList []Expression
func NewExpressionList ¶
func NewExpressionList() ExpressionList
func (ExpressionList) Append ¶
func (e ExpressionList) Append(i Expression) ExpressionList
func (ExpressionList) Get ¶
func (e ExpressionList) Get(i int) Expression
func (ExpressionList) Length ¶
func (e ExpressionList) Length() int
func (ExpressionList) String ¶
func (e ExpressionList) String() string
type Function ¶
type Function struct { Object // contains filtered or unexported fields }
func NewFunction ¶
func NewFunction(name string, call JSFunction) *Function
func (*Function) Call ¶
func (f *Function) Call(m *Machine, paramcount int) (int, *MachineException)
func (*Function) Type ¶
func (f *Function) Type() MachineType
type JSFunction ¶
type JSFunction func(*Machine, *Function, int) (int, *MachineException)
type Machine ¶
type Machine struct {
// contains filtered or unexported fields
}
func NewMachine ¶
func NewMachine() *Machine
func (*Machine) AddConst ¶
func (m *Machine) AddConst(c MachineValue) int
func (*Machine) Call ¶
func (m *Machine) Call(pc int) *MachineException
func (*Machine) Execute ¶
func (m *Machine) Execute() (MachineValue, *MachineException)
func (*Machine) Get ¶
func (m *Machine) Get(pos int) MachineValue
func (*Machine) GetConst ¶
func (m *Machine) GetConst(pos int) MachineValue
func (*Machine) GetIParamAt ¶
func (*Machine) GlobalObject ¶
func (*Machine) Push ¶
func (m *Machine) Push(e MachineValue) int
type MachineException ¶
type MachineException struct {
// contains filtered or unexported fields
}
func MatchRegexp ¶
func MatchRegexp(m *Machine, fn *Function, paramCount int) (int, *MachineException)
func NewMachineException ¶
func NewMachineException(format string, args ...interface{}) *MachineException
func (*MachineException) Error ¶
func (e *MachineException) Error() string
type MachineType ¶
type MachineType int
const ( TypeError MachineType = iota TypeNull TypeBoolean TypeNumber TypeString TypeObject TypeArray TypeFunction )
type MachineValue ¶
type MachineValue interface { Type() MachineType ToString() string ToNumber() float64 ToBoolean() bool ToJSON() string GetProperty(prop string) (MachineValue, *MachineException) SetProperty(prop string, val MachineValue) *MachineException }
func Import ¶
func Import(item interface{}) (MachineValue, error)
func NewBoolean ¶
func NewBoolean(b bool) MachineValue
func NewBooleanString ¶
func NewBooleanString(v string) MachineValue
func NewNull ¶
func NewNull() MachineValue
func NewNumber ¶
func NewNumber(f float64) MachineValue
func NewNumberString ¶
func NewNumberString(v string) MachineValue
func NewString ¶
func NewString(v string) MachineValue
type Null ¶
type Null struct{}
The null type
func (*Null) GetProperty ¶
func (u *Null) GetProperty(prop string) (MachineValue, *MachineException)
func (*Null) SetProperty ¶
func (u *Null) SetProperty(prop string, val MachineValue) *MachineException
func (*Null) Type ¶
func (u *Null) Type() MachineType
type Number ¶
type Number struct {
// contains filtered or unexported fields
}
The Number type
func (*Number) GetProperty ¶
func (n *Number) GetProperty(prop string) (MachineValue, *MachineException)
func (*Number) SetProperty ¶
func (n *Number) SetProperty(prop string, val MachineValue) *MachineException
func (*Number) Type ¶
func (n *Number) Type() MachineType
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
func CreateObjectWithPrototype ¶
func CreateObjectWithPrototype(klass string, prototype MachineValue) Object
func (*Object) GetProperty ¶
func (o *Object) GetProperty(prop string) (MachineValue, *MachineException)
func (*Object) SetProperty ¶
func (o *Object) SetProperty(prop string, val MachineValue) *MachineException
func (*Object) Type ¶
func (o *Object) Type() MachineType
type ParseError ¶
type ParseError struct {
// contains filtered or unexported fields
}
func NewParseError ¶
func NewParseError(format string, args ...interface{}) *ParseError
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type String ¶
type String struct {
// contains filtered or unexported fields
}
The String type
func (*String) GetProperty ¶
func (s *String) GetProperty(prop string) (MachineValue, *MachineException)
func (*String) SetProperty ¶
func (s *String) SetProperty(prop string, val MachineValue) *MachineException
func (*String) Type ¶
func (s *String) Type() MachineType
Click to show internal directories.
Click to hide internal directories.