rubyx-debugger/lib/views/left_view.rb

83 lines
2.0 KiB
Ruby
Raw Normal View History

require_relative "classes_view"
class LeftView < ListView
2018-04-17 15:43:25 +02:00
def initialize( interpreter )
@interpreter = interpreter
init_space
super([ SelectView.new(interpreter) ,
2018-04-17 15:43:25 +02:00
@space,
ClassesView.new(interpreter) ])
2018-04-17 15:43:25 +02:00
interpreter.register_event(:state_changed, self)
end
def init_space
@space = ObjectView.new( Parfait.object_space , @interpreter , 26)
end
def state_changed( old , new_s )
return unless new_s == :running
init_space
replace_at( 1 , @space )
end
def draw
super(".classes")
end
end
class SelectView < ElementView
def initialize( interpreter )
super
@interpreter = interpreter
@codes = nil
end
def draw
@element = div("h4.select", "Code") << (list = div("ul.nav!"))
list << (div("li.code_list") << div("a.selected" , "none selected"))
selection_codes unless @codes
@element << div("br")
@element << div("br")
end
def selection_codes
@codes = get_codes.keys
list = div "ul"
@codes << @codes.first if @codes.length == 1 #otherwise unselectable
@codes.each do |c|
code = div("li") << div("a" , c )
code.style["z-index"] = 10
code.on("click"){ select(c) }
list << code
end
@element.at_css(".code_list") << list
end
2018-04-03 17:24:57 +02:00
def select( code )
puts "selecting #{code}"
2018-06-22 18:44:50 +02:00
Risc.machine.boot
@interpreter.set_state :stopped
@element.at_css(".selected").text = code
2018-04-03 17:24:57 +02:00
ruby = get_codes[code]
2018-06-22 18:44:50 +02:00
Risc.machine.boot
Vool::VoolCompiler.ruby_to_binary( as_main(ruby) , :interpreter )
@interpreter.start_machine
2018-04-03 17:24:57 +02:00
end
def as_main(statements)
"class Space ;def main(arg) ; #{statements}; end; end"
end
def get_codes
{ while_with_calls: 'a = 0; while( 0 > a); a = 1 + a;end;return a',
set_internal_byte: "return 'Hello'.set_internal_byte(1,75)" ,
called_if: 'if( 10 ); return "then";else;return "else";end' ,
2018-05-15 11:07:52 +02:00
plus: 'return 5 + 7' ,
2018-06-22 18:44:50 +02:00
return: 'return 5' ,
hello_world: "h = 'Hello World'.putstring;return h",
dynamic_call: "a = 150 ; return a.div10",
}
end
end