2828use PHPJava \Kernel \Types \_Long ;
2929use PHPJava \Kernel \Types \_Short ;
3030use PHPJava \Utilities \ArrayTool ;
31+ use PHPJava \Utilities \Formatter ;
3132
3233class StackMapTable extends Attribute
3334{
@@ -125,6 +126,19 @@ public function getValue(): string
125126 $ emulatedAccumulator = new Accumulator ();
126127 $ currentOffset = 0 ;
127128
129+ // foreach ($this->localVariables as $variableName => $variable) {
130+ // [$index, $classType] = $variable;
131+ // $emulatedAccumulator
132+ // ->setDefaultLocal(
133+ // $index,
134+ // [
135+ // VerificationTypeTag::ITEM_Object,
136+ // $this->getEnhancedConstantPool()
137+ // ->findClass($classType),
138+ // ]
139+ // );
140+ // }
141+
128142 foreach ($ this ->operations as $ operation ) {
129143 $ programCounter = $ this ->calculateProgramCounterByOperationCodes (
130144 $ this ->operations ,
@@ -163,7 +177,7 @@ static function (FullFrame $a, FullFrame $b) {
163177 );
164178
165179 /**
166- * Remove duplicated branch target.
180+ * Remove duplicated branch target and frame type was zero .
167181 *
168182 * @var FullFrame $previousFrame
169183 */
@@ -186,7 +200,9 @@ static function (array $carry, FullFrame $frame) use (&$entries) {
186200 []
187201 );
188202
189- // Build frame
203+ /**
204+ * @var FullFrame[] $frames
205+ */
190206 $ frames = [];
191207
192208 $ previousFrame = null ;
@@ -206,15 +222,13 @@ static function (array $carry, FullFrame $frame) use (&$entries) {
206222 $ offsetDelta = $ frame ->getBranchTarget () - $ previousFrame ->getBranchTarget () - 1 ;
207223 }
208224
209- if ((
210- $ previousFrame !== null
211- && ArrayTool::compare ($ previousFrame ->getLocals (), $ frame ->getLocals ())
212- && ArrayTool::compare ($ previousFrame ->getStacks (), $ frame ->getStacks ())
213- )
214- || ($ stacks === 0 && ($ locals === 0 || $ samePreviousLocalsAndCurrentLocals ))
225+ if ($ stacks === 0
226+ && ($ locals === 0 || $ samePreviousLocalsAndCurrentLocals )
215227 ) {
216228 $ entry = SameFrame::init ();
217- } elseif ($ stacks > 0 && ($ locals === 0 || $ samePreviousLocalsAndCurrentLocals )) {
229+ } elseif ($ stacks === 1
230+ && ($ locals === 0 || $ samePreviousLocalsAndCurrentLocals )
231+ ) {
218232 $ entry = SameLocals1StackItemFrame::init ();
219233 } elseif ($ stacks === 0 && $ locals > 0 ) {
220234 $ entry = AppendFrame::init ();
@@ -275,11 +289,26 @@ static function (array $carry, FullFrame $frame) use (&$entries) {
275289 * @var FullFrame $entry
276290 */
277291 $ writer ->writeUnsignedShort ($ entry ->getOffsetDelta ());
292+ $ locals = [];
293+ foreach ($ this ->localVariables as $ variableName => $ variable ) {
294+ [$ index , $ classType , $ deepArray ] = $ variable ;
295+ $ classType = Formatter::buildSignature ($ classType , $ deepArray );
296+ $ locals [$ index ] = [
297+ VerificationTypeTag::ITEM_Object,
298+ $ this ->getEnhancedConstantPool ()
299+ ->findClass ($ classType ),
300+ ];
301+ }
302+
303+ ArrayTool::concat (
304+ $ locals ,
305+ ...$ entry ->getLocals ()
306+ );
278307
279- $ writer ->writeUnsignedShort (count ($ entry -> getLocals () ));
308+ $ writer ->writeUnsignedShort (count ($ locals ));
280309 $ this ->writeStackMapTableVerificationSegment (
281310 $ writer ,
282- $ entry -> getLocals ()
311+ $ locals
283312 );
284313
285314 $ writer ->writeUnsignedShort (count ($ entry ->getStacks ()));
@@ -319,7 +348,7 @@ protected function writeStackMapTableVerificationSegment(BinaryWriter $writer, a
319348 // Nothing to do.
320349 break ;
321350 case VerificationTypeTag::ITEM_Object:
322- [ $ classEntry] = $ segment [1 ];
351+ $ classEntry = $ segment [1 ];
323352 /**
324353 * @var ConstantPoolFinderResult $classEntry
325354 */
0 commit comments