From 6ea195588650fc1ced5bc7afa81ac2efb078c401 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Tue, 27 Aug 2019 20:41:00 +0200 Subject: [PATCH] Fix the stack value of array new. --- .../jwebassembly/module/WasmArrayInstruction.java | 7 +++++-- .../inetsoftware/jwebassembly/module/WasmCodeBuilder.java | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/de/inetsoftware/jwebassembly/module/WasmArrayInstruction.java b/src/de/inetsoftware/jwebassembly/module/WasmArrayInstruction.java index 5b6fc1a..733792b 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmArrayInstruction.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmArrayInstruction.java @@ -38,6 +38,8 @@ class WasmArrayInstruction extends WasmInstruction { private final AnyType type; + private final TypeManager types; + /** * Create an instance of an array operation. * @@ -50,10 +52,11 @@ class WasmArrayInstruction extends WasmInstruction { * @param lineNumber * the line number in the Java source code */ - WasmArrayInstruction( @Nullable ArrayOperator op, @Nullable AnyType type, int javaCodePos, int lineNumber ) { + WasmArrayInstruction( @Nullable ArrayOperator op, @Nullable AnyType type, TypeManager types, int javaCodePos, int lineNumber ) { super( javaCodePos, lineNumber ); this.op = op; this.type = type; + this.types = types; } /** @@ -77,7 +80,7 @@ class WasmArrayInstruction extends WasmInstruction { AnyType getPushValueType() { switch( op ) { case NEW: - return ValueType.anyref; + return types.arrayType( type ); case GET: return type instanceof ValueType ? (ValueType)type : ValueType.anyref; case SET: diff --git a/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java b/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java index a040aa4..d4ed513 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java @@ -343,7 +343,7 @@ public abstract class WasmCodeBuilder { */ protected void addArrayInstruction( ArrayOperator op, AnyType type, int javaCodePos, int lineNumber ) { if( useGC ) { - instructions.add( new WasmArrayInstruction( op, type, javaCodePos, lineNumber ) ); + instructions.add( new WasmArrayInstruction( op, type, types, javaCodePos, lineNumber ) ); } else { try { if( type.getCode() >= 0 ) {