object

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package object defines all available object types in Tamarin.

For external users of Tamarin, most often an object.Object interface will be type asserted to a specific object type, such as *object.Float.

For example:

switch obj := obj.(type) {
case *object.String:
	// do something with obj.Value
case *object.Float:
	// do something with obj.Value
}

The Type() method of each object may also be used to get a string name of the object type, such as "STRING" or "FLOAT".

Index

Constants

View Source
const TenMB = 1024 * 1024 * 10

Variables

View Source
var (
	Nil   = &NilType{}
	True  = &Bool{value: true}
	False = &Bool{value: false}
)

Functions

func AsList added in v0.0.10

func AsList(obj Object) (*List, *Error)

func AsMap added in v0.0.11

func AsMap(obj Object) (*Map, *Error)

func AsSet added in v0.0.9

func AsSet(obj Object) (*Set, *Error)

func CompareTypes added in v0.0.9

func CompareTypes(a, b Object) int

func Equals added in v0.0.12

func Equals(a, b Object) bool

func IsError

func IsError(obj Object) bool

func ResolveIndex added in v0.0.13

func ResolveIndex(idx int64, size int64) (int64, error)

ResolveIndex checks that the index is inbounds and transforms a negative index into the corresponding positive index. If the index is out of bounds, an error is returned.

func ResolveIntSlice added in v0.0.13

func ResolveIntSlice(slice Slice, size int64) (start int64, stop int64, err error)

ResolveIntSlice checks that the slice start and stop indices are inbounds and transforms negative indices into the corresponding positive indices. If the slice is out of bounds, an error is returned.

func WithCallFunc added in v0.0.12

func WithCallFunc(ctx context.Context, fn CallFunc) context.Context

WithCallFunc adds an CallFunc to the context, which can be used by objects to call a Tamarin function at runtime.

Types

type Bool added in v0.0.11

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

Bool wraps bool and implements Object and Hashable interface.

func NewBool added in v0.0.12

func NewBool(value bool) *Bool

func Not added in v0.0.12

func Not(b *Bool) *Bool

func (*Bool) Compare added in v0.0.11

func (b *Bool) Compare(other Object) (int, error)

func (*Bool) Equals added in v0.0.12

func (b *Bool) Equals(other Object) Object

func (*Bool) GetAttr added in v0.0.12

func (b *Bool) GetAttr(name string) (Object, bool)

func (*Bool) HashKey added in v0.0.11

func (b *Bool) HashKey() HashKey

func (*Bool) Inspect added in v0.0.11

func (b *Bool) Inspect() string

func (*Bool) Interface added in v0.0.13

func (b *Bool) Interface() interface{}

func (*Bool) IsTruthy added in v0.0.13

func (b *Bool) IsTruthy() bool

func (*Bool) String added in v0.0.11

func (b *Bool) String() string

func (*Bool) Type added in v0.0.11

func (b *Bool) Type() Type

func (*Bool) Value added in v0.0.11

func (b *Bool) Value() bool

type BooleanConverter added in v0.0.9

type BooleanConverter struct{}

BooleanConverter converts between bool and Bool.

func (*BooleanConverter) From added in v0.0.9

func (c *BooleanConverter) From(obj interface{}) (Object, error)

func (*BooleanConverter) To added in v0.0.9

func (c *BooleanConverter) To(obj Object) (interface{}, error)

func (*BooleanConverter) Type added in v0.0.9

func (c *BooleanConverter) Type() reflect.Type

type Builtin

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

Builtin wraps func and implements Object interface.

func NewBuiltin added in v0.0.13

func NewBuiltin(name string, fn BuiltinFunction, module ...*Module) *Builtin

func NewErrorHandler added in v0.0.13

func NewErrorHandler(name string, fn BuiltinFunction, module ...*Module) *Builtin

func NewNoopBuiltin added in v0.0.6

func NewNoopBuiltin(name string, module *Module) *Builtin

NewNoopBuiltin creates a builtin function that has no effect.

func (*Builtin) Call added in v0.0.13

func (b *Builtin) Call(ctx context.Context, args ...Object) Object

func (*Builtin) Equals added in v0.0.12

func (b *Builtin) Equals(other Object) Object

func (*Builtin) GetAttr added in v0.0.12

func (b *Builtin) GetAttr(name string) (Object, bool)

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

func (*Builtin) Interface added in v0.0.13

func (b *Builtin) Interface() interface{}

func (*Builtin) IsErrorHandler added in v0.0.13

func (b *Builtin) IsErrorHandler() bool

func (*Builtin) IsTruthy added in v0.0.13

func (b *Builtin) IsTruthy() bool

func (*Builtin) Key added in v0.0.6

func (b *Builtin) Key() string

Returns a string that uniquely identifies this builtin function.

func (*Builtin) Name added in v0.0.6

func (b *Builtin) Name() string

func (*Builtin) String added in v0.0.6

func (b *Builtin) String() string

func (*Builtin) Type

func (b *Builtin) Type() Type

func (*Builtin) Value added in v0.0.13

func (b *Builtin) Value() BuiltinFunction

type BuiltinFunction

type BuiltinFunction func(ctx context.Context, args ...Object) Object

BuiltinFunction holds the type of a built-in function.

type CallFunc added in v0.0.12

type CallFunc func(ctx context.Context, scope interface{}, fn Object, args []Object) Object

CallFunc defines a type signature for a function that can call a Tamarin function. In part, this type definition is useful to avoid a circular dependency with the evaluator package.

func GetCallFunc added in v0.0.12

func GetCallFunc(ctx context.Context) (CallFunc, bool)

GetCallFunc returns the CallFunc from the context, if it exists.

type Comparable added in v0.0.9

type Comparable interface {
	Compare(other Object) (int, error)
}

Comparable is an interface used to compare two objects.

-1 if this < other
 0 if this == other
 1 if this > other

type Container added in v0.0.13

