rubyx-debugger/app/main/controllers/main_controller.rb

64 lines
1.8 KiB
Ruby
Raw Normal View History

2015-07-06 20:55:34 +02:00
require "opal/parser" # to get eval to work
require "salama"
Virtual::Machine.boot
2015-07-06 13:20:21 +02:00
module Main
class MainController < Volt::ModelController
2015-07-06 21:22:57 +02:00
2015-07-06 13:20:21 +02:00
def index
page._registers!.clear
page._classes!.clear
page._objects!.clear
page._block = BlockModel.new nil
fill_regs
parse_and_fill
2015-07-06 13:20:21 +02:00
end
def about
2015-07-06 13:20:21 +02:00
end
private
def parse_and_fill
ParseTask.parse(1).then do |result|
is = Ast::Expression.from_basic(result)
Virtual::Compiler.compile( is , Virtual.machine.space.get_main )
Virtual.machine.run_before "Register::CallImplementation"
fill_classes
end.fail do |error|
raise "Error: #{error}"
end
end
def fill_classes
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
page._block = BlockModel.new Virtual.machine.init
end
def fill_regs
register_names = (0..8).collect {|i| "r#{i}"}
register_names.each do |reg_name|
reg = Volt::Model.new :name => reg_name
page._registers << reg
end
end
2015-07-06 13:20:21 +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