40
40
*/
41
41
package com .oracle .graal .python .nodes .bytecode ;
42
42
43
- import static com .oracle .graal .python .builtins .PythonBuiltinClassType .KeyError ;
44
43
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .RecursionError ;
45
44
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .SystemError ;
46
45
import static com .oracle .graal .python .nodes .BuiltinNames .__BUILD_CLASS__ ;
120
119
import com .oracle .graal .python .nodes .frame .ReadNameNode ;
121
120
import com .oracle .graal .python .nodes .frame .WriteGlobalNode ;
122
121
import com .oracle .graal .python .nodes .frame .WriteNameNode ;
123
- import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
124
122
import com .oracle .graal .python .nodes .object .IsNode ;
125
123
import com .oracle .graal .python .nodes .statement .ExceptNode .ExceptMatchNode ;
126
124
import com .oracle .graal .python .nodes .statement .ExceptionHandlingStatementNode ;
@@ -423,35 +421,41 @@ public int getLineno(Frame frame) {
423
421
return bciToLine (getBci (frame ));
424
422
}
425
423
426
- public void syncLocals (VirtualFrame virtualFrame , Object localsObject , Frame frameToSync , PyObjectSetItem setItem , PyObjectDelItem delItem , IsBuiltinClassProfile errorProfile ) {
427
- Frame localFrame = frameToSync ;
424
+ public int getVariableCount () {
428
425
CodeUnit code = rootNode .co ;
429
- if (code .isGeneratorOrCoroutine ()) {
430
- localFrame = PArguments .getGeneratorFrame (frameToSync );
426
+ return code .varnames .length + code .cellvars .length + code .freevars .length ;
427
+ }
428
+
429
+ public String getVariableName (int slot ) {
430
+ CodeUnit code = rootNode .co ;
431
+ if (slot < code .varnames .length ) {
432
+ return code .varnames [slot ];
433
+ } else if (slot < code .varnames .length + code .cellvars .length ) {
434
+ return code .cellvars [slot - code .varnames .length ];
435
+ } else {
436
+ return code .freevars [slot - code .varnames .length - code .cellvars .length ];
431
437
}
438
+ }
439
+
440
+ @ TruffleBoundary
441
+ public int findVariable (String name ) {
442
+ CodeUnit code = rootNode .co ;
432
443
for (int i = 0 ; i < code .varnames .length ; i ++) {
433
- setVar (virtualFrame , localsObject , setItem , delItem , errorProfile , code .varnames [i ], localFrame .getObject (i ));
444
+ if (name .equals (code .varnames [i ])) {
445
+ return i ;
446
+ }
434
447
}
435
448
for (int i = 0 ; i < code .cellvars .length ; i ++) {
436
- PCell cell = (PCell ) localFrame .getObject (rootNode .celloffset + i );
437
- setVar (virtualFrame , localsObject , setItem , delItem , errorProfile , code .cellvars [i ], cell .getRef ());
449
+ if (name .equals (code .cellvars [i ])) {
450
+ return code .varnames .length + i ;
451
+ }
438
452
}
439
453
for (int i = 0 ; i < code .freevars .length ; i ++) {
440
- PCell cell = (PCell ) localFrame .getObject (rootNode .freeoffset + i );
441
- setVar (virtualFrame , localsObject , setItem , delItem , errorProfile , code .freevars [i ], cell .getRef ());
442
- }
443
- }
444
-
445
- private void setVar (VirtualFrame virtualFrame , Object localsObject , PyObjectSetItem setItem , PyObjectDelItem delItem , IsBuiltinClassProfile errorProfile , String name , Object value ) {
446
- if (value == null ) {
447
- try {
448
- delItem .execute (virtualFrame , localsObject , name );
449
- } catch (PException e ) {
450
- e .expect (KeyError , errorProfile );
454
+ if (name .equals (code .freevars [i ])) {
455
+ return code .varnames .length + code .cellvars .length + i ;
451
456
}
452
- } else {
453
- setItem .execute (virtualFrame , localsObject , name , value );
454
457
}
458
+ return -1 ;
455
459
}
456
460
}
457
461
@@ -463,11 +467,17 @@ private static FrameDescriptor makeFrameDescriptor(CodeUnit co) {
463
467
FrameDescriptor .Builder newBuilder = FrameDescriptor .newBuilder (capacity );
464
468
newBuilder .info (new FrameInfo ());
465
469
// locals
466
- newBuilder .addSlots (co .varnames .length , FrameSlotKind .Illegal );
470
+ for (int i = 0 ; i < co .varnames .length ; i ++) {
471
+ newBuilder .addSlot (FrameSlotKind .Illegal , co .varnames [i ], null );
472
+ }
467
473
// cells
468
- newBuilder .addSlots (co .cellvars .length , FrameSlotKind .Illegal );
474
+ for (int i = 0 ; i < co .cellvars .length ; i ++) {
475
+ newBuilder .addSlot (FrameSlotKind .Illegal , co .cellvars [i ], null );
476
+ }
469
477
// freevars
470
- newBuilder .addSlots (co .freevars .length , FrameSlotKind .Illegal );
478
+ for (int i = 0 ; i < co .freevars .length ; i ++) {
479
+ newBuilder .addSlot (FrameSlotKind .Illegal , co .freevars [i ], null );
480
+ }
471
481
// stack
472
482
newBuilder .addSlots (co .stacksize , FrameSlotKind .Illegal );
473
483
// BCI filled when unwinding the stack or when pausing generators
0 commit comments