type Container interface {

	// GetItem implements the [key] operator for a container type.
	GetItem(key Object) (Object, *Error)

	// GetSlice implements the [start:stop] operator for a container type.
	GetSlice(s Slice) (Object, *Error)

	// SetItem implements the [key] = value operator for a container type.
	SetItem(key, value Object) *Error

	// DelItem implements the del [key] operator for a container type.
	DelItem(key Object) *Error

	// Contains returns true if the given item is found in this container.
	Contains(item Object) *Bool

	// Len returns the number of items in this container.
	Len() *Int

	// Iter returns an iterator for this container.
	Iter() Iterator
}

type ContextConverter added in v0.0.12

type ContextConverter struct{}

ContextConverter converts between context.Context and Context.

func (*ContextConverter) From added in v0.0.12

func (c *ContextConverter) From(obj interface{}) (Object, error)

func (*ContextConverter) To added in v0.0.12

func (c *ContextConverter) To(obj Object) (interface{}, error)

func (*ContextConverter) Type added in v0.0.12

func (c *ContextConverter) Type() reflect.Type

type Control added in v0.0.13

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

Control is used internally during evaluation of "break", "continue", and "return" statements.

func NewBreak added in v0.0.13

func NewBreak() *Control

func NewContinue added in v0.0.13

func NewContinue() *Control

func NewReturn added in v0.0.13

func NewReturn(value Object) *Control

func (*Control) Equals added in v0.0.13

func (c *Control) Equals(other Object) Object

func (*Control) GetAttr added in v0.0.13

func (c *Control) GetAttr(name string) (Object, bool)

func (*Control) Inspect added in v0.0.13

func (c *Control) Inspect() string

func (*Control) Interface added in v0.0.13

func (c *Control) Interface() interface{}

func (*Control) IsTruthy added in v0.0.13

func (c *Control) IsTruthy() bool

func (*Control) Keyword added in v0.0.13

func (c *Control) Keyword() string

func (*Control) String added in v0.0.13

func (c *Control) String() string

func (*Control) Type added in v0.0.13

func (c *Control) Type() Type

func (*Control) Value added in v0.0.13

func (c *Control) Value() Object

type DefaultTypeRegistry added in v0.0.12

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

DefaultTypeRegistry implements the GoTypeRegistry interface.

func NewTypeRegistry added in v0.0.12

func NewTypeRegistry(opts ...TypeRegistryOpts) (*DefaultTypeRegistry, error)

NewTypeRegistry creates a GoTypeRegistry that can be used to proxy method calls to various struct types. The provided type conversion functions are used to translate between Go and Tamarin types.

func (*DefaultTypeRegistry) GetAttr added in v0.0.12

func (p *DefaultTypeRegistry) GetAttr(obj interface{}, name string) (GoAttr, bool)

func (*DefaultTypeRegistry) GetType added in v0.0.12

func (p *DefaultTypeRegistry) GetType(obj interface{}) (*GoType, bool)

func (*DefaultTypeRegistry) Register added in v0.0.12

func (p *DefaultTypeRegistry) Register(obj interface{}) (*GoType, error)

type Entry added in v0.0.13

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

func NewEntry added in v0.0.13

func NewEntry(key, value Object) *Entry

func (*Entry) Equals added in v0.0.13

func (e *Entry) Equals(other Object) Object

func (*Entry) GetAttr added in v0.0.13

func (e *Entry) GetAttr(name string) (Object, bool)

func (*Entry) Inspect added in v0.0.13

func (e *Entry) Inspect() string

func (*Entry) Interface added in v0.0.13

func (e *Entry) Interface() interface{}

func (*Entry) IsTruthy added in v0.0.13

func (e *Entry) IsTruthy() bool

func (*Entry) Key added in v0.0.13

func (e *Entry) Key() Object

func (*Entry) Type added in v0.0.13

func (e *Entry) Type() Type

func (*Entry) Value added in v0.0.13

func (e *Entry) Value() Object

type Error

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

Error wraps a Go error interface and implements Object.

func AsFloat added in v0.0.4

func AsFloat(obj Object) (float64, *Error)

func AsInt added in v0.0.13

func AsInt(obj Object) (int64, *Error)

func AsString added in v0.0.4

func AsString(obj Object) (result string, err *Error)

func AsTime added in v0.0.4

func AsTime(obj Object) (result time.Time, err *Error)

func Errorf added in v0.0.13

func Errorf(format string, a ...interface{}) *Error

func NewArgsError added in v0.0.12

func NewArgsError(fn string, takes, given int) *Error

func NewArgsRangeError added in v0.0.12

func NewArgsRangeError(fn string, takesMin, takesMax, given int) *Error

func NewError

func NewError(err error) *Error

func Sort added in v0.0.12

func Sort(items []Object) *Error

Sort a list in place. If the list contains a non-comparable object, an error is returned.

func (*Error) Compare added in v0.0.9

func (e *Error) Compare(other Object) (int, error)

func (*Error) Equals added in v0.0.12

func (e *Error) Equals(other Object) Object

func (*Error) GetAttr added in v0.0.12

func (e *Error) GetAttr(name string) (Object, bool)

func (*Error) Inspect

func (e *Error) Inspect() string

func (*Error) Interface added in v0.0.13

func (e *Error) Interface() interface{}

func (*Error) IsTruthy added in v0.0.13

func (e *Error) IsTruthy() bool

func (*Error) Message

func (e *Error) Message() *String

func (*Error) String added in v0.0.13

func (e *Error) String() string

func (*Error) Type

func (e *Error) Type() Type

func (*Error) Value added in v0.0.13

func (e *Error) Value() error

type ErrorConverter added in v0.0.9

type ErrorConverter struct{}

ErrorConverter converts between error and Error.

func (*ErrorConverter) From added in v0.0.9

func (c *ErrorConverter) From(obj interface{}) (Object, error)

func (*ErrorConverter) To added in v0.0.9

func (c *ErrorConverter) To(obj Object) (interface{}, error)

func (*ErrorConverter) Type added in v0.0.9

func (c *ErrorConverter) Type() reflect.Type

type Float

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

Float wraps float64 and implements Object and Hashable interfaces.

func NewFloat added in v0.0.4

func NewFloat(value float64) *Float

func (*Float) Compare added in v0.0.9

func (f *Float) Compare(other Object) (int, error)

