fix logic instruction arguments

This commit is contained in:
Torsten Ruger
2014-05-18 12:18:57 +03:00
parent 6abd10f278
commit 2be96dccdc
9 changed files with 69 additions and 61 deletions

View File

@ -67,11 +67,7 @@ module Vm
# sugar to create instructions easily. Any method with one arg is sent to the machine and the result
# (hopefully an instruction) added as code
def method_missing(meth, *args, &block)
if args.length == 2
add_code CMachine.instance.send(meth , *args)
else
super
end
add_code CMachine.instance.send(meth , *args)
end
end

View File

@ -48,7 +48,7 @@ module Vm
define_instruction_one(inst , StackInstruction)
end
[:adc, :add, :and, :bic, :eor, :orr, :rsb, :rsc, :sbc, :sub].each do |inst|
define_instruction_one(inst , LogicInstruction)
define_instruction_three(inst , LogicInstruction)
end
[:mov, :mvn].each do |inst|
define_instruction_one(inst , MoveInstruction)
@ -104,11 +104,22 @@ module Vm
# same for two args (left right, from to etc)
def define_instruction_two(inst , clazz , defaults = {} )
clazz = class_for(clazz)
create_method(inst) do |first ,second , options = nil|
create_method(inst) do |left ,right , options = nil|
options = {} if options == nil
options.merge defaults
options[:opcode] = inst
clazz.new(first , second ,options)
clazz.new(left , right ,options)
end
end
# same for three args (result = left right,)
def define_instruction_three(inst , clazz , defaults = {} )
clazz = class_for(clazz)
create_method(inst) do |result , left ,right , options = nil|
options = {} if options == nil
options.merge defaults
options[:opcode] = inst
clazz.new(result, left , right ,options)
end
end

View File

@ -43,8 +43,10 @@ module Vm
end
end
class LogicInstruction < Instruction
def initialize first , options
@first = first
def initialize result , left , right , options
@result = result
@left = left
@right = right
super(options)
end
end