diff --git a/app/main/controllers/main_controller.rb b/app/main/controllers/main_controller.rb index 843a0f6..1c17989 100644 --- a/app/main/controllers/main_controller.rb +++ b/app/main/controllers/main_controller.rb @@ -5,6 +5,13 @@ require "interpreter/interpreter" module Main class MainController < Volt::ModelController + + def initialize *args + super(*args) + @volt_app.class.attr_accessor :interpreter + @volt_app.interpreter = Interpreter::Interpreter.new + end + def index init_machine init_classes @@ -24,18 +31,17 @@ module Main code = Ast::ExpressionList.new( [Ast::CallSiteExpression.new(:putstring, [] ,Ast::StringExpression.new("Hello again"))]) Virtual::Compiler.compile( code , machine.space.get_main ) machine.run_before "Register::CallImplementation" - @interpreter = Interpreter::Interpreter.new page._interpreter = { } - @interpreter.start machine.init + @volt_app.interpreter.start machine.init end def init_registers page._registers!.clear - @interpreter.registers.each do |reg , val| + @volt_app.interpreter.registers.each do |reg , val| model = RegisterModel.new( :name => reg , :value => val) page._registers << model - @interpreter.register_event(:register_changed, model) - @interpreter.register_event(:object_changed, model) - model.register_changed( reg , nil , @interpreter.registers[reg]) + @volt_app.interpreter.register_event(:register_changed, model) + @volt_app.interpreter.register_event(:object_changed, model) + model.register_changed( reg , nil , @volt_app.interpreter.registers[reg]) end end def init_classes @@ -49,12 +55,12 @@ module Main def init_blocks blocks = BlocksModel.new page._blocks = blocks - @interpreter.register_event(:instruction_changed, blocks) + @volt_app.interpreter.register_event(:instruction_changed, blocks) end def init_source sources = SourceModel.new page._sources = sources - @interpreter.register_event(:instruction_changed, sources) + @volt_app.interpreter.register_event(:instruction_changed, sources) end # The main template contains a #template binding that shows another # template. This is the path to that template. It may change based diff --git a/app/main/controllers/registers_controller.rb b/app/main/controllers/registers_controller.rb index d73ff0a..13009e9 100644 --- a/app/main/controllers/registers_controller.rb +++ b/app/main/controllers/registers_controller.rb @@ -1,19 +1,20 @@ module Main class RegistersController < Volt::ModelController - def initialize app , context - super(app , context) + def initialize *args + super(*args) self.model = [] - init_registers attrs.interpreter + init_registers end - def init_registers interpreter - interpreter.registers.each do |reg , val| + + def init_registers + @volt_app.interpreter.registers.each do |reg , val| r = RegisterModel.new( :name => reg , :value => val) self.model << r - interpreter.register_event(:register_changed, r) - interpreter.register_event(:object_changed, r) - r.register_changed( reg , nil , interpreter.registers[reg]) + @volt_app.interpreter.register_event(:register_changed, r) + @volt_app.interpreter.register_event(:object_changed, r) + r.register_changed( reg , nil , @volt_app.interpreter.registers[reg]) end end diff --git a/app/main/controllers/status_controller.rb b/app/main/controllers/status_controller.rb index b24db04..57211a0 100644 --- a/app/main/controllers/status_controller.rb +++ b/app/main/controllers/status_controller.rb @@ -1,27 +1,27 @@ module Main class StatusController < Volt::ModelController - def initialize app , context - super(app , context) - @interpreter = attrs.interpreter + + def initialize *args + super(*args) self.model = Volt::Model.new update_interpreter end def tick - @interpreter.tick + @volt_app.interpreter.tick update_interpreter end def update_interpreter - self._clock = @interpreter.clock - self._state = @interpreter.state - self._stdout = @interpreter.stdout - self._link = @interpreter.link.to_s + self._clock = @volt_app.interpreter.clock + self._state = @volt_app.interpreter.state + self._stdout = @volt_app.interpreter.stdout + self._link = @volt_app.interpreter.link.to_s page._method_name = method_name - page._block_name = @interpreter.block ? @interpreter.block.name : " " + page._block_name = @volt_app.interpreter.block ? @volt_app.interpreter.block.name : " " end def method_name - bl = @interpreter.block + bl = @volt_app.interpreter.block return " " unless bl return bl.method if bl.method.is_a? String "#{bl.method.for_class.name}.#{bl.method.name}" diff --git a/app/main/views/main/index.html b/app/main/views/main/index.html index 73679bc..8938bc2 100644 --- a/app/main/views/main/index.html +++ b/app/main/views/main/index.html @@ -35,6 +35,6 @@ {{ end }} - <:status interpreter="{{ @interpreter }}"/> + <:status/> - <:registers interpreter="{{ @interpreter }}"/> + <:registers/>