commit ea8326427d84866bde4a69faaebf3f22307f8baa
parent 0733819dc303cd6750bdf46ecf0de302ae74126c
Author: Joe Finney <me@spxtr.net>
Date: Wed, 10 May 2023 17:01:22 -0700
Remove _ from function parameters.
This needs to be merged at the same time as the related change to
harec and hare-specification.
Signed-off-by: Joe Finney <me@spxtr.net>
Diffstat:
12 files changed, 58 insertions(+), 47 deletions(-)
diff --git a/fnmatch/fnmatch.ha b/fnmatch/fnmatch.ha
@@ -313,7 +313,7 @@ fn match_ctype(it: *strings::iterator, c: rune) (bool | errors::invalid) = {
return errors::invalid;
};
let name = strings::sub(s, 0, i - 1);
- const map: [_](str, *fn(_: rune) bool) = [
+ const map: [_](str, *fn(rune) bool) = [
("alnum", &ascii::isalnum), ("alpha", &ascii::isalpha),
("blank", &ascii::isblank), ("cntrl", &ascii::iscntrl),
("digit", &ascii::isdigit), ("graph", &ascii::isgraph),
diff --git a/hare/parse/+test/unit.ha b/hare/parse/+test/unit.ha
@@ -119,12 +119,14 @@ fn tup_to_import(tup: import_tuple) ast::import = ast::import {
@test fn decls() void = {
roundtrip("export type foo::bar = *int, baz = const void;\n\n"
"type foo = ...bar;\n\n"
- "type foo = nullable *fn(x: rune, _: int) void;\n\n"
+ "type foo = nullable *fn(x: rune, int) void;\n\n"
"export let @symbol(\"_\") foo::bar: int = void, baz: int = void, bat = void;\n\n"
"def foo::bar: int = void;\n\n"
"def foo::bar = void;\n\n"
"@symbol(\".f9$oo\") fn foo(bar: int, baz: int...) void;\n\n"
- "@test fn foo(_: int, ...) void;\n\n"
+ "@test fn foo(int, ...) void;\n\n"
+ "fn foo(bar) void;\n\n"
+ "fn foo(bar::baz) void;\n\n"
"export fn main() void = void;\n\n"
"fn long(\n"
"\tfirst: *const void,\n"
diff --git a/hare/parse/type.ha b/hare/parse/type.ha
@@ -26,19 +26,26 @@ fn prototype(lexer: *lex::lexer) (ast::func_type | error) = {
break;
};
- let name = match (try(lexer, ltok::UNDERSCORE)?) {
+ let name_or_type = _type(lexer)?;
+ match (try(lexer, ltok::COLON)?) {
case void =>
- yield want(lexer, ltok::NAME)?.1 as str;
+ append(params, ast::func_param {
+ loc = loc,
+ name = "",
+ _type = alloc(name_or_type),
+ });
case lex::token =>
- yield "";
+ // Bit of a hack because we can't unlex twice.
+ synassert(loc, name_or_type.repr is ast::alias_type,
+ "Invalid parameter name")?;
+ let ns = (name_or_type.repr as ast::alias_type).ident;
+ synassert(loc, len(ns) == 1, "Invalid parameter name")?;
+ append(params, ast::func_param {
+ loc = loc,
+ name = ns[0],
+ _type = alloc(_type(lexer)?),
+ });
};
-
- want(lexer, ltok::COLON)?;
- append(params, ast::func_param {
- loc = loc,
- name = name,
- _type = alloc(_type(lexer)?),
- });
match (try(lexer, ltok::ELLIPSIS)?) {
case void =>
yield void;
diff --git a/hare/unparse/decl.ha b/hare/unparse/decl.ha
@@ -256,5 +256,5 @@ fn decl_test(d: ast::decl, expected: str) bool = {
body = expr_void,
attrs = 0,
};
- assert(decl_test(d, "fn foo(_: int) int = void;"));
+ assert(decl_test(d, "fn foo(int) int = void;"));
};
diff --git a/hare/unparse/type.ha b/hare/unparse/type.ha
@@ -91,7 +91,7 @@ export fn prototype(
const param = t.params[i];
linelen += _type(&strm, indent, *param._type)?;
typenames[i] = strings::dup(strio::string(&strm));
- linelen += if (param.name == "") 1 else len(param.name);
+ linelen += if (param.name == "") -2 else len(param.name);
strio::reset(&strm);
};
switch (t.variadism) {
@@ -112,8 +112,9 @@ export fn prototype(
for (let i = 0z; i < len(t.params); i += 1) {
const param = t.params[i];
n += newline(out, indent)?;
- n += fmt::fprintf(out, "{}: ",
- if (param.name == "") "_" else param.name)?;
+ if (param.name != "") {
+ n += fmt::fprintf(out, "{}: ", param.name)?;
+ };
n += fmt::fprint(out, typenames[i])?;
if (i + 1 == len(t.params)
&& t.variadism == variadism::HARE) {
@@ -130,8 +131,9 @@ export fn prototype(
n += newline(out, indent)?;
} else for (let i = 0z; i < len(t.params); i += 1) {
const param = t.params[i];
- n += fmt::fprintf(out, "{}: ",
- if (param.name == "") "_" else param.name)?;
+ if (param.name != "") {
+ n += fmt::fprintf(out, "{}: ", param.name)?;
+ };
n += fmt::fprint(out, typenames[i])?;
if (i + 1 == len(t.params)) {
switch (t.variadism) {
@@ -448,7 +450,7 @@ fn type_test(t: ast::_type, expected: str) void = {
},
],
};
- type_test(t, "@noreturn fn(_: int, ...) int");
+ type_test(t, "@noreturn fn(int, ...) int");
t.repr = ast::func_type {
result = &type_int,
attrs = 0,
diff --git a/rt/+freebsd/syscalls.ha b/rt/+freebsd/syscalls.ha
@@ -3,13 +3,13 @@
// (c) 2021 Ember Sawady <ecs@d2evs.net>
// (c) 2021 Thomas Bracht Laumann Jespersen <t@laumann.xyz>
-fn syscall0(_: u64) u64;
-fn syscall1(_: u64, _: u64) u64;
-fn syscall2(_: u64, _: u64, _: u64) u64;
-fn syscall3(_: u64, _: u64, _: u64, _: u64) u64;
-fn syscall4(_: u64, _: u64, _: u64, _: u64, _: u64) u64;
-fn syscall5(_: u64, _: u64, _: u64, _: u64, _: u64, _: u64) u64;
-fn syscall6(_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64) u64;
+fn syscall0(u64) u64;
+fn syscall1(u64, u64) u64;
+fn syscall2(u64, u64, u64) u64;
+fn syscall3(u64, u64, u64, u64) u64;
+fn syscall4(u64, u64, u64, u64, u64) u64;
+fn syscall5(u64, u64, u64, u64, u64, u64) u64;
+fn syscall6(u64, u64, u64, u64, u64, u64, u64) u64;
export def PATH_MAX: size = 1024z;
export type path = (str | []u8 | *const u8);
diff --git a/rt/+freebsd/types.ha b/rt/+freebsd/types.ha
@@ -44,8 +44,8 @@ export def SIG_HOLD: uintptr = 3;
export type sigact = struct {
union {
- sa_handler: *fn (_: int) void,
- sa_sigaction: *fn (_: int, _: *siginfo, _: *void) void,
+ sa_handler: *fn (int) void,
+ sa_sigaction: *fn (int, *siginfo, *void) void,
},
sa_flags: int,
sa_mask: sigset,
diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha
@@ -6,13 +6,13 @@
// (c) 2021 Thomas Bracht Laumann Jespersen <t@laumann.xyz>
// (c) 2022 Vincent Dagonneau <v@vda.io>
-fn syscall0(_: u64) u64;
-fn syscall1(_: u64, _: u64) u64;
-fn syscall2(_: u64, _: u64, _: u64) u64;
-fn syscall3(_: u64, _: u64, _: u64, _: u64) u64;
-fn syscall4(_: u64, _: u64, _: u64, _: u64, _: u64) u64;
-fn syscall5(_: u64, _: u64, _: u64, _: u64, _: u64, _: u64) u64;
-fn syscall6(_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64) u64;
+fn syscall0(u64) u64;
+fn syscall1(u64, u64) u64;
+fn syscall2(u64, u64, u64) u64;
+fn syscall3(u64, u64, u64, u64) u64;
+fn syscall4(u64, u64, u64, u64, u64) u64;
+fn syscall5(u64, u64, u64, u64, u64, u64) u64;
+fn syscall6(u64, u64, u64, u64, u64, u64, u64) u64;
export def PATH_MAX: size = 4096z;
export type path = (str | []u8 | *const u8);
diff --git a/rt/+linux/types.ha b/rt/+linux/types.ha
@@ -512,8 +512,8 @@ export def SIG_HOLD: uintptr = 2;
export type sigact = struct {
union {
- sa_handler: *fn (_: int) void,
- sa_sigaction: *fn (_: int, _: *siginfo, _: *void) void,
+ sa_handler: *fn (int) void,
+ sa_sigaction: *fn (int, *siginfo, *void) void,
},
sa_flags: u64,
sa_restorer: *fn () void,
diff --git a/rt/malloc+libc.ha b/rt/malloc+libc.ha
@@ -22,6 +22,6 @@ export @symbol("rt.free") fn free_(p: nullable *void) void = {
c_free(p);
};
-@symbol("malloc") fn c_malloc(_: size) nullable *void;
-@symbol("realloc") fn c_realloc(_: nullable *void, _: size) nullable *void;
-@symbol("free") fn c_free(_: nullable *void) void;
+@symbol("malloc") fn c_malloc(size) nullable *void;
+@symbol("realloc") fn c_realloc(nullable *void, size) nullable *void;
+@symbol("free") fn c_free(nullable *void) void;
diff --git a/time/+linux/functions.ha b/time/+linux/functions.ha
@@ -79,15 +79,15 @@ export type clock = enum {
TAI = 11,
};
-fn cgt_vdso() nullable *fn(_: int, _: *rt::timespec) int = {
+fn cgt_vdso() nullable *fn(int, *rt::timespec) int = {
static let vdso_checked: bool = false;
- static let cgt_vdso: nullable *fn(_: int, _: *rt::timespec) int = null;
+ static let cgt_vdso: nullable *fn(int, *rt::timespec) int = null;
if (vdso_checked) {
return cgt_vdso;
};
vdso_checked = true;
cgt_vdso = vdso::getsym(VDSO_CGT_SYM, VDSO_CGT_VER):
- nullable *fn(_: int, _: *rt::timespec) int;
+ nullable *fn(int, *rt::timespec) int;
return cgt_vdso;
};
@@ -95,7 +95,7 @@ fn now_vdso(clock: clock, tp: *rt::timespec) (void | rt::errno) = {
const vfn = match (cgt_vdso()) {
case null =>
return rt::wrap_errno(rt::ENOSYS);
- case let vfn: *fn(_: int, _: *rt::timespec) int =>
+ case let vfn: *fn(int, *rt::timespec) int =>
yield vfn;
};
const ret = vfn(clock, tp);
diff --git a/unix/signal/+linux.ha b/unix/signal/+linux.ha
@@ -30,7 +30,7 @@ export fn handle(
};
let new = rt::sigact {
- sa_sigaction = handler: *fn(_: int, _: *rt::siginfo, _: *void) void,
+ sa_sigaction = handler: *fn(int, *rt::siginfo, *void) void,
sa_mask = sa_mask,
sa_flags = sa_flags,
// Filled in by rt:
@@ -38,7 +38,7 @@ export fn handle(
};
let old = rt::sigact {
// Filled in by rt:
- sa_sigaction = null: *fn(_: int, _: *rt::siginfo, _: *void) void,
+ sa_sigaction = null: *fn(int, *rt::siginfo, *void) void,
sa_restorer = null: *fn() void,
...
};