vm

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2017 License: MIT Imports: 22 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// UndefinedMethodError describes the error type in string
	UndefinedMethodError = "UndefinedMethodError"
	// ArgumentError describes the error type in string
	ArgumentError = "ArgumentError"
	// TypeError describes the error type in string
	TypeError = "TypeError"
	// UnsupportedMethodError describes the error type in string
	UnsupportedMethodError = "UnsupportedMethodError"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayObject

type ArrayObject struct {
	Class    *RArray
	Elements []Object
}

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 BaseClass

type BaseClass struct {
	// Name is the class's name
	Name string
	// Methods contains its instances' methods
	Methods *environment
	// ClassMethods contains this class's methods
	ClassMethods *environment

	// Class points to this class's class, which should be ClassClass
	Class *RClass
	// Singleton is a flag marks if this class a singleton class
	Singleton bool
	// contains filtered or unexported fields
}

BaseClass is a embedded struct that contains all the essential fields for a class

func (*BaseClass) ReturnName

func (c *BaseClass) ReturnName() string

ReturnName returns the name of the class

type BooleanObject

type BooleanObject struct {
	Class *RBool
	Value bool
}

BooleanObject represents boolean object in goby. It includes `true` and `FALSE` which represents logically true and false value.

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 {
	Class *RClass
	Chan  chan int
	// contains filtered or unexported fields
}

ChannelObject represents a goby channel, which carries a golang channel

type Class

type Class interface {
	ReturnName() string

	Object
	// contains filtered or unexported methods
}

Class is a built-in class, and also a parent superclass of Goby's built-in classes such as String/Array/Integer. Class class contains common basic class methods for any other built-in/user-defined classes.

**Note**: You can add methods to Class or override methods from Class, but you should avoid except for a final resort:

```ruby class Class

def my_method # adding method
  49
end
def name      # overriding method
  "foo"
end

end puts("string".my_method) # => 49 puts("string".name) # => foo ```

type Error

type Error struct {
	Class   *RClass
	Message string
}

Error ...

type FileObject added in v0.0.6

type FileObject struct {
	Class *RClass
	File  *os.File
}

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

type HashObject

type HashObject struct {
	Class *RHash
	Pairs map[string]Object
}

HashObject represents hash instances

type IntegerObject

type IntegerObject struct {
	Class *RInteger
	Value int
}

IntegerObject represents number objects which can bring into mathematical calculations.

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

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 {
	Class *RNull
}

NullObject represnts the null value in Goby.

var (

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

type Object

type Object interface {
	// 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 RArray

type RArray struct {
	*BaseClass
}

RArray is the built in array class

type RBool

type RBool struct {
	*BaseClass
}

RBool is the built in class of goby's boolean objects.

type RClass

type RClass struct {
	*BaseClass
}

RClass represents normal (not built in) class object

var (
	// UndefinedMethodErrorClass ...
	UndefinedMethodErrorClass *RClass
	// ArgumentErrorClass ...
	ArgumentErrorClass *RClass
	// TypeErrorClass ...
	TypeErrorClass *RClass
	// UnsupportedMethodClass
	UnsupportedMethodClass *RClass
)

type RHash

type RHash struct {
	*BaseClass
}

RHash is the class of hash objects

type RInteger

type RInteger struct {
	*BaseClass
}

RInteger is integer class

type RMethod added in v0.0.5

type RMethod struct {
	*BaseClass
}

RMethod represents all method's class. Currently has no methods.

type RNull

type RNull struct {
	*BaseClass
}

RNull is the built in class of Goby's null objects.

type RObject

type RObject struct {
	Class             *RClass
	InstanceVariables *environment
	InitializeMethod  *MethodObject
}

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

type RString

type RString struct {
	*BaseClass
}

RString is the built in string class

type StringObject

type StringObject struct {
	Class *RString
	Value string
}

StringObject represents string instances

type VM

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

VM represents a stack based virtual machine.

func New

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

New initializes a vm to initialize state and returns it.

func (*VM) ExecBytecodes

func (vm *VM) ExecBytecodes(bytecodes, fn string)

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

Jump to

Keyboard shortcuts

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