Files
corelang/examples/language_basics.kl
2022-07-28 14:19:48 +02:00

47 lines
1.6 KiB
Plaintext

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
combining_unsigned_with_signed := unsigned_variable->F64 + combining_types
// Silence unused variable warning
assert(combining_s64_and_s32->F64 + combining_unsigned_with_signed > 0)