Documentation ¶
Index ¶
- Constants
- Variables
- func EqualObjects(a, b []Object) bool
- func IsError(v interface{}) bool
- type Bitstring
- type Bool
- type Builtin
- type Env
- type Error
- type Float
- type Function
- type Int
- type List
- type Map
- type Object
- type ObjectType
- type Record
- type ReturnValue
- type Scope
- type String
- type Unit
- type Verdict
Constants ¶
View Source
const ( UNKNOWN ObjectType = "unknown object" UNDEFINED ObjectType = "undefined value" ERROR ObjectType = "runtime error" BREAK ObjectType = "break event" CONTINUE ObjectType = "continue event" RETURN_VALUE ObjectType = "return value" INTEGER ObjectType = "integer" FLOAT ObjectType = "float" BOOL ObjectType = "boolean" STRING ObjectType = "string" BITSTRING ObjectType = "bitstring" FUNCTION ObjectType = "function" LIST ObjectType = "list" RECORD ObjectType = "record" MAP ObjectType = "map" BUILTIN_OBJ ObjectType = "builtin function" VERDICT ObjectType = "verdict" Bit Unit = 1 Hex Unit = 4 Octett Unit = 8 NoneVerdict Verdict = "none" PassVerdict Verdict = "pass" InconcVerdict Verdict = "inconc" FailVerdict Verdict = "fail" ErrorVerdict Verdict = "error" )
Variables ¶
View Source
var ( ErrSyntax = errors.New("invalid syntax") Undefined = &singelton{typ: UNDEFINED} Break = &singelton{typ: BREAK} Continue = &singelton{typ: CONTINUE} )
View Source
var Builtins = map[string]*Builtin{ "lengthof": {Fn: func(args ...Object) Object { if len(args) != 1 { return Errorf("wrong number of arguments. got=%d, want=1", len(args)) } switch arg := args[0].(type) { case *String: return Int{Int: big.NewInt(int64(len(arg.Value)))} case *Bitstring: return Int{Int: big.NewInt(int64(arg.Value.BitLen() / int(arg.Unit)))} } return Errorf("%s arguments not supported", args[0].Type()) }}, "rnd": {Fn: func(args ...Object) Object { if len(args) != 0 { return Errorf("wrong number of arguments. got=%d, want=0", len(args)) } return Float(rand.Float64()) }}, "int2float": {Fn: func(args ...Object) Object { if len(args) != 1 { return Errorf("wrong number of arguments. got=%d, want=1", len(args)) } i, ok := args[0].(Int) if !ok { return Errorf("%s arguments not supported", args[0].Type()) } f, _ := new(big.Float).SetInt(i.Int).Float64() return Float(f) }}, "float2int": {Fn: func(args ...Object) Object { if len(args) != 1 { return Errorf("wrong number of arguments. got=%d, want=1", len(args)) } f, ok := args[0].(Float) if !ok { return Errorf("%s arguments not supported", args[0].Type()) } i, _ := new(big.Float).SetFloat64(float64(f)).Int(nil) return Int{Int: i} }}, "log": {Fn: func(args ...Object) Object { var ss []string for _, arg := range args { ss = append(ss, arg.Inspect()) } fmt.Println(strings.Join(ss, " ")) return nil }}, }
Functions ¶
func EqualObjects ¶ added in v0.9.6
EqualObjects compares two Object slices for equality.
Types ¶
type Bitstring ¶ added in v0.9.5
func NewBitstring ¶ added in v0.9.5
func (*Bitstring) Type ¶ added in v0.9.5
func (b *Bitstring) Type() ObjectType
type Builtin ¶ added in v0.9.5
func (*Builtin) Type ¶ added in v0.9.5
func (b *Builtin) Type() ObjectType
type Error ¶
type Error struct {
Message string
}
func (*Error) Type ¶
func (e *Error) Type() ObjectType
type Function ¶
type Function struct { Params *ast.FormalPars Body *ast.BlockStmt Env Scope }
func (*Function) Type ¶
func (f *Function) Type() ObjectType
type List ¶ added in v0.9.5
type List struct {
Elements []Object
}
func (*List) Type ¶ added in v0.9.5
func (l *List) Type() ObjectType
type Map ¶ added in v0.9.6
type Map struct {
// contains filtered or unexported fields
}
Map is a map of objects.
func (*Map) Type ¶ added in v0.9.6
func (m *Map) Type() ObjectType
type ObjectType ¶
type ObjectType string
type Record ¶ added in v0.9.6
type Record struct {
// contains filtered or unexported fields
}
TODO(5nord) For simplicity we reuse the Map implementation. We should implement proper record semantics later.
func (*Record) Type ¶ added in v0.9.6
func (r *Record) Type() ObjectType
type ReturnValue ¶
type ReturnValue struct {
Value Object
}
func (*ReturnValue) Equal ¶ added in v0.9.6
func (r *ReturnValue) Equal(obj Object) bool
func (*ReturnValue) Inspect ¶
func (r *ReturnValue) Inspect() string
func (*ReturnValue) Type ¶
func (r *ReturnValue) Type() ObjectType
Click to show internal directories.
Click to hide internal directories.