vm

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2018 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NormalMode int = iota
	REPLMode
	TestMode
)

These are the enums for marking parser's mode, which decides whether it should pop unused values.

View Source
const Version = "0.1.10"

Version stores current Goby version

Variables

View Source
var ConcurrentArrayMethodsForwardingTable = map[string]bool{
	"[]":           false,
	"*":            false,
	"+":            false,
	"[]=":          true,
	"any?":         false,
	"at":           false,
	"clear":        true,
	"concat":       true,
	"count":        false,
	"delete_at":    true,
	"each":         false,
	"each_index":   false,
	"empty?":       false,
	"first":        false,
	"flatten":      false,
	"join":         false,
	"last":         false,
	"length":       false,
	"map":          false,
	"pop":          true,
	"push":         true,
	"reduce":       false,
	"reverse":      false,
	"reverse_each": false,
	"rotate":       false,
	"select":       false,
	"shift":        true,
	"unshift":      true,
	"values_at":    false,
}

Pseudo-constant definition of the forwarded methods, mapped to a boolean representing the requirement for a write lock (true) or read lock (false)

We don't implement dig, as it has no concurrency guarantees.

View Source
var DefaultLibPath string

DefaultLibPath is used for overriding vm.libpath build-time.

Functions

func PrintError added in v0.1.3

func PrintError(v *VM)

PrintError prints an error report string given a vm which evaluated to and Error object

func RegisterExternalClass added in v0.1.10

func RegisterExternalClass(path string, c ...ClassLoader)

RegisterExternalClass will add the given class to the global registery of available classes

func VerifyExpected added in v0.1.10

func VerifyExpected(t *testing.T, i int, evaluated Object, expected interface{})

Types

type ArrayObject

type ArrayObject struct {
	Elements []Object
	// contains filtered or unexported fields
}

ArrayObject represents an instance from Array class. An array is a collection of different objects that are ordered and indexed. Elements in an array can belong to any class and you can also build a "tuple" within an array. Array objects should always be enumerable.

func (ArrayObject) Class

func (b ArrayObject) Class() *RClass

Class will return object's class

func (ArrayObject) InstanceVariableGet added in v0.1.10

func (b ArrayObject) InstanceVariableGet(name string) (Object, bool)

func (ArrayObject) InstanceVariableSet added in v0.1.10

func (b ArrayObject) InstanceVariableSet(name string, value Object) Object

func (ArrayObject) SetSingletonClass added in v0.1.0

