implement message pseudo variable (like self)

too easy
also simplified some tests
This commit is contained in:
Torsten Ruger 2015-11-08 13:55:38 +02:00
parent 69918c8e88
commit 37564d9c2e
2 changed files with 36 additions and 14 deletions

View File

@ -18,7 +18,7 @@ module Soml
add_code move add_code move
when :message when :message
#message Slot #message Slot
raise "message not yet" value = Register.message_reg
else else
if( index = @method.has_arg(receiver)) #argument if( index = @method.has_arg(receiver)) #argument
value = use_reg @method.arguments[index].type value = use_reg @method.arguments[index].type
@ -31,7 +31,7 @@ module Soml
add_code Register.get_slot(statement , :message , :frame , frame ) add_code Register.get_slot(statement , :message , :frame , frame )
code = Register.get_slot(statement ,frame , Parfait::Frame.get_indexed(index) , value ) code = Register.get_slot(statement ,frame , Parfait::Frame.get_indexed(index) , value )
else else
raise "Variable not defined #{name}" raise "Variable not defined #{receiver}"
end end
end end
end end

View File

@ -7,13 +7,10 @@ module Register
def test_field_frame def test_field_frame
@string_input = <<HERE @string_input = <<HERE
class Fielded
field int one
end
class Object class Object
int main() int main()
Fielded f Message m
return f.one return m.name
end end
end end
HERE HERE
@ -23,16 +20,13 @@ HERE
def test_field_arg def test_field_arg
@string_input = <<HERE @string_input = <<HERE
class Fielded
field int one
end
class Object class Object
int the_one(Fielded f) int get_name(Message main)
return f.one return main.name
end end
int main() int main()
Fielded f Message m
return the_one(f) return get_name(m)
end end
end end
HERE HERE
@ -42,5 +36,33 @@ HERE
FunctionReturn] FunctionReturn]
check check
end end
def test_self_field
@string_input = <<HERE
class Object
int main()
Layout l = self.layout
return 1
end
end
HERE
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot ,
Label, FunctionReturn]
check
end
def test_message_field
@string_input = <<HERE
class Object
int main()
Word name = message.name
return name
end
end
HERE
@expect = [Label, GetSlot, SetSlot, GetSlot, GetSlot, SetSlot, Label ,
FunctionReturn]
check
end
end end
end end