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

improve Triton assembly macros #240

Closed
wants to merge 3 commits into from
Closed

Conversation

jan-ferdinand
Copy link
Member

@jan-ferdinand jan-ferdinand commented Nov 17, 2023

It should be possible to make label building more general but I find it difficult to do1 so without metavariable expressions, which are currently unstable.

Footnotes

  1. probably more a testament to my macro-writing skill than anything else

@jan-ferdinand jan-ferdinand changed the title summarize all repeated instructions taking an argument improve Triton assembly macros Nov 17, 2023
@Sword-Smith
Copy link
Collaborator

Very nice. Looking forward to this :)

@jan-ferdinand
Copy link
Member Author

jan-ferdinand commented Nov 18, 2023

Experimenting and reading up on the matter, I can't seem to achieve the behavior I want using declarative macros. In particular, I would like to allow building labels like {expr}ident but disallow {expr} ident – the whitespace in between makes all the difference.1 Since declarative macros operate on token trees, whitespace is not preserved. As a consequence, detecting whether some token is part of a label becomes quite difficult. While it might work for label declarations, uniquely terminated by a colon, a call followed by a series of tokens can be ambiguous. Does call {my_list}push{my_item} describe a call to {my_list} followed by instruction push with {my_item}, or is the intended call target {my_list}push{my_item}?

A workaround2 is to fully declare the desired label within the expression:

{format!("{my_label}_inner")}: push 0 returncall {format!("{my_label}_inner")}

Note also that I can't easily mimic the internals of the format! macro, which is used in the workaround: internally, format! uses the format_args! macro, which is a compiler built-in.

The proper solution is to go full proc-macro, which is something that I want to do anyway. It just means that the fix for #220 is a bit further away than I thought it to be.

Footnotes

  1. Successfully matching {expr} ident as a label causes issues like {my_instruction} my_label: or call {my_label} halt being erroneously matched and fused.

  2. ugly, but works today

@jan-ferdinand jan-ferdinand deleted the improve_macros branch November 18, 2023 12:36
@Sword-Smith
Copy link
Collaborator

Too bad that this is not possible. Thanks for looking into it though!

@jan-ferdinand
Copy link
Member Author

I do plan to add the functionality. By closing this branch, I didn't want to communicate that #220 is off the table. It's just that the approach tried here does not work. ☺️

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