diff --git a/lib/std/core/env.c3 b/lib/std/core/env.c3 index deea29b5c..f7d08cd68 100644 --- a/lib/std/core/env.c3 +++ b/lib/std/core/env.c3 @@ -154,7 +154,12 @@ const bool NETBSD = LIBC && OS_TYPE == NETBSD; const bool BSD_FAMILY = env::FREEBSD || env::OPENBSD || env::NETBSD; const bool WASI = LIBC && OS_TYPE == WASI; const bool ANDROID = LIBC && OS_TYPE == ANDROID; -const bool WASM_NOLIBC @builtin = !LIBC && ARCH_TYPE == ArchType.WASM32 || ARCH_TYPE == ArchType.WASM64; +const bool WASM_NOLIBC @builtin @deprecated("Use 'FREESTANDING_WASM' instead") = !LIBC && ARCH_TYPE == ArchType.WASM32 || ARCH_TYPE == ArchType.WASM64; +const bool FREESTANDING_PE32 = NO_LIBC && OS_TYPE == WIN32; +const bool FREESTANDING_MACHO = NO_LIBC && OS_TYPE == MACOS; +const bool FREESTANDING_ELF = NO_LIBC && !env::FREESTANDING_PE32 && !env::FREESTANDING_MACHO && !env::FREESTANDING_WASM; +const bool FREESTANDING_WASM = NO_LIBC && (ARCH_TYPE == ArchType.WASM32 || ARCH_TYPE == ArchType.WASM64); +const bool FREESTANDING = env::FREESTANDING_PE32 || env::FREESTANDING_MACHO || env::FREESTANDING_ELF || env::FREESTANDING_WASM; const bool ADDRESS_SANITIZER = $$ADDRESS_SANITIZER; const bool MEMORY_SANITIZER = $$MEMORY_SANITIZER; const bool THREAD_SANITIZER = $$THREAD_SANITIZER; diff --git a/lib/std/core/mem.c3 b/lib/std/core/mem.c3 index 8bff0d47c..78a4afa3b 100644 --- a/lib/std/core/mem.c3 +++ b/lib/std/core/mem.c3 @@ -646,7 +646,7 @@ macro void @pool(usz reserve = 0; @body) @builtin @body(); } -module std::core::mem @if(WASM_NOLIBC); +module std::core::mem @if(env::FREESTANDING_WASM); import std::core::mem::allocator @public; SimpleHeapAllocator wasm_allocator @private; extern int __heap_base; diff --git a/lib/std/core/mem_allocator.c3 b/lib/std/core/mem_allocator.c3 index 8b2e4f68b..ca7dbb9f3 100644 --- a/lib/std/core/mem_allocator.c3 +++ b/lib/std/core/mem_allocator.c3 @@ -511,7 +511,7 @@ macro Allocator temp() @deprecated("Use 'tmem' instead") alias tmem @builtin = current_temp; -fn void allow_implicit_temp_allocator_on_load_thread() @init(1) @local @if(env::LIBC || env::WASM_NOLIBC) +fn void allow_implicit_temp_allocator_on_load_thread() @init(1) @local @if(env::LIBC || env::FREESTANDING_WASM) { auto_create_temp = true; } diff --git a/lib/std/core/runtime.c3 b/lib/std/core/runtime.c3 index f7583773f..66df6f015 100644 --- a/lib/std/core/runtime.c3 +++ b/lib/std/core/runtime.c3 @@ -39,7 +39,7 @@ macro @enum_lookup_new($Type, $name, value) } -module std::core::runtime @if(WASM_NOLIBC); +module std::core::runtime @if(env::FREESTANDING_WASM); extern fn void __wasm_call_ctors(); fn void wasm_initialize() @extern("_initialize") @wasm diff --git a/lib/std/math/random/math.seeder.c3 b/lib/std/math/random/math.seeder.c3 index ba9dee0f6..93ecee224 100644 --- a/lib/std/math/random/math.seeder.c3 +++ b/lib/std/math/random/math.seeder.c3 @@ -72,7 +72,7 @@ macro uint hash(value) @local return (uint)a5hash::hash(&&bitcast(value, char[$sizeof(value)])); } -fn char[8 * 4] entropy() @if(!env::WASM_NOLIBC) +fn char[8 * 4] entropy() @if(!env::FREESTANDING_WASM) { void* addr = malloc(1); free(addr); @@ -91,7 +91,7 @@ fn char[8 * 4] entropy() @if(!env::WASM_NOLIBC) return bitcast(entropy_data, char[8 * 4]); } -fn char[8 * 4] entropy() @if(env::WASM_NOLIBC) +fn char[8 * 4] entropy() @if(env::FREESTANDING_WASM) { static uint random_int; random_int += 0xedf19156; diff --git a/releasenotes.md b/releasenotes.md index e4c691967..c3b03479a 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -53,6 +53,7 @@ - Added the experimental `std::core::log` for logging. - Added array `@zip` and `@zip_into` macros. #2370 - Updated termios bindings to use bitstructs and fixed some constants with incorrect values #2372 +- Add Freestanding OS types to runtime `env::` booleans. - Added libloaderapi to `std::os::win32`. - Added `HashSet.values` and `String.contains_char` #2386