add clock and method name
This commit is contained in:
parent
e8a5a20db1
commit
4c4d90385f
@ -8,6 +8,9 @@ class Interpreter
|
|||||||
# current instruction or pc
|
# current instruction or pc
|
||||||
attr_reader :instruction
|
attr_reader :instruction
|
||||||
|
|
||||||
|
# current instruction or pc
|
||||||
|
attr_reader :clock
|
||||||
|
|
||||||
# an (arm style) link register. store the return address to return to
|
# an (arm style) link register. store the return address to return to
|
||||||
attr_reader :link
|
attr_reader :link
|
||||||
|
|
||||||
@ -26,6 +29,7 @@ class Interpreter
|
|||||||
@state = "runnnig"
|
@state = "runnnig"
|
||||||
@stdout = ""
|
@stdout = ""
|
||||||
@registers = {}
|
@registers = {}
|
||||||
|
@clock = 0
|
||||||
(0...16).each do |r|
|
(0...16).each do |r|
|
||||||
set_register "r#{r}".to_sym , "r#{r}:unknown"
|
set_register "r#{r}".to_sym , "r#{r}:unknown"
|
||||||
end
|
end
|
||||||
@ -68,6 +72,7 @@ class Interpreter
|
|||||||
|
|
||||||
def tick
|
def tick
|
||||||
return unless @instruction
|
return unless @instruction
|
||||||
|
@clock += 1
|
||||||
name = @instruction.class.name.split("::").last
|
name = @instruction.class.name.split("::").last
|
||||||
fetch = send "execute_#{name}"
|
fetch = send "execute_#{name}"
|
||||||
return unless fetch
|
return unless fetch
|
||||||
@ -136,6 +141,7 @@ class Interpreter
|
|||||||
raise "save return has nothing to save" unless @link
|
raise "save return has nothing to save" unless @link
|
||||||
trigger(:object_changed, @instruction.register )
|
trigger(:object_changed, @instruction.register )
|
||||||
object.internal_object_set @instruction.index , @link
|
object.internal_object_set @instruction.index , @link
|
||||||
|
@link = nil
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -157,9 +163,9 @@ class Interpreter
|
|||||||
|
|
||||||
def execute_FunctionReturn
|
def execute_FunctionReturn
|
||||||
object = object_for( @instruction.register )
|
object = object_for( @instruction.register )
|
||||||
#wouldn't need to assign to link, but makes tsting easier
|
#wouldn't need to assign to link, but makes testing easier
|
||||||
@link = object.internal_object_get( @instruction.index )
|
link = object.internal_object_get( @instruction.index )
|
||||||
@block , @instruction = @link
|
@block , @instruction = link
|
||||||
# we jump back to the call instruction. so it is as if the call never happened and we continue
|
# we jump back to the call instruction. so it is as if the call never happened and we continue
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
@ -10,19 +10,41 @@ module Main
|
|||||||
init_classes
|
init_classes
|
||||||
init_registers
|
init_registers
|
||||||
init_blocks
|
init_blocks
|
||||||
|
init_source
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tick
|
||||||
|
@interpreter.tick
|
||||||
|
update_interpreter
|
||||||
|
end
|
||||||
|
def update_interpreter
|
||||||
|
page._interpreter._clock = @interpreter.clock
|
||||||
|
page._interpreter._state = @interpreter.state
|
||||||
|
page._interpreter._stdout = @interpreter.stdout
|
||||||
|
page._interpreter._link = @interpreter.link.to_s
|
||||||
|
page._method_name = method_name
|
||||||
|
page._block_name = @interpreter.block ? @interpreter.block.name : " "
|
||||||
|
end
|
||||||
private
|
private
|
||||||
def marker var
|
def marker var
|
||||||
return "W" if var.is_a? String
|
return "W" if var.is_a? String
|
||||||
var.class.name.split("::").last[0]
|
var.class.name.split("::").last[0]
|
||||||
end
|
end
|
||||||
|
def method_name
|
||||||
|
bl = @interpreter.block
|
||||||
|
return " " unless bl
|
||||||
|
return bl.method if bl.method.is_a? String
|
||||||
|
"#{bl.method.for_class.name}.#{bl.method.name}"
|
||||||
|
end
|
||||||
|
|
||||||
def init_machine
|
def init_machine
|
||||||
machine = Virtual.machine.boot
|
machine = Virtual.machine.boot
|
||||||
code = Ast::ExpressionList.new( [Ast::CallSiteExpression.new(:putstring, [] ,Ast::StringExpression.new("Hello again"))])
|
code = Ast::ExpressionList.new( [Ast::CallSiteExpression.new(:putstring, [] ,Ast::StringExpression.new("Hello again"))])
|
||||||
Virtual::Compiler.compile( code , machine.space.get_main )
|
Virtual::Compiler.compile( code , machine.space.get_main )
|
||||||
machine.run_before "Register::CallImplementation"
|
machine.run_before "Register::CallImplementation"
|
||||||
@interpreter = Interpreter.new
|
@interpreter = Interpreter.new
|
||||||
|
page._interpreter = { }
|
||||||
|
update_interpreter
|
||||||
@interpreter.start machine.init
|
@interpreter.start machine.init
|
||||||
end
|
end
|
||||||
def init_registers
|
def init_registers
|
||||||
@ -48,6 +70,11 @@ module Main
|
|||||||
page._blocks = blocks
|
page._blocks = blocks
|
||||||
@interpreter.register_event(:instruction_changed, blocks)
|
@interpreter.register_event(:instruction_changed, blocks)
|
||||||
end
|
end
|
||||||
|
def init_source
|
||||||
|
sources = SourceModel.new
|
||||||
|
page._sources = sources
|
||||||
|
@interpreter.register_event(:instruction_changed, sources)
|
||||||
|
end
|
||||||
# The main template contains a #template binding that shows another
|
# The main template contains a #template binding that shows another
|
||||||
# template. This is the path to that template. It may change based
|
# template. This is the path to that template. It may change based
|
||||||
# on the params._component, params._controller, and params._action values.
|
# on the params._component, params._controller, and params._action values.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user