Class: Wilson::MachineCode
Overview
MachineCode is an abstract machine that has subclasses for each concrete machine type that you can write assembly language for. Right now this library only supports X86, so loko at MachineCodeX86 for more details on how to use it.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bits ⇒ Object
Returns the value of attribute bits.
-
#cachedInstructions ⇒ Object
Returns the value of attribute cachedInstructions.
- #instructions ⇒ Object
-
#procedure ⇒ Object
Returns the value of attribute procedure.
-
#processors ⇒ Object
Returns the value of attribute processors.
-
#stream ⇒ Object
Returns the value of attribute stream.
Instance Method Summary collapse
- #assemble(instruction) ⇒ Object
- #future_label ⇒ Object
-
#initialize ⇒ MachineCode
constructor
A new instance of MachineCode.
- #inspect ⇒ Object
- #instructionFromMessage(msg, *args) ⇒ Object
- #label ⇒ Object
- #method_missing(msg, *args) ⇒ Object
- #supportsProcessor(instructionProcessors) ⇒ Object
Constructor Details
#initialize ⇒ MachineCode
Returns a new instance of MachineCode.
592 593 594 595 596 597 598 599 |
# File 'lib/wilson.rb', line 592 def initialize self.procedure = nil self.bits = self.defaultBits self.processors = self.defaultProcessors self.stream = [] self.setupMachine end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(msg, *args) ⇒ Object
620 621 622 |
# File 'lib/wilson.rb', line 620 def method_missing msg, *args super unless self.instructionFromMessage(msg, *args).assemble end |
Instance Attribute Details
#bits ⇒ Object
Returns the value of attribute bits.
588 589 590 |
# File 'lib/wilson.rb', line 588 def bits @bits end |
#cachedInstructions ⇒ Object
Returns the value of attribute cachedInstructions.
588 589 590 |
# File 'lib/wilson.rb', line 588 def cachedInstructions @cachedInstructions end |
#instructions ⇒ Object
614 615 616 617 618 |
# File 'lib/wilson.rb', line 614 def instructions self.cachedInstructions ||= @instructions.select { |e| self.supportsProcessor e.processors } end |
#procedure ⇒ Object
Returns the value of attribute procedure.
588 589 590 |
# File 'lib/wilson.rb', line 588 def procedure @procedure end |
#processors ⇒ Object
Returns the value of attribute processors.
589 590 591 |
# File 'lib/wilson.rb', line 589 def processors @processors end |
#stream ⇒ Object
Returns the value of attribute stream.
588 589 590 |
# File 'lib/wilson.rb', line 588 def stream @stream end |
Instance Method Details
#assemble(instruction) ⇒ Object
636 637 638 639 640 641 |
# File 'lib/wilson.rb', line 636 def assemble instruction raise "no" # aBlock on: MessageNotUnderstood do: [:ex | # ex originator class = BlockClosure ifFalse: [ex pass]. # ex resume: (ex originator value m perform: ex parameter selector withArguments: ex parameter arguments)]</body> end |
#future_label ⇒ Object
632 633 634 |
# File 'lib/wilson.rb', line 632 def future_label FutureLabel.on self end |
#inspect ⇒ Object
601 602 603 |
# File 'lib/wilson.rb', line 601 def inspect "#{self.class}#{stream.inspect}" end |
#instructionFromMessage(msg, *args) ⇒ Object
624 625 626 |
# File 'lib/wilson.rb', line 624 def instructionFromMessage msg, *args Instruction. self, [msg, *args] end |
#label ⇒ Object
628 629 630 |
# File 'lib/wilson.rb', line 628 def label Label.on_at(self, stream.size) end |
#supportsProcessor(instructionProcessors) ⇒ Object
610 611 612 |
# File 'lib/wilson.rb', line 610 def supportsProcessor instructionProcessors processors.any? { |e| instructionProcessors.include? e } end |