up to, ut not including, creating frames
This commit is contained in:
parent
363fe5e35f
commit
df9d6284ae
@ -1,6 +1,9 @@
|
|||||||
# this is not a "normal" ruby file, ie it is not required by salama
|
# this is not a "normal" ruby file, ie it is not required by salama
|
||||||
# instead it is parsed by salama to define part of the program that runs
|
# instead it is parsed by salama to define part of the program that runs
|
||||||
|
|
||||||
|
class Frame #just for now
|
||||||
|
end
|
||||||
|
|
||||||
class Message
|
class Message
|
||||||
|
|
||||||
def get_type_for(name)
|
def get_type_for(name)
|
||||||
@ -8,7 +11,7 @@ class Message
|
|||||||
get_at(index)
|
get_at(index)
|
||||||
end
|
end
|
||||||
|
|
||||||
def __send__
|
def __send
|
||||||
typ = get_type_for( :receiver )
|
typ = get_type_for( :receiver )
|
||||||
# TODO: this will obviously be recoded as case, once that is done :-)
|
# TODO: this will obviously be recoded as case, once that is done :-)
|
||||||
# depending on value type get method
|
# depending on value type get method
|
||||||
|
@ -164,6 +164,10 @@ module Register
|
|||||||
send("add_#{clazz}".to_sym , object)
|
send("add_#{clazz}".to_sym , object)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_Message m
|
||||||
|
end
|
||||||
|
def add_Frame f
|
||||||
|
end
|
||||||
def add_Array( array )
|
def add_Array( array )
|
||||||
# also array has constant overhead, the padded helper fixes it to multiple of 8
|
# also array has constant overhead, the padded helper fixes it to multiple of 8
|
||||||
array.each do |elem|
|
array.each do |elem|
|
||||||
|
@ -4,11 +4,12 @@ module Register
|
|||||||
def run block
|
def run block
|
||||||
block.codes.dup.each do |code|
|
block.codes.dup.each do |code|
|
||||||
next unless code.is_a? Virtual::MethodEnter
|
next unless code.is_a? Virtual::MethodEnter
|
||||||
|
new_codes = []
|
||||||
# save return register and create a new frame
|
# save return register and create a new frame
|
||||||
to = RegisterReference.new(:r0) # message base
|
# lr is link register, ie where arm stores the return address when call is issued
|
||||||
pc = RegisterReference.new(:pc)
|
new_codes << RegisterMachine.instance.str( :lr , Virtual::Slot::MESSAGE_REGISTER , Virtual::Slot::MESSAGE_RETURN_ADDRESS )
|
||||||
move1 = RegisterMachine.instance.str( pc , to , Virtual::Slot::MESSAGE_RETURN_VALUE )
|
new_codes << Virtual::NewFrame.new
|
||||||
block.replace(code , [move1] )
|
block.replace(code , new_codes )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,17 +14,17 @@ module Virtual
|
|||||||
|
|
||||||
class BootSpace < Virtual::Object
|
class BootSpace < Virtual::Object
|
||||||
|
|
||||||
# Initialize with a string for cpu. Naming conventions are: for Machine XXX there exists a module XXX
|
def initialize
|
||||||
# with a XXXMachine in it that derives from Virtual::RegisterMachine
|
|
||||||
def initialize machine = nil
|
|
||||||
super()
|
super()
|
||||||
@classes = Parfait::Hash.new
|
@classes = Parfait::Hash.new
|
||||||
@main = Virtual::CompiledMethod.new("main" , [] )
|
@main = Virtual::CompiledMethod.new("main" , [] )
|
||||||
#global objects (data)
|
#global objects (data)
|
||||||
@objects = []
|
@objects = []
|
||||||
@symbols = []
|
@symbols = []
|
||||||
@messages = []
|
@messages = 100.times.collect{ ::Message.new }
|
||||||
@frames = []
|
@frames = 100.times.collect{ ::Frame.new }
|
||||||
|
@next_message = @messages.first
|
||||||
|
@next_frame = @frames.first
|
||||||
@passes = [ Virtual::SendImplementation ]
|
@passes = [ Virtual::SendImplementation ]
|
||||||
end
|
end
|
||||||
attr_reader :main , :classes , :objects , :symbols,:messages,:frames
|
attr_reader :main , :classes , :objects , :symbols,:messages,:frames
|
||||||
@ -77,7 +77,7 @@ module Virtual
|
|||||||
obj.add_instance_method Builtin::Object.send(f , @context)
|
obj.add_instance_method Builtin::Object.send(f , @context)
|
||||||
end
|
end
|
||||||
obj = get_or_create_class :Kernel
|
obj = get_or_create_class :Kernel
|
||||||
[:main , :__init__,:putstring,:exit,:__send__].each do |f|
|
[:main , :__init__,:putstring,:exit,:__send].each do |f|
|
||||||
obj.add_instance_method Builtin::Kernel.send(f , @context)
|
obj.add_instance_method Builtin::Kernel.send(f , @context)
|
||||||
end
|
end
|
||||||
obj = get_or_create_class :Integer
|
obj = get_or_create_class :Integer
|
||||||
|
@ -44,6 +44,7 @@ module Virtual
|
|||||||
end
|
end
|
||||||
#
|
#
|
||||||
def compile_get method , name
|
def compile_get method , name
|
||||||
|
raise "CALLED"
|
||||||
if method.has_arg(name)
|
if method.has_arg(name)
|
||||||
method.add_code MessageGet.new(name)
|
method.add_code MessageGet.new(name)
|
||||||
else
|
else
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require_relative "type"
|
require_relative "type"
|
||||||
|
require "parfait/message"
|
||||||
|
|
||||||
module Virtual
|
module Virtual
|
||||||
# our machine is made up of objects, some of which are code, some data
|
# our machine is made up of objects, some of which are code, some data
|
||||||
@ -80,6 +81,22 @@ module Virtual
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
::Message.class_eval do
|
||||||
|
def layout
|
||||||
|
Virtual::Object.layout
|
||||||
|
end
|
||||||
|
def mem_length
|
||||||
|
Virtual::Object.new.padded_words(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
::Frame.class_eval do
|
||||||
|
def layout
|
||||||
|
Virtual::Object.layout
|
||||||
|
end
|
||||||
|
def mem_length
|
||||||
|
Virtual::Object.new.padded_words(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
Parfait::Hash.class_eval do
|
Parfait::Hash.class_eval do
|
||||||
HASH = { :names => [:keys,:values] , :types => [Virtual::Reference,Virtual::Reference]}
|
HASH = { :names => [:keys,:values] , :types => [Virtual::Reference,Virtual::Reference]}
|
||||||
def layout
|
def layout
|
||||||
|
@ -27,7 +27,7 @@ module Virtual
|
|||||||
# note: this is the current view: call internal send, even the method name says else
|
# note: this is the current view: call internal send, even the method name says else
|
||||||
# but send is "special" and accesses the internal method name and resolves.
|
# but send is "special" and accesses the internal method name and resolves.
|
||||||
kernel = Virtual::BootSpace.space.get_or_create_class(:Kernel)
|
kernel = Virtual::BootSpace.space.get_or_create_class(:Kernel)
|
||||||
method = kernel.get_instance_method(:__send__)
|
method = kernel.get_instance_method(:__send)
|
||||||
new_codes << FunctionCall.new( method )
|
new_codes << FunctionCall.new( method )
|
||||||
raise "unimplemented #{code}"
|
raise "unimplemented #{code}"
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user