diff --git a/examples/language_basics.kl b/examples/language_basics.kl new file mode 100644 index 0000000..f0ddf2e --- /dev/null +++ b/examples/language_basics.kl @@ -0,0 +1,43 @@ + +main :: (): int + // Language has a bunch of standard builtin types: + // Signed integer types = S64, S32, S16, S8, int + // Unsigned integer types = U64, U32, U16, U8, + // Floating point types = F64, F32 + // String type = String + // Character type for compatibility with C = char + + // This is how we can assign variables + // There is no need for prefixes, compiler figures + // out the format by itself + signed_variable: S32 = 10 + unsigned_variable: U32 = 10 + + // We can also tell the compiler to infer the type + this_is_s64_by_default := 10 + this_is_f64_by_default := 10.1251 + this_is_string_by_default := "Thing" + + // Reassigning values is exactly like in other languages + this_is_s64_by_default = 20 + this_is_string_by_default = "Other_Thing" + 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) + + // There are also constant bindings in the language. + // You can bind all sorts of constants to names this way. + INT_VALUE :: 10 + FLOAT_VALUE :: 124.125 + + // For constants we can mix and match different types + COMBINE_VALUE :: INT_VALUE + FLOAT_VALUE + + // When it comes to runtime variables it's a bit different + // To do this we need a cast + combining_types := this_is_s64_by_default->F64 + this_is_f64_by_default + combining_s64_and_s32 := signed_variable->S64 + this_is_s64_by_default + + diff --git a/main.cpp b/main.cpp index 575341b..306d923 100644 --- a/main.cpp +++ b/main.cpp @@ -225,7 +225,7 @@ int main(int argument_count, char **arguments){ Scratch scratch; Array examples = os_list_dir(scratch, "examples"_s); - compile_file("examples/order_independent_declarations.kl"_s, COMPILE_AND_RUN); + compile_file("examples/language_basics.kl"_s, COMPILE_AND_RUN); // For(examples){ // if(it.is_directory) continue; // compile_file(it.absolute_path, COMPILE_AND_RUN);