object

package
Version: v0.0.0-...-9834360 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgumentError

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

ArgumentError represents an error in method call arguments

func NewArgumentError

func NewArgumentError(format string, args ...interface{}) *ArgumentError

NewArgumentError creates an ArgumentError. It has the same API as fmt.Errorf

func NewWrongNumberOfArgumentsError

func NewWrongNumberOfArgumentsError(expected, actual int) *ArgumentError

NewWrongNumberOfArgumentsError returns an ArgumentError populated with the default message

func (*ArgumentError) Class

func (e *ArgumentError) Class() RubyClass

Class returns argumentErrorClass

func (*ArgumentError) Error

func (e *ArgumentError) Error() string

func (*ArgumentError) Inspect

func (e *ArgumentError) Inspect() string

Inspect returns a string starting with the exception class name, followed by the message

func (*ArgumentError) Type

func (e *ArgumentError) Type() Type

Type returns EXCEPTION_OBJ

type Array

type Array struct {
	Elements []RubyObject
}

An Array represents a Ruby Array

func NewArray

func NewArray(elements ...RubyObject) *Array

NewArray returns a new array populated with elements.

func (*Array) Class

func (a *Array) Class() RubyClass

Class returns the class of the Array

func (*Array) Inspect

func (a *Array) Inspect() string

Inspect returns all elements within the array, divided by comma and surrounded by brackets

func (*Array) Type

func (a *Array) Type() Type

Type returns the ObjectType of the array

type Boolean

type Boolean struct {
	Value bool
}

Boolean represents a Boolean object in Ruby

func (*Boolean) Class

func (b *Boolean) Class() RubyClass

Class returns the TrueClass for true, and the FalseClass otherwise

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

Inspect returns the string representation of the boolean

func (*Boolean) Type

func (b *Boolean) Type() Type

Type returns the object type of the boolean

type CallContext

type CallContext interface {
	// Env returns the current environment at call time
	Env() Environment
	// Eval represents an evalualtion method suitable to eval arbitrary Ruby
	// AST Nodes and transform them into a resulting Ruby object or an error.
	Eval(ast.Node, Environment) (RubyObject, error)
	// Receiver returns the Ruby object the message is sent to
	Receiver() RubyObject
}

CallContext represents the context information when sending a message to an object.

func NewCallContext

func NewCallContext(env Environment, receiver RubyObject) CallContext

NewCallContext returns a new CallContext with a stubbed eval function

type EnvEntryInfo

type EnvEntryInfo interface {
	Name() string
	Env() Environment
}

EnvEntryInfo describes an entry in an Environment and is returned by EnvStat

func EnvStat

func EnvStat(env Environment, obj RubyObject) (EnvEntryInfo, bool)

EnvStat returns the EnvEntryInfo for obj. If obj is not found in the hierarchy of env, the bool will be false.

type Environment

type Environment interface {
	// Get returns the RubyObject found for this key. If it is not found,
	// ok  will be false
	Get(key string) (object RubyObject, ok bool)
	// GetAll returns all values for the current env as a map of string to RubyObject
	GetAll() map[string]RubyObject
	// Set sets the RubyObject for the given key. If there is already an
	// object with that key it will be overridden by object
	Set(key string, object RubyObject) RubyObject
	// Unset removes the entry for the given key. It returns the removed entry
	Unset(key string) RubyObject
	// SetGlobal sets val under name at the root of the environment
	SetGlobal(name string, val RubyObject) RubyObject
	// Outer returns the parent environment
	Outer() Environment
	// Clone returns a copy of the environment. It will shallow copy its values
	//
	// Note that clone will not set its outer env, so calls to Outer will
	// return nil on cloned Environments
	Clone() Environment
}

Environment holds Ruby object referenced by strings

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer Environment) Environment

NewEnclosedEnvironment returns an Environment wrapped by outer

func NewEnvironment

func NewEnvironment() Environment

NewEnvironment returns a new Environment ready to use

func NewMainEnvironment

func NewMainEnvironment() Environment

NewMainEnvironment returns a new Environment populated with all Ruby classes and the Kernel functions

func WithScopedLocalVariables

func WithScopedLocalVariables(e Environment) Environment

WithScopedLocalVariables returns an Environment which scopes the local variables within another env so they cannot leak out

type Exception

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

Exception represents a basic exception

func NewException

func NewException(message string, args ...interface{}) *Exception

NewException creates a new exception with the given message template and uses fmt.Sprintf to interpolate the args into messageinto message.

func (*Exception) Class

func (e *Exception) Class() RubyClass

Class returns exceptionClass

func (*Exception) Error

