WASM: add support of Character.toLowerCase/toUpperCase. Add _ prefix to names in c output

This commit is contained in:
Alexey Andreev 2016-09-17 12:37:49 +03:00
parent 558bcf1137
commit 0a00551af1
3 changed files with 20 additions and 2 deletions

View File

@ -16,6 +16,8 @@
package org.teavm.classlib.java.lang;
import org.teavm.classlib.impl.unicode.UnicodeHelper;
import org.teavm.interop.DelegateTo;
import org.teavm.interop.Import;
import org.teavm.platform.Platform;
import org.teavm.platform.metadata.MetadataProvider;
import org.teavm.platform.metadata.StringResource;
@ -231,18 +233,34 @@ public class TCharacter extends TObject implements TComparable<TCharacter> {
return (char) toLowerCase((int) ch);
}
@DelegateTo("toLowerCaseLowLevel")
public static int toLowerCase(int ch) {
return Platform.stringFromCharCode(ch).toLowerCase().charCodeAt(0);
}
private static int toLowerCaseLowLevel(int codePoint) {
return toLowerCaseSystem(codePoint);
}
@Import(module = "runtime", name = "towlower")
private static native int toLowerCaseSystem(int codePoint);
public static char toUpperCase(char ch) {
return (char) toUpperCase((int) ch);
}
@DelegateTo("toUpperCaseLowLevel")
public static int toUpperCase(int codePoint) {
return Platform.stringFromCharCode(codePoint).toUpperCase().charCodeAt(0);
}
private static int toUpperCaseLowLevel(int codePoint) {
return toUpperCaseSystem(codePoint);
}
@Import(module = "runtime", name = "towupper")
private static native int toUpperCaseSystem(int codePoint);
public static int digit(char ch, int radix) {
return digit((int) ch, radix);
}

View File

@ -83,7 +83,7 @@ public class WasmCRenderer {
for (WasmFunction function : module.getFunctions().values()) {
if (function.getExportName() != null && function.getExportName().equals("main")) {
line(function.getName() + "(0);");
line(function.getName() + "(1);");
}
}

View File

@ -1049,7 +1049,7 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor {
String result = localVariableNames[local.getIndex()];
if (result == null) {
if (local.getName() != null) {
result = local.getName();
result = "_" + local.getName();
} else {
result = "localVar" + local.getIndex();
}