Emitting proper lines and files, coding in the language!

This commit is contained in:
Krzosa Karol
2022-06-14 14:15:21 +02:00
parent f885abe3f5
commit d63a327e3e
5 changed files with 62 additions and 49 deletions

39
base.kl
View File

@@ -1,18 +1,11 @@
Windows :: #import "Windows.kl"
#import "Windows.kl"
Os :: #import "os.kl"
SizeU :: #strict U64
OS_PAGE_SIZE :: 4096
OS_Memory :: struct
commit : SizeU
reserve: SizeU
data : *U8
Arena :: struct
memory: OS_Memory
memory: Os.Memory
alignment: U64
len: SizeU
len: U64
clamp_top_sizeu :: (val: SizeU, max: SizeU): SizeU
if val > max
@@ -29,29 +22,3 @@ get_align_offset :: (size: SizeU, align: SizeU): SizeU
align_up :: (size: SizeU, align: SizeU): SizeU
result := size + get_align_offset(size, align)
return result
reserve :: (size: SizeU): OS_Memory
result := OS_Memory{reserve=align_up(size, OS_PAGE_SIZE)}
result.data = Windows.VirtualAlloc(
flProtect = Windows.PAGE_READWRITE,
dwSize = result.reserve,
flAllocationType = Windows.MEM_RESERVE,
lpAddress = 0)->*U8
return result
commit :: (m: *OS_Memory, size: SizeU): Bool
commit_size := align_up(size, OS_PAGE_SIZE)
total_commit := m.commit + commit_size
clamped_commit := clamp_top_sizeu(total_commit, m.reserve)
adjusted_commit := clamped_commit - m.commit
if adjusted_commit != 0
result := Windows.VirtualAlloc(
lpAddress = (m.data + m.commit)->*void,
dwSize = adjusted_commit,
flAllocationType = Windows.MEM_COMMIT,
flProtect = Windows.PAGE_READWRITE,
)
m.commit += adjusted_commit
return true
return false