2015-07-29 16:26:04 +02:00
|
|
|
# By default Volt generates this controller for your Main component
|
2015-07-29 19:50:39 +02:00
|
|
|
require "salama"
|
2015-07-30 18:23:25 +02:00
|
|
|
require "interpreter/interpreter"
|
2015-07-29 19:50:39 +02:00
|
|
|
|
2015-07-30 09:09:04 +02:00
|
|
|
|
2015-07-29 16:26:04 +02:00
|
|
|
module Main
|
|
|
|
class MainController < Volt::ModelController
|
|
|
|
def index
|
2015-07-29 19:50:39 +02:00
|
|
|
init_machine
|
|
|
|
init_classes
|
2015-07-29 20:05:02 +02:00
|
|
|
init_registers
|
2015-07-30 09:09:04 +02:00
|
|
|
init_blocks
|
2015-07-30 14:05:22 +02:00
|
|
|
init_source
|
2015-07-29 16:26:04 +02:00
|
|
|
end
|
|
|
|
|
2015-07-30 14:05:22 +02:00
|
|
|
def tick
|
|
|
|
@interpreter.tick
|
|
|
|
update_interpreter
|
|
|
|
end
|
|
|
|
def update_interpreter
|
|
|
|
page._interpreter._clock = @interpreter.clock
|
|
|
|
page._interpreter._state = @interpreter.state
|
|
|
|
page._interpreter._stdout = @interpreter.stdout
|
|
|
|
page._interpreter._link = @interpreter.link.to_s
|
|
|
|
page._method_name = method_name
|
|
|
|
page._block_name = @interpreter.block ? @interpreter.block.name : " "
|
|
|
|
end
|
2015-07-29 16:26:04 +02:00
|
|
|
private
|
2015-07-30 13:00:49 +02:00
|
|
|
def marker var
|
|
|
|
return "W" if var.is_a? String
|
|
|
|
var.class.name.split("::").last[0]
|
|
|
|
end
|
2015-07-30 14:05:22 +02:00
|
|
|
def method_name
|
|
|
|
bl = @interpreter.block
|
|
|
|
return " " unless bl
|
|
|
|
return bl.method if bl.method.is_a? String
|
|
|
|
"#{bl.method.for_class.name}.#{bl.method.name}"
|
|
|
|
end
|
|
|
|
|
2015-07-29 19:50:39 +02:00
|
|
|
def init_machine
|
|
|
|
machine = Virtual.machine.boot
|
|
|
|
code = Ast::ExpressionList.new( [Ast::CallSiteExpression.new(:putstring, [] ,Ast::StringExpression.new("Hello again"))])
|
|
|
|
Virtual::Compiler.compile( code , machine.space.get_main )
|
2015-07-30 09:27:27 +02:00
|
|
|
machine.run_before "Register::CallImplementation"
|
2015-07-30 18:23:25 +02:00
|
|
|
@interpreter = Interpreter::Interpreter.new
|
2015-07-30 14:05:22 +02:00
|
|
|
page._interpreter = { }
|
|
|
|
update_interpreter
|
2015-07-29 19:50:39 +02:00
|
|
|
@interpreter.start machine.init
|
|
|
|
end
|
2015-07-29 20:05:02 +02:00
|
|
|
def init_registers
|
|
|
|
page._registers!.clear
|
|
|
|
@interpreter.registers.each do |reg , val|
|
2015-07-30 13:00:49 +02:00
|
|
|
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])
|
2015-07-29 20:05:02 +02:00
|
|
|
end
|
|
|
|
end
|
2015-07-29 19:50:39 +02:00
|
|
|
def init_classes
|
|
|
|
page._classes!.clear
|
|
|
|
Virtual.machine.space.classes.each do |name , claz|
|
|
|
|
next if [:Kernel,:Module,:MetaClass,:BinaryCode].index name
|
|
|
|
c = Volt::Model.new :name => name
|
|
|
|
page._classes << c
|
|
|
|
end
|
|
|
|
end
|
2015-07-30 09:09:04 +02:00
|
|
|
def init_blocks
|
|
|
|
blocks = BlocksModel.new
|
|
|
|
page._blocks = blocks
|
|
|
|
@interpreter.register_event(:instruction_changed, blocks)
|
|
|
|
end
|
2015-07-30 14:05:22 +02:00
|
|
|
def init_source
|
|
|
|
sources = SourceModel.new
|
|
|
|
page._sources = sources
|
|
|
|
@interpreter.register_event(:instruction_changed, sources)
|
|
|
|
end
|
2015-07-29 16:26:04 +02:00
|
|
|
# The main template contains a #template binding that shows another
|
|
|
|
# template. This is the path to that template. It may change based
|
|
|
|
# on the params._component, params._controller, and params._action values.
|
|
|
|
def main_path
|
|
|
|
"#{params._component || 'main'}/#{params._controller || 'main'}/#{params._action || 'index'}"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Determine if the current nav component is the active one by looking
|
|
|
|
# at the first part of the url against the href attribute.
|
|
|
|
def active_tab?
|
|
|
|
url.path.split('/')[1] == attrs.href.split('/')[1]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|