diff --git a/programs/main.kl b/examples/drawing_to_screen_using_windows_api.kl similarity index 100% rename from programs/main.kl rename to examples/drawing_to_screen_using_windows_api.kl diff --git a/programs/any.kl b/programs/any.kl deleted file mode 100644 index d95c51e..0000000 --- a/programs/any.kl +++ /dev/null @@ -1,70 +0,0 @@ -#import "os_windows.kl" - -main :: (argc: int, argv: **char): int - test_any() - test_arrays() - test_type() - -test_array_any :: (any: Any, array_of_any: ..) - for array_of_any - pass - -test_any :: () - some_int_value := 10 - thing: Any = some_int_value - other_any: Any = thing - imp_any := thing - assert(thing.type != Any) - any_array := []Any{some_int_value, thing} - for any_array - assert(it.type == S64) - -test_arrays :: () - array1 := []S64{1,2,3,4,5} - array2: []S64 = {0,9,8} - array4 := [][]S64{[]S64{5,6},[]S64{4,3},[]S64{2,3}} - array5 := [][]S64{{5,6},{4,3},{2,3}} - for i := 0, i < length_of(array1), i+=1 - assert(i+1 == array1[i]) - array6: []*S64 = {&array1[0]} - - for array1;; *it = 0 - for array2;; *it = 0 - for i := 0, i < length_of(array1), i+=1;; assert(0 == array1[i]) - - print("Thing % %", {30, 20}) - test_array_any(array_of_any = {20, 30}, any = 10) - // test_array_any(10, 20, 30) // @fix - -Some_Struct :: struct - thing: int - -test_type :: () - type1: Type = **[]int - type2 := []*[]*Some_Struct - type3 := Some_Struct - type4 := [32]Some_Struct - type5 := [][32]*Some_Struct - type6 := [][32]*[16][]Some_Struct - - t1 := get_type_info(type1) - assert(t1.kind == Type_Info_Kind.POINTER) - - t2 := get_type_info(type2) - assert(t2.kind == Type_Info_Kind.SLICE) - - t3 := get_type_info(type3) - assert(t3.kind == Type_Info_Kind.STRUCT) - - t4 := get_type_info(type4) - assert(t4.array_size == 32) - assert(t4.kind == Type_Info_Kind.ARRAY) - - t5 := get_type_info(type5) - t51 := get_type_info(t5.base_type) - assert(t51.kind == Type_Info_Kind.ARRAY) - - t6 := get_type_info(type6) - t61 := get_type_info(t6.base_type) - t62 := get_type_info(t61.base_type) - assert(t62.kind == Type_Info_Kind.POINTER) \ No newline at end of file diff --git a/programs/base_test.kl b/programs/base_test.kl deleted file mode 100644 index a8a48da..0000000 --- a/programs/base_test.kl +++ /dev/null @@ -1,9 +0,0 @@ -#import "base.kl" - -main :: (argc: int, argv: **char): int - arena: Arena - arena_init(&arena) - data: *S64 = arena_push_size(&arena, size_of(S64)) - *data = 10 - - arena_release(&arena) diff --git a/programs/enums.kl b/programs/enums.kl deleted file mode 100644 index 82c8293..0000000 --- a/programs/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/programs/euler.kl b/programs/euler.kl deleted file mode 100644 index 05240e4..0000000 --- a/programs/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/programs/globals.kl b/programs/globals.kl deleted file mode 100644 index 92a2f7e..0000000 --- a/programs/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/programs/lambdas.kl b/programs/lambdas.kl deleted file mode 100644 index 9aea6d4..0000000 --- a/programs/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/programs/new_types.kl b/programs/new_types.kl deleted file mode 100644 index 6d8042e..0000000 --- a/programs/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/programs/order1.kl b/programs/order1.kl deleted file mode 100644 index 33cdc9f..0000000 --- a/programs/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/programs/order2.kl b/programs/order2.kl deleted file mode 100644 index 0a5d575..0000000 --- a/programs/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/programs/program.kl b/programs/program.kl deleted file mode 100644 index c2ea5bb..0000000 --- a/programs/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) - diff --git a/programs/vm.kl b/programs/vm.kl deleted file mode 100644 index 9454fe1..0000000 --- a/programs/vm.kl +++ /dev/null @@ -1,10 +0,0 @@ - -global_variable := 10 + 29 - -main :: () - a := 10 + 20 // a := 10 + 20 - b := a + 20 - return - -thing :: () - b := 20 \ No newline at end of file