2015-10-23 13:22:55 +02:00
|
|
|
module Soml
|
2015-09-19 17:56:18 +02:00
|
|
|
Compiler.class_eval do
|
2015-09-19 15:28:41 +02:00
|
|
|
|
|
|
|
# attr_reader :name
|
2016-03-07 10:55:28 +01:00
|
|
|
# compiling name needs to check if it's a local variable
|
|
|
|
# or an argument
|
2015-09-19 15:28:41 +02:00
|
|
|
# whichever way this goes the result is stored in the return slot (as all compiles)
|
2016-03-07 10:55:28 +01:00
|
|
|
def on_NameExpression statement
|
|
|
|
name = statement.name
|
2015-10-18 16:20:19 +02:00
|
|
|
if( name == :self)
|
|
|
|
ret = use_reg @clazz.name
|
2015-10-23 13:08:12 +02:00
|
|
|
add_code Register.get_slot(statement , :message , :receiver , ret )
|
2015-10-18 16:20:19 +02:00
|
|
|
return ret
|
|
|
|
end
|
2015-11-07 11:19:04 +01:00
|
|
|
if(name == :space)
|
|
|
|
space = Parfait::Space.object_space
|
|
|
|
reg = use_reg :Space , space
|
|
|
|
add_code Register::LoadConstant.new( statement, space , reg )
|
|
|
|
return reg
|
|
|
|
end
|
2015-11-09 22:29:14 +01:00
|
|
|
if(name == :message)
|
|
|
|
reg = use_reg :Message
|
|
|
|
add_code Register::RegisterTransfer.new( statement, Register.message_reg , reg )
|
|
|
|
return reg
|
|
|
|
end
|
2015-09-19 15:28:41 +02:00
|
|
|
# either an argument, so it's stored in message
|
2015-10-05 23:27:13 +02:00
|
|
|
if( index = @method.has_arg(name))
|
2016-02-25 20:41:03 +01:00
|
|
|
ret = use_reg @method.arguments[index].value_type
|
2015-10-27 15:05:50 +01:00
|
|
|
add_code Register.get_slot(statement , :message , Parfait::Message.get_indexed(index), ret )
|
2015-10-14 20:34:18 +02:00
|
|
|
return ret
|
2015-09-19 15:28:41 +02:00
|
|
|
else # or a local so it is in the frame
|
2015-10-05 23:27:13 +02:00
|
|
|
index = @method.has_local( name )
|
2015-09-27 15:06:48 +02:00
|
|
|
if(index)
|
2015-10-18 16:20:19 +02:00
|
|
|
frame = use_reg :Frame
|
2015-10-23 13:08:12 +02:00
|
|
|
add_code Register.get_slot(statement , :message , :frame , frame )
|
2016-02-25 20:41:03 +01:00
|
|
|
ret = use_reg @method.locals[index].value_type
|
2015-10-27 15:05:50 +01:00
|
|
|
add_code Register.get_slot(statement , frame , Parfait::Frame.get_indexed(index), ret )
|
2015-10-14 20:34:18 +02:00
|
|
|
return ret
|
2015-09-27 15:06:48 +02:00
|
|
|
end
|
2015-09-19 15:28:41 +02:00
|
|
|
end
|
2015-11-11 19:41:02 +01:00
|
|
|
raise "must define variable '#{name}' before using it"
|
2015-09-19 15:28:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end #module
|
|
|
|
end
|