From b232b9d5ea23fdd4d53f8e93cdfeb1f962811331 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Tue, 29 Nov 2016 22:08:48 +0000 Subject: Basic `when` statement - Compile time if statement This is similar to an #if in C but handled during the semantic checking stage. --- code/demo.odin | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'code') 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 } + -- cgit v1.2.3