fix name expression
This commit is contained in:
parent
1141ed9c99
commit
f105b1eb3c
@ -7,16 +7,18 @@ module Phisol
|
||||
# whichever way this goes the result is stored in the return slot (as all compiles)
|
||||
def on_name statement
|
||||
name = statement.to_a.first
|
||||
return Virtual::Self.new( @clazz) if name == :self
|
||||
return Register.self_reg(@clazz.name ) if(name == :self)
|
||||
# either an argument, so it's stored in message
|
||||
if( index = @method.has_arg(name))
|
||||
type = @method.arguments[index].type
|
||||
return Virtual::ArgSlot.new(index , type )
|
||||
ret = use_reg @method.arguments[index].type
|
||||
@method.source.add_code Register.get_slot(statement , :message , index , ret )
|
||||
return ret
|
||||
else # or a local so it is in the frame
|
||||
index = @method.has_local( name )
|
||||
if(index)
|
||||
type = @method.locals[index].type
|
||||
return Virtual::FrameSlot.new(index, type )
|
||||
ret = use_reg @method.locals[index].type
|
||||
@method.source.add_code Register.get_slot(statement , :frame , index , ret )
|
||||
return ret
|
||||
end
|
||||
end
|
||||
raise "must define variable #{name} before using it"
|
||||
|
@ -116,7 +116,7 @@ module Register
|
||||
when :new_message
|
||||
register = new_message_reg
|
||||
when :self
|
||||
register = self_reg(:Object) #TODO , prpbably have to get rid of this resolve method
|
||||
register = self_reg(:Object) #TODO , probably have to get rid of this resolve method
|
||||
when :frame
|
||||
register = frame_reg
|
||||
else
|
||||
|
@ -36,7 +36,6 @@ class TestBasic < MiniTest::Test
|
||||
|
||||
def test_self
|
||||
@string_input = 'self '
|
||||
@output = Virtual::Self
|
||||
check
|
||||
end
|
||||
|
||||
|
@ -36,7 +36,7 @@ module Virtual
|
||||
check
|
||||
end
|
||||
|
||||
def ttest_call_main_op
|
||||
def test_call_main_op
|
||||
Virtual.machine.space.get_main.ensure_local(:bar , :Integer)
|
||||
@root = :call_site
|
||||
@string_input = 'main( bar )'
|
||||
|
@ -26,5 +26,21 @@ HERE
|
||||
check
|
||||
end
|
||||
|
||||
def test_local
|
||||
Virtual.machine.space.get_main.ensure_local(:bar , :Integer)
|
||||
@root = :name
|
||||
@string_input = 'bar '
|
||||
@output = Register::RegisterValue
|
||||
check
|
||||
end
|
||||
|
||||
def test_args
|
||||
Virtual.machine.space.get_main.arguments.push Parfait::Variable.new(:Integer , :bar)
|
||||
@root = :name
|
||||
@string_input = 'bar '
|
||||
@output = Register::RegisterValue
|
||||
check
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user