Change naming convention from Ada_Like to RustLike

Naming Conventions:
In general, PascalCase for types and snake_case for values

Import Name:        snake_case (but prefer single word)
Types:              PascalCase
Union Variants:     PascalCase
Enum Values:        PascalCase
Procedures:         snake_case
Local Variables:    snake_case
Constant Variables: SCREAMING_SNAKE_CASE
This commit is contained in:
Ginger Bill
2017-05-28 14:47:11 +01:00
parent b41f09b730
commit 80c034ec7c
13 changed files with 374 additions and 362 deletions
+90 -79
View File
@@ -5,6 +5,17 @@
#import "utf8.odin"; #import "utf8.odin";
#import "raw.odin"; #import "raw.odin";
// Naming Conventions:
// In general, PascalCase for types and snake_case for values
//
// Import Name: snake_case (but prefer single word)
// Types: PascalCase
// Union Variants: PascalCase
// Enum Values: PascalCase
// Procedures: snake_case
// Local Variables: snake_case
// Constant Variables: SCREAMING_SNAKE_CASE
// IMPORTANT NOTE(bill): `type_info` & `type_info_val` cannot be used within a // IMPORTANT NOTE(bill): `type_info` & `type_info_val` cannot be used within a
// #shared_global_scope due to the internals of the compiler. // #shared_global_scope due to the internals of the compiler.
// This could change at a later date if the all these data structures are // This could change at a later date if the all these data structures are
@@ -13,20 +24,20 @@
// 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_Enum_Value :: raw_union { TypeInfoEnumValue :: raw_union {
f: f64, f: f64,
i: i64, i: i64,
} }
// NOTE(bill): This must match the compiler's // NOTE(bill): This must match the compiler's
Calling_Convention :: enum { CallingConvention :: enum {
ODIN = 0, ODIN = 0,
C = 1, C = 1,
STD = 2, STD = 2,
FAST = 3, FAST = 3,
} }
Type_Info_Record :: struct #ordered { TypeInfoRecord :: struct #ordered {
types: []^Type_Info, types: []^TypeInfo,
names: []string, names: []string,
offsets: []int, // offsets may not be used in tuples offsets: []int, // offsets may not be used in tuples
usings: []bool, // usings may not be used in tuples usings: []bool, // usings may not be used in tuples
@@ -35,11 +46,11 @@ Type_Info_Record :: struct #ordered {
custom_align: bool, custom_align: bool,
} }
Type_Info :: union { TypeInfo :: union {
size: int, size: int,
align: int, align: int,
Named{name: string, base: ^Type_Info}, Named{name: string, base: ^TypeInfo},
Integer{signed: bool}, Integer{signed: bool},
Float{}, Float{},
Complex{}, Complex{},
@@ -48,44 +59,44 @@ Type_Info :: union {
Boolean{}, Boolean{},
Any{}, Any{},
Pointer{ Pointer{
elem: ^Type_Info, // nil -> rawptr elem: ^TypeInfo, // nil -> rawptr
}, },
Atomic{elem: ^Type_Info}, Atomic{elem: ^TypeInfo},
Procedure{ Procedure{
params: ^Type_Info, // Type_Info.Tuple params: ^TypeInfo, // TypeInfo.Tuple
results: ^Type_Info, // Type_Info.Tuple results: ^TypeInfo, // TypeInfo.Tuple
variadic: bool, variadic: bool,
convention: Calling_Convention, convention: CallingConvention,
}, },
Array{ Array{
elem: ^Type_Info, elem: ^TypeInfo,
elem_size: int, elem_size: int,
count: int, count: int,
}, },
Dynamic_Array{elem: ^Type_Info, elem_size: int}, DynamicArray{elem: ^TypeInfo, elem_size: int},
Slice {elem: ^Type_Info, elem_size: int}, Slice {elem: ^TypeInfo, elem_size: int},
Vector {elem: ^Type_Info, elem_size, count: int}, Vector {elem: ^TypeInfo, elem_size, count: int},
Tuple {using record: Type_Info_Record}, // Only really used for procedures Tuple {using record: TypeInfoRecord}, // Only really used for procedures
Struct {using record: Type_Info_Record}, Struct {using record: TypeInfoRecord},
Raw_Union {using record: Type_Info_Record}, RawUnion {using record: TypeInfoRecord},
Union{ Union{
common_fields: struct { common_fields: struct {
types: []^Type_Info, types: []^TypeInfo,
names: []string, names: []string,
offsets: []int, // offsets may not be used in tuples offsets: []int, // offsets may not be used in tuples
}, },
variant_names: []string, variant_names: []string,
variant_types: []^Type_Info, variant_types: []^TypeInfo,
}, },
Enum{ Enum{
base: ^Type_Info, base: ^TypeInfo,
names: []string, names: []string,
values: []Type_Info_Enum_Value, values: []TypeInfoEnumValue,
}, },
Map{ Map{
key: ^Type_Info, key: ^TypeInfo,
value: ^Type_Info, value: ^TypeInfo,
generated_struct: ^Type_Info, generated_struct: ^TypeInfo,
count: int, // == 0 if dynamic count: int, // == 0 if dynamic
}, },
} }
@@ -93,33 +104,33 @@ Type_Info :: union {
// NOTE(bill): only the ones that are needed (not all types) // NOTE(bill): only the ones that are needed (not all types)
// This will be set by the compiler // This will be set by the compiler
__type_table: []Type_Info; __type_table: []TypeInfo;
__argv__: ^^byte; __argv__: ^^byte;
__argc__: i32; __argc__: i32;
type_info_base :: proc(info: ^Type_Info) -> ^Type_Info { type_info_base :: proc(info: ^TypeInfo) -> ^TypeInfo {
if info == nil { if info == nil {
return nil; return nil;
} }
base := info; base := info;
match i in base { match i in base {
case Type_Info.Named: case TypeInfo.Named:
base = i.base; base = i.base;
} }
return base; return base;
} }
type_info_base_without_enum :: proc(info: ^Type_Info) -> ^Type_Info { type_info_base_without_enum :: proc(info: ^TypeInfo) -> ^TypeInfo {
if info == nil { if info == nil {
return nil; return nil;
} }
base := info; base := info;
match i in base { match i in base {
case Type_Info.Named: case TypeInfo.Named:
base = i.base; base = i.base;
case Type_Info.Enum: case TypeInfo.Enum:
base = i.base; base = i.base;
} }
return base; return base;
@@ -135,17 +146,17 @@ read_cycle_counter :: proc() -> u64 #foreign __llvm_core "llvm.readcyclecounter"
// IMPORTANT NOTE(bill): Must be in this order (as the compiler relies upon it) // IMPORTANT NOTE(bill): Must be in this order (as the compiler relies upon it)
Allocator_Mode :: enum u8 { AllocatorMode :: enum u8 {
ALLOC, Alloc,
FREE, Free,
FREE_ALL, FreeAll,
RESIZE, Resize,
} }
Allocator_Proc :: #type proc(allocator_data: rawptr, mode: Allocator_Mode, AllocatorProc :: #type proc(allocator_data: rawptr, mode: AllocatorMode,
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 { Allocator :: struct #ordered {
procedure: Allocator_Proc, procedure: AllocatorProc,
data: rawptr, data: rawptr,
} }
@@ -181,7 +192,7 @@ alloc :: proc(size: int) -> rawptr #inline { return alloc_align(size, DEFAULT_AL
alloc_align :: proc(size, alignment: int) -> rawptr #inline { alloc_align :: proc(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, AllocatorMode.Alloc, size, alignment, nil, 0, 0);
} }
free_ptr_with_allocator :: proc(a: Allocator, ptr: rawptr) #inline { free_ptr_with_allocator :: proc(a: Allocator, ptr: rawptr) #inline {
@@ -191,7 +202,7 @@ free_ptr_with_allocator :: proc(a: Allocator, ptr: rawptr) #inline {
if a.procedure == nil { if a.procedure == nil {
return; return;
} }
a.procedure(a.data, Allocator_Mode.FREE, 0, 0, ptr, 0, 0); a.procedure(a.data, AllocatorMode.Free, 0, 0, ptr, 0, 0);
} }
free_ptr :: proc(ptr: rawptr) #inline { free_ptr :: proc(ptr: rawptr) #inline {
@@ -202,7 +213,7 @@ free_ptr :: proc(ptr: rawptr) #inline {
free_all :: proc() #inline { free_all :: proc() #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, AllocatorMode.FreeAll, 0, 0, nil, 0, 0);
} }
@@ -210,7 +221,7 @@ resize :: proc(ptr: rawptr, old_size, new_size: int) -> rawptr #inline { r
resize_align :: proc(ptr: rawptr, old_size, new_size, alignment: int) -> rawptr #inline { resize_align :: proc(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, AllocatorMode.Resize, new_size, alignment, ptr, old_size, 0);
} }
@@ -240,23 +251,23 @@ default_resize_align :: proc(old_memory: rawptr, old_size, new_size, alignment:
} }
default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, default_allocator_proc :: proc(allocator_data: rawptr, mode: AllocatorMode,
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 AllocatorMode;
match mode { match mode {
case ALLOC: case Alloc:
return os.heap_alloc(size); return os.heap_alloc(size);
case FREE: case Free:
os.heap_free(old_memory); os.heap_free(old_memory);
return nil; return nil;
case FREE_ALL: case FreeAll:
// NOTE(bill): Does nothing // NOTE(bill): Does nothing
case RESIZE: case Resize:
ptr := os.heap_resize(old_memory, size); ptr := os.heap_resize(old_memory, size);
assert(ptr != nil); assert(ptr != nil);
return ptr; return ptr;
@@ -360,7 +371,7 @@ __substring_expr_error :: proc(file: string, line, column: int, low, high: int)
file, line, column, low, high); file, line, column, low, high);
__debug_trap(); __debug_trap();
} }
__type_assertion_check :: proc(ok: bool, file: string, line, column: int, from, to: ^Type_Info) { __type_assertion_check :: proc(ok: bool, file: string, line, column: int, from, to: ^TypeInfo) {
if !ok { if !ok {
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid type_assertion from %T to %T\n", fmt.fprintf(os.stderr, "%s(%d:%d) Invalid type_assertion from %T to %T\n",
file, line, column, from, to); file, line, column, from, to);
@@ -429,7 +440,7 @@ __abs_quaternion256 :: proc(x: quaternion256) -> f64 #inline {
__dynamic_array_make :: proc(array_: rawptr, elem_size, elem_align: int, len, cap: int) { __dynamic_array_make :: proc(array_: rawptr, elem_size, elem_align: int, len, cap: int) {
array := ^raw.Dynamic_Array(array_); array := ^raw.DynamicArray(array_);
__check_context(); __check_context();
array.allocator = context.allocator; array.allocator = context.allocator;
assert(array.allocator.procedure != nil); assert(array.allocator.procedure != nil);
@@ -441,7 +452,7 @@ __dynamic_array_make :: proc(array_: rawptr, elem_size, elem_align: int, len, ca
} }
__dynamic_array_reserve :: proc(array_: rawptr, elem_size, elem_align: int, cap: int) -> bool { __dynamic_array_reserve :: proc(array_: rawptr, elem_size, elem_align: int, cap: int) -> bool {
array := ^raw.Dynamic_Array(array_); array := ^raw.DynamicArray(array_);
if cap <= array.cap { if cap <= array.cap {
return true; return true;
@@ -457,7 +468,7 @@ __dynamic_array_reserve :: proc(array_: rawptr, elem_size, elem_align: int, cap:
new_size := cap * elem_size; new_size := cap * elem_size;
allocator := array.allocator; allocator := array.allocator;
new_data := allocator.procedure(allocator.data, Allocator_Mode.RESIZE, new_size, elem_align, array.data, old_size, 0); new_data := allocator.procedure(allocator.data, AllocatorMode.Resize, new_size, elem_align, array.data, old_size, 0);
if new_data == nil { if new_data == nil {
return false; return false;
} }
@@ -468,7 +479,7 @@ __dynamic_array_reserve :: proc(array_: rawptr, elem_size, elem_align: int, cap:
} }
__dynamic_array_resize :: proc(array_: rawptr, elem_size, elem_align: int, len: int) -> bool { __dynamic_array_resize :: proc(array_: rawptr, elem_size, elem_align: int, len: int) -> bool {
array := ^raw.Dynamic_Array(array_); array := ^raw.DynamicArray(array_);
ok := __dynamic_array_reserve(array_, elem_size, elem_align, len); ok := __dynamic_array_reserve(array_, elem_size, elem_align, len);
if ok { if ok {
@@ -480,7 +491,7 @@ __dynamic_array_resize :: proc(array_: rawptr, elem_size, elem_align: int, len:
__dynamic_array_append :: proc(array_: rawptr, elem_size, elem_align: int, __dynamic_array_append :: proc(array_: rawptr, elem_size, elem_align: int,
items: rawptr, item_count: int) -> int { items: rawptr, item_count: int) -> int {
array := ^raw.Dynamic_Array(array_); array := ^raw.DynamicArray(array_);
if item_count <= 0 || items == nil { if item_count <= 0 || items == nil {
return array.len; return array.len;
@@ -504,7 +515,7 @@ __dynamic_array_append :: proc(array_: rawptr, elem_size, elem_align: int,
} }
__dynamic_array_append_nothing :: proc(array_: rawptr, elem_size, elem_align: int) -> int { __dynamic_array_append_nothing :: proc(array_: rawptr, elem_size, elem_align: int) -> int {
array := ^raw.Dynamic_Array(array_); array := ^raw.DynamicArray(array_);
ok := true; ok := true;
if array.cap <= array.len+1 { if array.cap <= array.len+1 {
@@ -559,27 +570,27 @@ __default_hash_string :: proc(s: string) -> u64 {
__INITIAL_MAP_CAP :: 16; __INITIAL_MAP_CAP :: 16;
__Map_Key :: struct #ordered { __MapKey :: struct #ordered {
hash: u64, hash: u64,
str: string, str: string,
} }
__Map_Find_Result :: struct #ordered { __MapFindResult :: struct #ordered {
hash_index: int, hash_index: int,
entry_prev: int, entry_prev: int,
entry_index: int, entry_index: int,
} }
__Map_Entry_Header :: struct #ordered { __MapEntryHeader :: struct #ordered {
key: __Map_Key, key: __MapKey,
next: int, next: int,
/* /*
value: Value_Type, value: Value_Type,
*/ */
} }
__Map_Header :: struct #ordered { __MapHeader :: struct #ordered {
m: ^raw.Dynamic_Map, m: ^raw.DynamicMap,
is_key_string: bool, is_key_string: bool,
entry_size: int, entry_size: int,
entry_align: int, entry_align: int,
@@ -587,18 +598,18 @@ __Map_Header :: struct #ordered {
value_size: int, value_size: int,
} }
__dynamic_map_reserve :: proc(using header: __Map_Header, cap: int) { __dynamic_map_reserve :: proc(using header: __MapHeader, cap: int) {
__dynamic_array_reserve(&m.hashes, size_of(int), align_of(int), cap); __dynamic_array_reserve(&m.hashes, size_of(int), align_of(int), cap);
__dynamic_array_reserve(&m.entries, entry_size, entry_align, cap); __dynamic_array_reserve(&m.entries, entry_size, entry_align, cap);
} }
__dynamic_map_rehash :: proc(using header: __Map_Header, new_count: int) { __dynamic_map_rehash :: proc(using header: __MapHeader, new_count: int) {
new_header: __Map_Header = header; new_header: __MapHeader = header;
nm: raw.Dynamic_Map; nm: raw.DynamicMap;
new_header.m = &nm; new_header.m = &nm;
header_hashes := ^raw.Dynamic_Array(&header.m.hashes); header_hashes := ^raw.DynamicArray(&header.m.hashes);
nm_hashes := ^raw.Dynamic_Array(&nm.hashes); nm_hashes := ^raw.DynamicArray(&nm.hashes);
__dynamic_array_resize(nm_hashes, size_of(int), align_of(int), new_count); __dynamic_array_resize(nm_hashes, size_of(int), align_of(int), new_count);
__dynamic_array_reserve(&nm.entries, entry_size, entry_align, m.entries.len); __dynamic_array_reserve(&nm.entries, entry_size, entry_align, m.entries.len);
@@ -637,7 +648,7 @@ __dynamic_map_rehash :: proc(using header: __Map_Header, new_count: int) {
header.m^ = nm; header.m^ = nm;
} }
__dynamic_map_get :: proc(h: __Map_Header, key: __Map_Key) -> rawptr { __dynamic_map_get :: proc(h: __MapHeader, key: __MapKey) -> rawptr {
index := __dynamic_map_find(h, key).entry_index; index := __dynamic_map_find(h, key).entry_index;
if index >= 0 { if index >= 0 {
data := ^byte(__dynamic_map_get_entry(h, index)); data := ^byte(__dynamic_map_get_entry(h, index));
@@ -647,7 +658,7 @@ __dynamic_map_get :: proc(h: __Map_Header, key: __Map_Key) -> rawptr {
return nil; return nil;
} }
__dynamic_map_set :: proc(using h: __Map_Header, key: __Map_Key, value: rawptr) { __dynamic_map_set :: proc(using h: __MapHeader, key: __MapKey, value: rawptr) {
index: int; index: int;
assert(value != nil); assert(value != nil);
@@ -682,17 +693,17 @@ __dynamic_map_set :: proc(using h: __Map_Header, key: __Map_Key, value: rawptr)
} }
__dynamic_map_grow :: proc(using h: __Map_Header) { __dynamic_map_grow :: proc(using h: __MapHeader) {
new_count := max(2*m.entries.cap + 8, __INITIAL_MAP_CAP); new_count := max(2*m.entries.cap + 8, __INITIAL_MAP_CAP);
__dynamic_map_rehash(h, new_count); __dynamic_map_rehash(h, new_count);
} }
__dynamic_map_full :: proc(using h: __Map_Header) -> bool { __dynamic_map_full :: proc(using h: __MapHeader) -> bool {
return int(0.75 * f64(len(m.hashes))) <= m.entries.cap; return int(0.75 * f64(len(m.hashes))) <= m.entries.cap;
} }
__dynamic_map_hash_equal :: proc(h: __Map_Header, a, b: __Map_Key) -> bool { __dynamic_map_hash_equal :: proc(h: __MapHeader, a, b: __MapKey) -> bool {
if a.hash == b.hash { if a.hash == b.hash {
if h.is_key_string { if h.is_key_string {
return a.str == b.str; return a.str == b.str;
@@ -702,8 +713,8 @@ __dynamic_map_hash_equal :: proc(h: __Map_Header, a, b: __Map_Key) -> bool {
return false; return false;
} }
__dynamic_map_find :: proc(using h: __Map_Header, key: __Map_Key) -> __Map_Find_Result { __dynamic_map_find :: proc(using h: __MapHeader, key: __MapKey) -> __MapFindResult {
fr := __Map_Find_Result{-1, -1, -1}; fr := __MapFindResult{-1, -1, -1};
if len(m.hashes) > 0 { if len(m.hashes) > 0 {
fr.hash_index = int(key.hash % u64(len(m.hashes))); fr.hash_index = int(key.hash % u64(len(m.hashes)));
fr.entry_index = m.hashes[fr.hash_index]; fr.entry_index = m.hashes[fr.hash_index];
@@ -719,7 +730,7 @@ __dynamic_map_find :: proc(using h: __Map_Header, key: __Map_Key) -> __Map_Find_
return fr; return fr;
} }
__dynamic_map_add_entry :: proc(using h: __Map_Header, key: __Map_Key) -> int { __dynamic_map_add_entry :: proc(using h: __MapHeader, key: __MapKey) -> int {
prev := m.entries.len; prev := m.entries.len;
c := __dynamic_array_append_nothing(&m.entries, entry_size, entry_align); c := __dynamic_array_append_nothing(&m.entries, entry_size, entry_align);
if c != prev { if c != prev {
@@ -731,19 +742,19 @@ __dynamic_map_add_entry :: proc(using h: __Map_Header, key: __Map_Key) -> int {
} }
__dynamic_map_delete :: proc(using h: __Map_Header, key: __Map_Key) { __dynamic_map_delete :: proc(using h: __MapHeader, key: __MapKey) {
fr := __dynamic_map_find(h, key); fr := __dynamic_map_find(h, key);
if fr.entry_index >= 0 { if fr.entry_index >= 0 {
__dynamic_map_erase(h, fr); __dynamic_map_erase(h, fr);
} }
} }
__dynamic_map_get_entry :: proc(using h: __Map_Header, index: int) -> ^__Map_Entry_Header { __dynamic_map_get_entry :: proc(using h: __MapHeader, index: int) -> ^__MapEntryHeader {
data := ^byte(m.entries.data) + index*entry_size; data := ^byte(m.entries.data) + index*entry_size;
return ^__Map_Entry_Header(data); return ^__MapEntryHeader(data);
} }
__dynamic_map_erase :: proc(using h: __Map_Header, fr: __Map_Find_Result) { __dynamic_map_erase :: proc(using h: __MapHeader, fr: __MapFindResult) {
if fr.entry_prev < 0 { if fr.entry_prev < 0 {
m.hashes[fr.hash_index] = __dynamic_map_get_entry(h, fr.entry_index).next; m.hashes[fr.hash_index] = __dynamic_map_get_entry(h, fr.entry_index).next;
} else { } else {
+59 -58
View File
@@ -8,57 +8,58 @@
_BUFFER_SIZE :: 1<<12; _BUFFER_SIZE :: 1<<12;
String_Buffer :: struct { // TODO(bill): Make this a union
StringBuffer :: struct {
is_dynamic: bool, is_dynamic: bool,
sa: []byte, sa: []byte,
da: [dynamic]byte, da: [dynamic]byte,
}; };
make_string_buffer_from_slice :: proc(b: []byte) -> String_Buffer { make_string_buffer_from_slice :: proc(b: []byte) -> StringBuffer {
return String_Buffer{ return StringBuffer{
is_dynamic = false, is_dynamic = false,
sa = b, sa = b,
}; };
} }
make_string_dynamic_buffer :: proc() -> String_Buffer { make_string_dynamic_buffer :: proc() -> StringBuffer {
return String_Buffer{ return StringBuffer{
is_dynamic = true, is_dynamic = true,
da = make([dynamic]byte), da = make([dynamic]byte),
}; };
} }
string_buffer_data :: proc(buf: ^String_Buffer) -> []byte { string_buffer_data :: proc(buf: ^StringBuffer) -> []byte {
return string_buffer_data(buf^); return string_buffer_data(buf^);
} }
string_buffer_data :: proc(buf: String_Buffer) -> []byte { string_buffer_data :: proc(buf: StringBuffer) -> []byte {
if buf.is_dynamic { if buf.is_dynamic {
return buf.da[..]; return buf.da[..];
} }
return buf.sa[..]; return buf.sa[..];
} }
to_string :: proc(buf: String_Buffer) -> string { to_string :: proc(buf: StringBuffer) -> string {
return string(string_buffer_data(buf)); return string(string_buffer_data(buf));
} }
write_string :: proc(buf: ^String_Buffer, s: string) { write_string :: proc(buf: ^StringBuffer, s: string) {
write_bytes(buf, []byte(s)); write_bytes(buf, []byte(s));
} }
write_bytes :: proc(buf: ^String_Buffer, b: []byte) { write_bytes :: proc(buf: ^StringBuffer, b: []byte) {
if buf.is_dynamic { if buf.is_dynamic {
append(buf.da, ..b); append(buf.da, ..b);
} else { } else {
append(buf.sa, ..b); append(buf.sa, ..b);
} }
} }
write_byte :: proc(buf: ^String_Buffer, b: byte) { write_byte :: proc(buf: ^StringBuffer, b: byte) {
if buf.is_dynamic { if buf.is_dynamic {
append(buf.da, b); append(buf.da, b);
} else { } else {
append(buf.sa, b); append(buf.sa, b);
} }
} }
write_rune :: proc(buf: ^String_Buffer, r: rune) { write_rune :: proc(buf: ^StringBuffer, r: rune) {
if r < utf8.RUNE_SELF { if r < utf8.RUNE_SELF {
write_byte(buf, byte(r)); write_byte(buf, byte(r));
return; return;
@@ -68,7 +69,7 @@ write_rune :: proc(buf: ^String_Buffer, r: rune) {
write_bytes(buf, b[0..<n]); write_bytes(buf, b[0..<n]);
} }
Fmt_Info :: struct { FmtInfo :: struct {
minus: bool, minus: bool,
plus: bool, plus: bool,
space: bool, space: bool,
@@ -83,7 +84,7 @@ Fmt_Info :: struct {
reordered: bool, reordered: bool,
good_arg_index: bool, good_arg_index: bool,
buf: ^String_Buffer, buf: ^StringBuffer,
arg: any, // Temporary arg: any, // Temporary
} }
@@ -169,19 +170,19 @@ bprintf :: proc(buf: []byte, fmt: string, args: ..any) -> string {
fprint_type :: proc(fd: os.Handle, info: ^Type_Info) { fprint_type :: proc(fd: os.Handle, info: ^TypeInfo) {
data: [_BUFFER_SIZE]byte; data: [_BUFFER_SIZE]byte;
buf := make_string_buffer_from_slice(data[0..<0]); buf := make_string_buffer_from_slice(data[0..<0]);
write_type(&buf, info); write_type(&buf, info);
os.write(fd, string_buffer_data(buf)); os.write(fd, string_buffer_data(buf));
} }
write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) { write_type :: proc(buf: ^StringBuffer, ti: ^TypeInfo) {
if ti == nil { if ti == nil {
return; return;
} }
using Type_Info; using TypeInfo;
match info in ti { match info in ti {
case Named: case Named:
write_string(buf, info.name); write_string(buf, info.name);
@@ -191,7 +192,7 @@ write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
case ti == type_info(uint): write_string(buf, "uint"); case ti == type_info(uint): write_string(buf, "uint");
case: case:
write_string(buf, info.signed ? "i" : "u"); write_string(buf, info.signed ? "i" : "u");
fi := Fmt_Info{buf = buf}; fi := FmtInfo{buf = buf};
fmt_int(&fi, u64(8*info.size), false, 64, 'd'); fmt_int(&fi, u64(8*info.size), false, 64, 'd');
} }
case Float: case Float:
@@ -259,11 +260,11 @@ write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
case Array: case Array:
write_string(buf, "["); write_string(buf, "[");
fi := Fmt_Info{buf = buf}; fi := FmtInfo{buf = buf};
fmt_int(&fi, u64(info.count), false, 64, 'd'); fmt_int(&fi, u64(info.count), false, 64, 'd');
write_string(buf, "]"); write_string(buf, "]");
write_type(buf, info.elem); write_type(buf, info.elem);
case Dynamic_Array: case DynamicArray:
write_string(buf, "[dynamic]"); write_string(buf, "[dynamic]");
write_type(buf, info.elem); write_type(buf, info.elem);
case Slice: case Slice:
@@ -271,7 +272,7 @@ write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
write_type(buf, info.elem); write_type(buf, info.elem);
case Vector: case Vector:
write_string(buf, "[vector "); write_string(buf, "[vector ");
fi := Fmt_Info{buf = buf}; fi := FmtInfo{buf = buf};
fmt_int(&fi, u64(info.count), false, 64, 'd'); fmt_int(&fi, u64(info.count), false, 64, 'd');
write_string(buf, "]"); write_string(buf, "]");
write_type(buf, info.elem); write_type(buf, info.elem);
@@ -288,7 +289,7 @@ write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
if info.ordered { write_string(buf, "#ordered "); } if info.ordered { write_string(buf, "#ordered "); }
if info.custom_align { if info.custom_align {
write_string(buf, "#align "); write_string(buf, "#align ");
fi := Fmt_Info{buf = buf}; fi := FmtInfo{buf = buf};
fmt_int(&fi, u64(info.align), false, 64, 'd'); fmt_int(&fi, u64(info.align), false, 64, 'd');
write_byte(buf, ' '); write_byte(buf, ' ');
} }
@@ -340,7 +341,7 @@ write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
} }
write_string(buf, "}"); write_string(buf, "}");
case Raw_Union: case RawUnion:
write_string(buf, "raw_union {"); write_string(buf, "raw_union {");
for name, i in info.names { for name, i in info.names {
if i > 0 { if i > 0 {
@@ -391,7 +392,7 @@ _parse_int :: proc(s: string, offset: int) -> (result: int, offset: int, ok: boo
return result, offset+i, i != 0; return result, offset+i, i != 0;
} }
_arg_number :: proc(fi: ^Fmt_Info, arg_index: int, format: string, offset, arg_count: int) -> (index, offset: int, ok: bool) { _arg_number :: proc(fi: ^FmtInfo, arg_index: int, format: string, offset, arg_count: int) -> (index, offset: int, ok: bool) {
parse_arg_number :: proc(format: string) -> (int, int, bool) { parse_arg_number :: proc(format: string) -> (int, int, bool) {
if len(format) < 3 { if len(format) < 3 {
return 0, 1, false; return 0, 1, false;
@@ -449,7 +450,7 @@ int_from_arg :: proc(args: []any, arg_index: int) -> (int, int, bool) {
} }
fmt_bad_verb :: proc(using fi: ^Fmt_Info, verb: rune) { fmt_bad_verb :: proc(using fi: ^FmtInfo, verb: rune) {
assert(verb != 'v'); assert(verb != 'v');
write_string(buf, "%!"); write_string(buf, "%!");
write_rune(buf, verb); write_rune(buf, verb);
@@ -464,7 +465,7 @@ fmt_bad_verb :: proc(using fi: ^Fmt_Info, verb: rune) {
write_byte(buf, ')'); write_byte(buf, ')');
} }
fmt_bool :: proc(using fi: ^Fmt_Info, b: bool, verb: rune) { fmt_bool :: proc(using fi: ^FmtInfo, b: bool, verb: rune) {
match verb { match verb {
case 't', 'v': case 't', 'v':
write_string(buf, b ? "true" : "false"); write_string(buf, b ? "true" : "false");
@@ -474,7 +475,7 @@ fmt_bool :: proc(using fi: ^Fmt_Info, b: bool, verb: rune) {
} }
fmt_write_padding :: proc(fi: ^Fmt_Info, width: int) { fmt_write_padding :: proc(fi: ^FmtInfo, width: int) {
if width <= 0 { if width <= 0 {
return; return;
} }
@@ -522,7 +523,7 @@ is_integer_negative :: proc(u: u64, is_signed: bool, bit_size: int) -> (unsigned
return u, neg; return u, neg;
} }
_write_int :: proc(fi: ^Fmt_Info, u: u64, base: int, is_signed: bool, bit_size: int, digits: string) { _write_int :: proc(fi: ^FmtInfo, u: u64, base: int, is_signed: bool, bit_size: int, digits: string) {
_, neg := is_integer_negative(u, is_signed, bit_size); _, neg := is_integer_negative(u, is_signed, bit_size);
BUF_SIZE :: 256; BUF_SIZE :: 256;
@@ -575,11 +576,11 @@ _write_int :: proc(fi: ^Fmt_Info, u: u64, base: int, is_signed: bool, bit_size:
immutable __DIGITS_LOWER := "0123456789abcdefx"; immutable __DIGITS_LOWER := "0123456789abcdefx";
immutable __DIGITS_UPPER := "0123456789ABCDEFX"; immutable __DIGITS_UPPER := "0123456789ABCDEFX";
fmt_rune :: proc(fi: ^Fmt_Info, r: rune) { fmt_rune :: proc(fi: ^FmtInfo, r: rune) {
write_rune(fi.buf, r); write_rune(fi.buf, r);
} }
fmt_int :: proc(fi: ^Fmt_Info, u: u64, is_signed: bool, bit_size: int, verb: rune) { fmt_int :: proc(fi: ^FmtInfo, u: u64, is_signed: bool, bit_size: int, verb: rune) {
match verb { match verb {
case 'v': _write_int(fi, u, 10, is_signed, bit_size, __DIGITS_LOWER); case 'v': _write_int(fi, u, 10, is_signed, bit_size, __DIGITS_LOWER);
case 'b': _write_int(fi, u, 2, is_signed, bit_size, __DIGITS_LOWER); case 'b': _write_int(fi, u, 2, is_signed, bit_size, __DIGITS_LOWER);
@@ -603,7 +604,7 @@ fmt_int :: proc(fi: ^Fmt_Info, u: u64, is_signed: bool, bit_size: int, verb: run
} }
} }
_pad :: proc(fi: ^Fmt_Info, s: string) { _pad :: proc(fi: ^FmtInfo, s: string) {
if !fi.width_set { if !fi.width_set {
write_string(fi.buf, s); write_string(fi.buf, s);
return; return;
@@ -618,7 +619,7 @@ _pad :: proc(fi: ^Fmt_Info, s: string) {
} }
} }
fmt_float :: proc(fi: ^Fmt_Info, v: f64, bit_size: int, verb: rune) { fmt_float :: proc(fi: ^FmtInfo, v: f64, bit_size: int, verb: rune) {
match verb { match verb {
// case 'e', 'E', 'f', 'F', 'g', 'G', 'v': // case 'e', 'E', 'f', 'F', 'g', 'G', 'v':
// case 'f', 'F', 'v': // case 'f', 'F', 'v':
@@ -664,7 +665,7 @@ fmt_float :: proc(fi: ^Fmt_Info, v: f64, bit_size: int, verb: rune) {
return; return;
} }
} }
fmt_string :: proc(fi: ^Fmt_Info, s: string, verb: rune) { fmt_string :: proc(fi: ^FmtInfo, s: string, verb: rune) {
match verb { match verb {
case 's', 'v': case 's', 'v':
write_string(fi.buf, s); write_string(fi.buf, s);
@@ -686,7 +687,7 @@ fmt_string :: proc(fi: ^Fmt_Info, s: string, verb: rune) {
} }
} }
fmt_pointer :: proc(fi: ^Fmt_Info, p: rawptr, verb: rune) { fmt_pointer :: proc(fi: ^FmtInfo, p: rawptr, verb: rune) {
match verb { match verb {
case 'p', 'v': case 'p', 'v':
// Okay // Okay
@@ -701,13 +702,13 @@ fmt_pointer :: proc(fi: ^Fmt_Info, p: rawptr, verb: rune) {
_write_int(fi, u, 16, false, 8*size_of(rawptr), __DIGITS_UPPER); _write_int(fi, u, 16, false, 8*size_of(rawptr), __DIGITS_UPPER);
} }
fmt_enum :: proc(fi: ^Fmt_Info, v: any, verb: rune) { fmt_enum :: proc(fi: ^FmtInfo, v: any, verb: rune) {
if v.type_info == nil || v.data == nil { if v.type_info == nil || v.data == nil {
write_string(fi.buf, "<nil>"); write_string(fi.buf, "<nil>");
return; return;
} }
using Type_Info; using TypeInfo;
match e in v.type_info { match e in v.type_info {
case: case:
fmt_bad_verb(fi, verb); fmt_bad_verb(fi, verb);
@@ -768,13 +769,13 @@ fmt_enum :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
} }
fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) { fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
if v.data == nil || v.type_info == nil { if v.data == nil || v.type_info == nil {
write_string(fi.buf, "<nil>"); write_string(fi.buf, "<nil>");
return; return;
} }
using Type_Info; using TypeInfo;
match info in v.type_info { match info in v.type_info {
case Named: case Named:
match b in info.base { match b in info.base {
@@ -808,8 +809,8 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
case String: fmt_arg(fi, v, verb); case String: fmt_arg(fi, v, verb);
case Pointer: case Pointer:
if v.type_info == type_info(^Type_Info) { if v.type_info == type_info(^TypeInfo) {
write_type(fi.buf, (^^Type_Info)(v.data)^); write_type(fi.buf, (^^TypeInfo)(v.data)^);
} else { } else {
fmt_pointer(fi, (^rawptr)(v.data)^, verb); fmt_pointer(fi, (^rawptr)(v.data)^, verb);
} }
@@ -828,10 +829,10 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
fmt_arg(fi, any{rawptr(data), info.elem}, verb); fmt_arg(fi, any{rawptr(data), info.elem}, verb);
} }
case Dynamic_Array: case DynamicArray:
write_byte(fi.buf, '['); write_byte(fi.buf, '[');
defer write_byte(fi.buf, ']'); defer write_byte(fi.buf, ']');
array := (^raw.Dynamic_Array)(v.data); array := (^raw.DynamicArray)(v.data);
for i in 0..<array.len { for i in 0..<array.len {
if i > 0 { if i > 0 {
write_string(fi.buf, ", "); write_string(fi.buf, ", ");
@@ -873,9 +874,9 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
write_string(fi.buf, "map["); write_string(fi.buf, "map[");
defer write_byte(fi.buf, ']'); defer write_byte(fi.buf, ']');
entries := &(^raw.Dynamic_Map(v.data).entries); entries := &(^raw.DynamicMap(v.data).entries);
gs := type_info_base(info.generated_struct).(^Struct); gs := type_info_base(info.generated_struct).(^Struct);
ed := type_info_base(gs.types[1]).(^Dynamic_Array); ed := type_info_base(gs.types[1]).(^DynamicArray);
entry_type := ed.elem.(^Struct); entry_type := ed.elem.(^Struct);
entry_size := ed.elem_size; entry_size := ed.elem_size;
@@ -885,11 +886,11 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
} }
data := ^byte(entries.data) + i*entry_size; data := ^byte(entries.data) + i*entry_size;
header := ^__Map_Entry_Header(data); header := ^__MapEntryHeader(data);
if types.is_string(info.key) { if types.is_string(info.key) {
write_string(fi.buf, header.key.str); write_string(fi.buf, header.key.str);
} else { } else {
fi := Fmt_Info{buf = fi.buf}; fi := FmtInfo{buf = fi.buf};
fmt_arg(&fi, any{rawptr(&header.key.hash), info.key}, 'v'); fmt_arg(&fi, any{rawptr(&header.key.hash), info.key}, 'v');
} }
@@ -931,7 +932,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
fmt_value(fi, any{rawptr(data), cf.types[i]}, 'v'); fmt_value(fi, any{rawptr(data), cf.types[i]}, 'v');
} }
case Raw_Union: case RawUnion:
write_string(fi.buf, "(raw_union)"); write_string(fi.buf, "(raw_union)");
case Enum: case Enum:
@@ -944,7 +945,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
} }
} }
fmt_complex :: proc(fi: ^Fmt_Info, c: complex128, bits: int, verb: rune) { fmt_complex :: proc(fi: ^FmtInfo, c: complex128, bits: int, verb: rune) {
match verb { match verb {
case 'f', 'F', 'v': case 'f', 'F', 'v':
r := real(c); r := real(c);
@@ -962,7 +963,7 @@ fmt_complex :: proc(fi: ^Fmt_Info, c: complex128, bits: int, verb: rune) {
} }
} }
fmt_quaternion :: proc(fi: ^Fmt_Info, c: quaternion256, bits: int, verb: rune) { fmt_quaternion :: proc(fi: ^FmtInfo, c: quaternion256, bits: int, verb: rune) {
match verb { match verb {
case 'f', 'F', 'v': case 'f', 'F', 'v':
r := real(c); r := real(c);
@@ -989,7 +990,7 @@ fmt_quaternion :: proc(fi: ^Fmt_Info, c: quaternion256, bits: int, verb: rune) {
} }
} }
fmt_arg :: proc(fi: ^Fmt_Info, arg: any, verb: rune) { fmt_arg :: proc(fi: ^FmtInfo, arg: any, verb: rune) {
if arg == nil { if arg == nil {
write_string(fi.buf, "<nil>"); write_string(fi.buf, "<nil>");
return; return;
@@ -999,7 +1000,7 @@ fmt_arg :: proc(fi: ^Fmt_Info, arg: any, verb: rune) {
if verb == 'T' { if verb == 'T' {
ti := arg.type_info; ti := arg.type_info;
match a in arg { match a in arg {
case ^Type_Info: ti = a; case ^TypeInfo: ti = a;
} }
write_type(fi.buf, ti); write_type(fi.buf, ti);
return; return;
@@ -1036,8 +1037,8 @@ fmt_arg :: proc(fi: ^Fmt_Info, arg: any, verb: rune) {
sbprint :: proc(buf: ^String_Buffer, args: ..any) -> string { sbprint :: proc(buf: ^StringBuffer, args: ..any) -> string {
fi: Fmt_Info; fi: FmtInfo;
fi.buf = buf; fi.buf = buf;
prev_string := false; prev_string := false;
@@ -1052,8 +1053,8 @@ sbprint :: proc(buf: ^String_Buffer, args: ..any) -> string {
return to_string(buf^); return to_string(buf^);
} }
sbprintln :: proc(buf: ^String_Buffer, args: ..any) -> string { sbprintln :: proc(buf: ^StringBuffer, args: ..any) -> string {
fi: Fmt_Info; fi: FmtInfo;
fi.buf = buf; fi.buf = buf;
for arg, i in args { for arg, i in args {
@@ -1066,13 +1067,13 @@ sbprintln :: proc(buf: ^String_Buffer, args: ..any) -> string {
return to_string(buf^); return to_string(buf^);
} }
sbprintf :: proc(b: ^String_Buffer, fmt: string, args: ..any) -> string { sbprintf :: proc(b: ^StringBuffer, fmt: string, args: ..any) -> string {
fi := Fmt_Info{}; fi := FmtInfo{};
end := len(fmt); end := len(fmt);
arg_index := 0; arg_index := 0;
was_prev_index := false; was_prev_index := false;
for i := 0; i < end; { for i := 0; i < end; {
fi = Fmt_Info{buf = b, good_arg_index = true}; fi = FmtInfo{buf = b, good_arg_index = true};
prev_i := i; prev_i := i;
for i < end && fmt[i] != '%' { for i < end && fmt[i] != '%' {
+23 -23
View File
@@ -50,11 +50,11 @@ align_forward :: proc(ptr: rawptr, align: int) -> rawptr {
Allocation_Header :: struct { AllocationHeader :: struct {
size: int, size: int,
} }
allocation_header_fill :: proc(header: ^Allocation_Header, data: rawptr, size: int) { allocation_header_fill :: proc(header: ^AllocationHeader, data: rawptr, size: int) {
header.size = size; header.size = size;
ptr := ^int(header+1); ptr := ^int(header+1);
@@ -62,7 +62,7 @@ allocation_header_fill :: proc(header: ^Allocation_Header, data: rawptr, size: i
(ptr+i)^ = -1; (ptr+i)^ = -1;
} }
} }
allocation_header :: proc(data: rawptr) -> ^Allocation_Header { allocation_header :: proc(data: rawptr) -> ^AllocationHeader {
if data == nil { if data == nil {
return nil; return nil;
} }
@@ -70,7 +70,7 @@ allocation_header :: proc(data: rawptr) -> ^Allocation_Header {
for (p-1)^ == -1 { for (p-1)^ == -1 {
p = (p-1); p = (p-1);
} }
return ^Allocation_Header(p-1); return ^AllocationHeader(p-1);
} }
@@ -85,7 +85,7 @@ Arena :: struct {
temp_count: int, temp_count: int,
} }
Arena_Temp_Memory :: struct { ArenaTempMemory :: struct {
arena: ^Arena, arena: ^Arena,
original_count: int, original_count: int,
} }
@@ -123,14 +123,14 @@ arena_allocator :: proc(arena: ^Arena) -> Allocator {
}; };
} }
arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, arena_allocator_proc :: proc(allocator_data: rawptr, mode: AllocatorMode,
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 AllocatorMode;
arena := ^Arena(allocator_data); arena := ^Arena(allocator_data);
match mode { match mode {
case ALLOC: case Alloc:
total_size := size + alignment; total_size := size + alignment;
if arena.offset + total_size > len(arena.memory) { if arena.offset + total_size > len(arena.memory) {
@@ -144,29 +144,29 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
arena.offset += total_size; arena.offset += total_size;
return zero(ptr, size); return zero(ptr, size);
case FREE: case Free:
// NOTE(bill): Free all at once // NOTE(bill): Free all at once
// Use Arena_Temp_Memory if you want to free a block // Use ArenaTempMemory if you want to free a block
case FREE_ALL: case FreeAll:
arena.offset = 0; arena.offset = 0;
case RESIZE: case Resize:
return default_resize_align(old_memory, old_size, size, alignment); return default_resize_align(old_memory, old_size, size, alignment);
} }
return nil; return nil;
} }
begin_arena_temp_memory :: proc(a: ^Arena) -> Arena_Temp_Memory { begin_arena_temp_memory :: proc(a: ^Arena) -> ArenaTempMemory {
tmp: Arena_Temp_Memory; tmp: ArenaTempMemory;
tmp.arena = a; tmp.arena = a;
tmp.original_count = len(a.memory); tmp.original_count = len(a.memory);
a.temp_count++; a.temp_count++;
return tmp; return tmp;
} }
end_arena_temp_memory :: proc(using tmp: Arena_Temp_Memory) { end_arena_temp_memory :: proc(using tmp: ArenaTempMemory) {
assert(len(arena.memory) >= original_count); assert(len(arena.memory) >= original_count);
assert(arena.temp_count > 0); assert(arena.temp_count > 0);
arena.memory = arena.memory[0..<original_count]; arena.memory = arena.memory[0..<original_count];
@@ -179,7 +179,7 @@ end_arena_temp_memory :: proc(using tmp: Arena_Temp_Memory) {
align_of_type_info :: proc(type_info: ^Type_Info) -> int { align_of_type_info :: proc(type_info: ^TypeInfo) -> int {
prev_pow2 :: proc(n: i64) -> i64 { prev_pow2 :: proc(n: i64) -> i64 {
if n <= 0 { if n <= 0 {
return 0; return 0;
@@ -195,7 +195,7 @@ align_of_type_info :: proc(type_info: ^Type_Info) -> int {
WORD_SIZE :: size_of(int); WORD_SIZE :: size_of(int);
MAX_ALIGN :: size_of([vector 64]f64); // TODO(bill): Should these constants be builtin constants? MAX_ALIGN :: size_of([vector 64]f64); // TODO(bill): Should these constants be builtin constants?
using Type_Info; using TypeInfo;
match info in type_info { match info in type_info {
case Named: case Named:
return align_of_type_info(info.base); return align_of_type_info(info.base);
@@ -215,7 +215,7 @@ align_of_type_info :: proc(type_info: ^Type_Info) -> int {
return WORD_SIZE; return WORD_SIZE;
case Array: case Array:
return align_of_type_info(info.elem); return align_of_type_info(info.elem);
case Dynamic_Array: case DynamicArray:
return WORD_SIZE; return WORD_SIZE;
case Slice: case Slice:
return WORD_SIZE; return WORD_SIZE;
@@ -230,7 +230,7 @@ align_of_type_info :: proc(type_info: ^Type_Info) -> int {
return info.align; return info.align;
case Union: case Union:
return info.align; return info.align;
case Raw_Union: case RawUnion:
return info.align; return info.align;
case Enum: case Enum:
return align_of_type_info(info.base); return align_of_type_info(info.base);
@@ -246,9 +246,9 @@ align_formula :: proc(size, align: int) -> int {
return result - result%align; return result - result%align;
} }
size_of_type_info :: proc(type_info: ^Type_Info) -> int { size_of_type_info :: proc(type_info: ^TypeInfo) -> int {
WORD_SIZE :: size_of(int); WORD_SIZE :: size_of(int);
using Type_Info; using TypeInfo;
match info in type_info { match info in type_info {
case Named: case Named:
return size_of_type_info(info.base); return size_of_type_info(info.base);
@@ -275,7 +275,7 @@ size_of_type_info :: proc(type_info: ^Type_Info) -> int {
align := align_of_type_info(info.elem); align := align_of_type_info(info.elem);
alignment := align_formula(size, align); alignment := align_formula(size, align);
return alignment*(count-1) + size; return alignment*(count-1) + size;
case Dynamic_Array: case DynamicArray:
return size_of(rawptr) + 2*size_of(int) + size_of(Allocator); return size_of(rawptr) + 2*size_of(int) + size_of(Allocator);
case Slice: case Slice:
return 2*WORD_SIZE; return 2*WORD_SIZE;
@@ -292,7 +292,7 @@ size_of_type_info :: proc(type_info: ^Type_Info) -> int {
return info.size; return info.size;
case Union: case Union:
return info.size; return info.size;
case Raw_Union: case RawUnion:
return info.size; return info.size;
case Enum: case Enum:
return size_of_type_info(info.base); return size_of_type_info(info.base);
+7 -7
View File
@@ -2,7 +2,7 @@
#import "strings.odin"; #import "strings.odin";
Handle :: i32; Handle :: i32;
File_Time :: u64; FileTime :: u64;
Errno :: i32; Errno :: i32;
// INVALID_HANDLE: Handle : -1; // INVALID_HANDLE: Handle : -1;
@@ -36,7 +36,7 @@ RTLD_GLOBAL :: 0x100;
// "Argv" arguments converted to Odin strings // "Argv" arguments converted to Odin strings
immutable args := _alloc_command_line_arguments(); immutable args := _alloc_command_line_arguments();
_File_Time :: struct #ordered { _FileTime :: struct #ordered {
seconds: i64, seconds: i64,
nanoseconds: i32, nanoseconds: i32,
reserved: i32, reserved: i32,
@@ -59,9 +59,9 @@ Stat :: struct #ordered {
block_size: i64, // Optimal bllocksize for I/O block_size: i64, // Optimal bllocksize for I/O
blocks: i64, // Number of 512-byte blocks allocated blocks: i64, // Number of 512-byte blocks allocated
last_access: _File_Time, // Time of last access last_access: _FileTime, // Time of last access
modified: _File_Time, // Time of last modification modified: _FileTime, // Time of last modification
status_change: _File_Time, // Time of last status change status_change: _FileTime, // Time of last status change
_reserve1, _reserve1,
_reserve2, _reserve2,
@@ -193,8 +193,8 @@ stdout: Handle = 1;
stderr: Handle = 2; stderr: Handle = 2;
/* TODO(zangent): Implement these! /* TODO(zangent): Implement these!
last_write_time :: proc(fd: Handle) -> File_Time {} last_write_time :: proc(fd: Handle) -> FileTime {}
last_write_time_by_name :: proc(name: string) -> File_Time {} last_write_time_by_name :: proc(name: string) -> FileTime {}
*/ */
stat :: proc(path: string) -> (Stat, int) #inline { stat :: proc(path: string) -> (Stat, int) #inline {
+9 -9
View File
@@ -1,7 +1,7 @@
#import win32 "sys/windows.odin"; #import win32 "sys/windows.odin";
Handle :: int; Handle :: int;
File_Time :: u64; FileTime :: u64;
Errno :: int; Errno :: int;
INVALID_HANDLE: Handle : -1; INVALID_HANDLE: Handle : -1;
@@ -214,17 +214,17 @@ get_std_handle :: proc(h: int) -> Handle {
last_write_time :: proc(fd: Handle) -> File_Time { last_write_time :: proc(fd: Handle) -> FileTime {
file_info: win32.By_Handle_File_Information; file_info: win32.ByHandleFileInformation;
win32.GetFileInformationByHandle(win32.Handle(fd), &file_info); win32.GetFileInformationByHandle(win32.Handle(fd), &file_info);
lo := File_Time(file_info.last_write_time.lo); lo := FileTime(file_info.last_write_time.lo);
hi := File_Time(file_info.last_write_time.hi); hi := FileTime(file_info.last_write_time.hi);
return lo | hi << 32; return lo | hi << 32;
} }
last_write_time_by_name :: proc(name: string) -> File_Time { last_write_time_by_name :: proc(name: string) -> FileTime {
last_write_time: win32.Filetime; last_write_time: win32.Filetime;
data: win32.File_Attribute_Data; data: win32.FileAttributeData;
buf: [1024]byte; buf: [1024]byte;
assert(len(buf) > len(name)); assert(len(buf) > len(name));
@@ -235,8 +235,8 @@ last_write_time_by_name :: proc(name: string) -> File_Time {
last_write_time = data.last_write_time; last_write_time = data.last_write_time;
} }
l := File_Time(last_write_time.lo); l := FileTime(last_write_time.lo);
h := File_Time(last_write_time.hi); h := FileTime(last_write_time.hi);
return l | h << 32; return l | h << 32;
} }
+3 -3
View File
@@ -2,7 +2,7 @@
#import "strings.odin"; #import "strings.odin";
Handle :: i32; Handle :: i32;
File_Time :: u64; FileTime :: u64;
Errno :: int; Errno :: int;
// TODO(zangent): Find out how to make this work on x64 and x32. // TODO(zangent): Find out how to make this work on x64 and x32.
@@ -211,8 +211,8 @@ stdout: Handle = 1; // get_std_handle(win32.STD_OUTPUT_HANDLE);
stderr: Handle = 2; // get_std_handle(win32.STD_ERROR_HANDLE); stderr: Handle = 2; // get_std_handle(win32.STD_ERROR_HANDLE);
/* TODO(zangent): Implement these! /* TODO(zangent): Implement these!
last_write_time :: proc(fd: Handle) -> File_Time {} last_write_time :: proc(fd: Handle) -> FileTime {}
last_write_time_by_name :: proc(name: string) -> File_Time {} last_write_time_by_name :: proc(name: string) -> FileTime {}
*/ */
stat :: proc(path: string) -> (Stat, bool) #inline { stat :: proc(path: string) -> (Stat, bool) #inline {
+4 -4
View File
@@ -1,6 +1,6 @@
Any :: struct #ordered { Any :: struct #ordered {
data: rawptr, data: rawptr,
type_info: ^Type_Info, type_info: ^TypeInfo,
} }
String :: struct #ordered { String :: struct #ordered {
@@ -14,14 +14,14 @@ Slice :: struct #ordered {
cap: int, cap: int,
}; };
Dynamic_Array :: struct #ordered { DynamicArray :: struct #ordered {
data: rawptr, data: rawptr,
len: int, len: int,
cap: int, cap: int,
allocator: Allocator, allocator: Allocator,
}; };
Dynamic_Map :: struct #ordered { DynamicMap :: struct #ordered {
hashes: [dynamic]int, hashes: [dynamic]int,
entries: Dynamic_Array, entries: DynamicArray,
}; };
+5 -5
View File
@@ -1,6 +1,6 @@
#import . "decimal.odin"; #import . "decimal.odin";
Int_Flag :: enum { IntFlag :: enum {
PREFIX = 1<<0, PREFIX = 1<<0,
PLUS = 1<<1, PLUS = 1<<1,
SPACE = 1<<2, SPACE = 1<<2,
@@ -320,7 +320,7 @@ is_integer_negative :: proc(u: u64, is_signed: bool, bit_size: int) -> (unsigned
} }
append_bits :: proc(buf: []byte, u: u64, base: int, is_signed: bool, bit_size: int, digits: string, flags: Int_Flag) -> string { append_bits :: proc(buf: []byte, u: u64, base: int, is_signed: bool, bit_size: int, digits: string, flags: IntFlag) -> string {
is_pow2 :: proc(x: i64) -> bool { is_pow2 :: proc(x: i64) -> bool {
if (x <= 0) { if (x <= 0) {
return false; return false;
@@ -348,7 +348,7 @@ append_bits :: proc(buf: []byte, u: u64, base: int, is_signed: bool, bit_size: i
i--; i--;
a[i] = digits[uint(u)]; a[i] = digits[uint(u)];
if flags&Int_Flag.PREFIX != 0 { if flags&IntFlag.PREFIX != 0 {
ok := true; ok := true;
match base { match base {
case 2: i--; a[i] = 'b'; case 2: i--; a[i] = 'b';
@@ -366,9 +366,9 @@ append_bits :: proc(buf: []byte, u: u64, base: int, is_signed: bool, bit_size: i
if neg { if neg {
i--; a[i] = '-'; i--; a[i] = '-';
} else if flags&Int_Flag.PLUS != 0 { } else if flags&IntFlag.PLUS != 0 {
i--; a[i] = '+'; i--; a[i] = '+';
} else if flags&Int_Flag.SPACE != 0 { } else if flags&IntFlag.SPACE != 0 {
i--; a[i] = ' '; i--; a[i] = ' ';
} }
+14 -14
View File
@@ -12,7 +12,7 @@ CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x00000002;
Hglrc :: Handle; Hglrc :: Handle;
Color_Ref :: u32; Color_Ref :: u32;
Layer_Plane_Descriptor :: struct { LayerPlaneDescriptor :: struct {
size: u16, size: u16,
version: u16, version: u16,
flags: u32, flags: u32,
@@ -39,28 +39,28 @@ Layer_Plane_Descriptor :: struct {
transparent: Color_Ref, transparent: Color_Ref,
} }
Point_Float :: struct { PointFloat :: struct {
x, y: f32, x, y: f32,
} }
Glyph_Metrics_Float :: struct { Glyph_MetricsFloat :: struct {
black_box_x: f32, black_box_x: f32,
black_box_y: f32, black_box_y: f32,
glyph_origin: Point_Float, glyph_origin: PointFloat,
cell_inc_x: f32, cell_inc_x: f32,
cell_inc_y: f32, cell_inc_y: f32,
} }
CreateContextAttribsARB_Type :: #type proc(hdc: Hdc, h_share_context: rawptr, attribList: ^i32) -> Hglrc; CreateContextAttribsARBType :: #type proc(hdc: Hdc, h_share_context: rawptr, attribList: ^i32) -> Hglrc;
ChoosePixelFormatARB_Type :: #type proc(hdc: Hdc, attrib_i_list: ^i32, attrib_f_list: ^f32, max_formats: u32, formats: ^i32, num_formats : ^u32) -> Bool #cc_c; ChoosePixelFormatARBType :: #type proc(hdc: Hdc, attrib_i_list: ^i32, attrib_f_list: ^f32, max_formats: u32, formats: ^i32, num_formats : ^u32) -> Bool #cc_c;
SwapIntervalEXT_Type :: #type proc(interval : i32) -> bool #cc_c; SwapIntervalEXTType :: #type proc(interval : i32) -> bool #cc_c;
GetExtensionsStringARB_Type :: #type proc(Hdc) -> ^byte #cc_c; GetExtensionsStringARBType :: #type proc(Hdc) -> ^byte #cc_c;
CreateContextAttribsARB: CreateContextAttribsARB_Type; CreateContextAttribsARB: CreateContextAttribsARBType;
ChoosePixelFormatARB: ChoosePixelFormatARB_Type; ChoosePixelFormatARB: ChoosePixelFormatARBType;
SwapIntervalEXT: SwapIntervalEXT_Type; SwapIntervalEXT: SwapIntervalEXTType;
GetExtensionsStringARB: GetExtensionsStringARB_Type; GetExtensionsStringARB: GetExtensionsStringARBType;
@@ -70,7 +70,7 @@ GetProcAddress :: proc(c_str: ^u8) -> Proc
DeleteContext :: proc(hglrc: Hglrc) -> Bool #foreign opengl32 "wglDeleteContext"; DeleteContext :: proc(hglrc: Hglrc) -> Bool #foreign opengl32 "wglDeleteContext";
CopyContext :: proc(src, dst: Hglrc, mask: u32) -> Bool #foreign opengl32 "wglCopyContext"; CopyContext :: proc(src, dst: Hglrc, mask: u32) -> Bool #foreign opengl32 "wglCopyContext";
CreateLayerContext :: proc(hdc: Hdc, layer_plane: i32) -> Hglrc #foreign opengl32 "wglCreateLayerContext"; CreateLayerContext :: proc(hdc: Hdc, layer_plane: i32) -> Hglrc #foreign opengl32 "wglCreateLayerContext";
DescribeLayerPlane :: proc(hdc: Hdc, pixel_format, layer_plane: i32, bytes: u32, pd: ^Layer_Plane_Descriptor) -> Bool #foreign opengl32 "wglDescribeLayerPlane"; DescribeLayerPlane :: proc(hdc: Hdc, pixel_format, layer_plane: i32, bytes: u32, pd: ^LayerPlaneDescriptor) -> Bool #foreign opengl32 "wglDescribeLayerPlane";
GetCurrentContext :: proc() -> Hglrc #foreign opengl32 "wglGetCurrentContext"; GetCurrentContext :: proc() -> Hglrc #foreign opengl32 "wglGetCurrentContext";
GetCurrentDC :: proc() -> Hdc #foreign opengl32 "wglGetCurrentDC"; GetCurrentDC :: proc() -> Hdc #foreign opengl32 "wglGetCurrentDC";
GetLayerPaletteEntries :: proc(hdc: Hdc, layer_plane, start, entries: i32, cr: ^Color_Ref) -> i32 #foreign opengl32 "wglGetLayerPaletteEntries"; GetLayerPaletteEntries :: proc(hdc: Hdc, layer_plane, start, entries: i32, cr: ^Color_Ref) -> i32 #foreign opengl32 "wglGetLayerPaletteEntries";
@@ -79,4 +79,4 @@ SetLayerPaletteEntries :: proc(hdc: Hdc, layer_plane, start, entries: i32, cr:
ShareLists :: proc(hglrc1, hglrc2: Hglrc) -> Bool #foreign opengl32 "wglShareLists"; ShareLists :: proc(hglrc1, hglrc2: Hglrc) -> Bool #foreign opengl32 "wglShareLists";
SwapLayerBuffers :: proc(hdc: Hdc, planes: u32) -> Bool #foreign opengl32 "wglSwapLayerBuffers"; SwapLayerBuffers :: proc(hdc: Hdc, planes: u32) -> Bool #foreign opengl32 "wglSwapLayerBuffers";
UseFontBitmaps :: proc(hdc: Hdc, first, count, list_base: u32) -> Bool #foreign opengl32 "wglUseFontBitmaps"; UseFontBitmaps :: proc(hdc: Hdc, first, count, list_base: u32) -> Bool #foreign opengl32 "wglUseFontBitmaps";
UseFontOutlines :: proc(hdc: Hdc, first, count, list_base: u32, deviation, extrusion: f32, format: i32, gmf: ^Glyph_Metrics_Float) -> Bool #foreign opengl32 "wglUseFontOutlines"; UseFontOutlines :: proc(hdc: Hdc, first, count, list_base: u32, deviation, extrusion: f32, format: i32, gmf: ^Glyph_MetricsFloat) -> Bool #foreign opengl32 "wglUseFontOutlines";
+113 -113
View File
@@ -18,7 +18,7 @@ Wparam :: uint;
Lparam :: int; Lparam :: int;
Lresult :: int; Lresult :: int;
Bool :: i32; Bool :: i32;
Wnd_Proc :: #type proc(Hwnd, u32, Wparam, Lparam) -> Lresult #cc_c; WndProc :: #type proc(Hwnd, u32, Wparam, Lparam) -> Lresult #cc_c;
INVALID_HANDLE :: Handle(~int(0)); INVALID_HANDLE :: Handle(~int(0));
@@ -71,7 +71,7 @@ Point :: struct #ordered {
WndClassExA :: struct #ordered { WndClassExA :: struct #ordered {
size, style: u32, size, style: u32,
wnd_proc: Wnd_Proc, wndproc: WndProc,
cls_extra, wnd_extra: i32, cls_extra, wnd_extra: i32,
instance: Hinstance, instance: Hinstance,
icon: Hicon, icon: Hicon,
@@ -107,7 +107,7 @@ Systemtime :: struct #ordered {
hour, minute, second, millisecond: u16, hour, minute, second, millisecond: u16,
} }
By_Handle_File_Information :: struct #ordered { ByHandleFileInformation :: struct #ordered {
file_attributes: u32, file_attributes: u32,
creation_time, creation_time,
last_access_time, last_access_time,
@@ -120,7 +120,7 @@ By_Handle_File_Information :: struct #ordered {
file_index_low: u32, file_index_low: u32,
} }
File_Attribute_Data :: struct #ordered { FileAttributeData :: struct #ordered {
file_attributes: u32, file_attributes: u32,
creation_time, creation_time,
last_access_time, last_access_time,
@@ -129,7 +129,7 @@ File_Attribute_Data :: struct #ordered {
file_size_low: u32, file_size_low: u32,
} }
Find_Data :: struct #ordered { FindData :: struct #ordered {
file_attributes : u32, file_attributes : u32,
creation_time : Filetime, creation_time : Filetime,
last_access_time : Filetime, last_access_time : Filetime,
@@ -188,7 +188,7 @@ AdjustWindowRect :: proc(rect: ^Rect, style: u32, menu: Bool) -> Bool #foreign u
GetActiveWindow :: proc() -> Hwnd #foreign user32; GetActiveWindow :: proc() -> Hwnd #foreign user32;
DestroyWindow :: proc(wnd: Hwnd) -> Bool #foreign user32; DestroyWindow :: proc(wnd: Hwnd) -> Bool #foreign user32;
DescribePixelFormat :: proc(dc: Hdc, pixel_format: i32, bytes : u32, pfd: ^PIXELFORMATDESCRIPTOR) -> i32 #foreign user32; DescribePixelFormat :: proc(dc: Hdc, pixel_format: i32, bytes : u32, pfd: ^PixelFormatDescriptor) -> i32 #foreign user32;
GetQueryPerformanceFrequency :: proc() -> i64 { GetQueryPerformanceFrequency :: proc() -> i64 {
@@ -222,15 +222,15 @@ WriteFile :: proc(h: Handle, buf: rawptr, len: i32, written_result: ^i32, overla
GetFileSizeEx :: proc(file_handle: Handle, file_size: ^i64) -> Bool #foreign kernel32; GetFileSizeEx :: proc(file_handle: Handle, file_size: ^i64) -> Bool #foreign kernel32;
GetFileAttributesA :: proc(filename : ^byte) -> u32 #foreign kernel32; GetFileAttributesA :: proc(filename : ^byte) -> u32 #foreign kernel32;
GetFileAttributesExA :: proc(filename: ^u8, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> Bool #foreign kernel32; GetFileAttributesExA :: proc(filename: ^u8, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> Bool #foreign kernel32;
GetFileInformationByHandle :: proc(file_handle: Handle, file_info: ^By_Handle_File_Information) -> Bool #foreign kernel32; GetFileInformationByHandle :: proc(file_handle: Handle, file_info: ^ByHandleFileInformation) -> Bool #foreign kernel32;
GetFileType :: proc(file_handle: Handle) -> u32 #foreign kernel32; GetFileType :: proc(file_handle: Handle) -> u32 #foreign kernel32;
SetFilePointer :: proc(file_handle: Handle, distance_to_move: i32, distance_to_move_high: ^i32, move_method: u32) -> u32 #foreign kernel32; SetFilePointer :: proc(file_handle: Handle, distance_to_move: i32, distance_to_move_high: ^i32, move_method: u32) -> u32 #foreign kernel32;
SetHandleInformation :: proc(obj: Handle, mask, flags: u32) -> Bool #foreign kernel32; SetHandleInformation :: proc(obj: Handle, mask, flags: u32) -> Bool #foreign kernel32;
FindFirstFileA :: proc(file_name : ^byte, data : ^Find_Data) -> Handle #foreign kernel32; FindFirstFileA :: proc(file_name : ^byte, data : ^FindData) -> Handle #foreign kernel32;
FindNextFileA :: proc(file : Handle, data : ^Find_Data) -> Bool #foreign kernel32; FindNextFileA :: proc(file : Handle, data : ^FindData) -> Bool #foreign kernel32;
FindClose :: proc(file : Handle) -> Bool #foreign kernel32; FindClose :: proc(file : Handle) -> Bool #foreign kernel32;
MAX_PATH :: 0x00000104; MAX_PATH :: 0x00000104;
@@ -350,14 +350,14 @@ SWP_NOSIZE :: 0x0001;
SWP_NOMOVE :: 0x0002; SWP_NOMOVE :: 0x0002;
Monitor_Info :: struct #ordered { MonitorInfo :: struct #ordered {
size: u32, size: u32,
monitor: Rect, monitor: Rect,
work: Rect, work: Rect,
flags: u32, flags: u32,
} }
Window_Placement :: struct #ordered { WindowPlacement :: struct #ordered {
length: u32, length: u32,
flags: u32, flags: u32,
show_cmd: u32, show_cmd: u32,
@@ -366,13 +366,13 @@ Window_Placement :: struct #ordered {
normal_pos: Rect, normal_pos: Rect,
} }
GetMonitorInfoA :: proc(monitor: Hmonitor, mi: ^Monitor_Info) -> Bool #foreign user32; GetMonitorInfoA :: proc(monitor: Hmonitor, mi: ^MonitorInfo) -> Bool #foreign user32;
MonitorFromWindow :: proc(wnd: Hwnd, flags : u32) -> Hmonitor #foreign user32; MonitorFromWindow :: proc(wnd: Hwnd, flags : u32) -> Hmonitor #foreign user32;
SetWindowPos :: proc(wnd: Hwnd, wndInsertAfter: Hwnd, x, y, width, height: i32, flags: u32) #foreign user32 "SetWindowPos"; SetWindowPos :: proc(wnd: Hwnd, wndInsertAfter: Hwnd, x, y, width, height: i32, flags: u32) #foreign user32 "SetWindowPos";
GetWindowPlacement :: proc(wnd: Hwnd, wndpl: ^Window_Placement) -> Bool #foreign user32; GetWindowPlacement :: proc(wnd: Hwnd, wndpl: ^WindowPlacement) -> Bool #foreign user32;
SetWindowPlacement :: proc(wnd: Hwnd, wndpl: ^Window_Placement) -> Bool #foreign user32; SetWindowPlacement :: proc(wnd: Hwnd, wndpl: ^WindowPlacement) -> Bool #foreign user32;
GetWindowRect :: proc(wnd: Hwnd, rect: ^Rect) -> Bool #foreign user32; GetWindowRect :: proc(wnd: Hwnd, rect: ^Rect) -> Bool #foreign user32;
GetWindowLongPtrA :: proc(wnd: Hwnd, index: i32) -> i64 #foreign user32; GetWindowLongPtrA :: proc(wnd: Hwnd, index: i32) -> i64 #foreign user32;
@@ -394,7 +394,7 @@ LOWORD :: proc(lParam: Lparam) -> u16 { return u16(lParam); }
Bitmap_Info_Header :: struct #ordered { BitmapInfoHeader :: struct #ordered {
size: u32, size: u32,
width, height: i32, width, height: i32,
planes, bit_count: i16, planes, bit_count: i16,
@@ -405,13 +405,13 @@ Bitmap_Info_Header :: struct #ordered {
clr_used: u32, clr_used: u32,
clr_important: u32, clr_important: u32,
} }
Bitmap_Info :: struct #ordered { BitmapInfo :: struct #ordered {
using header: Bitmap_Info_Header, using header: BitmapInfoHeader,
colors: [1]Rgb_Quad, colors: [1]RgbQuad,
} }
Rgb_Quad :: struct #ordered { blue, green, red, reserved: byte } RgbQuad :: struct #ordered { blue, green, red, reserved: byte }
BI_RGB :: 0; BI_RGB :: 0;
DIB_RGB_COLORS :: 0x00; DIB_RGB_COLORS :: 0x00;
@@ -421,7 +421,7 @@ SRCCOPY: u32 : 0x00cc0020;
StretchDIBits :: proc (hdc: Hdc, StretchDIBits :: proc (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: ^Bitmap_Info, bits: rawptr, bits_info: ^BitmapInfo,
usage: u32, usage: u32,
rop: u32) -> i32 #foreign gdi32; rop: u32) -> i32 #foreign gdi32;
@@ -457,7 +457,7 @@ PFD_DOUBLEBUFFER_DONTCARE :: 0x40000000;
PFD_STEREO_DONTCARE :: 0x80000000; PFD_STEREO_DONTCARE :: 0x80000000;
PIXELFORMATDESCRIPTOR :: struct #ordered { PixelFormatDescriptor :: struct #ordered {
size, size,
version, version,
flags: u32, flags: u32,
@@ -489,8 +489,8 @@ PIXELFORMATDESCRIPTOR :: struct #ordered {
} }
GetDC :: proc(h: Hwnd) -> Hdc #foreign user32; GetDC :: proc(h: Hwnd) -> Hdc #foreign user32;
SetPixelFormat :: proc(hdc: Hdc, pixel_format: i32, pfd: ^PIXELFORMATDESCRIPTOR) -> Bool #foreign gdi32; SetPixelFormat :: proc(hdc: Hdc, pixel_format: i32, pfd: ^PixelFormatDescriptor) -> Bool #foreign gdi32;
ChoosePixelFormat :: proc(hdc: Hdc, pfd: ^PIXELFORMATDESCRIPTOR) -> i32 #foreign gdi32; ChoosePixelFormat :: proc(hdc: Hdc, pfd: ^PixelFormatDescriptor) -> i32 #foreign gdi32;
SwapBuffers :: proc(hdc: Hdc) -> Bool #foreign gdi32; SwapBuffers :: proc(hdc: Hdc) -> Bool #foreign gdi32;
ReleaseDC :: proc(wnd: Hwnd, hdc: Hdc) -> i32 #foreign user32; ReleaseDC :: proc(wnd: Hwnd, hdc: Hdc) -> i32 #foreign user32;
@@ -501,62 +501,62 @@ Proc :: #type proc() #cc_c;
GetKeyState :: proc(v_key: i32) -> i16 #foreign user32; GetKeyState :: proc(v_key: i32) -> i16 #foreign user32;
GetAsyncKeyState :: proc(v_key: i32) -> i16 #foreign user32; GetAsyncKeyState :: proc(v_key: i32) -> i16 #foreign user32;
is_key_down :: proc(key: Key_Code) -> bool #inline { return GetAsyncKeyState(i32(key)) < 0; } is_key_down :: proc(key: KeyCode) -> bool #inline { return GetAsyncKeyState(i32(key)) < 0; }
Key_Code :: enum i32 { KeyCode :: enum i32 {
LBUTTON = 0x01, Lbutton = 0x01,
RBUTTON = 0x02, Rbutton = 0x02,
CANCEL = 0x03, Cancel = 0x03,
MBUTTON = 0x04, Mbutton = 0x04,
BACK = 0x08, Back = 0x08,
TAB = 0x09, Tab = 0x09,
CLEAR = 0x0C, Clear = 0x0C,
RETURN = 0x0D, Return = 0x0D,
SHIFT = 0x10, Shift = 0x10,
CONTROL = 0x11, Control = 0x11,
MENU = 0x12, Menu = 0x12,
PAUSE = 0x13, Pause = 0x13,
CAPITAL = 0x14, Capital = 0x14,
KANA = 0x15, Kana = 0x15,
HANGEUL = 0x15, Hangeul = 0x15,
HANGUL = 0x15, Hangul = 0x15,
JUNJA = 0x17, Junja = 0x17,
FINAL = 0x18, Final = 0x18,
HANJA = 0x19, Hanja = 0x19,
KANJI = 0x19, Kanji = 0x19,
ESCAPE = 0x1B, Escape = 0x1B,
CONVERT = 0x1C, Convert = 0x1C,
NONCONVERT = 0x1D, NonConvert = 0x1D,
ACCEPT = 0x1E, Accept = 0x1E,
MODECHANGE = 0x1F, ModeChange = 0x1F,
SPACE = 0x20, Space = 0x20,
PRIOR = 0x21, Prior = 0x21,
NEXT = 0x22, Next = 0x22,
END = 0x23, End = 0x23,
HOME = 0x24, Home = 0x24,
LEFT = 0x25, Left = 0x25,
UP = 0x26, Up = 0x26,
RIGHT = 0x27, Right = 0x27,
DOWN = 0x28, Down = 0x28,
SELECT = 0x29, Select = 0x29,
PRINT = 0x2A, Print = 0x2A,
EXECUTE = 0x2B, Execute = 0x2B,
SNAPSHOT = 0x2C, Snapshot = 0x2C,
INSERT = 0x2D, Insert = 0x2D,
DELETE = 0x2E, Delete = 0x2E,
HELP = 0x2F, Help = 0x2F,
NUM0 = '0', Num0 = '0',
NUM1 = '1', Num1 = '1',
NUM2 = '2', Num2 = '2',
NUM3 = '3', Num3 = '3',
NUM4 = '4', Num4 = '4',
NUM5 = '5', Num5 = '5',
NUM6 = '6', Num6 = '6',
NUM7 = '7', Num7 = '7',
NUM8 = '8', Num8 = '8',
NUM9 = '9', Num9 = '9',
A = 'A', A = 'A',
B = 'B', B = 'B',
C = 'C', C = 'C',
@@ -584,26 +584,26 @@ Key_Code :: enum i32 {
Y = 'Y', Y = 'Y',
Z = 'Z', Z = 'Z',
LWIN = 0x5B, Lwin = 0x5B,
RWIN = 0x5C, Rwin = 0x5C,
APPS = 0x5D, Apps = 0x5D,
NUMPAD0 = 0x60, Numpad0 = 0x60,
NUMPAD1 = 0x61, Numpad1 = 0x61,
NUMPAD2 = 0x62, Numpad2 = 0x62,
NUMPAD3 = 0x63, Numpad3 = 0x63,
NUMPAD4 = 0x64, Numpad4 = 0x64,
NUMPAD5 = 0x65, Numpad5 = 0x65,
NUMPAD6 = 0x66, Numpad6 = 0x66,
NUMPAD7 = 0x67, Numpad7 = 0x67,
NUMPAD8 = 0x68, Numpad8 = 0x68,
NUMPAD9 = 0x69, Numpad9 = 0x69,
MULTIPLY = 0x6A, Multiply = 0x6A,
ADD = 0x6B, Add = 0x6B,
SEPARATOR = 0x6C, Separator = 0x6C,
SUBTRACT = 0x6D, Subtract = 0x6D,
DECIMAL = 0x6E, Decimal = 0x6E,
DIVIDE = 0x6F, Divide = 0x6F,
F1 = 0x70, F1 = 0x70,
F2 = 0x71, F2 = 0x71,
@@ -630,22 +630,22 @@ Key_Code :: enum i32 {
F23 = 0x86, F23 = 0x86,
F24 = 0x87, F24 = 0x87,
NUMLOCK = 0x90, Numlock = 0x90,
SCROLL = 0x91, Scroll = 0x91,
LSHIFT = 0xA0, Lshift = 0xA0,
RSHIFT = 0xA1, Rshift = 0xA1,
LCONTROL = 0xA2, Lcontrol = 0xA2,
RCONTROL = 0xA3, Rcontrol = 0xA3,
LMENU = 0xA4, Lmenu = 0xA4,
RMENU = 0xA5, Rmenu = 0xA5,
ProcESSKEY = 0xE5, ProcessKey = 0xE5,
ATTN = 0xF6, Attn = 0xF6,
CRSEL = 0xF7, Crsel = 0xF7,
EXSEL = 0xF8, Exsel = 0xF8,
EREOF = 0xF9, Ereof = 0xF9,
PLAY = 0xFA, Play = 0xFA,
ZOOM = 0xFB, Zoom = 0xFB,
NONAME = 0xFC, Noname = 0xFC,
PA1 = 0xFD, Pa1 = 0xFD,
OEM_CLEAR = 0xFE, OemClear = 0xFE,
} }
+39 -39
View File
@@ -1,98 +1,98 @@
is_signed :: proc(info: ^Type_Info) -> bool { is_signed :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
match i in type_info_base(info) { match i in type_info_base(info) {
case Type_Info.Integer: return i.signed; case TypeInfo.Integer: return i.signed;
case Type_Info.Float: return true; case TypeInfo.Float: return true;
} }
return false; return false;
} }
is_integer :: proc(info: ^Type_Info) -> bool { is_integer :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Integer); _, ok := type_info_base(info).(^TypeInfo.Integer);
return ok; return ok;
} }
is_float :: proc(info: ^Type_Info) -> bool { is_float :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Float); _, ok := type_info_base(info).(^TypeInfo.Float);
return ok; return ok;
} }
is_complex :: proc(info: ^Type_Info) -> bool { is_complex :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Complex); _, ok := type_info_base(info).(^TypeInfo.Complex);
return ok; return ok;
} }
is_any :: proc(info: ^Type_Info) -> bool { is_any :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Any); _, ok := type_info_base(info).(^TypeInfo.Any);
return ok; return ok;
} }
is_string :: proc(info: ^Type_Info) -> bool { is_string :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.String); _, ok := type_info_base(info).(^TypeInfo.String);
return ok; return ok;
} }
is_boolean :: proc(info: ^Type_Info) -> bool { is_boolean :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Boolean); _, ok := type_info_base(info).(^TypeInfo.Boolean);
return ok; return ok;
} }
is_pointer :: proc(info: ^Type_Info) -> bool { is_pointer :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Pointer); _, ok := type_info_base(info).(^TypeInfo.Pointer);
return ok; return ok;
} }
is_procedure :: proc(info: ^Type_Info) -> bool { is_procedure :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Procedure); _, ok := type_info_base(info).(^TypeInfo.Procedure);
return ok; return ok;
} }
is_array :: proc(info: ^Type_Info) -> bool { is_array :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Array); _, ok := type_info_base(info).(^TypeInfo.Array);
return ok; return ok;
} }
is_dynamic_array :: proc(info: ^Type_Info) -> bool { is_dynamic_array :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Dynamic_Array); _, ok := type_info_base(info).(^TypeInfo.DynamicArray);
return ok; return ok;
} }
is_dynamic_map :: proc(info: ^Type_Info) -> bool { is_dynamic_map :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Map); _, ok := type_info_base(info).(^TypeInfo.Map);
return ok; return ok;
} }
is_slice :: proc(info: ^Type_Info) -> bool { is_slice :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Slice); _, ok := type_info_base(info).(^TypeInfo.Slice);
return ok; return ok;
} }
is_vector :: proc(info: ^Type_Info) -> bool { is_vector :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Vector); _, ok := type_info_base(info).(^TypeInfo.Vector);
return ok; return ok;
} }
is_tuple :: proc(info: ^Type_Info) -> bool { is_tuple :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Tuple); _, ok := type_info_base(info).(^TypeInfo.Tuple);
return ok; return ok;
} }
is_struct :: proc(info: ^Type_Info) -> bool { is_struct :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Struct); _, ok := type_info_base(info).(^TypeInfo.Struct);
return ok; return ok;
} }
is_union :: proc(info: ^Type_Info) -> bool { is_union :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Union); _, ok := type_info_base(info).(^TypeInfo.Union);
return ok; return ok;
} }
is_raw_union :: proc(info: ^Type_Info) -> bool { is_raw_union :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Raw_Union); _, ok := type_info_base(info).(^TypeInfo.RawUnion);
return ok; return ok;
} }
is_enum :: proc(info: ^Type_Info) -> bool { is_enum :: proc(info: ^TypeInfo) -> bool {
if info == nil { return false; } if info == nil { return false; }
_, ok := type_info_base(info).(^Type_Info.Enum); _, ok := type_info_base(info).(^TypeInfo.Enum);
return ok; return ok;
} }
+2 -2
View File
@@ -28,9 +28,9 @@ RUNE3_MAX :: 1<<16 - 1;
LOCB :: 0b1000_0000; LOCB :: 0b1000_0000;
HICB :: 0b1011_1111; HICB :: 0b1011_1111;
Accept_Range :: struct { lo, hi: u8 } AcceptRange :: struct { lo, hi: u8 }
immutable accept_ranges := [5]Accept_Range{ immutable accept_ranges := [5]AcceptRange{
{0x80, 0xbf}, {0x80, 0xbf},
{0xa0, 0xbf}, {0xa0, 0xbf},
{0x80, 0x9f}, {0x80, 0x9f},
+6 -6
View File
@@ -1201,22 +1201,22 @@ void init_preload(Checker *c) {
} }
if (t_type_info == NULL) { if (t_type_info == NULL) {
Entity *type_info_entity = find_core_entity(c, str_lit("Type_Info")); Entity *type_info_entity = find_core_entity(c, str_lit("TypeInfo"));
t_type_info = type_info_entity->type; t_type_info = type_info_entity->type;
t_type_info_ptr = make_type_pointer(c->allocator, t_type_info); t_type_info_ptr = make_type_pointer(c->allocator, t_type_info);
GB_ASSERT(is_type_union(type_info_entity->type)); GB_ASSERT(is_type_union(type_info_entity->type));
TypeRecord *record = &base_type(type_info_entity->type)->Record; TypeRecord *record = &base_type(type_info_entity->type)->Record;
t_type_info_record = find_core_entity(c, str_lit("Type_Info_Record"))->type; t_type_info_record = find_core_entity(c, str_lit("TypeInfoRecord"))->type;
t_type_info_record_ptr = make_type_pointer(c->allocator, t_type_info_record); t_type_info_record_ptr = make_type_pointer(c->allocator, t_type_info_record);
t_type_info_enum_value = find_core_entity(c, str_lit("Type_Info_Enum_Value"))->type; t_type_info_enum_value = find_core_entity(c, str_lit("TypeInfoEnumValue"))->type;
t_type_info_enum_value_ptr = make_type_pointer(c->allocator, t_type_info_enum_value); t_type_info_enum_value_ptr = make_type_pointer(c->allocator, t_type_info_enum_value);
if (record->variant_count != 22) { if (record->variant_count != 22) {
compiler_error("Invalid `Type_Info` layout"); compiler_error("Invalid `TypeInfo` layout");
} }
t_type_info_named = record->variants[ 1]->type; t_type_info_named = record->variants[ 1]->type;
t_type_info_integer = record->variants[ 2]->type; t_type_info_integer = record->variants[ 2]->type;
@@ -1277,12 +1277,12 @@ void init_preload(Checker *c) {
} }
if (t_map_key == NULL) { if (t_map_key == NULL) {
Entity *e = find_core_entity(c, str_lit("__Map_Key")); Entity *e = find_core_entity(c, str_lit("__MapKey"));
t_map_key = e->type; t_map_key = e->type;
} }
if (t_map_header == NULL) { if (t_map_header == NULL) {
Entity *e = find_core_entity(c, str_lit("__Map_Header")); Entity *e = find_core_entity(c, str_lit("__MapHeader"));
t_map_header = e->type; t_map_header = e->type;
} }