os_specific_orca.odin 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #+build orca
  2. #+private
  3. package runtime
  4. import "base:intrinsics"
  5. // Constants allowing to specify the level of logging verbosity.
  6. log_level :: enum u32 {
  7. // Only errors are logged.
  8. ERROR = 0,
  9. // Only warnings and errors are logged.
  10. WARNING = 1,
  11. // All messages are logged.
  12. INFO = 2,
  13. COUNT = 3,
  14. }
  15. @(default_calling_convention="c", link_prefix="oc_")
  16. foreign {
  17. abort_ext :: proc(file: cstring, function: cstring, line: i32, fmt: cstring, #c_vararg args: ..any) -> ! ---
  18. assert_fail :: proc(file: cstring, function: cstring, line: i32, src: cstring, fmt: cstring, #c_vararg args: ..any) -> ! ---
  19. log_ext :: proc(level: log_level, function: cstring, file: cstring, line: i32, fmt: cstring, #c_vararg args: ..any) ---
  20. }
  21. // NOTE: This is all pretty gross, don't look.
  22. // WASM is single threaded so this should be fine.
  23. orca_stderr_buffer: [4096]byte
  24. orca_stderr_buffer_idx: int
  25. _stderr_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
  26. for b in data {
  27. orca_stderr_buffer[orca_stderr_buffer_idx] = b
  28. orca_stderr_buffer_idx += 1
  29. if b == '\n' || orca_stderr_buffer_idx == len(orca_stderr_buffer)-1 {
  30. log_ext(.ERROR, "", "", 0, cstring(raw_data(orca_stderr_buffer[:orca_stderr_buffer_idx])))
  31. orca_stderr_buffer_idx = 0
  32. }
  33. }
  34. return len(data), 0
  35. }