add code options

this time inline (not server generated) into the switch view
This commit is contained in:
Torsten Ruger 2016-12-27 20:31:41 +02:00
parent a6c63f4e57
commit 7be8e040bb
3 changed files with 30 additions and 25 deletions

View File

@ -1,2 +1 @@
Opal.use_gem "salama"
Opal.use_gem "salama-arm"

View File

@ -38,13 +38,7 @@ class MainView < ListView
include AST::Sexp
def initialize
machine = Register.machine.boot
code = s(:statements, s(:call,
s(:name, :set_internal_byte),
s(:arguments, s(:int, 1), s(:int, 104)),
s(:receiver, s(:string, "Hello"))))
Typed.compile( code )
machine.collect
Register.machine.boot
@interpreter = Register::Interpreter.new
super( [SwitchView.new(@interpreter) ,
SourceView.new(@interpreter) ,

View File

@ -22,44 +22,56 @@ class SelectView < ElementView
def draw
@element = div("h4", "Code") << (list = div("ul.nav!"))
list << (div("li.code_list") << div("a.selected" , "none selected"))
get_codes unless @codes
selection_codes unless @codes
@element << div("br")
@element << div("br")
end
def get_codes
@codes = ["set_internal_byte"]
add_selection
end
def add_selection
def selection_codes
@codes = get_codes.keys
list = div "ul"
@codes << @codes.first if @codes.length == 1
@codes << @codes.first if @codes.length == 1 #otherwise unselectable
@codes.each do |c|
code = div("li") << div("a" , c )
code.on("click"){ select(c) }
list << code
end
Promise.new.then{
select(@codes.first)
}
@element.at_css(".code_list") << list
end
def select code
puts "selecting #{code}"
@interpreter.set_state :stopped
@element.at_css(".selected").text = code
input = s(:statements, s(:call,
s(:name, :set_internal_byte),
s(:arguments, s(:int, 1), s(:int, 104)),
s(:receiver, s(:string, "Hello"))))
main , clean = get_codes[code]
machine = Register.machine.boot
#do_clean_compile
Typed.compile( input )
clean_compile(*clean) if clean
Typed.compile( main )
machine.collect
puts "starting"
@interpreter.start machine.init
end
def get_codes
{"set_internal_byte" => [s(:statements, s(:call,
s(:name, :set_internal_byte),
s(:arguments, s(:int, 1), s(:int, 104)),
s(:receiver, s(:string, "Hello")))) , nil ] ,
"called_if" => [s(:statements, s(:call, s(:name, :itest), s(:arguments, s(:int, 20)))) ,
[:Space , :itest , {:n => :Integer} ,
s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:name, :n), s(:int, 12))),
s(:true_statements, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "then")))),
s(:false_statements, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "else"))))))]],
"hello world" => [ s(:statements, s(:return, s(:call, s(:name, :putstring), s(:arguments),
s(:receiver, s(:string, "Hello again\\n"))))),
nil],
}
end
def clean_compile(clazz_name , method_name , args , statements)
compiler = Typed::MethodCompiler.new.create_method(clazz_name,method_name,args ).init_method
compiler.process( Typed.ast_to_code( statements ) )
end
end