Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertToGoFuncArgs(args []Object) ([]interface{}, error)
- func PrintError(v *VM)
- func RegisterExternalClass(name string, c ...ClassLoader)
- func VerifyExpected(t *testing.T, i int, evaluated Object, expected interface{})
- type ArrayObject
- type BaseObj
- type BlockObject
- type BooleanObject
- type BuiltinMethodObject
- type ChannelObject
- type ClassLoader
- type ConcurrentArrayObject
- type ConcurrentHashObject
- type ConcurrentRWLockObject
- type Decimal
- type DecimalObject
- func (d *DecimalObject) DecimalValue() interface{}
- func (d *DecimalObject) FloatValue() float64
- func (d *DecimalObject) Inspect() string
- func (d *DecimalObject) IntegerValue() int
- func (d *DecimalObject) ToJSON(t *Thread) string
- func (d *DecimalObject) ToString() string
- func (d *DecimalObject) Value() interface{}
- type Diggable
- type Error
- type FileObject
- type Float
- type FloatObject
- type GoMap
- type GoObject
- type HashObject
- type Int
- type IntegerObject
- type Match
- type MatchDataObject
- type Method
- type MethodObject
- type NullObject
- type Numeric
- type Object
- type Pointer
- type RClass
- type RObject
- type RangeObject
- type Regexp
- type RegexpObject
- type Stack
- type StringObject
- type Thread
- type VM
- func (vm *VM) ExecInstructions(sets []*bytecode.InstructionSet, fn string)
- func (vm *VM) GetExecResult() Object
- func (vm *VM) GetREPLResult() string
- func (vm *VM) InitArrayObject(elements []Object) *ArrayObject
- func (vm *VM) InitErrorObject(errorType string, sourceLine int, format string, args ...interface{}) *Error
- func (vm *VM) InitForREPL()
- func (vm *VM) InitHashObject(pairs map[string]Object) *HashObject
- func (vm *VM) InitIntegerObject(value int) *IntegerObject
- func (vm *VM) InitNoMethodError(sourceLine int, methodName string, receiver Object) *Error
- func (v *VM) InitObjectFromGoType(value interface{}) Object
- func (vm *VM) InitStringObject(value string) *StringObject
- func (vm *VM) REPLExec(sets []*bytecode.InstructionSet)
- func (vm *VM) SetClassISIndexTable(fn filename)
- func (vm *VM) SetMethodISIndexTable(fn filename)
- func (vm *VM) TopLevelClass(cn string) *RClass
Constants ¶
const Version = "0.1.13"
Version stores current Goby version
Variables ¶
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, }
ConcurrentArrayMethodsForwardingTable is a 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.
var DefaultLibPath string
DefaultLibPath is used for overriding vm.libpath build-time.
Functions ¶
func ConvertToGoFuncArgs ¶ added in v0.1.11
ConvertToGoFuncArgs converts Goby's args to Go func's args
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(name string, c ...ClassLoader)
RegisterExternalClass will add the given class to the global registry of available classes
Types ¶
type ArrayObject ¶
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) Len ¶ added in v0.1.11
func (a *ArrayObject) Len() int
Len returns the length of array's elements
func (*ArrayObject) Less ¶ added in v0.1.11
func (a *ArrayObject) Less(i, j int) bool
Less is one of the required method to fulfill sortable interface
func (*ArrayObject) Swap ¶ added in v0.1.11
func (a *ArrayObject) Swap(i, j int)
Swap is one of the required method to fulfill sortable interface
func (*ArrayObject) ToJSON ¶ added in v0.1.11
func (a *ArrayObject) ToJSON(t *Thread) string
ToJSON returns the object's elements as the JSON string format
func (*ArrayObject) ToString ¶ added in v0.1.11
func (a *ArrayObject) ToString() string
ToString returns the object's elements as the string format
func (*ArrayObject) Value ¶ added in v0.1.0
func (a *ArrayObject) Value() interface{}
Value returns the elements from the object
type BaseObj ¶ added in v0.1.11
type BaseObj struct { InstanceVariables *environment // contains filtered or unexported fields }
BaseObj ==============================================================
func NewBaseObject ¶ added in v0.1.11
NewBaseObject creates a BaseObj
func (*BaseObj) InstanceVariableGet ¶ added in v0.1.11
InstanceVariableGet returns an instance variable specified
func (*BaseObj) InstanceVariableSet ¶ added in v0.1.11
InstanceVariableSet sets the instance variable specified
func (*BaseObj) SetSingletonClass ¶ added in v0.1.11
SetSingletonClass sets object's singleton class
func (*BaseObj) SingletonClass ¶ added in v0.1.11
SingletonClass returns object's singleton class
type BlockObject ¶ added in v0.1.7
type BlockObject struct { *BaseObj // 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) Inspect ¶ added in v0.1.11
func (bo *BlockObject) Inspect() string
Inspect delegates to ToString
func (*BlockObject) ToJSON ¶ added in v0.1.11
func (bo *BlockObject) ToJSON(t *Thread) string
ToJSON just delegates to ToString
func (*BlockObject) ToString ¶ added in v0.1.11
func (bo *BlockObject) ToString() string
ToString returns the object's name as the string format
func (*BlockObject) Value ¶ added in v0.1.7
func (bo *BlockObject) Value() interface{}
Value returns the object
type BooleanObject ¶
type BooleanObject struct { *BaseObj // 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) Inspect ¶
func (b *BooleanObject) Inspect() string
Inspect delegates to ToString
func (*BooleanObject) ToJSON ¶ added in v0.1.11
func (b *BooleanObject) ToJSON(t *Thread) string
ToJSON just delegates to `ToString`
func (*BooleanObject) ToString ¶ added in v0.1.11
func (b *BooleanObject) ToString() string
ToString returns the object's name as the string format
type BuiltinMethodObject ¶ added in v0.1.3
BuiltinMethodObject represents methods defined in go.
func DefineForwardedConcurrentArrayMethod ¶ added in v0.1.6
func DefineForwardedConcurrentArrayMethod(methodName string, requireWriteLock bool) *BuiltinMethodObject
DefineForwardedConcurrentArrayMethod defines methods for ConcurrentArrayObject
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) Inspect ¶ added in v0.1.11
func (bim *BuiltinMethodObject) Inspect() string
Inspect delegates to ToString
func (*BuiltinMethodObject) ToJSON ¶ added in v0.1.11
func (bim *BuiltinMethodObject) ToJSON(t *Thread) string
ToJSON just delegates to `ToString`
func (*BuiltinMethodObject) ToString ¶ added in v0.1.11
func (bim *BuiltinMethodObject) ToString() string
ToString returns the object's name as the string format
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
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) Inspect ¶ added in v0.1.11
func (co *ChannelObject) Inspect() string
Inspect delegates to ToString
func (*ChannelObject) ToJSON ¶ added in v0.1.11
func (co *ChannelObject) ToJSON(t *Thread) string
ToJSON just delegates to ToString
func (*ChannelObject) ToString ¶ added in v0.1.11
func (co *ChannelObject) ToString() string
ToString returns the object's name as the string format
func (*ChannelObject) Value ¶ added in v0.1.0
func (co *ChannelObject) Value() interface{}
Value returns the object
type ClassLoader ¶ added in v0.1.10
ClassLoader can be registered with a vm so that it can load this library at vm creation
func NewExternalClassLoader ¶ added in v0.1.13
func NewExternalClassLoader(className, libPath string, classMethods, instanceMethods map[string]Method) ClassLoader
NewExternalClassLoader helps define external go classes by generating a class loader function
type ConcurrentArrayObject ¶ added in v0.1.6
type ConcurrentArrayObject struct { *BaseObj InternalArray *ArrayObject sync.RWMutex }
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) Inspect ¶ added in v0.1.11
func (cao *ConcurrentArrayObject) Inspect() string
Inspect delegates to ToString
func (*ConcurrentArrayObject) ToJSON ¶ added in v0.1.11
func (cao *ConcurrentArrayObject) ToJSON(t *Thread) string
ToJSON returns the object's name as the JSON string format
func (*ConcurrentArrayObject) ToString ¶ added in v0.1.11
func (cao *ConcurrentArrayObject) ToString() string
ToString returns the object's name as the string format
func (*ConcurrentArrayObject) Value ¶ added in v0.1.6
func (cao *ConcurrentArrayObject) Value() interface{}
Value returns the object
type ConcurrentHashObject ¶ added in v0.1.6
type ConcurrentHashObject struct { *BaseObj // 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) Inspect ¶ added in v0.1.11
func (h *ConcurrentHashObject) Inspect() string
Inspect delegates to ToString
func (*ConcurrentHashObject) ToJSON ¶ added in v0.1.11
func (h *ConcurrentHashObject) ToJSON(t *Thread) string
ToJSON returns the object's name as the JSON string format
func (*ConcurrentHashObject) ToString ¶ added in v0.1.11
func (h *ConcurrentHashObject) ToString() string
ToString returns the object's name as the string format
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 { *BaseObj // 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) Inspect ¶ added in v0.1.11
func (lock *ConcurrentRWLockObject) Inspect() string
Inspect delegates to ToString
func (*ConcurrentRWLockObject) ToJSON ¶ added in v0.1.11
func (lock *ConcurrentRWLockObject) ToJSON(t *Thread) string
ToJSON just delegates to ToString
func (*ConcurrentRWLockObject) ToString ¶ added in v0.1.11
func (lock *ConcurrentRWLockObject) ToString() string
ToString returns the object's name as the string format
func (*ConcurrentRWLockObject) Value ¶ added in v0.1.6
func (lock *ConcurrentRWLockObject) Value() interface{}
Value returns the object
type DecimalObject ¶ added in v0.1.6
type DecimalObject struct { *BaseObj // contains filtered or unexported fields }
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 (experimental). 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) DecimalValue ¶ added in v0.1.6
func (d *DecimalObject) DecimalValue() interface{}
DecimalValue is an alias of Value()
func (*DecimalObject) FloatValue ¶ added in v0.1.6
func (d *DecimalObject) FloatValue() float64
FloatValue is a float interface
func (*DecimalObject) Inspect ¶ added in v0.1.11
func (d *DecimalObject) Inspect() string
Inspect delegates to ToString
func (*DecimalObject) IntegerValue ¶ added in v0.1.6
func (d *DecimalObject) IntegerValue() int
IntegerValue returns integer part of decimal
func (*DecimalObject) ToJSON ¶ added in v0.1.11
func (d *DecimalObject) ToJSON(t *Thread) string
ToJSON just delegates to ToString
func (*DecimalObject) ToString ¶ added in v0.1.11
func (d *DecimalObject) ToString() string
ToString returns the object's approximate float value as the string format.
func (*DecimalObject) Value ¶ added in v0.1.6
func (d *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 ¶
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.
type FileObject ¶ added in v0.0.6
FileObject is a special type that contains file pointer so we can keep track on target file. Using `File.open` with block is recommended because the instance (block variable) automatically closes.
```ruby File.open("/tmp/goby/out.txt", "w", 0755) do |f|
a = f.read f.write(a + "12345")
end # f automatically closes ```
func (*FileObject) Inspect ¶ added in v0.0.6
func (f *FileObject) Inspect() string
Inspect delegates to ToString
func (*FileObject) ToJSON ¶ added in v0.1.11
func (f *FileObject) ToJSON(t *Thread) string
ToJSON just delegates to `ToString`
func (*FileObject) ToString ¶ added in v0.1.11
func (f *FileObject) ToString() string
ToString returns the object's name as the string format
func (*FileObject) Value ¶ added in v0.1.6
func (f *FileObject) Value() interface{}
Value returns file object's string format
type FloatObject ¶ added in v0.1.6
type FloatObject struct { *BaseObj // 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) Inspect ¶ added in v0.1.11
func (f *FloatObject) Inspect() string
Inspect delegates to ToString
func (*FloatObject) ToJSON ¶ added in v0.1.11
func (f *FloatObject) ToJSON(t *Thread) string
ToJSON just delegates to ToString
func (*FloatObject) ToString ¶ added in v0.1.11
func (f *FloatObject) ToString() string
ToString returns the object's value as the string format, in non exponential format (straight number, without exponent `E<exp>`).
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 { *BaseObj // contains filtered or unexported fields }
GoMap ...
type GoObject ¶ added in v0.1.0
type GoObject struct { *BaseObj // contains filtered or unexported fields }
GoObject ...
type HashObject ¶
type HashObject struct { *BaseObj Pairs map[string]Object // See `[]` and `[]=` for the operational explanation of the default value. Default Object }
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. In hash literals, only a symbol literals such as `symbol:` can be used as a key. String literal like "mickey mouse" cannot be used as a key in hash literals. (String and symbol are equivalent in Goby)
Retrieving a value via `[]`, you can use both symbol literals or string literals as keys.
```ruby a = { balthazar1: 100 } # valid b = { 2melchior: 200 } # invalid b = { "casper": 200 } # invalid x = 'balthazar1'
a["balthazar1"] # => 100 a[balthazar1:] # => 100 a[x] # => 100 a[balthazar1] # => error ```
- **value:** String literals 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) ToJSON ¶ added in v0.1.11
func (h *HashObject) ToJSON(t *Thread) string
ToJSON returns the object's name as the JSON string format
func (*HashObject) ToString ¶ added in v0.1.11
func (h *HashObject) ToString() string
ToString returns the object's name as the string format
func (*HashObject) Value ¶ added in v0.1.0
func (h *HashObject) Value() interface{}
Value returns the object
type IntegerObject ¶
type IntegerObject struct { *BaseObj // 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) Inspect ¶
func (i *IntegerObject) Inspect() string
Inspect delegates to ToString
func (*IntegerObject) ToJSON ¶ added in v0.1.11
func (i *IntegerObject) ToJSON(t *Thread) string
ToJSON just delegates to ToString
func (*IntegerObject) ToString ¶ added in v0.1.11
func (i *IntegerObject) ToString() string
ToString returns the object's name as the string format
type MatchDataObject ¶ added in v0.1.6
type MatchDataObject struct { *BaseObj // contains filtered or unexported fields }
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.
func (*MatchDataObject) Inspect ¶ added in v0.1.11
func (m *MatchDataObject) Inspect() string
Inspect delegates to ToString
func (*MatchDataObject) ToJSON ¶ added in v0.1.11
func (m *MatchDataObject) ToJSON(t *Thread) string
ToJSON returns a `{ captureNumber: captureValue }` JSON-encoded string
func (*MatchDataObject) ToString ¶ added in v0.1.11
func (m *MatchDataObject) ToString() string
ToString returns a string representation of the object
func (*MatchDataObject) Value ¶ added in v0.1.6
func (m *MatchDataObject) Value() interface{}
Value redirects to ToString()
type MethodObject ¶ added in v0.0.5
MethodObject represents methods defined using goby.
func (*MethodObject) Inspect ¶ added in v0.0.5
func (m *MethodObject) Inspect() string
Inspect delegates to ToString
func (*MethodObject) ToJSON ¶ added in v0.1.11
func (m *MethodObject) ToJSON(t *Thread) string
ToJSON just delegates to ToString
func (*MethodObject) ToString ¶ added in v0.1.11
func (m *MethodObject) ToString() string
ToString returns the object's name as the string format
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 {
*BaseObj
}
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) Inspect ¶ added in v0.0.5
func (n *NullObject) Inspect() string
Inspect returns string "nil" instead of "" like ToString
func (*NullObject) ToJSON ¶ added in v0.1.11
func (n *NullObject) ToJSON(t *Thread) string
ToJSON just delegates to ToString
func (*NullObject) ToString ¶ added in v0.1.11
func (n *NullObject) ToString() string
ToString returns the object's name as the string format
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) ToString() string Inspect() string ToJSON(t *Thread) string ID() int 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.
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 *BaseObj // contains filtered or unexported fields }
RClass represents normal (not built in) class object
func (*RClass) ReturnName ¶ added in v0.0.9
ReturnName returns the object's name as the string format
type RObject ¶
type RObject struct { *BaseObj InitializeMethod *MethodObject }
RObject represents any non built-in class's instance.
type RangeObject ¶ added in v0.0.9
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) Inspect ¶ added in v0.1.11
func (ro *RangeObject) Inspect() string
Inspect delegates to ToString
func (*RangeObject) ToJSON ¶ added in v0.1.11
func (ro *RangeObject) ToJSON(t *Thread) string
ToJSON just delegates to ToString
func (*RangeObject) ToString ¶ added in v0.1.11
func (ro *RangeObject) ToString() string
ToString returns the object's name as the string format
func (*RangeObject) Value ¶ added in v0.1.6
func (ro *RangeObject) Value() interface{}
Value returns range object's string format
type RegexpObject ¶ added in v0.1.6
type RegexpObject struct { *BaseObj // contains filtered or unexported fields }
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 '/.../'
func (*RegexpObject) Inspect ¶ added in v0.1.11
func (r *RegexpObject) Inspect() string
Inspect delegates to ToString
func (*RegexpObject) ToJSON ¶ added in v0.1.11
func (r *RegexpObject) ToJSON(t *Thread) string
ToJSON just delegates to ToString
func (*RegexpObject) ToString ¶ added in v0.1.11
func (r *RegexpObject) ToString() string
ToString returns the object's name as the string format
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 implementation
type StringObject ¶
type StringObject struct { *BaseObj // 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 or symbol literals. Double or single quotations can be used for representation.
```ruby a = "Three" b = 'zero' c = '漢' d = 'Tiếng Việt' e = "😏️️" f = :symbol ```
**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) Inspect ¶
func (s *StringObject) Inspect() string
Inspect wraps ToString with double quotes
func (*StringObject) ToJSON ¶ added in v0.1.11
func (s *StringObject) ToJSON(t *Thread) string
ToJSON just delegates to ToString
func (*StringObject) ToString ¶ added in v0.1.11
func (s *StringObject) ToString() string
ToString returns the object's name as the string format
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) BlockGiven ¶ added in v0.1.11
BlockGiven returns whethe or not we have a block frame below us in the stack
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
VM represents a stack based virtual machine.
func InitIssueReportVM ¶ added in v0.1.3
InitIssueReportVM initializes a vm in test mode for issue reporting
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 ¶
GetExecResult returns stack's top most value. Normally it's used in tests.
func (*VM) GetREPLResult ¶ added in v0.0.9
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
InitErrorObject initializes and returns Error object
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
InitHashObject creates a HashObject
func (*VM) InitIntegerObject ¶ added in v0.1.10
func (vm *VM) InitIntegerObject(value int) *IntegerObject
InitIntegerObject initializes IntegerObject
func (*VM) InitNoMethodError ¶ added in v0.1.11
InitNoMethodError is to print unsupported method errors. This is exported for using from sub-packages.
func (*VM) InitObjectFromGoType ¶ added in v0.1.10
InitObjectFromGoType creates an object based on Go's type
func (*VM) InitStringObject ¶ added in v0.1.10
func (vm *VM) InitStringObject(value string) *StringObject
InitStringObject creates a 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
func (*VM) TopLevelClass ¶ added in v0.1.11
TopLevelClass returns a specified top-level class (stored under the Object constant)
Source Files ¶
- array.go
- block.go
- boolean.go
- call_frame.go
- call_object.go
- channel.go
- class.go
- concurrent_array.go
- concurrent_hash.go
- concurrent_rw_lock.go
- decimal.go
- diggable.go
- environment.go
- error.go
- file.go
- float.go
- go_map.go
- go_object.go
- hash.go
- http.go
- http_client.go
- inspection_methods.go
- instruction.go
- instruction_translator.go
- integer.go
- issue_vm.go
- json.go
- match_data.go
- method.go
- null.go
- numeric.go
- object.go
- range.go
- regexp.go
- repl.go
- simple_server.go
- spec.go
- stack.go
- string.go
- thread.go
- uri.go
- validate.go
- vm.go