fixing compiler bugs

This commit is contained in:
Krzosa Karol
2022-06-17 10:35:05 +02:00
parent 6696fd80f0
commit ae62b6933e
9 changed files with 54 additions and 12 deletions

View File

@@ -1,9 +1,17 @@
Os :: #import "os.kl"
SizeU :: #strict U64
arena_di: U64
ALLOCATOR_ACTION :: enum
ALLOCATE
RESIZE
FREE_ALL
Allocator :: struct
proc: (a: *Allocator, action: ALLOCATOR_ACTION, size: SizeU, old_pointer: *void): *void
Arena :: struct
allocator: Allocator
di: U64 // @debug_id
memory: Os.Memory
alignment: U64
@@ -33,6 +41,7 @@ arena_init :: (a: *Arena)
a.memory = Os.reserve(a.DEFAULT_RESERVE_SIZE)
a.alignment = a.DEFAULT_ALIGNMENT
a.di = arena_di++
a.allocator.proc = arena_allocator_proc
arena_push_size :: (a: *Arena, size: SizeU): *void
generous_size := size + a.alignment
@@ -47,3 +56,21 @@ arena_push_size :: (a: *Arena, size: SizeU): *void
a.len += size
return result
arena_release :: (a: *Arena)
Os.release(&a.memory)
arena_allocator_proc :: (a: *Allocator, action: ALLOCATOR_ACTION, size: SizeU, old_pointer: *void): *void
arena: *Arena = a->*Arena
if action == ALLOCATOR_ACTION.ALLOCATE
return arena_push_size(arena, size)
elif action == ALLOCATOR_ACTION.RESIZE
pass
elif action == ALLOCATOR_ACTION.FREE_ALL
pass
else;; assert(false, "Invalid codepath")
return 0
allocate :: (a: *Allocator, size: SizeU): *void
return a.proc(a, ALLOCATOR_ACTION.ALLOCATE, size, 0)

View File

@@ -3,4 +3,7 @@
main :: (argc: int, argv: **char): int
arena: Arena
arena_init(&arena)
data: *S64 = arena_push_size(&arena, size_of(S64))
data: *S64 = arena_push_size(&arena, size_of(S64))
*data = 10
arena_release(&arena)

View File

@@ -1,4 +1,4 @@
#load "Windows.kl"
#import "Windows.kl"
RBGQUAD :: struct;; rgbBlue: BYTE; rgbGreen: BYTE; rgbRed: BYTE; rgbReserved: BYTE
BITMAPINFOHEADER :: struct;; biSize: DWORD; biWidth: LONG; biHeight: LONG; biPlanes: WORD; biBitCount: WORD; biCompression: DWORD; biSizeImage: DWORD; biXPelsPerMeter: LONG; biYPelsPerMeter: LONG; biClrUsed: DWORD; biClrImportant: DWORD
BITMAPINFO :: struct;; bmiHeader: BITMAPINFOHEADER; bmiColors: [1]RBGQUAD

View File

@@ -1,7 +1,8 @@
// #import "base.kl"
#load "gdi32.kl"
#load "user32.kl"
#load "os.kl"
#import "base.kl"
#import "gdi32.kl"
#import "user32.kl"
#import "os.kl"
#import "Windows.kl"
question_mark16 :: 0x003f
String32 :: struct;; str: *U32; len: S64

View File

@@ -1,4 +1,4 @@
#load "Windows.kl"
#import "Windows.kl"
WNDPROC :: (hwnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM): LRESULT
WNDCLASSW :: struct;; style: UINT; lpfnWndProc: WNDPROC; cbClsExtra: int; cbWndExtra: int; hInstance: HINSTANCE; hIcon: HICON; hCursor: HCURSOR; hbrBackground: HBRUSH; lpszMenuName: LPCWSTR; lpszClassName: LPCWSTR
MSG :: struct;; hwnd: HWND; message: UINT; wParam: WPARAM; lParam: LPARAM; time: DWORD; pt: POINT; lPrivate: DWORD