Language basics

This commit is contained in:
Krzosa Karol
2022-07-28 14:16:42 +02:00
parent 93f984bd96
commit ed4eac0285
2 changed files with 44 additions and 1 deletions

View File

@@ -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

View File

@@ -225,7 +225,7 @@ int main(int argument_count, char **arguments){
Scratch scratch; Scratch scratch;
Array<OS_File_Info> examples = os_list_dir(scratch, "examples"_s); Array<OS_File_Info> 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){ // For(examples){
// if(it.is_directory) continue; // if(it.is_directory) continue;
// compile_file(it.absolute_path, COMPILE_AND_RUN); // compile_file(it.absolute_path, COMPILE_AND_RUN);