Class: Twostroke::Runtime::VM

Inherits:
Object
  • Object
show all
Defined in:
lib/twostroke/runtime/vm.rb

Defined Under Namespace

Classes: Frame

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bytecode) ⇒ VM

Returns a new instance of VM.



6
7
8
9
10
# File 'lib/twostroke/runtime/vm.rb', line 6

def initialize(bytecode)
  @bytecode = bytecode
  @global_scope = GlobalScope.new self
  @lib = {}
end

Instance Attribute Details

#bytecodeObject

Returns the value of attribute bytecode.



3
4
5
# File 'lib/twostroke/runtime/vm.rb', line 3

def bytecode
  @bytecode
end

#global_scopeObject (readonly)

Returns the value of attribute global_scope.



4
5
6
# File 'lib/twostroke/runtime/vm.rb', line 4

def global_scope
  @global_scope
end

#libObject (readonly)

Returns the value of attribute lib.



4
5
6
# File 'lib/twostroke/runtime/vm.rb', line 4

def lib
  @lib
end

Instance Method Details

#execute(section = :main, scope = nil) ⇒ Object



12
13
14
# File 'lib/twostroke/runtime/vm.rb', line 12

def execute(section = :main, scope = nil)
  Frame.new(self, section).execute scope      
end

#throw_error(type, message) ⇒ Object



16
17
18
# File 'lib/twostroke/runtime/vm.rb', line 16

def throw_error(type, message)
  throw :exception, lib[type].(nil, global_scope.root_object, [Types::String.new(message)])
end