Class: Lignite::SimpleAssembler

Inherits:
Object
  • Object
show all
Defined in:
lib/lignite/assembler.rb

Overview

Acts like DirectCommands but instead of executing, assembles them to a RBF file

Instance Method Summary collapse

Constructor Details

#initializeSimpleAssembler

Returns a new instance of SimpleAssembler.



116
117
118
119
120
121
122
# File 'lib/lignite/assembler.rb', line 116

def initialize
  @globals = Variables.new
  @locals = Variables.new
  @declarer = RbfDeclarer::Dummy.new

  @interp = BodyCompiler.new(@globals, @locals, @declarer)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Delegate the ops to the BodyCompiler,



135
136
137
138
139
# File 'lib/lignite/assembler.rb', line 135

def method_missing(name, *args, &block)
  super unless @interp.respond_to?(name)

  @interp.public_send(name, *args, &block)
end

Instance Method Details

#respond_to_missing?(name, _include_private) ⇒ Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/lignite/assembler.rb', line 141

def respond_to_missing?(name, _include_private)
  @interp.respond_to?(name) || super
end

#write(rbf_filename) ⇒ Object



124
125
126
127
128
129
130
131
132
# File 'lib/lignite/assembler.rb', line 124

def write(rbf_filename)
  @interp.object_end
  vmthread = RbfObject.vmthread(body: @interp.bytes, local_bytes: @locals.bytesize)

  asm = Assembler.new
  asm.objects = [vmthread]
  asm.globals = @globals
  asm.write(rbf_filename)
end