update to use s-tree, not soml

This commit is contained in:
Torsten Ruger 2016-12-22 21:18:51 +02:00
parent ba34c510c3
commit 0aafeeeb22
4 changed files with 24 additions and 58 deletions

View File

@ -58,8 +58,8 @@ class ElementView
@element = wrap_node_with @element , wrapper @element = wrap_node_with @element , wrapper
end end
#wrap the given node with the wappper, so for a div wrapper and a button node # wrap the given node with the wappper, so for a div wrapper and a button node
# the result will be <div> <button>hwatever was in there</button> <div> # the result will be <div> <button>whatever was in there</button> <div>
def wrap_node_with node , wrapper def wrap_node_with node , wrapper
node.replace_with(wrapper) if node.parent node.replace_with(wrapper) if node.parent
wrapper << node wrapper << node

View File

@ -31,12 +31,12 @@ class ListView < ElementView
# replace the child at index with the given one (second arg) # replace the child at index with the given one (second arg)
# The child must be an ElementView , which will be rendered and # The child must be an ElementView , which will be rendered and
# the old node will be replaced in the live dom # the old node will be replaced in the live dom
def replace_at index , with def replace_at( index , node)
old = @elements[index] old = @elements[index]
@children[index] = with @children[index] = node
rendered = with.draw rendered = node.draw
@elements[index] = rendered @elements[index] = rendered
old.replace_with rendered old.replace_with(rendered) if old
end end
# remove the first child and element (from view) # remove the first child and element (from view)
@ -46,10 +46,10 @@ class ListView < ElementView
# remove both child and element at given position # remove both child and element at given position
def remove_at index def remove_at index
raise "insex out of bounds #{index} => #{@children.length}" if(index >= @children.length or index < 0) raise "index out of bounds #{index} => #{@children.length}" if(index >= @children.length or index < 0)
@children.delete_at( index ) @children.delete_at( index )
element = @elements.delete_at(index) element = @elements.delete_at(index)
element.remove element.remove if element
end end
# remove all elements and views, basically resetting the list to empty # remove all elements and views, basically resetting the list to empty

View File

@ -7,7 +7,6 @@ require 'browser'
require 'browser/http' require 'browser/http'
require 'native' require 'native'
require "salama" require "salama"
require "salama-reader"
require "ast" require "ast"
require "register/interpreter" require "register/interpreter"
# the base, our own litle framework, allows for child and parent views and handles updates # the base, our own litle framework, allows for child and parent views and handles updates
@ -40,9 +39,8 @@ class MainView < ListView
def initialize def initialize
machine = Register.machine.boot machine = Register.machine.boot
code = s(:statements, s(:class, :Object, s(:derives, nil), code = s(:statements, s(:return, s(:operator_value, :+, s(:int, 5), s(:int, 7))))
s(:statements, s(:class_field, :Integer, :x)))) Typed.compile( code )
Soml.compile( code )
machine.collect machine.collect
@interpreter = Register::Interpreter.new @interpreter = Register::Interpreter.new
super( [SwitchView.new(@interpreter) , super( [SwitchView.new(@interpreter) ,

View File

@ -22,25 +22,14 @@ class SelectView < ElementView
def draw def draw
@element = div("h4", "Code") << (list = div("ul.nav!")) @element = div("h4", "Code") << (list = div("ul.nav!"))
list << (div("li.code_list") << div("a.selected" , "none selected")) list << (div("li.code_list") << div("a.selected" , "none selected"))
get_parfait unless @parfait
get_codes unless @codes get_codes unless @codes
@element << div("br") @element << div("br")
@element << div("br") @element << div("br")
end end
def get_codes def get_codes
promise = Browser::HTTP.get "/codes.json" @codes = ["1", "2"]
promise.then do |response| add_selection
@codes = response.text.split("----")
add_selection
end
end
def get_parfait
promise = Browser::HTTP.get "/parfait.json"
promise.then do |response|
@parfait = decode response.text
end
end end
def add_selection def add_selection
@ -51,44 +40,23 @@ class SelectView < ElementView
code.on("click"){ select(c) } code.on("click"){ select(c) }
list << code list << code
end end
select(@codes.first) Promise.new.then{
select(@codes.first)
}
@element.at_css(".code_list") << list @element.at_css(".code_list") << list
end end
def decode code
begin
val = Kernel.eval(code)
return val
rescue => e
@element.at_css(".selected").text = "error, #{e}"
puts e.backtrace
end
s(:statements, s(:class, :Foo, s(:derives, nil), s(:statements, s(:class_field, :Integer, :x))))
end
def select code def select code
@interpreter.set_state :stopped @interpreter.set_state :stopped
@element.at_css(".selected").text = code @element.at_css(".selected").text = code
promise = Browser::HTTP.get "/#{code}.json" input = s(:statements, s(:return, s(:operator_value, :+, s(:int, 5), s(:int, 7))))
promise.then do |response|
code = decode( response.text) machine = Register.machine.boot
machine = Register.machine.boot #do_clean_compile
@parfait.each do |part| Typed.compile( input )
begin machine.collect
Soml.compile( part )
rescue => e puts "starting"
puts e.backtrace @interpreter.start machine.init
end
end
begin
Soml.compile( code )
rescue => e
puts e.backtrace
raise e
end
machine.collect
puts "starting"
@interpreter.start machine.init
end
end end
end end