67 lines
1.7 KiB
Ruby
67 lines
1.7 KiB
Ruby
|
|
require "opal/parser" # to get eval to work
|
|
require "salama"
|
|
|
|
Virtual::Machine.boot
|
|
|
|
module Main
|
|
class MainController < Volt::ModelController
|
|
|
|
def index
|
|
page._registers!.clear
|
|
page._classes!.clear
|
|
page._objects!.clear
|
|
|
|
fill_regs
|
|
parse_and_fill
|
|
end
|
|
|
|
def about
|
|
|
|
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 )
|
|
begin
|
|
Virtual.machine.run_before Virtual::Machine::FIRST_PASS
|
|
rescue => e
|
|
puts "FILL #{e}"
|
|
end
|
|
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
|
|
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
|
|
# 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
|