mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 15:37:52 +01:00
implements dup_x1 instruction
This commit is contained in:
parent
f0828196b7
commit
f15fb1cdf9
@ -306,8 +306,10 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
|||||||
addDupInstruction( codePos, lineNumber );
|
addDupInstruction( codePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
case 90: // dup_x1
|
case 90: // dup_x1
|
||||||
case 91: // dup_x2
|
|
||||||
case 93: // dup2_x1
|
case 93: // dup2_x1
|
||||||
|
addDupX1Instruction( codePos, lineNumber );
|
||||||
|
break;
|
||||||
|
case 91: // dup_x2
|
||||||
case 94: // dup2_x2
|
case 94: // dup2_x2
|
||||||
case 95: // swap
|
case 95: // swap
|
||||||
// can be do with functions with more as one return value in future WASM standard
|
// can be do with functions with more as one return value in future WASM standard
|
||||||
|
@ -333,6 +333,33 @@ public abstract class WasmCodeBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simulate the dup_x1 Java byte code instruction.<p>
|
||||||
|
*
|
||||||
|
* ..., value2, value1 → ..., value1, value2, value1
|
||||||
|
*
|
||||||
|
* @param javaCodePos
|
||||||
|
* the code position/offset in the Java method
|
||||||
|
* @param lineNumber
|
||||||
|
* the line number in the Java source code
|
||||||
|
*/
|
||||||
|
protected void addDupX1Instruction( int javaCodePos, int lineNumber ) {
|
||||||
|
AnyType type1 = findValueTypeFromStack( 1, javaCodePos );
|
||||||
|
AnyType type2 = findValueTypeFromStack( 2, javaCodePos );
|
||||||
|
|
||||||
|
int varIndex1 = getTempVariable( type1, javaCodePos, javaCodePos + 1 );
|
||||||
|
int varIndex2 = getTempVariable( type2, javaCodePos, javaCodePos + 1 );;
|
||||||
|
|
||||||
|
// save in temp variables
|
||||||
|
instructions.add( new WasmLocalInstruction( VariableOperator.set, varIndex1, localVariables, javaCodePos, lineNumber ) );
|
||||||
|
instructions.add( new WasmLocalInstruction( VariableOperator.set, varIndex2, localVariables, javaCodePos, lineNumber ) );
|
||||||
|
|
||||||
|
// and restore it in new order on the stack
|
||||||
|
instructions.add( new WasmLocalInstruction( VariableOperator.get, varIndex1, localVariables, javaCodePos, lineNumber ) );
|
||||||
|
instructions.add( new WasmLocalInstruction( VariableOperator.get, varIndex2, localVariables, javaCodePos, lineNumber ) );
|
||||||
|
instructions.add( new WasmLocalInstruction( VariableOperator.get, varIndex1, localVariables, javaCodePos, lineNumber ) );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a global instruction
|
* Add a global instruction
|
||||||
*
|
*
|
||||||
|
@ -132,9 +132,8 @@ public class StructsGC extends AbstractBaseTest {
|
|||||||
static int multipleAssign() {
|
static int multipleAssign() {
|
||||||
Abc2 val = new Abc2();
|
Abc2 val = new Abc2();
|
||||||
for( int i = 0; i < 1_000; i++ ) {
|
for( int i = 0; i < 1_000; i++ ) {
|
||||||
val.a = 42;
|
val = val.abc = new Abc2();
|
||||||
// TODO
|
val.a = i;
|
||||||
//val = val.abc = new Abc2();
|
|
||||||
}
|
}
|
||||||
return val.a;
|
return val.a;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import org.junit.runners.Parameterized.Parameters;
|
|||||||
import de.inetsoftware.jwebassembly.ScriptEngine;
|
import de.inetsoftware.jwebassembly.ScriptEngine;
|
||||||
import de.inetsoftware.jwebassembly.WasmRule;
|
import de.inetsoftware.jwebassembly.WasmRule;
|
||||||
import de.inetsoftware.jwebassembly.api.annotation.Export;
|
import de.inetsoftware.jwebassembly.api.annotation.Export;
|
||||||
|
import de.inetsoftware.jwebassembly.runtime.StructsGC.Abc2;
|
||||||
import de.inetsoftware.jwebassembly.web.JSObject;
|
import de.inetsoftware.jwebassembly.web.JSObject;
|
||||||
|
|
||||||
public class StructsNonGC extends AbstractBaseTest {
|
public class StructsNonGC extends AbstractBaseTest {
|
||||||
@ -140,9 +141,8 @@ public class StructsNonGC extends AbstractBaseTest {
|
|||||||
static int multipleAssign() {
|
static int multipleAssign() {
|
||||||
Abc2 val = new Abc2();
|
Abc2 val = new Abc2();
|
||||||
for( int i = 0; i < 1_000; i++ ) {
|
for( int i = 0; i < 1_000; i++ ) {
|
||||||
val.a = 42;
|
val = val.abc = new Abc2();
|
||||||
// TODO
|
val.a = i;
|
||||||
//val = val.abc = new Abc2();
|
|
||||||
}
|
}
|
||||||
return val.a;
|
return val.a;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user