From baee9e79e3296332c400749644eb557d6bb8c2a6 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 25 Jan 2025 22:53:02 -0700 Subject: lib9p: idl.gen: Obviate the join_lines function --- lib9p/idl.gen | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/lib9p/idl.gen b/lib9p/idl.gen index b179415..619c791 100755 --- a/lib9p/idl.gen +++ b/lib9p/idl.gen @@ -40,12 +40,8 @@ def add_prefix(p: str, s: str) -> str: return p + s -def join_lines(*args: str) -> str: - return "\n".join([a.rstrip() for a in args]).rstrip() + "\n" - - -def c_macro(*args: str) -> str: - full = join_lines(*args).rstrip() +def c_macro(full: str) -> str: + full = full.rstrip() assert "\n" in full lines = [l.rstrip() for l in full.split("\n")] width = max(len(l.expandtabs(tabsize=8)) for l in lines[:-1]) @@ -818,16 +814,16 @@ LM_ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) """ ret += c_macro( - f"#define _MSG_RECV(typ) [{idprefix.upper()}TYP_##typ/2] = {{", - f"\t\t.basesize = sizeof(struct {idprefix}msg_##typ),", - f"\t\t.validate = validate_##typ,", - f"\t\t.unmarshal = (_unmarshal_fn_t)unmarshal_##typ,", - f"\t}}", + f"#define _MSG_RECV(typ) [{idprefix.upper()}TYP_##typ/2] = {{\n" + f"\t\t.basesize = sizeof(struct {idprefix}msg_##typ),\n" + f"\t\t.validate = validate_##typ,\n" + f"\t\t.unmarshal = (_unmarshal_fn_t)unmarshal_##typ,\n" + f"\t}}\n" ) ret += c_macro( - f"#define _MSG_SEND(typ) [{idprefix.upper()}TYP_##typ/2] = {{", - f"\t\t.marshal = (_marshal_fn_t)marshal_##typ,", - f"\t}}", + f"#define _MSG_SEND(typ) [{idprefix.upper()}TYP_##typ/2] = {{\n" + f"\t\t.marshal = (_marshal_fn_t)marshal_##typ,\n" + f"\t}}\n" ) ret += "\n" ret += msg_table("Tmsg", "recv", f"struct _{idprefix}recv_tentry", (0, 0x100, 2)) -- cgit v1.2.3-2-g168b