aboutsummaryrefslogtreecommitdiff
path: root/code
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2016-11-29 22:08:48 +0000
committerGinger Bill <bill@gingerbill.org>2016-11-29 22:08:48 +0000
commitb232b9d5ea23fdd4d53f8e93cdfeb1f962811331 (patch)
tree6b4fbe56bf1fc7e7929104790cfb05b42b5f4071 /code
parent348bcc3f9a1375ddf24b952fad537b5c84e84053 (diff)
Basic `when` statement - Compile time if statement
This is similar to an #if in C but handled during the semantic checking stage.
Diffstat (limited to 'code')
-rw-r--r--code/demo.odin27
1 files changed, 22 insertions, 5 deletions
diff --git a/code/demo.odin b/code/demo.odin
index c97a37e07..303c3b448 100644
--- a/code/demo.odin
+++ b/code/demo.odin
@@ -1,11 +1,27 @@
-#import "fmt.odin"
+// #import "fmt.odin"
#import "utf8.odin"
+when ODIN_OS == "window" {
+ when ODIN_OS != "window" {
+ } else {
+ MAX :: 64
+ }
+ #import "fmt.odin"
+} else {
+
+}
+
+
main :: proc() {
- MAX :: 64
+ when true {
+ OffsetType :: type int
+ }
+
+ // MAX :: 64
buf: [MAX]rune
backing: [MAX]byte
- offset: int
+ offset: OffsetType
+
msg := "Hello"
count := utf8.rune_count(msg)
@@ -17,16 +33,17 @@ main :: proc() {
s := msg[offset:]
r, len := utf8.decode_rune(s)
runes[count-i-1] = r
- offset += len
+ offset += len as OffsetType
}
offset = 0
for i := 0; i < count; i++ {
data, len := utf8.encode_rune(runes[i])
copy(backing[offset:], data[:len])
- offset += len
+ offset += len as OffsetType
}
reverse := backing[:offset] as string
fmt.println(reverse) // olleH
}
+