Change to globals are PascalCase, locals are snake_case

This commit is contained in:
Krzosa Karol
2022-09-27 10:51:12 +02:00
parent 3dd9fae080
commit b8ab388bfc
11 changed files with 123 additions and 148 deletions

View File

@@ -7,14 +7,14 @@ Memory :: struct
reserve: SizeU
data : *U8
process_heap: HANDLE
allocate :: (size: U64): *void
if process_heap == 0
process_heap = GetProcessHeap()
return HeapAlloc(process_heap, 0, size)
ProcessHeap: HANDLE
Allocate :: (size: U64): *void
if ProcessHeap == 0
ProcessHeap = GetProcessHeap()
return HeapAlloc(ProcessHeap, 0, size)
reserve :: (size: SizeU): Memory
result := Memory{reserve=align_up(size, PAGE_SIZE)}
Reserve :: (size: SizeU): Memory
result := Memory{reserve=AlignUp(size, PAGE_SIZE)}
result.data = VirtualAlloc(
flProtect = PAGE_READWRITE,
dwSize = result.reserve,
@@ -22,10 +22,10 @@ reserve :: (size: SizeU): Memory
lpAddress = 0)->*U8
return result
commit :: (m: *Memory, size: SizeU): Bool
commit_size := align_up(size, PAGE_SIZE)
Commit :: (m: *Memory, size: SizeU): Bool
commit_size := AlignUp(size, PAGE_SIZE)
total_commit := m.commit + commit_size
clamped_commit := clamp_top_sizeu(total_commit, m.reserve)
clamped_commit := ClampTopSizeU(total_commit, m.reserve)
adjusted_commit := clamped_commit - m.commit
if adjusted_commit != 0
result := VirtualAlloc(
@@ -38,28 +38,28 @@ commit :: (m: *Memory, size: SizeU): Bool
return true
return false
release :: (m: *Memory)
Release :: (m: *Memory)
result := VirtualFree(m.data->*void, 0, MEM_RELEASE)
if result != 0
m.data = 0
m.commit = 0
m.reserve = 0
write_console :: (string: String16)
WriteConsole :: (string: String16)
handle := GetStdHandle(STD_OUTPUT_HANDLE)
WriteConsoleW(handle, string.str->*void, string.len->DWORD, 0, 0)
performance_frequency: F64
time :: (): F64
PerformanceFrequency: F64
Time :: (): F64
query: LARGE_INTEGER
if !performance_frequency
if !PerformanceFrequency
err := QueryPerformanceFrequency(&query)
assert(err != 0)
performance_frequency = query->F64
Assert(err != 0)
PerformanceFrequency = query->F64
err := QueryPerformanceCounter(&query)
assert(err != 0)
result := query->F64 / performance_frequency
Assert(err != 0)
result := query->F64 / PerformanceFrequency
return result
/**
@@ -67,7 +67,7 @@ time :: (): F64
* Written by Lukás Chmela
* Released under GPLv3.
*/
itoa :: (value: S64, result: *U8, base: S64): *U8
Itoa :: (value: S64, result: *U8, base: S64): *U8
// check that the base if valid
if (base < 2) || (base > 36)
*result = 0 // '
@@ -94,14 +94,14 @@ itoa :: (value: S64, result: *U8, base: S64): *U8
return result
print :: (string: String, args: ..)
Print :: (string: String, args: ..)
buffer: [1024]U8
buffer_len: S64
arg_counter := 0
for i := 0, i < length_of(string), i+=1
if string[i] == '%'
assert(arg_counter < length_of(args), "Passing too many [%] to a print lambda")
Assert(arg_counter < length_of(args), "Passing too many [%] to a print lambda")
arg := args[arg_counter++]
if arg.type == S64
@@ -110,6 +110,6 @@ print :: (string: String, args: ..)
p := itoa(value, &itoa_buff[0], 10)
for *p != 0
buffer[buffer_len++] = *p++
else;; assert(false)
else;; Assert(false)
else
buffer[buffer_len++] = string[i]