mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
Fix the type of array.get operation. Before it was ever i32 from array index.
This commit is contained in:
parent
f0a0b0116b
commit
481bffe31a
@ -186,7 +186,7 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
|||||||
addArrayInstruction( ArrayOperator.GET, ValueType.f64, codePos, lineNumber );
|
addArrayInstruction( ArrayOperator.GET, ValueType.f64, codePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
case 50: // aaload
|
case 50: // aaload
|
||||||
AnyType storeType = findPreviousPushInstructionPushValueType();
|
AnyType storeType = findValueTypeFromStack( 2 );
|
||||||
addArrayInstruction( ArrayOperator.GET, storeType, codePos, lineNumber );
|
addArrayInstruction( ArrayOperator.GET, storeType, codePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
case 51: // baload
|
case 51: // baload
|
||||||
@ -244,7 +244,7 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
|||||||
if( branchManager.isCatch( codePos ) ) {
|
if( branchManager.isCatch( codePos ) ) {
|
||||||
storeType = ValueType.anyref; // for the catch there are no previous instructions
|
storeType = ValueType.anyref; // for the catch there are no previous instructions
|
||||||
} else {
|
} else {
|
||||||
storeType = findPreviousPushInstructionPushValueType();
|
storeType = findValueTypeFromStack( 1 );
|
||||||
}
|
}
|
||||||
addLoadStoreInstruction( storeType, false, op - 75, codePos, lineNumber );
|
addLoadStoreInstruction( storeType, false, op - 75, codePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
@ -261,7 +261,7 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
|||||||
addArrayInstruction( ArrayOperator.SET, ValueType.f64, codePos, lineNumber );
|
addArrayInstruction( ArrayOperator.SET, ValueType.f64, codePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
case 83: // aastore
|
case 83: // aastore
|
||||||
storeType = findPreviousPushInstructionPushValueType();
|
storeType = findValueTypeFromStack( 1 );
|
||||||
addArrayInstruction( ArrayOperator.SET, storeType, codePos, lineNumber );
|
addArrayInstruction( ArrayOperator.SET, storeType, codePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
case 84: // bastore
|
case 84: // bastore
|
||||||
@ -279,7 +279,7 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
|||||||
break;
|
break;
|
||||||
case 89: // dup: duplicate the value on top of the stack
|
case 89: // dup: duplicate the value on top of the stack
|
||||||
case 92: // dup2
|
case 92: // dup2
|
||||||
storeType = findPreviousPushInstructionPushValueType();
|
storeType = findValueTypeFromStack( 1 );
|
||||||
addCallInstruction( new SyntheticFunctionName( "dup"
|
addCallInstruction( new SyntheticFunctionName( "dup"
|
||||||
+ storeType, "local.get 0 local.get 0 return", storeType, null, storeType, storeType ), codePos, lineNumber );
|
+ storeType, "local.get 0 local.get 0 return", storeType, null, storeType, storeType ), codePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
@ -768,17 +768,19 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
|||||||
/**
|
/**
|
||||||
* We need the value type from the stack.
|
* We need the value type from the stack.
|
||||||
*
|
*
|
||||||
|
* @param count
|
||||||
|
* the count of values on the stack back. 1 means the last value. 2 means the penultimate value.
|
||||||
* @return the type of the last push value
|
* @return the type of the last push value
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private AnyType findPreviousPushInstructionPushValueType() {
|
private AnyType findValueTypeFromStack( int count ) {
|
||||||
int valueCount = 0;
|
int valueCount = 0;
|
||||||
List<WasmInstruction> instructions = getInstructions();
|
List<WasmInstruction> instructions = getInstructions();
|
||||||
for( int i = instructions.size() - 1; i >= 0; i-- ) {
|
for( int i = instructions.size() - 1; i >= 0; i-- ) {
|
||||||
WasmInstruction instr = instructions.get( i );
|
WasmInstruction instr = instructions.get( i );
|
||||||
AnyType valueType = instr.getPushValueType();
|
AnyType valueType = instr.getPushValueType();
|
||||||
if( valueType != null ) {
|
if( valueType != null ) {
|
||||||
if( ++valueCount == 1 ) {
|
if( ++valueCount == count ) {
|
||||||
return valueType;
|
return valueType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,6 @@ class LocaleVariableManager {
|
|||||||
names.clear();
|
names.clear();
|
||||||
for( int i = 0; i < size; i++ ) {
|
for( int i = 0; i < size; i++ ) {
|
||||||
Variable var = variables[i];
|
Variable var = variables[i];
|
||||||
var.valueType = null; // TODO temporary hack
|
|
||||||
var.name = findUniqueVarName( var.name );
|
var.name = findUniqueVarName( var.name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user