func (e *Exception) Error() string

func (*Exception) Inspect

func (e *Exception) Inspect() string

Inspect returns a string starting with the exception class name, followed by the message

func (*Exception) Type

func (e *Exception) Type() Type

Type returns the type of the RubyObject

type File

type File struct {
	Map map[RubyObject]RubyObject
}

A File represents the Ruby class File

func (*File) Class

func (f *File) Class() RubyClass

Class returns the class of the Array

func (*File) Inspect

func (f *File) Inspect() string

Inspect returns all elements within the array, divided by comma and surrounded by brackets

func (*File) Type

func (f *File) Type() Type

Type returns the ObjectType of the array

type Function

type Function struct {
	Parameters       []*FunctionParameter
	Body             *ast.BlockStatement
	Env              Environment
	MethodVisibility MethodVisibility
}

A Function represents a user defined function. It is no real Ruby object.

func (*Function) Call

func (f *Function) Call(context CallContext, args ...RubyObject) (RubyObject, error)

Call implements the RubyMethod interface. It evaluates f.Body and returns its result

func (*Function) String

func (f *Function) String() string

String returns the function literal

func (*Function) Visibility

func (f *Function) Visibility() MethodVisibility

Visibility implements the RubyMethod interface. It returns f.MethodVisibility

type FunctionParameter

type FunctionParameter struct {
	Name    string
	Default RubyObject
}

FunctionParameter represents a parameter within a function

func (*FunctionParameter) String

func (f *FunctionParameter) String() string

type Hash

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

A Hash represents a Ruby Hash

func (*Hash) Class

func (h *Hash) Class() RubyClass

Class returns the class of the Array

func (*Hash) Get

func (h *Hash) Get(key RubyObject) (RubyObject, bool)

Get retrieves the object for key within the hash. If not found, the boolean will be false

func (*Hash) Inspect

func (h *Hash) Inspect() string

Inspect returns all elements within the array, divided by comma and surrounded by brackets

func (*Hash) Map

func (h *Hash) Map() map[RubyObject]RubyObject

Map returns a map of RubyObject to RubyObject

func (*Hash) Set

func (h *Hash) Set(key, value RubyObject) RubyObject

Set puts the object obj into the Hash

func (*Hash) Type

func (h *Hash) Type() Type

Type returns the ObjectType of the array

type Integer

type Integer struct {
	Value int64
}

Integer represents an integer in Ruby

func NewInteger

func NewInteger(value int64) *Integer

NewInteger returns a new Integer with the given value

func (*Integer) Class

func (i *Integer) Class() RubyClass

Class returns integerClass

func (*Integer) Inspect

func (i *Integer) Inspect() string

Inspect returns the value as string

func (*Integer) Type

func (i *Integer) Type() Type

Type returns INTEGER_OBJ

type LoadError

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

LoadError represents an error while loading another file

func NewNoSuchFileLoadError

func NewNoSuchFileLoadError(filepath string) *LoadError

NewNoSuchFileLoadError returns a new LoadError with the default message

func (*LoadError) Class

func (e *LoadError) Class() RubyClass

Class returns loadErrorClass

func (*LoadError) Error

func (e *LoadError) Error() string

func (*LoadError) Inspect

func (e *LoadError) Inspect() string

Inspect returns a string starting with the exception class name, followed by the message

func (*LoadError) Type

func (e *LoadError) Type() Type

Type returns EXCEPTION_OBJ

type LocalJumpError

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

LocalJumpError represents an error for a not supported jump

func NewNoBlockGivenLocalJumpError

func NewNoBlockGivenLocalJumpError() *LocalJumpError

NewNoBlockGivenLocalJumpError returns a LocalJumpError with the default message for missing blocks

func (*LocalJumpError) Class

func (e *LocalJumpError) Class() RubyClass

Class returns notImplementedErrorClass

func (*LocalJumpError) Error

func (e *LocalJumpError) Error() string

func (*LocalJumpError) Inspect

func (e *LocalJumpError) Inspect() string

Inspect returns a string starting with the exception class name, followed by the message

func (*LocalJumpError) Type

func (e *LocalJumpError) Type() Type

Type returns EXCEPTION_OBJ

type MethodSet

type MethodSet interface {
	// Get returns the method found for name. The boolean will return true if
	// a method was found, false otherwise
	Get(name string) (RubyMethod, bool)
	// GetAll returns a map of name to methods representing the MethodSet.
	GetAll() map[string]RubyMethod
}

MethodSet represents a set of methods

type MethodVisibility

type MethodVisibility visibility

MethodVisibility represents the visibility of a method

