From 62aaffdb83037f2595d5f90e3606180db176ec3e Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Fri, 14 Oct 2022 07:06:55 +0200 Subject: [PATCH] Working on modules finding bugs --- core_main.cpp | 5 ++- examples/raymarcher.core | 2 +- modules/Arena.core | 2 +- modules/Base.core | 2 +- modules/KERNEL32.core | 30 +++++++++++++++- modules/Windows.core | 65 ----------------------------------- modules/win32_multimedia.core | 2 +- 7 files changed, 37 insertions(+), 71 deletions(-) delete mode 100644 modules/Windows.core diff --git a/core_main.cpp b/core_main.cpp index cbe9394..680bfeb 100644 --- a/core_main.cpp +++ b/core_main.cpp @@ -10,6 +10,10 @@ Fix backlog * a.void[10] - [ ] Test and bulletproof any, slices - [ ] Need tests that make sure stuff errors out +- [ ] String declaration in Language.core this way we can compound create it and access fields and stuff +- [ ] This error is valid error case when someone creates a compound out of basic type C:/AProgramming/cparse/compiler/examples/arms_race/arms_race.core:137 Internal compiler error: Invalid type was passed to the compound expression, should have been an array, struct or slice + result := String{data, filesize} +- [ ] Fix tuple being able to colapse into a single variable Future features @@ -28,7 +32,6 @@ Future features Probably need some UInt Int types and those should be default, target decides the size of these -- [ ] String declaration in Language.core - [ ] Way to import and force evaluate #import_lazy #import ? Redesign: diff --git a/examples/raymarcher.core b/examples/raymarcher.core index f241272..79058c3 100644 --- a/examples/raymarcher.core +++ b/examples/raymarcher.core @@ -94,7 +94,7 @@ Raymarcher_Update :: () #import "Base.core" #import "Arena.core" -#import "Windows.core" +#import "OS$OS.core" #import "KERNEL32.core" #import "GDI32.core" #import "USER32.core" diff --git a/modules/Arena.core b/modules/Arena.core index 8573f1e..665f9a1 100644 --- a/modules/Arena.core +++ b/modules/Arena.core @@ -1,4 +1,4 @@ -OS :: #import "Windows.core" +OS :: #import "OS$OS.core" Base :: #import "Base.core" ArenaDI: U64 diff --git a/modules/Base.core b/modules/Base.core index 0682ec0..f30d94c 100644 --- a/modules/Base.core +++ b/modules/Base.core @@ -1,5 +1,5 @@ #import "Arena.core" -OS :: #import "Windows.core" +OS :: #import "OS$OS.core" SizeU :: U64 ClampTopSizeU :: (val: SizeU, max: SizeU): SizeU diff --git a/modules/KERNEL32.core b/modules/KERNEL32.core index 1abe617..80550e2 100644 --- a/modules/KERNEL32.core +++ b/modules/KERNEL32.core @@ -28,6 +28,8 @@ LONG :: S32 // @todo long UINT :: U32 // @todo uint ATOM :: WORD LARGE_INTEGER :: S64 +PLARGE_INTEGER :: *LARGE_INTEGER +LPOVERLAPPED :: *OVERLAPPED MEM_COMMIT :: 0x00001000 MEM_RESERVE :: 0x00002000 @@ -63,4 +65,30 @@ GetLastError :: #foreign (): DWORD QueryPerformanceFrequency :: #foreign (lpFrequency: *LARGE_INTEGER): BOOL QueryPerformanceCounter :: #foreign (lpFrequency: *LARGE_INTEGER): BOOL Sleep :: #foreign (dwMilliseconds: DWORD) -OutputDebugStringA :: #foreign (lpOutputString: LPCSTR) \ No newline at end of file +OutputDebugStringA :: #foreign (lpOutputString: LPCSTR) + +CreateFileW :: #foreign (lpFileName: LPCWSTR, dwDesiredAccess: DWORD, dwShareMode: DWORD, lpSecurityAttributes: LPSECURITY_ATTRIBUTES, dwCreationDisposition: DWORD, dwFlagsAndAttributes: DWORD, hTemplateFile: HANDLE): HANDLE +ReadFile :: #foreign (hFile: HANDLE, lpBuffer: LPVOID, nNumberOfBytesToRead: DWORD, lpNumberOfBytesRead: LPDWORD, lpOverlapped: LPOVERLAPPED): BOOL +CloseHandle :: #foreign (hObject: HANDLE): BOOL +GetFileSizeEx :: #foreign (hFile: HANDLE, lpFileSize: PLARGE_INTEGER) + +OVERLAPPED :: struct + Internal: ULONG_PTR + InternalHigh: ULONG_PTR + Pointer: PVOID + hEvent: HANDLE + +GENERIC_READ :: 0x80000000 +GENERIC_WRITE :: 0x40000000 +GENERIC_EXECUTE :: 0x20000000 +GENERIC_ALL :: 0x10000000 + +CREATE_NEW :: 1 +CREATE_ALWAYS :: 2 +OPEN_EXISTING :: 3 +OPEN_ALWAYS :: 4 +TRUNCATE_EXISTING :: 5 + +FILE_SHARE_READ :: 0x00000001 +FILE_SHARE_WRITE :: 0x00000002 +FILE_SHARE_DELETE :: 0x00000004 diff --git a/modules/Windows.core b/modules/Windows.core deleted file mode 100644 index 56393cf..0000000 --- a/modules/Windows.core +++ /dev/null @@ -1,65 +0,0 @@ -#import "KERNEL32.core" -#import "Base.core" - -PAGE_SIZE :: 4096 -Memory :: struct - commit : SizeU - reserve: SizeU - data : *U8 - -ProcessHeap: HANDLE -Allocate :: (size: U64): *void - if ProcessHeap == 0 - ProcessHeap = GetProcessHeap() - return HeapAlloc(ProcessHeap, 0, size) - -Reserve :: (size: SizeU): Memory - result := Memory{reserve=AlignUp(size, PAGE_SIZE)} - result.data = VirtualAlloc( - flProtect = PAGE_READWRITE, - dwSize = result.reserve, - flAllocationType = MEM_RESERVE, - lpAddress = 0)->*U8 - return result - -Commit :: (m: *Memory, size: SizeU): Bool - commit_size := AlignUp(size, PAGE_SIZE) - total_commit := m.commit + commit_size - clamped_commit := ClampTopSizeU(total_commit, m.reserve) - adjusted_commit := clamped_commit - m.commit - if adjusted_commit != 0 - result := VirtualAlloc( - lpAddress = (m.data + m.commit)->*void, - dwSize = adjusted_commit, - flAllocationType = MEM_COMMIT, - flProtect = PAGE_READWRITE, - ) - Assert(result != 0) - m.commit += adjusted_commit - return true - return false - -Release :: (m: *Memory) - result := VirtualFree(m.data->*void, 0, MEM_RELEASE) - if result != 0 - m.data = 0 - m.commit = 0 - m.reserve = 0 - -WriteConsole :: (string: String16) - handle := GetStdHandle(STD_OUTPUT_HANDLE) - WriteConsoleW(handle, string.str->*void, string.len->DWORD, 0, 0) - -PerformanceFrequency: F64 -PerformanceFrequency_S64: S64 -Time :: (): F64 - query: LARGE_INTEGER - if PerformanceFrequency_S64 == 0 - err := QueryPerformanceFrequency(&PerformanceFrequency_S64) - Assert(err != 0) - PerformanceFrequency = PerformanceFrequency_S64->F64 - - err := QueryPerformanceCounter(&query) - Assert(err != 0) - result := query->F64 / PerformanceFrequency - return result diff --git a/modules/win32_multimedia.core b/modules/win32_multimedia.core index 1bdf5b8..aca9832 100644 --- a/modules/win32_multimedia.core +++ b/modules/win32_multimedia.core @@ -2,7 +2,7 @@ #import "GDI32.core" #import "USER32.core" #import "WINMM.core" -#import "Windows.core" +#import "OS$OS.core" Platform :: struct bitmap: WIN32_Bitmap