Files
corelang/examples/dynamic_typing.core
2022-10-09 15:20:53 +02:00

37 lines
857 B
Core

storage: [32]S64
len : S64
"+" :: (a: Any, b: Any): Any
result: Any = storage[len++]
if a.type == S64 && b.type == S64
*(result.data->*S64) = *(a.data->*S64) + *(b.data->*S64)
return result
"+" :: (a: Any, b: S64): Any
result: Any = storage[len++]
if a.type == S64
*(result.data->*S64) = *(a.data->*S64) + b
return result
"==" :: (a: Any, b: S64): Bool
result := false
if a.type == S64
result = *(a.data->*S64) == b
return result
"==" :: (a: Any, b: Any): Bool
result := false
if a.type == S64 && b.type == S64
result = *(a.data->*S64) == *(b.data->*S64)
return result
main :: (): int
a: Any = 10
b: Any = 20
c := a + b
// - [ ] DANGEROUS BUG! &(int64_t){32} creates a new value, we shouldn't do this with variables!!!
// Assert(c.type == S64 && c == 30)
// Assert(a+b+a==c+(5+5))
return 0