mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 00:04:10 -08:00
wasm gc: fix remaining issues that prevent running trivial example
This commit is contained in:
parent
54dc7fe5f8
commit
9b5e1e7661
|
@ -24,7 +24,7 @@ public class JSStdoutPrintStream extends JsConsolePrintStream {
|
|||
public void print(String s) {
|
||||
if (PlatformDetector.isWebAssemblyGC()) {
|
||||
for (int i = 0; i < s.length(); ++i) {
|
||||
WasmGCSupport.putCharStderr(s.charAt(i));
|
||||
WasmGCSupport.putCharStdout(s.charAt(i));
|
||||
}
|
||||
} else {
|
||||
writeJs(s);
|
||||
|
|
|
@ -125,10 +125,11 @@ public class WasmGCDeclarationsGenerator {
|
|||
}
|
||||
|
||||
public void contributeToInitializer(WasmFunction function) {
|
||||
classGenerator.contributeToInitializer(function);
|
||||
var contributors = List.of(classGenerator, classGenerator.strings);
|
||||
for (var contributor : contributors) {
|
||||
contributor.contributeToInitializerDefinitions(function);
|
||||
}
|
||||
for (var contributor : contributors) {
|
||||
contributor.contributeToInitializer(function);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class WasmGCStringPool implements WasmGCStringProvider, WasmGCInitializer
|
|||
if (nextCharArrayFunction == null) {
|
||||
initNextCharArrayFunction();
|
||||
}
|
||||
binaryWriter.writeInt32(string.length());
|
||||
binaryWriter.writeLEB(string.length());
|
||||
binaryWriter.writeBytes(string.getBytes(StandardCharsets.UTF_8));
|
||||
var globalName = "teavm_java_string_" + stringMap.size();
|
||||
var globalType = standardClasses.stringClass().getType();
|
||||
|
|
|
@ -20,11 +20,15 @@ import org.teavm.backend.wasm.model.WasmGlobal;
|
|||
import org.teavm.backend.wasm.model.WasmLocal;
|
||||
import org.teavm.backend.wasm.model.WasmType;
|
||||
import org.teavm.backend.wasm.model.expression.WasmGetGlobal;
|
||||
import org.teavm.backend.wasm.model.expression.WasmGetLocal;
|
||||
import org.teavm.backend.wasm.model.expression.WasmInt32Constant;
|
||||
import org.teavm.backend.wasm.model.expression.WasmInt32Subtype;
|
||||
import org.teavm.backend.wasm.model.expression.WasmIntBinary;
|
||||
import org.teavm.backend.wasm.model.expression.WasmIntBinaryOperation;
|
||||
import org.teavm.backend.wasm.model.expression.WasmIntType;
|
||||
import org.teavm.backend.wasm.model.expression.WasmLoadInt32;
|
||||
import org.teavm.backend.wasm.model.expression.WasmReturn;
|
||||
import org.teavm.backend.wasm.model.expression.WasmSetGlobal;
|
||||
import org.teavm.backend.wasm.model.expression.WasmSetLocal;
|
||||
import org.teavm.model.MethodReference;
|
||||
|
||||
|
@ -38,9 +42,11 @@ public class WasmGCStringPoolGenerator implements WasmGCCustomGenerator {
|
|||
var resultLocal = new WasmLocal(WasmType.INT32);
|
||||
function.add(resultLocal);
|
||||
|
||||
function.getBody().add(new WasmSetLocal(resultLocal, new WasmLoadInt32(1, new WasmGetGlobal(pointer),
|
||||
WasmInt32Subtype.UINT8)));
|
||||
var increment = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.ADD,
|
||||
new WasmGetGlobal(pointer), new WasmInt32Constant(1));
|
||||
function.getBody().add(new WasmSetLocal(resultLocal, increment));
|
||||
function.getBody().add(new WasmReturn(new WasmGetGlobal(pointer)));
|
||||
function.getBody().add(new WasmSetGlobal(pointer, increment));
|
||||
function.getBody().add(new WasmReturn(new WasmGetLocal(resultLocal)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -477,6 +477,23 @@ public class WasmBinaryRenderer {
|
|||
section.writeBytes(payload);
|
||||
}
|
||||
|
||||
var globals = module.globals.stream()
|
||||
.filter(g -> g.getName() != null)
|
||||
.collect(Collectors.toList());
|
||||
if (!globals.isEmpty()) {
|
||||
var globalsSubsection = new WasmBinaryWriter();
|
||||
globalsSubsection.writeLEB(globals.size());
|
||||
for (var global : globals) {
|
||||
globalsSubsection.writeLEB(module.globals.indexOf(global));
|
||||
globalsSubsection.writeAsciiString(global.getName());
|
||||
}
|
||||
|
||||
payload = globalsSubsection.getData();
|
||||
section.writeLEB(7);
|
||||
section.writeLEB(payload.length);
|
||||
section.writeBytes(payload);
|
||||
}
|
||||
|
||||
writeSection(SECTION_UNKNOWN, "name", section.getData());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user