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

@@ -15,15 +15,15 @@ main :: (): int
static_array: [8]int
// We can get size of array using length_of builtin
#assert(length_of(static_array) == 8)
#Assert(length_of(static_array) == 8)
// Accessing values is like in C
// Variables are zeroed by default
assert(static_array[1] == 0)
Assert(static_array[1] == 0)
element2 := static_array[2]
element0: int = static_array[0]
assert(element0 == 0 && element2 == 0)
Assert(element0 == 0 && element2 == 0)
// We can loop through arrays
// this implicitly defines 'it' variable
@@ -31,16 +31,16 @@ main :: (): int
*it = 1
// We set all variables to 1 so
assert(static_array[6] == 1)
Assert(static_array[6] == 1)
// This is how slice is defined, no [] index in between brackets
// slice is array pointer + length
// Other then that it works exactly like regular array
slice: []int = static_array
// We can't do a compile time assert anymore
assert(length_of(slice) == 8)
assert(slice[4] == 1)
// We can't do a compile time Assert anymore
Assert(length_of(slice) == 8)
Assert(slice[4] == 1)
// After we loop and reassign slice values
// old static_array gets changed
@@ -50,4 +50,4 @@ main :: (): int
// example in a single line
for slice;; *it = 2
assert(static_array[2] == 2)
Assert(static_array[2] == 2)

View File

@@ -1,4 +1,5 @@
#import "base.kl"
Arena :: #import "arena.kl"
#import "os_windows.kl"
#import "kernel32.kl"
#import "gdi32.kl"
@@ -18,7 +19,7 @@ Bitmap :: struct
size: Vec2I
data: *U32
create_bitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap
CreateBitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap
result: Windows_Bitmap = {size = size}
if bottom_up == false
result.size.y = -result.size.y
@@ -42,11 +43,11 @@ create_bitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap
return result
app_is_running := true
window_procedure :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT
AppIsRunning := true
WindowProc :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT
if msg == WM_DESTROY
PostQuitMessage(0)
app_is_running = false
AppIsRunning = false
return 0
else;; return DefWindowProcW(hwnd, msg, wparam, lparam)
@@ -54,15 +55,15 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
if good_scheduling := false, timeBeginPeriod(1) == TIMERR_NOERROR
good_scheduling = true
arena: Arena
arena: Arena.Arena
window_name := string_to_string16(&arena, "Have a wonderful day! 豈 更 車 賈 滑 串 句 龜 ")
window_name := StringToString16(&arena, "Have a wonderful day! 豈 更 車 賈 滑 串 句 龜 ")
w := WNDCLASSW{
lpfnWndProc = window_procedure,
lpfnWndProc = WindowProc,
hInstance = hInstance,
lpszClassName = window_name.str,
}
assert(RegisterClassW(&w) != 0)
Assert(RegisterClassW(&w) != 0)
screen_size: Vec2I = {1280, 720}
window := CreateWindowExW(
@@ -73,17 +74,17 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
dwStyle = WS_OVERLAPPEDWINDOW,
hInstance = hInstance
)
assert(window != 0)
Assert(window != 0)
ShowWindow(window, nShowCmd)
window_dc := GetDC(window)
bitmap := create_bitmap(screen_size)
bitmap := CreateBitmap(screen_size)
requested_time_per_frame := 1.0 / 60.0
frame_start_time := time()
frame_start_time := Time()
frame_number: S64
total_time: F64
for app_is_running
for AppIsRunning
msg: MSG
for PeekMessageW(&msg, window, 0, 0, PM_REMOVE) > 0
TranslateMessage(&msg)
@@ -97,7 +98,7 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
BitBlt(window_dc, 0, 0, (bitmap.size.x)->int, (bitmap.size.y)->int, bitmap.hdc, 0, 0, SRCCOPY)
frame_time := time() - frame_start_time
frame_time := Time() - frame_start_time
if frame_time < requested_time_per_frame
if good_scheduling
time_to_sleep := (requested_time_per_frame - frame_time) * 1000
@@ -106,9 +107,9 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
// @check if time_to_sleep_dword truncates down
Sleep(time_to_sleep_dword)
new_frame_time := time()
new_frame_time := Time()
for new_frame_time < requested_time_per_frame
new_frame_time = time() - frame_start_time
new_frame_time = Time() - frame_start_time
frame_time = new_frame_time
frame_number += 1

