@@ -830,31 +830,42 @@ private Expression listOfValueTypes(List<ValType> valTypes) {
830830 return new MethodCallExpr (new NameExpr ("List" ), "of" , NodeList .nodeList (values ));
831831 }
832832
833+ /** The {@code ValType} shorthand constant for an abstract heap type, or null if there is none. */
834+ private static String abstractRefShorthand (int typeIdx ) {
835+ if (typeIdx == ValType .TypeIdxCode .EXTERN .code ()) {
836+ return "ExternRef" ;
837+ } else if (typeIdx == ValType .TypeIdxCode .ANY .code ()) {
838+ return "AnyRef" ;
839+ } else if (typeIdx == ValType .TypeIdxCode .EQ .code ()) {
840+ return "EqRef" ;
841+ } else if (typeIdx == ValType .TypeIdxCode .I31 .code ()) {
842+ return "I31Ref" ;
843+ } else if (typeIdx == ValType .TypeIdxCode .STRUCT .code ()) {
844+ return "StructRef" ;
845+ } else if (typeIdx == ValType .TypeIdxCode .ARRAY .code ()) {
846+ return "ArrayRef" ;
847+ } else if (typeIdx == ValType .TypeIdxCode .NONE .code ()) {
848+ return "NoneRef" ;
849+ } else if (typeIdx == ValType .TypeIdxCode .FUNC .code ()) {
850+ return "FuncRef" ;
851+ } else if (typeIdx == ValType .TypeIdxCode .EXN .code ()) {
852+ return "ExnRef" ;
853+ } else if (typeIdx == ValType .TypeIdxCode .NOFUNC .code ()) {
854+ return "NoFuncRef" ;
855+ } else if (typeIdx == ValType .TypeIdxCode .NOEXTERN .code ()) {
856+ return "NoExternRef" ;
857+ } else {
858+ return null ;
859+ }
860+ }
861+
833862 private static Expression valTypeRefExpr (ValType vt ) {
834863 int ti = vt .typeIdx ();
835- if (ti == ValType .TypeIdxCode .EXTERN .code ()) {
836- return new FieldAccessExpr (new NameExpr ("ValType" ), "ExternRef" );
837- } else if (ti == ValType .TypeIdxCode .ANY .code ()) {
838- return new FieldAccessExpr (new NameExpr ("ValType" ), "AnyRef" );
839- } else if (ti == ValType .TypeIdxCode .EQ .code ()) {
840- return new FieldAccessExpr (new NameExpr ("ValType" ), "EqRef" );
841- } else if (ti == ValType .TypeIdxCode .I31 .code ()) {
842- return new FieldAccessExpr (new NameExpr ("ValType" ), "I31Ref" );
843- } else if (ti == ValType .TypeIdxCode .STRUCT .code ()) {
844- return new FieldAccessExpr (new NameExpr ("ValType" ), "StructRef" );
845- } else if (ti == ValType .TypeIdxCode .ARRAY .code ()) {
846- return new FieldAccessExpr (new NameExpr ("ValType" ), "ArrayRef" );
847- } else if (ti == ValType .TypeIdxCode .NONE .code ()) {
848- return new FieldAccessExpr (new NameExpr ("ValType" ), "NoneRef" );
849- } else if (ti == ValType .TypeIdxCode .FUNC .code ()) {
850- return new FieldAccessExpr (new NameExpr ("ValType" ), "FuncRef" );
851- } else if (ti == ValType .TypeIdxCode .EXN .code ()) {
852- return new FieldAccessExpr (new NameExpr ("ValType" ), "ExnRef" );
853- } else if (ti == ValType .TypeIdxCode .NOFUNC .code ()) {
854- return new FieldAccessExpr (new NameExpr ("ValType" ), "NoFuncRef" );
855- } else if (ti == ValType .TypeIdxCode .NOEXTERN .code ()) {
856- return new FieldAccessExpr (new NameExpr ("ValType" ), "NoExternRef" );
857- } else if (ti >= 0 ) {
864+ String shorthand = abstractRefShorthand (ti );
865+ // the shorthands are all nullable, a non-nullable ref has to be built explicitly
866+ if (shorthand != null && vt .opcode () == ValType .ID .RefNull ) {
867+ return new FieldAccessExpr (new NameExpr ("ValType" ), shorthand );
868+ } else if (shorthand != null || ti >= 0 ) {
858869 String opcName = vt .opcode () == ValType .ID .Ref ? "Ref" : "RefNull" ;
859870 return new MethodCallExpr (
860871 new MethodCallExpr (
0 commit comments