const (
	// PUBLIC_METHOD declares that a method is visible from the outside of an object
	PUBLIC_METHOD MethodVisibility = iota
	// PROTECTED_METHOD declares that a method is not visible from the outside
	// of an object but to all of its decendents
	PROTECTED_METHOD
	// PRIVATE_METHOD declares that a method is not visible from the outside
	// of an object and not to all of its decendents
	PRIVATE_METHOD
)

type Module

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

Module represents a module in Ruby

func NewModule

func NewModule(name string, outerEnv Environment) *Module

NewModule returns a new module with the given name and adds methods to its method set.

func (*Module) Class

func (m *Module) Class() RubyClass

Class returns the set class or moduleClass

func (*Module) Inspect

func (m *Module) Inspect() string

Inspect returns the name of the module

func (*Module) Type

func (m *Module) Type() Type

Type returns MODULE_OBJ

type NameError

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

A NameError represents an error accessing an identifier unknown to the environment

func NewUndefinedLocalVariableOrMethodNameError

func NewUndefinedLocalVariableOrMethodNameError(context RubyObject, name string) *NameError

NewUndefinedLocalVariableOrMethodNameError returns a NameError with the default message for undefined names

func NewUninitializedConstantNameError

func NewUninitializedConstantNameError(name string) *NameError

NewUninitializedConstantNameError returns a NameError with the default message for uninitialized constants

func (*NameError) Class

func (e *NameError) Class() RubyClass

Class returns nameErrorClass

func (*NameError) Error

func (e *NameError) Error() string

func (*NameError) Inspect

func (e *NameError) Inspect() string

Inspect returns a string starting with the exception class name, followed by the message

func (*NameError) Type

func (e *NameError) Type() Type

Type returns EXCEPTION_OBJ

type NoMethodError

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

NoMethodError represents an error finding a fitting method on an object

func NewNoMethodError

func NewNoMethodError(context RubyObject, method string) *NoMethodError

NewNoMethodError returns a NoMethodError with the default message for undefined methods

func NewPrivateNoMethodError

func NewPrivateNoMethodError(context RubyObject, method string) *NoMethodError

NewPrivateNoMethodError returns a NoMethodError with the default message for private methods

func (*NoMethodError) Class

func (e *NoMethodError) Class() RubyClass

Class returns noMethodErrorClass

func (*NoMethodError) Error

func (e *NoMethodError) Error() string

func (*NoMethodError) Inspect

func (e *NoMethodError) Inspect() string

Inspect returns a string starting with the exception class name, followed by the message

func (*NoMethodError) Type

func (e *NoMethodError) Type() Type

Type returns EXCEPTION_OBJ

type NotImplementedError

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

NotImplementedError represents an error for a not implemented feature on a given platform

func NewNotImplementedError

func NewNotImplementedError(format string, args ...interface{}) *NotImplementedError

NewNotImplementedError returns a NotImplementedError with the provided message

func (*NotImplementedError) Class

func (e *NotImplementedError) Class() RubyClass

Class returns notImplementedErrorClass

func (*NotImplementedError) Error

func (e *NotImplementedError) Error() string

func (*NotImplementedError) Inspect

func (e *NotImplementedError) Inspect() string

Inspect returns a string starting with the exception class name, followed by the message

func (*NotImplementedError) Type

func (e *NotImplementedError) Type() Type

Type returns EXCEPTION_OBJ

type Object

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

Object represents an Object in Ruby

func (*Object) Class

func (o *Object) Class() RubyClass

Class returns objectClass

func (*Object) Inspect

func (o *Object) Inspect() string

Inspect return ""

func (*Object) Type

func (o *Object) Type() Type

Type returns OBJECT_OBJ

type Proc

type Proc struct {
	Parameters             []*ast.FunctionParameter
	Body                   *ast.BlockStatement
	Env                    Environment
	ArgumentCountMandatory bool
}

A Proc represents a user defined block of code.

func (*Proc) Call

func (p *Proc) Call(context CallContext, args ...RubyObject) (RubyObject, error)

Call implements the RubyMethod interface. It evaluates p.Body and returns its result

func (*Proc) Class

func (p *Proc) Class() RubyClass

Class returns procClass

func (*Proc) Inspect

func (p *Proc) Inspect() string

Inspect returns the proc body

func (*Proc) Type

func (p *Proc) Type() Type

Type returns proc_OBJ

type ReturnValue

type ReturnValue struct {
	Value RubyObject
}

ReturnValue represents a wrapper object for a return statement. It is no real Ruby object and only used within the interpreter evaluation

func (*ReturnValue) Class

func (rv *ReturnValue) Class() RubyClass

