~sircmpwn/hare-dev

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

Details
Message ID
<20240416004851.35045-1-jturtl@pm.me>
DKIM signature
pass
Download raw message
Patch: +11 -0
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

builds.sr.ht <builds@sr.ht>
Details
Message ID
<D0L4UKU889GE.23JCAK7H0PSBC@fra01>
In-Reply-To
<20240416004851.35045-1-jturtl@pm.me> (view parent)
DKIM signature
missing
Download raw message
harec/patches: SUCCESS in 39s

[typedef: emit struct literals][0] from [jturtle][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/51046
[1]: jturtl@pm.me

✓ #1196889 SUCCESS harec/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/1196889
✓ #1196891 SUCCESS harec/patches/netbsd.yml  https://builds.sr.ht/~sircmpwn/job/1196891
✓ #1196890 SUCCESS harec/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/1196890
✓ #1196892 SUCCESS harec/patches/openbsd.yml https://builds.sr.ht/~sircmpwn/job/1196892
Details
Message ID
<D1FVKJRLH7QR.1DKO7MFC1S4HF@sebsite.pw>
In-Reply-To
<20240416004851.35045-1-jturtl@pm.me> (view parent)
DKIM signature
pass
Download raw message
Could you add a test for this in testmod?
Lorenz (xha) <me@xha.li>
Details
Message ID
<Zk15JSs_vL1VNAGK@xha.li>
In-Reply-To
<20240416004851.35045-1-jturtl@pm.me> (view parent)
DKIM signature
pass
Download raw message
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
> 
> 
Details
Message ID
<D1KC10BOEU6H.3AJDO1YA5KESC@cmpwn.com>
In-Reply-To
<20240416004851.35045-1-jturtl@pm.me> (view parent)
DKIM signature
pass
Download raw message
+1 but agree that we should add a test
Reply to thread Export thread (mbox)