Class: Wilson::Instruction
Overview
Instruction is an instruction shape that we’re going to match to Commands to find out what we should write in to memory.
Instance Attribute Summary collapse
-
#machine ⇒ Object
Returns the value of attribute machine.
-
#opcode ⇒ Object
Returns the value of attribute opcode.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
Class Method Summary collapse
-
.on_message(machine, message) ⇒ Object
TODO: remove.
Instance Method Summary collapse
- #assemble ⇒ Object
- #first ⇒ Object
-
#initialize(message, machine) ⇒ Instruction
constructor
A new instance of Instruction.
- #second ⇒ Object
- #theAddress ⇒ Object
- #theImmediate ⇒ Object
- #theSecondImmediate ⇒ Object
Constructor Details
#initialize(message, machine) ⇒ Instruction
Returns a new instance of Instruction.
458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/wilson.rb', line 458 def initialize , machine self.machine = machine self.opcode, *self.parameters = self.opcode = opcode.to_s.upcase self.machine = parameters[1].machine unless machine self.parameters.map! { |each| Proc === each ? each.call.m : each } self.parameters.each do |each| each.machine = self.machine if each.operand? end end |
Instance Attribute Details
#machine ⇒ Object
Returns the value of attribute machine.
452 453 454 |
# File 'lib/wilson.rb', line 452 def machine @machine end |
#opcode ⇒ Object
Returns the value of attribute opcode.
452 453 454 |
# File 'lib/wilson.rb', line 452 def opcode @opcode end |
#parameters ⇒ Object
Returns the value of attribute parameters.
452 453 454 |
# File 'lib/wilson.rb', line 452 def parameters @parameters end |
Class Method Details
.on_message(machine, message) ⇒ Object
TODO: remove
454 455 456 |
# File 'lib/wilson.rb', line 454 def self. machine, # TODO: remove self.new , machine end |
Instance Method Details
#assemble ⇒ Object
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'lib/wilson.rb', line 484 def assemble instructions = machine.instructions.select { |command| command.instruction_applies? self } return false if instructions.empty? bytes = instructions.map { |instruction| instruction.assemble self } sorted_bytes = bytes.sort_by {|byte| [byte.size, (byte[0]||0), (byte[1]||0)]} machine.stream.push(*sorted_bytes.first) true end |
#first ⇒ Object
472 473 474 |
# File 'lib/wilson.rb', line 472 def first parameters.first end |
#second ⇒ Object
476 477 478 |
# File 'lib/wilson.rb', line 476 def second parameters.second end |
#theAddress ⇒ Object
480 481 482 |
# File 'lib/wilson.rb', line 480 def theAddress parameters.detect { |e| e.address? } end |
#theImmediate ⇒ Object
504 505 506 |
# File 'lib/wilson.rb', line 504 def theImmediate parameters.reverse.detect { |e| e.immediate_value? } end |
#theSecondImmediate ⇒ Object
500 501 502 |
# File 'lib/wilson.rb', line 500 def theSecondImmediate parameters.detect { |e| e.immediate_value? } end |