Skip to content

Commit

Permalink
[stdlib] replace tabs with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
chnoblouch committed Dec 15, 2024
1 parent 7be4f23 commit b0efccf
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 137 deletions.
4 changes: 2 additions & 2 deletions lib/stdlib2/internal/runtime.bnj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
struct StackFrame {
var address: addr;
var symbol: *u8;
var address: addr;
var symbol: *u8;
}

@[link_name=___banjo_print_string] native func print_string(format: *u8, string: *u8);
Expand Down
14 changes: 7 additions & 7 deletions lib/stdlib2/os/winapi.bnj
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ native func local_free(mem: addr) -> addr;

@[link_name=FormatMessageA]
native func format_message(
flags: Dword,
source: addr,
message_id: Dword,
language_id: Dword,
buffer: **u8,
size: Dword,
arguments: addr
flags: Dword,
source: addr,
message_id: Dword,
language_id: Dword,
buffer: **u8,
size: Dword,
arguments: addr
) -> u32;

# --- minwinbase.h ---
Expand Down
8 changes: 4 additions & 4 deletions lib/stdlib2/std/array.bnj
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ struct Array[T] {
memory.copy(self.data, data, size);

return Array[T] {
data,
length: self.length,
capacity: self.length,
};
data,
length: self.length,
capacity: self.length,
};
}

