From 4377db747d41748687bf30c445ea49f60f509bf0 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Sat, 11 Jan 2020 21:48:04 +0100 Subject: [PATCH] use needThisParameter for popCount of method calls --- .../module/WasmCallIndirectInstruction.java | 10 +--------- .../module/WasmCallInstruction.java | 17 +++++++++++------ .../jwebassembly/module/WasmCodeBuilder.java | 5 +++-- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/de/inetsoftware/jwebassembly/module/WasmCallIndirectInstruction.java b/src/de/inetsoftware/jwebassembly/module/WasmCallIndirectInstruction.java index 81be057..8039456 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmCallIndirectInstruction.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmCallIndirectInstruction.java @@ -59,7 +59,7 @@ class WasmCallIndirectInstruction extends WasmCallInstruction { * compiler properties */ WasmCallIndirectInstruction( FunctionName name, int javaCodePos, int lineNumber, TypeManager types, WasmOptions options ) { - super( name, javaCodePos, lineNumber, types ); + super( name, javaCodePos, lineNumber, types, true ); this.type = types.valueOf( name.className ); this.options = options; } @@ -128,12 +128,4 @@ class WasmCallIndirectInstruction extends WasmCallInstruction { writer.writeVirtualFunctionCall( getFunctionName(), type ); } } - - /** - * {@inheritDoc} - */ - @Override - int getPopCount() { - return super.getPopCount() + 1; // this -> +1 - } } diff --git a/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java b/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java index 0a8db94..6a20cce 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java @@ -31,13 +31,15 @@ import de.inetsoftware.jwebassembly.wasm.AnyType; */ class WasmCallInstruction extends WasmInstruction { - private AnyType valueType; + private AnyType valueType; - private FunctionName name; + private FunctionName name; - private int paramCount = -1; + private int paramCount = -1; - private TypeManager types; + private final TypeManager types; + + private final boolean needThisParameter; /** * Create an instance of a function call instruction @@ -50,11 +52,14 @@ class WasmCallInstruction extends WasmInstruction { * the line number in the Java source code * @param types * the type manager + * @param needThisParameter + * true, if this function need additional to the parameter of the signature an extra "this" parameter */ - WasmCallInstruction( FunctionName name, int javaCodePos, int lineNumber, TypeManager types ) { + WasmCallInstruction( FunctionName name, int javaCodePos, int lineNumber, TypeManager types, boolean needThisParameter ) { super( javaCodePos, lineNumber ); this.name = name; this.types = types; + this.needThisParameter = needThisParameter; } /** @@ -117,7 +122,7 @@ class WasmCallInstruction extends WasmInstruction { return; } Iterator parser = name.getSignature( types ); - paramCount = name.methodName.equals( "" ) ? 1 : 0; + paramCount = needThisParameter ? 1 : 0; while( parser.next() != null ) { paramCount++; } diff --git a/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java b/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java index 4498740..b3aa0c3 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java @@ -421,7 +421,8 @@ public abstract class WasmCodeBuilder { * the line number in the Java source code */ protected void addCallInstruction( FunctionName name, int javaCodePos, int lineNumber ) { - WasmCallInstruction instruction = new WasmCallInstruction( name, javaCodePos, lineNumber, types ); + boolean needThisParameter = functions.needThisParameter( name ); + WasmCallInstruction instruction = new WasmCallInstruction( name, javaCodePos, lineNumber, types, needThisParameter ); if( "".equals( name.methodName ) ) { // check if there a factory for the constructor in JavaScript then we need to do some more complex patching @@ -459,7 +460,7 @@ public abstract class WasmCodeBuilder { } } // the new instruction - instruction = new WasmCallInstruction( factoryName, javaCodePos, lineNumber, types ); + instruction = new WasmCallInstruction( factoryName, javaCodePos, lineNumber, types, false ); } }