func (*Float) Equals added in v0.0.12

func (f *Float) Equals(other Object) Object

func (*Float) GetAttr added in v0.0.12

func (f *Float) GetAttr(name string) (Object, bool)

func (*Float) HashKey

func (f *Float) HashKey() HashKey

func (*Float) Inspect

func (f *Float) Inspect() string

func (*Float) Interface added in v0.0.13

func (f *Float) Interface() interface{}

func (*Float) IsTruthy added in v0.0.13

func (f *Float) IsTruthy() bool

func (*Float) String

func (f *Float) String() string

func (*Float) Type

func (f *Float) Type() Type

func (*Float) Value

func (f *Float) Value() float64

type Float32Converter added in v0.0.9

type Float32Converter struct{}

Float32Converter converts between float32 and Float.

func (*Float32Converter) From added in v0.0.9

func (c *Float32Converter) From(obj interface{}) (Object, error)

func (*Float32Converter) To added in v0.0.9

func (c *Float32Converter) To(obj Object) (interface{}, error)

func (*Float32Converter) Type added in v0.0.9

func (c *Float32Converter) Type() reflect.Type

type Float64Converter added in v0.0.9

type Float64Converter struct{}

Float64Converter converts between float64 and Float.

func (*Float64Converter) From added in v0.0.9

func (c *Float64Converter) From(obj interface{}) (Object, error)

func (*Float64Converter) To added in v0.0.9

func (c *Float64Converter) To(obj Object) (interface{}, error)

func (*Float64Converter) Type added in v0.0.9

func (c *Float64Converter) Type() reflect.Type

type Function

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

Function contains the AST for user defined function and implements Object interface.

func NewFunction added in v0.0.13

func NewFunction(
	name string,
	parameters []*ast.Ident,
	body *ast.Block,
	defaults map[string]ast.Expression,
	scope Scope,
) *Function

func (*Function) Body

func (f *Function) Body() *ast.Block

func (*Function) Defaults

func (f *Function) Defaults() map[string]ast.Expression

func (*Function) Equals added in v0.0.12

func (f *Function) Equals(other Object) Object

func (*Function) GetAttr added in v0.0.12

func (f *Function) GetAttr(name string) (Object, bool)

func (*Function) Inspect

func (f *Function) Inspect() string

func (*Function) Interface added in v0.0.13

func (f *Function) Interface() interface{}

func (*Function) IsTruthy added in v0.0.13

func (f *Function) IsTruthy() bool

func (*Function) Name added in v0.0.13

func (f *Function) Name() string

func (*Function) Parameters

func (f *Function) Parameters() []*ast.Ident

func (*Function) Scope

func (f *Function) Scope() Scope

func (*Function) Type

func (f *Function) Type() Type

type GoAttr added in v0.0.12

type GoAttr interface {

	// Name of the attribute.
	Name() string

	// Type indicates whether the attribute is a method or a field.
	AttrType() GoAttrType
}

GoAttr is an interface to represent an attribute on a Go type. This could be either a field or a method.

type GoAttrType added in v0.0.12

type GoAttrType string

GoAttrType is used to indicate whether a GoAttr is a field or a method.

const (
	// GoAttrTypeMethod indicates that the GoAttr is a method.
	GoAttrTypeMethod GoAttrType = "method"

	// GoAttrTypeField indicates that the GoAttr is a field.
	GoAttrTypeField GoAttrType = "field"
)

type GoField added in v0.0.12

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

GoField represents a single field on a Go type that can be read or written.

func (*GoField) AttrType added in v0.0.12

func (f *GoField) AttrType() GoAttrType

func (*GoField) Converter added in v0.0.12

func (f *GoField) Converter() TypeConverter

func (*GoField) Name added in v0.0.12

func (f *GoField) Name() string

func (*GoField) Tag added in v0.0.12

func (f *GoField) Tag() reflect.StructTag

func (*GoField) Type added in v0.0.12

func (f *GoField) Type() reflect.Type

type GoMethod added in v0.0.12

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

GoMethod represents a single method on a Go type that can be proxied.

func (*GoMethod) AttrType added in v0.0.12

func (m *GoMethod) AttrType() GoAttrType

func (*GoMethod) Name added in v0.0.12

func (m *GoMethod) Name() string

type GoType added in v0.0.12

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

GoType represents a single Go type whose methods and fields can be proxied.

func (*GoType) AttrByName added in v0.0.12

func (gt *GoType) AttrByName(name string) (GoAttr, bool)

func (*GoType) Attrs added in v0.0.12

func (gt *GoType) Attrs() []GoAttr

func (*GoType) FieldByName added in v0.0.12

func (gt *GoType) FieldByName(name string) (*GoField, bool)

func (*GoType) Fields added in v0.0.12

func (gt *GoType) Fields() []*GoField

func (*GoType) MethodByName added in v0.0.12

func (gt *GoType) MethodByName(name string) (*GoMethod, bool)

func (*GoType) Methods added in v0.0.12

func (gt *GoType) Methods() []*GoMethod

func (*GoType) Name added in v0.0.12

func (gt *GoType) Name() string

func (*GoType) StructType added in v0.0.12

func (gt *GoType) StructType() reflect.Type

func (*GoType) Type added in v0.0.12

func (gt *GoType) Type() reflect.Type

type GoTypeRegistry added in v0.0.12

type GoTypeRegistry interface {

	// Register determines type and method information for the provided
	// object and saves that information for use in later method call proxying.
	Register(obj interface{}) (*GoType, error)

	// GetType returns the GoType for the given object and a boolean that
	// indicates whether the type was found. Only types that were previously
	// registered will be found.
	GetType(obj interface{}) (*GoType, bool)

	// GetAttr returns the GoAttr for the given object and name.
	GetAttr(obj interface{}, name string) (GoAttr, bool)
}

GoTypeRegistry is an interface that defines a way to register Go types and call methods on instances of those types.

type HashKey

type HashKey struct {
	// Type of the object being referenced.
	Type Type
	// FltValue is used as the key for floats.
	FltValue float64
	// IntValue is used as the key for integers.
	IntValue int64
	// StrValue is used as the key for strings.
	StrValue string
}

