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.
520 521 522 523 524 525 526 527 |
# File 'lib/wilson.rb', line 520 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
550 551 552 |
# File 'lib/wilson.rb', line 550 def method_missing msg, *args super unless self.instructionFromMessage(msg, *args).assemble end |
Instance Attribute Details
#bits ⇒ Object
Returns the value of attribute bits.
516 517 518 |
# File 'lib/wilson.rb', line 516 def bits @bits end |
#cachedInstructions ⇒ Object
Returns the value of attribute cachedInstructions.
516 517 518 |
# File 'lib/wilson.rb', line 516 def cachedInstructions @cachedInstructions end |
#instructions ⇒ Object
543 544 545 546 547 548 |
# File 'lib/wilson.rb', line 543 def instructions self.cachedInstructions ||= @instructions.select { |e| self.supportsProcessor e.processors } self.cachedInstructions end |
#procedure ⇒ Object
Returns the value of attribute procedure.
516 517 518 |
# File 'lib/wilson.rb', line 516 def procedure @procedure end |
#processors ⇒ Object
Returns the value of attribute processors.
517 518 519 |
# File 'lib/wilson.rb', line 517 def processors @processors end |
#stream ⇒ Object
Returns the value of attribute stream.
516 517 518 |
# File 'lib/wilson.rb', line 516 def stream @stream end |
Instance Method Details
#assemble(instruction) ⇒ Object
566 567 568 569 570 571 |
# File 'lib/wilson.rb', line 566 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
562 563 564 |
# File 'lib/wilson.rb', line 562 def future_label FutureLabel.on self end |
#inspect ⇒ Object
529 530 531 |
# File 'lib/wilson.rb', line 529 def inspect "#{self.class}#{stream.inspect}" end |
#instructionFromMessage(msg, *args) ⇒ Object
554 555 556 |
# File 'lib/wilson.rb', line 554 def instructionFromMessage msg, *args Instruction. self, [msg, *args] end |
#label ⇒ Object
558 559 560 |
# File 'lib/wilson.rb', line 558 def label Label.on_at(self, stream.size) end |
#supportsProcessor(instructionProcessors) ⇒ Object
538 539 540 541 |
# File 'lib/wilson.rb', line 538 def supportsProcessor instructionProcessors # TODO: can still be improved. hashes, caching... something ! (processors & instructionProcessors).empty? end |