Class: WLang::Compiler::ToRubyCode

Inherits:
Temple::Generator
  • Object
show all
Defined in:
lib/wlang/compiler/to_ruby_code.rb

Defined Under Namespace

Classes: IdGen

Instance Method Summary collapse

Instance Method Details

#call(x) ⇒ Object



21
22
23
# File 'lib/wlang/compiler/to_ruby_code.rb', line 21

def call(x)
  compile(x)
end

#idgenObject



13
14
15
# File 'lib/wlang/compiler/to_ruby_code.rb', line 13

def idgen
  options[:idgen] ? options[:idgen] : (@idgen ||= IdGen.new)
end

#myidObject



17
18
19
# File 'lib/wlang/compiler/to_ruby_code.rb', line 17

def myid
  options[:myid] || 0
end

#on_arg(code) ⇒ Object



34
35
36
# File 'lib/wlang/compiler/to_ruby_code.rb', line 34

def on_arg(code)
  code.inspect
end

#on_dispatch(meth, *procs) ⇒ Object



29
30
31
32
# File 'lib/wlang/compiler/to_ruby_code.rb', line 29

def on_dispatch(meth, *procs)
  procs = procs.map{|p| call(p)}.join(', ')
  "d#{myid}.#{meth}(b#{myid}, #{procs})"
end

#on_modulo(dialect, fn) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/wlang/compiler/to_ruby_code.rb', line 38

def on_modulo(dialect, fn)
  if fn.first == :arg
    call(fn)
  else
    id   = idgen.next
    code = call(fn)
    "Proc.new{|d#{id},b#{id}| #{code}.call(#{dialect}.new(d#{id}.options, d#{id}.template), b#{id}) }"
  end
end

#on_proc(code) ⇒ Object



48
49
50
51
52
53
# File 'lib/wlang/compiler/to_ruby_code.rb', line 48

def on_proc(code)
  id   = idgen.next
  gen  = ToRubyCode.new(:buffer => "b#{id}", :idgen => idgen, :myid => id)
  code = gen.call(code)
  "Proc.new{|d#{id},b#{id}| #{code} }"
end

#on_template(fn) ⇒ Object



25
26
27
# File 'lib/wlang/compiler/to_ruby_code.rb', line 25

def on_template(fn)
  call(fn)
end