enums
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
Animal :: enum {
|
||||
dog
|
||||
cat
|
||||
}
|
||||
|
||||
favorite :: func() Animal {
|
||||
return .cat
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
animals :: import "./animals"
|
||||
|
||||
State :: enum(u16) {
|
||||
started = 10
|
||||
running
|
||||
stopped = 20
|
||||
}
|
||||
|
||||
initial State :: State.started
|
||||
|
||||
same :: func(left State, right State) bool {
|
||||
return left == right
|
||||
}
|
||||
|
||||
identity :: c_func(value State) State {
|
||||
return value
|
||||
}
|
||||
|
||||
main :: func() i32 {
|
||||
state State = identity(.running)
|
||||
values [2]State :: [.started, State.stopped]
|
||||
animal animals.Animal :: animals.Animal.dog
|
||||
if same(state, .running) and
|
||||
values[0] != values[1] and
|
||||
animal != animals.favorite() and
|
||||
initial == State.started {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
}
|
||||
Reference in New Issue
Block a user