rubyx-debugger/lib/main_view.rb
2015-08-20 19:40:47 +02:00

67 lines
1.7 KiB
Ruby

require 'browser'
require 'native'
require "salama"
require "interpreter/interpreter"
require "list_view"
require_relative "class_view"
#require_relative "registers_view"
#require_relative "object_view"
#require_relative "space_view"
class MainView < ListView
def initialize
machine = Virtual.machine.boot
# compile_main includes the parse
# parsing generates an ast as seen below and then compiles it.
# machine.compile_main "2 + 5"
# so the code above is functionally equivalent to the one below, minus the parse
# When the ast expression is given all works, so pretty sure it is the parse that fails
code = Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(2),Ast::IntegerExpression.new(5))
Virtual::Compiler.compile( code , machine.space.get_main )
machine.run_before "Register::CallImplementation"
@interpreter = Interpreter::Interpreter.new
super( [ClassView.new(@interpreter)] )
end
def draww
node = DOM { |m|
Kernel.puts "DOM #{self.class}"
m.div.info {
Kernel.puts "div #{self.class}" ; ""
m.span.red @interpreter.state
}
}
node.append_to(@parent)
end
def no
body = Native(`window.document.body`)
# bit of a hack as it assumes index's structure
html_con = body.firstElementChild
html_con.insertBefore renderer.view , html_con.lastElementChild
registers = RegisterView.new(height - 150)
@canvas.add_child registers
space = SpaceView.new
@container.add_child space
animate = Proc.new do
`requestAnimationFrame(animate)`
registers.draw_me
space.draw_me
renderer.render @container
end
animate.call
end
end