split compiled_method into method and compiled_method_info
This commit is contained in:
@ -15,28 +15,28 @@ module Virtual
|
||||
def self.compile_integer expression , method
|
||||
int = IntegerConstant.new(expression.value)
|
||||
to = Return.new(Integer , int)
|
||||
method.add_code Set.new( to , int)
|
||||
method.info.add_code Set.new( to , int)
|
||||
to
|
||||
end
|
||||
|
||||
def self.compile_true expression , method
|
||||
value = TrueConstant.new
|
||||
to = Return.new(Reference , value)
|
||||
method.add_code Set.new( to , value )
|
||||
method.info.add_code Set.new( to , value )
|
||||
to
|
||||
end
|
||||
|
||||
def self.compile_false expression , method
|
||||
value = FalseConstant.new
|
||||
to = Return.new(Reference , value)
|
||||
method.add_code Set.new( to , value )
|
||||
method.info.add_code Set.new( to , value )
|
||||
to
|
||||
end
|
||||
|
||||
def self.compile_nil expression , method
|
||||
value = NilConstant.new
|
||||
to = Return.new(Reference , value)
|
||||
method.add_code Set.new( to , value )
|
||||
method.info.add_code Set.new( to , value )
|
||||
to
|
||||
end
|
||||
|
||||
@ -50,9 +50,9 @@ module Virtual
|
||||
if method.has_var(expression.name)
|
||||
# either an argument, so it's stored in message
|
||||
if( index = method.has_arg(name))
|
||||
method.add_code MessageGet.new(name , index)
|
||||
method.info.add_code MessageGet.new(name , index)
|
||||
else # or a local so it is in the frame
|
||||
method.add_code FrameGet.new(name , index)
|
||||
method.info.add_code FrameGet.new(name , index)
|
||||
end
|
||||
else
|
||||
call = Ast::CallSiteExpression.new(expression.name , [] ) #receiver self is implicit
|
||||
@ -65,7 +65,7 @@ module Virtual
|
||||
clazz = Space.space.get_class_by_name name
|
||||
raise "uups #{clazz}.#{name}" unless clazz
|
||||
to = Return.new(Reference , clazz )
|
||||
method.add_code Set.new( to , clazz )
|
||||
method.info.add_code Set.new( to , clazz )
|
||||
to
|
||||
end
|
||||
|
||||
@ -74,7 +74,7 @@ module Virtual
|
||||
value = Virtual.new_word(expression.string)
|
||||
to = Return.new(Reference , value)
|
||||
Machine.instance.space.add_object value
|
||||
method.add_code Set.new( to , value )
|
||||
method.info.add_code Set.new( to , value )
|
||||
to
|
||||
end
|
||||
|
||||
@ -85,16 +85,16 @@ module Virtual
|
||||
raise "oh noo, nil from where #{expression.right.inspect}" unless r
|
||||
index = method.has_arg(name)
|
||||
if index
|
||||
method.add_code Set.new(Return.new , MessageSlot.new(index , r,type , r ))
|
||||
method.info.add_code Set.new(Return.new , MessageSlot.new(index , r,type , r ))
|
||||
else
|
||||
index = method.ensure_local(expression.left.name)
|
||||
method.add_code Set.new(Return.new , FrameSlot.new(index , r.type , r ))
|
||||
method.info.add_code Set.new(Return.new , FrameSlot.new(index , r.type , r ))
|
||||
end
|
||||
r
|
||||
end
|
||||
|
||||
def self.compile_variable expression, method
|
||||
method.add_code InstanceGet.new(expression.name)
|
||||
method.info.add_code InstanceGet.new(expression.name)
|
||||
Return.new( Mystery )
|
||||
end
|
||||
end
|
||||
|
@ -6,9 +6,9 @@ module Virtual
|
||||
|
||||
def self.compile_callsite expession , method
|
||||
me = Compiler.compile( expession.receiver , method )
|
||||
method.add_code NewMessage.new
|
||||
method.add_code Set.new(NewSelf.new(me.type), me)
|
||||
method.add_code Set.new(NewName.new(), Virtual.new_word(expession.name))
|
||||
method.info.add_code NewMessage.new
|
||||
method.info.add_code Set.new(NewSelf.new(me.type), me)
|
||||
method.info.add_code Set.new(NewName.new(), Virtual.new_word(expession.name))
|
||||
compiled_args = []
|
||||
expession.args.each_with_index do |arg , i|
|
||||
#compile in the running method, ie before passing control
|
||||
@ -16,13 +16,13 @@ module Virtual
|
||||
# move the compiled value to it's slot in the new message
|
||||
to = NewMessageSlot.new(i ,val.type , val)
|
||||
# (doing this immediately, not after the loop, so if it's a return it won't get overwritten)
|
||||
method.add_code Set.new(to , val )
|
||||
method.info.add_code Set.new(to , val )
|
||||
compiled_args << to
|
||||
end
|
||||
method.add_code MessageSend.new(expession.name , me , compiled_args) #and pass control
|
||||
method.info.add_code MessageSend.new(expession.name , me , compiled_args) #and pass control
|
||||
# the effect of the method is that the NewMessage Return slot will be filled, return it
|
||||
# (this is what is moved _inside_ above loop for such expressions that are calls (or constants))
|
||||
Return.new( method.return_type )
|
||||
Return.new( method.info.return_type )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -7,7 +7,7 @@ module Virtual
|
||||
p.name
|
||||
end
|
||||
r = expression.receiver ? Compiler.compile(expression.receiver, method ) : Self.new()
|
||||
new_method = CompiledMethod.new(expression.name , args , r )
|
||||
new_method = CompiledMethodInfo.create_method(expression.name , args , r )
|
||||
new_method.class_name = r.is_a?(Parfait::Class) ? r.name : method.class_name
|
||||
clazz = Machine.instance.space.get_class_by_name(new_method.class_name)
|
||||
clazz.add_instance_method new_method
|
||||
|
Reference in New Issue
Block a user