mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Wasm backend: fix many tests
This commit is contained in:
parent
5e3514e5dd
commit
f23128bb13
|
@ -234,8 +234,7 @@ public class TStreamTokenizer {
|
|||
}
|
||||
}
|
||||
peekChar = currentChar;
|
||||
sval = forceLowercase ? word.toString().toLowerCase() : word
|
||||
.toString();
|
||||
sval = forceLowercase ? word.toString().toLowerCase() : word.toString();
|
||||
ttype = TT_WORD;
|
||||
return ttype;
|
||||
}
|
||||
|
|
|
@ -40,8 +40,12 @@ public class TRandom extends TObject implements TSerializable {
|
|||
}
|
||||
|
||||
protected int next(int bits) {
|
||||
if (bits == 32) {
|
||||
return (int) (nextDouble() * ((1L << 32) - 1) + Integer.MIN_VALUE);
|
||||
} else {
|
||||
return (int) (nextDouble() * (1L << TMath.min(32, bits)));
|
||||
}
|
||||
}
|
||||
|
||||
public void nextBytes(byte[] bytes) {
|
||||
for (int i = 0; i < bytes.length; ++i) {
|
||||
|
|
|
@ -129,6 +129,7 @@ public final class WasmRuntime {
|
|||
public static void moveMemoryBlock(Address source, Address target, int count) {
|
||||
if (count < 8) {
|
||||
slowMemoryMove(source, target, count);
|
||||
return;
|
||||
}
|
||||
int diff = source.toInt() - target.toInt();
|
||||
if (diff == 0) {
|
||||
|
|
|
@ -94,6 +94,7 @@ import org.teavm.model.CallLocation;
|
|||
import org.teavm.model.ClassHolder;
|
||||
import org.teavm.model.ClassHolderTransformer;
|
||||
import org.teavm.model.ClassReader;
|
||||
import org.teavm.model.ClassReaderSource;
|
||||
import org.teavm.model.ElementModifier;
|
||||
import org.teavm.model.FieldReader;
|
||||
import org.teavm.model.FieldReference;
|
||||
|
@ -325,7 +326,7 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
|||
context.addIntrinsic(new PlatformClassMetadataIntrinsic());
|
||||
context.addIntrinsic(new ClassIntrinsic());
|
||||
|
||||
IntrinsicFactoryContext intrinsicFactoryContext = new IntrinsicFactoryContext(classes);
|
||||
IntrinsicFactoryContext intrinsicFactoryContext = new IntrinsicFactoryContext();
|
||||
for (WasmIntrinsicFactory additionalIntrinsicFactory : additionalIntrinsics) {
|
||||
context.addIntrinsic(additionalIntrinsicFactory.create(intrinsicFactoryContext));
|
||||
}
|
||||
|
@ -416,15 +417,9 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
|||
}
|
||||
|
||||
private class IntrinsicFactoryContext implements WasmIntrinsicFactoryContext {
|
||||
private ListableClassReaderSource classSource;
|
||||
|
||||
IntrinsicFactoryContext(ListableClassReaderSource classSource) {
|
||||
this.classSource = classSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListableClassReaderSource getClassSource() {
|
||||
return classSource;
|
||||
public ClassReaderSource getClassSource() {
|
||||
return controller.getUnprocessedClassSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -175,8 +175,10 @@ public class WasmClassGenerator {
|
|||
binaryData.data.setInt(CLASS_IS_INSTANCE, functionTable.size());
|
||||
binaryData.data.setInt(CLASS_CANARY, RuntimeClass.computeCanary(4, 0));
|
||||
functionTable.add(names.forSupertypeFunction(type));
|
||||
binaryData.data.setAddress(CLASS_NAME, stringPool.getStringPointer(type.toString()));
|
||||
binaryData.data.setAddress(CLASS_SIMPLE_NAME, 0);
|
||||
binaryData.data.setInt(CLASS_INIT, -1);
|
||||
binaryData.data.setAddress(CLASS_PARENT, getClassPointer(ValueType.object("java.lang.Object")));
|
||||
binaryData.start = binaryWriter.append(vtableSize > 0 ? wrapper : binaryData.data);
|
||||
|
||||
itemBinaryData.data.setAddress(CLASS_ARRAY_TYPE, binaryData.start);
|
||||
|
@ -428,7 +430,11 @@ public class WasmClassGenerator {
|
|||
int desiredAlignment = getTypeSize(field.getType());
|
||||
if (field.hasModifier(ElementModifier.STATIC)) {
|
||||
DataType type = asDataType(field.getType());
|
||||
data.fieldLayout.put(field.getName(), binaryWriter.append(type.createValue()));
|
||||
DataValue value = type.createValue();
|
||||
if (field.getInitialValue() != null) {
|
||||
setInitialValue(field.getType(), value, field.getInitialValue());
|
||||
}
|
||||
data.fieldLayout.put(field.getName(), binaryWriter.append(value));
|
||||
} else {
|
||||
int offset = align(data.size, desiredAlignment);
|
||||
data.fieldLayout.put(field.getName(), offset);
|
||||
|
@ -440,6 +446,41 @@ public class WasmClassGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
private void setInitialValue(ValueType type, DataValue data, Object value) {
|
||||
if (value instanceof Number) {
|
||||
switch (((ValueType.Primitive) type).getKind()) {
|
||||
case BYTE:
|
||||
data.setByte(0, ((Number) value).byteValue());
|
||||
break;
|
||||
case SHORT:
|
||||
data.setShort(0, ((Number) value).shortValue());
|
||||
break;
|
||||
case CHARACTER:
|
||||
data.setShort(0, ((Number) value).shortValue());
|
||||
break;
|
||||
case INTEGER:
|
||||
data.setInt(0, ((Number) value).intValue());
|
||||
break;
|
||||
case LONG:
|
||||
data.setLong(0, ((Number) value).longValue());
|
||||
break;
|
||||
case FLOAT:
|
||||
data.setFloat(0, ((Number) value).floatValue());
|
||||
break;
|
||||
case DOUBLE:
|
||||
data.setDouble(0, ((Number) value).doubleValue());
|
||||
break;
|
||||
case BOOLEAN:
|
||||
data.setByte(0, ((Number) value).byteValue());
|
||||
break;
|
||||
}
|
||||
} else if (value instanceof Boolean) {
|
||||
data.setByte(0, (Boolean) value ? (byte) 1 : 0);
|
||||
} else if (value instanceof String) {
|
||||
data.setAddress(0, stringPool.getStringPointer((String) value));
|
||||
}
|
||||
}
|
||||
|
||||
private static DataType asDataType(ValueType type) {
|
||||
if (type instanceof ValueType.Primitive) {
|
||||
switch (((ValueType.Primitive) type).getKind()) {
|
||||
|
|
|
@ -813,7 +813,7 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
|
|||
|
||||
private void translateSwitchToWasmSwitch(SwitchStatement statement, WasmExpression condition,
|
||||
WasmBlock initialWrapper, WasmBlock defaultTarget, WasmBlock[] targets, int min, int max) {
|
||||
if (min > 0) {
|
||||
if (min != 0) {
|
||||
condition = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SUB, condition,
|
||||
new WasmInt32Constant(min));
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ public class PlatformIntrinsic implements WasmIntrinsic {
|
|||
switch (methodDescriptor.getName()) {
|
||||
case "getPlatformObject":
|
||||
case "asJavaClass":
|
||||
case "getName":
|
||||
case "createQueue":
|
||||
return true;
|
||||
default:
|
||||
|
@ -48,7 +47,6 @@ public class PlatformIntrinsic implements WasmIntrinsic {
|
|||
case "getPlatformObject":
|
||||
case "asJavaClass":
|
||||
return manager.generate(invocation.getArguments().get(0));
|
||||
case "getName":
|
||||
case "createQueue":
|
||||
return new WasmInt32Constant(0);
|
||||
default:
|
||||
|
|
|
@ -17,10 +17,10 @@ package org.teavm.backend.wasm.intrinsics;
|
|||
|
||||
import java.util.Properties;
|
||||
import org.teavm.common.ServiceRepository;
|
||||
import org.teavm.model.ListableClassReaderSource;
|
||||
import org.teavm.model.ClassReaderSource;
|
||||
|
||||
public interface WasmIntrinsicFactoryContext {
|
||||
ListableClassReaderSource getClassSource();
|
||||
ClassReaderSource getClassSource();
|
||||
|
||||
ClassLoader getClassLoader();
|
||||
|
||||
|
|
|
@ -308,13 +308,25 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor {
|
|||
|
||||
@Override
|
||||
public void visit(WasmFloat32Constant expression) {
|
||||
if (Float.isInfinite(expression.getValue())) {
|
||||
value = CExpression.relocatable(expression.getValue() < 0 ? "-INFINITY" : "INFINITY");
|
||||
} else if (Float.isNaN(expression.getValue())) {
|
||||
value = CExpression.relocatable("NAN");
|
||||
} else {
|
||||
value = CExpression.relocatable(Float.toHexString(expression.getValue()) + "F");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(WasmFloat64Constant expression) {
|
||||
if (Double.isInfinite(expression.getValue())) {
|
||||
value = CExpression.relocatable(expression.getValue() < 0 ? "-INFINITY" : "INFINITY");
|
||||
} else if (Double.isNaN(expression.getValue())) {
|
||||
value = CExpression.relocatable("NAN");
|
||||
} else {
|
||||
value = CExpression.relocatable(Double.toHexString(expression.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(WasmGetLocal expression) {
|
||||
|
|
|
@ -78,9 +78,11 @@ public class VirtualTableProvider {
|
|||
Set<MethodDescriptor> newDescriptors = virtualMethodMap.get(className);
|
||||
if (newDescriptors != null) {
|
||||
for (MethodDescriptor method : newDescriptors) {
|
||||
if (!table.entries.containsKey(method)) {
|
||||
table.entries.put(method, new VirtualTableEntry(table, method, null, table.entries.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (MethodReader method : cls.getMethods()) {
|
||||
if (method.hasModifier(ElementModifier.ABSTRACT)) {
|
||||
|
|
|
@ -6,7 +6,15 @@
|
|||
#include <math.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <time.h>
|
||||
|
||||
static inline float TeaVM_getNaN() {
|
||||
return NAN;
|
||||
}
|
||||
|
||||
static int64_t currentTimeMillis() {
|
||||
struct timespec time;
|
||||
clock_gettime(CLOCK_REALTIME, &time);
|
||||
|
||||
return time.tv_sec * 1000 + (int64_t) round(time.tv_nsec / 1000000);
|
||||
}
|
|
@ -227,6 +227,7 @@ public final class Platform {
|
|||
return cls.getMetadata().getArrayItem();
|
||||
}
|
||||
|
||||
@Unmanaged
|
||||
public static String getName(PlatformClass cls) {
|
||||
return cls.getMetadata().getName();
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.teavm.backend.wasm.model.expression.WasmExpression;
|
|||
import org.teavm.backend.wasm.model.expression.WasmInt32Constant;
|
||||
import org.teavm.common.ServiceRepository;
|
||||
import org.teavm.model.CallLocation;
|
||||
import org.teavm.model.ListableClassReaderSource;
|
||||
import org.teavm.model.ClassReaderSource;
|
||||
import org.teavm.model.MethodReader;
|
||||
import org.teavm.model.MethodReference;
|
||||
import org.teavm.platform.metadata.MetadataGenerator;
|
||||
|
@ -41,13 +41,13 @@ import org.teavm.platform.metadata.MetadataProvider;
|
|||
import org.teavm.platform.metadata.Resource;
|
||||
|
||||
public class MetadataIntrinsic implements WasmIntrinsic {
|
||||
private ListableClassReaderSource classSource;
|
||||
private ClassReaderSource classSource;
|
||||
private ClassLoader classLoader;
|
||||
private ServiceRepository services;
|
||||
private Properties properties;
|
||||
private Map<ResourceTypeDescriptor, DataStructure> resourceTypeCache = new HashMap<>();
|
||||
|
||||
public MetadataIntrinsic(ListableClassReaderSource classSource, ClassLoader classLoader,
|
||||
public MetadataIntrinsic(ClassReaderSource classSource, ClassLoader classLoader,
|
||||
ServiceRepository services, Properties properties) {
|
||||
this.classSource = classSource;
|
||||
this.classLoader = classLoader;
|
||||
|
|
|
@ -287,7 +287,7 @@ public class StreamTokenizerTest {
|
|||
public void test_toString() throws IOException {
|
||||
setTest("ABC Hello World");
|
||||
st.nextToken();
|
||||
assertTrue("toString failed." + st.toString(), st.toString().equals("Token[ABC], line 1"));
|
||||
assertEquals("toString failed.", "Token[ABC], line 1", st.toString());
|
||||
|
||||
// Regression test for HARMONY-4070
|
||||
byte[] data = new byte[] { (byte) '-' };
|
||||
|
|
Loading…
Reference in New Issue
Block a user