Documentation
¶
Index ¶
- Constants
- type ArrayObject
- type BooleanObject
- type BuiltInMethodObject
- type ChannelObject
- type Error
- type FileObject
- type HashObject
- type IntegerObject
- type MethodObject
- type NullObject
- type Object
- 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" )
const Version = "0.0.9"
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.
type BooleanObject ¶
type BooleanObject struct {
Value bool
// 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 )
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.
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
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
type FileObject ¶ added in v0.0.6
FileObject is a special type that contains file pointer so we can keep track on target file.
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.
type IntegerObject ¶
type IntegerObject struct {
Value int
// 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.
type MethodObject ¶ added in v0.0.5
type MethodObject struct {
Name string
// contains filtered or unexported fields
}
MethodObject represents methods defined using goby.
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 )
type Object ¶
type Object interface {
Class() *RClass
// 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
}
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
// ClassMethods contains this class's methods
ClassMethods *environment
// Singleton is a flag marks if this class a singleton class
Singleton bool
// contains filtered or unexported fields
}
RClass represents normal (not built in) class object
var ( // InternalErrorClass ... InternalErrorClass *RClass // ArgumentErrorClass ... ArgumentErrorClass *RClass // NameErrorClass ... NameErrorClass *RClass // TypeErrorClass ... TypeErrorClass *RClass // UndefinedMethodErrorClass ... UndefinedMethodErrorClass *RClass // UnsupportedMethodClass ... UnsupportedMethodClass *RClass )
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
type RObject ¶
type RObject struct {
InitializeMethod *MethodObject
// contains filtered or unexported fields
}
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 ```
type StringObject ¶
type StringObject struct {
Value string
// 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.
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