View File

@@ -21,10 +21,10 @@ main :: (): int
string_val: String = "String type"
cstring_val: *char = "CString type"
assert(s64val == 0 && s32val == 0 && s16val == 0 && s8val == 0 && intval == 0 && u64val == 0 && u32val == 0 && u16val == 0 && u8val == 0 && f64val == 0 && f32val == 0)
Assert(s64val == 0 && s32val == 0 && s16val == 0 && s8val == 0 && intval == 0 && u64val == 0 && u32val == 0 && u16val == 0 && u8val == 0 && f64val == 0 && f32val == 0)
// @todo: Fix error here !!
// assert(string_val[0] == 'S) //'
assert(cstring_val[0] == 'C')
// Assert(string_val[0] == 'S) //'
Assert(cstring_val[0] == 'C')
// This is how we can assign variables
// There is no need for prefixes, compiler figures
@@ -43,8 +43,8 @@ main :: (): int
this_is_f64_by_default = 15.1255
// @todo: Add type_of operator!!!
// assert(type_of(this_is_string_by_default) == String)
// assert(type_of(this_is_s64_by_default) == S64)
// Assert(type_of(this_is_string_by_default) == String)
// Assert(type_of(this_is_s64_by_default) == S64)
// There are also constant bindings in the language.
// You can bind all sorts of constants to names this way.
@@ -59,8 +59,8 @@ main :: (): int
combining_types := this_is_s64_by_default->F64 + this_is_f64_by_default
assert(signed_variable == 10 && unsigned_variable == 10)
assert(INT_VALUE == 10)
assert(FLOAT_VALUE == 124.125)
assert(this_is_f64_by_default == 15.1255)
assert(combining_types == 15.1255 + 20)
Assert(signed_variable == 10 && unsigned_variable == 10)
Assert(INT_VALUE == 10)
Assert(FLOAT_VALUE == 124.125)
Assert(this_is_f64_by_default == 15.1255)
Assert(combining_types == 15.1255 + 20)

View File

@@ -16,10 +16,10 @@ main :: (): int
if type_info.type == S64
// We can use size_of and align_of operators
// to figure out the type alignment and it's size
assert(type_info.size == size_of(S64))
assert(type_info.align == align_of(S64))
Assert(type_info.size == size_of(S64))
Assert(type_info.align == align_of(S64))
else;; assert(false, "We expected S64 here! What a boomer!")
else;; Assert(false, "We expected S64 here! What a boomer!")
//
// @todo: This should work
@@ -41,12 +41,12 @@ main :: (): int
elif any_value.type == int
value: *int = any_value.data
*value = 30
elif any_value.type == char;; assert(false, "No bueno")
elif any_value.type == char;; Assert(false, "No bueno")
assert(value_to_be_wrapped == 20)
Assert(value_to_be_wrapped == 20)
letter := get_first_letter_of_type(value_to_be_wrapped)
assert(letter == 'I')
Assert(letter == 'I')
get_first_letter_of_type :: (a: Any): U8
type_info := get_type_info(a.type)

View File

@@ -1,15 +1,15 @@
main :: (): int
// Types can be evaluated at compile time for equality
#assert(int == int)
#assert(int != char)
#assert(*char == *char)
#Assert(int == int)
#Assert(int != char)
#Assert(*char == *char)
// They can also be evaluated at runtime, they basically get
// replaced with type ids, which are just unique integers assigned
// to each type
assert(int == int)
assert(int != char)
assert(*char == *char)
Assert(int == int)
Assert(int != char)
Assert(*char == *char)
// We can assign types to compile time variable constants
New_Type :: int
@@ -17,19 +17,19 @@ main :: (): int
// This is a loose association
thing: int = 10
new_type_thing: New_Type = thing
#assert(New_Type == int)
#Assert(New_Type == int)
// to force typechecker to treat
// to force typechecker to treat$
// both of these types as different we need to add a #strict directive
Strict_Type :: #strict int
// new_strict_type_thing: Strict_Type = thing // This produces a compile time type error
// But this works
strict_thing: Strict_Type = 10
#assert(Strict_Type != int)
#Assert(Strict_Type != int)
// If we want to use those types together we need to cast
assert(new_type_thing + strict_thing->int != 0)
Assert(new_type_thing + strict_thing->int != 0)
// We can also assign types to runtime variables, there is a special type for that
some_type: Type = int