@@ -28,10 +28,10 @@ namespace Wacs.Core.Instructions.GC
2828{
2929 public class InstArrayNew : InstructionBase , IConstInstruction
3030 {
31+ public InstArrayNew ( ) : base ( ByteCode . ArrayNew , - 1 ) { }
32+
3133 private TypeIdx X ;
32- public override ByteCode Op => GcCode . ArrayNew ;
33- public override int StackDiff => - 1 ;
34-
34+
3535 public override void Validate ( IWasmValidationContext context )
3636 {
3737 context . Assert ( context . Types . Contains ( X ) ,
@@ -99,8 +99,9 @@ public override InstructionBase Parse(BinaryReader reader)
9999
100100 public class InstArrayNewDefault : InstructionBase , IConstInstruction
101101 {
102+ public InstArrayNewDefault ( ) : base ( ByteCode . ArrayNewDefault ) { }
103+
102104 private TypeIdx X ;
103- public override ByteCode Op => GcCode . ArrayNewDefault ;
104105
105106 public override void Validate ( IWasmValidationContext context )
106107 {
@@ -157,10 +158,10 @@ public override InstructionBase Parse(BinaryReader reader)
157158
158159 public class InstArrayNewFixed : InstructionBase , IConstInstruction
159160 {
161+ public InstArrayNewFixed ( ) : base ( ByteCode . ArrayNewFixed ) { }
162+
160163 private uint N ;
161164 private TypeIdx X ;
162- public override ByteCode Op => GcCode . ArrayNewFixed ;
163- public override int StackDiff => - ( ( int ) N - 1 ) ;
164165
165166 public override void Validate ( IWasmValidationContext context )
166167 {
@@ -184,6 +185,13 @@ public override void Validate(IWasmValidationContext context)
184185 context . OpStack . PushType ( resultType ) ; // -(N-1)
185186 }
186187
188+ public override InstructionBase Link ( ExecContext context , int pointer )
189+ {
190+ int stackDiff = + 1 - ( int ) N ;
191+ context . DeltaStack ( stackDiff ) ;
192+ return this ;
193+ }
194+
187195 public override void Execute ( ExecContext context )
188196 {
189197 //2
@@ -222,12 +230,11 @@ public override InstructionBase Parse(BinaryReader reader)
222230
223231 public class InstArrayNewData : InstructionBase
224232 {
233+ public InstArrayNewData ( ) : base ( ByteCode . ArrayNewData , - 1 ) { }
234+
225235 private TypeIdx X ;
226236 private DataIdx Y ;
227237
228- public override ByteCode Op => GcCode . ArrayNewData ;
229- public override int StackDiff => - 1 ;
230-
231238 public override void Validate ( IWasmValidationContext context )
232239 {
233240 context . Assert ( context . Types . Contains ( X ) ,
@@ -334,12 +341,11 @@ public override InstructionBase Parse(BinaryReader reader)
334341
335342 public class InstArrayNewElem : InstructionBase
336343 {
344+ public InstArrayNewElem ( ) : base ( ByteCode . ArrayNewElem , - 1 ) { }
345+
337346 private TypeIdx X ;
338347 private ElemIdx Y ;
339348
340- public override ByteCode Op => GcCode . ArrayNewElem ;
341- public override int StackDiff => - 1 ;
342-
343349 public override void Validate ( IWasmValidationContext context )
344350 {
345351 context . Assert ( context . Types . Contains ( X ) ,
@@ -424,21 +430,17 @@ public class InstArrayGet : InstructionBase
424430 private readonly PackedExt Sx ;
425431 private TypeIdx X ;
426432
427- public InstArrayGet ( PackedExt sx )
428- {
429- Sx = sx ;
430- }
433+ public InstArrayGet ( PackedExt sx ) : base ( GetOp ( sx ) , - 1 )
434+ => Sx = sx ;
431435
432- public override ByteCode Op => Sx switch
436+ private static ByteCode GetOp ( PackedExt sx ) => sx switch
433437 {
434- PackedExt . Signed => GcCode . ArrayGetS ,
435- PackedExt . NotPacked => GcCode . ArrayGet ,
436- PackedExt . Unsigned => GcCode . ArrayGetU ,
437- _ => throw new InvalidDataException ( $ "Undefined packedtype: { Sx } ")
438+ PackedExt . Signed => ByteCode . ArrayGetS ,
439+ PackedExt . NotPacked => ByteCode . ArrayGet ,
440+ PackedExt . Unsigned => ByteCode . ArrayGetU ,
441+ _ => throw new InvalidDataException ( $ "Undefined packedtype: { sx } ")
438442 } ;
439443
440- public override int StackDiff => - 1 ;
441-
442444 /// <summary>
443445 /// https://webassembly.github.io/gc/core/bikeshed/index.html#-hrefsyntax-instr-structmathsfstructgetmathsf_hrefsyntax-sxmathitsxxy
444446 /// </summary>
@@ -532,11 +534,10 @@ public override InstructionBase Parse(BinaryReader reader)
532534
533535 public class InstArraySet : InstructionBase
534536 {
537+ public InstArraySet ( ) : base ( ByteCode . ArraySet , - 3 ) { }
538+
535539 private TypeIdx X ;
536-
537- public override ByteCode Op => GcCode . ArraySet ;
538- public override int StackDiff => - 3 ;
539-
540+
540541 public override void Validate ( IWasmValidationContext context )
541542 {
542543 context . Assert ( context . Types . Contains ( X ) ,
@@ -617,7 +618,7 @@ public override InstructionBase Parse(BinaryReader reader)
617618
618619 public class InstArrayLen : InstructionBase
619620 {
620- public override ByteCode Op => GcCode . ArrayLen ;
621+ public InstArrayLen ( ) : base ( ByteCode . ArrayLen ) { }
621622
622623 public override void Validate ( IWasmValidationContext context )
623624 {
@@ -653,10 +654,10 @@ public override void Execute(ExecContext context)
653654
654655 public class InstArrayFill : InstructionBase
655656 {
657+ public InstArrayFill ( ) : base ( ByteCode . ArrayFill , - 4 ) { }
658+
656659 private TypeIdx X ;
657- public override ByteCode Op => GcCode . ArrayFill ;
658- public override int StackDiff => - 4 ;
659-
660+
660661 public override void Validate ( IWasmValidationContext context )
661662 {
662663 context . Assert ( context . Types . Contains ( X ) ,
@@ -734,11 +735,11 @@ public override InstructionBase Parse(BinaryReader reader)
734735
735736 public class InstArrayCopy : InstructionBase
736737 {
738+ public InstArrayCopy ( ) : base ( ByteCode . ArrayCopy , - 5 ) { }
739+
737740 private TypeIdx X ; //dest
738741 private TypeIdx Y ; //src
739- public override ByteCode Op => GcCode . ArrayCopy ;
740- public override int StackDiff => - 5 ;
741-
742+
742743 public override void Validate ( IWasmValidationContext context )
743744 {
744745 context . Assert ( context . Types . Contains ( X ) ,
@@ -862,12 +863,11 @@ public override InstructionBase Parse(BinaryReader reader)
862863
863864 public class InstArrayInitData : InstructionBase
864865 {
866+ public InstArrayInitData ( ) : base ( ByteCode . ArrayInitData , - 4 ) { }
867+
865868 private TypeIdx X ;
866869 private DataIdx Y ;
867-
868- public override ByteCode Op => GcCode . ArrayInitData ;
869- public override int StackDiff => - 4 ;
870-
870+
871871 /// <summary>
872872 /// https://webassembly.github.io/gc/core/bikeshed/index.html#-hrefsyntax-instr-arraymathsfarrayinit_dataxy
873873 /// </summary>
@@ -993,12 +993,11 @@ public override InstructionBase Parse(BinaryReader reader)
993993
994994 public class InstArrayInitElem : InstructionBase
995995 {
996+ public InstArrayInitElem ( ) : base ( ByteCode . ArrayInitElem , - 4 ) { }
997+
996998 private TypeIdx X ;
997999 private ElemIdx Y ;
9981000
999- public override ByteCode Op => GcCode . ArrayInitElem ;
1000- public override int StackDiff => - 4 ;
1001-
10021001 /// <summary>
10031002 /// https://webassembly.github.io/gc/core/bikeshed/index.html#-hrefsyntax-instr-arraymathsfarrayinit_elemxy
10041003 /// </summary>
0 commit comments