This thread contains a patchset. You're looking at the original emails,
but you may wish to use the patch review UI.
Review patch
4
4
[PATCH harec] typedef: emit struct literals
Now you can do `export def THING: struct_type = (etc);`!
Unions still don't work, more to do elsewhere.
Signed-off-by: jturtle <jturtl@pm.me>
---
src/typedef.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/typedef.c b/src/typedef.c
index 9991223..167cec7 100644
--- a/src/typedef.c
+++ b/src/typedef.c
@@ -167,6 +167,17 @@ emit_literal(const struct expression *expr, FILE *out)
xfprintf(out, ")");
break;
case STORAGE_STRUCT:
+ xfprintf(out, "struct { ");
+ for (const struct struct_literal *lit = val->_struct;
+ lit; lit = lit->next) {
+ xfprintf(out, "%s: ", lit->field->name);
+ emit_type(lit->field->type, out);
+ xfprintf(out, " = ");
+ emit_literal(lit->value, out);
+ xfprintf(out, ", ");
+ }
+ xfprintf(out, "}");
+ break;
case STORAGE_UNION:
assert(0); // TODO
case STORAGE_ALIAS:
--
2.44.0
[harec/patches] build success
Could you add a test for this in testmod?
On Tue, Apr 16, 2024 at 12:49:03AM +0000, jturtle wrote:
> Now you can do `export def THING: struct_type = (etc);`!
> Unions still don't work, more to do elsewhere.
OK, looks fine to me
> Signed-off-by: jturtle <jturtl@pm.me>
> ---
> src/typedef.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/src/typedef.c b/src/typedef.c
> index 9991223..167cec7 100644
> --- a/src/typedef.c
> +++ b/src/typedef.c
> @@ -167,6 +167,17 @@ emit_literal(const struct expression *expr, FILE *out)
> xfprintf(out, ")");
> break;
> case STORAGE_STRUCT:
> + xfprintf(out, "struct { ");
> + for (const struct struct_literal *lit = val->_struct;
> + lit; lit = lit->next) {
> + xfprintf(out, "%s: ", lit->field->name);
> + emit_type(lit->field->type, out);
> + xfprintf(out, " = ");
> + emit_literal(lit->value, out);
> + xfprintf(out, ", ");
> + }
> + xfprintf(out, "}");
> + break;
> case STORAGE_UNION:
> assert(0); // TODO
> case STORAGE_ALIAS:
> --
> 2.44.0
>
>
+1 but agree that we should add a test