pub func __index__(self, index: usize) -> *T {
Expand Down
22 changes: 11 additions & 11 deletions lib/stdlib2/std/io.bnj
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ use std.platform;
use c.lib.stdio.{fread, ferror, fgetc, fputc, fwrite, fflush};

struct Error {
var handle: platform.Error;
pub func last() -> Error {
return Error {
handle: platform.error_last(),
};
}
pub func __str__(self) -> String {
return platform.error_to_string(self.handle);
}
var handle: platform.Error;
pub func last() -> Error {
return Error {
handle: platform.error_last(),
};
}
pub func __str__(self) -> String {
return platform.error_to_string(self.handle);
}
}

struct Reader[T] {
Expand Down
58 changes: 29 additions & 29 deletions lib/stdlib2/std/math.bnj
Original file line number Diff line number Diff line change
Expand Up @@ -3,101 +3,101 @@ use c.lib.math as cmath;
const PI32: f32 = 3.14159;

pub func abs(x: f64) -> f64 {
if x >= 0.0 {
return x;
} else {
return -x;
}
if x >= 0.0 {
return x;
} else {
return -x;
}
}

pub func sqrt(x: f64) -> f64 {
return cmath.sqrt(x);
}

pub func sin(x: f64) -> f64 {
return cmath.sin(x);
return cmath.sin(x);
}

pub func cos(x: f64) -> f64 {
return cmath.cos(x);
return cmath.cos(x);
}

pub func tan(x: f64) -> f64 {
return cmath.tan(x);
return cmath.tan(x);
}

pub func asin(x: f64) -> f64 {
return cmath.asin(x);
return cmath.asin(x);
}

pub func acos(x: f64) -> f64 {
return cmath.acos(x);
return cmath.acos(x);
}

pub func atan(x: f64) -> f64 {
return cmath.atan(x);
return cmath.atan(x);
}

pub func atan2(y: f64, x: f64) -> f64 {
return cmath.atan2(y, x);
return cmath.atan2(y, x);
}

pub func abs(x: f32) -> f32 {
if x >= 0.0 {
return x;
} else {
return -x;
}
if x >= 0.0 {
return x;
} else {
return -x;
}
}

pub func sqrt(x: f32) -> f32 {
return cmath.sqrtf(x);
}

pub func sin(x: f32) -> f32 {
return cmath.sinf(x);
return cmath.sinf(x);
}

pub func cos(x: f32) -> f32 {
return cmath.cosf(x);
return cmath.cosf(x);
}

pub func tan(x: f32) -> f32 {
return cmath.tanf(x);
return cmath.tanf(x);
}

pub func asin(x: f32) -> f32 {
return cmath.asinf(x);
return cmath.asinf(x);
}

pub func acos(x: f32) -> f32 {
return cmath.acosf(x);
return cmath.acosf(x);
}

pub func atan(x: f32) -> f32 {
return cmath.atanf(x);
return cmath.atanf(x);
}

pub func atan2(y: f32, x: f32) -> f32 {
return cmath.atan2f(y, x);
return cmath.atan2f(y, x);
}

pub func deg2rad(deg: f32) -> f32 {
return deg * PI32 / 180.0;
return deg * PI32 / 180.0;
}

pub func rad2deg(rad: f32) -> f32 {
return rad * 180.0 / PI32;
return rad * 180.0 / PI32;
}

pub func min[T](a: T, b: T) -> T {
if a < b { return a; } else { return b; }
if a < b { return a; } else { return b; }
}

pub func max[T](a: T, b: T) -> T {
if a > b { return a; } else { return b; }
if a > b { return a; } else { return b; }
}

pub func clamp[T](v: T, minv: T, maxv: T) -> T {
return min[T](maxv, max[T](minv, v));
return min[T](maxv, max[T](minv, v));
}
12 changes: 6 additions & 6 deletions lib/stdlib2/std/memory.bnj
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ pub func copy(src: addr, dst: addr, size: usize) {
}

pub func alloc_box[T]() -> *T {
return alloc(meta(T).size) as *T;
return alloc(meta(T).size) as *T;
}

pub func box[T](value: T) -> *T {
var box = alloc(meta(T).size) as *T;
var box = alloc(meta(T).size) as *T;
*box = value;
return box;
return box;
}

pub func zero[T]() -> T {
var value: T;
cmemset(&value, 0, meta(T).size);
return value;
var value: T;
cmemset(&value, 0, meta(T).size);
return value;
}

struct PointerIter[T] {
Expand Down
12 changes: 6 additions & 6 deletions lib/stdlib2/std/platform_impl/unix.bnj
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ meta if IS_UNIX {
const SOCKET_PROTOCOL_UDP: i32 = posix.IPPROTO_UDP;

pub func error_last() -> Error {
return posix.errno();
}
pub func error_to_string(error: Error) -> String {
return String.from_cstr(posix.strerror(error));
}
return posix.errno();
}
pub func error_to_string(error: Error) -> String {
return String.from_cstr(posix.strerror(error));
}

pub func io_get_stdin_stream() -> addr {
return posix.stdin;
Expand Down
72 changes: 36 additions & 36 deletions lib/stdlib2/std/platform_impl/windows.bnj
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ meta if IS_WINDOWS {

pub func error_to_string(error: Error) -> String {
var buffer: *u8 = null;
var length = winapi.format_message(
winapi.FORMAT_MESSAGE_ALLOCATE_BUFFER | winapi.FORMAT_MESSAGE_FROM_SYSTEM | winapi.FORMAT_MESSAGE_IGNORE_INSERTS,
null,
error,
0x400, # MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)
&buffer,
0,
null
);
var trimmed_length = length as usize - 2;
var string = String.from((buffer, trimmed_length));
winapi.local_free(buffer);
var length = winapi.format_message(
winapi.FORMAT_MESSAGE_ALLOCATE_BUFFER | winapi.FORMAT_MESSAGE_FROM_SYSTEM | winapi.FORMAT_MESSAGE_IGNORE_INSERTS,
null,
error,
0x400, # MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)
&buffer,
0,
null
);
var trimmed_length = length as usize - 2;
var string = String.from((buffer, trimmed_length));
winapi.local_free(buffer);
return string;
}

Expand All @@ -52,27 +52,27 @@ meta if IS_WINDOWS {
}

pub func thread_spawn(function: func(addr), argument: addr) -> usize {
var handle = winapi.create_thread(null, 0, function, argument, 0, null);
return handle as usize;
}

pub func thread_join(handle: usize) {
winapi.wait_for_single_object(handle as addr, 0xFFFFFFFF);
}

pub func thread_close(handle: usize) {
winapi.close_handle(handle as addr);
}

pub func thread_sleep(milliseconds: u32) {
winapi.sleep(milliseconds);
}

pub func thread_hardware_concurrency() -> u32 {
var system_info: winapi.SystemInfo;
winapi.get_native_system_info(&system_info);
return system_info.number_of_processors;
}
var handle = winapi.create_thread(null, 0, function, argument, 0, null);
return handle as usize;
}

pub func thread_join(handle: usize) {
winapi.wait_for_single_object(handle as addr, 0xFFFFFFFF);
}

pub func thread_close(handle: usize) {
winapi.close_handle(handle as addr);
}

pub func thread_sleep(milliseconds: u32) {
winapi.sleep(milliseconds);
}

pub func thread_hardware_concurrency() -> u32 {
var system_info: winapi.SystemInfo;
winapi.get_native_system_info(&system_info);
return system_info.number_of_processors;
}

pub func time_system_ticks() -> u64 {
var time: winapi.Filetime;
Expand Down
34 changes: 17 additions & 17 deletions lib/stdlib2/std/system.bnj
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ meta if config.OS == config.WINDOWS {
}

pub func exit(status: i32) {
cexit(status);
cexit(status);
}

pub func panic(message: String) {
println("\n================================================================");
print("panic: ");
println(message);
meta if config.BUILD_CONFIG == config.DEBUG {
stack_trace.print_stack_trace();
}
println("================================================================\n");
exit(1);
println("\n================================================================");
print("panic: ");
println(message);
meta if config.BUILD_CONFIG == config.DEBUG {
stack_trace.print_stack_trace();
}
println("================================================================\n");
exit(1);
}

func errno_str() -> *u8 {
meta if config.OS == config.WINDOWS {
return strerror(*_errno());
} else if config.OS == config.LINUX {
return strerror(*__errno_location());
} else {
meta if config.OS == config.WINDOWS {
return strerror(*_errno());
} else if config.OS == config.LINUX {
return strerror(*__errno_location());
} else {
return "<unknown>";
}
}
2 changes: 1 addition & 1 deletion lib/stdlib2/std/test.bnj
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ func assert_ne[T](a: T, b: T) {
}

func fail() {
print("test failed");
print("test failed");
}
Loading

0 comments on commit b0efccf

Please sign in to comment.