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

Modifying jasmin2tex integer representation to fit source integer representation better #886

Merged
merged 11 commits into from
Sep 6, 2024

Conversation

MrDaiki
Copy link
Collaborator

@MrDaiki MrDaiki commented Sep 3, 2024

Issue

jasmin2tex program always convert integer from source file to base 10. In certain cases, it makes readability of the program harder. For example :

tab[i] = 0xab;

is converted to :

\jasminindent{2}tab[i] = 172;\\

Solution

We implement a new Syntax node pbinteger that store the raw integer string coming from source file :

type pbinteger = {zvalue:Z.t; raw:string}

At pretyping, we convert this type back to Z.t, which mean that it does not affect the behavior of the compiler for all next compilation steps. Since latex_printer is executed before pre-typing, we can use the raw string for generating latex file. The new output is now :

\jasminindent{2}tab[i] = 0xab;\\

Changelog

  • Add new Syntax Node pbasedinteger which dissapear at pretyping
  • Changing parser and lexer accordingly
  • Changing latex_printer integer handling

* Add new Syntax Node `pbasedinteger` which dissapear at pretyping
* Changing parser and lexer accordingly
* Changing latex_printer integer handling
Comment on lines 138 to 142
{ INT {zvalue=Z.of_string s;raw=s}}

| ('0' ['x' 'X'] hexdigit+) as s
{ INT (Z.of_string s) }
{ INT {zvalue=Z.of_string s;raw=s} }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you compute the Z value here? Isn’t it simpler to only keep the string here and compute the value in pre-typing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't very used to the process of the compiler so I wanted the modification to affect the smallest possible part of the code. If you think it is preferable that the Z type building is done in pre-typing, I can change it (it will indeed simplify code readability)

@vbgl vbgl added this to the 2024.07.1 milestone Sep 4, 2024
* type pbaseinteger deleted (not usefull anymore)
* converting is done in pre-typing
Copy link
Member

@vbgl vbgl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering your future plans, it might be worth introducing an abstract type (say int_notation) right now.

MrDaiki and others added 3 commits September 5, 2024 16:42
Co-authored-by: Vincent Laporte <vbgl@users.noreply.github.com>
vbgl
vbgl previously approved these changes Sep 6, 2024
Copy link
Member

@vbgl vbgl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I’ll merge as soon as CI completes.

@vbgl vbgl dismissed their stale review September 6, 2024 08:46

merge conflicts

@vbgl vbgl merged commit faf9b1d into jasmin-lang:main Sep 6, 2024
1 check passed
vbgl pushed a commit that referenced this pull request Sep 6, 2024
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