func (b ArrayObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (ArrayObject) SingletonClass added in v0.1.0

func (b ArrayObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*ArrayObject) Value added in v0.1.0

func (a *ArrayObject) Value() interface{}

Value returns the elements from the object

type BlockObject added in v0.1.7

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

BlockObject represents an instance of `Block` class. In Goby, block literals can be used to define an "anonymous function" by using the `Block` class.

A block literal consists of `do`-`end` and code snippets between them, containing optional "block parameters" surrounded by `| |` that can be referred to within the block as "block variables".

`Block.new` can take a block literal, returning a "block" object.

You can call `#call` method on the block object to execute the block whenever and wherever you want. You can even pass around the block objects across your codebase.

```ruby bl = Block.new do |array|

array.reduce do |sum, i|
  sum + i
end

end

#=> <Block: REPL>

bl.call([1, 2, 3, 4]) #=> 10 ```

You can even form a `closure` (note that you can do that without using `Block.new`):

```ruby n = 1 bl = Block.new do

n = n + 1

end #=> <Block: REPL> bl.call #=> 2 bl.call #=> 3 bl.call #=> 4 ```

func (BlockObject) Class added in v0.1.7

func (b BlockObject) Class() *RClass

Class will return object's class

func (BlockObject) InstanceVariableGet added in v0.1.10

func (b BlockObject) InstanceVariableGet(name string) (Object, bool)

func (BlockObject) InstanceVariableSet added in v0.1.10

func (b BlockObject) InstanceVariableSet(name string, value Object) Object

func (BlockObject) SetSingletonClass added in v0.1.7

func (b BlockObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (BlockObject) SingletonClass added in v0.1.7

func (b BlockObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*BlockObject) Value added in v0.1.7

func (bo *BlockObject) Value() interface{}

Value returns the object

type BooleanObject

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

BooleanObject represents boolean object in goby and no instance methods are contained within it. `Boolean` class is just a dummy to hold logical `true` and `false` representation and no other active usage. `Boolean.new` is not supported.

Please note that class checking such as `#is_a?(Boolean)` **should be avoided in principle**. `#is_a?` often leads to redundant code. Consider using `respond_to?` first, but actually it is unnecessary in almost all cases.

var (
	// TRUE is shared boolean object that represents true
	TRUE *BooleanObject
	// FALSE is shared boolean object that represents false
	FALSE *BooleanObject
)

func (BooleanObject) Class

func (b BooleanObject) Class() *RClass

Class will return object's class

func (BooleanObject) InstanceVariableGet added in v0.1.10

func (b BooleanObject) InstanceVariableGet(name string) (Object, bool)

func (BooleanObject) InstanceVariableSet added in v0.1.10

func (b BooleanObject) InstanceVariableSet(name string, value Object) Object

func (BooleanObject) SetSingletonClass added in v0.1.0

func (b BooleanObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (BooleanObject) SingletonClass added in v0.1.0

func (b BooleanObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*BooleanObject) Value

func (b *BooleanObject) Value() interface{}

Value returns the object

type BuiltinMethodObject added in v0.1.3

type BuiltinMethodObject struct {
	Name string
	Fn   builtinMethodBody
	// contains filtered or unexported fields
}

BuiltinMethodObject represents methods defined in go.

func DefineForwardedConcurrentArrayMethod added in v0.1.6

func DefineForwardedConcurrentArrayMethod(methodName string, requireWriteLock bool) *BuiltinMethodObject

func ExternalBuiltinMethod added in v0.1.10

func ExternalBuiltinMethod(name string, m Method) *BuiltinMethodObject

ExternalBuiltinMethod is a function that builds a BuiltinMethodObject from an external function

func (BuiltinMethodObject) Class added in v0.1.3

func (b BuiltinMethodObject) Class() *RClass

Class will return object's class

func (BuiltinMethodObject) InstanceVariableGet added in v0.1.10

func (b BuiltinMethodObject) InstanceVariableGet(name string) (Object, bool)

func (BuiltinMethodObject) InstanceVariableSet added in v0.1.10

func (b BuiltinMethodObject) InstanceVariableSet(name string, value Object) Object

func (BuiltinMethodObject) SetSingletonClass added in v0.1.3

func (b BuiltinMethodObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (BuiltinMethodObject) SingletonClass added in v0.1.3

func (b BuiltinMethodObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*BuiltinMethodObject) Value added in v0.1.6

func (bim *BuiltinMethodObject) Value() interface{}

Value returns builtin method object's function

type ChannelObject added in v0.0.8

type ChannelObject struct {
	Chan         chan int
	ChannelState int
	// contains filtered or unexported fields
}

ChannelObject represents Goby's "channel", which equips the Golang' channel and works with `thread`. `thread` is actually a "goroutine". A channel object can relay any kind of objects and guarantees thread-safe communications. You should always use channel objects for safe communications between threads. `Channel#new` is available.

Note that channels are not like files and you don't need to explicitly close them (e.g.: exiting a loop). See https://tour.golang.org/concurrency/4

```ruby def f(from)

i = 0
while i < 3 do
  puts(from + ": " + i.to_s)
  i += 1
end

end

f("direct")

c = Channel.new # spawning a channel object

thread do

puts(c.receive)
f("thread")

end

thread do

puts("going")
c.deliver(10)

end

sleep(2) # This is to prevent main program finished before goroutine. ```

Note that the possibility of race conditions still exists. Handle them with care.

```ruby c = Channel.new

i = 0 thread do

i += 1
c.deliver(i)     # sends `i` to channel `c`

end

# If we put a bare `i += 1` here, then it will execute along with other thread, # which will cause a race condition. # The following "receive" is needed to block the main process until thread is finished c.receive i += 1

c.close # Redundant: just for explanation and you don't need to call this here ```

func (ChannelObject) Class added in v0.0.8

func (b ChannelObject) Class() *RClass

Class will return object's class

func (ChannelObject) InstanceVariableGet added in v0.1.10

func (b ChannelObject) InstanceVariableGet(name string) (Object, bool)

func (ChannelObject) InstanceVariableSet added in v0.1.10

func (b ChannelObject) InstanceVariableSet(name string, value Object) Object

func (ChannelObject) SetSingletonClass added in v0.1.0

func (b ChannelObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (ChannelObject) SingletonClass added in v0.1.0

func (b ChannelObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*ChannelObject) Value added in v0.1.0

func (co *ChannelObject) Value() interface{}

Value returns the object

type ClassLoader added in v0.1.10

type ClassLoader = func(*VM) error

ClassLoader can be registerd with a vm so that it can load this library at vm creation

func ExternalClass added in v0.1.10

func ExternalClass(name, path string, classMethods, instanceMethods map[string]Method) ClassLoader

ExternalClass helps define external go classes

type ConcurrentArrayObject added in v0.1.6

type ConcurrentArrayObject struct {
	InternalArray *ArrayObject

	sync.RWMutex
	// contains filtered or unexported fields
}

ConcurrentArrayObject is a thread-safe Array, implemented as a wrapper of an ArrayObject, coupled with an R/W mutex.

Arrays returned by any of the methods are in turn thread-safe.

For implementation simplicity, methods are simple redirection, and defined via a table.

func (ConcurrentArrayObject) Class added in v0.1.6

func (b ConcurrentArrayObject) Class() *RClass

Class will return object's class

func (ConcurrentArrayObject) InstanceVariableGet added in v0.1.10

func (b ConcurrentArrayObject) InstanceVariableGet(name string) (Object, bool)

func (ConcurrentArrayObject) InstanceVariableSet added in v0.1.10

func (b ConcurrentArrayObject) InstanceVariableSet(name string, value Object) Object

func (ConcurrentArrayObject) SetSingletonClass added in v0.1.6

func (b ConcurrentArrayObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (ConcurrentArrayObject) SingletonClass added in v0.1.6

func (b ConcurrentArrayObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*ConcurrentArrayObject) Value added in v0.1.6

func (cac *ConcurrentArrayObject) Value() interface{}

Value returns the object

type ConcurrentHashObject added in v0.1.6

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

ConcurrentHashObject is an implementation of thread-safe associative arrays (Hash).

The implementation internally uses Go's `sync.Map` type, with some advantages and disadvantages:

- it is highly performant and predictable for a certain pattern of usage (`concurrent loops with keys that are stable over time, and either few steady-state stores, or stores localized to one goroutine per key.`); performance and predictability in other conditions are unspecified; - iterations are non-deterministic; during iterations, keys may not be included; - size can't be retrieved; - for the reasons above, the Hash APIs implemented are minimal.

For details, see https://golang.org/pkg/sync/#Map.

```ruby require 'concurrent/hash' hash = Concurrent::Hash.new({ "a": 1, "b": 2 }) hash["a"] # => 1 ```

func (ConcurrentHashObject) Class added in v0.1.6

func (b ConcurrentHashObject) Class() *RClass

Class will return object's class

func (ConcurrentHashObject) InstanceVariableGet added in v0.1.10

func (b ConcurrentHashObject) InstanceVariableGet(name string) (Object, bool)

func (ConcurrentHashObject) InstanceVariableSet added in v0.1.10

func (b ConcurrentHashObject) InstanceVariableSet(name string, value Object) Object

func (ConcurrentHashObject) SetSingletonClass added in v0.1.6

func (b ConcurrentHashObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (ConcurrentHashObject) SingletonClass added in v0.1.6

func (b ConcurrentHashObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*ConcurrentHashObject) Value added in v0.1.6

func (h *ConcurrentHashObject) Value() interface{}

Value returns the object

type ConcurrentRWLockObject added in v0.1.6

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

ConcurrentRWLockObject is a Readers-Writer Lock (readers can concurrently put a lock, while a writer requires exclusive access).

The implementation internally uses Go's `sync.RWLock` type.

```ruby require 'concurrent/rw_lock' lock = Concurrent::RWLock.new lock.with_read_lock do

# critical section

end lock.with_write_lock do

# critical section

end ```

func (ConcurrentRWLockObject) Class added in v0.1.6

func (b ConcurrentRWLockObject) Class() *RClass

Class will return object's class

func (ConcurrentRWLockObject) InstanceVariableGet added in v0.1.10

func (b ConcurrentRWLockObject) InstanceVariableGet(name string) (Object, bool)

func (ConcurrentRWLockObject) InstanceVariableSet added in v0.1.10

func (b ConcurrentRWLockObject) InstanceVariableSet(name string, value Object) Object

func (ConcurrentRWLockObject) SetSingletonClass added in v0.1.6

func (b ConcurrentRWLockObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (ConcurrentRWLockObject) SingletonClass added in v0.1.6

func (b ConcurrentRWLockObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*ConcurrentRWLockObject) Value added in v0.1.6

func (lock *ConcurrentRWLockObject) Value() interface{}

Value returns the object

type Decimal added in v0.1.6

type Decimal = big.Rat

A type alias for representing a decimal

type DecimalObject added in v0.1.6

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

(Experiment) DecimalObject represents a comparable decimal number using Go's Rational representation `big.Rat` from math/big package, which consists of a numerator and a denominator with arbitrary size. By using Decimal you can avoid errors on float type during calculations. To keep accuracy, avoid conversions until all calculations have been finished. The numerator can be 0, but the denominator cannot be 0. Using Decimal for loop counters or like that is not recommended (TBD).

```ruby "3.14".to_d # => 3.14 "-0.7238943".to_d # => -0.7238943 "355/113".to_d # => 3.1415929203539823008849557522123893805309734513274336283185840

a = "16.1".to_d b = "1.1".to_d e = "17.2".to_d a + b # => 0.1 a + b == e # => true

('16.1'.to_d + "1.1".to_d).to_s #=> 17.2 ('16.1'.to_f + "1.1".to_f).to_s #=> 17.200000000000003 ```

- `Decimal.new` is not supported.

func (DecimalObject) Class added in v0.1.6

func (b DecimalObject) Class() *RClass

Class will return object's class

func (*DecimalObject) DecimalValue added in v0.1.6

func (f *DecimalObject) DecimalValue() interface{}

Alias of Value()

func (*DecimalObject) FloatValue added in v0.1.6

func (f *DecimalObject) FloatValue() float64

Float interface

func (DecimalObject) InstanceVariableGet added in v0.1.10

func (b DecimalObject) InstanceVariableGet(name string) (Object, bool)

func (DecimalObject) InstanceVariableSet added in v0.1.10

func (b DecimalObject) InstanceVariableSet(name string, value Object) Object

func (*DecimalObject) IntegerValue added in v0.1.6

func (f *DecimalObject) IntegerValue() int

Returns integer part of decimal

func (DecimalObject) SetSingletonClass added in v0.1.6

func (b DecimalObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (DecimalObject) SingletonClass added in v0.1.6

func (b DecimalObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*DecimalObject) Value added in v0.1.6

func (f *DecimalObject) Value() interface{}

Value returns the object

type Diggable added in v0.1.6

type Diggable interface {
	// contains filtered or unexported methods
}

Diggable represents a class that support the #dig method.

type Error

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

Error class is actually a special struct to hold internal error types with messages. Goby developers need not to take care of the struct. Goby maintainers should consider using the appropriate error type. Cannot create instances of Error class, or inherit Error class.

The type of internal errors:

see vm/errors/error.go.

func (Error) Class

func (b Error) Class() *RClass

Class will return object's class

func (Error) InstanceVariableGet added in v0.1.10

func (b Error) InstanceVariableGet(name string) (Object, bool)

func (Error) InstanceVariableSet added in v0.1.10

func (b Error) InstanceVariableSet(name string, value Object) Object

func (*Error) Message

func (e *Error) Message() string

Message prints the error's message and its stack traces

func (Error) SetSingletonClass added in v0.1.0

func (b Error) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (Error) SingletonClass added in v0.1.0

func (b Error) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*Error) Value added in v0.1.6

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

type FileObject added in v0.0.6

type FileObject struct {
	File *os.File
	// contains filtered or unexported fields
}

FileObject is a special type that contains file pointer so we can keep track on target file.

func (FileObject) Class added in v0.0.6

func (b FileObject) Class() *RClass

Class will return object's class

func (FileObject) InstanceVariableGet added in v0.1.10

func (b FileObject) InstanceVariableGet(name string) (Object, bool)

func (FileObject) InstanceVariableSet added in v0.1.10

func (b FileObject) InstanceVariableSet(name string, value Object) Object

func (FileObject) SetSingletonClass added in v0.1.0

func (b FileObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (FileObject) SingletonClass added in v0.1.0

func (b FileObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*FileObject) Value added in v0.1.6

func (f *FileObject) Value() interface{}

Value returns file object's string format

type Float added in v0.1.6

type Float = big.Float

type FloatObject added in v0.1.6

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

FloatObject represents an inexact real number using the native architecture's double-precision floating point representation.

```ruby 1.1 + 1.1 # => 2.2 2.1 * 2.1 # => 4.41 ```

- `Float.new` is not supported.

func (FloatObject) Class added in v0.1.6

func (b FloatObject) Class() *RClass

Class will return object's class

func (FloatObject) InstanceVariableGet added in v0.1.10

func (b FloatObject) InstanceVariableGet(name string) (Object, bool)

func (FloatObject) InstanceVariableSet added in v0.1.10

func (b FloatObject) InstanceVariableSet(name string, value Object) Object

func (FloatObject) SetSingletonClass added in v0.1.6

func (b FloatObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (FloatObject) SingletonClass added in v0.1.6

func (b FloatObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*FloatObject) Value added in v0.1.6

func (f *FloatObject) Value() interface{}

Value returns the object

type GoMap added in v0.1.6

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

GoMap ...

func (GoMap) Class added in v0.1.6

func (b GoMap) Class() *RClass

Class will return object's class

func (GoMap) InstanceVariableGet added in v0.1.10

func (b GoMap) InstanceVariableGet(name string) (Object, bool)

func (GoMap) InstanceVariableSet added in v0.1.10

func (b GoMap) InstanceVariableSet(name string, value Object) Object

func (GoMap) SetSingletonClass added in v0.1.6

func (b GoMap) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (GoMap) SingletonClass added in v0.1.6

func (b GoMap) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*GoMap) Value added in v0.1.6

func (m *GoMap) Value() interface{}

Value returns the object

type GoObject added in v0.1.0

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

GoObject ...

func (GoObject) Class added in v0.1.0

func (b GoObject) Class() *RClass

Class will return object's class

func (GoObject) InstanceVariableGet added in v0.1.10

func (b GoObject) InstanceVariableGet(name string) (Object, bool)

func (GoObject) InstanceVariableSet added in v0.1.10

func (b GoObject) InstanceVariableSet(name string, value Object) Object

func (GoObject) SetSingletonClass added in v0.1.0

func (b GoObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (GoObject) SingletonClass added in v0.1.0

func (b GoObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*GoObject) Value added in v0.1.0

func (s *GoObject) Value() interface{}

Value returns the object

type HashObject

type HashObject struct {
	Pairs map[string]Object

	// See `[]` and `[]=` for the operational explanation of the default value.
	Default Object
	// contains filtered or unexported fields
}

HashObject represents hash instances Hash is a collection of key-value pair, which works like a dictionary. Hash literal is represented with curly brackets `{ }` like `{ key: value }`. Each key of the hash is unique and cannot be duplicate within the hash. Adding a leading space and a trailing space within curly brackets are preferable.

- **Key:** an alphanumeric word that starts with alphabet, without containing space and punctuations. Underscore `_` can also be used within the key. String literal like "mickey mouse" cannot be used as a hash key. The internal key is actually a String and **not a Symbol** for now (TBD). Thus only a String object or a string literal should be used when referencing with `[ ]`.

```ruby a = { balthazar1: 100 } # valid b = { 2melchior: 200 } # invalid x = 'balthazar1'

a["balthazar1"] # => 100 a[x] # => 100 a[balthazar1] # => error ```

- **value:** String literal and objects (Integer, String, Array, Hash, nil, etc) can be used.

**Note:** - The order of key-value pairs are **not** preserved. - Operator `=>` is not supported. - `Hash.new` is not supported.

func (HashObject) Class

func (b HashObject) Class() *RClass

Class will return object's class

func (HashObject) InstanceVariableGet added in v0.1.10

func (b HashObject) InstanceVariableGet(name string) (Object, bool)

func (HashObject) InstanceVariableSet added in v0.1.10

func (b HashObject) InstanceVariableSet(name string, value Object) Object

func (HashObject) SetSingletonClass added in v0.1.0

func (b HashObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (HashObject) SingletonClass added in v0.1.0

func (b HashObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*HashObject) Value added in v0.1.0

func (h *HashObject) Value() interface{}

Value returns the object

type Int added in v0.1.6

type Int = big.Int

type IntegerObject

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

IntegerObject represents number objects which can bring into mathematical calculations.

```ruby 1 + 1 # => 2 2 * 2 # => 4 ```

- `Integer.new` is not supported.

func (IntegerObject) Class

func (b IntegerObject) Class() *RClass

Class will return object's class

func (IntegerObject) InstanceVariableGet added in v0.1.10

func (b IntegerObject) InstanceVariableGet(name string) (Object, bool)

func (IntegerObject) InstanceVariableSet added in v0.1.10

func (b IntegerObject) InstanceVariableSet(name string, value Object) Object

func (IntegerObject) SetSingletonClass added in v0.1.0

func (b IntegerObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (IntegerObject) SingletonClass added in v0.1.0

func (b IntegerObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*IntegerObject) Value

func (i *IntegerObject) Value() interface{}

Value returns the object

type Match added in v0.1.6

type Match = regexp2.Match

MatchDataObject represents the match data returned by a regular expression matching operation. You can use named-captures via `(?<name>)`.

```ruby 'abcd'.match(Regexp.new('(b.)')) #=> #<MatchData 0:"bc" 1:"bc">

'abcd'.match(Regexp.new('a(?<first>b)(?<second>c)')) #=> #<MatchData 0:"abc" first:"b" second:"c"> ```

- `MatchData.new` is not supported.

type MatchDataObject added in v0.1.6

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

func (MatchDataObject) Class added in v0.1.6

func (b MatchDataObject) Class() *RClass

Class will return object's class

func (MatchDataObject) InstanceVariableGet added in v0.1.10

func (b MatchDataObject) InstanceVariableGet(name string) (Object, bool)

func (MatchDataObject) InstanceVariableSet added in v0.1.10

func (b MatchDataObject) InstanceVariableSet(name string, value Object) Object

func (MatchDataObject) SetSingletonClass added in v0.1.6

func (b MatchDataObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (MatchDataObject) SingletonClass added in v0.1.6

func (b MatchDataObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*MatchDataObject) Value added in v0.1.6

func (m *MatchDataObject) Value() interface{}

redirects to toString()

type Method

type Method = func(receiver Object, line int, t *Thread, args []Object) Object

Method is a callable function

type MethodObject added in v0.0.5

type MethodObject struct {
	Name string
	// contains filtered or unexported fields
}

MethodObject represents methods defined using goby.

func (MethodObject) Class added in v0.0.9

func (b MethodObject) Class() *RClass

Class will return object's class

func (MethodObject) InstanceVariableGet added in v0.1.10

func (b MethodObject) InstanceVariableGet(name string) (Object, bool)

func (MethodObject) InstanceVariableSet added in v0.1.10

func (b MethodObject) InstanceVariableSet(name string, value Object) Object

func (MethodObject) SetSingletonClass added in v0.1.0

func (b MethodObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (MethodObject) SingletonClass added in v0.1.0

func (b MethodObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*MethodObject) Value added in v0.1.6

func (m *MethodObject) Value() interface{}

Value returns method object's string format

type NullObject added in v0.0.5

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

NullObject (`nil`) represents the null value in Goby. `nil` is convert into `null` when exported to JSON format. - `Null.new` is not supported.

var (
	// NULL represents Goby's null objects.
	NULL *NullObject
)

func (NullObject) Class added in v0.0.5

func (b NullObject) Class() *RClass

Class will return object's class

func (NullObject) InstanceVariableGet added in v0.1.10

func (b NullObject) InstanceVariableGet(name string) (Object, bool)

func (NullObject) InstanceVariableSet added in v0.1.10

func (b NullObject) InstanceVariableSet(name string, value Object) Object

func (NullObject) SetSingletonClass added in v0.1.0

func (b NullObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (NullObject) SingletonClass added in v0.1.0

func (b NullObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*NullObject) Value added in v0.1.0

func (n *NullObject) Value() interface{}

Value returns the object

type Numeric added in v0.1.6

type Numeric interface {
	// contains filtered or unexported methods
}

Numeric currently represents a class that support some numeric conversions. At this stage, it's not meant to be a Goby class in a strict sense, but only a convenient interface.

type Object

type Object interface {
	Class() *RClass
	Value() interface{}
	SingletonClass() *RClass
	SetSingletonClass(*RClass)

	InstanceVariableGet(string) (Object, bool)
	InstanceVariableSet(string, Object) Object
	// contains filtered or unexported methods
}

Object represents all objects in Goby, including Array, Integer or even Method and Error.

func ExecAndReturn added in v0.1.10

func ExecAndReturn(t *testing.T, src string) Object

type PluginObject added in v0.1.0

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

PluginObject is a special type that contains a Go's plugin

func (PluginObject) Class added in v0.1.0

func (b PluginObject) Class() *RClass

Class will return object's class

func (PluginObject) InstanceVariableGet added in v0.1.10

func (b PluginObject) InstanceVariableGet(name string) (Object, bool)

func (PluginObject) InstanceVariableSet added in v0.1.10

func (b PluginObject) InstanceVariableSet(name string, value Object) Object

func (PluginObject) SetSingletonClass added in v0.1.0

func (b PluginObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (PluginObject) SingletonClass added in v0.1.0

func (b PluginObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*PluginObject) Value added in v0.1.6

func (p *PluginObject) Value() interface{}

Value returns plugin object's string format

type Pointer

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

Pointer is used to point to an object. Variables should hold pointer instead of holding a object directly.

type RClass

type RClass struct {
	// Name is the class's name
	Name string
	// Methods contains its instances' methods
	Methods *environment
	// contains filtered or unexported fields
}

RClass represents normal (not built in) class object

func (RClass) Class added in v0.0.9

func (b RClass) Class() *RClass

Class will return object's class

func (RClass) InstanceVariableGet added in v0.1.10

func (b RClass) InstanceVariableGet(name string) (Object, bool)

func (RClass) InstanceVariableSet added in v0.1.10

func (b RClass) InstanceVariableSet(name string, value Object) Object

func (*RClass) ReturnName added in v0.0.9

func (c *RClass) ReturnName() string

ReturnName returns the object's name as the string format

func (RClass) SetSingletonClass added in v0.1.0

func (b RClass) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (RClass) SingletonClass added in v0.1.0

func (b RClass) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*RClass) Value added in v0.1.6

func (c *RClass) Value() interface{}

Value returns class itself

type RObject

type RObject struct {
	InitializeMethod *MethodObject
	// contains filtered or unexported fields
}

RObject represents any non built-in class's instance.

func (RObject) Class

func (b RObject) Class() *RClass

Class will return object's class

func (RObject) InstanceVariableGet added in v0.1.10

func (b RObject) InstanceVariableGet(name string) (Object, bool)

func (RObject) InstanceVariableSet added in v0.1.10

func (b RObject) InstanceVariableSet(name string, value Object) Object

func (RObject) SetSingletonClass added in v0.1.0

func (b RObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (RObject) SingletonClass added in v0.1.0

func (b RObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*RObject) Value added in v0.1.6

func (ro *RObject) Value() interface{}

Value returns object's string format

type RangeObject added in v0.0.9

type RangeObject struct {
	Start int
	End   int
	// contains filtered or unexported fields
}

RangeObject is the built in range class Range represents an interval: a set of values from the beginning to the end specified. Currently, only Integer objects or integer literal are supported.

```ruby r = 0 (1..(1+4)).each do |i|

puts(r = r + i)

end ```

```ruby r = 0 a = 1 b = 5 (a..b).each do |i|

r = r + i

end ```

func (RangeObject) Class added in v0.0.9

func (b RangeObject) Class() *RClass

Class will return object's class

func (RangeObject) InstanceVariableGet added in v0.1.10

func (b RangeObject) InstanceVariableGet(name string) (Object, bool)

func (RangeObject) InstanceVariableSet added in v0.1.10

func (b RangeObject) InstanceVariableSet(name string, value Object) Object

func (RangeObject) SetSingletonClass added in v0.1.0

func (b RangeObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (RangeObject) SingletonClass added in v0.1.0

func (b RangeObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*RangeObject) Value added in v0.1.6

func (ro *RangeObject) Value() interface{}

Value returns range object's string format

type Regexp added in v0.1.6

type Regexp = regexp2.Regexp

RegexpObject represents regexp instances, which of the type is actually string. Regexp object holds regexp strings. Powered by: github.com/dlclark/regexp2 The regexp2 package had been ported from .NET Framework's regexp library, which is PCRE-compatible and is almost all equivalent to Ruby's Onigmo regexp library.

```ruby a = Regexp.new("orl") a.match?("Hello World") #=> true a.match?("Hello Regexp") #=> false

b = Regexp.new("😏") b.match?("🤡 😏 😐") #=> true b.match?("😝 😍 😊") #=> false

c = Regexp.new("居(ら(?=れ)|さ(?=せ)|る|ろ|れ(?=[ばる])|よ|(?=な[いかくけそ]|ま[しすせ]|そう|た|て))") c.match?("居られればいいのに") #=> true c.match?("居ずまいを正す") #=> false ```

**Note:**

- Currently, manipulations are based upon Golang's Unicode manipulations. - Currently, UTF-8 encoding is assumed based upon Golang's string manipulation, but the encoding is not actually specified(TBD). - `Regexp.new` is exceptionally supported.

**To Goby maintainers**: avoid using Go's standard regexp package (slow and not rich). Consider the faster `Trim` or `Split` etc in Go's "strings" package first, or just use the dlclark/regexp2 instead. ToDo: Regexp literals with '/.../'

type RegexpObject added in v0.1.6

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

func (RegexpObject) Class added in v0.1.6

func (b RegexpObject) Class() *RClass

Class will return object's class

func (RegexpObject) InstanceVariableGet added in v0.1.10

func (b RegexpObject) InstanceVariableGet(name string) (Object, bool)

func (RegexpObject) InstanceVariableSet added in v0.1.10

func (b RegexpObject) InstanceVariableSet(name string, value Object) Object

func (RegexpObject) SetSingletonClass added in v0.1.6

func (b RegexpObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (RegexpObject) SingletonClass added in v0.1.6

func (b RegexpObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*RegexpObject) Value added in v0.1.6

func (r *RegexpObject) Value() interface{}

Value returns the object

type Stack added in v0.1.10

type Stack struct {

	// Although every thread has its own stack, vm's main thread still can be accessed by other threads.
	// This is why we need a lock in stack
	// TODO: Find a way to fix this instead of put lock on every stack.
	sync.RWMutex
	// contains filtered or unexported fields
}

Stack is a basic stack implimentation

func (*Stack) Pop added in v0.1.10

func (s *Stack) Pop() *Pointer

Pop an element off the top of the stack

func (*Stack) Push added in v0.1.10

func (s *Stack) Push(v *Pointer)

Push an element to the top of the stack

func (*Stack) Set added in v0.1.10

func (s *Stack) Set(index int, pointer *Pointer)

Set a value at a given index in the stack. TODO: Maybe we should be checking for size before we do this.

type StringObject

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

StringObject represents string instances String object holds and manipulates a sequence of characters. String objects may be created using as string literals. Double or single quotations can be used for representation.

```ruby a = "Three" b = 'zero' c = '漢' d = 'Tiếng Việt' e = "😏️️" ```

**Note:**

- Currently, manipulations are based upon Golang's Unicode manipulations. - Currently, UTF-8 encoding is assumed based upon Golang's string manipulation, but the encoding is not actually specified(TBD). - `String.new` is not supported.

func (StringObject) Class

func (b StringObject) Class() *RClass

Class will return object's class

func (StringObject) InstanceVariableGet added in v0.1.10

func (b StringObject) InstanceVariableGet(name string) (Object, bool)

func (StringObject) InstanceVariableSet added in v0.1.10

func (b StringObject) InstanceVariableSet(name string, value Object) Object

func (StringObject) SetSingletonClass added in v0.1.0

func (b StringObject) SetSingletonClass(c *RClass)

SetSingletonClass sets object's singleton class

func (StringObject) SingletonClass added in v0.1.0

func (b StringObject) SingletonClass() *RClass

SingletonClass returns object's singleton class

func (*StringObject) Value

func (s *StringObject) Value() interface{}

Value returns the object

type Thread added in v0.1.10

type Thread struct {

	// data Stack
	Stack Stack
	// contains filtered or unexported fields
}

Thread is the context needed for a single thread of execution

func (*Thread) VM added in v0.1.10

func (t *Thread) VM() *VM

type VM

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

VM represents a stack based virtual machine.

func InitIssueReportVM added in v0.1.3

func InitIssueReportVM(dir string, args []string) (*VM, error)

InitIssueReportVM initializes a vm in test mode for issue reporting

func New

func New(fileDir string, args []string) (vm *VM, e error)

New initializes a vm to initialize state and returns it.

func (*VM) ExecInstructions added in v0.0.9

func (vm *VM) ExecInstructions(sets []*bytecode.InstructionSet, fn string)

ExecInstructions accepts a sequence of bytecodes and use vm to evaluate them.

func (*VM) GetExecResult

func (vm *VM) GetExecResult() Object

GetExecResult returns stack's top most value. Normally it's used in tests.

func (*VM) GetREPLResult added in v0.0.9

func (vm *VM) GetREPLResult() string

GetREPLResult returns strings that should be showed after each evaluation.

func (*VM) InitArrayObject added in v0.1.10

func (vm *VM) InitArrayObject(elements []Object) *ArrayObject

InitArrayObject returns a new object with the given elemnts

func (*VM) InitErrorObject added in v0.1.10

func (vm *VM) InitErrorObject(errorType string, sourceLine int, format string, args ...interface{}) *Error

func (*VM) InitForREPL added in v0.0.9

func (vm *VM) InitForREPL()

InitForREPL does following things: - Initialize instruction sets' index tables - Set vm to REPL mode - Create and push main object frame

func (*VM) InitHashObject added in v0.1.10

func (vm *VM) InitHashObject(pairs map[string]Object) *HashObject

func (*VM) InitIntegerObject added in v0.1.10

func (vm *VM) InitIntegerObject(value int) *IntegerObject

func (*VM) InitObjectFromGoType added in v0.1.10

func (v *VM) InitObjectFromGoType(value interface{}) Object

func (*VM) InitStringObject added in v0.1.10

func (vm *VM) InitStringObject(value string) *StringObject

func (*VM) REPLExec added in v0.0.9

func (vm *VM) REPLExec(sets []*bytecode.InstructionSet)

REPLExec executes instructions differently from normal program execution.

func (*VM) SetClassISIndexTable added in v0.0.9

func (vm *VM) SetClassISIndexTable(fn filename)

SetClassISIndexTable adds new instruction set's index table to vm.classISIndexTables

func (*VM) SetMethodISIndexTable added in v0.0.9

func (vm *VM) SetMethodISIndexTable(fn filename)

SetMethodISIndexTable adds new instruction set's index table to vm.methodISIndexTables

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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