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.
530 531 532 533 534 535 536 537 538 539 540 541 542 |
# File 'lib/wilson.rb', line 530 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.
524 525 526 |
# File 'lib/wilson.rb', line 524 def machine @machine end |
#opcode ⇒ Object
Returns the value of attribute opcode.
524 525 526 |
# File 'lib/wilson.rb', line 524 def opcode @opcode end |
#parameters ⇒ Object
Returns the value of attribute parameters.
524 525 526 |
# File 'lib/wilson.rb', line 524 def parameters @parameters end |
Class Method Details
.on_message(machine, message) ⇒ Object
TODO: remove
526 527 528 |
# File 'lib/wilson.rb', line 526 def self. machine, # TODO: remove self.new , machine end |
Instance Method Details
#assemble ⇒ Object
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 |
# File 'lib/wilson.rb', line 556 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
544 545 546 |
# File 'lib/wilson.rb', line 544 def first parameters.first end |
#second ⇒ Object
548 549 550 |
# File 'lib/wilson.rb', line 548 def second parameters.second end |
#theAddress ⇒ Object
552 553 554 |
# File 'lib/wilson.rb', line 552 def theAddress parameters.detect { |e| e.address? } end |
#theImmediate ⇒ Object
576 577 578 |
# File 'lib/wilson.rb', line 576 def theImmediate parameters.reverse.detect { |e| e.immediate_value? } end |
#theSecondImmediate ⇒ Object
572 573 574 |
# File 'lib/wilson.rb', line 572 def theSecondImmediate parameters.detect { |e| e.immediate_value? } end |