Module: Atomy::Compiler
- Defined in:
- lib/atomy/compiler.rb
Class Method Summary collapse
- .compile(node, mod, state = LocalState.new) ⇒ Object
- .construct_block(code, binding) ⇒ Object
- .generate(file, line = 0, state = LocalState.new) {|gen| ... } ⇒ Object
- .package(file, line = 0, state = LocalState.new, &blk) ⇒ Object
Class Method Details
.compile(node, mod, state = LocalState.new) ⇒ Object
8 9 10 11 12 |
# File 'lib/atomy/compiler.rb', line 8 def compile(node, mod, state = LocalState.new) package(mod.file, 0, state) do |gen| mod.compile(gen, node) end end |
.construct_block(code, binding) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/atomy/compiler.rb', line 45 def construct_block(code, binding) code = code.dup code.scope = binding.lexical_scope code.name = binding.variables.method.name code.scope.script = Rubinius::CompiledCode::Script.new(code, code.file.to_s, true) block = Rubinius::BlockEnvironment.new block.under_context(binding.variables, code) block end |
.generate(file, line = 0, state = LocalState.new) {|gen| ... } ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/atomy/compiler.rb', line 24 def generate(file, line = 0, state = LocalState.new) gen = CodeTools::Generator.new gen.file = file gen.set_line(line) gen.push_state(state) yield gen gen.ret gen.close gen.local_count = gen.state.scope.local_count gen.local_names = gen.state.scope.local_names gen.encode gen end |
.package(file, line = 0, state = LocalState.new, &blk) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/atomy/compiler.rb', line 14 def package(file, line = 0, state = LocalState.new, &blk) generate(file, line, state, &blk).package(Rubinius::CompiledCode).tap do |code| if ENV["DEBUG"] printer = CodeTools::Compiler::MethodPrinter.new printer.bytecode = true printer.print_method(code) end end end |