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
end
#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>
# wrap the given node with the wappper, so for a div wrapper and a button node
# the result will be <div> <button>whatever was in there</button> <div>
def wrap_node_with node , wrapper
node.replace_with(wrapper) if node.parent
wrapper << node

View File

@ -31,12 +31,12 @@ class ListView < ElementView
# replace the child at index with the given one (second arg)
# The child must be an ElementView , which will be rendered and
# the old node will be replaced in the live dom
def replace_at index , with
def replace_at( index , node)
old = @elements[index]
@children[index] = with
rendered = with.draw
@children[index] = node
rendered = node.draw
@elements[index] = rendered
old.replace_with rendered
old.replace_with(rendered) if old
end
# remove the first child and element (from view)
@ -46,10 +46,10 @@ class ListView < ElementView
# remove both child and element at given position
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 )
element = @elements.delete_at(index)
element.remove
element.remove if element
end
# remove all elements and views, basically resetting the list to empty

View File

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

View File

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