Open km19809 opened 1 year ago
The WebAssembly backend does not support importing the os
module. .js.v
and .c.v
files are also not properly discriminated against. The backend is currently WIP right now, I will keep these in mind.
Then how can I read from stdin?
os.input
is the only input function I know.
Is there any workaround?
@km19809 you can build for WASM via emscripten for now
-os wasm32-emscripten
I tried -os wasm32=emscripten
which generates a JS file and a WASM.
The code compiles but prints -b js
.
Somehow, a simple echo going tough...
I should try WASM.fd_read
.
WASM.fd_read
is currently not implemented in the standard library yet, only WASM.fd_write
. You can find a reference implementation for WASM.fd_write
to help you out inside vlib/builtin/wasm/wasi/wasi.v
.
Describe the bug
I compiled my calculator code, which runs successfully in Ubuntu 20.04. (
v calc.v
) However, when I usev -b wasm calc.v
, it throws an error aboutos.File
.My code (
calc.v
):The calculator module only uses math, random, and datatypes. It does not use any
os
function or struct.calc.v
is the only place that I useos
module.Expected Behavior
It should be compiled into WASI binary.
Current Behavior
It throws:
Reproduction Steps
I made a sample code to reproduce (
echo.v
):Then run
v -b wasm echo.v
.Possible Solution
I assume that
-b wasm
tries to compile bothvlib/os/file.c.v
andvlib/os/file.js.v
. I've searched all the files in the os module forstruct File {
, butvlib/os/file.c.v
andvlib/os/file.js.v
were only occurrences. Also, if I tryv -b js echo.v
instead, it compiles into js. I suspect that WASM backend tries to compile all the.v
files.I made an example to prove it:
main.v
:sus.c.v
:sus.js.v
:The result of
v -b wasm main.v
:Additional Information/Context
No response
V version
V 0.3.3 130f35c
Environment details (OS name and version, etc.)
V full version: V 0.3.3 130f35c OS: linux, Ubuntu 20.04.6 LTS (WSL 2) Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
getwd: /mnt/c/Users//Desktop/py&others/velegram
vexe: /home//hobby/v/v
vexe mtime: 2023-03-26 14:15:10
vroot: OK, value: /home//hobby/v
VMODULES: OK, value: /home//.vmodules
VTMP: OK, value: /tmp/v_1000
Git version: git version 2.25.1 Git vroot status: weekly.2023.12-35-g130f35c7 .git/config present: true
CC version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 thirdparty/tcc status: thirdparty-linux-amd64 12f392c3