2015-10-21 13:04:42 +02:00
|
|
|
require_relative "classes_view"
|
|
|
|
|
2018-04-07 18:44:47 +02:00
|
|
|
class LeftView < ListView
|
2018-04-17 15:43:25 +02:00
|
|
|
def initialize( interpreter )
|
|
|
|
@interpreter = interpreter
|
|
|
|
init_space
|
2018-04-07 18:44:47 +02:00
|
|
|
super([ SelectView.new(interpreter) ,
|
2018-04-17 15:43:25 +02:00
|
|
|
@space,
|
2018-04-07 18:44:47 +02:00
|
|
|
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 )
|
2015-10-21 13:04:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def draw
|
|
|
|
super(".classes")
|
|
|
|
end
|
|
|
|
end
|
2018-04-07 18:44:47 +02:00
|
|
|
|
2015-10-21 13:04:42 +02:00
|
|
|
|
|
|
|
class SelectView < ElementView
|
2015-10-27 11:47:17 +01:00
|
|
|
|
2018-04-18 16:54:58 +02:00
|
|
|
def initialize( interpreter )
|
|
|
|
super
|
2015-10-21 13:04:42 +02:00
|
|
|
@interpreter = interpreter
|
|
|
|
@codes = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def draw
|
2018-04-18 16:54:58 +02:00
|
|
|
@element = div("h4.select", "Code") << (list = div("ul.nav!"))
|
2015-10-21 13:04:42 +02:00
|
|
|
list << (div("li.code_list") << div("a.selected" , "none selected"))
|
2016-12-27 19:31:41 +01:00
|
|
|
selection_codes unless @codes
|
2015-10-21 13:04:42 +02:00
|
|
|
@element << div("br")
|
|
|
|
@element << div("br")
|
|
|
|
end
|
|
|
|
|
2016-12-27 19:31:41 +01:00
|
|
|
def selection_codes
|
|
|
|
@codes = get_codes.keys
|
2015-10-21 13:04:42 +02:00
|
|
|
list = div "ul"
|
2016-12-27 19:31:41 +01:00
|
|
|
@codes << @codes.first if @codes.length == 1 #otherwise unselectable
|
2015-10-21 13:04:42 +02:00
|
|
|
@codes.each do |c|
|
|
|
|
code = div("li") << div("a" , c )
|
2018-04-18 16:54:58 +02:00
|
|
|
code.style["z-index"] = 10
|
2015-10-21 13:04:42 +02:00
|
|
|
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 )
|
2016-12-27 19:31:41 +01:00
|
|
|
puts "selecting #{code}"
|
2018-04-03 17:24:57 +02:00
|
|
|
machine = Risc.machine.boot
|
2015-10-21 13:04:42 +02:00
|
|
|
@interpreter.set_state :stopped
|
|
|
|
@element.at_css(".selected").text = code
|
2018-04-03 17:24:57 +02:00
|
|
|
ruby = get_codes[code]
|
|
|
|
Vool::VoolCompiler.ruby_to_vool( as_main(ruby) )
|
|
|
|
machine.objects
|
|
|
|
@interpreter.start machine.risc_init
|
|
|
|
end
|
|
|
|
def as_main(statements)
|
|
|
|
"class Space ;def main(arg) ; #{statements}; end; end"
|
2015-10-21 13:04:42 +02:00
|
|
|
end
|
2016-12-27 19:31:41 +01:00
|
|
|
def get_codes
|
2018-04-20 18:40:17 +02:00
|
|
|
{ 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' ,
|
|
|
|
hello_world: "h = 'Hello World'.putstring;return h",
|
|
|
|
dynamic_call: "a = 150 ; return a.div10",
|
|
|
|
}
|
2016-12-27 19:31:41 +01:00
|
|
|
end
|
|
|
|
|
2015-10-21 13:04:42 +02:00
|
|
|
end
|