named the first intruction constructor argument

This commit is contained in:
Torsten Ruger
2014-05-15 19:41:51 +03:00
parent b4c79d218f
commit a0f0d08e81
13 changed files with 78 additions and 77 deletions

View File

@ -66,7 +66,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 == 1
if args.length == 2
add_code CMachine.instance.send(meth , *args)
else
super

View File

@ -81,11 +81,11 @@ module Vm
# defaults gets merged into the instructions options hash, ie passed on to the (machine specific)
# Instruction constructor and as such can be used to influence that classes behaviour
def define_instruction(inst , clazz , defaults = {} )
create_method(inst) do |options|
create_method(inst) do |left , options|
options = {} if options == nil
options.merge defaults
options[:opcode] = inst
clazz.new(options)
clazz.new(left , options)
end
end

View File

@ -25,7 +25,8 @@ module Vm
# Make hash attributes to object attributes
include Support::HashAttributes
def initialize options
def initialize left , options
@left = left
@attributes = options
end
end
@ -43,7 +44,7 @@ module Vm
class MoveInstruction < Instruction
end
class CallInstruction < Instruction
def initialize options
def initialize left , options
super
opcode = @attributes[:opcode].to_s
if opcode.length == 3 and opcode[0] == "b"