HashKey is used to identify unique values in a set.

type Hashable

type Hashable interface {

	// Hash returns a hash key for the given object.
	HashKey() HashKey
}

Hashable types can be hashed and consequently used in a set.

type HttpResponse

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

func NewHttpResponse added in v0.0.13

func NewHttpResponse(resp *http.Response) *HttpResponse

func (*HttpResponse) ContentLength added in v0.0.13

func (r *HttpResponse) ContentLength() *Int

func (*HttpResponse) Equals added in v0.0.12

func (r *HttpResponse) Equals(other Object) Object

func (*HttpResponse) GetAttr added in v0.0.12

func (r *HttpResponse) GetAttr(name string) (Object, bool)

func (*HttpResponse) Header added in v0.0.13

func (r *HttpResponse) Header() *Map

func (*HttpResponse) Inspect

func (r *HttpResponse) Inspect() string

func (*HttpResponse) Interface added in v0.0.13

func (r *HttpResponse) Interface() interface{}

func (*HttpResponse) IsTruthy added in v0.0.13

func (r *HttpResponse) IsTruthy() bool

func (*HttpResponse) JSON

func (r *HttpResponse) JSON() *Result

func (*HttpResponse) Proto added in v0.0.13

func (r *HttpResponse) Proto() *String

func (*HttpResponse) Status added in v0.0.13

func (r *HttpResponse) Status() *String

func (*HttpResponse) StatusCode added in v0.0.13

func (r *HttpResponse) StatusCode() *Int

func (*HttpResponse) Text

func (r *HttpResponse) Text() *Result

func (*HttpResponse) Type

func (r *HttpResponse) Type() Type

type Int added in v0.0.11

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

Int wraps int64 and implements Object and Hashable interfaces.

func NewInt added in v0.0.11

func NewInt(value int64) *Int

func (*Int) Compare added in v0.0.11

func (i *Int) Compare(other Object) (int, error)

func (*Int) Equals added in v0.0.12

func (i *Int) Equals(other Object) Object

func (*Int) GetAttr added in v0.0.12

func (i *Int) GetAttr(name string) (Object, bool)

func (*Int) HashKey added in v0.0.11

func (i *Int) HashKey() HashKey

func (*Int) Inspect added in v0.0.11

func (i *Int) Inspect() string

func (*Int) Interface added in v0.0.13

func (i *Int) Interface() interface{}

func (*Int) IsTruthy added in v0.0.13

func (i *Int) IsTruthy() bool

func (*Int) String added in v0.0.11

func (i *Int) String() string

func (*Int) Type added in v0.0.11

func (i *Int) Type() Type

func (*Int) Value added in v0.0.11

func (i *Int) Value() int64

type Int64Converter added in v0.0.9

type Int64Converter struct{}

Int64Converter converts between int64 and Integer.

func (*Int64Converter) From added in v0.0.9

func (c *Int64Converter) From(obj interface{}) (Object, error)

func (*Int64Converter) To added in v0.0.9

func (c *Int64Converter) To(obj Object) (interface{}, error)

func (*Int64Converter) Type added in v0.0.9

func (c *Int64Converter) Type() reflect.Type

type IntConverter added in v0.0.9

type IntConverter struct{}

IntConverter converts between int and Integer.

func (*IntConverter) From added in v0.0.9

func (c *IntConverter) From(obj interface{}) (Object, error)

func (*IntConverter) To added in v0.0.9

func (c *IntConverter) To(obj Object) (interface{}, error)

func (*IntConverter) Type added in v0.0.9

func (c *IntConverter) Type() reflect.Type

type Iterator added in v0.0.13

type Iterator interface {
	Object

	// Next returns the next item in the iterator and a bool indicating whether
	// the returned item is valid. If the iteration is complete, (nil, false) is
	// returned.
	Next() (IteratorEntry, bool)
}

Iterator is an interface used to iterate over a container.

type IteratorEntry added in v0.0.13

type IteratorEntry interface {
	Object
	Key() Object
	Value() Object
}

IteratorEntry is a single item returned by an iterator.

type List added in v0.0.10

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

List of objects

func NewList added in v0.0.10

func NewList(items []Object) *List

func NewStringList added in v0.0.10

func NewStringList(s []string) *List

func (*List) Append added in v0.0.12

func (ls *List) Append(obj Object)

Append adds an item at the end of the list.

func (*List) Clear added in v0.0.12

func (ls *List) Clear()

Clear removes all the items from the list.

func (*List) Compare added in v0.0.10

func (ls *List) Compare(other Object) (int, error)

func (*List) Contains added in v0.0.13

func (ls *List) Contains(item Object) *Bool

Contains returns true if the given item is found in this container.

func (*List) Copy added in v0.0.12

func (ls *List) Copy() *List

Copy returns a shallow copy of the list.

func (*List) Count added in v0.0.12

func (ls *List) Count(obj Object) int64

Count returns the number of items with the specified value.

func (*List) DelItem added in v0.0.13

func (ls *List) DelItem(key Object) *Error

DelItem implements the del [key] operator for a container type.

func (*List) Each added in v0.0.12

func (ls *List) Each(ctx context.Context, fn Object) Object

func (*List) Equals added in v0.0.12

func (ls *List) Equals(other Object) Object

func (*List) Extend added in v0.0.12

func (ls *List) Extend(other *List)

Extend adds the items of a list to the end of the current list.

func (*List) Filter added in v0.0.12

func (ls *List) Filter(ctx context.Context, fn Object) Object

func (*List) GetAttr added in v0.0.12

func (ls *List) GetAttr(name string) (Object, bool)

func (*List) GetItem added in v0.0.13

func (ls *List) GetItem(key Object) (Object, *Error)

func (*List) GetSlice added in v0.0.13

func (ls *List) GetSlice(s Slice) (Object, *Error)

GetSlice implements the [start:stop] operator for a container type.

func (*List) Index added in v0.0.12

func (ls *List) Index(obj Object) int64

Index returns the index of the first item with the specified value.

func (*List) Insert added in v0.0.12

