diff --git a/core/src/main/java/org/teavm/backend/wasm/render/WasmCRenderingVisitor.java b/core/src/main/java/org/teavm/backend/wasm/render/WasmCRenderingVisitor.java index 11bbf00aa..19381165a 100644 --- a/core/src/main/java/org/teavm/backend/wasm/render/WasmCRenderingVisitor.java +++ b/core/src/main/java/org/teavm/backend/wasm/render/WasmCRenderingVisitor.java @@ -1064,20 +1064,24 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor { public void visit(WasmFill expression) { var result = new CExpression(); + requiredType = WasmType.INT32; expression.getIndex().acceptVisitor(this); var dest = value; + requiredType = WasmType.INT32; expression.getValue().acceptVisitor(this); var v = value; - expression.getValue().acceptVisitor(this); + requiredType = WasmType.INT32; + expression.getCount().acceptVisitor(this); var num = value; result.getLines().addAll(dest.getLines()); result.getLines().addAll(v.getLines()); result.getLines().addAll(num.getLines()); - result.addLine("memset(" + dest.getText() + ", " + v.getText() + ", " + num.getText() + ");"); + result.addLine("memset(wasm_heap + " + dest.getText() + ", " + v.getText() + + ", " + num.getText() + ");"); value = result; } @@ -1085,12 +1089,15 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor { public void visit(WasmCopy expression) { var result = new CExpression(); + requiredType = WasmType.INT32; expression.getDestinationIndex().acceptVisitor(this); var dest = value; + requiredType = WasmType.INT32; expression.getSourceIndex().acceptVisitor(this); var src = value; + requiredType = WasmType.INT32; expression.getCount().acceptVisitor(this); var num = value; @@ -1098,7 +1105,8 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor { result.getLines().addAll(src.getLines()); result.getLines().addAll(num.getLines()); - result.addLine("memcpy(" + dest.getText() + ", " + src.getText() + ", " + num.getText() + ");"); + result.addLine("memcpy(wasm_heap + " + dest.getText() + ", wasm_heap + " + src.getText() + ", " + + num.getText() + ");"); value = result; } diff --git a/core/src/main/resources/org/teavm/backend/wasm/wasm-runtime.c b/core/src/main/resources/org/teavm/backend/wasm/wasm-runtime.c index 5abdb5b22..3f6063157 100644 --- a/core/src/main/resources/org/teavm/backend/wasm/wasm-runtime.c +++ b/core/src/main/resources/org/teavm/backend/wasm/wasm-runtime.c @@ -21,7 +21,11 @@ static char** wasm_argv; #define teavmMath_ceil ceil #define teavmMath_floor floor -int64_t teavm_currentTimeMillis() { +double teavmMath_random() { + return rand() / (double) RAND_MAX; +} + +double teavm_currentTimeMillis() { struct timespec time; clock_gettime(CLOCK_REALTIME, &time); @@ -148,4 +152,11 @@ int32_t wasi_snapshot_preview1_fd_write(int32_t fd, int32_t iovs, int32_t count, int32_t* resultPtr = (int32_t*) (wasm_heap + result); *resultPtr = written; return 0; +} + +void teavm_putwcharsOut(int32_t chars, int32_t count) { + int16_t* chars_array = (int16_t*) (wasm_heap + chars); + for (int32_t i = 0; i < count; ++i) { + putwchar(chars_array[i]); + } } \ No newline at end of file