Class reurns the class of the wrapped object

func (*ReturnValue) Inspect

func (rv *ReturnValue) Inspect() string

Inspect returns the string representation of the wrapped object

func (*ReturnValue) Type

func (rv *ReturnValue) Type() Type

Type returns RETURN_VALUE_OBJ

type RubyClass

type RubyClass interface {
	Methods() MethodSet
	SuperClass() RubyClass
	New(args ...RubyObject) (RubyObject, error)
	Name() string
}

RubyClass represents a class in Ruby

type RubyClassObject

type RubyClassObject interface {
	RubyObject
	RubyClass
}

RubyClassObject represents a class object in Ruby

func NewClass

func NewClass(name string, superClass RubyClass, env Environment) RubyClassObject

NewClass returns a new Ruby Class

type RubyMethod

type RubyMethod interface {
	Call(context CallContext, args ...RubyObject) (RubyObject, error)
	Visibility() MethodVisibility
}

RubyMethod defines a Ruby method

type RubyObject

type RubyObject interface {
	Type() Type
	Class() RubyClass
	// contains filtered or unexported methods
}

RubyObject represents an object in Ruby

var (

	// TRUE represents the singleton object for the Boolean true
	TRUE RubyObject = &Boolean{Value: true}
	// FALSE represents the singleton object for the Boolean false
	FALSE RubyObject = &Boolean{Value: false}
)
var (

	// NIL represents the singleton object nil
	NIL RubyObject = &nilObject{}
)

func AddMethod

func AddMethod(context RubyObject, methodName string, method *Function) RubyObject

AddMethod adds a method to a given object. It returns the object with the modified method set

func Send

func Send(context CallContext, method string, args ...RubyObject) (RubyObject, error)

Send sends message method with args to context and returns its result

type RuntimeError

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

RuntimeError is a generic error class raised when an invalid operation is attempted

func NewRuntimeError

func NewRuntimeError(format string, args ...interface{}) *RuntimeError

NewRuntimeError returns a new RuntimeError with the formatted message

func (*RuntimeError) Class

func (e *RuntimeError) Class() RubyClass

Class returns runtimeErrorClass

func (*RuntimeError) Error

func (e *RuntimeError) Error() string

func (*RuntimeError) Inspect

func (e *RuntimeError) Inspect() string

Inspect returns a string starting with the exception class name, followed by the message

func (*RuntimeError) Type

func (e *RuntimeError) Type() Type

Type returns EXCEPTION_OBJ

type ScriptError

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

ScriptError represetns an error in the loaded script

func NewScriptError

func NewScriptError(format string, args ...interface{}) *ScriptError

NewScriptError returns a new script error with the provided message

func (*ScriptError) Class

func (e *ScriptError) Class() RubyClass

Class returns scriptErrorClass

func (*ScriptError) Error

func (e *ScriptError) Error() string

func (*ScriptError) Inspect

func (e *ScriptError) Inspect() string

Inspect returns a string starting with the exception class name, followed by the message

func (*ScriptError) Type

func (e *ScriptError) Type() Type

Type returns EXCEPTION_OBJ

type Self

type Self struct {
	RubyObject        // The encapsuled object acting as self
	Block      *Proc  // the block given to the current execution binding
	Name       string // The name of self in this context
}

Self represents the value associated to `self`. It acts as a wrapper around the RubyObject and is just meant to indicate that the given object is self in the given context.

func (*Self) Inspect

func (s *Self) Inspect() string

Inspect returns the name of Self

func (*Self) Type

func (s *Self) Type() Type

Type returns SELF

type SettableMethodSet

type SettableMethodSet interface {
	MethodSet
	// Set will set method to key name. If there was a method prior defined
	// under name it will be overridden.
	Set(name string, method RubyMethod)
}

SettableMethodSet represents a MethodSet which can be mutated by setting methods on it.

func NewMethodSet

func NewMethodSet(methods map[string]RubyMethod) SettableMethodSet

NewMethodSet returns a new method set populated with the given methods

type StandardError

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

StandardError is the default class for rescue blocks

func NewStandardError

func NewStandardError(message string) *StandardError

NewStandardError returns a StandardError with the given message

func (*StandardError) Class

func (e *StandardError) Class() RubyClass

Class returns standardErrorClass

func (*StandardError) Error

func (e *StandardError) Error() string

func (*StandardError) Inspect

func (e *StandardError) Inspect() string

Inspect returns a string starting with the exception class name, followed by the message

func (*StandardError) Type

func (e *StandardError) Type() Type

Type returns EXCEPTION_OBJ

type String

type String struct {
	Value string
}

