summaryrefslogtreecommitdiff
path: root/lib9p
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-12-21 21:39:02 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-12-26 17:56:35 -0700
commitd018906715b395e0fb9624cbd5b7fbf1c0e3f559 (patch)
tree59f39653cbd95158b1555a321086fcd4b6bf95ff /lib9p
parentd6bac0f1ca6489e1d532c4e1a5fb3e6b774aafd7 (diff)
lib9p: idl.gen: Do a better job of organizing the Python into sections
Diffstat (limited to 'lib9p')
-rwxr-xr-xlib9p/idl.gen36
1 files changed, 21 insertions, 15 deletions
diff --git a/lib9p/idl.gen b/lib9p/idl.gen
index 47d1102..4f1e8b8 100755
--- a/lib9p/idl.gen
+++ b/lib9p/idl.gen
@@ -17,7 +17,7 @@ import idl
# this script, marked with "SPECIAL".
-# Generate C ###################################################################
+# Utilities ####################################################################
idprefix = "lib9p_"
@@ -54,6 +54,21 @@ def c_typename(typ: idl.Type) -> str:
raise ValueError(f"not a type: {typ.__class__.__name__}")
+def c_expr(expr: idl.Expr) -> str:
+ ret: list[str] = []
+ for tok in expr.tokens:
+ match tok:
+ case idl.ExprOp():
+ ret += [tok.op]
+ case idl.ExprLit():
+ ret += [str(tok.val)]
+ case idl.ExprSym(name="end"):
+ ret += ["ctx->net_offset"]
+ case idl.ExprSym():
+ ret += [f"_{tok.name[1:]}_offset"]
+ return " ".join(ret)
+
+
_ifdef_stack: list[str | None] = []
@@ -96,6 +111,9 @@ def ifdef_pop(n: int) -> str:
return ret
+# Generate .h ##################################################################
+
+
def gen_h(versions: set[str], typs: list[idl.Type]) -> str:
global _ifdef_stack
_ifdef_stack = []
@@ -236,19 +254,7 @@ enum {idprefix}version {{
return ret
-def c_expr(expr: idl.Expr) -> str:
- ret: list[str] = []
- for tok in expr.tokens:
- match tok:
- case idl.ExprOp():
- ret += [tok.op]
- case idl.ExprLit():
- ret += [str(tok.val)]
- case idl.ExprSym(name="end"):
- ret += ["ctx->net_offset"]
- case idl.ExprSym():
- ret += [f"_{tok.name[1:]}_offset"]
- return " ".join(ret)
+# Generate .c ##################################################################
def gen_c(versions: set[str], typs: list[idl.Type]) -> str:
@@ -716,7 +722,7 @@ LM_FLATTEN bool _{idprefix}marshal_stat(struct _marshal_ctx *ctx, struct lib9p_s
return ret
-################################################################################
+# Main #########################################################################
if __name__ == "__main__":