2015-07-22 15:22:54 +02:00
|
|
|
class SourceView
|
|
|
|
|
|
|
|
include React::Component
|
|
|
|
|
2015-07-27 20:29:41 +02:00
|
|
|
required_param :interpreter
|
2015-07-22 15:22:54 +02:00
|
|
|
|
2015-07-27 11:09:35 +02:00
|
|
|
define_state :sources => []
|
|
|
|
|
2015-07-27 20:29:41 +02:00
|
|
|
before_mount do
|
|
|
|
interpreter.register_event(:instruction_changed, self)
|
|
|
|
instruction_changed nil , interpreter.instruction
|
|
|
|
end
|
|
|
|
|
|
|
|
def instruction_changed old , ins
|
2015-07-28 15:16:09 +02:00
|
|
|
text = ins ? source_text(ins.source) : "exit"
|
2015-07-27 11:09:35 +02:00
|
|
|
return if sources.last == text
|
|
|
|
sources << text
|
|
|
|
sources.shift if sources.length > 5
|
2015-07-27 20:29:41 +02:00
|
|
|
sources! sources
|
2015-07-27 11:09:35 +02:00
|
|
|
end
|
2015-07-27 20:29:41 +02:00
|
|
|
|
2015-07-22 15:22:54 +02:00
|
|
|
def render
|
2015-07-27 20:29:41 +02:00
|
|
|
div.source_view do
|
|
|
|
h4 {"Virtual Machine Instruction"}
|
2015-07-27 11:09:35 +02:00
|
|
|
sources.each do |s|
|
|
|
|
s.br
|
|
|
|
end
|
2015-07-22 15:22:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-27 20:29:41 +02:00
|
|
|
def source_text source
|
2015-07-27 11:09:35 +02:00
|
|
|
if source.is_a? Virtual::Instruction
|
|
|
|
return source.class.name
|
|
|
|
else
|
|
|
|
return "Method: #{source.name}"
|
|
|
|
end
|
|
|
|
end
|
2015-07-22 15:22:54 +02:00
|
|
|
end
|