Class: Pure::Compiler::RubyParser
- Inherits:
-
Object
- Object
- Pure::Compiler::RubyParser
- Defined in:
- lib/pure/compiler/ruby_parser.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#compile_function(spec) ⇒ Object
Compiles a function spec extracted by Pure::Parser::RubyParser.
-
#evaluate_function(spec, *args) ⇒ Object
Compiles and evaluates a function spec with arg values.
-
#fun_to_define_method(name, sexp) ⇒ Object
Code-transform ‘fun’ definitions into ‘define_method’ definitions.
-
#initialize ⇒ RubyParser
constructor
A new instance of RubyParser.
Constructor Details
#initialize ⇒ RubyParser
14 15 16 |
# File 'lib/pure/compiler/ruby_parser.rb', line 14 def initialize @ruby2ruby = Ruby2Ruby.new end |
Instance Method Details
#compile_function(spec) ⇒ Object
Compiles a function spec extracted by Pure::Parser::RubyParser.
Returns an object which responds to spec.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pure/compiler/ruby_parser.rb', line 31 def compile_function(spec) sexp = ( if spec[:origin] == :fun fun_to_define_method(spec[:name], spec[:code]) else spec[:code] end ) instance = Names.new(spec[:name], spec[:args]) Thread.current[:pure_compiler_input] = @ruby2ruby.process(sexp) # use singleton to hide locals class << instance eval(Thread.current[:pure_compiler_input]) end instance end |
#evaluate_function(spec, *args) ⇒ Object
Compiles and evaluates a function spec with arg values.
21 22 23 |
# File 'lib/pure/compiler/ruby_parser.rb', line 21 def evaluate_function(spec, *args) compile_function(spec).send(spec[:name], *args) end |
#fun_to_define_method(name, sexp) ⇒ Object
Code-transform ‘fun’ definitions into ‘define_method’ definitions.
54 55 56 57 58 59 60 |
# File 'lib/pure/compiler/ruby_parser.rb', line 54 def fun_to_define_method(name, sexp) s(:iter, s(:call, nil, :define_method, s(:arglist, s(:lit, name.to_sym))), sexp[2], sexp[3] ) end |