Skip to content
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

Have .size available on integer values #95

Open
aperezdc opened this issue Jul 22, 2021 · 1 comment
Open

Have .size available on integer values #95

aperezdc opened this issue Jul 22, 2021 · 1 comment

Comments

@aperezdc
Copy link

I am trying to make some rules which generate chunks in a certain file format (similar to the Amiga HUNK format), and I would like to be able to calculate sizes inside a rule.

Currently one can manually place labels around, like in this simple example:

#ruledef {
    item {data}, {size: u32} => size @ data
}

; This works, but needs to manually add the label and extra parameter
item "hello world", (item_end - $)
item_end:

But this gets tiresome and the global name space of labels gets polluted. It would be much nicer if local labels could be used inside a rule, for example like this:

#ruledef {
    item {data} => {
        (.item_end - $)`32 @ data
	.item_end:
    }
}

; This does not currently work, would be nice to have
item "hello world"

Alternatively, allowing “local” variables inside rules could also work for this use case. The same example, using local variables, could be as follows:

#ruledef {
    item {data} => {
        (item_end - $)`32 @ data
	item_end = $
    }
}

; This almost works currently, the "item_end" variable is considered undefined.
item "hello world"
@hlorenzi
Copy link
Owner

Hmm, perhaps we could make it possible to retrieve the size of a passed value, so your first example would look like:

#ruledef {
    item {data} => data.size`32 @ data
}

item "hello world"

Would this be your only use-case for this feature right now? Or are there more complex situations that wouldn't be covered by my suggestion?

@hlorenzi hlorenzi changed the title Support nested labels/variables inside rules Have .size available on integer values May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants