Documentation ¶
Index ¶
- Constants
- type ArrayObject
- type BooleanObject
- type BuiltInMethodObject
- type ChannelObject
- type Error
- type FileObject
- type GoObject
- type HashObject
- type IntegerObject
- type MethodObject
- type NullObject
- type Object
- type PluginObject
- type Pointer
- type RClass
- type RObject
- type RangeObject
- type StringObject
- type VM
- func (vm *VM) ExecInstructions(sets []*bytecode.InstructionSet, fn string)
- func (vm *VM) GetExecResult() Object
- func (vm *VM) GetREPLResult() string
- func (vm *VM) InitForREPL()
- func (vm *VM) REPLExec(sets []*bytecode.InstructionSet)
- func (vm *VM) SetClassISIndexTable(fn filename)
- func (vm *VM) SetMethodISIndexTable(fn filename)
Constants ¶
const ( // InternalError is the default error type InternalError = "InternalError" // ArgumentError is for an argument-related error ArgumentError = "ArgumentError" // NameError is for a constant-related error NameError = "NameError" // TypeError is for a type-related error TypeError = "TypeError" // UndefinedMethodError is for an undefined-method error UndefinedMethodError = "UndefinedMethodError" // UnsupportedMethodError is for an intentionally unsupported-method error UnsupportedMethodError = "UnsupportedMethodError" // ConstantAlreadyInitializedError means user re-declares twice ConstantAlreadyInitializedError = "ConstantAlreadyInitializedError" )
const ( WrongNumberOfArgumentFormat = "Expect %d arguments. got: %d" WrongArgumentTypeFormat = "Expect argument to be %s. got: %s" CantYieldWithoutBlockFormat = "Can't yield without a block" )
Here defines different error message formats for different types of errors
const ( NormalMode int = iota REPLMode TestMode )
These are the enums for marking parser's mode, which decides whether it should pop unused values.
const Version = "0.1.2"
Version stores current Goby version
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayObject ¶
type ArrayObject struct { Elements []Object // contains filtered or unexported fields }
ArrayObject represents 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.
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{}
type BooleanObject ¶
type BooleanObject struct {
// contains filtered or unexported fields
}
BooleanObject represents boolean object in goby. It includes `true` and `FALSE` which represents logically true and false value. - `Boolean.new` is not supported.
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) 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{}
type BuiltInMethodObject ¶ added in v0.0.5
type BuiltInMethodObject struct { Name string Fn func(receiver Object) builtinMethodBody // contains filtered or unexported fields }
BuiltInMethodObject represents methods defined in go.
func (BuiltInMethodObject) Class ¶ added in v0.0.9
func (b BuiltInMethodObject) Class() *RClass
Class will return object's class
func (BuiltInMethodObject) SetSingletonClass ¶ added in v0.1.0
func (b BuiltInMethodObject) SetSingletonClass(c *RClass)
SetSingletonClass sets object's singleton class
func (BuiltInMethodObject) SingletonClass ¶ added in v0.1.0
func (b BuiltInMethodObject) SingletonClass() *RClass
SingletonClass returns object's singleton class
type ChannelObject ¶ added in v0.0.8
type ChannelObject struct { Chan chan int // contains filtered or unexported fields }
ChannelObject represents a goby channel, which carries a golang channel
func (ChannelObject) Class ¶ added in v0.0.8
func (b ChannelObject) Class() *RClass
Class will return object's class
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{}
type Error ¶
type Error struct { Message 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:
* `InternalError`: default error type * `ArgumentError`: an argument-related error * `NameError`: a constant-related error * `TypeError`: a type-related error * `UndefinedMethodError`: undefined-method error * `UnsupportedMethodError`: intentionally unsupported-method error
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
type FileObject ¶ added in v0.0.6
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) 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
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) 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
type HashObject ¶
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) 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{}
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) 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{}
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) 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
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) 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{}
type Object ¶
type Object interface { Class() *RClass SingletonClass() *RClass SetSingletonClass(*RClass) // contains filtered or unexported methods }
Object represents all objects in Goby, including Array, Integer or even Method and Error.
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) 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
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) ReturnName ¶ added in v0.0.9
ReturnName returns the name of the class
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
type RObject ¶
type RObject struct { InitializeMethod *MethodObject // contains filtered or unexported fields }
RObject represents any non built-in class's instance.
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
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) Class ¶ added in v0.0.9
func (b RangeObject) Class() *RClass
Class will return object's class
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
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) 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{}
type VM ¶
VM represents a stack based virtual machine.
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) 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) 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
Source Files ¶
- array.go
- boolean.go
- call_frame.go
- channel.go
- class.go
- db.go
- environment.go
- error.go
- file.go
- go_object.go
- hash.go
- http.go
- inspection_methods.go
- instruction.go
- instruction_translator.go
- integer.go
- json.go
- method.go
- null.go
- object.go
- plugin.go
- plugin_generator.go
- range.go
- repl.go
- simple_server.go
- stack.go
- string.go
- thread.go
- uri.go
- vm.go