From f223086ef3f9cdb3db08c0b67b0660bcb8494649 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Tue, 14 Jun 2022 14:28:21 +0200 Subject: [PATCH] Restructure --- Windows.kl | 40 ------------------- base.kl | 24 ----------- enums.kl | 7 ---- euler.kl | 78 ------------------------------------ globals.kl | 91 ------------------------------------------ lambdas.kl | 64 ------------------------------ main.kl | 9 ----- new_types.kl | 110 --------------------------------------------------- order1.kl | 21 ---------- order2.kl | 69 -------------------------------- os.kl | 44 --------------------- program.kl | 43 -------------------- 12 files changed, 600 deletions(-) delete mode 100644 Windows.kl delete mode 100644 base.kl delete mode 100644 enums.kl delete mode 100644 euler.kl delete mode 100644 globals.kl delete mode 100644 lambdas.kl delete mode 100644 main.kl delete mode 100644 new_types.kl delete mode 100644 order1.kl delete mode 100644 order2.kl delete mode 100644 os.kl delete mode 100644 program.kl diff --git a/Windows.kl b/Windows.kl deleted file mode 100644 index d9b2986..0000000 --- a/Windows.kl +++ /dev/null @@ -1,40 +0,0 @@ -DWORD :: U32 -LPCSTR :: *char -HWND :: *void -HMENU :: *void -HINSTANCE :: *void -LPVOID :: *void -SIZE_T :: U64 -BOOL :: int -HANDLE :: *void -VOID :: void -LPDWORD :: *DWORD - -CreateWindowA :: #foreign (dwExStyle: DWORD, lpClassName: *char, lpWindowName: *char, dwStyle: DWORD, X: int, Y: int, nWidth: int, nHeight: int, hWndParent: HWND, hMenu: HMENU, hInstance: HINSTANCE, lpParam: *void): HWND - - -MEM_COMMIT :: 0x00001000 -MEM_RESERVE :: 0x00002000 -MEM_RESET :: 0x00080000 -MEM_RESET_UNDO :: 0x1000000 - -MEM_DECOMMIT :: 0x00004000 -MEM_RELEASE :: 0x00008000 - -PAGE_NOACCESS :: 1 -PAGE_READONLY :: 2 -PAGE_READWRITE :: 4 -PAGE_WRITECOPY :: 8 -PAGE_EXECUTE :: 0x10 -PAGE_EXECUTE_READ :: 0x20 -PAGE_EXECUTE_READWRITE :: 0x40 -PAGE_EXECUTE_WRITECOPY :: 0x80 - -VirtualAlloc :: #foreign (lpAddress: LPVOID, dwSize: SIZE_T, flAllocationType: DWORD, flProtect: DWORD): LPVOID -VirtualFree :: #foreign (lpAddress: LPVOID, dwSize: SIZE_T, dwFreeType: DWORD): BOOL - -STD_INPUT_HANDLE :: 4294967286//(-10)->DWORD -STD_OUTPUT_HANDLE :: 4294967285//(-11)->DWORD -//STD_ERROR_HANDLE :: (-12)->DWORD -GetStdHandle :: #foreign (nStdHandle: DWORD): HANDLE -WriteConsoleA :: #foreign (hConsoleOutput: HANDLE,lpBuffer: *VOID,nNumberOfCharsToWrite: DWORD,lpNumberOfCharsWritten: LPDWORD,lpReserve: LPVOID): BOOL \ No newline at end of file diff --git a/base.kl b/base.kl deleted file mode 100644 index 458e039..0000000 --- a/base.kl +++ /dev/null @@ -1,24 +0,0 @@ -Os :: #import "os.kl" - -SizeU :: #strict U64 - -Arena :: struct - memory: Os.Memory - alignment: U64 - len: U64 - -clamp_top_sizeu :: (val: SizeU, max: SizeU): SizeU - if val > max - return max - return val - -get_align_offset :: (size: SizeU, align: SizeU): SizeU - mask := align - 1 - val := size & mask - if val != 0 - val = align - val - return val - -align_up :: (size: SizeU, align: SizeU): SizeU - result := size + get_align_offset(size, align) - return result diff --git a/enums.kl b/enums.kl deleted file mode 100644 index 82c8293..0000000 --- a/enums.kl +++ /dev/null @@ -1,7 +0,0 @@ -Allocator_Kind :: enum #flag - Null; Arena; Heap - -kind := Allocator_Kind.Heap - -basic_type_assignment :: () // This works - return \ No newline at end of file diff --git a/euler.kl b/euler.kl deleted file mode 100644 index 05240e4..0000000 --- a/euler.kl +++ /dev/null @@ -1,78 +0,0 @@ -// @todo: Add more stats in the preview -// @todo: for 0..1000(implicit i) and for i in 0..1000 -// @todo: Add blocks of stmts that you can simply define inside a function etc. - -entry :: () - print_str("\n") - euler1() - euler3() - -//----------------------------------------------------------------------------- -// Euler 2 -//----------------------------------------------------------------------------- -euler1 :: () - end := 1000 - result := 0 - for i := 0, i < end, i++ - if i % 3 == 0 - result += i - else if i % 5 == 0 - result += i - print_str("Euler1: ") - print_int(result) - print_str("\n") - - -//----------------------------------------------------------------------------- -// Euler 3 -//----------------------------------------------------------------------------- -int_sqrt :: (s: S64): S64 - result := sqrt(cast(s: F64)) - return cast(result: S64) - -// https://en.wikipedia.org/wiki/Integer_square_root -int_sqrt1 :: (s: S64): S64 - x0 := s / 2 - - if x0 != 0 - x1 := (x0 + s / x0) / 2 - for x1 < x0 - x0 = x1 - x1 = (x0 + s / x0) / 2 - return x0 - else - return s - -euler3 :: () - n := 600851475143 - results: [32]S64 - results_len := 0 - - // First search all 2's - for n % 2 == 0 - results[results_len++] = 2 - n /= 2 - - // Then search other primes, 3, 5, 7 etc. - for i := 3, i <= int_sqrt1(n), i += 2 - for n % i == 0 - results[results_len++] = i - n /= i - - // Then check if our number is a prime it self - if n > 2 - results[results_len++] = n - - print_str("Euler3: ") - - is_correct: S64 = 1 - for i := 0, i < results_len, i++ - is_correct = is_correct * results[i] - print_int(is_correct) - - print_str(":: ") - print_int(is_correct) - -sqrt :: (v: F64): F64 #foreign -print_int :: (i: S64) #foreign -print_str :: (i: String) #foreign \ No newline at end of file diff --git a/globals.kl b/globals.kl deleted file mode 100644 index 92a2f7e..0000000 --- a/globals.kl +++ /dev/null @@ -1,91 +0,0 @@ -lambdas :: #load "lambdas.kl" -Memory :: #load "enums.kl" -#load "lambdas.kl" -#load "lambdas.kl" -#import "order1.kl" -#import "order1.kl" -order :: #import "order1.kl" - - - -test_load :: () - new_types :: #load "new_types.kl" - new_types.basic_type_assignment() - arena__: order2.Arena - Arena_ :: order.order2.Arena - arena___: Arena_ -//----------------------------------------------------------------------------- -// Function types -//----------------------------------------------------------------------------- -test_function :: (thing: S64): *S64 -function_type: test_function -const_function_alias :: test_function -// null_function: (t: S64): *S64 = null - -//----------------------------------------------------------------------------- -// Booleans -//----------------------------------------------------------------------------- -Boolean: Bool = true - -//----------------------------------------------------------------------------- -// Nulls -//----------------------------------------------------------------------------- -// int_null: S64 = null -// str_null: String = null -// Bool_null: Bool = null - -//----------------------------------------------------------------------------- -// Compound expressions -//----------------------------------------------------------------------------- -array1: [4]S64 = {1,2,3,4} -imp_array := [5]S64{1,2} -// imp_array_a := [5]S64{1,2,3,4,5,6} -// imp_array_b: [5]S64 = {1,2,3,4,5,6} -imp_array_c: [5]S64 = {[0] = 1, [2] = 2, [1] = 0} // @todo this should be illegal -// without_size: []S64 = {} // @todo: this should be slice, converting from array should be implicit - -string: *char = "string" -first_letter := string[0] -decl_char: char = 55 - -//----------------------------------------------------------------------------- -// Pointers -//----------------------------------------------------------------------------- -pointer_decl : *S64 -variable_from_deref: S64 = *pointer_decl -pointer_from_var : *S64 = &variable_from_deref -Boolean_pointer := &Boolean - -//----------------------------------------------------------------------------- -// Implicit type -//----------------------------------------------------------------------------- -implicit_int :: 10 -implicit_str :: "Hello world" - -//----------------------------------------------------------------------------- -// Pointers -//----------------------------------------------------------------------------- -// pointer1: *S64 = 0 -// pointer2: *S64 = pointer1 -// pointer3: **S64 = 0 - -//----------------------------------------------------------------------------- -// String types -//----------------------------------------------------------------------------- -string1 :: "Test" -string2 :: string1 - -//----------------------------------------------------------------------------- -// Constant S64 variables -//----------------------------------------------------------------------------- -thing0 :: 10 -thing4 :: thing0 + 11 -thing3 :: thing4 + 20 -combin :: thing0 + thing4 + thing3 - -Some :: struct - len: S64 - cap: S64 - -some := Some{3, 2} -other := Some{len = 1, cap = 3} \ No newline at end of file diff --git a/lambdas.kl b/lambdas.kl deleted file mode 100644 index 9aea6d4..0000000 --- a/lambdas.kl +++ /dev/null @@ -1,64 +0,0 @@ -Test :: struct - len: S64 - - -test: Test -member := test.len - -enum_val: Memory.Allocator_Kind = Memory.Allocator_Kind.Heap -other_enum_val: S64 = enum_val->S64 - -a_type :: S64 -pointer_type :: *S64 -// null_pointer: pointer_type = null - -if_stmt :: (cond: S64): type - CONSTANT :: 10 - thing := 10 - if i := thing + cond, cond > CONSTANT - return i + CONSTANT - else if cond < CONSTANT - return i - CONSTANT - else - return CONSTANT - - -for_stmt :: () - for i := 0, i < 10, i+=1 - out_of_order_resolving() - -out_of_order_resolving :: () - i := 10 - -add_10 :: (size: S64): S64 - add_20 :: (new_size: S64): S64 - return 20 - - add :: (a: S64, b: S64 = 10): S64 - return a + b - - constant :: 20; result := constant + 10 - - v3 := add(1,2) - // v2 := add(a = 1, b = 2) - // v1 := add(a = 1) - // // v_err := add([0] = 1) - // v4 := add(b = 1, a = 2) - // // v_err := add([0] = 1, [1] = 2) - // // v_err := add([0] = 1, 10) // illegal - // // v_err := add([1] = 1) // illegal - // // v_err := add() // illegal - v4 := constant - return v4 - -return_constant :: (): S64 - constant :: 10 - return constant - -returning_void :: (insert: S64) - // val1: S64 = return_constant() - // val2: S64 = add_10(val1) - return - - -type :: a_type \ No newline at end of file diff --git a/main.kl b/main.kl deleted file mode 100644 index 3a91ce3..0000000 --- a/main.kl +++ /dev/null @@ -1,9 +0,0 @@ -#import "base.kl" -os :: #import "os.kl" - -main :: (argc: int, argv: **char): int - memory := os.reserve(size = 10000) - os.commit(&memory, 1000) - os.release(&memory) - os.print("Hello world") - diff --git a/new_types.kl b/new_types.kl deleted file mode 100644 index 6d8042e..0000000 --- a/new_types.kl +++ /dev/null @@ -1,110 +0,0 @@ - -unary_test :: () - int_val :: 141 - float_val :: 124.42 - conversion: F64 = -+int_val - float2 := -float_val - unsigned: S64 = -+-+-int_val - - not: Bool = !int_val - notf := !float_val - notb := !true - neg64: S64 = ~int_val - neg32: S32 = ~int_val - big_neg32: U32 = ~41512512->U32 - - var1: S64 - var2: S64 = 20 - var_bool: Bool = !var1 == !var2 - - pointer: *S64 - pointer += 10 - // pointer = pointer + pointer - - // uns: U64 = -int_val - // int_float: S64 = float_val - // string :: -"Thing" - // boolean :: -true - // var := -true - // var := +true - -// @note: Poggers -big_number1 :: 12512512512512521524242 -big_number2 :: 12512512512512521524242 -big_number3 :: 12512512512512521524242 -big_number4 :: 12512512512512521524242 -big_number5 :: 12512512512512521524242 + big_number1 * big_number1 -binary_test :: (thing: S32 = 442) - int_val :: 1000 - add :: int_val + 10 + 2.242 + 124 - mul :: 4 * 2 - bit_and :: 3 & 1 - bit_or :: 1 | 4 - bit_xor :: 8 ^ 7 - character :: 'รณ - -// ' - - boolean_equals :: true == false - boolean_var: Bool = boolean_equals - - cast_value :: 4242 + 32->S32 + 42->S32 - value: S32 = cast_value - - bvar2 := int_val > 1 - if int_val < 1 - if int_val > 1 - pass - -basic_type_assignment :: () - // custom_data1 := Custom_Data(thing = 23) - // custom_data2: Custom_Data - some_constant :: true - thing: Bool = some_constant - float_val :: 325.42 - float_var := float_val - - -for_loops :: () - for thing2 := 10 - pass - for thing1 := 10,,thing1+=1 - pass - for - pass - for i := 0, i == 4, i+=1 - pass - for j:=0, j < 10 - pass - -/* -Custom_Data :: struct - thing: S32 - -get_element_item :: (array: []Custom_Data, index: S64): Custom_Data - if index < array.len - return array[index] - else - return Custom_Data() - -get_element_pointer :: (array: []Custom_Data, index: S64): *Custom_Data - if index < array.len - return &array[index] - else - return 0 - -get_slice_len :: (array: []Custom_Data): S64 - return array.len - -array_test :: () - thing := []Custom_Data(Custom_Data(1), Custom_Data(2)) - reference := thing - length := reference.len - - item := get_element_item(thing, 1) - pointer := get_element_pointer(thing, 0) - len := get_slice_len(thing) - - with_size: [2]Custom_Data -*/ - // get_slice_len(with_size) \ No newline at end of file diff --git a/order1.kl b/order1.kl deleted file mode 100644 index 33cdc9f..0000000 --- a/order1.kl +++ /dev/null @@ -1,21 +0,0 @@ -order2 :: #load "order2.kl" - -recursive_lambda :: (thing: S64) - in_val := recursive_lambda - some_value := thing + const_in_lambda - -other_func :: () - a_val := recursive_lambda - -const_in_lambda :: 10 - -not_const := val + 10 -val := CONSTANT_VAL - -DEPENDENCE :: CONSTANT_VAL -CONSTANT_VAL :: 10 - -global_thing: a_type = 10 - -arena: *order2.Arena -order1_arena: order2.Arena diff --git a/order2.kl b/order2.kl deleted file mode 100644 index 0a5d575..0000000 --- a/order2.kl +++ /dev/null @@ -1,69 +0,0 @@ - -Str16 :: String16 -arena_pointer: *Arena = 0 -order2_arena: Arena -no_type := order2_arena - -Arena :: struct - next: *Arena - data: *S64 - len : S64 - cap : S64 - -string16: Str16 - -String16 :: struct - data: *void - len : S64 - -thing := arena_pointer.len -with_type: Arena = order2_arena -test_dot := with_type.len -pointer := &with_type -deref := *pointer - - -test_assignments :: () - i := 0 - i += 4 - i -= 1 - i *= 2 - i /= 2 - i %= 2 - i = 2 - i &= 2 - i |= 2 - i >>= 2 - i <<= 2 - - boolean := i > 2 - CONST :: 23 == 23 - CONST_FLOAT :: 23.52 - - j: *S64 - *j = 1 - /* invalid - 8 = 32 - i + 4 = 32 - i += "String" - - */ - - -/* -for - pass -for i:=0, i < 10, i+=1 - pass -for array - pass -for it in array - pass -for it,i in array - pass -for i in 0..10 - pass - - - -*/ \ No newline at end of file diff --git a/os.kl b/os.kl deleted file mode 100644 index 14f0f62..0000000 --- a/os.kl +++ /dev/null @@ -1,44 +0,0 @@ -#import "Windows.kl" -#import "base.kl" - -PAGE_SIZE :: 4096 -Memory :: struct - commit : SizeU - reserve: SizeU - data : *U8 - -reserve :: (size: SizeU): Memory - result := Memory{reserve=align_up(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 := align_up(size, 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 := VirtualAlloc( - lpAddress = (m.data + m.commit)->*void, - dwSize = adjusted_commit, - flAllocationType = MEM_COMMIT, - flProtect = PAGE_READWRITE, - ) - 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 - -print :: (string: String) - handle := GetStdHandle(STD_OUTPUT_HANDLE) - WriteConsoleA(handle, &string[0]->*void, length_of(string)->DWORD, 0, 0) diff --git a/program.kl b/program.kl deleted file mode 100644 index c2ea5bb..0000000 --- a/program.kl +++ /dev/null @@ -1,43 +0,0 @@ -#foreign printf :: (str: String, ...) - -Token :: struct - kind: U8 - str: *U8 - len: S64 - - Kind :: enum - Number - - -kind_name :: (kind: U8): String - if kind == Token.Kind.Number - return "" - else - return "" - -is_numeric :: (c: U8): Bool - result := c >= '0 && c <= '9 - return result - -print_tokens :: (tokens: []Token) - for i := 0, i < tokens.len, i++ - t := &tokens[i] - printf("%d. %.*s", i, cast(t.len: S32), t.str) - -entry :: () - string_to_lex := "Identifier 2425525 Not_Number" - token_array: [32]Token - token_count: S64 = 0 - - t: Token - for i := 0, i < string_to_lex.len, i+=1 - if is_numeric(string_to_lex.str[i]) - t.kind = Token.Kind.Number - t.str = &string_to_lex.str[i] - t.len = i - for is_numeric(string_to_lex.str[i]) - i+=1 - t.len = i - t.len - token_array[token_count++] = t - print_tokens(token_array) -