String represents a string in Ruby

func (*String) Class

func (s *String) Class() RubyClass

Class returns stringClass

func (*String) Inspect

func (s *String) Inspect() string

Inspect returns the Value

func (*String) Type

func (s *String) Type() Type

Type returns STRING_OBJ

type Symbol

type Symbol struct {
	Value string
}

A Symbol represents a symbol in Ruby

func (*Symbol) Class

func (s *Symbol) Class() RubyClass

Class returns symbolClass

func (*Symbol) Inspect

func (s *Symbol) Inspect() string

Inspect returns the value of the symbol

func (*Symbol) Type

func (s *Symbol) Type() Type

Type returns SYMBOL_OBJ

type SyntaxError

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

SyntaxError represents a syntax error in the ruby scripts

func NewSyntaxError

func NewSyntaxError(syntaxError error) *SyntaxError

NewSyntaxError returns a new SyntaxError with the default message

func (*SyntaxError) Class

func (e *SyntaxError) Class() RubyClass

Class returns syntaxErrorClass

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

func (*SyntaxError) Inspect

func (e *SyntaxError) Inspect() string

Inspect returns a string starting with the exception class name, followed by the message

func (*SyntaxError) Type

func (e *SyntaxError) Type() Type

Type returns EXCEPTION_OBJ

func (*SyntaxError) UnderlyingError

func (e *SyntaxError) UnderlyingError() error

UnderlyingError returns the parser error wrapped by SyntaxError

type Type

type Type string

Type represents a type of an object

const (
	EIGENCLASS_OBJ     Type = "EIGENCLASS"
	FUNCTION_OBJ       Type = "FUNCTION"
	RETURN_VALUE_OBJ   Type = "RETURN_VALUE"
	BASIC_OBJECT_OBJ   Type = "BASIC_OBJECT"
	OBJECT_OBJ         Type = "OBJECT"
	CLASS_OBJ          Type = "CLASS"
	CLASS_INSTANCE_OBJ Type = "CLASS"
	ARRAY_OBJ          Type = "ARRAY"
	HASH_OBJ           Type = "HASH"
	INTEGER_OBJ        Type = "INTEGER"
	STRING_OBJ         Type = "STRING"
	SYMBOL_OBJ         Type = "SYMBOL"
	BOOLEAN_OBJ        Type = "BOOLEAN"
	NIL_OBJ            Type = "NIL"
	NIL_CLASS_OBJ      Type = "NIL_CLASS"
	EXCEPTION_OBJ      Type = "EXCEPTION"
	MODULE_OBJ         Type = "MODULE"
	SELF               Type = "SELF"
)

type TypeError

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

TypeError represents an error when the given type does not fit in the given context

func NewCoercionTypeError

func NewCoercionTypeError(expected, actual RubyObject) *TypeError

NewCoercionTypeError returns a TypeError with the default message for coercing errors

func NewImplicitConversionTypeError

func NewImplicitConversionTypeError(expected, actual RubyObject) *TypeError

NewImplicitConversionTypeError returns a TypeError with the default message for impossible implicit conversions

func NewTypeError

func NewTypeError(message string) *TypeError

NewTypeError returns a TypeError with the provided message

func NewWrongArgumentTypeError

func NewWrongArgumentTypeError(expected, actual RubyObject) *TypeError

NewWrongArgumentTypeError returns a TypeError with the default message for wrong arugument type errors

func (*TypeError) Class

func (e *TypeError) Class() RubyClass

Class returns typeErrorClass

func (*TypeError) Error

func (e *TypeError) Error() string

func (*TypeError) Inspect

func (e *TypeError) Inspect() string

Inspect returns a string starting with the exception class name, followed by the message

func (*TypeError) Type

func (e *TypeError) Type() Type

Type returns EXCEPTION_OBJ

type ZeroDivisionError

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

ZeroDivisionError represents an arithmethic error when dividing through 0

func NewZeroDivisionError

func NewZeroDivisionError() *ZeroDivisionError

NewZeroDivisionError returns a new ZeroDivisionError with the default message

func (*ZeroDivisionError) Class

func (e *ZeroDivisionError) Class() RubyClass

Class returns zeroDivisionErrorClass

func (*ZeroDivisionError) Error

func (e *ZeroDivisionError) Error() string

func (*ZeroDivisionError) Inspect

func (e *ZeroDivisionError) Inspect() string

Inspect returns a string starting with the exception class name, followed by the message

func (*ZeroDivisionError) Type

func (e *ZeroDivisionError) Type() Type

Type returns EXCEPTION_OBJ

Jump to

Keyboard shortcuts

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