Begin work in semi-standardized js_wasm32 target

This commit is contained in:
gingerBill
2021-11-07 19:56:01 +00:00
parent 1296fabe2c
commit 518460af66
18 changed files with 215 additions and 66 deletions
+44
View File
@@ -0,0 +1,44 @@
//+build js
package fmt
import "core:io"
foreign import "odin_env"
@(private="file")
foreign odin_env {
write :: proc "c" (fd: u32, p: []byte) ---
}
@(private="file")
write_vtable := &io.Stream_VTable{
impl_write = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) {
fd := u32(uintptr(s.stream_data))
write(fd, p)
return len(p), nil
},
}
@(private="file")
stdout := io.Writer{
stream = {
stream_vtable = write_vtable,
stream_data = rawptr(uintptr(1)),
},
}
@(private="file")
stderr := io.Writer{
stream = {
stream_vtable = write_vtable,
stream_data = rawptr(uintptr(2)),
},
}
// print* procedures return the number of bytes written
print :: proc(args: ..any, sep := " ") -> int { return wprint(w=stdout, args=args, sep=sep) }
println :: proc(args: ..any, sep := " ") -> int { return wprintln(w=stdout, args=args, sep=sep) }
printf :: proc(fmt: string, args: ..any) -> int { return wprintf(stdout, fmt, ..args) }
eprint :: proc(args: ..any, sep := " ") -> int { return wprint(w=stderr, args=args, sep=sep) }
eprintln :: proc(args: ..any, sep := " ") -> int { return wprintln(w=stderr, args=args, sep=sep) }
eprintf :: proc(fmt: string, args: ..any) -> int { return wprintf(stderr, fmt, ..args) }
+1 -1
View File
@@ -1,4 +1,4 @@
//+build !freestanding
//+build !freestanding !js
package fmt
import "core:runtime"