Skip to content

feature: add iotas #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed

Conversation

seija-amanojaku
Copy link
Contributor

@seija-amanojaku seija-amanojaku commented Jul 7, 2025

This PR adds three keywords (iota, iota_reset, iota_skip), which serve as a counter.
Functions also automatically reset that counter to 0.

Opinions on changes/ideas to the syntax are welcome.

STRUCT_OKINA_FOO iota_set(0);
STRUCT_OKINA_BAR iota_skip(1);
/* iota_skip can generally be used to create an n-element wordlist */
STRUCT_OKINA_BAZ iota_skip(12);

/* Try to reset an iota to start a new struct */
STRUCT_YUKARI_BAR iota_reset;
STRUCT_YUKARI_FOO iota;
STRUCT_YUKARI_BAZ iota_skip(128);         /* Can be used to initialise 128 bytes of space */
STRUCT_YUKARI_BARRIER iota;

list[4];

main() {
    printf("%d %d %d\n", STRUCT_OKINA_FOO, STRUCT_OKINA_BAR, STRUCT_OKINA_BAZ);
    printf("%d %d %d\n", STRUCT_YUKARI_FOO, STRUCT_YUKARI_BAR, STRUCT_YUKARI_BAZ);
    
    /* Using iotas in general expressions */
    list[iota_reset] = 1;
    list[iota] = 2;
    list[iota] = 3;
    list[iota] = 4;
    printf("%d %d\n", iota, list[1]);

    /* iota = N <=> iota_set(N)
     * iota += N <=> iota_skip(N) */
    printf("%d\n", iota = 0);
    return (0);
}

I don't particularly like how it is right now, so I'll just wait for
some new ideas to arrive.
I feel like that's a reasonable thing to do.
nullnominal recommended the "iota = [imm]" syntax as a standin for
iota_set(imm), but I won't do it right now. It's 2am. I should go to
bed.
@seija-amanojaku seija-amanojaku marked this pull request as ready for review July 10, 2025 14:03
@rexim
Copy link
Member

rexim commented Jul 12, 2025

I do not consider this solution satisfactory, sorry. We need something to do enumerations at compile time, but this is way too clunky. I'm still thinking what could be a good solution here that also fits in the spirit of B. Thank you for the suggestion.

@rexim rexim closed this Jul 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants