hare

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

commit b218a528a703c95c7c2337160a72b4b17b6346ff
parent d41710edea3e02878d9410fa3ed4282e7cce963e
Author: Autumn! <autumnull@posteo.net>
Date:   Sat,  6 May 2023 22:30:02 +0000

hare::{lex,parse}: statically allocate syntax error path

Signed-off-by: Autumn! <autumnull@posteo.net>

Diffstat:
Mhare/lex/lex.ha | 8+++++++-
Mhare/parse/parse.ha | 2+-
Mscripts/gen-stdlib | 2+-
Mstdlib.mk | 4++--
4 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha @@ -11,6 +11,7 @@ use encoding::utf8; use fmt; use io; use os; +use path; use sort; use strconv; use strings; @@ -844,4 +845,9 @@ export fn prevloc(lex: *lexer) location = { }; }; -fn syntaxerr(loc: location, why: str) error = (loc, why); +export fn syntaxerr(loc: location, why: str) error = { + static let buf = path::buffer{...}; + path::set(&buf, loc.path)!; + loc.path = path::string(&buf); + return (loc, why); +}; diff --git a/hare/parse/parse.ha b/hare/parse/parse.ha @@ -21,7 +21,7 @@ fn syntaxerr( args: fmt::field... ) lex::error = { let why = fmt::asprintf(fmt, args...); - return (loc, why): lex::syntax: lex::error; + return lex::syntaxerr(loc, why); }; // Requires the next token to have a matching ltok. Returns that token, or an diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -789,7 +789,7 @@ hare_lex() { +test.ha fi gen_ssa hare::lex ascii io bufio encoding::utf8 strings fmt sort strio \ - strconv + strconv path } hare_module() { diff --git a/stdlib.mk b/stdlib.mk @@ -1300,7 +1300,7 @@ stdlib_hare_lex_any_srcs = \ $(STDLIB)/hare/lex/token.ha \ $(STDLIB)/hare/lex/lex.ha -$(HARECACHE)/hare/lex/hare_lex-any.ssa: $(stdlib_hare_lex_any_srcs) $(stdlib_rt) $(stdlib_ascii_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_bufio_$(PLATFORM)) $(stdlib_encoding_utf8_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_sort_$(PLATFORM)) $(stdlib_strio_$(PLATFORM)) $(stdlib_strconv_$(PLATFORM)) +$(HARECACHE)/hare/lex/hare_lex-any.ssa: $(stdlib_hare_lex_any_srcs) $(stdlib_rt) $(stdlib_ascii_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_bufio_$(PLATFORM)) $(stdlib_encoding_utf8_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_sort_$(PLATFORM)) $(stdlib_strio_$(PLATFORM)) $(stdlib_strconv_$(PLATFORM)) $(stdlib_path_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/hare/lex @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nhare::lex \ @@ -3549,7 +3549,7 @@ testlib_hare_lex_any_srcs = \ $(STDLIB)/hare/lex/lex.ha \ $(STDLIB)/hare/lex/+test.ha -$(TESTCACHE)/hare/lex/hare_lex-any.ssa: $(testlib_hare_lex_any_srcs) $(testlib_rt) $(testlib_ascii_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_bufio_$(PLATFORM)) $(testlib_encoding_utf8_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_sort_$(PLATFORM)) $(testlib_strio_$(PLATFORM)) $(testlib_strconv_$(PLATFORM)) +$(TESTCACHE)/hare/lex/hare_lex-any.ssa: $(testlib_hare_lex_any_srcs) $(testlib_rt) $(testlib_ascii_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_bufio_$(PLATFORM)) $(testlib_encoding_utf8_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_sort_$(PLATFORM)) $(testlib_strio_$(PLATFORM)) $(testlib_strconv_$(PLATFORM)) $(testlib_path_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/hare/lex @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nhare::lex \