func (ls *List) Insert(index int64, obj Object)

Insert adds an item at the specified position.

func (*List) Inspect added in v0.0.10

func (ls *List) Inspect() string

func (*List) Interface added in v0.0.13

func (ls *List) Interface() interface{}

func (*List) IsTruthy added in v0.0.13

func (ls *List) IsTruthy() bool

func (*List) Iter added in v0.0.13

func (ls *List) Iter() Iterator

func (*List) Keys added in v0.0.12

func (ls *List) Keys() Object

func (*List) Len added in v0.0.13

func (ls *List) Len() *Int

Len returns the number of items in this container.

func (*List) Map added in v0.0.12

func (ls *List) Map(ctx context.Context, fn Object) Object

func (*List) Pop added in v0.0.12

func (ls *List) Pop(index int64) Object

Pop removes the item at the specified position.

func (*List) Remove added in v0.0.12

func (ls *List) Remove(obj Object)

Remove removes the first item with the specified value.

func (*List) Reverse added in v0.0.12

func (ls *List) Reverse()

Reverse reverses the order of the list.

func (*List) Reversed added in v0.0.10

func (ls *List) Reversed() *List

func (*List) SetItem added in v0.0.13

func (ls *List) SetItem(key, value Object) *Error

SetItem implements the [key] = value operator for a container type.

func (*List) String added in v0.0.10

func (ls *List) String() string

func (*List) Type added in v0.0.10

func (ls *List) Type() Type

func (*List) Value added in v0.0.13

func (ls *List) Value() []Object

type ListIter added in v0.0.13

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

func NewListIter added in v0.0.13

func NewListIter(l *List) *ListIter

func (*ListIter) Equals added in v0.0.13

func (iter *ListIter) Equals(other Object) Object

func (*ListIter) GetAttr added in v0.0.13

func (iter *ListIter) GetAttr(name string) (Object, bool)

func (*ListIter) Inspect added in v0.0.13

func (iter *ListIter) Inspect() string

func (*ListIter) Interface added in v0.0.13

func (iter *ListIter) Interface() interface{}

func (*ListIter) IsTruthy added in v0.0.13

func (iter *ListIter) IsTruthy() bool

func (*ListIter) Next added in v0.0.13

func (iter *ListIter) Next() (IteratorEntry, bool)

func (*ListIter) Type added in v0.0.13

func (iter *ListIter) Type() Type

type Map added in v0.0.11

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

func NewMap added in v0.0.11

func NewMap(m map[string]Object) *Map

func NewMapFromGo added in v0.0.13

func NewMapFromGo(m map[string]interface{}) *Map

func (*Map) Clear added in v0.0.12

func (m *Map) Clear()

func (*Map) Contains added in v0.0.12

func (m *Map) Contains(key Object) *Bool

Contains returns true if the given item is found in this container.

func (*Map) Copy added in v0.0.12

func (m *Map) Copy() *Map

func (*Map) DelItem added in v0.0.13

func (m *Map) DelItem(key Object) *Error

DelItem deletes the item with the given key from the map.

func (*Map) Delete added in v0.0.11

func (m *Map) Delete(key string) Object

func (*Map) Equals added in v0.0.12

func (m *Map) Equals(other Object) Object

func (*Map) Get added in v0.0.11

func (m *Map) Get(key string) Object

func (*Map) GetAttr added in v0.0.12

func (m *Map) GetAttr(name string) (Object, bool)

func (*Map) GetItem added in v0.0.13

func (m *Map) GetItem(key Object) (Object, *Error)

func (*Map) GetSlice added in v0.0.13

func (m *Map) GetSlice(s Slice) (Object, *Error)

GetSlice implements the [start:stop] operator for a container type.

func (*Map) GetWithDefault added in v0.0.13

func (m *Map) GetWithDefault(key string, defaultValue Object) Object

func (*Map) GetWithObject added in v0.0.11

func (m *Map) GetWithObject(key *String) Object

func (*Map) Inspect added in v0.0.11

func (m *Map) Inspect() string

func (*Map) Interface added in v0.0.13

func (m *Map) Interface() interface{}

func (*Map) IsTruthy added in v0.0.13

func (m *Map) IsTruthy() bool

func (*Map) Iter added in v0.0.13

func (m *Map) Iter() Iterator

func (*Map) Keys added in v0.0.11

func (m *Map) Keys() *List

func (*Map) Len added in v0.0.13

func (m *Map) Len() *Int

Len returns the number of items in this container.

func (*Map) ListItems added in v0.0.12

func (m *Map) ListItems() *List

func (*Map) Pop added in v0.0.12

func (m *Map) Pop(key string, def Object) Object

func (*Map) Set added in v0.0.11

func (m *Map) Set(key string, value Object)

func (*Map) SetDefault added in v0.0.12

func (m *Map) SetDefault(key string, value Object) Object

func (*Map) SetItem added in v0.0.13

func (m *Map) SetItem(key, value Object) *Error

SetItem assigns a value to the given key in the map.

func (*Map) Size added in v0.0.11

func (m *Map) Size() int

func (*Map) SortedKeys added in v0.0.12

func (m *Map) SortedKeys() []string

func (*Map) String added in v0.0.13

func (m *Map) String() string

func (*Map) Type added in v0.0.11

func (m *Map) Type() Type

func (*Map) Update added in v0.0.12

func (m *Map) Update(other *Map)

func (*Map) Value added in v0.0.13

func (m *Map) Value() map[string]Object

func (*Map) Values added in v0.0.11

func (m *Map) Values() *List

type MapIter added in v0.0.13

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

func NewMapIter added in v0.0.13

func NewMapIter(m *Map) *MapIter

func (*MapIter) Equals added in v0.0.13

func (iter *MapIter) Equals(other Object) Object

func (*MapIter) GetAttr added in v0.0.13

func (iter *MapIter) GetAttr(name string) (Object, bool)

func (*MapIter) Inspect added in v0.0.13

func (iter *MapIter) Inspect() string

func (*MapIter) Interface added in v0.0.13

func (iter *MapIter) Interface() interface{}

