Class: Verneuil::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/verneuil/generator.rb

Overview

A generator for VM code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGenerator

Returns a new instance of Generator.



11
12
13
# File 'lib/verneuil/generator.rb', line 11

def initialize
  @program = Verneuil::Program.new
end

Instance Attribute Details

#programObject (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_adrObject

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_adrObject

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