aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-06-08 11:20:39 +0100
committergingerBill <bill@gingerbill.org>2021-06-08 11:20:39 +0100
commit16eaa17ed988e8a04cc75d8aae3cdea4bd56ad9d (patch)
tree3a3298da10da8446d289c3294089d7ab587e7ce4
parent9491c13a5c967ff0fa6d5ce3c330dcbf13888d6c (diff)
Fix `-target:js_wasm32` for `core:runtime`
-rw-r--r--core/os/os_js_wasm32.odin5
-rw-r--r--core/runtime/default_allocators_general.odin30
-rw-r--r--core/runtime/default_allocators_nil.odin17
-rw-r--r--core/runtime/default_allocators_windows.odin39
-rw-r--r--core/runtime/default_temporary_allocator.odin (renamed from core/runtime/default_allocators.odin)65
-rw-r--r--core/runtime/os_specific_any.odin1
6 files changed, 90 insertions, 67 deletions
diff --git a/core/os/os_js_wasm32.odin b/core/os/os_js_wasm32.odin
index 683e4a501..b70bdda1a 100644
--- a/core/os/os_js_wasm32.odin
+++ b/core/os/os_js_wasm32.odin
@@ -35,8 +35,9 @@ open :: proc(path: string, mode: int = O_RDONLY, perm: int = 0) -> (Handle, Errn
close :: proc(fd: Handle) -> Errno {
return 0;
}
-
-
+seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
+ return 0, 0;
+}
current_thread_id :: proc "contextless" () -> int {
return 0;
}
diff --git a/core/runtime/default_allocators_general.odin b/core/runtime/default_allocators_general.odin
new file mode 100644
index 000000000..8f598b7a1
--- /dev/null
+++ b/core/runtime/default_allocators_general.odin
@@ -0,0 +1,30 @@
+//+build !windows
+//+build !freestanding
+//+build !js
+package runtime
+
+when ODIN_DEFAULT_TO_NIL_ALLOCATOR {
+ // mem.nil_allocator reimplementation
+
+ default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
+ size, alignment: int,
+ old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, Allocator_Error) {
+ return nil, .None;
+ }
+
+ default_allocator :: proc() -> Allocator {
+ return Allocator{
+ procedure = default_allocator_proc,
+ data = nil,
+ };
+ }
+} else {
+ // TODO(bill): reimplement these procedures in the os_specific stuff
+ import "core:os"
+
+ default_allocator_proc :: os.heap_allocator_proc;
+
+ default_allocator :: proc() -> Allocator {
+ return os.heap_allocator();
+ }
+}
diff --git a/core/runtime/default_allocators_nil.odin b/core/runtime/default_allocators_nil.odin
new file mode 100644
index 000000000..4e1d7a1d3
--- /dev/null
+++ b/core/runtime/default_allocators_nil.odin
@@ -0,0 +1,17 @@
+//+build freestanding, js
+package runtime
+
+// mem.nil_allocator reimplementation
+
+default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
+ size, alignment: int,
+ old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, Allocator_Error) {
+ return nil, .None;
+}
+
+default_allocator :: proc() -> Allocator {
+ return Allocator{
+ procedure = default_allocator_proc,
+ data = nil,
+ };
+}
diff --git a/core/runtime/default_allocators_windows.odin b/core/runtime/default_allocators_windows.odin
new file mode 100644
index 000000000..64b2dd23e
--- /dev/null
+++ b/core/runtime/default_allocators_windows.odin
@@ -0,0 +1,39 @@
+//+build windows
+package runtime
+
+default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
+ size, alignment: int,
+ old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, Allocator_Error) {
+ switch mode {
+ case .Alloc:
+ return _windows_default_alloc(size, alignment);
+
+ case .Free:
+ _windows_default_free(old_memory);
+
+ case .Free_All:
+ // NOTE(tetra): Do nothing.
+
+ case .Resize:
+ return _windows_default_resize(old_memory, old_size, size, alignment);
+
+ case .Query_Features:
+ set := (^Allocator_Mode_Set)(old_memory);
+ if set != nil {
+ set^ = {.Alloc, .Free, .Resize, .Query_Features};
+ }
+ return nil, nil;
+
+ case .Query_Info:
+ return nil, nil;
+ }
+
+ return nil, nil;
+}
+
+default_allocator :: proc() -> Allocator {
+ return Allocator{
+ procedure = default_allocator_proc,
+ data = nil,
+ };
+}
diff --git a/core/runtime/default_allocators.odin b/core/runtime/default_temporary_allocator.odin
index 86fce47ae..f5bad2a7d 100644
--- a/core/runtime/default_allocators.odin
+++ b/core/runtime/default_temporary_allocator.odin
@@ -1,70 +1,5 @@
package runtime
-when ODIN_DEFAULT_TO_NIL_ALLOCATOR || ODIN_OS == "freestanding" || ODIN_OS == "js" {
- // mem.nil_allocator reimplementation
-
- default_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,
- size, alignment: int,
- old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, Allocator_Error) {
- return nil, .None;
- }
-
- default_allocator :: proc() -> Allocator {
- return Allocator{
- procedure = default_allocator_proc,
- data = nil,
- };
- }
-
-} else when ODIN_OS == "windows" {
- default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
- size, alignment: int,
- old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, Allocator_Error) {
- switch mode {
- case .Alloc:
- return _windows_default_alloc(size, alignment);
-
- case .Free:
- _windows_default_free(old_memory);
-
- case .Free_All:
- // NOTE(tetra): Do nothing.
-
- case .Resize:
- return _windows_default_resize(old_memory, old_size, size, alignment);
-
- case .Query_Features:
- set := (^Allocator_Mode_Set)(old_memory);
- if set != nil {
- set^ = {.Alloc, .Free, .Resize, .Query_Features};
- }
- return nil, nil;
-
- case .Query_Info:
- return nil, nil;
- }
-
- return nil, nil;
- }
-
- default_allocator :: proc() -> Allocator {
- return Allocator{
- procedure = default_allocator_proc,
- data = nil,
- };
- }
-
-} else {
- // TODO(bill): reimplement these procedures in the os_specific stuff
- import "core:os"
-
- default_allocator_proc :: os.heap_allocator_proc;
-
- default_allocator :: proc() -> Allocator {
- return os.heap_allocator();
- }
-}
-
@(private)
byte_slice :: #force_inline proc "contextless" (data: rawptr, len: int) -> []byte {
return transmute([]u8)Raw_Slice{data=data, len=max(len, 0)};
diff --git a/core/runtime/os_specific_any.odin b/core/runtime/os_specific_any.odin
index 9c2686661..5a8fd2e94 100644
--- a/core/runtime/os_specific_any.odin
+++ b/core/runtime/os_specific_any.odin
@@ -1,5 +1,6 @@
//+build !freestanding
//+build !windows
+//+build !js
package runtime
import "core:os"