func (*MapIter) IsTruthy added in v0.0.13

func (iter *MapIter) IsTruthy() bool

func (*MapIter) Next added in v0.0.13

func (iter *MapIter) Next() (IteratorEntry, bool)

func (*MapIter) Type added in v0.0.13

func (iter *MapIter) Type() Type

type MapStringIfaceConverter added in v0.0.9

type MapStringIfaceConverter struct{}

MapStringIfaceConverter converts between map[string]interface{} and Hash.

func (*MapStringIfaceConverter) From added in v0.0.9

func (c *MapStringIfaceConverter) From(obj interface{}) (Object, error)

func (*MapStringIfaceConverter) To added in v0.0.9

func (c *MapStringIfaceConverter) To(obj Object) (interface{}, error)

func (*MapStringIfaceConverter) Type added in v0.0.9

type Module

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

func NewModule added in v0.0.13

func NewModule(name string, scope Scope) *Module

func (*Module) Compare added in v0.0.9

func (m *Module) Compare(other Object) (int, error)

func (*Module) Equals added in v0.0.12

func (m *Module) Equals(other Object) Object

func (*Module) GetAttr added in v0.0.12

func (m *Module) GetAttr(name string) (Object, bool)

func (*Module) Inspect

func (m *Module) Inspect() string

func (*Module) Interface added in v0.0.13

func (m *Module) Interface() interface{}

func (*Module) IsTruthy added in v0.0.13

func (m *Module) IsTruthy() bool

func (*Module) Name

func (m *Module) Name() *String

func (*Module) String

func (m *Module) String() string

func (*Module) Type

func (m *Module) Type() Type

type NilType added in v0.0.11

type NilType struct{}

func (*NilType) Compare added in v0.0.11

func (n *NilType) Compare(other Object) (int, error)

func (*NilType) Equals added in v0.0.12

func (n *NilType) Equals(other Object) Object

func (*NilType) GetAttr added in v0.0.12

func (n *NilType) GetAttr(name string) (Object, bool)

func (*NilType) HashKey added in v0.0.13

func (n *NilType) HashKey() HashKey

func (*NilType) Inspect added in v0.0.11

func (n *NilType) Inspect() string

func (*NilType) Interface added in v0.0.13

func (n *NilType) Interface() interface{}

func (*NilType) IsTruthy added in v0.0.13

func (n *NilType) IsTruthy() bool

func (*NilType) String added in v0.0.13

func (n *NilType) String() string

func (*NilType) Type added in v0.0.11

func (n *NilType) Type() Type

type Object

type Object interface {

	// Type of the object.
	Type() Type

	// Inspect returns a string representation of the given object.
	Inspect() string

	// Interface converts the given object to a native Go value.
	Interface() interface{}

	// Returns True if the given object is equal to this object.
	Equals(other Object) Object

	// GetAttr returns the attribute with the given name from this object.
	GetAttr(name string) (Object, bool)

	// IsTruthy returns true if the object is considered "truthy".
	IsTruthy() bool
}

Object is the interface that all object types in Tamarin must implement.

func FromGoType

func FromGoType(obj interface{}) Object

func NewSet added in v0.0.13

func NewSet(items []Object) Object

type Proxy added in v0.0.9

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

Proxy is a Tamarin type that proxies method calls to a wrapped Go struct. Only the public methods of the Go type are proxied.

func NewProxy added in v0.0.9

func NewProxy(reg GoTypeRegistry, obj interface{}) (*Proxy, error)

NewProxy returns a new Tamarin proxy object that wraps the given Go object. The Go type is registered with the type registry, which has no effect if the type is already registered. This operation may fail if the Go type has attributes whose types cannot be converted to Tamarin types.

func (*Proxy) Equals added in v0.0.12

func (p *Proxy) Equals(other Object) Object

func (*Proxy) GetAttr added in v0.0.12

func (p *Proxy) GetAttr(name string) (Object, bool)

func (*Proxy) Inspect added in v0.0.9

func (p *Proxy) Inspect() string

func (*Proxy) Interface added in v0.0.13

func (p *Proxy) Interface() interface{}

func (*Proxy) IsTruthy added in v0.0.13

func (p *Proxy) IsTruthy() bool

func (*Proxy) String added in v0.0.9

func (p *Proxy) String() string

func (*Proxy) Type added in v0.0.9

func (p *Proxy) Type() Type

type Regexp

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

Regexp wraps regexp.Regexp and implements the Object interface.

func NewRegexp added in v0.0.13

func NewRegexp(re *regexp.Regexp) *Regexp

func (*Regexp) Compare added in v0.0.9

func (r *Regexp) Compare(other Object) (int, error)

func (*Regexp) Equals added in v0.0.12

func (r *Regexp) Equals(other Object) Object

func (*Regexp) GetAttr added in v0.0.12

func (r *Regexp) GetAttr(name string) (Object, bool)

func (*Regexp) Inspect

func (r *Regexp) Inspect() string

func (*Regexp) Interface added in v0.0.13

func (r *Regexp) Interface() interface{}

func (*Regexp) IsTruthy added in v0.0.13

func (r *Regexp) IsTruthy() bool

func (*Regexp) String added in v0.0.13

func (r *Regexp) String() string

func (*Regexp) Type

func (r *Regexp) Type() Type

func (*Regexp) Value

func (r *Regexp) Value() *regexp.Regexp

type Result

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

Result contains one of: an "ok" value or an "err" value

func NewErrResult added in v0.0.13

func NewErrResult(err *Error) *Result

func NewOkResult added in v0.0.4

func NewOkResult(ok Object) *Result

func (*Result) Equals added in v0.0.12

func (rv *Result) Equals(other Object) Object

func (*Result) ErrMsg added in v0.0.13

func (rv *Result) ErrMsg() *String

func (*Result) Expect added in v0.0.12

func (rv *Result) Expect(other Object) Object

func (*Result) GetAttr added in v0.0.12

func (rv *Result) GetAttr(name string) (Object, bool)

func (*Result) Inspect

func (rv *Result) Inspect() string

func (*Result) Interface added in v0.0.13

func (rv *Result) Interface() interface{}

