Class: Brainfuck::CodeLoader
- Inherits:
-
Rubinius::CodeLoader
- Object
- Rubinius::CodeLoader
- Brainfuck::CodeLoader
- Defined in:
- lib/brainfuck/code_loader.rb
Class Method Summary collapse
- .execute_code(code, binding, from_module, print = Compiler::Print.new) ⇒ Object
-
.execute_file(name, compile_to = nil, print = Compiler::Print.new) ⇒ Object
Takes a .bf file name, compiles it if needed and executes it.
Class Method Details
.execute_code(code, binding, from_module, print = Compiler::Print.new) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/brainfuck/code_loader.rb', line 4 def self.execute_code(code, binding, from_module, print = Compiler::Print.new) cm = Compiler.compile_for_eval(code, binding.variables, "(eval)", 1, print) cm.scope = binding.static_scope.dup cm.name = :__eval__ script = Rubinius::CompiledMethod::Script.new(cm, "(eval)", true) script.eval_binding = binding script.eval_source = code cm.scope.script = script be = Rubinius::BlockEnvironment.new be.under_context(binding.variables, cm) be.from_eval! be.call end |
.execute_file(name, compile_to = nil, print = Compiler::Print.new) ⇒ Object
Takes a .bf file name, compiles it if needed and executes it.
23 24 25 26 27 28 29 |
# File 'lib/brainfuck/code_loader.rb', line 23 def self.execute_file(name, compile_to = nil, print = Compiler::Print.new) cm = Compiler.compile_if_needed(name, compile_to, print) ss = ::Rubinius::StaticScope.new Object code = Object.new ::Rubinius.attach_method(:__run__, cm, ss, code) code.__run__ end |