mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 22:58:46 +00:00
Begin work in semi-standardized js_wasm32 target
This commit is contained in:
@@ -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,4 +1,4 @@
|
||||
//+build !freestanding
|
||||
//+build !freestanding !js
|
||||
package fmt
|
||||
|
||||
import "core:runtime"
|
||||
|
||||
Reference in New Issue
Block a user