hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit c78635712a723f4b6fef8656bc3ddc4f1ebdc900
parent 2515998ad482de05f14a081329135c4828cbc4b8
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon,  1 Apr 2024 16:18:26 +0200

debug: updates per for-each support

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mdebug/+aarch64/walk.ha | 6+++---
Mdebug/+riscv64/walk.ha | 8++++----
Mdebug/+x86_64/walk.ha | 6+++---
Mdebug/abort.ha | 2+-
Mdebug/backtrace.ha | 5++---
Mdebug/dwarf/abbrev.ha | 6+++---
Mdebug/dwarf/addr_to_line.ha | 11++---------
Mdebug/dwarf/aranges.ha | 9++-------
Mdebug/dwarf/info.ha | 3+--
Mdebug/ident.ha | 7+------
Mdebug/image/sections.ha | 7+++----
11 files changed, 25 insertions(+), 45 deletions(-)

diff --git a/debug/+aarch64/walk.ha b/debug/+aarch64/walk.ha @@ -13,13 +13,13 @@ export type stackframe = struct { export fn walk() stackframe = *getfp(); // Returns the next stack frame walking the stack. -export fn next(frame: stackframe) (stackframe | void) = { +export fn next(frame: stackframe) (stackframe | done) = { match (frame.fp) { case null => - return; + return done; case let next: *stackframe => if (next.fp == null) { - return; + return done; }; return *next; }; diff --git a/debug/+riscv64/walk.ha b/debug/+riscv64/walk.ha @@ -13,13 +13,13 @@ export type stackframe = struct { export fn walk() stackframe = *getfp(); // Returns the next stack frame walking the stack. -export fn next(frame: stackframe) (stackframe | void) = { +export fn next(frame: stackframe) (stackframe | done) = { match (frame.fp) { case null => - return; + return done; case let next: *stackframe => - if (next.fp == null) { - return; + if (next.fp == done) { + return done; }; return *next; }; diff --git a/debug/+x86_64/walk.ha b/debug/+x86_64/walk.ha @@ -13,13 +13,13 @@ export type stackframe = struct { export fn walk() stackframe = *getfp(); // Returns the next stack frame walking the stack. -export fn next(frame: stackframe) (stackframe | void) = { +export fn next(frame: stackframe) (stackframe | done) = { match (frame.fp) { case null => - return; + return done; case let next: *stackframe => if (next.fp == null) { - return; + return done; }; return *next; }; diff --git a/debug/abort.ha b/debug/abort.ha @@ -32,7 +32,7 @@ fn debug_abort( match (next(frame)) { case let next: stackframe => frame = next; - case void => halt(); + case done => halt(); }; }; diff --git a/debug/backtrace.ha b/debug/backtrace.ha @@ -22,8 +22,7 @@ fn backtrace(self: *image::image, frame: stackframe) void = { match (next(frame)) { case let next: stackframe => frame = next; - case void => - break; + case done => break; }; }; frame = orig; @@ -50,7 +49,7 @@ fn backtrace(self: *image::image, frame: stackframe) void = { match (next(frame)) { case let next: stackframe => frame = next; - case void => + case done => break; }; }; diff --git a/debug/dwarf/abbrev.ha b/debug/dwarf/abbrev.ha @@ -104,9 +104,9 @@ export fn abbrev_table_finish(table: *abbrev_table) void = { // Retrieves an abbreviation from an [[abbrev_table]] by its abbreviation code. export fn get_abbrev(table: *abbrev_table, code: u64) const nullable *abbrev = { // TODO: Sort the list and do this faster - for (let i = 0z; i < len(table.items); i += 1) { - if (table.items[i].code == code) { - return &table.items[i]; + for (let item &.. table.items) { + if (item.code == code) { + return item; }; }; return null; diff --git a/debug/dwarf/addr_to_line.ha b/debug/dwarf/addr_to_line.ha @@ -41,8 +41,7 @@ export fn addr_to_line( continue; }; - for (let i = 0z; i < len(entry.fields); i += 1) { - const field = &entry.fields[i]; + for (const field &.. entry.fields) { switch (field.attr) { case DW_AT_stmt_list => stmt_list = field.constant; @@ -63,13 +62,7 @@ export fn addr_to_line( defer line_program_finish(&prog); let last = line_state { ... }; - for (true) { - const state = match (line_next(&prog)?) { - case let state: line_state => - yield state; - case io::EOF => - break; - }; + for (const state => line_next(&prog)?) { defer last = state; if (state.file == 1) { diff --git a/debug/dwarf/aranges.ha b/debug/dwarf/aranges.ha @@ -25,14 +25,9 @@ export fn arange_lookup( return; }; + // Read all arange tables in this section const rd = image::section_reader(image, aranges); - for (true) { - const rd = match (new_table_reader(&rd, true)!) { - case io::EOF => break; - case let rd: table_reader => - yield rd; - }; - + for (const rd => new_table_reader(&rd, true)!) { match (arange_match(&rd, addr)) { case void => void; case let u: u64 => diff --git a/debug/dwarf/info.ha b/debug/dwarf/info.ha @@ -123,8 +123,7 @@ fn read_die( abbrev: *abbrev, ) (entry | io::error) = { let fields: []field = []; - for (let i = 0z; i < len(abbrev.fields); i += 1) { - const abf = &abbrev.fields[i]; + for (const abf &.. abbrev.fields) { let field = field { attr = abf.attr, form = abf.form, diff --git a/debug/ident.ha b/debug/ident.ha @@ -11,12 +11,7 @@ export fn symname_to_ident(name: str) const str = { let slice = buf[..0]; const iter = strings::iter(name); - for (true) { - const rn = match (strings::next(&iter)) { - case let rn: rune => - yield rn; - case => break; - }; + for (const rn => strings::next(&iter)) { if (rn == '.') { static append(slice, ':'); static append(slice, ':'); diff --git a/debug/image/sections.ha b/debug/image/sections.ha @@ -30,8 +30,7 @@ export fn section_byname( (".debug_line", &image.debug_line), (".debug_str", &image.debug_str), ]; - for (let i = 0z; i < len(cached); i += 1) { - const (cand, val) = cached[i]; + for (const (cand, val) .. cached) { if (cand == name) { match (*val) { case null => break; @@ -61,10 +60,10 @@ export fn section_byname( case null => return null; case let sec: *elf::section64 => - for (let i = 0z; i < len(cached); i += 1) { - const (cand, val) = cached[i]; + for (let (cand, val) .. cached) { if (cand == name) { *val = sec; + break; }; }; };