@@ -81,10 +81,13 @@ public TranslatorEnvironment(
81
81
this .parent = parent ;
82
82
83
83
if (descriptor == null ) {
84
- BlockFrameDescriptorInfo parentDescriptor = blockDepth > 0
85
- ? Objects .requireNonNull (parent .blockFrameDescriptorInfo )
86
- : null ;
87
- this .frameDescriptorBuilder = newFrameDescriptorBuilder (parentDescriptor , blockDepth == 0 );
84
+ if (blockDepth > 0 ) {
85
+ BlockFrameDescriptorInfo parentBlockDescriptor = Objects
86
+ .requireNonNull (parent .blockFrameDescriptorInfo );
87
+ this .frameDescriptorBuilder = newFrameDescriptorBuilderForBlock (parentBlockDescriptor );
88
+ } else {
89
+ this .frameDescriptorBuilder = newFrameDescriptorBuilderForMethod ();
90
+ }
88
91
this .blockFrameDescriptorInfo = new BlockFrameDescriptorInfo ();
89
92
} else {
90
93
this .frameDescriptor = descriptor ;
@@ -143,36 +146,42 @@ public boolean isTopLevelObjectScope() {
143
146
}
144
147
145
148
// region frame descriptor
146
- public static FrameDescriptor .Builder newFrameDescriptorBuilder (BlockFrameDescriptorInfo parentDescriptor ,
147
- boolean canHaveSpecialVariables ) {
148
- if ((parentDescriptor != null ) == canHaveSpecialVariables ) {
149
+ public static FrameDescriptor .Builder newFrameDescriptorBuilderForBlock (BlockFrameDescriptorInfo parentBlockInfo ) {
150
+ if (parentBlockInfo == null ) {
149
151
throw CompilerDirectives .shouldNotReachHere (
150
- "A descriptor should either be a method and have special variables, or be a block and have no special variables " );
152
+ "Frame descriptor for block has to have parent " );
151
153
}
152
154
153
155
var builder = FrameDescriptor .newBuilder ().defaultValue (Nil .INSTANCE );
156
+ builder .info (parentBlockInfo );
154
157
155
- if (parentDescriptor != null ) {
156
- builder .info (parentDescriptor );
157
- } else if (canHaveSpecialVariables ) {
158
- // We need to access this Assumption from the FrameDescriptor,
159
- // and there is no way to get a RootNode from a FrameDescriptor, so we store it in the descriptor info.
160
- // We do not store it as slot info for footprint, to avoid needing an info array per FrameDescriptor.
161
- final Assumption doesNotNeedSpecialVariableStorageAssumption = Assumption
162
- .create (SpecialVariableStorage .ASSUMPTION_NAME );
163
- builder .info (doesNotNeedSpecialVariableStorageAssumption );
158
+ int selfIndex = builder .addSlot (FrameSlotKind .Illegal , SelfNode .SELF_IDENTIFIER , null );
159
+ if (selfIndex != SelfNode .SELF_INDEX ) {
160
+ throw CompilerDirectives .shouldNotReachHere ("(self) should be at index 0" );
164
161
}
165
162
163
+ return builder ;
164
+ }
165
+
166
+ public static FrameDescriptor .Builder newFrameDescriptorBuilderForMethod () {
167
+
168
+ var builder = FrameDescriptor .newBuilder ().defaultValue (Nil .INSTANCE );
169
+ // We need to access this Assumption from the FrameDescriptor,
170
+ // and there is no way to get a RootNode from a FrameDescriptor, so we store it in the descriptor info.
171
+ // We do not store it as slot info for footprint, to avoid needing an info array per FrameDescriptor.
172
+ final Assumption doesNotNeedSpecialVariableStorageAssumption = Assumption
173
+ .create (SpecialVariableStorage .ASSUMPTION_NAME );
174
+ builder .info (doesNotNeedSpecialVariableStorageAssumption );
175
+
176
+
166
177
int selfIndex = builder .addSlot (FrameSlotKind .Illegal , SelfNode .SELF_IDENTIFIER , null );
167
178
if (selfIndex != SelfNode .SELF_INDEX ) {
168
179
throw CompilerDirectives .shouldNotReachHere ("(self) should be at index 0" );
169
180
}
170
181
171
- if (canHaveSpecialVariables ) {
172
- int svarsSlot = builder .addSlot (FrameSlotKind .Illegal , SpecialVariableStorage .SLOT_NAME , null );
173
- if (svarsSlot != SpecialVariableStorage .SLOT_INDEX ) {
174
- throw CompilerDirectives .shouldNotReachHere ("svars should be at index 1" );
175
- }
182
+ int svarsSlot = builder .addSlot (FrameSlotKind .Illegal , SpecialVariableStorage .SLOT_NAME , null );
183
+ if (svarsSlot != SpecialVariableStorage .SLOT_INDEX ) {
184
+ throw CompilerDirectives .shouldNotReachHere ("svars should be at index 1" );
176
185
}
177
186
178
187
return builder ;
0 commit comments