mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Change of proc and type declaration syntax to "prefix" style
`proc name()` from `name :: proc()`
This commit is contained in:
+12
-12
@@ -1,14 +1,14 @@
|
|||||||
Test1 :: type union {
|
#import "atomic.odin";
|
||||||
A: int;
|
#import "fmt.odin";
|
||||||
B: int;
|
#import "hash.odin";
|
||||||
};
|
#import "math.odin";
|
||||||
|
#import "mem.odin";
|
||||||
|
#import "opengl.odin";
|
||||||
|
#import "os.odin";
|
||||||
|
#import "sync.odin";
|
||||||
|
#import "utf8.odin";
|
||||||
|
|
||||||
Test :: type struct {
|
proc main() {
|
||||||
a: Test1;
|
fmt.println("Here");
|
||||||
};
|
|
||||||
|
|
||||||
main :: proc() {
|
}
|
||||||
test: Test;
|
|
||||||
match type x : ^test.a {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|||||||
+44
-44
@@ -12,12 +12,12 @@
|
|||||||
|
|
||||||
// IMPORTANT NOTE(bill): Do not change the order of any of this data
|
// IMPORTANT NOTE(bill): Do not change the order of any of this data
|
||||||
// The compiler relies upon this _exact_ order
|
// The compiler relies upon this _exact_ order
|
||||||
Type_Info_Member :: struct #ordered {
|
type Type_Info_Member struct #ordered {
|
||||||
name: string; // can be empty if tuple
|
name: string; // can be empty if tuple
|
||||||
type_info: ^Type_Info;
|
type_info: ^Type_Info;
|
||||||
offset: int; // offsets are not used in tuples
|
offset: int; // offsets are not used in tuples
|
||||||
};
|
};
|
||||||
Type_Info_Record :: struct #ordered {
|
type Type_Info_Record struct #ordered {
|
||||||
fields: []Type_Info_Member;
|
fields: []Type_Info_Member;
|
||||||
size: int; // in bytes
|
size: int; // in bytes
|
||||||
align: int; // in bytes
|
align: int; // in bytes
|
||||||
@@ -25,7 +25,7 @@ Type_Info_Record :: struct #ordered {
|
|||||||
ordered: bool;
|
ordered: bool;
|
||||||
};
|
};
|
||||||
|
|
||||||
Type_Info :: union {
|
type Type_Info union {
|
||||||
Named: struct #ordered {
|
Named: struct #ordered {
|
||||||
name: string;
|
name: string;
|
||||||
base: ^Type_Info; // This will _not_ be a Type_Info.Named
|
base: ^Type_Info; // This will _not_ be a Type_Info.Named
|
||||||
@@ -77,7 +77,7 @@ Type_Info :: union {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
type_info_base :: proc(info: ^Type_Info) -> ^Type_Info {
|
proc type_info_base(info: ^Type_Info) -> ^Type_Info {
|
||||||
if info == nil {
|
if info == nil {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@@ -91,47 +91,47 @@ type_info_base :: proc(info: ^Type_Info) -> ^Type_Info {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
assume :: proc(cond: bool) #foreign "llvm.assume"
|
proc assume(cond: bool) #foreign "llvm.assume"
|
||||||
|
|
||||||
__debug_trap :: proc() #foreign "llvm.debugtrap"
|
proc __debug_trap () #foreign "llvm.debugtrap"
|
||||||
__trap :: proc() #foreign "llvm.trap"
|
proc __trap () #foreign "llvm.trap"
|
||||||
read_cycle_counter :: proc() -> u64 #foreign "llvm.readcyclecounter"
|
proc read_cycle_counter() -> u64 #foreign "llvm.readcyclecounter"
|
||||||
|
|
||||||
bit_reverse16 :: proc(b: u16) -> u16 #foreign "llvm.bitreverse.i16"
|
proc bit_reverse16(b: u16) -> u16 #foreign "llvm.bitreverse.i16"
|
||||||
bit_reverse32 :: proc(b: u32) -> u32 #foreign "llvm.bitreverse.i32"
|
proc bit_reverse32(b: u32) -> u32 #foreign "llvm.bitreverse.i32"
|
||||||
bit_reverse64 :: proc(b: u64) -> u64 #foreign "llvm.bitreverse.i64"
|
proc bit_reverse64(b: u64) -> u64 #foreign "llvm.bitreverse.i64"
|
||||||
|
|
||||||
byte_swap16 :: proc(b: u16) -> u16 #foreign "llvm.bswap.i16"
|
proc byte_swap16(b: u16) -> u16 #foreign "llvm.bswap.i16"
|
||||||
byte_swap32 :: proc(b: u32) -> u32 #foreign "llvm.bswap.i32"
|
proc byte_swap32(b: u32) -> u32 #foreign "llvm.bswap.i32"
|
||||||
byte_swap64 :: proc(b: u64) -> u64 #foreign "llvm.bswap.i64"
|
proc byte_swap64(b: u64) -> u64 #foreign "llvm.bswap.i64"
|
||||||
|
|
||||||
fmuladd32 :: proc(a, b, c: f32) -> f32 #foreign "llvm.fmuladd.f32"
|
proc fmuladd32(a, b, c: f32) -> f32 #foreign "llvm.fmuladd.f32"
|
||||||
fmuladd64 :: proc(a, b, c: f64) -> f64 #foreign "llvm.fmuladd.f64"
|
proc fmuladd64(a, b, c: f64) -> f64 #foreign "llvm.fmuladd.f64"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Allocator_Mode :: enum {
|
type Allocator_Mode enum {
|
||||||
ALLOC,
|
ALLOC,
|
||||||
FREE,
|
FREE,
|
||||||
FREE_ALL,
|
FREE_ALL,
|
||||||
RESIZE,
|
RESIZE,
|
||||||
}
|
}
|
||||||
Allocator_Proc :: type proc(allocator_data: rawptr, mode: Allocator_Mode,
|
type Allocator_Proc proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||||
size, alignment: int,
|
size, alignment: int,
|
||||||
old_memory: rawptr, old_size: int, flags: u64) -> rawptr;
|
old_memory: rawptr, old_size: int, flags: u64) -> rawptr;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Allocator :: struct #ordered {
|
type Allocator struct #ordered {
|
||||||
procedure: Allocator_Proc;
|
procedure: Allocator_Proc;
|
||||||
data: rawptr;
|
data: rawptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Context :: struct #ordered {
|
type Context struct #ordered {
|
||||||
thread_id: int;
|
thread_id: int;
|
||||||
|
|
||||||
allocator: Allocator;
|
allocator: Allocator;
|
||||||
@@ -146,7 +146,7 @@ Context :: struct #ordered {
|
|||||||
DEFAULT_ALIGNMENT :: align_of([vector 4]f32);
|
DEFAULT_ALIGNMENT :: align_of([vector 4]f32);
|
||||||
|
|
||||||
|
|
||||||
__check_context :: proc() {
|
proc __check_context() {
|
||||||
c := ^__context;
|
c := ^__context;
|
||||||
|
|
||||||
if c.allocator.procedure == nil {
|
if c.allocator.procedure == nil {
|
||||||
@@ -157,30 +157,30 @@ __check_context :: proc() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
alloc :: proc(size: int) -> rawptr #inline { return alloc_align(size, DEFAULT_ALIGNMENT); }
|
proc alloc(size: int) -> rawptr #inline { return alloc_align(size, DEFAULT_ALIGNMENT); }
|
||||||
|
|
||||||
alloc_align :: proc(size, alignment: int) -> rawptr #inline {
|
proc alloc_align(size, alignment: int) -> rawptr #inline {
|
||||||
__check_context();
|
__check_context();
|
||||||
a := context.allocator;
|
a := context.allocator;
|
||||||
return a.procedure(a.data, Allocator_Mode.ALLOC, size, alignment, nil, 0, 0);
|
return a.procedure(a.data, Allocator_Mode.ALLOC, size, alignment, nil, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
free :: proc(ptr: rawptr) #inline {
|
proc free(ptr: rawptr) #inline {
|
||||||
__check_context();
|
__check_context();
|
||||||
a := context.allocator;
|
a := context.allocator;
|
||||||
if ptr != nil {
|
if ptr != nil {
|
||||||
a.procedure(a.data, Allocator_Mode.FREE, 0, 0, ptr, 0, 0);
|
a.procedure(a.data, Allocator_Mode.FREE, 0, 0, ptr, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free_all :: proc() #inline {
|
proc free_all() #inline {
|
||||||
__check_context();
|
__check_context();
|
||||||
a := context.allocator;
|
a := context.allocator;
|
||||||
a.procedure(a.data, Allocator_Mode.FREE_ALL, 0, 0, nil, 0, 0);
|
a.procedure(a.data, Allocator_Mode.FREE_ALL, 0, 0, nil, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
resize :: proc(ptr: rawptr, old_size, new_size: int) -> rawptr #inline { return resize_align(ptr, old_size, new_size, DEFAULT_ALIGNMENT); }
|
proc resize (ptr: rawptr, old_size, new_size: int) -> rawptr #inline { return resize_align(ptr, old_size, new_size, DEFAULT_ALIGNMENT); }
|
||||||
resize_align :: proc(ptr: rawptr, old_size, new_size, alignment: int) -> rawptr #inline {
|
proc resize_align(ptr: rawptr, old_size, new_size, alignment: int) -> rawptr #inline {
|
||||||
__check_context();
|
__check_context();
|
||||||
a := context.allocator;
|
a := context.allocator;
|
||||||
return a.procedure(a.data, Allocator_Mode.RESIZE, new_size, alignment, ptr, old_size, 0);
|
return a.procedure(a.data, Allocator_Mode.RESIZE, new_size, alignment, ptr, old_size, 0);
|
||||||
@@ -188,7 +188,7 @@ resize_align :: proc(ptr: rawptr, old_size, new_size, alignment: int) -> rawptr
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
default_resize_align :: proc(old_memory: rawptr, old_size, new_size, alignment: int) -> rawptr {
|
proc default_resize_align(old_memory: rawptr, old_size, new_size, alignment: int) -> rawptr {
|
||||||
if old_memory == nil {
|
if old_memory == nil {
|
||||||
return alloc_align(new_size, alignment);
|
return alloc_align(new_size, alignment);
|
||||||
}
|
}
|
||||||
@@ -213,7 +213,7 @@ default_resize_align :: proc(old_memory: rawptr, old_size, new_size, alignment:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
proc default_allocator_proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||||
size, alignment: int,
|
size, alignment: int,
|
||||||
old_memory: rawptr, old_size: int, flags: u64) -> rawptr {
|
old_memory: rawptr, old_size: int, flags: u64) -> rawptr {
|
||||||
using Allocator_Mode;
|
using Allocator_Mode;
|
||||||
@@ -262,7 +262,7 @@ default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
default_allocator :: proc() -> Allocator {
|
proc default_allocator() -> Allocator {
|
||||||
return Allocator{
|
return Allocator{
|
||||||
procedure = default_allocator_proc,
|
procedure = default_allocator_proc,
|
||||||
data = nil,
|
data = nil,
|
||||||
@@ -279,7 +279,7 @@ default_allocator :: proc() -> Allocator {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
__string_eq :: proc(a, b: string) -> bool {
|
proc __string_eq(a, b: string) -> bool {
|
||||||
if a.count != b.count {
|
if a.count != b.count {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -289,24 +289,24 @@ __string_eq :: proc(a, b: string) -> bool {
|
|||||||
return mem.compare(a.data, b.data, a.count) == 0;
|
return mem.compare(a.data, b.data, a.count) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
__string_cmp :: proc(a, b : string) -> int {
|
proc __string_cmp(a, b : string) -> int {
|
||||||
return mem.compare(a.data, b.data, min(a.count, b.count));
|
return mem.compare(a.data, b.data, min(a.count, b.count));
|
||||||
}
|
}
|
||||||
|
|
||||||
__string_ne :: proc(a, b: string) -> bool #inline { return !__string_eq(a, b); }
|
proc __string_ne(a, b: string) -> bool #inline { return !__string_eq(a, b); }
|
||||||
__string_lt :: proc(a, b: string) -> bool #inline { return __string_cmp(a, b) < 0; }
|
proc __string_lt(a, b: string) -> bool #inline { return __string_cmp(a, b) < 0; }
|
||||||
__string_gt :: proc(a, b: string) -> bool #inline { return __string_cmp(a, b) > 0; }
|
proc __string_gt(a, b: string) -> bool #inline { return __string_cmp(a, b) > 0; }
|
||||||
__string_le :: proc(a, b: string) -> bool #inline { return __string_cmp(a, b) <= 0; }
|
proc __string_le(a, b: string) -> bool #inline { return __string_cmp(a, b) <= 0; }
|
||||||
__string_ge :: proc(a, b: string) -> bool #inline { return __string_cmp(a, b) >= 0; }
|
proc __string_ge(a, b: string) -> bool #inline { return __string_cmp(a, b) >= 0; }
|
||||||
|
|
||||||
|
|
||||||
__assert :: proc(file: string, line, column: int, msg: string) #inline {
|
proc __assert(file: string, line, column: int, msg: string) #inline {
|
||||||
fmt.fprintf(os.stderr, "%(%:%) Runtime assertion: %\n",
|
fmt.fprintf(os.stderr, "%(%:%) Runtime assertion: %\n",
|
||||||
file, line, column, msg);
|
file, line, column, msg);
|
||||||
__debug_trap();
|
__debug_trap();
|
||||||
}
|
}
|
||||||
|
|
||||||
__bounds_check_error :: proc(file: string, line, column: int,
|
proc __bounds_check_error(file: string, line, column: int,
|
||||||
index, count: int) {
|
index, count: int) {
|
||||||
if 0 <= index && index < count {
|
if 0 <= index && index < count {
|
||||||
return;
|
return;
|
||||||
@@ -316,7 +316,7 @@ __bounds_check_error :: proc(file: string, line, column: int,
|
|||||||
__debug_trap();
|
__debug_trap();
|
||||||
}
|
}
|
||||||
|
|
||||||
__slice_expr_error :: proc(file: string, line, column: int,
|
proc __slice_expr_error(file: string, line, column: int,
|
||||||
low, high, max: int) {
|
low, high, max: int) {
|
||||||
if 0 <= low && low <= high && high <= max {
|
if 0 <= low && low <= high && high <= max {
|
||||||
return;
|
return;
|
||||||
@@ -325,7 +325,7 @@ __slice_expr_error :: proc(file: string, line, column: int,
|
|||||||
file, line, column, low, high, max);
|
file, line, column, low, high, max);
|
||||||
__debug_trap();
|
__debug_trap();
|
||||||
}
|
}
|
||||||
__substring_expr_error :: proc(file: string, line, column: int,
|
proc __substring_expr_error(file: string, line, column: int,
|
||||||
low, high: int) {
|
low, high: int) {
|
||||||
if 0 <= low && low <= high {
|
if 0 <= low && low <= high {
|
||||||
return;
|
return;
|
||||||
@@ -335,7 +335,7 @@ __substring_expr_error :: proc(file: string, line, column: int,
|
|||||||
__debug_trap();
|
__debug_trap();
|
||||||
}
|
}
|
||||||
|
|
||||||
__enum_to_string :: proc(info: ^Type_Info, value: i64) -> string {
|
proc __enum_to_string(info: ^Type_Info, value: i64) -> string {
|
||||||
match type ti : type_info_base(info) {
|
match type ti : type_info_base(info) {
|
||||||
case Type_Info.Enum:
|
case Type_Info.Enum:
|
||||||
// TODO(bill): Search faster than linearly
|
// TODO(bill): Search faster than linearly
|
||||||
|
|||||||
+24
-24
@@ -5,36 +5,36 @@
|
|||||||
_ := compile_assert(ODIN_ARCH == "amd64"); // TODO(bill): x86 version
|
_ := compile_assert(ODIN_ARCH == "amd64"); // TODO(bill): x86 version
|
||||||
|
|
||||||
|
|
||||||
yield_thread :: proc() { win32._mm_pause(); }
|
proc yield_thread() { win32._mm_pause(); }
|
||||||
mfence :: proc() { win32.ReadWriteBarrier(); }
|
proc mfence () { win32.ReadWriteBarrier(); }
|
||||||
sfence :: proc() { win32.WriteBarrier(); }
|
proc sfence () { win32.WriteBarrier(); }
|
||||||
lfence :: proc() { win32.ReadBarrier(); }
|
proc lfence () { win32.ReadBarrier(); }
|
||||||
|
|
||||||
|
|
||||||
load32 :: proc(a: ^i32) -> i32 {
|
proc load32(a: ^i32) -> i32 {
|
||||||
return a^;
|
return a^;
|
||||||
}
|
}
|
||||||
store32 :: proc(a: ^i32, value: i32) {
|
proc store32(a: ^i32, value: i32) {
|
||||||
a^ = value;
|
a^ = value;
|
||||||
}
|
}
|
||||||
compare_exchange32 :: proc(a: ^i32, expected, desired: i32) -> i32 {
|
proc compare_exchange32(a: ^i32, expected, desired: i32) -> i32 {
|
||||||
return win32.InterlockedCompareExchange(a, desired, expected);
|
return win32.InterlockedCompareExchange(a, desired, expected);
|
||||||
}
|
}
|
||||||
exchanged32 :: proc(a: ^i32, desired: i32) -> i32 {
|
proc exchanged32(a: ^i32, desired: i32) -> i32 {
|
||||||
return win32.InterlockedExchange(a, desired);
|
return win32.InterlockedExchange(a, desired);
|
||||||
}
|
}
|
||||||
fetch_add32 :: proc(a: ^i32, operand: i32) -> i32 {
|
proc fetch_add32(a: ^i32, operand: i32) -> i32 {
|
||||||
return win32.InterlockedExchangeAdd(a, operand);
|
return win32.InterlockedExchangeAdd(a, operand);
|
||||||
|
|
||||||
}
|
}
|
||||||
fetch_and32 :: proc(a: ^i32, operand: i32) -> i32 {
|
proc fetch_and32(a: ^i32, operand: i32) -> i32 {
|
||||||
return win32.InterlockedAnd(a, operand);
|
return win32.InterlockedAnd(a, operand);
|
||||||
|
|
||||||
}
|
}
|
||||||
fetch_or32 :: proc(a: ^i32, operand: i32) -> i32 {
|
proc fetch_or32(a: ^i32, operand: i32) -> i32 {
|
||||||
return win32.InterlockedOr(a, operand);
|
return win32.InterlockedOr(a, operand);
|
||||||
}
|
}
|
||||||
spin_lock32 :: proc(a: ^i32, time_out: int) -> bool { // NOTE(bill): time_out = -1 as default
|
proc spin_lock32(a: ^i32, time_out: int) -> bool { // NOTE(bill): time_out = -1 as default
|
||||||
old_value := compare_exchange32(a, 1, 0);
|
old_value := compare_exchange32(a, 1, 0);
|
||||||
counter := 0;
|
counter := 0;
|
||||||
for old_value != 0 && (time_out < 0 || counter < time_out) {
|
for old_value != 0 && (time_out < 0 || counter < time_out) {
|
||||||
@@ -45,11 +45,11 @@ spin_lock32 :: proc(a: ^i32, time_out: int) -> bool { // NOTE(bill): time_out =
|
|||||||
}
|
}
|
||||||
return old_value == 0;
|
return old_value == 0;
|
||||||
}
|
}
|
||||||
spin_unlock32 :: proc(a: ^i32) {
|
proc spin_unlock32(a: ^i32) {
|
||||||
store32(a, 0);
|
store32(a, 0);
|
||||||
mfence();
|
mfence();
|
||||||
}
|
}
|
||||||
try_acquire_lock32 :: proc(a: ^i32) -> bool {
|
proc try_acquire_lock32(a: ^i32) -> bool {
|
||||||
yield_thread();
|
yield_thread();
|
||||||
old_value := compare_exchange32(a, 1, 0);
|
old_value := compare_exchange32(a, 1, 0);
|
||||||
mfence();
|
mfence();
|
||||||
@@ -57,28 +57,28 @@ try_acquire_lock32 :: proc(a: ^i32) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
load64 :: proc(a: ^i64) -> i64 {
|
proc load64(a: ^i64) -> i64 {
|
||||||
return a^;
|
return a^;
|
||||||
}
|
}
|
||||||
store64 :: proc(a: ^i64, value: i64) {
|
proc store64(a: ^i64, value: i64) {
|
||||||
a^ = value;
|
a^ = value;
|
||||||
}
|
}
|
||||||
compare_exchange64 :: proc(a: ^i64, expected, desired: i64) -> i64 {
|
proc compare_exchange64(a: ^i64, expected, desired: i64) -> i64 {
|
||||||
return win32.InterlockedCompareExchange64(a, desired, expected);
|
return win32.InterlockedCompareExchange64(a, desired, expected);
|
||||||
}
|
}
|
||||||
exchanged64 :: proc(a: ^i64, desired: i64) -> i64 {
|
proc exchanged64(a: ^i64, desired: i64) -> i64 {
|
||||||
return win32.InterlockedExchange64(a, desired);
|
return win32.InterlockedExchange64(a, desired);
|
||||||
}
|
}
|
||||||
fetch_add64 :: proc(a: ^i64, operand: i64) -> i64 {
|
proc fetch_add64(a: ^i64, operand: i64) -> i64 {
|
||||||
return win32.InterlockedExchangeAdd64(a, operand);
|
return win32.InterlockedExchangeAdd64(a, operand);
|
||||||
}
|
}
|
||||||
fetch_and64 :: proc(a: ^i64, operand: i64) -> i64 {
|
proc fetch_and64(a: ^i64, operand: i64) -> i64 {
|
||||||
return win32.InterlockedAnd64(a, operand);
|
return win32.InterlockedAnd64(a, operand);
|
||||||
}
|
}
|
||||||
fetch_or64 :: proc(a: ^i64, operand: i64) -> i64 {
|
proc fetch_or64(a: ^i64, operand: i64) -> i64 {
|
||||||
return win32.InterlockedOr64(a, operand);
|
return win32.InterlockedOr64(a, operand);
|
||||||
}
|
}
|
||||||
spin_lock64 :: proc(a: ^i64, time_out: int) -> bool { // NOTE(bill): time_out = -1 as default
|
proc spin_lock64(a: ^i64, time_out: int) -> bool { // NOTE(bill): time_out = -1 as default
|
||||||
old_value := compare_exchange64(a, 1, 0);
|
old_value := compare_exchange64(a, 1, 0);
|
||||||
counter := 0;
|
counter := 0;
|
||||||
for old_value != 0 && (time_out < 0 || counter < time_out) {
|
for old_value != 0 && (time_out < 0 || counter < time_out) {
|
||||||
@@ -89,11 +89,11 @@ spin_lock64 :: proc(a: ^i64, time_out: int) -> bool { // NOTE(bill): time_out =
|
|||||||
}
|
}
|
||||||
return old_value == 0;
|
return old_value == 0;
|
||||||
}
|
}
|
||||||
spin_unlock64 :: proc(a: ^i64) {
|
proc spin_unlock64(a: ^i64) {
|
||||||
store64(a, 0);
|
store64(a, 0);
|
||||||
mfence();
|
mfence();
|
||||||
}
|
}
|
||||||
try_acquire_lock64 :: proc(a: ^i64) -> bool {
|
proc try_acquire_lock64(a: ^i64) -> bool {
|
||||||
yield_thread();
|
yield_thread();
|
||||||
old_value := compare_exchange64(a, 1, 0);
|
old_value := compare_exchange64(a, 1, 0);
|
||||||
mfence();
|
mfence();
|
||||||
|
|||||||
+33
-33
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
PRINT_BUF_SIZE :: 1<<12;
|
PRINT_BUF_SIZE :: 1<<12;
|
||||||
|
|
||||||
fprint :: proc(f: ^os.File, args: ..any) -> int {
|
proc fprint(f: ^os.File, args: ..any) -> int {
|
||||||
data: [PRINT_BUF_SIZE]byte;
|
data: [PRINT_BUF_SIZE]byte;
|
||||||
buf := data[:0];
|
buf := data[:0];
|
||||||
bprint(^buf, ..args);
|
bprint(^buf, ..args);
|
||||||
@@ -12,14 +12,14 @@ fprint :: proc(f: ^os.File, args: ..any) -> int {
|
|||||||
return buf.count;
|
return buf.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintln :: proc(f: ^os.File, args: ..any) -> int {
|
proc fprintln(f: ^os.File, args: ..any) -> int {
|
||||||
data: [PRINT_BUF_SIZE]byte;
|
data: [PRINT_BUF_SIZE]byte;
|
||||||
buf := data[:0];
|
buf := data[:0];
|
||||||
bprintln(^buf, ..args);
|
bprintln(^buf, ..args);
|
||||||
os.write(f, buf);
|
os.write(f, buf);
|
||||||
return buf.count;
|
return buf.count;
|
||||||
}
|
}
|
||||||
fprintf :: proc(f: ^os.File, fmt: string, args: ..any) -> int {
|
proc fprintf(f: ^os.File, fmt: string, args: ..any) -> int {
|
||||||
data: [PRINT_BUF_SIZE]byte;
|
data: [PRINT_BUF_SIZE]byte;
|
||||||
buf := data[:0];
|
buf := data[:0];
|
||||||
bprintf(^buf, fmt, ..args);
|
bprintf(^buf, fmt, ..args);
|
||||||
@@ -28,19 +28,19 @@ fprintf :: proc(f: ^os.File, fmt: string, args: ..any) -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
print :: proc(args: ..any) -> int {
|
proc print(args: ..any) -> int {
|
||||||
return fprint(os.stdout, ..args);
|
return fprint(os.stdout, ..args);
|
||||||
}
|
}
|
||||||
println :: proc(args: ..any) -> int {
|
proc println(args: ..any) -> int {
|
||||||
return fprintln(os.stdout, ..args);
|
return fprintln(os.stdout, ..args);
|
||||||
}
|
}
|
||||||
printf :: proc(fmt: string, args: ..any) -> int {
|
proc printf(fmt: string, args: ..any) -> int {
|
||||||
return fprintf(os.stdout, fmt, ..args);
|
return fprintf(os.stdout, fmt, ..args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fprint_type :: proc(f: ^os.File, info: ^Type_Info) {
|
proc fprint_type(f: ^os.File, info: ^Type_Info) {
|
||||||
data: [PRINT_BUF_SIZE]byte;
|
data: [PRINT_BUF_SIZE]byte;
|
||||||
buf := data[:0];
|
buf := data[:0];
|
||||||
bprint_type(^buf, info);
|
bprint_type(^buf, info);
|
||||||
@@ -49,7 +49,7 @@ fprint_type :: proc(f: ^os.File, info: ^Type_Info) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
print_byte_buffer :: proc(buf: ^[]byte, b: []byte) {
|
proc print_byte_buffer(buf: ^[]byte, b: []byte) {
|
||||||
if buf.count < buf.capacity {
|
if buf.count < buf.capacity {
|
||||||
n := min(buf.capacity-buf.count, b.count);
|
n := min(buf.capacity-buf.count, b.count);
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
@@ -59,29 +59,29 @@ print_byte_buffer :: proc(buf: ^[]byte, b: []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bprint_string :: proc(buf: ^[]byte, s: string) {
|
proc bprint_string(buf: ^[]byte, s: string) {
|
||||||
print_byte_buffer(buf, s as []byte);
|
print_byte_buffer(buf, s as []byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
byte_reverse :: proc(b: []byte) {
|
proc byte_reverse(b: []byte) {
|
||||||
n := b.count;
|
n := b.count;
|
||||||
for i := 0; i < n/2; i++ {
|
for i := 0; i < n/2; i++ {
|
||||||
b[i], b[n-1-i] = b[n-1-i], b[i];
|
b[i], b[n-1-i] = b[n-1-i], b[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bprint_rune :: proc(buf: ^[]byte, r: rune) {
|
proc bprint_rune(buf: ^[]byte, r: rune) {
|
||||||
b, n := utf8.encode_rune(r);
|
b, n := utf8.encode_rune(r);
|
||||||
bprint_string(buf, b[:n] as string);
|
bprint_string(buf, b[:n] as string);
|
||||||
}
|
}
|
||||||
|
|
||||||
bprint_space :: proc(buf: ^[]byte) { bprint_rune(buf, ' '); }
|
proc bprint_space(buf: ^[]byte) { bprint_rune(buf, ' '); }
|
||||||
bprint_nl :: proc(buf: ^[]byte) { bprint_rune(buf, '\n'); }
|
proc bprint_nl (buf: ^[]byte) { bprint_rune(buf, '\n'); }
|
||||||
|
|
||||||
__NUM_TO_CHAR_TABLE := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@$";
|
__NUM_TO_CHAR_TABLE := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@$";
|
||||||
|
|
||||||
bprint_bool :: proc(buffer: ^[]byte, b : bool) {
|
proc bprint_bool(buffer: ^[]byte, b : bool) {
|
||||||
if b {
|
if b {
|
||||||
bprint_string(buffer, "true");
|
bprint_string(buffer, "true");
|
||||||
} else {
|
} else {
|
||||||
@@ -89,15 +89,15 @@ bprint_bool :: proc(buffer: ^[]byte, b : bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bprint_pointer :: proc(buffer: ^[]byte, p: rawptr) #inline {
|
proc bprint_pointer(buffer: ^[]byte, p: rawptr) #inline {
|
||||||
bprint_string(buffer, "0x");
|
bprint_string(buffer, "0x");
|
||||||
bprint_u64(buffer, p as uint as u64);
|
bprint_u64(buffer, p as uint as u64);
|
||||||
}
|
}
|
||||||
|
|
||||||
bprint_f16 :: proc(buffer: ^[]byte, f: f32) #inline { print__f64(buffer, f as f64, 4); }
|
proc bprint_f16 (buffer: ^[]byte, f: f32) #inline { print__f64(buffer, f as f64, 4); }
|
||||||
bprint_f32 :: proc(buffer: ^[]byte, f: f32) #inline { print__f64(buffer, f as f64, 7); }
|
proc bprint_f32 (buffer: ^[]byte, f: f32) #inline { print__f64(buffer, f as f64, 7); }
|
||||||
bprint_f64 :: proc(buffer: ^[]byte, f: f64) #inline { print__f64(buffer, f as f64, 16); }
|
proc bprint_f64 (buffer: ^[]byte, f: f64) #inline { print__f64(buffer, f as f64, 16); }
|
||||||
bprint_u64 :: proc(buffer: ^[]byte, value: u64) {
|
proc bprint_u64(buffer: ^[]byte, value: u64) {
|
||||||
i := value;
|
i := value;
|
||||||
buf: [20]byte;
|
buf: [20]byte;
|
||||||
len := 0;
|
len := 0;
|
||||||
@@ -113,7 +113,7 @@ bprint_u64 :: proc(buffer: ^[]byte, value: u64) {
|
|||||||
byte_reverse(buf[:len]);
|
byte_reverse(buf[:len]);
|
||||||
bprint_string(buffer, buf[:len] as string);
|
bprint_string(buffer, buf[:len] as string);
|
||||||
}
|
}
|
||||||
bprint_i64 :: proc(buffer: ^[]byte, value: i64) {
|
proc bprint_i64(buffer: ^[]byte, value: i64) {
|
||||||
// TODO(bill): Cleanup printing
|
// TODO(bill): Cleanup printing
|
||||||
i := value;
|
i := value;
|
||||||
if i < 0 {
|
if i < 0 {
|
||||||
@@ -124,14 +124,14 @@ bprint_i64 :: proc(buffer: ^[]byte, value: i64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
bprint_u128 :: proc(buffer: ^[]byte, value: u128) {
|
proc bprint_u128(buffer: ^[]byte, value: u128) {
|
||||||
a := value transmute [2]u64;
|
a := value transmute [2]u64;
|
||||||
if a[1] != 0 {
|
if a[1] != 0 {
|
||||||
bprint_u64(buffer, a[1]);
|
bprint_u64(buffer, a[1]);
|
||||||
}
|
}
|
||||||
bprint_u64(buffer, a[0]);
|
bprint_u64(buffer, a[0]);
|
||||||
}
|
}
|
||||||
bprint_i128 :: proc(buffer: ^[]byte, value: i128) {
|
proc bprint_i128(buffer: ^[]byte, value: i128) {
|
||||||
i := value;
|
i := value;
|
||||||
if i < 0 {
|
if i < 0 {
|
||||||
i = -i;
|
i = -i;
|
||||||
@@ -142,7 +142,7 @@ bprint_i128 :: proc(buffer: ^[]byte, value: i128) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
print__f64 :: proc(buffer: ^[]byte, value: f64, decimal_places: int) {
|
proc print__f64(buffer: ^[]byte, value: f64, decimal_places: int) {
|
||||||
f := value;
|
f := value;
|
||||||
if f == 0 {
|
if f == 0 {
|
||||||
bprint_rune(buffer, '0');
|
bprint_rune(buffer, '0');
|
||||||
@@ -168,7 +168,7 @@ print__f64 :: proc(buffer: ^[]byte, value: f64, decimal_places: int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bprint_type :: proc(buf: ^[]byte, ti: ^Type_Info) {
|
proc bprint_type(buf: ^[]byte, ti: ^Type_Info) {
|
||||||
if ti == nil {
|
if ti == nil {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -299,14 +299,14 @@ bprint_type :: proc(buf: ^[]byte, ti: ^Type_Info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
make_any :: proc(type_info: ^Type_Info, data: rawptr) -> any {
|
proc make_any(type_info: ^Type_Info, data: rawptr) -> any {
|
||||||
a: any;
|
a: any;
|
||||||
a.type_info = type_info;
|
a.type_info = type_info;
|
||||||
a.data = data;
|
a.data = data;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
bprint_any :: proc(buf: ^[]byte, arg: any) {
|
proc bprint_any(buf: ^[]byte, arg: any) {
|
||||||
if arg.type_info == nil {
|
if arg.type_info == nil {
|
||||||
bprint_string(buf, "<nil>");
|
bprint_string(buf, "<nil>");
|
||||||
return;
|
return;
|
||||||
@@ -435,7 +435,7 @@ bprint_any :: proc(buf: ^[]byte, arg: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Vector:
|
case Vector:
|
||||||
is_bool :: proc(type_info: ^Type_Info) -> bool {
|
proc is_bool(type_info: ^Type_Info) -> bool {
|
||||||
match type info : type_info {
|
match type info : type_info {
|
||||||
case Named:
|
case Named:
|
||||||
return is_bool(info.base);
|
return is_bool(info.base);
|
||||||
@@ -489,12 +489,12 @@ bprint_any :: proc(buf: ^[]byte, arg: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) -> int {
|
proc bprintf(buf: ^[]byte, fmt: string, args: ..any) -> int {
|
||||||
is_digit :: proc(r: rune) -> bool #inline {
|
proc is_digit(r: rune) -> bool #inline {
|
||||||
return '0' <= r && r <= '9';
|
return '0' <= r && r <= '9';
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_int :: proc(s: string, offset: int) -> (int, int) {
|
proc parse_int(s: string, offset: int) -> (int, int) {
|
||||||
result := 0;
|
result := 0;
|
||||||
|
|
||||||
for ; offset < s.count; offset++ {
|
for ; offset < s.count; offset++ {
|
||||||
@@ -554,8 +554,8 @@ bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bprint :: proc(buf: ^[]byte, args: ..any) -> int {
|
proc bprint(buf: ^[]byte, args: ..any) -> int {
|
||||||
is_type_string :: proc(info: ^Type_Info) -> bool {
|
proc is_type_string(info: ^Type_Info) -> bool {
|
||||||
using Type_Info;
|
using Type_Info;
|
||||||
if info == nil {
|
if info == nil {
|
||||||
return false;
|
return false;
|
||||||
@@ -582,7 +582,7 @@ bprint :: proc(buf: ^[]byte, args: ..any) -> int {
|
|||||||
return buf.count;
|
return buf.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
bprintln :: proc(buf: ^[]byte, args: ..any) -> int {
|
proc bprintln(buf: ^[]byte, args: ..any) -> int {
|
||||||
for i := 0; i < args.count; i++ {
|
for i := 0; i < args.count; i++ {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
append(buf, ' ');
|
append(buf, ' ');
|
||||||
|
|||||||
+7
-7
@@ -1,4 +1,4 @@
|
|||||||
crc32 :: proc(data: rawptr, len: int) -> u32 {
|
proc crc32(data: rawptr, len: int) -> u32 {
|
||||||
result := ~(0 as u32);
|
result := ~(0 as u32);
|
||||||
s := slice_ptr(data as ^u8, len);
|
s := slice_ptr(data as ^u8, len);
|
||||||
for i := 0; i < len; i++ {
|
for i := 0; i < len; i++ {
|
||||||
@@ -7,7 +7,7 @@ crc32 :: proc(data: rawptr, len: int) -> u32 {
|
|||||||
}
|
}
|
||||||
return ~result;
|
return ~result;
|
||||||
}
|
}
|
||||||
crc64 :: proc(data: rawptr, len: int) -> u64 {
|
proc crc64(data: rawptr, len: int) -> u64 {
|
||||||
result := ~(0 as u64);
|
result := ~(0 as u64);
|
||||||
s := slice_ptr(data as ^u8, len);
|
s := slice_ptr(data as ^u8, len);
|
||||||
for i := 0; i < len; i++ {
|
for i := 0; i < len; i++ {
|
||||||
@@ -17,7 +17,7 @@ crc64 :: proc(data: rawptr, len: int) -> u64 {
|
|||||||
return ~result;
|
return ~result;
|
||||||
}
|
}
|
||||||
|
|
||||||
fnv32 :: proc(data: rawptr, len: int) -> u32 {
|
proc fnv32(data: rawptr, len: int) -> u32 {
|
||||||
s := slice_ptr(data as ^u8, len);
|
s := slice_ptr(data as ^u8, len);
|
||||||
|
|
||||||
h: u32 = 0x811c9dc5;
|
h: u32 = 0x811c9dc5;
|
||||||
@@ -27,7 +27,7 @@ fnv32 :: proc(data: rawptr, len: int) -> u32 {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
fnv64 :: proc(data: rawptr, len: int) -> u64 {
|
proc fnv64(data: rawptr, len: int) -> u64 {
|
||||||
s := slice_ptr(data as ^u8, len);
|
s := slice_ptr(data as ^u8, len);
|
||||||
|
|
||||||
h: u64 = 0xcbf29ce484222325;
|
h: u64 = 0xcbf29ce484222325;
|
||||||
@@ -37,7 +37,7 @@ fnv64 :: proc(data: rawptr, len: int) -> u64 {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
fnv32a :: proc(data: rawptr, len: int) -> u32 {
|
proc fnv32a(data: rawptr, len: int) -> u32 {
|
||||||
s := slice_ptr(data as ^u8, len);
|
s := slice_ptr(data as ^u8, len);
|
||||||
|
|
||||||
h: u32 = 0x811c9dc5;
|
h: u32 = 0x811c9dc5;
|
||||||
@@ -47,7 +47,7 @@ fnv32a :: proc(data: rawptr, len: int) -> u32 {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
fnv64a :: proc(data: rawptr, len: int) -> u64 {
|
proc fnv64a(data: rawptr, len: int) -> u64 {
|
||||||
s := slice_ptr(data as ^u8, len);
|
s := slice_ptr(data as ^u8, len);
|
||||||
|
|
||||||
h: u64 = 0xcbf29ce484222325;
|
h: u64 = 0xcbf29ce484222325;
|
||||||
@@ -58,7 +58,7 @@ fnv64a :: proc(data: rawptr, len: int) -> u64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
murmur64 :: proc(data_: rawptr, len: int) -> u64 {
|
proc murmur64(data_: rawptr, len: int) -> u64 {
|
||||||
SEED :: 0x9747b28c;
|
SEED :: 0x9747b28c;
|
||||||
|
|
||||||
when size_of(int) == 8 {
|
when size_of(int) == 8 {
|
||||||
|
|||||||
+52
-52
@@ -17,66 +17,66 @@ EPSILON :: 1.19209290e-7;
|
|||||||
π :: PI;
|
π :: PI;
|
||||||
|
|
||||||
|
|
||||||
Vec2 :: type [vector 2]f32;
|
type Vec2 [vector 2]f32;
|
||||||
Vec3 :: type [vector 3]f32;
|
type Vec3 [vector 3]f32;
|
||||||
Vec4 :: type [vector 4]f32;
|
type Vec4 [vector 4]f32;
|
||||||
;
|
|
||||||
Mat2 :: type [2]Vec2;
|
type Mat2 [2]Vec2;
|
||||||
Mat3 :: type [3]Vec3;
|
type Mat3 [3]Vec3;
|
||||||
Mat4 :: type [4]Vec4;
|
type Mat4 [4]Vec4;
|
||||||
|
|
||||||
|
|
||||||
sqrt32 :: proc(x: f32) -> f32 #foreign "llvm.sqrt.f32"
|
proc sqrt32(x: f32) -> f32 #foreign "llvm.sqrt.f32"
|
||||||
sqrt64 :: proc(x: f64) -> f64 #foreign "llvm.sqrt.f64"
|
proc sqrt64(x: f64) -> f64 #foreign "llvm.sqrt.f64"
|
||||||
|
|
||||||
sin32 :: proc(x: f32) -> f32 #foreign "llvm.sin.f32"
|
proc sin32(x: f32) -> f32 #foreign "llvm.sin.f32"
|
||||||
sin64 :: proc(x: f64) -> f64 #foreign "llvm.sin.f64"
|
proc sin64(x: f64) -> f64 #foreign "llvm.sin.f64"
|
||||||
|
|
||||||
cos32 :: proc(x: f32) -> f32 #foreign "llvm.cos.f32"
|
proc cos32(x: f32) -> f32 #foreign "llvm.cos.f32"
|
||||||
cos64 :: proc(x: f64) -> f64 #foreign "llvm.cos.f64"
|
proc cos64(x: f64) -> f64 #foreign "llvm.cos.f64"
|
||||||
|
|
||||||
tan32 :: proc(x: f32) -> f32 #inline { return sin32(x)/cos32(x); }
|
proc tan32(x: f32) -> f32 #inline { return sin32(x)/cos32(x); }
|
||||||
tan64 :: proc(x: f64) -> f64 #inline { return sin64(x)/cos64(x); }
|
proc tan64(x: f64) -> f64 #inline { return sin64(x)/cos64(x); }
|
||||||
|
|
||||||
lerp32 :: proc(a, b, t: f32) -> f32 { return a*(1-t) + b*t; }
|
proc lerp32(a, b, t: f32) -> f32 { return a*(1-t) + b*t; }
|
||||||
lerp64 :: proc(a, b, t: f64) -> f64 { return a*(1-t) + b*t; }
|
proc lerp64(a, b, t: f64) -> f64 { return a*(1-t) + b*t; }
|
||||||
|
|
||||||
sign32 :: proc(x: f32) -> f32 { if x >= 0 { return +1; } return -1; }
|
proc sign32(x: f32) -> f32 { if x >= 0 { return +1; } return -1; }
|
||||||
sign64 :: proc(x: f64) -> f64 { if x >= 0 { return +1; } return -1; }
|
proc sign64(x: f64) -> f64 { if x >= 0 { return +1; } return -1; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
copy_sign32 :: proc(x, y: f32) -> f32 {
|
proc copy_sign32(x, y: f32) -> f32 {
|
||||||
ix := x transmute u32;
|
ix := x transmute u32;
|
||||||
iy := y transmute u32;
|
iy := y transmute u32;
|
||||||
ix &= 0x7fffffff;
|
ix &= 0x7fffffff;
|
||||||
ix |= iy & 0x80000000;
|
ix |= iy & 0x80000000;
|
||||||
return ix transmute f32;
|
return ix transmute f32;
|
||||||
}
|
}
|
||||||
round32 :: proc(x: f32) -> f32 {
|
proc round32(x: f32) -> f32 {
|
||||||
if x >= 0 {
|
if x >= 0 {
|
||||||
return floor32(x + 0.5);
|
return floor32(x + 0.5);
|
||||||
}
|
}
|
||||||
return ceil32(x - 0.5);
|
return ceil32(x - 0.5);
|
||||||
}
|
}
|
||||||
floor32 :: proc(x: f32) -> f32 {
|
proc floor32(x: f32) -> f32 {
|
||||||
if x >= 0 {
|
if x >= 0 {
|
||||||
return x as int as f32;
|
return x as int as f32;
|
||||||
}
|
}
|
||||||
return (x-0.5) as int as f32;
|
return (x-0.5) as int as f32;
|
||||||
}
|
}
|
||||||
ceil32 :: proc(x: f32) -> f32 {
|
proc ceil32(x: f32) -> f32 {
|
||||||
if x < 0 {
|
if x < 0 {
|
||||||
return x as int as f32;
|
return x as int as f32;
|
||||||
}
|
}
|
||||||
return ((x as int)+1) as f32;
|
return ((x as int)+1) as f32;
|
||||||
}
|
}
|
||||||
|
|
||||||
remainder32 :: proc(x, y: f32) -> f32 {
|
proc remainder32(x, y: f32) -> f32 {
|
||||||
return x - round32(x/y) * y;
|
return x - round32(x/y) * y;
|
||||||
}
|
}
|
||||||
|
|
||||||
fmod32 :: proc(x, y: f32) -> f32 {
|
proc fmod32(x, y: f32) -> f32 {
|
||||||
y = abs(y);
|
y = abs(y);
|
||||||
result := remainder32(abs(x), y);
|
result := remainder32(abs(x), y);
|
||||||
if sign32(result) < 0 {
|
if sign32(result) < 0 {
|
||||||
@@ -86,32 +86,32 @@ fmod32 :: proc(x, y: f32) -> f32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
to_radians :: proc(degrees: f32) -> f32 { return degrees * TAU / 360; }
|
proc to_radians(degrees: f32) -> f32 { return degrees * TAU / 360; }
|
||||||
to_degrees :: proc(radians: f32) -> f32 { return radians * 360 / TAU; }
|
proc to_degrees(radians: f32) -> f32 { return radians * 360 / TAU; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dot2 :: proc(a, b: Vec2) -> f32 { c := a*b; return c.x + c.y; }
|
proc dot2(a, b: Vec2) -> f32 { c := a*b; return c.x + c.y; }
|
||||||
dot3 :: proc(a, b: Vec3) -> f32 { c := a*b; return c.x + c.y + c.z; }
|
proc dot3(a, b: Vec3) -> f32 { c := a*b; return c.x + c.y + c.z; }
|
||||||
dot4 :: proc(a, b: Vec4) -> f32 { c := a*b; return c.x + c.y + c.z + c.w; }
|
proc dot4(a, b: Vec4) -> f32 { c := a*b; return c.x + c.y + c.z + c.w; }
|
||||||
|
|
||||||
cross3 :: proc(x, y: Vec3) -> Vec3 {
|
proc cross3(x, y: Vec3) -> Vec3 {
|
||||||
a := swizzle(x, 1, 2, 0) * swizzle(y, 2, 0, 1);
|
a := swizzle(x, 1, 2, 0) * swizzle(y, 2, 0, 1);
|
||||||
b := swizzle(x, 2, 0, 1) * swizzle(y, 1, 2, 0);
|
b := swizzle(x, 2, 0, 1) * swizzle(y, 1, 2, 0);
|
||||||
return a - b;
|
return a - b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
vec2_mag :: proc(v: Vec2) -> f32 { return sqrt32(dot2(v, v)); }
|
proc vec2_mag(v: Vec2) -> f32 { return sqrt32(dot2(v, v)); }
|
||||||
vec3_mag :: proc(v: Vec3) -> f32 { return sqrt32(dot3(v, v)); }
|
proc vec3_mag(v: Vec3) -> f32 { return sqrt32(dot3(v, v)); }
|
||||||
vec4_mag :: proc(v: Vec4) -> f32 { return sqrt32(dot4(v, v)); }
|
proc vec4_mag(v: Vec4) -> f32 { return sqrt32(dot4(v, v)); }
|
||||||
|
|
||||||
vec2_norm :: proc(v: Vec2) -> Vec2 { return v / Vec2{vec2_mag(v)}; }
|
proc vec2_norm(v: Vec2) -> Vec2 { return v / Vec2{vec2_mag(v)}; }
|
||||||
vec3_norm :: proc(v: Vec3) -> Vec3 { return v / Vec3{vec3_mag(v)}; }
|
proc vec3_norm(v: Vec3) -> Vec3 { return v / Vec3{vec3_mag(v)}; }
|
||||||
vec4_norm :: proc(v: Vec4) -> Vec4 { return v / Vec4{vec4_mag(v)}; }
|
proc vec4_norm(v: Vec4) -> Vec4 { return v / Vec4{vec4_mag(v)}; }
|
||||||
|
|
||||||
vec2_norm0 :: proc(v: Vec2) -> Vec2 {
|
proc vec2_norm0(v: Vec2) -> Vec2 {
|
||||||
m := vec2_mag(v);
|
m := vec2_mag(v);
|
||||||
if m == 0 {
|
if m == 0 {
|
||||||
return Vec2{0};
|
return Vec2{0};
|
||||||
@@ -119,7 +119,7 @@ vec2_norm0 :: proc(v: Vec2) -> Vec2 {
|
|||||||
return v / Vec2{m};
|
return v / Vec2{m};
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3_norm0 :: proc(v: Vec3) -> Vec3 {
|
proc vec3_norm0(v: Vec3) -> Vec3 {
|
||||||
m := vec3_mag(v);
|
m := vec3_mag(v);
|
||||||
if m == 0 {
|
if m == 0 {
|
||||||
return Vec3{0};
|
return Vec3{0};
|
||||||
@@ -127,7 +127,7 @@ vec3_norm0 :: proc(v: Vec3) -> Vec3 {
|
|||||||
return v / Vec3{m};
|
return v / Vec3{m};
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4_norm0 :: proc(v: Vec4) -> Vec4 {
|
proc vec4_norm0(v: Vec4) -> Vec4 {
|
||||||
m := vec4_mag(v);
|
m := vec4_mag(v);
|
||||||
if m == 0 {
|
if m == 0 {
|
||||||
return Vec4{0};
|
return Vec4{0};
|
||||||
@@ -137,7 +137,7 @@ vec4_norm0 :: proc(v: Vec4) -> Vec4 {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
mat4_identity :: proc() -> Mat4 {
|
proc mat4_identity() -> Mat4 {
|
||||||
return Mat4{
|
return Mat4{
|
||||||
{1, 0, 0, 0},
|
{1, 0, 0, 0},
|
||||||
{0, 1, 0, 0},
|
{0, 1, 0, 0},
|
||||||
@@ -146,7 +146,7 @@ mat4_identity :: proc() -> Mat4 {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4_transpose :: proc(m: Mat4) -> Mat4 {
|
proc mat4_transpose(m: Mat4) -> Mat4 {
|
||||||
for j := 0; j < 4; j++ {
|
for j := 0; j < 4; j++ {
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
m[i][j], m[j][i] = m[j][i], m[i][j];
|
m[i][j], m[j][i] = m[j][i], m[i][j];
|
||||||
@@ -155,7 +155,7 @@ mat4_transpose :: proc(m: Mat4) -> Mat4 {
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4_mul :: proc(a, b: Mat4) -> Mat4 {
|
proc mat4_mul(a, b: Mat4) -> Mat4 {
|
||||||
c: Mat4;
|
c: Mat4;
|
||||||
for j := 0; j < 4; j++ {
|
for j := 0; j < 4; j++ {
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
@@ -168,7 +168,7 @@ mat4_mul :: proc(a, b: Mat4) -> Mat4 {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4_mul_vec4 :: proc(m: Mat4, v: Vec4) -> Vec4 {
|
proc mat4_mul_vec4(m: Mat4, v: Vec4) -> Vec4 {
|
||||||
return Vec4{
|
return Vec4{
|
||||||
m[0][0]*v.x + m[1][0]*v.y + m[2][0]*v.z + m[3][0]*v.w,
|
m[0][0]*v.x + m[1][0]*v.y + m[2][0]*v.z + m[3][0]*v.w,
|
||||||
m[0][1]*v.x + m[1][1]*v.y + m[2][1]*v.z + m[3][1]*v.w,
|
m[0][1]*v.x + m[1][1]*v.y + m[2][1]*v.z + m[3][1]*v.w,
|
||||||
@@ -177,7 +177,7 @@ mat4_mul_vec4 :: proc(m: Mat4, v: Vec4) -> Vec4 {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4_inverse :: proc(m: Mat4) -> Mat4 {
|
proc mat4_inverse(m: Mat4) -> Mat4 {
|
||||||
o: Mat4;
|
o: Mat4;
|
||||||
|
|
||||||
sf00 := m[2][2] * m[3][3] - m[3][2] * m[2][3];
|
sf00 := m[2][2] * m[3][3] - m[3][2] * m[2][3];
|
||||||
@@ -246,7 +246,7 @@ mat4_inverse :: proc(m: Mat4) -> Mat4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mat4_translate :: proc(v: Vec3) -> Mat4 {
|
proc mat4_translate(v: Vec3) -> Mat4 {
|
||||||
m := mat4_identity();
|
m := mat4_identity();
|
||||||
m[3][0] = v.x;
|
m[3][0] = v.x;
|
||||||
m[3][1] = v.y;
|
m[3][1] = v.y;
|
||||||
@@ -255,7 +255,7 @@ mat4_translate :: proc(v: Vec3) -> Mat4 {
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4_rotate :: proc(v: Vec3, angle_radians: f32) -> Mat4 {
|
proc mat4_rotate(v: Vec3, angle_radians: f32) -> Mat4 {
|
||||||
c := cos32(angle_radians);
|
c := cos32(angle_radians);
|
||||||
s := sin32(angle_radians);
|
s := sin32(angle_radians);
|
||||||
|
|
||||||
@@ -282,14 +282,14 @@ mat4_rotate :: proc(v: Vec3, angle_radians: f32) -> Mat4 {
|
|||||||
return rot;
|
return rot;
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4_scale :: proc(m: Mat4, v: Vec3) -> Mat4 {
|
proc mat4_scale(m: Mat4, v: Vec3) -> Mat4 {
|
||||||
m[0][0] *= v.x;
|
m[0][0] *= v.x;
|
||||||
m[1][1] *= v.y;
|
m[1][1] *= v.y;
|
||||||
m[2][2] *= v.z;
|
m[2][2] *= v.z;
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4_scalef :: proc(m: Mat4, s: f32) -> Mat4 {
|
proc mat4_scalef(m: Mat4, s: f32) -> Mat4 {
|
||||||
m[0][0] *= s;
|
m[0][0] *= s;
|
||||||
m[1][1] *= s;
|
m[1][1] *= s;
|
||||||
m[2][2] *= s;
|
m[2][2] *= s;
|
||||||
@@ -297,7 +297,7 @@ mat4_scalef :: proc(m: Mat4, s: f32) -> Mat4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mat4_look_at :: proc(eye, centre, up: Vec3) -> Mat4 {
|
proc mat4_look_at(eye, centre, up: Vec3) -> Mat4 {
|
||||||
f := vec3_norm(centre - eye);
|
f := vec3_norm(centre - eye);
|
||||||
s := vec3_norm(cross3(f, up));
|
s := vec3_norm(cross3(f, up));
|
||||||
u := cross3(s, f);
|
u := cross3(s, f);
|
||||||
@@ -311,7 +311,7 @@ mat4_look_at :: proc(eye, centre, up: Vec3) -> Mat4 {
|
|||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
mat4_perspective :: proc(fovy, aspect, near, far: f32) -> Mat4 {
|
proc mat4_perspective(fovy, aspect, near, far: f32) -> Mat4 {
|
||||||
m: Mat4;
|
m: Mat4;
|
||||||
tan_half_fovy := tan32(0.5 * fovy);
|
tan_half_fovy := tan32(0.5 * fovy);
|
||||||
m[0][0] = 1.0 / (aspect*tan_half_fovy);
|
m[0][0] = 1.0 / (aspect*tan_half_fovy);
|
||||||
@@ -323,7 +323,7 @@ mat4_perspective :: proc(fovy, aspect, near, far: f32) -> Mat4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mat4_ortho3d :: proc(left, right, bottom, top, near, far: f32) -> Mat4 {
|
proc mat4_ortho3d(left, right, bottom, top, near, far: f32) -> Mat4 {
|
||||||
m := mat4_identity();
|
m := mat4_identity();
|
||||||
m[0][0] = +2.0 / (right - left);
|
m[0][0] = +2.0 / (right - left);
|
||||||
m[1][1] = +2.0 / (top - bottom);
|
m[1][1] = +2.0 / (top - bottom);
|
||||||
|
|||||||
+32
-32
@@ -1,32 +1,32 @@
|
|||||||
#import "fmt.odin";
|
#import "fmt.odin";
|
||||||
#import "os.odin";
|
#import "os.odin";
|
||||||
|
|
||||||
set :: proc(data: rawptr, value: i32, len: int) -> rawptr #link_name "__mem_set" {
|
proc set(data: rawptr, value: i32, len: int) -> rawptr #link_name "__mem_set" {
|
||||||
llvm_memset_64bit :: proc(dst: rawptr, val: byte, len: int, align: i32, is_volatile: bool) #foreign "llvm.memset.p0i8.i64"
|
proc llvm_memset_64bit(dst: rawptr, val: byte, len: int, align: i32, is_volatile: bool) #foreign "llvm.memset.p0i8.i64"
|
||||||
llvm_memset_64bit(data, value as byte, len, 1, false);
|
llvm_memset_64bit(data, value as byte, len, 1, false);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
zero :: proc(data: rawptr, len: int) -> rawptr #link_name "__mem_zero" {
|
proc zero(data: rawptr, len: int) -> rawptr #link_name "__mem_zero" {
|
||||||
return set(data, 0, len);
|
return set(data, 0, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
copy :: proc(dst, src: rawptr, len: int) -> rawptr #link_name "__mem_copy" {
|
proc copy(dst, src: rawptr, len: int) -> rawptr #link_name "__mem_copy" {
|
||||||
// NOTE(bill): This _must_ implemented like C's memmove
|
// NOTE(bill): This _must_ implemented like C's memmove
|
||||||
llvm_memmove_64bit :: proc(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #foreign "llvm.memmove.p0i8.p0i8.i64"
|
proc llvm_memmove_64bit(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #foreign "llvm.memmove.p0i8.p0i8.i64"
|
||||||
llvm_memmove_64bit(dst, src, len, 1, false);
|
llvm_memmove_64bit(dst, src, len, 1, false);
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_non_overlapping :: proc(dst, src: rawptr, len: int) -> rawptr #link_name "__mem_copy_non_overlapping" {
|
proc copy_non_overlapping(dst, src: rawptr, len: int) -> rawptr #link_name "__mem_copy_non_overlapping" {
|
||||||
// NOTE(bill): This _must_ implemented like C's memcpy
|
// NOTE(bill): This _must_ implemented like C's memcpy
|
||||||
llvm_memcpy_64bit :: proc(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #foreign "llvm.memcpy.p0i8.p0i8.i64"
|
proc llvm_memcpy_64bit(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #foreign "llvm.memcpy.p0i8.p0i8.i64"
|
||||||
llvm_memcpy_64bit(dst, src, len, 1, false);
|
llvm_memcpy_64bit(dst, src, len, 1, false);
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
compare :: proc(dst, src: rawptr, n: int) -> int #link_name "__mem_compare" {
|
proc compare(dst, src: rawptr, n: int) -> int #link_name "__mem_compare" {
|
||||||
// Translation of http://mgronhol.github.io/fast-strcmp/
|
// Translation of http://mgronhol.github.io/fast-strcmp/
|
||||||
a := slice_ptr(dst as ^byte, n);
|
a := slice_ptr(dst as ^byte, n);
|
||||||
b := slice_ptr(src as ^byte, n);
|
b := slice_ptr(src as ^byte, n);
|
||||||
@@ -63,19 +63,19 @@ compare :: proc(dst, src: rawptr, n: int) -> int #link_name "__mem_compare" {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
kilobytes :: proc(x: int) -> int #inline { return (x) * 1024; }
|
proc kilobytes(x: int) -> int #inline { return (x) * 1024; }
|
||||||
megabytes :: proc(x: int) -> int #inline { return kilobytes(x) * 1024; }
|
proc megabytes(x: int) -> int #inline { return kilobytes(x) * 1024; }
|
||||||
gigabytes :: proc(x: int) -> int #inline { return gigabytes(x) * 1024; }
|
proc gigabytes(x: int) -> int #inline { return gigabytes(x) * 1024; }
|
||||||
terabytes :: proc(x: int) -> int #inline { return terabytes(x) * 1024; }
|
proc terabytes(x: int) -> int #inline { return terabytes(x) * 1024; }
|
||||||
|
|
||||||
is_power_of_two :: proc(x: int) -> bool {
|
proc is_power_of_two(x: int) -> bool {
|
||||||
if x <= 0 {
|
if x <= 0 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (x & (x-1)) == 0;
|
return (x & (x-1)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
align_forward :: proc(ptr: rawptr, align: int) -> rawptr {
|
proc align_forward(ptr: rawptr, align: int) -> rawptr {
|
||||||
assert(is_power_of_two(align));
|
assert(is_power_of_two(align));
|
||||||
|
|
||||||
a := align as uint;
|
a := align as uint;
|
||||||
@@ -89,10 +89,10 @@ align_forward :: proc(ptr: rawptr, align: int) -> rawptr {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
AllocationHeader :: struct {
|
type Allocation_Header struct {
|
||||||
size: int;
|
size: int;
|
||||||
}
|
}
|
||||||
allocation_header_fill :: proc(header: ^AllocationHeader, data: rawptr, size: int) {
|
proc allocation_header_fill(header: ^Allocation_Header, data: rawptr, size: int) {
|
||||||
header.size = size;
|
header.size = size;
|
||||||
ptr := (header+1) as ^int;
|
ptr := (header+1) as ^int;
|
||||||
|
|
||||||
@@ -100,12 +100,12 @@ allocation_header_fill :: proc(header: ^AllocationHeader, data: rawptr, size: in
|
|||||||
(ptr+i)^ = -1;
|
(ptr+i)^ = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allocation_header :: proc(data: rawptr) -> ^AllocationHeader {
|
proc allocation_header(data: rawptr) -> ^Allocation_Header {
|
||||||
p := data as ^int;
|
p := data as ^int;
|
||||||
for (p-1)^ == -1 {
|
for (p-1)^ == -1 {
|
||||||
p = (p-1);
|
p = (p-1);
|
||||||
}
|
}
|
||||||
return (p as ^AllocationHeader)-1;
|
return (p as ^Allocation_Header)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -114,13 +114,13 @@ allocation_header :: proc(data: rawptr) -> ^AllocationHeader {
|
|||||||
|
|
||||||
// Custom allocators
|
// Custom allocators
|
||||||
|
|
||||||
Arena :: struct {
|
type Arena struct {
|
||||||
backing: Allocator;
|
backing: Allocator;
|
||||||
memory: []byte;
|
memory: []byte;
|
||||||
temp_count: int;
|
temp_count: int;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arena_Temp_Memory :: struct {
|
type Arena_Temp_Memory struct {
|
||||||
arena: ^Arena;
|
arena: ^Arena;
|
||||||
original_count: int;
|
original_count: int;
|
||||||
}
|
}
|
||||||
@@ -129,19 +129,19 @@ Arena_Temp_Memory :: struct {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
init_arena_from_memory :: proc(using a: ^Arena, data: []byte) {
|
proc init_arena_from_memory(using a: ^Arena, data: []byte) {
|
||||||
backing = Allocator{};
|
backing = Allocator{};
|
||||||
memory = data[:0];
|
memory = data[:0];
|
||||||
temp_count = 0;
|
temp_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
init_arena_from_context :: proc(using a: ^Arena, size: int) {
|
proc init_arena_from_context(using a: ^Arena, size: int) {
|
||||||
backing = context.allocator;
|
backing = context.allocator;
|
||||||
memory = new_slice(byte, 0, size);
|
memory = new_slice(byte, 0, size);
|
||||||
temp_count = 0;
|
temp_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
free_arena :: proc(using a: ^Arena) {
|
proc free_arena(using a: ^Arena) {
|
||||||
if backing.procedure != nil {
|
if backing.procedure != nil {
|
||||||
push_allocator backing {
|
push_allocator backing {
|
||||||
free(memory.data);
|
free(memory.data);
|
||||||
@@ -150,14 +150,14 @@ free_arena :: proc(using a: ^Arena) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
arena_allocator :: proc(arena: ^Arena) -> Allocator {
|
proc arena_allocator(arena: ^Arena) -> Allocator {
|
||||||
return Allocator{
|
return Allocator{
|
||||||
procedure = arena_allocator_proc,
|
procedure = arena_allocator_proc,
|
||||||
data = arena,
|
data = arena,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
proc arena_allocator_proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||||
size, alignment: int,
|
size, alignment: int,
|
||||||
old_memory: rawptr, old_size: int, flags: u64) -> rawptr {
|
old_memory: rawptr, old_size: int, flags: u64) -> rawptr {
|
||||||
arena := allocator_data as ^Arena;
|
arena := allocator_data as ^Arena;
|
||||||
@@ -192,7 +192,7 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
begin_arena_temp_memory :: proc(a: ^Arena) -> Arena_Temp_Memory {
|
proc begin_arena_temp_memory(a: ^Arena) -> Arena_Temp_Memory {
|
||||||
tmp: Arena_Temp_Memory;
|
tmp: Arena_Temp_Memory;
|
||||||
tmp.arena = a;
|
tmp.arena = a;
|
||||||
tmp.original_count = a.memory.count;
|
tmp.original_count = a.memory.count;
|
||||||
@@ -200,7 +200,7 @@ begin_arena_temp_memory :: proc(a: ^Arena) -> Arena_Temp_Memory {
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
end_arena_temp_memory :: proc(using tmp: Arena_Temp_Memory) {
|
proc end_arena_temp_memory(using tmp: Arena_Temp_Memory) {
|
||||||
assert(arena.memory.count >= original_count);
|
assert(arena.memory.count >= original_count);
|
||||||
assert(arena.temp_count > 0);
|
assert(arena.temp_count > 0);
|
||||||
arena.memory.count = original_count;
|
arena.memory.count = original_count;
|
||||||
@@ -213,8 +213,8 @@ end_arena_temp_memory :: proc(using tmp: Arena_Temp_Memory) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
align_of_type_info :: proc(type_info: ^Type_Info) -> int {
|
proc align_of_type_info(type_info: ^Type_Info) -> int {
|
||||||
prev_pow2 :: proc(n: i64) -> i64 {
|
proc prev_pow2(n: i64) -> i64 {
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -270,12 +270,12 @@ align_of_type_info :: proc(type_info: ^Type_Info) -> int {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
align_formula :: proc(size, align: int) -> int {
|
proc align_formula(size, align: int) -> int {
|
||||||
result := size + align-1;
|
result := size + align-1;
|
||||||
return result - result%align;
|
return result - result%align;
|
||||||
};
|
};
|
||||||
|
|
||||||
size_of_type_info :: proc(type_info: ^Type_Info) -> int {
|
proc size_of_type_info(type_info: ^Type_Info) -> int {
|
||||||
WORD_SIZE :: size_of(int);
|
WORD_SIZE :: size_of(int);
|
||||||
using Type_Info;
|
using Type_Info;
|
||||||
match type info : type_info {
|
match type info : type_info {
|
||||||
@@ -309,7 +309,7 @@ size_of_type_info :: proc(type_info: ^Type_Info) -> int {
|
|||||||
case Slice:
|
case Slice:
|
||||||
return 3*WORD_SIZE;
|
return 3*WORD_SIZE;
|
||||||
case Vector:
|
case Vector:
|
||||||
is_bool :: proc(type_info: ^Type_Info) -> bool {
|
proc is_bool(type_info: ^Type_Info) -> bool {
|
||||||
match type info : type_info {
|
match type info : type_info {
|
||||||
case Named:
|
case Named:
|
||||||
return is_bool(info.base);
|
return is_bool(info.base);
|
||||||
|
|||||||
+27
-27
@@ -2,37 +2,37 @@
|
|||||||
#import win32 "sys/windows.odin" when ODIN_OS == "windows";
|
#import win32 "sys/windows.odin" when ODIN_OS == "windows";
|
||||||
#include "opengl_constants.odin";
|
#include "opengl_constants.odin";
|
||||||
|
|
||||||
Clear :: proc(mask: u32) #foreign "glClear"
|
proc Clear (mask: u32) #foreign "glClear"
|
||||||
ClearColor :: proc(r, g, b, a: f32) #foreign "glClearColor"
|
proc ClearColor (r, g, b, a: f32) #foreign "glClearColor"
|
||||||
Begin :: proc(mode: i32) #foreign "glBegin"
|
proc Begin (mode: i32) #foreign "glBegin"
|
||||||
End :: proc() #foreign "glEnd"
|
proc End () #foreign "glEnd"
|
||||||
Finish :: proc() #foreign "glFinish"
|
proc Finish () #foreign "glFinish"
|
||||||
BlendFunc :: proc(sfactor, dfactor: i32) #foreign "glBlendFunc"
|
proc BlendFunc (sfactor, dfactor: i32) #foreign "glBlendFunc"
|
||||||
Enable :: proc(cap: i32) #foreign "glEnable"
|
proc Enable (cap: i32) #foreign "glEnable"
|
||||||
Disable :: proc(cap: i32) #foreign "glDisable"
|
proc Disable (cap: i32) #foreign "glDisable"
|
||||||
GenTextures :: proc(count: i32, result: ^u32) #foreign "glGenTextures"
|
proc GenTextures (count: i32, result: ^u32) #foreign "glGenTextures"
|
||||||
DeleteTextures :: proc(count: i32, result: ^u32) #foreign "glDeleteTextures"
|
proc DeleteTextures(count: i32, result: ^u32) #foreign "glDeleteTextures"
|
||||||
TexParameteri :: proc(target, pname, param: i32) #foreign "glTexParameteri"
|
proc TexParameteri (target, pname, param: i32) #foreign "glTexParameteri"
|
||||||
TexParameterf :: proc(target: i32, pname: i32, param: f32) #foreign "glTexParameterf"
|
proc TexParameterf (target: i32, pname: i32, param: f32) #foreign "glTexParameterf"
|
||||||
BindTexture :: proc(target: i32, texture: u32) #foreign "glBindTexture"
|
proc BindTexture (target: i32, texture: u32) #foreign "glBindTexture"
|
||||||
LoadIdentity :: proc() #foreign "glLoadIdentity"
|
proc LoadIdentity () #foreign "glLoadIdentity"
|
||||||
Viewport :: proc(x, y, width, height: i32) #foreign "glViewport"
|
proc Viewport (x, y, width, height: i32) #foreign "glViewport"
|
||||||
Ortho :: proc(left, right, bottom, top, near, far: f64) #foreign "glOrtho"
|
proc Ortho (left, right, bottom, top, near, far: f64) #foreign "glOrtho"
|
||||||
Color3f :: proc(r, g, b: f32) #foreign "glColor3f"
|
proc Color3f (r, g, b: f32) #foreign "glColor3f"
|
||||||
Vertex3f :: proc(x, y, z: f32) #foreign "glVertex3f"
|
proc Vertex3f (x, y, z: f32) #foreign "glVertex3f"
|
||||||
TexImage2D :: proc(target, level, internal_format,
|
proc TexImage2D (target, level, internal_format,
|
||||||
width, height, border,
|
width, height, border,
|
||||||
format, _type: i32, pixels: rawptr) #foreign "glTexImage2D"
|
format, _type: i32, pixels: rawptr) #foreign "glTexImage2D"
|
||||||
|
|
||||||
GetError :: proc() -> i32 #foreign "glGetError"
|
proc GetError () -> i32 #foreign "glGetError"
|
||||||
GetString :: proc(name: i32) -> ^byte #foreign "glGetString"
|
proc GetString (name: i32) -> ^byte #foreign "glGetString"
|
||||||
GetIntegerv :: proc(name: i32, v: ^i32) #foreign "glGetIntegerv"
|
proc GetIntegerv(name: i32, v: ^i32) #foreign "glGetIntegerv"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_libgl := win32.LoadLibraryA(("opengl32.dll\x00" as string).data);
|
_libgl := win32.LoadLibraryA(("opengl32.dll\x00" as string).data);
|
||||||
|
|
||||||
GetProcAddress :: proc(name: string) -> proc() {
|
proc GetProcAddress(name: string) -> proc() {
|
||||||
assert(name[name.count-1] == 0);
|
assert(name[name.count-1] == 0);
|
||||||
res := win32.wglGetProcAddress(name.data);
|
res := win32.wglGetProcAddress(name.data);
|
||||||
if res == nil {
|
if res == nil {
|
||||||
@@ -100,8 +100,8 @@ UniformMatrix4fv: proc(loc: i32, count: u32, transpose: i32, value: ^f32);
|
|||||||
|
|
||||||
GetUniformLocation: proc(program: u32, name: ^byte) -> i32;
|
GetUniformLocation: proc(program: u32, name: ^byte) -> i32;
|
||||||
|
|
||||||
init :: proc() {
|
proc init() {
|
||||||
set_proc_address :: proc(p: rawptr, name: string) #inline { (p as ^proc())^ = GetProcAddress(name); }
|
proc set_proc_address(p: rawptr, name: string) #inline { (p as ^proc())^ = GetProcAddress(name); }
|
||||||
|
|
||||||
set_proc_address(^GenBuffers, "glGenBuffers\x00");
|
set_proc_address(^GenBuffers, "glGenBuffers\x00");
|
||||||
set_proc_address(^GenVertexArrays, "glGenVertexArrays\x00");
|
set_proc_address(^GenVertexArrays, "glGenVertexArrays\x00");
|
||||||
|
|||||||
+18
-18
@@ -1,19 +1,19 @@
|
|||||||
#import win32 "sys/windows.odin";
|
#import win32 "sys/windows.odin";
|
||||||
#import "fmt.odin";
|
#import "fmt.odin";
|
||||||
|
|
||||||
File_Time :: type u64;
|
type File_Time u64;
|
||||||
|
|
||||||
File_Handle :: raw_union {
|
type File_Handle raw_union {
|
||||||
p: rawptr;
|
p: rawptr;
|
||||||
i: int;
|
i: int;
|
||||||
}
|
}
|
||||||
|
|
||||||
File :: struct {
|
type File struct {
|
||||||
handle: File_Handle;
|
handle: File_Handle;
|
||||||
last_write_time: File_Time;
|
last_write_time: File_Time;
|
||||||
}
|
}
|
||||||
|
|
||||||
open :: proc(name: string) -> (File, bool) {
|
proc open(name: string) -> (File, bool) {
|
||||||
using win32;
|
using win32;
|
||||||
buf: [300]byte;
|
buf: [300]byte;
|
||||||
copy(buf[:], name as []byte);
|
copy(buf[:], name as []byte);
|
||||||
@@ -24,7 +24,7 @@ open :: proc(name: string) -> (File, bool) {
|
|||||||
return f, success;
|
return f, success;
|
||||||
}
|
}
|
||||||
|
|
||||||
create :: proc(name: string) -> (File, bool) {
|
proc create(name: string) -> (File, bool) {
|
||||||
using win32;
|
using win32;
|
||||||
buf: [300]byte;
|
buf: [300]byte;
|
||||||
copy(buf[:], name as []byte);
|
copy(buf[:], name as []byte);
|
||||||
@@ -35,16 +35,16 @@ create :: proc(name: string) -> (File, bool) {
|
|||||||
return f, success;
|
return f, success;
|
||||||
}
|
}
|
||||||
|
|
||||||
close :: proc(using f: ^File) {
|
proc close(using f: ^File) {
|
||||||
win32.CloseHandle(handle.p as win32.HANDLE);
|
win32.CloseHandle(handle.p as win32.HANDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
write :: proc(using f: ^File, buf: []byte) -> bool {
|
proc write(using f: ^File, buf: []byte) -> bool {
|
||||||
bytes_written: i32;
|
bytes_written: i32;
|
||||||
return win32.WriteFile(handle.p as win32.HANDLE, buf.data, buf.count as i32, ^bytes_written, nil) != 0;
|
return win32.WriteFile(handle.p as win32.HANDLE, buf.data, buf.count as i32, ^bytes_written, nil) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
file_has_changed :: proc(f: ^File) -> bool {
|
proc file_has_changed(f: ^File) -> bool {
|
||||||
last_write_time := last_write_time(f);
|
last_write_time := last_write_time(f);
|
||||||
if f.last_write_time != last_write_time {
|
if f.last_write_time != last_write_time {
|
||||||
f.last_write_time = last_write_time;
|
f.last_write_time = last_write_time;
|
||||||
@@ -55,7 +55,7 @@ file_has_changed :: proc(f: ^File) -> bool {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
last_write_time :: proc(f: ^File) -> File_Time {
|
proc last_write_time(f: ^File) -> File_Time {
|
||||||
file_info: win32.BY_HANDLE_FILE_INFORMATION;
|
file_info: win32.BY_HANDLE_FILE_INFORMATION;
|
||||||
win32.GetFileInformationByHandle(f.handle.p as win32.HANDLE, ^file_info);
|
win32.GetFileInformationByHandle(f.handle.p as win32.HANDLE, ^file_info);
|
||||||
l := file_info.last_write_time.low_date_time as File_Time;
|
l := file_info.last_write_time.low_date_time as File_Time;
|
||||||
@@ -63,7 +63,7 @@ last_write_time :: proc(f: ^File) -> File_Time {
|
|||||||
return l | h << 32;
|
return l | h << 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
last_write_time_by_name :: proc(name: string) -> File_Time {
|
proc last_write_time_by_name(name: string) -> File_Time {
|
||||||
last_write_time: win32.FILETIME;
|
last_write_time: win32.FILETIME;
|
||||||
data: win32.WIN32_FILE_ATTRIBUTE_DATA;
|
data: win32.WIN32_FILE_ATTRIBUTE_DATA;
|
||||||
buf: [1024]byte;
|
buf: [1024]byte;
|
||||||
@@ -84,7 +84,7 @@ last_write_time_by_name :: proc(name: string) -> File_Time {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
File_Standard :: enum {
|
type File_Standard enum {
|
||||||
INPUT,
|
INPUT,
|
||||||
OUTPUT,
|
OUTPUT,
|
||||||
ERROR,
|
ERROR,
|
||||||
@@ -103,7 +103,7 @@ stderr := ^__std_files[File_Standard.ERROR];
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
read_entire_file :: proc(name: string) -> ([]byte, bool) {
|
proc read_entire_file(name: string) -> ([]byte, bool) {
|
||||||
buf: [300]byte;
|
buf: [300]byte;
|
||||||
copy(buf[:], name as []byte);
|
copy(buf[:], name as []byte);
|
||||||
|
|
||||||
@@ -151,25 +151,25 @@ read_entire_file :: proc(name: string) -> ([]byte, bool) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
heap_alloc :: proc(size: int) -> rawptr {
|
proc heap_alloc(size: int) -> rawptr {
|
||||||
return win32.HeapAlloc(win32.GetProcessHeap(), win32.HEAP_ZERO_MEMORY, size);
|
return win32.HeapAlloc(win32.GetProcessHeap(), win32.HEAP_ZERO_MEMORY, size);
|
||||||
}
|
}
|
||||||
heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
|
proc heap_resize(ptr: rawptr, new_size: int) -> rawptr {
|
||||||
return win32.HeapReAlloc(win32.GetProcessHeap(), win32.HEAP_ZERO_MEMORY, ptr, new_size);
|
return win32.HeapReAlloc(win32.GetProcessHeap(), win32.HEAP_ZERO_MEMORY, ptr, new_size);
|
||||||
}
|
}
|
||||||
heap_free :: proc(ptr: rawptr) {
|
proc heap_free(ptr: rawptr) {
|
||||||
win32.HeapFree(win32.GetProcessHeap(), 0, ptr);
|
win32.HeapFree(win32.GetProcessHeap(), 0, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exit :: proc(code: int) {
|
proc exit(code: int) {
|
||||||
win32.ExitProcess(code as u32);
|
win32.ExitProcess(code as u32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
current_thread_id :: proc() -> int {
|
proc current_thread_id() -> int {
|
||||||
GetCurrentThreadId :: proc() -> u32 #foreign #dll_import
|
proc GetCurrentThreadId() -> u32 #foreign #dll_import
|
||||||
return GetCurrentThreadId() as int;
|
return GetCurrentThreadId() as int;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-13
@@ -1,11 +1,11 @@
|
|||||||
#import win32 "sys/windows.odin" when ODIN_OS == "windows";
|
#import win32 "sys/windows.odin" when ODIN_OS == "windows";
|
||||||
#import "atomic.odin";
|
#import "atomic.odin";
|
||||||
|
|
||||||
Semaphore :: struct {
|
type Semaphore struct {
|
||||||
handle: win32.HANDLE;
|
handle: win32.HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mutex :: struct {
|
type Mutex struct {
|
||||||
semaphore: Semaphore;
|
semaphore: Semaphore;
|
||||||
counter: i32;
|
counter: i32;
|
||||||
owner: i32;
|
owner: i32;
|
||||||
@@ -13,39 +13,39 @@ Mutex :: struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
current_thread_id :: proc() -> i32 {
|
proc current_thread_id() -> i32 {
|
||||||
return win32.GetCurrentThreadId() as i32;
|
return win32.GetCurrentThreadId() as i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
semaphore_init :: proc(s: ^Semaphore) {
|
proc semaphore_init(s: ^Semaphore) {
|
||||||
s.handle = win32.CreateSemaphoreA(nil, 0, 1<<31-1, nil);
|
s.handle = win32.CreateSemaphoreA(nil, 0, 1<<31-1, nil);
|
||||||
}
|
}
|
||||||
|
|
||||||
semaphore_destroy :: proc(s: ^Semaphore) {
|
proc semaphore_destroy(s: ^Semaphore) {
|
||||||
win32.CloseHandle(s.handle);
|
win32.CloseHandle(s.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
semaphore_post :: proc(s: ^Semaphore, count: int) {
|
proc semaphore_post(s: ^Semaphore, count: int) {
|
||||||
win32.ReleaseSemaphore(s.handle, count as i32, nil);
|
win32.ReleaseSemaphore(s.handle, count as i32, nil);
|
||||||
}
|
}
|
||||||
|
|
||||||
semaphore_release :: proc(s: ^Semaphore) #inline { semaphore_post(s, 1); }
|
proc semaphore_release(s: ^Semaphore) #inline { semaphore_post(s, 1); }
|
||||||
|
|
||||||
semaphore_wait :: proc(s: ^Semaphore) {
|
proc semaphore_wait(s: ^Semaphore) {
|
||||||
win32.WaitForSingleObject(s.handle, win32.INFINITE);
|
win32.WaitForSingleObject(s.handle, win32.INFINITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mutex_init :: proc(m: ^Mutex) {
|
proc mutex_init(m: ^Mutex) {
|
||||||
atomic.store32(^m.counter, 0);
|
atomic.store32(^m.counter, 0);
|
||||||
atomic.store32(^m.owner, current_thread_id());
|
atomic.store32(^m.owner, current_thread_id());
|
||||||
semaphore_init(^m.semaphore);
|
semaphore_init(^m.semaphore);
|
||||||
m.recursion = 0;
|
m.recursion = 0;
|
||||||
}
|
}
|
||||||
mutex_destroy :: proc(m: ^Mutex) {
|
proc mutex_destroy(m: ^Mutex) {
|
||||||
semaphore_destroy(^m.semaphore);
|
semaphore_destroy(^m.semaphore);
|
||||||
}
|
}
|
||||||
mutex_lock :: proc(m: ^Mutex) {
|
proc mutex_lock(m: ^Mutex) {
|
||||||
thread_id := current_thread_id();
|
thread_id := current_thread_id();
|
||||||
if atomic.fetch_add32(^m.counter, 1) > 0 {
|
if atomic.fetch_add32(^m.counter, 1) > 0 {
|
||||||
if thread_id != atomic.load32(^m.owner) {
|
if thread_id != atomic.load32(^m.owner) {
|
||||||
@@ -55,7 +55,7 @@ mutex_lock :: proc(m: ^Mutex) {
|
|||||||
atomic.store32(^m.owner, thread_id);
|
atomic.store32(^m.owner, thread_id);
|
||||||
m.recursion++;
|
m.recursion++;
|
||||||
}
|
}
|
||||||
mutex_try_lock :: proc(m: ^Mutex) -> bool {
|
proc mutex_try_lock(m: ^Mutex) -> bool {
|
||||||
thread_id := current_thread_id();
|
thread_id := current_thread_id();
|
||||||
if atomic.load32(^m.owner) == thread_id {
|
if atomic.load32(^m.owner) == thread_id {
|
||||||
atomic.fetch_add32(^m.counter, 1);
|
atomic.fetch_add32(^m.counter, 1);
|
||||||
@@ -72,7 +72,7 @@ mutex_try_lock :: proc(m: ^Mutex) -> bool {
|
|||||||
m.recursion++;
|
m.recursion++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
mutex_unlock :: proc(m: ^Mutex) {
|
proc mutex_unlock(m: ^Mutex) {
|
||||||
recursion: i32;
|
recursion: i32;
|
||||||
thread_id := current_thread_id();
|
thread_id := current_thread_id();
|
||||||
assert(thread_id == atomic.load32(^m.owner));
|
assert(thread_id == atomic.load32(^m.owner));
|
||||||
|
|||||||
+106
-106
@@ -1,22 +1,22 @@
|
|||||||
#foreign_system_library "user32" when ODIN_OS == "windows";
|
#foreign_system_library "user32" when ODIN_OS == "windows";
|
||||||
#foreign_system_library "gdi32" when ODIN_OS == "windows";
|
#foreign_system_library "gdi32" when ODIN_OS == "windows";
|
||||||
|
|
||||||
HANDLE :: type rawptr;
|
type HANDLE rawptr;
|
||||||
HWND :: type HANDLE;
|
type HWND HANDLE;
|
||||||
HDC :: type HANDLE;
|
type HDC HANDLE;
|
||||||
HINSTANCE :: type HANDLE;
|
type HINSTANCE HANDLE;
|
||||||
HICON :: type HANDLE;
|
type HICON HANDLE;
|
||||||
HCURSOR :: type HANDLE;
|
type HCURSOR HANDLE;
|
||||||
HMENU :: type HANDLE;
|
type HMENU HANDLE;
|
||||||
HBRUSH :: type HANDLE;
|
type HBRUSH HANDLE;
|
||||||
HGDIOBJ :: type HANDLE;
|
type HGDIOBJ HANDLE;
|
||||||
HMODULE :: type HANDLE;
|
type HMODULE HANDLE;
|
||||||
WPARAM :: type uint;
|
type WPARAM uint;
|
||||||
LPARAM :: type int;
|
type LPARAM int;
|
||||||
LRESULT :: type int;
|
type LRESULT int;
|
||||||
ATOM :: type i16;
|
type ATOM i16;
|
||||||
BOOL :: type i32;
|
type BOOL i32;
|
||||||
WNDPROC :: type proc(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT;
|
type WNDPROC proc(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT;
|
||||||
|
|
||||||
INVALID_HANDLE_VALUE :: (-1 as int) as HANDLE;
|
INVALID_HANDLE_VALUE :: (-1 as int) as HANDLE;
|
||||||
|
|
||||||
@@ -50,12 +50,12 @@ SM_CYSCREEN :: 1;
|
|||||||
|
|
||||||
SW_SHOW :: 5;
|
SW_SHOW :: 5;
|
||||||
|
|
||||||
POINT :: struct #ordered {
|
type POINT struct #ordered {
|
||||||
x, y: i32;
|
x, y: i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
WNDCLASSEXA :: struct #ordered {
|
type WNDCLASSEXA struct #ordered {
|
||||||
size, style: u32;
|
size, style: u32;
|
||||||
wnd_proc: WNDPROC;
|
wnd_proc: WNDPROC;
|
||||||
cls_extra, wnd_extra: i32;
|
cls_extra, wnd_extra: i32;
|
||||||
@@ -67,7 +67,7 @@ WNDCLASSEXA :: struct #ordered {
|
|||||||
sm: HICON;
|
sm: HICON;
|
||||||
}
|
}
|
||||||
|
|
||||||
MSG :: struct #ordered {
|
type MSG struct #ordered {
|
||||||
hwnd: HWND;
|
hwnd: HWND;
|
||||||
message: u32;
|
message: u32;
|
||||||
wparam: WPARAM;
|
wparam: WPARAM;
|
||||||
@@ -76,18 +76,18 @@ MSG :: struct #ordered {
|
|||||||
pt: POINT;
|
pt: POINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
RECT :: struct #ordered {
|
type RECT struct #ordered {
|
||||||
left: i32;
|
left: i32;
|
||||||
top: i32;
|
top: i32;
|
||||||
right: i32;
|
right: i32;
|
||||||
bottom: i32;
|
bottom: i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILETIME :: struct #ordered {
|
type FILETIME struct #ordered {
|
||||||
low_date_time, high_date_time: u32;
|
low_date_time, high_date_time: u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
BY_HANDLE_FILE_INFORMATION :: struct #ordered {
|
type BY_HANDLE_FILE_INFORMATION struct #ordered {
|
||||||
file_attributes: u32;
|
file_attributes: u32;
|
||||||
creation_time,
|
creation_time,
|
||||||
last_access_time,
|
last_access_time,
|
||||||
@@ -100,7 +100,7 @@ BY_HANDLE_FILE_INFORMATION :: struct #ordered {
|
|||||||
file_index_low: u32;
|
file_index_low: u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
WIN32_FILE_ATTRIBUTE_DATA :: struct #ordered {
|
type WIN32_FILE_ATTRIBUTE_DATA struct #ordered {
|
||||||
file_attributes: u32;
|
file_attributes: u32;
|
||||||
creation_time,
|
creation_time,
|
||||||
last_access_time,
|
last_access_time,
|
||||||
@@ -109,72 +109,72 @@ WIN32_FILE_ATTRIBUTE_DATA :: struct #ordered {
|
|||||||
file_size_low: u32;
|
file_size_low: u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
GET_FILEEX_INFO_LEVELS :: type i32;
|
type GET_FILEEX_INFO_LEVELS i32;
|
||||||
GetFileExInfoStandard :: 0 as GET_FILEEX_INFO_LEVELS;
|
GetFileExInfoStandard :: 0 as GET_FILEEX_INFO_LEVELS;
|
||||||
GetFileExMaxInfoLevel :: 1 as GET_FILEEX_INFO_LEVELS;
|
GetFileExMaxInfoLevel :: 1 as GET_FILEEX_INFO_LEVELS;
|
||||||
|
|
||||||
GetLastError :: proc() -> i32 #foreign #dll_import
|
proc GetLastError () -> i32 #foreign #dll_import
|
||||||
ExitProcess :: proc(exit_code: u32) #foreign #dll_import
|
proc ExitProcess (exit_code: u32) #foreign #dll_import
|
||||||
GetDesktopWindow :: proc() -> HWND #foreign #dll_import
|
proc GetDesktopWindow() -> HWND #foreign #dll_import
|
||||||
GetCursorPos :: proc(p: ^POINT) -> i32 #foreign #dll_import
|
proc GetCursorPos (p: ^POINT) -> i32 #foreign #dll_import
|
||||||
ScreenToClient :: proc(h: HWND, p: ^POINT) -> i32 #foreign #dll_import
|
proc ScreenToClient (h: HWND, p: ^POINT) -> i32 #foreign #dll_import
|
||||||
GetModuleHandleA :: proc(module_name: ^u8) -> HINSTANCE #foreign #dll_import
|
proc GetModuleHandleA(module_name: ^u8) -> HINSTANCE #foreign #dll_import
|
||||||
GetStockObject :: proc(fn_object: i32) -> HGDIOBJ #foreign #dll_import
|
proc GetStockObject (fn_object: i32) -> HGDIOBJ #foreign #dll_import
|
||||||
PostQuitMessage :: proc(exit_code: i32) #foreign #dll_import
|
proc PostQuitMessage (exit_code: i32) #foreign #dll_import
|
||||||
SetWindowTextA :: proc(hwnd: HWND, c_string: ^u8) -> BOOL #foreign #dll_import
|
proc SetWindowTextA (hwnd: HWND, c_string: ^u8) -> BOOL #foreign #dll_import
|
||||||
|
|
||||||
QueryPerformanceFrequency :: proc(result: ^i64) -> i32 #foreign #dll_import
|
proc QueryPerformanceFrequency(result: ^i64) -> i32 #foreign #dll_import
|
||||||
QueryPerformanceCounter :: proc(result: ^i64) -> i32 #foreign #dll_import
|
proc QueryPerformanceCounter (result: ^i64) -> i32 #foreign #dll_import
|
||||||
|
|
||||||
Sleep :: proc(ms: i32) -> i32 #foreign #dll_import
|
proc Sleep(ms: i32) -> i32 #foreign #dll_import
|
||||||
|
|
||||||
OutputDebugStringA :: proc(c_str: ^u8) #foreign #dll_import
|
proc OutputDebugStringA(c_str: ^u8) #foreign #dll_import
|
||||||
|
|
||||||
|
|
||||||
RegisterClassExA :: proc(wc: ^WNDCLASSEXA) -> ATOM #foreign #dll_import
|
proc RegisterClassExA(wc: ^WNDCLASSEXA) -> ATOM #foreign #dll_import
|
||||||
CreateWindowExA :: proc(ex_style: u32,
|
proc CreateWindowExA (ex_style: u32,
|
||||||
class_name, title: ^u8,
|
class_name, title: ^u8,
|
||||||
style: u32,
|
style: u32,
|
||||||
x, y, w, h: i32,
|
x, y, w, h: i32,
|
||||||
parent: HWND, menu: HMENU, instance: HINSTANCE,
|
parent: HWND, menu: HMENU, instance: HINSTANCE,
|
||||||
param: rawptr) -> HWND #foreign #dll_import
|
param: rawptr) -> HWND #foreign #dll_import
|
||||||
|
|
||||||
ShowWindow :: proc(hwnd: HWND, cmd_show: i32) -> BOOL #foreign #dll_import
|
proc ShowWindow (hwnd: HWND, cmd_show: i32) -> BOOL #foreign #dll_import
|
||||||
TranslateMessage :: proc(msg: ^MSG) -> BOOL #foreign #dll_import
|
proc TranslateMessage(msg: ^MSG) -> BOOL #foreign #dll_import
|
||||||
DispatchMessageA :: proc(msg: ^MSG) -> LRESULT #foreign #dll_import
|
proc DispatchMessageA(msg: ^MSG) -> LRESULT #foreign #dll_import
|
||||||
UpdateWindow :: proc(hwnd: HWND) -> BOOL #foreign #dll_import
|
proc UpdateWindow (hwnd: HWND) -> BOOL #foreign #dll_import
|
||||||
PeekMessageA :: proc(msg: ^MSG, hwnd: HWND,
|
proc PeekMessageA (msg: ^MSG, hwnd: HWND,
|
||||||
msg_filter_min, msg_filter_max, remove_msg: u32) -> BOOL #foreign #dll_import
|
msg_filter_min, msg_filter_max, remove_msg: u32) -> BOOL #foreign #dll_import
|
||||||
|
|
||||||
DefWindowProcA :: proc(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT #foreign #dll_import
|
proc DefWindowProcA (hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT #foreign #dll_import
|
||||||
|
|
||||||
AdjustWindowRect :: proc(rect: ^RECT, style: u32, menu: BOOL) -> BOOL #foreign #dll_import
|
proc AdjustWindowRect(rect: ^RECT, style: u32, menu: BOOL) -> BOOL #foreign #dll_import
|
||||||
GetActiveWindow :: proc() -> HWND #foreign #dll_import
|
proc GetActiveWindow () -> HWND #foreign #dll_import
|
||||||
|
|
||||||
|
|
||||||
GetQueryPerformanceFrequency :: proc() -> i64 {
|
proc GetQueryPerformanceFrequency() -> i64 {
|
||||||
r: i64;
|
r: i64;
|
||||||
QueryPerformanceFrequency(^r);
|
QueryPerformanceFrequency(^r);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetCommandLineA :: proc() -> ^u8 #foreign #dll_import
|
proc GetCommandLineA() -> ^u8 #foreign #dll_import
|
||||||
GetSystemMetrics :: proc(index: i32) -> i32 #foreign #dll_import
|
proc GetSystemMetrics(index: i32) -> i32 #foreign #dll_import
|
||||||
GetCurrentThreadId :: proc() -> u32 #foreign #dll_import
|
proc GetCurrentThreadId() -> u32 #foreign #dll_import
|
||||||
|
|
||||||
// File Stuff
|
// File Stuff
|
||||||
|
|
||||||
CloseHandle :: proc(h: HANDLE) -> i32 #foreign #dll_import
|
proc CloseHandle (h: HANDLE) -> i32 #foreign #dll_import
|
||||||
GetStdHandle :: proc(h: i32) -> HANDLE #foreign #dll_import
|
proc GetStdHandle(h: i32) -> HANDLE #foreign #dll_import
|
||||||
CreateFileA :: proc(filename: ^u8, desired_access, share_mode: u32,
|
proc CreateFileA (filename: ^u8, desired_access, share_mode: u32,
|
||||||
security: rawptr,
|
security: rawptr,
|
||||||
creation, flags_and_attribs: u32, template_file: HANDLE) -> HANDLE #foreign #dll_import
|
creation, flags_and_attribs: u32, template_file: HANDLE) -> HANDLE #foreign #dll_import
|
||||||
ReadFile :: proc(h: HANDLE, buf: rawptr, to_read: u32, bytes_read: ^i32, overlapped: rawptr) -> BOOL #foreign #dll_import
|
proc ReadFile (h: HANDLE, buf: rawptr, to_read: u32, bytes_read: ^i32, overlapped: rawptr) -> BOOL #foreign #dll_import
|
||||||
WriteFile :: proc(h: HANDLE, buf: rawptr, len: i32, written_result: ^i32, overlapped: rawptr) -> i32 #foreign #dll_import
|
proc WriteFile (h: HANDLE, buf: rawptr, len: i32, written_result: ^i32, overlapped: rawptr) -> i32 #foreign #dll_import
|
||||||
|
|
||||||
GetFileSizeEx :: proc(file_handle: HANDLE, file_size: ^i64) -> BOOL #foreign #dll_import
|
proc GetFileSizeEx (file_handle: HANDLE, file_size: ^i64) -> BOOL #foreign #dll_import
|
||||||
GetFileAttributesExA :: proc(filename: ^u8, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> BOOL #foreign #dll_import
|
proc GetFileAttributesExA (filename: ^u8, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> BOOL #foreign #dll_import
|
||||||
GetFileInformationByHandle :: proc(file_handle: HANDLE, file_info: ^BY_HANDLE_FILE_INFORMATION) -> BOOL #foreign #dll_import
|
proc GetFileInformationByHandle(file_handle: HANDLE, file_info: ^BY_HANDLE_FILE_INFORMATION) -> BOOL #foreign #dll_import
|
||||||
|
|
||||||
FILE_SHARE_READ :: 0x00000001;
|
FILE_SHARE_READ :: 0x00000001;
|
||||||
FILE_SHARE_WRITE :: 0x00000002;
|
FILE_SHARE_WRITE :: 0x00000002;
|
||||||
@@ -198,17 +198,17 @@ TRUNCATE_EXISTING :: 5;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
HeapAlloc :: proc(h: HANDLE, flags: u32, bytes: int) -> rawptr #foreign #dll_import
|
proc HeapAlloc (h: HANDLE, flags: u32, bytes: int) -> rawptr #foreign #dll_import
|
||||||
HeapReAlloc :: proc(h: HANDLE, flags: u32, memory: rawptr, bytes: int) -> rawptr #foreign #dll_import
|
proc HeapReAlloc (h: HANDLE, flags: u32, memory: rawptr, bytes: int) -> rawptr #foreign #dll_import
|
||||||
HeapFree :: proc(h: HANDLE, flags: u32, memory: rawptr) -> BOOL #foreign #dll_import
|
proc HeapFree (h: HANDLE, flags: u32, memory: rawptr) -> BOOL #foreign #dll_import
|
||||||
GetProcessHeap :: proc() -> HANDLE #foreign #dll_import
|
proc GetProcessHeap() -> HANDLE #foreign #dll_import
|
||||||
|
|
||||||
|
|
||||||
HEAP_ZERO_MEMORY :: 0x00000008;
|
HEAP_ZERO_MEMORY :: 0x00000008;
|
||||||
|
|
||||||
// Synchronization
|
// Synchronization
|
||||||
|
|
||||||
SECURITY_ATTRIBUTES :: struct #ordered {
|
type SECURITY_ATTRIBUTES struct #ordered {
|
||||||
length: u32;
|
length: u32;
|
||||||
security_descriptor: rawptr;
|
security_descriptor: rawptr;
|
||||||
inherit_handle: BOOL;
|
inherit_handle: BOOL;
|
||||||
@@ -216,32 +216,32 @@ SECURITY_ATTRIBUTES :: struct #ordered {
|
|||||||
|
|
||||||
INFINITE :: 0xffffffff;
|
INFINITE :: 0xffffffff;
|
||||||
|
|
||||||
CreateSemaphoreA :: proc(attributes: ^SECURITY_ATTRIBUTES, initial_count, maximum_count: i32, name: ^byte) -> HANDLE #foreign #dll_import
|
proc CreateSemaphoreA (attributes: ^SECURITY_ATTRIBUTES, initial_count, maximum_count: i32, name: ^byte) -> HANDLE #foreign #dll_import
|
||||||
ReleaseSemaphore :: proc(semaphore: HANDLE, release_count: i32, previous_count: ^i32) -> BOOL #foreign #dll_import
|
proc ReleaseSemaphore (semaphore: HANDLE, release_count: i32, previous_count: ^i32) -> BOOL #foreign #dll_import
|
||||||
WaitForSingleObject :: proc(handle: HANDLE, milliseconds: u32) -> u32 #foreign #dll_import
|
proc WaitForSingleObject(handle: HANDLE, milliseconds: u32) -> u32 #foreign #dll_import
|
||||||
|
|
||||||
|
|
||||||
InterlockedCompareExchange :: proc(dst: ^i32, exchange, comparand: i32) -> i32 #foreign
|
proc InterlockedCompareExchange(dst: ^i32, exchange, comparand: i32) -> i32 #foreign
|
||||||
InterlockedExchange :: proc(dst: ^i32, desired: i32) -> i32 #foreign
|
proc InterlockedExchange (dst: ^i32, desired: i32) -> i32 #foreign
|
||||||
InterlockedExchangeAdd :: proc(dst: ^i32, desired: i32) -> i32 #foreign
|
proc InterlockedExchangeAdd (dst: ^i32, desired: i32) -> i32 #foreign
|
||||||
InterlockedAnd :: proc(dst: ^i32, desired: i32) -> i32 #foreign
|
proc InterlockedAnd (dst: ^i32, desired: i32) -> i32 #foreign
|
||||||
InterlockedOr :: proc(dst: ^i32, desired: i32) -> i32 #foreign
|
proc InterlockedOr (dst: ^i32, desired: i32) -> i32 #foreign
|
||||||
|
|
||||||
InterlockedCompareExchange64 :: proc(dst: ^i64, exchange, comparand: i64) -> i64 #foreign
|
proc InterlockedCompareExchange64(dst: ^i64, exchange, comparand: i64) -> i64 #foreign
|
||||||
InterlockedExchange64 :: proc(dst: ^i64, desired: i64) -> i64 #foreign
|
proc InterlockedExchange64 (dst: ^i64, desired: i64) -> i64 #foreign
|
||||||
InterlockedExchangeAdd64 :: proc(dst: ^i64, desired: i64) -> i64 #foreign
|
proc InterlockedExchangeAdd64 (dst: ^i64, desired: i64) -> i64 #foreign
|
||||||
InterlockedAnd64 :: proc(dst: ^i64, desired: i64) -> i64 #foreign
|
proc InterlockedAnd64 (dst: ^i64, desired: i64) -> i64 #foreign
|
||||||
InterlockedOr64 :: proc(dst: ^i64, desired: i64) -> i64 #foreign
|
proc InterlockedOr64 (dst: ^i64, desired: i64) -> i64 #foreign
|
||||||
|
|
||||||
_mm_pause :: proc() #foreign
|
proc _mm_pause () #foreign
|
||||||
ReadWriteBarrier :: proc() #foreign
|
proc ReadWriteBarrier() #foreign
|
||||||
WriteBarrier :: proc() #foreign
|
proc WriteBarrier () #foreign
|
||||||
ReadBarrier :: proc() #foreign
|
proc ReadBarrier () #foreign
|
||||||
|
|
||||||
|
|
||||||
// GDI
|
// GDI
|
||||||
|
|
||||||
BITMAPINFOHEADER :: struct #ordered {
|
type BITMAPINFOHEADER struct #ordered {
|
||||||
size: u32;
|
size: u32;
|
||||||
width, height: i32;
|
width, height: i32;
|
||||||
planes, bit_count: i16;
|
planes, bit_count: i16;
|
||||||
@@ -252,13 +252,13 @@ BITMAPINFOHEADER :: struct #ordered {
|
|||||||
clr_used: u32;
|
clr_used: u32;
|
||||||
clr_important: u32;
|
clr_important: u32;
|
||||||
}
|
}
|
||||||
BITMAPINFO :: struct #ordered {
|
type BITMAPINFO struct #ordered {
|
||||||
using header: BITMAPINFOHEADER;
|
using header: BITMAPINFOHEADER;
|
||||||
colors: [1]RGBQUAD;
|
colors: [1]RGBQUAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RGBQUAD :: struct #ordered {
|
type RGBQUAD struct #ordered {
|
||||||
blue, green, red, reserved: byte;
|
blue, green, red, reserved: byte;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,7 +266,7 @@ BI_RGB :: 0;
|
|||||||
DIB_RGB_COLORS :: 0x00;
|
DIB_RGB_COLORS :: 0x00;
|
||||||
SRCCOPY :: 0x00cc0020 as u32;
|
SRCCOPY :: 0x00cc0020 as u32;
|
||||||
|
|
||||||
StretchDIBits :: proc(hdc: HDC,
|
proc StretchDIBits(hdc: HDC,
|
||||||
x_dst, y_dst, width_dst, height_dst: i32,
|
x_dst, y_dst, width_dst, height_dst: i32,
|
||||||
x_src, y_src, width_src, header_src: i32,
|
x_src, y_src, width_src, header_src: i32,
|
||||||
bits: rawptr, bits_info: ^BITMAPINFO,
|
bits: rawptr, bits_info: ^BITMAPINFO,
|
||||||
@@ -275,11 +275,11 @@ StretchDIBits :: proc(hdc: HDC,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
LoadLibraryA :: proc(c_str: ^u8) -> HMODULE #foreign
|
proc LoadLibraryA (c_str: ^u8) -> HMODULE #foreign
|
||||||
FreeLibrary :: proc(h: HMODULE) #foreign
|
proc FreeLibrary (h: HMODULE) #foreign
|
||||||
GetProcAddress :: proc(h: HMODULE, c_str: ^u8) -> PROC #foreign
|
proc GetProcAddress(h: HMODULE, c_str: ^u8) -> PROC #foreign
|
||||||
|
|
||||||
GetClientRect :: proc(hwnd: HWND, rect: ^RECT) -> BOOL #foreign
|
proc GetClientRect(hwnd: HWND, rect: ^RECT) -> BOOL #foreign
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -307,12 +307,12 @@ PFD_DEPTH_DONTCARE :: 0x20000000;
|
|||||||
PFD_DOUBLEBUFFER_DONTCARE :: 0x40000000;
|
PFD_DOUBLEBUFFER_DONTCARE :: 0x40000000;
|
||||||
PFD_STEREO_DONTCARE :: 0x80000000;
|
PFD_STEREO_DONTCARE :: 0x80000000;
|
||||||
|
|
||||||
HGLRC :: type HANDLE;
|
type HGLRC HANDLE;
|
||||||
PROC :: type proc();
|
type PROC proc();
|
||||||
wglCreateContextAttribsARBType :: type proc(hdc: HDC, hshareContext: rawptr, attribList: ^i32) -> HGLRC;
|
type wglCreateContextAttribsARBType proc(hdc: HDC, hshareContext: rawptr, attribList: ^i32) -> HGLRC;
|
||||||
|
|
||||||
|
|
||||||
PIXELFORMATDESCRIPTOR :: struct #ordered {
|
type PIXELFORMATDESCRIPTOR struct #ordered {
|
||||||
size,
|
size,
|
||||||
version,
|
version,
|
||||||
flags: u32;
|
flags: u32;
|
||||||
@@ -343,11 +343,11 @@ PIXELFORMATDESCRIPTOR :: struct #ordered {
|
|||||||
damage_mask: u32;
|
damage_mask: u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetDC :: proc(h: HANDLE) -> HDC #foreign
|
proc GetDC (h: HANDLE) -> HDC #foreign
|
||||||
SetPixelFormat :: proc(hdc: HDC, pixel_format: i32, pfd: ^PIXELFORMATDESCRIPTOR ) -> BOOL #foreign #dll_import
|
proc SetPixelFormat (hdc: HDC, pixel_format: i32, pfd: ^PIXELFORMATDESCRIPTOR ) -> BOOL #foreign #dll_import
|
||||||
ChoosePixelFormat :: proc(hdc: HDC, pfd: ^PIXELFORMATDESCRIPTOR) -> i32 #foreign #dll_import
|
proc ChoosePixelFormat(hdc: HDC, pfd: ^PIXELFORMATDESCRIPTOR) -> i32 #foreign #dll_import
|
||||||
SwapBuffers :: proc(hdc: HDC) -> BOOL #foreign #dll_import
|
proc SwapBuffers (hdc: HDC) -> BOOL #foreign #dll_import
|
||||||
ReleaseDC :: proc(wnd: HWND, hdc: HDC) -> i32 #foreign #dll_import
|
proc ReleaseDC (wnd: HWND, hdc: HDC) -> i32 #foreign #dll_import
|
||||||
|
|
||||||
WGL_CONTEXT_MAJOR_VERSION_ARB :: 0x2091;
|
WGL_CONTEXT_MAJOR_VERSION_ARB :: 0x2091;
|
||||||
WGL_CONTEXT_MINOR_VERSION_ARB :: 0x2092;
|
WGL_CONTEXT_MINOR_VERSION_ARB :: 0x2092;
|
||||||
@@ -355,21 +355,21 @@ WGL_CONTEXT_PROFILE_MASK_ARB :: 0x9126;
|
|||||||
WGL_CONTEXT_CORE_PROFILE_BIT_ARB :: 0x0001;
|
WGL_CONTEXT_CORE_PROFILE_BIT_ARB :: 0x0001;
|
||||||
WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x0002;
|
WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x0002;
|
||||||
|
|
||||||
wglCreateContext :: proc(hdc: HDC) -> HGLRC #foreign #dll_import
|
proc wglCreateContext (hdc: HDC) -> HGLRC #foreign #dll_import
|
||||||
wglMakeCurrent :: proc(hdc: HDC, hglrc: HGLRC) -> BOOL #foreign #dll_import
|
proc wglMakeCurrent (hdc: HDC, hglrc: HGLRC) -> BOOL #foreign #dll_import
|
||||||
wglGetProcAddress :: proc(c_str: ^u8) -> PROC #foreign #dll_import
|
proc wglGetProcAddress(c_str: ^u8) -> PROC #foreign #dll_import
|
||||||
wglDeleteContext :: proc(hglrc: HGLRC) -> BOOL #foreign #dll_import
|
proc wglDeleteContext (hglrc: HGLRC) -> BOOL #foreign #dll_import
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GetKeyState :: proc(v_key: i32) -> i16 #foreign #dll_import
|
proc GetKeyState (v_key: i32) -> i16 #foreign #dll_import
|
||||||
GetAsyncKeyState :: proc(v_key: i32) -> i16 #foreign #dll_import
|
proc GetAsyncKeyState(v_key: i32) -> i16 #foreign #dll_import
|
||||||
|
|
||||||
is_key_down :: proc(key: Key_Code) -> bool {
|
proc is_key_down(key: Key_Code) -> bool {
|
||||||
return GetAsyncKeyState(key as i32) < 0;
|
return GetAsyncKeyState(key as i32) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Key_Code :: enum i32 {
|
type Key_Code enum i32 {
|
||||||
LBUTTON = 0x01,
|
LBUTTON = 0x01,
|
||||||
RBUTTON = 0x02,
|
RBUTTON = 0x02,
|
||||||
CANCEL = 0x03,
|
CANCEL = 0x03,
|
||||||
|
|||||||
+7
-7
@@ -10,7 +10,7 @@ SURROGATE_MIN :: 0xd800;
|
|||||||
SURROGATE_MAX :: 0xdfff;
|
SURROGATE_MAX :: 0xdfff;
|
||||||
|
|
||||||
|
|
||||||
Accept_Range :: struct {
|
type Accept_Range struct {
|
||||||
lo, hi: u8;
|
lo, hi: u8;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ accept_sizes := [256]byte{
|
|||||||
0x34, 0x04, 0x04, 0x04, 0x44, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xf0-0xff
|
0x34, 0x04, 0x04, 0x04, 0x44, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xf0-0xff
|
||||||
};
|
};
|
||||||
|
|
||||||
encode_rune :: proc(r_: rune) -> ([4]byte, int) {
|
proc encode_rune(r_: rune) -> ([4]byte, int) {
|
||||||
r := r_;
|
r := r_;
|
||||||
buf: [4]byte;
|
buf: [4]byte;
|
||||||
i := r as u32;
|
i := r as u32;
|
||||||
@@ -77,7 +77,7 @@ encode_rune :: proc(r_: rune) -> ([4]byte, int) {
|
|||||||
return buf, 4;
|
return buf, 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
decode_rune :: proc(s: string) -> (rune, int) {
|
proc decode_rune(s: string) -> (rune, int) {
|
||||||
n := s.count;
|
n := s.count;
|
||||||
if n < 1 {
|
if n < 1 {
|
||||||
return RUNE_ERROR, 0;
|
return RUNE_ERROR, 0;
|
||||||
@@ -122,7 +122,7 @@ decode_rune :: proc(s: string) -> (rune, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
valid_rune :: proc(r: rune) -> bool {
|
proc valid_rune(r: rune) -> bool {
|
||||||
if r < 0 {
|
if r < 0 {
|
||||||
return false;
|
return false;
|
||||||
} else if SURROGATE_MIN <= r && r <= SURROGATE_MAX {
|
} else if SURROGATE_MIN <= r && r <= SURROGATE_MAX {
|
||||||
@@ -133,7 +133,7 @@ valid_rune :: proc(r: rune) -> bool {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
valid_string :: proc(s: string) -> bool {
|
proc valid_string(s: string) -> bool {
|
||||||
n := s.count;
|
n := s.count;
|
||||||
for i := 0; i < n; {
|
for i := 0; i < n; {
|
||||||
si := s[i];
|
si := s[i];
|
||||||
@@ -166,7 +166,7 @@ valid_string :: proc(s: string) -> bool {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
rune_count :: proc(s: string) -> int {
|
proc rune_count(s: string) -> int {
|
||||||
count := 0;
|
count := 0;
|
||||||
n := s.count;
|
n := s.count;
|
||||||
for i := 0; i < n; count++ {
|
for i := 0; i < n; count++ {
|
||||||
@@ -203,7 +203,7 @@ rune_count :: proc(s: string) -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rune_size :: proc(r: rune) -> int {
|
proc rune_size(r: rune) -> int {
|
||||||
match {
|
match {
|
||||||
case r < 0: return -1;
|
case r < 0: return -1;
|
||||||
case r <= 1<<7 - 1: return 1;
|
case r <= 1<<7 - 1: return 1;
|
||||||
|
|||||||
+59
-43
@@ -1565,10 +1565,13 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
|
|||||||
default: {
|
default: {
|
||||||
AstNode *type = parse_identifier_or_type(f);
|
AstNode *type = parse_identifier_or_type(f);
|
||||||
if (type != NULL) {
|
if (type != NULL) {
|
||||||
|
// TODO(bill): Is this correct???
|
||||||
// NOTE(bill): Sanity check as identifiers should be handled already
|
// NOTE(bill): Sanity check as identifiers should be handled already
|
||||||
GB_ASSERT_MSG(type->kind != AstNode_Ident, "Type Cannot be identifier");
|
// TokenPos pos = ast_node_token(type).pos;
|
||||||
|
// GB_ASSERT_MSG(type->kind != AstNode_Ident, "Type Cannot be identifier %.*s(%td:%td)", LIT(pos.file), pos.line, pos.column);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1859,9 +1862,6 @@ void parse_check_name_list_for_reserves(AstFile *f, AstNodeArray names) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AstNode *parse_proc_decl(AstFile *f, Token proc_token, AstNode *name);
|
|
||||||
|
|
||||||
|
|
||||||
AstNode *parse_simple_stmt(AstFile *f) {
|
AstNode *parse_simple_stmt(AstFile *f) {
|
||||||
isize lhs_count = 0, rhs_count = 0;
|
isize lhs_count = 0, rhs_count = 0;
|
||||||
AstNodeArray lhs = parse_lhs_expr_list(f);
|
AstNodeArray lhs = parse_lhs_expr_list(f);
|
||||||
@@ -1932,33 +1932,33 @@ AstNode *parse_simple_stmt(AstFile *f) {
|
|||||||
|
|
||||||
Token colon_colon = expect_token(f, Token_ColonColon);
|
Token colon_colon = expect_token(f, Token_ColonColon);
|
||||||
|
|
||||||
if (f->curr_token.kind == Token_type ||
|
// if (f->curr_token.kind == Token_type ||
|
||||||
f->curr_token.kind == Token_struct ||
|
// f->curr_token.kind == Token_struct ||
|
||||||
f->curr_token.kind == Token_enum ||
|
// f->curr_token.kind == Token_enum ||
|
||||||
f->curr_token.kind == Token_union ||
|
// f->curr_token.kind == Token_union ||
|
||||||
f->curr_token.kind == Token_raw_union) {
|
// f->curr_token.kind == Token_raw_union) {
|
||||||
// if (f->curr_token.kind == Token_type) {
|
// // if (f->curr_token.kind == Token_type) {
|
||||||
Token token = f->curr_token;
|
// Token token = f->curr_token;
|
||||||
if (token.kind == Token_type) {
|
// if (token.kind == Token_type) {
|
||||||
next_token(f);
|
// next_token(f);
|
||||||
}
|
// }
|
||||||
if (names.count != 1) {
|
// if (names.count != 1) {
|
||||||
syntax_error_node(names.e[0], "You can only declare one type at a time");
|
// syntax_error_node(names.e[0], "You can only declare one type at a time");
|
||||||
return make_bad_decl(f, names.e[0]->Ident, token);
|
// return make_bad_decl(f, names.e[0]->Ident, token);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return make_type_decl(f, token, names.e[0], parse_type(f));
|
// return make_type_decl(f, token, names.e[0], parse_type(f));
|
||||||
} else if (f->curr_token.kind == Token_proc) {
|
// } else if (f->curr_token.kind == Token_proc) {
|
||||||
// NOTE(bill): Procedure declarations
|
// // NOTE(bill): Procedure declarations
|
||||||
Token proc_token = f->curr_token;
|
// Token proc_token = f->curr_token;
|
||||||
AstNode *name = names.e[0];
|
// AstNode *name = names.e[0];
|
||||||
if (names.count != 1) {
|
// if (names.count != 1) {
|
||||||
syntax_error(proc_token, "You can only declare one procedure at a time");
|
// syntax_error(proc_token, "You can only declare one procedure at a time");
|
||||||
return make_bad_decl(f, name->Ident, proc_token);
|
// return make_bad_decl(f, name->Ident, proc_token);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return parse_proc_decl(f, proc_token, name);
|
// return parse_proc_decl(f, proc_token, name);
|
||||||
}
|
// }
|
||||||
|
|
||||||
AstNodeArray values = parse_rhs_expr_list(f);
|
AstNodeArray values = parse_rhs_expr_list(f);
|
||||||
if (values.count > names.count) {
|
if (values.count > names.count) {
|
||||||
@@ -2059,13 +2059,14 @@ AstNode *parse_type(AstFile *f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Token parse_proc_signature(AstFile *f, AstNodeArray *params, AstNodeArray *results);
|
void parse_proc_signature(AstFile *f, AstNodeArray *params, AstNodeArray *results);
|
||||||
|
|
||||||
AstNode *parse_proc_type(AstFile *f) {
|
AstNode *parse_proc_type(AstFile *f) {
|
||||||
AstNodeArray params = {0};
|
AstNodeArray params = {0};
|
||||||
AstNodeArray results = {0};
|
AstNodeArray results = {0};
|
||||||
|
|
||||||
Token proc_token = parse_proc_signature(f, ¶ms, &results);
|
Token proc_token = expect_token(f, Token_proc);
|
||||||
|
parse_proc_signature(f, ¶ms, &results);
|
||||||
|
|
||||||
return make_proc_type(f, proc_token, params, results, 0);
|
return make_proc_type(f, proc_token, params, results, 0);
|
||||||
}
|
}
|
||||||
@@ -2406,15 +2407,13 @@ AstNodeArray parse_results(AstFile *f) {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
Token parse_proc_signature(AstFile *f,
|
void parse_proc_signature(AstFile *f,
|
||||||
AstNodeArray *params,
|
AstNodeArray *params,
|
||||||
AstNodeArray *results) {
|
AstNodeArray *results) {
|
||||||
Token proc_token = expect_token(f, Token_proc);
|
|
||||||
expect_token(f, Token_OpenParen);
|
expect_token(f, Token_OpenParen);
|
||||||
*params = parse_parameter_list(f, true);
|
*params = parse_parameter_list(f, true);
|
||||||
expect_token_after(f, Token_CloseParen, "parameter list");
|
expect_token_after(f, Token_CloseParen, "parameter list");
|
||||||
*results = parse_results(f);
|
*results = parse_results(f);
|
||||||
return proc_token;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AstNode *parse_body(AstFile *f) {
|
AstNode *parse_body(AstFile *f) {
|
||||||
@@ -2429,8 +2428,16 @@ AstNode *parse_body(AstFile *f) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
AstNode *parse_proc_decl(AstFile *f, Token proc_token, AstNode *name) {
|
AstNode *parse_proc_decl(AstFile *f) {
|
||||||
AstNode *proc_type = parse_proc_type(f);
|
Token proc_token = expect_token(f, Token_proc);
|
||||||
|
|
||||||
|
AstNode *name = parse_identifier(f);
|
||||||
|
|
||||||
|
AstNodeArray params = {0};
|
||||||
|
AstNodeArray results = {0};
|
||||||
|
parse_proc_signature(f, ¶ms, &results);
|
||||||
|
|
||||||
|
AstNode *proc_type = make_proc_type(f, proc_token, params, results, 0);
|
||||||
|
|
||||||
AstNode *body = NULL;
|
AstNode *body = NULL;
|
||||||
u64 tags = 0;
|
u64 tags = 0;
|
||||||
@@ -2737,9 +2744,6 @@ AstNode *parse_defer_stmt(AstFile *f) {
|
|||||||
AstNode *parse_asm_stmt(AstFile *f) {
|
AstNode *parse_asm_stmt(AstFile *f) {
|
||||||
Token token = expect_token(f, Token_asm);
|
Token token = expect_token(f, Token_asm);
|
||||||
bool is_volatile = false;
|
bool is_volatile = false;
|
||||||
if (allow_token(f, Token_volatile)) {
|
|
||||||
is_volatile = true;
|
|
||||||
}
|
|
||||||
Token open, close, code_string;
|
Token open, close, code_string;
|
||||||
open = expect_token(f, Token_OpenBrace);
|
open = expect_token(f, Token_OpenBrace);
|
||||||
code_string = expect_token(f, Token_String);
|
code_string = expect_token(f, Token_String);
|
||||||
@@ -2764,7 +2768,14 @@ AstNode *parse_asm_stmt(AstFile *f) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AstNode *parse_type_decl(AstFile *f) {
|
||||||
|
Token token = expect_token(f, Token_type);
|
||||||
|
AstNode *name = parse_identifier(f);
|
||||||
|
AstNode *type = parse_type(f);
|
||||||
|
AstNode *decl = make_type_decl(f, token, name, type);
|
||||||
|
expect_semicolon(f, decl);
|
||||||
|
return decl;
|
||||||
|
}
|
||||||
|
|
||||||
AstNode *parse_stmt(AstFile *f) {
|
AstNode *parse_stmt(AstFile *f) {
|
||||||
AstNode *s = NULL;
|
AstNode *s = NULL;
|
||||||
@@ -2777,7 +2788,6 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
case Token_Rune:
|
case Token_Rune:
|
||||||
case Token_String:
|
case Token_String:
|
||||||
case Token_OpenParen:
|
case Token_OpenParen:
|
||||||
case Token_proc:
|
|
||||||
// Unary Operators
|
// Unary Operators
|
||||||
case Token_Add:
|
case Token_Add:
|
||||||
case Token_Sub:
|
case Token_Sub:
|
||||||
@@ -2804,6 +2814,12 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
expect_semicolon(f, s);
|
expect_semicolon(f, s);
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
|
case Token_proc:
|
||||||
|
return parse_proc_decl(f);
|
||||||
|
|
||||||
|
case Token_type:
|
||||||
|
return parse_type_decl(f);
|
||||||
|
|
||||||
|
|
||||||
case Token_using: {
|
case Token_using: {
|
||||||
AstNode *node = NULL;
|
AstNode *node = NULL;
|
||||||
|
|||||||
+3
-3
@@ -84,9 +84,11 @@ TOKEN_KIND(Token__OperatorEnd, "_OperatorEnd"), \
|
|||||||
\
|
\
|
||||||
TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
|
TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
|
||||||
TOKEN_KIND(Token_type, "type"), \
|
TOKEN_KIND(Token_type, "type"), \
|
||||||
|
TOKEN_KIND(Token_proc, "proc"), \
|
||||||
|
TOKEN_KIND(Token_var, "var"), \
|
||||||
|
TOKEN_KIND(Token_const, "const"), \
|
||||||
/* TOKEN_KIND(Token_import, "import"), */\
|
/* TOKEN_KIND(Token_import, "import"), */\
|
||||||
/* TOKEN_KIND(Token_include, "include"), */\
|
/* TOKEN_KIND(Token_include, "include"), */\
|
||||||
TOKEN_KIND(Token_proc, "proc"), \
|
|
||||||
TOKEN_KIND(Token_macro, "macro"), \
|
TOKEN_KIND(Token_macro, "macro"), \
|
||||||
TOKEN_KIND(Token_match, "match"), \
|
TOKEN_KIND(Token_match, "match"), \
|
||||||
TOKEN_KIND(Token_break, "break"), \
|
TOKEN_KIND(Token_break, "break"), \
|
||||||
@@ -109,8 +111,6 @@ TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
|
|||||||
TOKEN_KIND(Token_vector, "vector"), \
|
TOKEN_KIND(Token_vector, "vector"), \
|
||||||
TOKEN_KIND(Token_using, "using"), \
|
TOKEN_KIND(Token_using, "using"), \
|
||||||
TOKEN_KIND(Token_asm, "asm"), \
|
TOKEN_KIND(Token_asm, "asm"), \
|
||||||
TOKEN_KIND(Token_volatile, "volatile"), \
|
|
||||||
/* TOKEN_KIND(Token_atomic, "atomic"), */\
|
|
||||||
TOKEN_KIND(Token_push_allocator, "push_allocator"), \
|
TOKEN_KIND(Token_push_allocator, "push_allocator"), \
|
||||||
TOKEN_KIND(Token_push_context, "push_context"), \
|
TOKEN_KIND(Token_push_context, "push_context"), \
|
||||||
TOKEN_KIND(Token__KeywordEnd, "_KeywordEnd"), \
|
TOKEN_KIND(Token__KeywordEnd, "_KeywordEnd"), \
|
||||||
|
|||||||
Reference in New Issue
Block a user