90 lines
2.3 KiB
Core
90 lines
2.3 KiB
Core
main :: (): int
|
|
// Language has a bunch of standard builtin types:
|
|
// Signed integer types
|
|
s64val: S64 = 0
|
|
s32val: S32 = 0
|
|
s16val: S16 = 0
|
|
s8val : S8 = 0
|
|
intval: int = 0
|
|
|
|
// Unsigned integer types = U64, U32, U16, U8,
|
|
u64val: U64 = 0
|
|
u32val: U32 = 0
|
|
u16val: U16 = 0
|
|
u8val : U8 = 0
|
|
|
|
// Floating point types = F64, F32
|
|
f64val: F64 = 0
|
|
f32val: F32 = 0
|
|
|
|
// String type = String
|
|
string_val: String = "String type"
|
|
cstring_val: *char = "CString type"
|
|
|
|
// 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
|
|
|
|
Assert(s64val == 0 && s32val == 0 && s16val == 0 && s8val == 0 && intval == 0 && u64val == 0 && u32val == 0 && u16val == 0 && u8val == 0 && f64val == 0 && f32val == 0)
|
|
Assert(string_val[0] == 'S')
|
|
Assert(cstring_val[0] == 'C')
|
|
Assert(signed_variable == 10 && unsigned_variable == 10)
|
|
Assert(INT_VALUE == 10)
|
|
Assert(FLOAT_VALUE == 124.125)
|
|
Assert(this_is_f64_by_default == 15.1255)
|
|
Assert(combining_types == 15.1255 + 20)
|
|
|
|
// Compound statements
|
|
data1 := Data{
|
|
a = 1,
|
|
d = 2
|
|
}
|
|
data2: Data = {
|
|
a = 4,
|
|
b = 2,
|
|
}
|
|
Assert(data1.a == 1)
|
|
Assert(data1.b == 0)
|
|
Assert(data1.c == 0)
|
|
Assert(data1.d == 2)
|
|
Assert(data2.a == 4)
|
|
Assert(data2.b == 2)
|
|
Assert(data2.c == 0)
|
|
Assert(data2.d == 0)
|
|
|
|
return 0
|
|
|
|
Data :: struct
|
|
a: S64
|
|
b: S32
|
|
c: S32
|
|
d: S32
|