2014-07-14 13:29:33 +02:00
|
|
|
require_relative "object"
|
|
|
|
|
2014-06-26 17:39:02 +02:00
|
|
|
module Virtual
|
2015-05-06 07:55:14 +02:00
|
|
|
|
|
|
|
# Instruction is an abstract for all the code of the object-machine.
|
|
|
|
# Derived classes make up the actual functionality of the machine.
|
2014-06-25 01:47:59 +02:00
|
|
|
# All functions on the machine are captured as instances of instructions
|
2014-06-26 17:39:02 +02:00
|
|
|
#
|
2015-05-06 14:15:33 +02:00
|
|
|
# It is actually 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.
|
2015-05-06 07:55:14 +02:00
|
|
|
|
2014-07-14 13:29:33 +02:00
|
|
|
class Instruction < Virtual::Object
|
2014-08-13 10:59:51 +02:00
|
|
|
|
2014-08-14 16:40:56 +02:00
|
|
|
# simple thought: don't recurse for Blocks, just check their names
|
2014-07-17 23:29:45 +02:00
|
|
|
def == other
|
2015-05-06 07:55:14 +02:00
|
|
|
return false unless other.class == self.class
|
2014-08-19 22:03:39 +02:00
|
|
|
Sof::Util.attributes(self).each do |a|
|
|
|
|
begin
|
|
|
|
left = send(a)
|
|
|
|
rescue NoMethodError
|
|
|
|
next # not using instance variables that are not defined as attr_readers for equality
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
right = other.send(a)
|
|
|
|
rescue NoMethodError
|
|
|
|
return false
|
|
|
|
end
|
2015-05-06 07:55:14 +02:00
|
|
|
return false unless left.class == right.class
|
2014-08-13 10:59:51 +02:00
|
|
|
if( left.is_a? Block)
|
2014-07-17 23:29:45 +02:00
|
|
|
return false unless left.name == right.name
|
|
|
|
else
|
|
|
|
return false unless left == right
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
2014-06-25 01:47:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2014-10-03 09:25:10 +02:00
|
|
|
|
2015-05-06 07:55:14 +02:00
|
|
|
require_relative "instructions/branch"
|
|
|
|
require_relative "instructions/halt"
|
|
|
|
require_relative "instructions/instance_get"
|
|
|
|
require_relative "instructions/message_send"
|
|
|
|
require_relative "instructions/method_call"
|
|
|
|
require_relative "instructions/method_enter"
|
|
|
|
require_relative "instructions/method_return"
|
|
|
|
require_relative "instructions/new_frame"
|
|
|
|
require_relative "instructions/new_message"
|
|
|
|
require_relative "instructions/set"
|