Skip to content

Commit cfbadfa

Browse files
committed
anyref --> externref, add kind to ref.null and ref.is_null, WebAssembly/reference-types#87
1 parent 56c38bb commit cfbadfa

23 files changed

+69
-65
lines changed

src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ private void writeTableSection() throws IOException {
193193

194194
// string constants table
195195
if( count >= 2 ) {
196-
stream.writeValueType( ValueType.anyref ); // the type of elements
196+
stream.writeValueType( ValueType.externref ); // the type of elements
197197
stream.writeVaruint32( 0 ); // flags; 1-maximum is available, 0-no maximum value available
198198
stream.writeVaruint32( stringCount ); // initial length
199199
}
200200

201201
// table with classes
202202
if( count >= 3 ) {
203-
stream.writeValueType( ValueType.anyref ); // the type of elements
203+
stream.writeValueType( ValueType.externref ); // the type of elements
204204
stream.writeVaruint32( 0 ); // flags; 1-maximum is available, 0-no maximum value available
205205
stream.writeVaruint32( typeCount ); // initial length
206206
}
@@ -497,7 +497,7 @@ protected int writeStructType( StructType type ) throws IOException {
497497
type.writeToStream( dataStream, (funcName) -> getFunction( funcName ).id );
498498

499499
if( !options.useGC() ) {
500-
return ValueType.anyref.getCode();
500+
return ValueType.externref.getCode();
501501
}
502502

503503
int typeId = functionTypes.size();
@@ -512,7 +512,7 @@ protected int writeStructType( StructType type ) throws IOException {
512512
protected void writeException() throws IOException {
513513
if( exceptionSignatureIndex <= 0 ) {
514514
FunctionTypeEntry type = new FunctionTypeEntry();
515-
type.params.add( ValueType.anyref );
515+
type.params.add( ValueType.externref );
516516
exceptionSignatureIndex = functionTypes.indexOf( type );
517517
if( exceptionSignatureIndex < 0 ) {
518518
exceptionSignatureIndex = functionTypes.size();
@@ -522,7 +522,7 @@ protected void writeException() throws IOException {
522522
// result type of catch block for unboxing
523523
type = new FunctionTypeEntry();
524524
type.params.add( ValueType.exnref );
525-
type.results.add( ValueType.anyref );
525+
type.results.add( ValueType.externref );
526526
options.setCatchType( functionTypes.size() );
527527
functionTypes.add( type );
528528
}
@@ -1394,7 +1394,7 @@ protected void writeStructOperator( StructOperator op, AnyType type, NamedStorag
13941394
break;
13951395
case NULL:
13961396
opCode = REF_NULL;
1397-
type = null;
1397+
type = ValueType.externref;
13981398
break;
13991399
default:
14001400
throw new Error( "Unknown operator: " + op );

src/de/inetsoftware/jwebassembly/binary/InstructionOpcodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ interface InstructionOpcodes {
451451

452452
static final int REF_NULL = 0xD0;
453453

454-
static final int REF_ISNULL = 0xD1;
454+
static final int REF_ISNULL = 0xD16F; // "ref.is_null extern"
455455

456456
/** converts a nullable reference to a non-nullable one or traps if null */
457457
static final int REF_AS_NON_NULL = 0xD3;

src/de/inetsoftware/jwebassembly/binary/WasmOutputStream.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void writeRefValueType( AnyType type ) throws IOException {
100100
if( options.useGC() ) {
101101
writeValueType( ValueType.ref_type );
102102
} else {
103-
type = ValueType.anyref;
103+
type = ValueType.externref;
104104
}
105105
}
106106
writeValueType( type );
@@ -128,14 +128,16 @@ public void writeDefaultValue( AnyType type ) throws IOException {
128128
case i16:
129129
writeConst( 0, ValueType.i32 );
130130
break;
131-
case anyref:
131+
case externref:
132132
writeOpCode( InstructionOpcodes.REF_NULL );
133+
writeValueType( ValueType.externref );
133134
break;
134135
default:
135136
throw new WasmException( "Not supported storage type: " + type, -1 );
136137
}
137138
} else {
138139
writeOpCode( InstructionOpcodes.REF_NULL );
140+
writeValueType( ValueType.externref );
139141
}
140142
}
141143

src/de/inetsoftware/jwebassembly/javascript/JavaScriptNewMultiArrayFunctionName.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private static ValueType getElementType( ArrayType type ) {
5656
type = (ArrayType)arrayType;
5757
continue;
5858
}
59-
return arrayType.getClass() == ValueType.class ? (ValueType)arrayType : ValueType.anyref;
59+
return arrayType.getClass() == ValueType.class ? (ValueType)arrayType : ValueType.externref;
6060
} while( true );
6161
}
6262

src/de/inetsoftware/jwebassembly/javascript/NonGC.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public abstract class NonGC {
4444
native static double[] array_new_f64( int length );
4545

4646
@Import( js = "(l) => Object.seal(new Array(l).fill(null))" )
47-
native static Object[] array_new_anyref( int length );
47+
native static Object[] array_new_externref( int length );
4848

4949
@Import( js = "(a) => a.length" )
5050
native static int array_len_i8( Object array );
@@ -65,7 +65,7 @@ public abstract class NonGC {
6565
native static int array_len_f64( Object array );
6666

6767
@Import( js = "(a) => a.length" )
68-
native static int array_len_anyref( Object array );
68+
native static int array_len_externref( Object array );
6969

7070
@Import( js = "(a,i,v) => a[i]=v" )
7171
native static void array_set_i8( byte[] array, int idx, byte value );
@@ -86,7 +86,7 @@ public abstract class NonGC {
8686
native static void array_set_f64( double[] array, int idx, double value );
8787

8888
@Import( js = "(a,i,v) => a[i]=v" )
89-
native static void array_set_anyref( Object[] array, int idx, Object value );
89+
native static void array_set_externref( Object[] array, int idx, Object value );
9090

9191
@Import( js = "(a,i) => a[i]" )
9292
native static byte array_get_i8( byte[] array, int idx );
@@ -107,7 +107,7 @@ public abstract class NonGC {
107107
native static double array_get_f64( double[] array, int idx );
108108

109109
@Import( js = "(a,i) => a[i]" )
110-
native static Object array_get_anyref( Object[] array, int idx );
110+
native static Object array_get_externref( Object[] array, int idx );
111111

112112
@Import( js = "(a,b) => a === b" )
113113
native static int ref_eq( Object a, Object b );

src/de/inetsoftware/jwebassembly/module/JavaMethodWasmCodeBuilder.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private void writeCode( CodeInputStream byteCode, ConstantPool constantPool, Cla
158158
addLoadStoreInstruction( ValueType.f64, true, byteCode.readUnsignedIndex( wide ), codePos, lineNumber );
159159
break;
160160
case 25: // aload
161-
addLoadStoreInstruction( ValueType.anyref, true, byteCode.readUnsignedIndex( wide ), codePos, lineNumber );
161+
addLoadStoreInstruction( ValueType.externref, true, byteCode.readUnsignedIndex( wide ), codePos, lineNumber );
162162
break;
163163
case 26: // iload_0
164164
case 27: // iload_1
@@ -188,7 +188,7 @@ private void writeCode( CodeInputStream byteCode, ConstantPool constantPool, Cla
188188
case 43: //aload_1
189189
case 44: //aload_2
190190
case 45: //aload_3
191-
addLoadStoreInstruction( ValueType.anyref, true, op - 42, codePos, lineNumber );
191+
addLoadStoreInstruction( ValueType.externref, true, op - 42, codePos, lineNumber );
192192
break;
193193
case 46: // iaload
194194
addArrayInstruction( ArrayOperator.GET, ValueType.i32, codePos, lineNumber );
@@ -229,8 +229,8 @@ private void writeCode( CodeInputStream byteCode, ConstantPool constantPool, Cla
229229
break;
230230
case 58: // astore
231231
if( branchManager.isCatch( codePos ) ) {
232-
addJumpPlaceholder( codePos, 0, ValueType.anyref, codePos, lineNumber );
233-
storeType = ValueType.anyref; // for the catch there are no previous instructions
232+
addJumpPlaceholder( codePos, 0, ValueType.externref, codePos, lineNumber );
233+
storeType = ValueType.externref; // for the catch there are no previous instructions
234234
} else {
235235
storeType = findValueTypeFromStack( 1, codePos );
236236
}
@@ -265,8 +265,8 @@ private void writeCode( CodeInputStream byteCode, ConstantPool constantPool, Cla
265265
case 77: // astore_2
266266
case 78: // astore_3
267267
if( branchManager.isCatch( codePos ) ) {
268-
addJumpPlaceholder( codePos, 0, ValueType.anyref, codePos, lineNumber );
269-
storeType = ValueType.anyref; // for the catch there are no previous instructions
268+
addJumpPlaceholder( codePos, 0, ValueType.externref, codePos, lineNumber );
269+
storeType = ValueType.externref; // for the catch there are no previous instructions
270270
} else {
271271
storeType = findValueTypeFromStack( 1, codePos );
272272
}
@@ -580,7 +580,7 @@ private void writeCode( CodeInputStream byteCode, ConstantPool constantPool, Cla
580580
type = ValueType.f64;
581581
break;
582582
case 176: // areturn
583-
type = ValueType.anyref;
583+
type = ValueType.externref;
584584
break;
585585
}
586586
addBlockInstruction( WasmBlockOperator.RETURN, type, codePos, lineNumber );
@@ -671,7 +671,7 @@ private void writeCode( CodeInputStream byteCode, ConstantPool constantPool, Cla
671671
break;
672672
case 189: // anewarray
673673
name = ((ConstantClass)constantPool.get( byteCode.readUnsignedShort() )).getName();
674-
type = ValueType.anyref; //TODO we need to use the right type from name; getTypeManager().valueOf( name );
674+
type = ValueType.externref; //TODO we need to use the right type from name; getTypeManager().valueOf( name );
675675
addArrayInstruction( ArrayOperator.NEW, type, codePos, lineNumber );
676676
break;
677677
case 190: // arraylength

src/de/inetsoftware/jwebassembly/module/LocaleVariableManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void reset( LocalVariableTable variableTable, MethodInfo method, Iterator<AnyTyp
163163
if( (maxLocals > 0 || variableTable == null) && size == 0 && (method != null || signature != null )) {
164164
Iterator<AnyType> parser = signature == null ? new ValueTypeParser( method.getType(), types ) : signature;
165165
if( method != null && !method.isStatic() ) {
166-
resetAddVar( ValueType.anyref, size );
166+
resetAddVar( ValueType.externref, size );
167167
}
168168
while( true ) {
169169
AnyType type = parser.next();

src/de/inetsoftware/jwebassembly/module/TypeManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ public boolean isRefType() {
740740
@Override
741741
public boolean isSubTypeOf( AnyType type ) {
742742
//TODO if type is StructType (class or interface)
743-
return type == this || type == ValueType.anyref;
743+
return type == this || type == ValueType.externref;
744744
}
745745

746746
/**

src/de/inetsoftware/jwebassembly/module/WasmArrayInstruction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ AnyType getPushValueType() {
8282
case NEW:
8383
return types.arrayType( type );
8484
case GET:
85-
return type instanceof ValueType ? (ValueType)type : ValueType.anyref;
85+
return type instanceof ValueType ? (ValueType)type : ValueType.externref;
8686
case SET:
8787
return null;
8888
case LEN:
@@ -98,9 +98,9 @@ AnyType getPushValueType() {
9898
@Override
9999
int getPopCount() {
100100
switch( op ) {
101-
case NEW:
102101
case GET:
103102
return 2;
103+
case NEW:
104104
case LEN:
105105
return 1;
106106
case SET:

src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,8 @@ protected void addArrayInstruction( ArrayOperator op, AnyType type, int javaCode
740740
if( options.useGC() ) {
741741
instructions.add( new WasmArrayInstruction( op, type, types, javaCodePos, lineNumber ) );
742742
} else {
743-
if( type.getCode() >= 0 || type.getCode() == ValueType.anyref.getCode() ) {
744-
type = ValueType.anyref; // handle all not native types as anyref
743+
if( type.getCode() >= 0 || type.getCode() == ValueType.externref.getCode() ) {
744+
type = ValueType.externref; // handle all not native types as anyref
745745
}
746746
String api = "array_" + op.toString().toLowerCase() + "_" + type;
747747
FunctionName name = getNonGC( api, lineNumber );

0 commit comments

Comments
 (0)