Made most libraries panic on js targets instead of not compiling

This commit is contained in:
Dragos Popescu
2023-03-20 04:08:48 +01:00
parent fe533fb809
commit adac039a2b
7 changed files with 569 additions and 2 deletions
+15
View File
@@ -0,0 +1,15 @@
//+build js
//+private
package dynlib
_load_library :: proc(path: string, global_symbols := false) -> (Library, bool) {
panic("core:dynlib not supported by JS target")
}
_unload_library :: proc(library: Library) -> bool {
panic("core:dynlib not supported by JS target")
}
_symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found: bool) {
panic("core:dynlib not supported by JS target")
}
+161 -2
View File
@@ -1,4 +1,163 @@
//+build js
package os
// +build js
#panic("package os does not support a js target")
import "core:intrinsics"
import "core:runtime"
import "core:unicode/utf16"
is_path_separator :: proc(c: byte) -> bool {
return c == '/' || c == '\\'
}
open :: proc(path: string, mode: int = O_RDONLY, perm: int = 0) -> (Handle, Errno) {
panic("core:os procedure not supported on JS target")
}
close :: proc(fd: Handle) -> Errno {
panic("core:os procedure not supported on JS target")
}
flush :: proc(fd: Handle) -> (err: Errno) {
panic("core:os procedure not supported on JS target")
}
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
panic("core:os procedure not supported on JS target")
}
@(private="file")
read_console :: proc(handle: win32.HANDLE, b: []byte) -> (n: int, err: Errno) {
panic("core:os procedure not supported on JS target")
}
read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
panic("core:os procedure not supported on JS target")
}
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
panic("core:os procedure not supported on JS target")
}
file_size :: proc(fd: Handle) -> (i64, Errno) {
panic("core:os procedure not supported on JS target")
}
@(private)
MAX_RW :: 1<<30
@(private)
pread :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
panic("core:os procedure not supported on JS target")
}
@(private)
pwrite :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
panic("core:os procedure not supported on JS target")
}
read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Errno) {
panic("core:os procedure not supported on JS target")
}
write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Errno) {
panic("core:os procedure not supported on JS target")
}
// NOTE(bill): Uses startup to initialize it
//stdin := get_std_handle(uint(win32.STD_INPUT_HANDLE))
//stdout := get_std_handle(uint(win32.STD_OUTPUT_HANDLE))
//stderr := get_std_handle(uint(win32.STD_ERROR_HANDLE))
get_std_handle :: proc "contextless" (h: uint) -> Handle {
panic("core:os procedure not supported on JS target")
}
exists :: proc(path: string) -> bool {
panic("core:os procedure not supported on JS target")
}
is_file :: proc(path: string) -> bool {
panic("core:os procedure not supported on JS target")
}
is_dir :: proc(path: string) -> bool {
panic("core:os procedure not supported on JS target")
}
// NOTE(tetra): GetCurrentDirectory is not thread safe with SetCurrentDirectory and GetFullPathName
//@private cwd_lock := win32.SRWLOCK{} // zero is initialized
get_current_directory :: proc(allocator := context.allocator) -> string {
panic("core:os procedure not supported on JS target")
}
set_current_directory :: proc(path: string) -> (err: Errno) {
panic("core:os procedure not supported on JS target")
}
change_directory :: proc(path: string) -> (err: Errno) {
panic("core:os procedure not supported on JS target")
}
make_directory :: proc(path: string, mode: u32 = 0) -> (err: Errno) {
panic("core:os procedure not supported on JS target")
}
remove_directory :: proc(path: string) -> (err: Errno) {
panic("core:os procedure not supported on JS target")
}
@(private)
is_abs :: proc(path: string) -> bool {
panic("core:os procedure not supported on JS target")
}
@(private)
fix_long_path :: proc(path: string) -> string {
panic("core:os procedure not supported on JS target")
}
link :: proc(old_name, new_name: string) -> (err: Errno) {
panic("core:os procedure not supported on JS target")
}
unlink :: proc(path: string) -> (err: Errno) {
panic("core:os procedure not supported on JS target")
}
rename :: proc(old_path, new_path: string) -> (err: Errno) {
panic("core:os procedure not supported on JS target")
}
ftruncate :: proc(fd: Handle, length: i64) -> (err: Errno) {
panic("core:os procedure not supported on JS target")
}
truncate :: proc(path: string, length: i64) -> (err: Errno) {
panic("core:os procedure not supported on JS target")
}
remove :: proc(name: string) -> Errno {
panic("core:os procedure not supported on JS target")
}
pipe :: proc() -> (r, w: Handle, err: Errno) {
panic("core:os procedure not supported on JS target")
}
+55
View File
@@ -0,0 +1,55 @@
//+build js
package thread
import "core:intrinsics"
import "core:sync"
import "core:mem"
Thread_State :: enum u8 {
Started,
Joined,
Done,
}
Thread_Os_Specific :: struct {
}
_thread_priority_map := [Thread_Priority]i32{
.Normal = 0,
.Low = -2,
.High = +2,
}
_create :: proc(procedure: Thread_Proc, priority := Thread_Priority.Normal) -> ^Thread {
panic("core:thread procedure not supported on js target")
}
_start :: proc(t: ^Thread) {
panic("core:thread procedure not supported on js target")
}
_is_done :: proc(t: ^Thread) -> bool {
panic("core:thread procedure not supported on js target")
}
_join :: proc(t: ^Thread) {
panic("core:thread procedure not supported on js target")
}
_join_multiple :: proc(threads: ..^Thread) {
panic("core:thread procedure not supported on js target")
}
_destroy :: proc(thread: ^Thread) {
panic("core:thread procedure not supported on js target")
}
_terminate :: proc(using thread : ^Thread, exit_code: int) {
panic("core:thread procedure not supported on js target")
}
_yield :: proc() {
panic("core:thread procedure not supported on js target")
}