From e72a2b8e778fff230848769643a125ae995fbe58 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 3 Feb 2017 16:30:40 +0100 Subject: Add array indexing (not writing yet, though...) --- nl/string_index.nl | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'nl') diff --git a/nl/string_index.nl b/nl/string_index.nl index deb4188..55bbc08 100644 --- a/nl/string_index.nl +++ b/nl/string_index.nl @@ -1,15 +1,44 @@ extern func void(i32) putchar; extern func u64(ptr(i8)) strlen; +extern func ptr(i8)(u64) malloc; + +void printnum(i32 n) { + if (n < 0) { + putchar('-'); + n = -n; + } + if (n == 0) { + putchar('0'); + return; + } + while (n > 0) { + putchar('0' + n % 10); + n = n / 10; + } +} i32 main() { ptr(i8) s = "kaas"; - ptr(i8) orig = s; - s = s + strlen(s) - 1; i32 i = 0; - while (i < strlen(orig)) { - putchar(*(s - i)); + while (i < cast(i32)(strlen(s))) { + putchar(s[i]); i = i + 1; } putchar('\n'); + + /*ptr(i32) arr = cast(ptr(i32))(malloc(4U*16U)); + arr[0] = 1; + arr[1] = 1; + i32 i = 2; + while (i < 16) { + arr[i] = arr[i-2] + arr[i-1]; + i = i + 1; + } + i = 0; + while (i < 16) { + printnum(arr[i]); + putchar(' '); + } + putchar('\n');*/ return 0; } -- cgit v1.2.3-70-g09d2