2014-07-14 14:29:33 +03:00
|
|
|
require_relative "object"
|
|
|
|
|
2014-06-26 18:39:02 +03:00
|
|
|
module Virtual
|
2014-06-25 02:47:59 +03:00
|
|
|
|
|
|
|
# Instruction is an abstract for all the code of the object-machine. Derived classe make up the actual functionality
|
|
|
|
# of the machine.
|
|
|
|
# All functions on the machine are captured as instances of instructions
|
2014-06-26 18:39:02 +03:00
|
|
|
#
|
|
|
|
# It is actully the point of the virtual machine layer to express oo functionality in the set of instructions, thus
|
|
|
|
# defining a minimal set of instructions needed to implement oo.
|
|
|
|
|
2014-06-29 19:05:35 +03:00
|
|
|
# This is partly because jumping over this layer and doing in straight in assember was too big a step
|
2014-07-14 14:29:33 +03:00
|
|
|
class Instruction < Virtual::Object
|
2014-07-10 17:14:38 +03:00
|
|
|
attr_accessor :next
|
2014-07-14 14:29:33 +03:00
|
|
|
def attributes
|
|
|
|
[:next]
|
2014-07-10 17:14:38 +03:00
|
|
|
end
|
2014-07-14 16:19:47 +03:00
|
|
|
def initialize nex = nil
|
|
|
|
@next = nex
|
|
|
|
end
|
2014-06-25 02:47:59 +03:00
|
|
|
end
|
|
|
|
|
2014-06-29 19:05:35 +03:00
|
|
|
# the first instruction we need is to stop. Off course in a real machine this would be a syscall, but that is just
|
|
|
|
# an implementation (in a programm it would be a function). But in a virtual machine, not only do we need this instruction,
|
|
|
|
# it is indeed the first instruction as just this instruction is the smallest possible programm for the machine.
|
|
|
|
# As such it is the next instruction for any first instruction that we generate.
|
|
|
|
class Halt < Instruction
|
|
|
|
|
|
|
|
end
|
2014-07-10 17:14:38 +03:00
|
|
|
|
|
|
|
# following classes are stubs. currently in brainstorming mode, so anything may change anytime
|
|
|
|
class MethodEnter < Instruction
|
|
|
|
end
|
|
|
|
|
|
|
|
class FrameGet < Instruction
|
2014-07-15 18:27:13 +03:00
|
|
|
def initialize name , nex = nil
|
|
|
|
super(nex)
|
2014-07-10 17:14:38 +03:00
|
|
|
@name = name
|
|
|
|
end
|
2014-07-14 21:28:21 +03:00
|
|
|
attr_reader :name
|
|
|
|
def attributes
|
2014-07-15 18:27:13 +03:00
|
|
|
[:name ] + super
|
2014-07-14 21:28:21 +03:00
|
|
|
end
|
2014-07-10 17:14:38 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
class FrameSend < Instruction
|
2014-07-15 18:27:13 +03:00
|
|
|
def initialize name , args = [] , nex = nil
|
|
|
|
super(nex)
|
2014-07-10 17:14:38 +03:00
|
|
|
@name = name.to_sym
|
2014-07-13 16:00:48 +03:00
|
|
|
@args = args
|
2014-07-10 17:14:38 +03:00
|
|
|
end
|
2014-07-13 16:00:48 +03:00
|
|
|
attr_reader :name , :args
|
2014-07-14 21:28:21 +03:00
|
|
|
def attributes
|
2014-07-15 18:27:13 +03:00
|
|
|
[:name , :args ] + super
|
2014-07-10 17:14:38 +03:00
|
|
|
end
|
2014-07-14 21:28:21 +03:00
|
|
|
end
|
|
|
|
|
2014-07-15 18:27:13 +03:00
|
|
|
class FrameSet < Instruction
|
|
|
|
def initialize name , val , nex = nil
|
|
|
|
super(nex)
|
2014-07-14 21:28:21 +03:00
|
|
|
@name = name.to_sym
|
|
|
|
@value = val
|
|
|
|
end
|
|
|
|
attr_reader :name , :value
|
|
|
|
def attributes
|
2014-07-15 18:27:13 +03:00
|
|
|
[:name , :value] + super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class LoadSelf < Instruction
|
|
|
|
def initialize val , nex = nil
|
|
|
|
super(nex)
|
|
|
|
@value = val
|
|
|
|
end
|
|
|
|
attr_reader :value
|
|
|
|
def attributes
|
|
|
|
[:value] + super
|
2014-07-10 17:14:38 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-14 21:28:21 +03:00
|
|
|
class ObjectGet < Instruction
|
2014-07-15 18:27:13 +03:00
|
|
|
def initialize name , nex = nil
|
|
|
|
super(nex)
|
2014-07-14 21:28:21 +03:00
|
|
|
@name = name
|
|
|
|
end
|
|
|
|
attr_reader :name
|
|
|
|
def attributes
|
2014-07-15 18:27:13 +03:00
|
|
|
[:name] + super
|
2014-07-14 21:28:21 +03:00
|
|
|
end
|
|
|
|
end
|
2014-06-25 02:47:59 +03:00
|
|
|
end
|