func (*Result) IsErr added in v0.0.7

func (rv *Result) IsErr() bool

func (*Result) IsOk

func (rv *Result) IsOk() bool

func (*Result) IsTruthy added in v0.0.13

func (rv *Result) IsTruthy() bool

func (*Result) String

func (rv *Result) String() string

func (*Result) Type

func (rv *Result) Type() Type

func (*Result) Unwrap added in v0.0.12

func (rv *Result) Unwrap() Object

func (*Result) UnwrapErr added in v0.0.13

func (rv *Result) UnwrapErr() *Error

func (*Result) UnwrapOr added in v0.0.12

func (rv *Result) UnwrapOr(other Object) Object

type Scope added in v0.0.12

type Scope interface {

	// Name of the scope, to aid debugging
	Name() string

	// IsReadOnly returns true iff the scope contains a variable with the
	// given name and that variable is marked as read-only.
	IsReadOnly(name string) bool

	// Get returns the object associated with the given name, and a boolean
	// indicating whether the object was found.
	Get(name string) (Object, bool)

	// Declare adds a new variable to the scope. If the variable already
	// exists, an error is returned.
	Declare(name string, obj Object, readOnly bool) error

	// Update the variable with the given name. If the variable does not
	// exist, an error is returned.
	Update(name string, obj Object) error

	// Contents returns a map of all variables in the scope.
	Contents() map[string]Object
}

Scope is an interface that can be used to implement variable storage for a specific context.

type Set

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

func NewSetWithSize added in v0.0.9

func NewSetWithSize(size int) *Set

func (*Set) Add added in v0.0.9

func (s *Set) Add(items ...Object) Object

func (*Set) Contains added in v0.0.9

func (s *Set) Contains(key Object) *Bool

Contains returns true if the given item is found in this container.

func (*Set) DelItem added in v0.0.13

func (s *Set) DelItem(key Object) *Error

DelItem deletes the item with the given key from the map.

func (*Set) Difference added in v0.0.9

func (s *Set) Difference(other *Set) *Set

Difference returns a new set that is the difference of the two sets.

func (*Set) Equals added in v0.0.12

func (s *Set) Equals(other Object) Object

func (*Set) GetAttr added in v0.0.12

func (s *Set) GetAttr(name string) (Object, bool)

func (*Set) GetItem added in v0.0.13

func (s *Set) GetItem(key Object) (Object, *Error)

func (*Set) GetSlice added in v0.0.13

func (s *Set) GetSlice(slice Slice) (Object, *Error)

GetSlice implements the [start:stop] operator for a container type.

func (*Set) Inspect

func (s *Set) Inspect() string

func (*Set) Interface added in v0.0.13

func (s *Set) Interface() interface{}

func (*Set) Intersection added in v0.0.9

func (s *Set) Intersection(other *Set) *Set

Intersection returns a new set that is the intersection of the two sets.

func (*Set) IsTruthy added in v0.0.13

func (s *Set) IsTruthy() bool

func (*Set) Iter added in v0.0.13

func (s *Set) Iter() Iterator

func (*Set) Keys added in v0.0.13

func (s *Set) Keys() []HashKey

func (*Set) Len added in v0.0.13

func (s *Set) Len() *Int

Len returns the number of items in this container.

func (*Set) List added in v0.0.10

func (s *Set) List() *List

func (*Set) Remove added in v0.0.9

func (s *Set) Remove(items ...Object) Object

func (*Set) SetItem added in v0.0.13

func (s *Set) SetItem(key, value Object) *Error

SetItem assigns a value to the given key in the map.

func (*Set) Size added in v0.0.9

func (s *Set) Size() int

func (*Set) SortedItems added in v0.0.12

func (s *Set) SortedItems() []Object

func (*Set) String added in v0.0.13

func (s *Set) String() string

func (*Set) Type

func (s *Set) Type() Type

func (*Set) Union added in v0.0.9

func (s *Set) Union(other *Set) *Set

Union returns a new set that is the union of the two sets.

func (*Set) Value added in v0.0.13

func (s *Set) Value() map[HashKey]Object

type SetIter added in v0.0.13

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

func NewSetIter added in v0.0.13

func NewSetIter(set *Set) *SetIter

func (*SetIter) Equals added in v0.0.13

func (iter *SetIter) Equals(other Object) Object

func (*SetIter) GetAttr added in v0.0.13

func (iter *SetIter) GetAttr(name string) (Object, bool)

func (*SetIter) Inspect added in v0.0.13

func (iter *SetIter) Inspect() string

func (*SetIter) Interface added in v0.0.13

func (iter *SetIter) Interface() interface{}

func (*SetIter) IsTruthy added in v0.0.13

func (iter *SetIter) IsTruthy() bool

func (*SetIter) Next added in v0.0.13

func (iter *SetIter) Next() (IteratorEntry, bool)

func (*SetIter) Type added in v0.0.13

func (iter *SetIter) Type() Type

type Slice added in v0.0.13

type Slice struct {
	Start Object
	Stop  Object
}

Slice is used to specify a range or slice of items in a container.

type String

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

func NewString added in v0.0.4

func NewString(s string) *String

func (*String) Compare added in v0.0.9

func (s *String) Compare(other Object) (int, error)

func (*String) Contains added in v0.0.13

func (s *String) Contains(key Object) *Bool

func (*String) DelItem added in v0.0.13

func (s *String) DelItem(key Object) *Error

func (*String) Equals added in v0.0.12

func (s *String) Equals(other Object) Object

func (*String) GetAttr added in v0.0.12

func (s *String) GetAttr(name string) (Object, bool)

func (*String) GetItem added in v0.0.13

func (s *String) GetItem(key Object) (Object, *Error)

func (*String) GetSlice added in v0.0.13

func (s *String) GetSlice(slice Slice) (Object, *Error)

func (*String) HashKey

func (s *String) HashKey() HashKey

func (*String) Inspect

func (s *String) Inspect() string

func (*String) Interface added in v0.0.13

func (s *String) Interface() interface{}

func (*String) IsTruthy added in v0.0.13

func (s *String) IsTruthy() bool

