Class: WLang::Compiler::ToRubyCode
- Inherits:
-
Temple::Generator
- Object
- Temple::Generator
- WLang::Compiler::ToRubyCode
- Defined in:
- lib/wlang/compiler/to_ruby_code.rb
Defined Under Namespace
Classes: IdGen
Instance Method Summary collapse
- #call(x) ⇒ Object
- #idgen ⇒ Object
- #myid ⇒ Object
- #on_arg(code) ⇒ Object
- #on_dispatch(meth, *procs) ⇒ Object
- #on_modulo(dialect, fn) ⇒ Object
- #on_proc(code) ⇒ Object
- #on_template(fn) ⇒ Object
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 |
#idgen ⇒ Object
13 14 15 |
# File 'lib/wlang/compiler/to_ruby_code.rb', line 13 def idgen [:idgen] ? [:idgen] : (@idgen ||= IdGen.new) end |
#myid ⇒ Object
17 18 19 |
# File 'lib/wlang/compiler/to_ruby_code.rb', line 17 def myid [: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 |