Class: Verneuil::Program
- Inherits:
-
Object
- Object
- Verneuil::Program
- Defined in:
- lib/verneuil/program.rb
Overview
A program is a sequence of instructions that can be run inside a process. You can use the compiler (Verneuil::Compiler) to create programs.
Instance Attribute Summary collapse
-
#instructions ⇒ Object
readonly
Gives access to the internal array of instructions (the program memory).
-
#symbols ⇒ Object
readonly
Access to the programs symbol table.
Instance Method Summary collapse
- #==(program) ⇒ Object
-
#[](idx) ⇒ Object
Retrieves instruction at idx.
-
#add(instruction) ⇒ Object
Adds an instruction to the program.
-
#eql?(program) ⇒ Boolean
:nodoc:.
-
#hash ⇒ Object
Make programs behave nicely with respect to comparison.
-
#initialize ⇒ Program
constructor
A new instance of Program.
-
#inspect ⇒ Object
Printing.
-
#size ⇒ Object
Returns the size of the current program.
Constructor Details
#initialize ⇒ Program
Returns a new instance of Program.
13 14 15 16 |
# File 'lib/verneuil/program.rb', line 13 def initialize @instructions = [] @symbols = Verneuil::SymbolTable.new end |
Instance Attribute Details
#instructions ⇒ Object (readonly)
Gives access to the internal array of instructions (the program memory)
9 10 11 |
# File 'lib/verneuil/program.rb', line 9 def instructions @instructions end |
#symbols ⇒ Object (readonly)
Access to the programs symbol table.
11 12 13 |
# File 'lib/verneuil/program.rb', line 11 def symbols @symbols end |
Instance Method Details
#==(program) ⇒ Object
25 26 27 |
# File 'lib/verneuil/program.rb', line 25 def ==(program) instructions == program.instructions end |
#[](idx) ⇒ Object
Retrieves instruction at idx
31 32 33 |
# File 'lib/verneuil/program.rb', line 31 def [](idx) instructions[idx] end |
#add(instruction) ⇒ Object
Adds an instruction to the program. (at the end)
43 44 45 |
# File 'lib/verneuil/program.rb', line 43 def add(instruction) @instructions << instruction end |
#eql?(program) ⇒ Boolean
:nodoc:
22 23 24 |
# File 'lib/verneuil/program.rb', line 22 def eql?(program) # :nodoc: instructions.eql? program.instructions end |
#hash ⇒ Object
Make programs behave nicely with respect to comparison.
19 20 21 |
# File 'lib/verneuil/program.rb', line 19 def hash # :nodoc: instructions.hash end |
#inspect ⇒ Object
Printing
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/verneuil/program.rb', line 49 def inspect s = '' @instructions.each_with_index do |instruction, idx| method_label = '' if entry=symbols.methods.find { |(r,n), m| m.address.ip == idx } m = entry.last method_label = [m.receiver, m.name].inspect end s << sprintf("%20s %04d %s\n", method_label, idx, instruction) end s end |
#size ⇒ Object
Returns the size of the current program
37 38 39 |
# File 'lib/verneuil/program.rb', line 37 def size instructions.size end |