From 1c3531d4da2e2f56bf09c38a756a8c5f7c615b80 Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Thu, 20 Mar 2025 15:23:42 +0100 Subject: il: add static slice allocation example --- cmd/il.ha | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/il.ha b/cmd/il.ha index fc5bd40..afc1ee5 100644 --- a/cmd/il.ha +++ b/cmd/il.ha @@ -10,11 +10,26 @@ use io; export fn main() void = { const scanner = bufio::newscanner(os::stdin); defer bufio::finish(&scanner); + let items: []str = []; for (let line: const str => bufio::scan_line(&scanner)!) { append(items, strings::dup(line)); }; defer strings::freeall(items); + + // static slice allocation + //let buf: [1024]str = [""...]; + //let items = buf[..0]; + //for (let line: const str => bufio::scan_line(&scanner)!) { + // match (static append(items, strings::dup(line))) { + // case void => + // void; + // case nomem => + // fmt::fatal("Error: too many items"); + // }; + //}; + //defer for (let s .. items) free(s); + const state = tui::init()!; defer tui::finish(&state); let li = list::newscrolllist( -- cgit v1.2.3