2018-07-09 15:48:23 +02:00
|
|
|
module Risc
|
|
|
|
|
2019-09-28 16:24:10 +02:00
|
|
|
# A BlockCompiler is much like a MethodCompiler, exept for it's for blocks
|
2020-02-26 18:01:01 +01:00
|
|
|
# This only changes scoping for variables, see slot_type
|
|
|
|
# (dynamic resolve, as needed when the block is passed, is not implemented)
|
2018-07-09 15:48:23 +02:00
|
|
|
#
|
2018-07-10 21:03:32 +02:00
|
|
|
class BlockCompiler < CallableCompiler
|
2018-07-09 15:48:23 +02:00
|
|
|
|
2019-08-13 18:32:17 +02:00
|
|
|
attr_reader :block , :risc_instructions , :constants , :in_method
|
2018-07-09 15:48:23 +02:00
|
|
|
|
2019-10-03 19:55:41 +02:00
|
|
|
def initialize( block , in_method , slot_label)
|
2019-08-13 18:32:17 +02:00
|
|
|
@in_method = in_method
|
2019-10-03 19:55:41 +02:00
|
|
|
super(block , slot_label)
|
2018-07-10 21:03:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def source_name
|
2019-08-13 18:32:17 +02:00
|
|
|
"#{@in_method.self_type.name}.init"
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
|
|
|
|
2018-07-17 09:37:33 +02:00
|
|
|
# resolve the type of the slot, by inferring from it's name, using the type
|
|
|
|
# scope related slots are resolved by the compiler by method/block
|
|
|
|
#
|
|
|
|
# This mainly calls super, and only for :caller adds extra info
|
|
|
|
# Using the info, means assuming that the block is not passed around (FIXME in 2020)
|
|
|
|
def slot_type( slot , type)
|
|
|
|
new_type = super
|
|
|
|
if slot == :caller
|
2019-08-13 18:32:17 +02:00
|
|
|
extra_info = { type_frame: @in_method.frame_type ,
|
|
|
|
type_arguments: @in_method.arguments_type ,
|
|
|
|
type_self: @in_method.self_type}
|
2018-07-17 09:37:33 +02:00
|
|
|
end
|
|
|
|
return new_type , extra_info
|
|
|
|
end
|
2018-07-09 16:53:56 +02:00
|
|
|
|
2018-07-10 21:03:32 +02:00
|
|
|
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
|
|
|
end
|