Untyped nil

This commit is contained in:
Ginger Bill
2016-10-06 17:11:17 +01:00
parent fee504636f
commit 50301557b2
28 changed files with 8078 additions and 8567 deletions
+16 -16
View File
@@ -14,10 +14,10 @@ Type_Info :: union {
}
Record :: struct #ordered {
fields: []Member
packed: bool
ordered: bool
size: int // in bytes
align: int // in bytes
packed: bool
ordered: bool
}
Named: struct #ordered {
@@ -60,15 +60,15 @@ Type_Info :: union {
Union: Record
Raw_Union: Record
Enum: struct #ordered {
base: ^Type_Info
base: ^Type_Info
values: []i64
names: []string
}
}
type_info_base :: proc(info: ^Type_Info) -> ^Type_Info {
if info == null {
return null
if info == nil {
return nil
}
match type i : info {
case Type_Info.Named:
@@ -142,7 +142,7 @@ current_context :: proc() -> Context { // Copy of context
__check_context :: proc() {
c := ^__context
if c.allocator.procedure == null {
if c.allocator.procedure == nil {
c.allocator = __default_allocator()
}
if c.thread_id == 0 {
@@ -155,20 +155,20 @@ alloc :: proc(size: int) -> rawptr #inline { return alloc_align(size, DEFAULT_AL
alloc_align :: proc(size, alignment: int) -> rawptr #inline {
__check_context()
a := current_context().allocator
return a.procedure(a.data, Allocator.Mode.ALLOC, size, alignment, null, 0, 0)
return a.procedure(a.data, Allocator.Mode.ALLOC, size, alignment, nil, 0, 0)
}
free :: proc(ptr: rawptr) #inline {
__check_context()
a := current_context().allocator
if ptr != null {
if ptr != nil {
a.procedure(a.data, Allocator.Mode.FREE, 0, 0, ptr, 0, 0)
}
}
free_all :: proc() #inline {
__check_context()
a := current_context().allocator
a.procedure(a.data, Allocator.Mode.FREE_ALL, 0, 0, null, 0, 0)
a.procedure(a.data, Allocator.Mode.FREE_ALL, 0, 0, nil, 0, 0)
}
@@ -181,13 +181,13 @@ 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 {
if old_memory == null {
if old_memory == nil {
return alloc_align(new_size, alignment)
}
if new_size == 0 {
free(old_memory)
return null
return nil
}
if new_size == old_size {
@@ -195,8 +195,8 @@ default_resize_align :: proc(old_memory: rawptr, old_size, new_size, alignment:
}
new_memory := alloc_align(new_size, alignment)
if new_memory == null {
return null
if new_memory == nil {
return nil
}
mem.copy(new_memory, old_memory, min(old_size, new_size));
@@ -220,7 +220,7 @@ __default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator.Mode,
case FREE:
os.heap_free(mem.allocation_header(old_memory))
return null
return nil
case FREE_ALL:
// NOTE(bill): Does nothing
@@ -234,13 +234,13 @@ __default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator.Mode,
return mem.zero(ptr, size)
}
return null
return nil
}
__default_allocator :: proc() -> Allocator {
return Allocator{
procedure = __default_allocator_proc,
data = null,
data = nil,
}
}
+19 -15
View File
@@ -197,7 +197,7 @@ print__f64 :: proc(buffer: ^[]byte, f: f64, decimal_places: int) {
}
print_type_to_buffer :: proc(buf: ^[]byte, ti: ^Type_Info) {
if ti == null { return }
if ti == nil { return }
using Type_Info
match type info : ti {
@@ -230,7 +230,7 @@ print_type_to_buffer :: proc(buf: ^[]byte, ti: ^Type_Info) {
print_type_to_buffer(buf, info.elem)
case Procedure:
print_string_to_buffer(buf, "proc")
if info.params == null {
if info.params == nil {
print_string_to_buffer(buf, "()")
} else {
count := (info.params as ^Tuple).fields.count
@@ -238,7 +238,7 @@ print_type_to_buffer :: proc(buf: ^[]byte, ti: ^Type_Info) {
print_type_to_buffer(buf, info.params)
if count == 1 { print_string_to_buffer(buf, ")") }
}
if info.results != null {
if info.results != nil {
print_string_to_buffer(buf, " -> ")
print_type_to_buffer(buf, info.results)
}
@@ -320,7 +320,11 @@ print_type_to_buffer :: proc(buf: ^[]byte, ti: ^Type_Info) {
}
print_any_to_buffer :: proc(buf: ^[]byte, arg: any) {
print_any_to_buffer :: proc(buf: ^[]byte, arg: any) {
if arg.type_info == nil {
print_string_to_buffer(buf, "<nil>")
return
}
using Type_Info
match type info : arg.type_info {
case Named:
@@ -352,7 +356,7 @@ print_any_to_buffer :: proc(buf: ^[]byte, arg: any) {
case Integer:
if info.signed {
i: i64 = 0;
if arg.data != null {
if arg.data != nil {
match info.size {
case 1: i = (arg.data as ^i8)^ as i64
case 2: i = (arg.data as ^i16)^ as i64
@@ -363,7 +367,7 @@ print_any_to_buffer :: proc(buf: ^[]byte, arg: any) {
print_i64_to_buffer(buf, i)
} else {
i: u64 = 0;
if arg.data != null {
if arg.data != nil {
match info.size {
case 1: i = (arg.data as ^u8)^ as u64
case 2: i = (arg.data as ^u16)^ as u64
@@ -376,7 +380,7 @@ print_any_to_buffer :: proc(buf: ^[]byte, arg: any) {
case Float:
f: f64 = 0
if arg.data != null {
if arg.data != nil {
match info.size {
case 4: f = (arg.data as ^f32)^ as f64
case 8: f = (arg.data as ^f64)^ as f64
@@ -386,27 +390,27 @@ print_any_to_buffer :: proc(buf: ^[]byte, arg: any) {
case String:
s := ""
if arg.data != null {
if arg.data != nil {
s = (arg.data as ^string)^
}
print_string_to_buffer(buf, s)
case Boolean:
v := false;
if arg.data != null {
if arg.data != nil {
v = (arg.data as ^bool)^
}
print_bool_to_buffer(buf, v)
case Pointer:
if arg.data != null {
if arg.data != nil {
if arg.type_info == type_info(^Type_Info) {
print_type_to_buffer(buf, (arg.data as ^^Type_Info)^)
} else {
print_pointer_to_buffer(buf, (arg.data as ^rawptr)^)
}
} else {
print_pointer_to_buffer(buf, null)
print_pointer_to_buffer(buf, nil)
}
case Enum:
@@ -414,7 +418,7 @@ print_any_to_buffer :: proc(buf: ^[]byte, arg: any) {
match type i : info.base {
case Integer:
if i.signed {
if arg.data != null {
if arg.data != nil {
match i.size {
case 1: value = (arg.data as ^i8)^ as i64
case 2: value = (arg.data as ^i16)^ as i64
@@ -423,7 +427,7 @@ print_any_to_buffer :: proc(buf: ^[]byte, arg: any) {
}
}
} else {
if arg.data != null {
if arg.data != nil {
match i.size {
case 1: value = (arg.data as ^u8)^ as i64
case 2: value = (arg.data as ^u16)^ as i64
@@ -582,7 +586,7 @@ bprint :: proc(buf: ^[]byte, args: ..any) {
is_type_string :: proc(info: ^Type_Info) -> bool {
using Type_Info
info = type_info_base(info)
if info == null {
if info == nil {
return false
}
@@ -597,7 +601,7 @@ bprint :: proc(buf: ^[]byte, args: ..any) {
prev_string := false
for i := 0; i < args.count; i++ {
arg := args[i]
is_string := arg.data != null && is_type_string(arg.type_info)
is_string := arg.data != nil && is_type_string(arg.type_info)
if i > 0 && !is_string && !prev_string {
print_space_to_buffer(buf)
}
+3 -3
View File
@@ -143,7 +143,7 @@ init_sub_arena :: proc(sub, parent: ^Arena, size: int) {
}
free_arena :: proc(using a: ^Arena) {
if backing.procedure != null {
if backing.procedure != nil {
push_allocator backing {
free(memory.data)
memory = memory[0:0:0]
@@ -170,7 +170,7 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator.Mode,
if arena.memory.count + total_size > arena.memory.capacity {
fmt.fprintln(os.stderr, "Arena out of memory")
return null
return nil
}
#no_bounds_check end := ^arena.memory[arena.memory.count]
@@ -190,7 +190,7 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator.Mode,
return default_resize_align(old_memory, old_size, size, alignment)
}
return null
return nil
}
begin_temp_arena_memory :: proc(a: ^Arena) -> Temp_Arena_Memory {
+5 -5
View File
@@ -9,7 +9,7 @@ open :: proc(name: string) -> (File, bool) {
using win32
buf: [300]byte
copy(buf[:], name as []byte)
f := File{CreateFileA(^buf[0], FILE_GENERIC_READ, FILE_SHARE_READ, null, OPEN_EXISTING, 0, null)}
f := File{CreateFileA(^buf[0], FILE_GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0, nil)}
success := f.handle != INVALID_HANDLE_VALUE as File.Handle
return f, success
@@ -20,7 +20,7 @@ create :: proc(name: string) -> (File, bool) {
buf: [300]byte
copy(buf[:], name as []byte)
f := File{
handle = CreateFileA(^buf[0], FILE_GENERIC_WRITE, FILE_SHARE_READ, null, CREATE_ALWAYS, 0, null),
handle = CreateFileA(^buf[0], FILE_GENERIC_WRITE, FILE_SHARE_READ, nil, CREATE_ALWAYS, 0, nil),
}
success := f.handle != INVALID_HANDLE_VALUE as File.Handle
return f, success
@@ -32,7 +32,7 @@ close :: proc(using f: ^File) {
write :: proc(using f: ^File, buf: []byte) -> bool {
bytes_written: i32
return win32.WriteFile(handle, buf.data, buf.count as i32, ^bytes_written, null) != 0
return win32.WriteFile(handle, buf.data, buf.count as i32, ^bytes_written, nil) != 0
}
@@ -72,7 +72,7 @@ read_entire_file :: proc(name: string) -> (string, bool) {
}
data := new_slice(u8, length)
if data.data == null {
if data.data == nil {
return "", false
}
@@ -89,7 +89,7 @@ read_entire_file :: proc(name: string) -> (string, bool) {
to_read = MAX
}
win32.ReadFile(f.handle as win32.HANDLE, ^data[total_read], to_read, ^single_read_length, null)
win32.ReadFile(f.handle as win32.HANDLE, ^data[total_read], to_read, ^single_read_length, nil)
if single_read_length <= 0 {
free(data.data)
return "", false
+6 -6
View File
@@ -12,14 +12,14 @@ Accept_Range :: struct {
}
accept_ranges := [5]Accept_Range{
Accept_Range{0x80, 0xbf},
Accept_Range{0xa0, 0xbf},
Accept_Range{0x80, 0x9f},
Accept_Range{0x90, 0xbf},
Accept_Range{0x80, 0x8f},
{0x80, 0xbf},
{0xa0, 0xbf},
{0x80, 0x9f},
{0x90, 0xbf},
{0x80, 0x8f},
}
accept_sizes := [256]u8{
accept_sizes := [256]byte{
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x00-0x0f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x10-0x1f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x20-0x2f