Class: Verneuil::Generator
- Inherits:
-
Object
- Object
- Verneuil::Generator
- Defined in:
- lib/verneuil/generator.rb
Overview
A generator for VM code.
Instance Attribute Summary collapse
-
#program ⇒ Object
readonly
Returns the instruction stream as has been assembled to this moment.
Instance Method Summary collapse
-
#abs_adr(ip) ⇒ Object
Returns an address that points at the location given by
ip
. -
#add_instruction(*parts) ⇒ Object
Adds an instruction to the current stream.
-
#current_adr ⇒ Object
Returns an address that points at the current location in the program.
-
#fwd_adr ⇒ Object
Returns an address that hasn’t been fixed to an instruction pointer yet.
-
#initialize ⇒ Generator
constructor
A new instance of Generator.
-
#resolve(adr) ⇒ Object
Resolves an address to the current location.
Constructor Details
Instance Attribute Details
#program ⇒ Object (readonly)
Returns the instruction stream as has been assembled to this moment.
9 10 11 |
# File 'lib/verneuil/generator.rb', line 9 def program @program end |
Instance Method Details
#abs_adr(ip) ⇒ Object
Returns an address that points at the location given by ip
.
29 30 31 |
# File 'lib/verneuil/generator.rb', line 29 def abs_adr(ip) Verneuil::Address.new(ip, self) end |
#add_instruction(*parts) ⇒ Object
Adds an instruction to the current stream.
17 18 19 |
# File 'lib/verneuil/generator.rb', line 17 def add_instruction(*parts) @program.add Verneuil::Instruction.new(*parts) end |
#current_adr ⇒ Object
Returns an address that points at the current location in the program.
35 36 37 |
# File 'lib/verneuil/generator.rb', line 35 def current_adr Verneuil::Address.new(program.size, self) end |
#fwd_adr ⇒ Object
Returns an address that hasn’t been fixed to an instruction pointer yet.
23 24 25 |
# File 'lib/verneuil/generator.rb', line 23 def fwd_adr current_adr end |
#resolve(adr) ⇒ Object
Resolves an address to the current location.
41 42 43 |
# File 'lib/verneuil/generator.rb', line 41 def resolve(adr) adr.ip = program.size end |