vm

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2017 License: MIT Imports: 38 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.3"

Version stores current Goby version

Variables

This section is empty.

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

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) Class

func (b ArrayObject) Class() *RClass

Class will return object's 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{}

Value returns the elements from the object

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{}

Value returns the object

type BuiltinMethodObject added in v0.1.3

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.1.3

func (b BuiltinMethodObject) Class() *RClass

Class will return object's class

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

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{}

Value returns the object

type Error

type Error struct {
	Message string
	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:

* `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) Class

func (b Error) Class() *RClass

Class will return object's class

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

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) 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

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
	// 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) 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 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{}

Value returns the object

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{}

Value returns the object

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

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

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) 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

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) 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) Class

func (b StringObject) Class() *RClass

Class will return object's class

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 VM

type VM struct {
	sync.Mutex
	// 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) 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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