updating on changed method

This commit is contained in:
Torsten Ruger 2015-11-01 18:11:38 +02:00
parent 752310ab0a
commit d19e89567f

View File

@ -6,7 +6,7 @@ class SourceView < ElementView
end end
def draw def draw
@text = div @text = div(".text")
@ticker = div @ticker = div
@element = div(".source_view") << div("h4.source" , "Class.Method") << @ticker << @text @element = div(".source_view") << div("h4.source" , "Class.Method") << @ticker << @text
@element @element
@ -20,8 +20,16 @@ class SourceView < ElementView
end end
case i.source case i.source
when AST::Node when AST::Node
update_code id = i.source.object_id
@ticker.text = "" text = i.source.type + ":#{id}"
if e = @text.at_css("#i#{id}")
if (old = @text.at_css(".fade_in"))
old.remove_class("fade_in")
end
text += " found"
e.add_class "fade_in"
end
@ticker.text = text
when String when String
@ticker.text = i.source @ticker.text = i.source
else else
@ -33,10 +41,7 @@ class SourceView < ElementView
cl_name , method_name = *@interpreter.instruction.name.split(".") cl_name , method_name = *@interpreter.instruction.name.split(".")
clazz = Register.machine.space.get_class_by_name cl_name clazz = Register.machine.space.get_class_by_name cl_name
method = clazz.get_instance_method( method_name) method = clazz.get_instance_method( method_name)
puts "found method #{method.source.class}" @text.inner_html = ToCode.new.process( method.source )
html = ToCode.new.process( method.source )
puts html
@text.inner_html = html
end end
def update_code def update_code
@ -45,15 +50,19 @@ class SourceView < ElementView
end end
class ToCode < AST::Processor class ToCode < AST::Processor
alias :old_process :process
def process s
return "" unless s
old_process(s)
end
def handler_missing s def handler_missing s
puts "Missing: " + s.type puts "Missing: " + s.type
s.to_sexp
end end
def div statement , html def div statement , html
"<div class='statement #{statement.object_id}'>" + html + "</div>" "<div class='statement' id='i#{statement.object_id}'>" + html + "</div>"
end end
def span statement , html def span statement , html
"<span class='#{statement.object_id}'>" + html + "</span>" "<span class='expression' id='i#{statement.object_id}'>" + html + "</span>"
end end
def on_function statement def on_function statement
return_type , name , parameters, kids , receiver = *statement return_type , name , parameters, kids , receiver = *statement
@ -78,7 +87,7 @@ class ToCode < AST::Processor
type , name , value = *statement type , name , value = *statement
str = span(type, type) + " " + span(name,name) str = span(type, type) + " " + span(name,name)
str += " = #{process(value)}" if value str += " = #{process(value)}" if value
div(s,str) div(statement,str)
end end
def on_return statement def on_return statement
str = "return " + process(statement.first ) str = "return " + process(statement.first )
@ -107,7 +116,7 @@ class ToCode < AST::Processor
end end
def on_assignment statement def on_assignment statement
name , value = *statement name , value = *statement
name = name.to_a.first name = process(name)
v = process(value) v = process(value)
str = name + " = " + v str = name + " = " + v
div(statement,str) div(statement,str)
@ -115,7 +124,7 @@ class ToCode < AST::Processor
def on_call c def on_call c
name , arguments , receiver = *c name , arguments , receiver = *c
ret = process(name) ret = process(name)
ret += process(receiver.first) + "." + ret if receiver ret = process(receiver.first) + "." + ret if receiver
ret += "(" ret += "("
ret += process(arguments).join(",") ret += process(arguments).join(",")
ret += ")" ret += ")"