Class: Burn::Generator::Telnet::JitCompiler

Inherits:
Object
  • Object
show all
Includes:
Debug, Fuel::Telnet
Defined in:
lib/burn/generator/telnet/jit_compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Debug

#log

Constructor Details

#initializeJitCompiler

Returns a new instance of JitCompiler.



9
10
11
# File 'lib/burn/generator/telnet/jit_compiler.rb', line 9

def initialize
  @opcodes = Array.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/burn/generator/telnet/jit_compiler.rb', line 22

def method_missing(method_symbol, *args, &block)
  log :method_symbol=>method_symbol, :args=>args, :block=>block
  if method_symbol == :scene then
    # preprocess
    args[0] = "main" if args[0].nil?
    
    # execute dsls
    @opcodes << "##{args[0]}"
    Scene.new(args[0], self).instance_eval(&block)
    @opcodes << "#END"
    
  elsif method_symbol == :declare then
    Declare.new(args[0], self).instance_eval(&block) 
    
  end
end

Instance Attribute Details

#opcodesObject (readonly)

Returns the value of attribute opcodes.



7
8
9
# File 'lib/burn/generator/telnet/jit_compiler.rb', line 7

def opcodes
  @opcodes
end

Instance Method Details

#compile(source) ⇒ Object



17
18
19
20
# File 'lib/burn/generator/telnet/jit_compiler.rb', line 17

def compile(source)
  instance_eval source
  @opcodes
end

#get_contextObject



13
14
15
# File 'lib/burn/generator/telnet/jit_compiler.rb', line 13

def get_context
  self
end