func (*String) Iter added in v0.0.13

func (s *String) Iter() Iterator

func (*String) Len added in v0.0.13

func (s *String) Len() *Int

func (*String) Reversed added in v0.0.9

func (s *String) Reversed() *String

func (*String) SetItem added in v0.0.13

func (s *String) SetItem(key, value Object) *Error

func (*String) String

func (s *String) String() string

func (*String) Type

func (s *String) Type() Type

func (*String) Value

func (s *String) Value() string

type StringConverter added in v0.0.9

type StringConverter struct{}

StringConverter converts between string and String.

func (*StringConverter) From added in v0.0.9

func (c *StringConverter) From(obj interface{}) (Object, error)

func (*StringConverter) To added in v0.0.9

func (c *StringConverter) To(obj Object) (interface{}, error)

func (*StringConverter) Type added in v0.0.9

func (c *StringConverter) Type() reflect.Type

type StringIter added in v0.0.13

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

func NewStringIter added in v0.0.13

func NewStringIter(s *String) *StringIter

func (*StringIter) Equals added in v0.0.13

func (iter *StringIter) Equals(other Object) Object

func (*StringIter) GetAttr added in v0.0.13

func (iter *StringIter) GetAttr(name string) (Object, bool)

func (*StringIter) Inspect added in v0.0.13

func (iter *StringIter) Inspect() string

func (*StringIter) Interface added in v0.0.13

func (iter *StringIter) Interface() interface{}

func (*StringIter) IsTruthy added in v0.0.13

func (iter *StringIter) IsTruthy() bool

func (*StringIter) Next added in v0.0.13

func (iter *StringIter) Next() (IteratorEntry, bool)

func (*StringIter) Type added in v0.0.13

func (iter *StringIter) Type() Type

type StructConverter added in v0.0.9

type StructConverter struct {
	Prototype interface{}
	AsPointer bool
}

StructConverter converts between a struct and a Hash via JSON marshaling.

func (*StructConverter) From added in v0.0.9

func (c *StructConverter) From(obj interface{}) (Object, error)

func (*StructConverter) To added in v0.0.9

func (c *StructConverter) To(obj Object) (interface{}, error)

func (*StructConverter) Type added in v0.0.9

func (c *StructConverter) Type() reflect.Type

type Time added in v0.0.4

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

func NewTime added in v0.0.9

func NewTime(t time.Time) *Time

func (*Time) After added in v0.0.13

func (t *Time) After(ctx context.Context, args ...Object) Object

func (*Time) Before added in v0.0.13

func (t *Time) Before(ctx context.Context, args ...Object) Object

func (*Time) Compare added in v0.0.9

func (t *Time) Compare(other Object) (int, error)

func (*Time) Equals added in v0.0.12

func (t *Time) Equals(other Object) Object

func (*Time) Format added in v0.0.13

func (t *Time) Format(ctx context.Context, args ...Object) Object

func (*Time) GetAttr added in v0.0.12

func (t *Time) GetAttr(name string) (Object, bool)

func (*Time) Inspect added in v0.0.4

func (t *Time) Inspect() string

func (*Time) Interface added in v0.0.13

func (t *Time) Interface() interface{}

func (*Time) IsTruthy added in v0.0.13

func (t *Time) IsTruthy() bool

func (*Time) String added in v0.0.4

func (t *Time) String() string

func (*Time) Type added in v0.0.4

func (t *Time) Type() Type

func (*Time) UTC added in v0.0.13

func (t *Time) UTC(ctx context.Context, args ...Object) Object

func (*Time) Unix added in v0.0.13

func (t *Time) Unix(ctx context.Context, args ...Object) Object

func (*Time) Value added in v0.0.4

func (t *Time) Value() time.Time

type TimeConverter added in v0.0.9

type TimeConverter struct{}

TimeConverter converts between time.Time and Time.

func (*TimeConverter) From added in v0.0.9

func (c *TimeConverter) From(obj interface{}) (Object, error)

func (*TimeConverter) To added in v0.0.9

func (c *TimeConverter) To(obj Object) (interface{}, error)

func (*TimeConverter) Type added in v0.0.9

func (c *TimeConverter) Type() reflect.Type

type Type

type Type string

Type defines the type of an object.

const (
	INT           Type = "int"
	FLOAT         Type = "float"
	BOOL          Type = "bool"
	NIL           Type = "nil"
	ERROR         Type = "error"
	FUNCTION      Type = "function"
	STRING        Type = "string"
	BUILTIN       Type = "builtin"
	LIST          Type = "list"
	MAP           Type = "map"
	FILE          Type = "file"
	REGEXP        Type = "regexp"
	SET           Type = "set"
	MODULE        Type = "module"
	RESULT        Type = "result"
	HTTP_RESPONSE Type = "http_response"
	DB_CONNECTION Type = "db_connection"
	TIME          Type = "time"
	PROXY         Type = "proxy"
	CONTROL       Type = "control"
	STRING_ITER   Type = "string_iter"
	LIST_ITER     Type = "list_iter"
	MAP_ITER      Type = "map_iter"
	SET_ITER      Type = "set_iter"
	ITER_ENTRY    Type = "iter_entry"
)

Type constants

type TypeConverter added in v0.0.9

type TypeConverter interface {

	// To converts a Tamarin object to a Go object.
	To(Object) (interface{}, error)

	// From converts a Go object to a Tamarin object.
	From(interface{}) (Object, error)

	// Type that this TypeConverter is responsible for.
	Type() reflect.Type
}

TypeConverter is an interface used to convert between Go and Tamarin objects for a single Go type. There may be a way to use generics here...

type TypeRegistryOpts added in v0.0.12

type TypeRegistryOpts struct {
	// Converters is a list of TypeConverters that will be used to convert
	// input and output types for method calls.
	Converters []TypeConverter

	// NoDefaults indicates that the default TypeConverters should not be
	// automatically used by the registry. If this is set, the caller should
	// provide their own TypeConverters.
	NoDefaults bool
}

TypeRegistryOpts contains options used to create a GoTypeRegistry.

Jump to

Keyboard shortcuts

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