From 14732048600fdc63f75f8c3cad3ef42b0cbec565 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sat, 1 Oct 2022 14:31:46 +0200 Subject: [PATCH] Constant expressions --- examples/constant_expressions.core | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 examples/constant_expressions.core diff --git a/examples/constant_expressions.core b/examples/constant_expressions.core new file mode 100644 index 0000000..5d867d5 --- /dev/null +++ b/examples/constant_expressions.core @@ -0,0 +1,38 @@ +// We can bind module to a name +M :: #import "Multimedia.core" + +// We can bind a struct to a name +Mu :: M.Mu + +// We can bind a lambda to a name +Start :: M.StartMultimedia + +// Other example of binding a lambda to a name +SomeOtherLambda :: () ;; pass +AliasOf :: SomeOtherLambda + +// We can bind a simple type to name, this type is +// exactly the same as int, typechecker doesn't complain +NewInt :: int + +// We can force it to complain using a '#strict' directive +// this makes a new type that requires casting, good for ids +// and stuff like that, normal int operations still work! +StrictInt :: #strict int + +SomeStruct :: struct ;; a: int +StructAlias :: SomeStruct + + +main :: (): int + some_struct: SomeStruct = {a = 10} + struct_alias: StructAlias = some_struct + Assert(struct_alias.a == 10) + + #Assert(SomeStruct == StructAlias) + #Assert(NewInt == int) + #Assert(StrictInt != int) + + mu: Mu = Start(x = 1280, y = 720) + Assert(mu.x == 1280 && mu.y == 720) + return 0 \ No newline at end of file