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 look 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.
606 607 608 609 610 611 612 613 |
# File 'lib/wilson.rb', line 606 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
634 635 636 |
# File 'lib/wilson.rb', line 634 def method_missing msg, *args super unless self.instructionFromMessage(msg, *args).assemble end |
Instance Attribute Details
#bits ⇒ Object
Returns the value of attribute bits.
602 603 604 |
# File 'lib/wilson.rb', line 602 def bits @bits end |
#cachedInstructions ⇒ Object
Returns the value of attribute cachedInstructions.
602 603 604 |
# File 'lib/wilson.rb', line 602 def cachedInstructions @cachedInstructions end |
#instructions ⇒ Object
628 629 630 631 632 |
# File 'lib/wilson.rb', line 628 def instructions self.cachedInstructions ||= @instructions.select { |e| self.supportsProcessor e.processors } end |
#procedure ⇒ Object
Returns the value of attribute procedure.
602 603 604 |
# File 'lib/wilson.rb', line 602 def procedure @procedure end |
#processors ⇒ Object
Returns the value of attribute processors.
603 604 605 |
# File 'lib/wilson.rb', line 603 def processors @processors end |
#stream ⇒ Object
Returns the value of attribute stream.
602 603 604 |
# File 'lib/wilson.rb', line 602 def stream @stream end |
Instance Method Details
#assemble(instruction) ⇒ Object
650 651 652 653 654 655 |
# File 'lib/wilson.rb', line 650 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
646 647 648 |
# File 'lib/wilson.rb', line 646 def future_label FutureLabel.on self end |
#inspect ⇒ Object
615 616 617 |
# File 'lib/wilson.rb', line 615 def inspect "#{self.class}#{stream.inspect}" end |
#instructionFromMessage(msg, *args) ⇒ Object
638 639 640 |
# File 'lib/wilson.rb', line 638 def instructionFromMessage msg, *args Instruction. self, [msg, *args] end |
#label ⇒ Object
642 643 644 |
# File 'lib/wilson.rb', line 642 def label Label.on_at(self, stream.size) end |
#supportsProcessor(instructionProcessors) ⇒ Object
624 625 626 |
# File 'lib/wilson.rb', line 624 def supportsProcessor instructionProcessors processors.any? { |e| instructionProcessors.include? e } end |