Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat(docs):
asm
functions #1061base: main
Are you sure you want to change the base?
feat(docs):
asm
functions #1061Changes from 9 commits
385c0d0
1738dff
d5de05d
9c4c71b
7263c88
7157a2e
0dd10fe
558387c
2070ae3
71a7469
ab143a6
7e56f85
720ab55
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is still not clear what the notation
-> 1 0
means regarding what happens to the results ofLDVARUINT16
in the stack itself. The explanation states that 1 represents the value of stack register 1, etc. but it does not explain the significance of writing them in the order-> 1 0
. Probably what needs to be said is that the notation-> 1 0
describes how the contents of the stack will be rearranged, when reading-> 1 0
left-to-right: the contents of registers1
will be placed at the top of the stack, and the contents of registers0
will be placed second-to-top.One alternative way of explaining could be in terms of removing from the stack:
-> 1 0
means thats1
is removed first, followed bys0
. Hence, the function returns theBuilder
ins0
because it was the stack content removed last.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I am having second thoughts on using "removing" because it becomes confusing with what happens with the rest of the stack. For example, suppose that after executing some asm function with declaration
-> 2 1 0
, we have the 5 element stack (top is leftmost):Then,
-> 0 1 2
means "removes0
, thens1
, thens2
", so that the stack after removings0
is:But then,
s0
contains nowb
, when previouslyb
was ins1
.So, probably a better word instead of "removing" would be "read from":
-> 1 0
means thats1
is read from the stack first, followed bys0
. Hence, the function returns theBuilder
ins0
because it was the stack content read last.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thing is, as I've just checked in tests,
-> 0 1 2
is not about taking or not taking any results, but merely about positioning items for the whatever result type we've specified. Like, if the return type isInt
, one can only specify-> 0
and nothing else, even though-> 0
in this case is the same as not writing anything at all. And when the Structs, long Structs (more than 15 entries) or even nested Structs are involved, this is getting complicated.Thus, my description of
s0
matching0
,s1
matching1
is actually incorrect and has to be rewritten. And I've got to check the cases with long or nested Structs here as well, same as for the "stack calling conventions" bit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. So, this declaration is incorrect (because it returns only one element):
but this is correct:
even though it will discard the
Slice
result and keep only theInt
. Or is this last one also incorrect?Mmmm.... very confusing indeed. So, when using the notation
-> m n p
it is not possible to discard values in the result type. I think this is acceptable. It is better to explicitly state all the results than to rely on understanding implicit discards.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First one is incorrect. Second one could've been correct if we had our own backend or if we'd alter FunC generation, but since I tested that it's also incorrect — nothing can be discarded in result type.
It worked for me in previous tests mainly because FunC doesn't perform any checks, and because all asm function bodies are embedded in Fift code.
I had some DROP instructions very deep later on in other asm functions, which unexpectedly (for me) cleared the stack for this one. And I noticed that a little too late.
In the end, this really proves the point of those cautionary paragraphs at the top of the assembly functions description. This stuff is really messy, intertwined and hard to debug (until our own backend for it, of course). But I'll persevere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand and thank you for your effort!
So, let's adapt the explanation so that no discards happen in the result type.
Now, regarding nested structs, structs in arguments and structs with more than 15 fields, if you think that the explanation would become too complex to fit it in the page or that the explanation would become so convoluted because of those exceptional cases, probably it would be better to explain those in a separate page, with a link to that page.