move the interpreter to the app

too ugly to drag it around everywhere
This commit is contained in:
Torsten Ruger 2015-07-31 18:32:36 +03:00
parent 1728cc1b25
commit cfc6f09ec1
4 changed files with 35 additions and 28 deletions

View File

@ -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

View File

@ -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

View File

@ -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}"

View File

@ -35,6 +35,6 @@
{{ end }}
</div>
<:status interpreter="{{ @interpreter }}"/>
<:status/>
<:registers interpreter="{{ @interpreter }}"/>
<:registers/>