hare

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

commit 92001a988574d8d0327db2616ce855fb399280cc
parent 2a34935300a56982f743338bbb718a238310daca
Author: Sebastian <sebastian@sebsite.pw>
Date:   Thu, 28 Apr 2022 17:27:41 -0400

fmt: add fatalf

fatal now behaves like println, and fatalf behaves like printfln.

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mcmd/hare/plan.ha | 8++++----
Mcmd/hare/schedule.ha | 6+++---
Mcmd/hare/subcmds.ha | 18+++++++++---------
Mcmd/harec/main.ha | 2+-
Mcmd/haredoc/main.ha | 15+++++++--------
Mcmd/haredoc/resolver.ha | 2+-
Mcmd/haretype/main.ha | 6+++---
Mfmt/fmt.ha | 10+++++++++-
Mhare/parse/+test/loc.ha | 2+-
Mregex/+test.ha | 38+++++++++++++++++++-------------------
10 files changed, 57 insertions(+), 50 deletions(-)

diff --git a/cmd/hare/plan.ha b/cmd/hare/plan.ha @@ -70,7 +70,7 @@ type plan_progress = struct { fn mkplan(ctx: *module::context, libs: []str) plan = { const rtdir = match (module::lookup(ctx, ["rt"])) { case let err: module::error => - fmt::fatal("Error resolving rt: {}", module::strerror(err)); + fmt::fatal("Error resolving rt:", module::strerror(err)); case let ver: module::version => yield ver.basedir; }; @@ -184,7 +184,7 @@ fn plan_execute(plan: *plan, verbose: bool) (void | !exec::exit_status) = { match (execute(plan, task, verbose)) { case let err: exec::error => progress_clear(plan); - fmt::fatal("Error: {}: {}", task.cmd[0], + fmt::fatalf("Error: {}: {}", task.cmd[0], exec::strerror(err)); case let err: !exec::exit_status => progress_clear(plan); @@ -212,7 +212,7 @@ fn update_cache(plan: *plan, mod: modcache) void = { }; match (module::manifest_write(plan.context, &manifest)) { case let err: module::error => - fmt::fatal("Error updating module cache: {}", + fmt::fatal("Error updating module cache:", module::strerror(err)); case void => void; }; @@ -248,7 +248,7 @@ fn execute( case let cmd: exec::command => yield cmd; case let err: exec::error => - fmt::fatal("Error resolving {}: {}", task.cmd[0], + fmt::fatalf("Error resolving {}: {}", task.cmd[0], exec::strerror(err)); }; for (let i = 0z; i < len(plan.environ); i += 1) { diff --git a/cmd/hare/schedule.ha b/cmd/hare/schedule.ha @@ -37,7 +37,7 @@ fn sched_module(plan: *plan, ident: ast::ident, link: *[]*task) *task = { let ver = match (module::lookup(plan.context, ident)) { case let err: module::error => let ident = unparse::identstr(ident); - fmt::fatal("Error resolving {}: {}", ident, + fmt::fatalf("Error resolving {}: {}", ident, module::strerror(err)); case let ver: module::version => yield ver; @@ -208,7 +208,7 @@ fn sched_hare_object( let manifest = match (module::manifest_load( plan.context, namespace)) { case let err: module::error => - fmt::fatal("Error reading cache entry for {}: {}", ns, + fmt::fatalf("Error reading cache entry for {}: {}", ns, module::strerror(err)); case let m: module::manifest => yield m; @@ -230,7 +230,7 @@ fn sched_hare_object( match (os::mkdirs(path)) { case void => void; case let err: fs::error => - fmt::fatal("Error: mkdirs {}: {}", path, + fmt::fatalf("Error: mkdirs {}: {}", path, fs::strerror(err)); }; append(harec.cmd, ["-t", path::join(path, td)]...); diff --git a/cmd/hare/subcmds.ha b/cmd/hare/subcmds.ha @@ -157,7 +157,7 @@ fn build(args: []str) void = { case let ver: module::version => yield ver; case let err: module::error => - fmt::fatal("Error scanning input module: {}", + fmt::fatal("Error scanning input module:", module::strerror(err)); }; @@ -177,7 +177,7 @@ fn build(args: []str) void = { match (plan_execute(&plan, verbose)) { case void => void; case !exec::exit_status => - fmt::fatal("{} {}: build failed", os::args[0], os::args[1]); + fmt::fatalf("{} {}: build failed", os::args[0], os::args[1]); }; if (tty::isatty(os::stdout_file)) { fmt::print("\a")!; @@ -263,7 +263,7 @@ fn release(args: []str) void = { case let err: fs::error => fmt::fatal(fs::strerror(err)); case let err: git_error => - fmt::fatal("git: {}", exec::exitstr(err)); + fmt::fatal("git:", exec::exitstr(err)); case badversion => fmt::fatal("Error: invalid format string. Hare uses semantic versioning, in the form major.minor.patch."); }; @@ -347,7 +347,7 @@ fn run(args: []str) void = { case let ver: module::version => yield ver; case let err: module::error => - fmt::fatal("Error scanning input module: {}", + fmt::fatal("Error scanning input module:", module::strerror(err)); }; @@ -364,11 +364,11 @@ fn run(args: []str) void = { match (plan_execute(&plan, verbose)) { case void => void; case !exec::exit_status => - fmt::fatal("{} {}: build failed", os::args[0], os::args[1]); + fmt::fatalf("{} {}: build failed", os::args[0], os::args[1]); }; const cmd = match (exec::cmd(output, runargs...)) { case let err: exec::error => - fmt::fatal("exec: {}", exec::strerror(err)); + fmt::fatal("exec:", exec::strerror(err)); case let cmd: exec::command => yield cmd; }; @@ -465,7 +465,7 @@ fn test(args: []str) void = { case let items: []ast::ident => yield items; case let err: module::error => - fmt::fatal("Error scanning source root: {}", + fmt::fatal("Error scanning source root:", module::strerror(err)); }; @@ -491,7 +491,7 @@ fn test(args: []str) void = { match (plan_execute(&plan, verbose)) { case void => void; case !exec::exit_status => - fmt::fatal("{} {}: build failed", os::args[0], os::args[1]); + fmt::fatalf("{} {}: build failed", os::args[0], os::args[1]); }; if (have_output) { @@ -500,7 +500,7 @@ fn test(args: []str) void = { const cmd = match (exec::cmd(output, runargs...)) { case let err: exec::error => - fmt::fatal("exec: {}", exec::strerror(err)); + fmt::fatal("exec:", exec::strerror(err)); case let cmd: exec::command => yield cmd; }; diff --git a/cmd/harec/main.ha b/cmd/harec/main.ha @@ -67,7 +67,7 @@ export fn main() void = { case let f: io::file => yield f; case let err: fs::error => - fmt::fatal("Error opening {}: {}", + fmt::fatalf("Error opening {}: {}", cmd.args[i], fs::strerror(err)); }; defer io::close(input)!; diff --git a/cmd/haredoc/main.ha b/cmd/haredoc/main.ha @@ -72,7 +72,7 @@ export fn main() void = { case "gemtext" => fmt = format::GEMTEXT; case => - fmt::fatal("Invalid format {}", opt.1); + fmt::fatal("Invalid format", opt.1); }; case 't' => template = false; @@ -101,7 +101,7 @@ export fn main() void = { if (len(cmd.args) < 1) [] else match (parseident(cmd.args[0])) { case let err: parse::error => - fmt::fatal("{}", parse::strerror(err)); + fmt::fatal(parse::strerror(err)); case let id: ast::ident => yield id; }; @@ -118,8 +118,7 @@ export fn main() void = { decl = id[len(id) - 1]; yield ver; case let err: module::error => - fmt::fatal( - "Error scanning input module: {}", + fmt::fatal("Error scanning input module:", module::strerror(err)); }; }; @@ -134,7 +133,7 @@ export fn main() void = { case let u: ast::subunit => append(decls, u.decls...); case let err: error => - fmt::fatal("Error: {}", strerror(err)); + fmt::fatal("Error:", strerror(err)); }; }; @@ -165,7 +164,7 @@ export fn main() void = { }; }; if (len(new) == 0) { - fmt::fatal("Could not find {}::{}", + fmt::fatalf("Could not find {}::{}", unparse::identstr(dirname), decl); }; free(decls); @@ -195,7 +194,7 @@ export fn main() void = { match (emit(&ctx)) { case void => void; case let err: error => - fmt::fatal("Error: {}", strerror(err)); + fmt::fatal("Error:", strerror(err)); }; io::close(ctx.out)!; @@ -321,7 +320,7 @@ fn scan(path: str) (ast::subunit | error) = { case let f: io::file => yield f; case let err: fs::error => - fmt::fatal("Error reading {}: {}", path, fs::strerror(err)); + fmt::fatalf("Error reading {}: {}", path, fs::strerror(err)); }; defer io::close(input)!; const lexer = lex::init(input, path, lex::flags::COMMENTS); diff --git a/cmd/haredoc/resolver.ha b/cmd/haredoc/resolver.ha @@ -149,7 +149,7 @@ fn lookup_remote_enum(ctx: *context, what: ast::ident) (ast::ident | void) = { case let u: ast::subunit => append(decls, u.decls...); case let err: error => - fmt::fatal("Error: {}", strerror(err)); + fmt::fatal("Error:", strerror(err)); }; }; diff --git a/cmd/haretype/main.ha b/cmd/haretype/main.ha @@ -83,11 +83,11 @@ export fn main() void = { match (typeinfo(store, cmd.args[i])) { case void => void; case let err: io::error => - fmt::fatal("I/O error: {}", io::strerror(err)); + fmt::fatal("I/O error:", io::strerror(err)); case let err: parse::error => - fmt::fatal("{}", parse::strerror(err)); + fmt::fatal(parse::strerror(err)); case let err: types::error => - fmt::fatal("{}", types::strerror(err)); + fmt::fatal(types::strerror(err)); case types::deferred => fmt::fatal("Invalid type"); }; diff --git a/fmt/fmt.ha b/fmt/fmt.ha @@ -59,11 +59,19 @@ export fn bsprintf(buf: []u8, fmt: str, args: field...) str = { // Formats text for printing and writes it to [[os::stderr]], followed by a line // feed, then exits the program with an error status. -export @noreturn fn fatal(fmt: str, args: field...) void = { +export @noreturn fn fatalf(fmt: str, args: field...) void = { fprintfln(os::stderr, fmt, args...)!; os::exit(1); }; +// Formats values for printing using the default format modifiers and writes +// them to [[os::stderr]] separated by spaces and followed by a line feed, then +// exits the program with an error status. +export @noreturn fn fatal(args: formattable...) void = { + fprintln(os::stderr, args...)!; + os::exit(1); +}; + // Formats text for printing and writes it to an [[io::handle]], followed by a // line feed. export fn fprintfln( diff --git a/hare/parse/+test/loc.ha b/hare/parse/+test/loc.ha @@ -18,7 +18,7 @@ fn expr_testloc(srcs: str...) void = for (let i = 0z; i < len(srcs); i += 1) { case let exp: ast::expr => yield exp; case let err: error => - fmt::fatal("{}: {}", srcs[i], strerror(err)); + fmt::fatalf("{}: {}", srcs[i], strerror(err)); }; defer ast::expr_finish(exp); let runes = 0z; diff --git a/regex/+test.ha b/regex/+test.ha @@ -19,12 +19,12 @@ fn run_find_case( case let e: error => if (expected == matchres::MATCH) { fmt::println(e)!; - fmt::fatal("Expected expression /{}/ to match, but it errored", + fmt::fatalf("Expected expression /{}/ to match, but it errored", expr, string); }; if (expected == matchres::NOMATCH) { fmt::println(e)!; - fmt::fatal("Expected expression /{}/ to not match, but it errored", + fmt::fatalf("Expected expression /{}/ to not match, but it errored", expr, string); }; return; @@ -33,39 +33,39 @@ fn run_find_case( match (find(re, string)) { case void => if (expected == matchres::MATCH) { - fmt::fatal("Expected expression /{}/ to match string \"{}\", but it did not", + fmt::fatalf("Expected expression /{}/ to match string \"{}\", but it did not", expr, string); }; if (expected == matchres::ERROR) { - fmt::fatal("Expression /{}/ failed to match, but should have errored", + fmt::fatalf("Expression /{}/ failed to match, but should have errored", expr, string); }; case let m: []matchgroup => if (expected == matchres::NOMATCH) { - fmt::fatal("Expected expression /{}/ to not match string \"{}\", but it did", + fmt::fatalf("Expected expression /{}/ to not match string \"{}\", but it did", expr, string); }; if (expected == matchres::ERROR) { - fmt::fatal("Expression /{}/ matched, but should have errored", + fmt::fatalf("Expression /{}/ matched, but should have errored", expr, string); }; if (start: size != m[0].start) { - fmt::fatal("Expected start of main match group to be {} but it was {}", + fmt::fatalf("Expected start of main match group to be {} but it was {}", start, m[0].start); }; if (end: size != m[0].end) { - fmt::fatal("Expected end of main match group to be {} but it was {}", + fmt::fatalf("Expected end of main match group to be {} but it was {}", end, m[0].end); }; case let e: error => if (expected == matchres::MATCH) { - fmt::fatal("Expected expression /{}/ to match, but it errored", + fmt::fatalf("Expected expression /{}/ to match, but it errored", expr, string); }; if (expected == matchres::NOMATCH) { - fmt::fatal("Expected expression /{}/ to not match, but it errored", + fmt::fatalf("Expected expression /{}/ to not match, but it errored", expr, string); }; }; @@ -82,12 +82,12 @@ fn run_findall_case( case let e: error => if (expected == matchres::MATCH) { fmt::println(e)!; - fmt::fatal("Expected expression /{}/ to match, but it errored", + fmt::fatalf("Expected expression /{}/ to match, but it errored", expr, string); }; if (expected == matchres::NOMATCH) { fmt::println(e)!; - fmt::fatal("Expected expression /{}/ to not match, but it errored", + fmt::fatalf("Expected expression /{}/ to not match, but it errored", expr, string); }; return; @@ -96,35 +96,35 @@ fn run_findall_case( match (findall(re, string)) { case void => if (expected == matchres::MATCH) { - fmt::fatal("Expected expression /{}/ to match string \"{}\", but it did not", + fmt::fatalf("Expected expression /{}/ to match string \"{}\", but it did not", expr, string); }; if (expected == matchres::ERROR) { - fmt::fatal("Expression /{}/ failed to match, but should have errored", + fmt::fatalf("Expression /{}/ failed to match, but should have errored", expr, string); }; case let groupsets: [][]matchgroup => if (expected == matchres::NOMATCH) { - fmt::fatal("Expected expression /{}/ to not match string \"{}\", but it did", + fmt::fatalf("Expected expression /{}/ to not match string \"{}\", but it did", expr, string); }; if (expected == matchres::ERROR) { - fmt::fatal("Expression /{}/ matched, but should have errored", + fmt::fatalf("Expression /{}/ matched, but should have errored", expr, string); }; if (count: size != len(groupsets)) { - fmt::fatal("Expected to find {} matches but found {}", + fmt::fatalf("Expected to find {} matches but found {}", count, len(groupsets)); }; case let e: error => if (expected == matchres::MATCH) { - fmt::fatal("Expected expression /{}/ to match, but it errored", + fmt::fatalf("Expected expression /{}/ to match, but it errored", expr, string); }; if (expected == matchres::NOMATCH) { - fmt::fatal("Expected expression /{}/ to not match, but it errored", + fmt::fatalf("Expected expression /{}/ to not match, but it errored", expr, string); }; };