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
Types from beginning to end #37
Types from beginning to end #37
Changes from 23 commits
0d41365
fe4610d
2f4d462
9a013f3
5831094
055931c
08f8d36
2578acc
89337ae
9fa9485
3457d53
b5b3183
8a94037
61f28a8
98ae71e
f06972a
aa23eae
c9be95c
61d343d
1ad6dbf
d82cd3d
9b30942
20e42a0
3ad2392
e7d77a7
b4af7c9
8013c43
a836f0b
9d23bd2
55e1ec0
e339100
6c4570d
a94f836
933ed59
312d4e7
ac386a8
ab4eac2
4423fee
c57b388
ab7dcf8
db2d432
1bd10b3
66f7289
b125c17
bee8136
afebae2
e669db3
c9ccbb2
6615957
9b71982
dc49514
4e3e0f8
ec7b772
974bdff
32f6a44
b2d090d
b14fa1c
8281a44
ec35e50
6574a1d
e830a9f
339e07c
84f1e10
80749cf
81aaf8e
a400f57
4a70c4c
cd2381a
f922e21
13b8210
33c195c
49c9970
e594ee5
b95d879
b7be438
49f6762
6c49cac
7253339
7b84f66
771b9b4
df8ffb0
5a60f48
cc09b8b
836f99b
acd725c
f3fab2d
a8241fa
6c027c7
c7f87aa
88715b4
1104d93
b222c7f
6411d36
40b4430
f1f876c
8282edc
3a9c115
79c22b1
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.
This probably should not be by name; rather, we should just pass the variable itself here and it would return its ref instead. Not sure where this is used or if there is a good reason why we aren’t doing that, but that’s what I’d do.
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.
What is "the variable itself" here?
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.
The
IRStaticVariable*
or whatever it’s calledThere 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.
How would we go about getting the IRStaticVariable from a variable reference AST node, if not by name?
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.
See one of my other comments in codegen.c just now
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.
As it turns out, now that the backend is working better with order of operands and such, we can also just use
subs_lhs = var
instead ofsubs_lhs = ir_static_reference(...)
. So we may actually be able to remove this.Tangent: doing this has made me realise what stack spilling is and why it's needed; you can save a value on the stack and then just load it into a register vs keeping that register around for as long as it's needed, freeing up more registers for other things. That's exactly what I implemented in the codegen of the IR for static refs, in order to get around botched use of a working RA. Lol.
Relevant code:
https://github.com/LensPlaysGames/FUNCompiler/blob/1104d937a70f065746b8b8e9a1773152e7811ed0/src/codegen.c#L373-L383
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.
https://github.com/LensPlaysGames/FUNCompiler/blob/6411d364fb55d1f81fff0a5f33ee85b3188a2976/src/codegen.c#L376-L380
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.
Yeah, in that branch, the
var
is already a static ref, so you can just reuse that one. That’s pretty much what I meant with ‘you don’t have to look up variables by name’.I think this could just be
;Þ
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.
Well the original idea was that there would ever only be one IR_STATIC_REF for each static variable. That’s why there simply was no
ir_create_static_ref()
, simply because the idea of such an operation would have been flawed to begin with, at least when I wrote this.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.
Interesting; so there's only some confusion in the fact that IR_STATIC_REF both creates a static as well as holds a reference to an existing static (it's address), in the same way that ALLOCA does. However, can't a static be referenced from multiple scopes? If so, won't each one need a reference to the static? Maybe I'm thinking about this the wrong way
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.
When you create a static variable, it creates an
IRStaticVariable
, which is added to a vector in the context and it’s how the variables are emitted by the backend. This structure holds information about e.g. the name of a static variable:https://github.com/LensPlaysGames/FUNCompiler/blob/8282edc50843fc5ec882469198e1aedb149dd46e/src/codegen.h#L40-L44
By contrast, an
IR_STATIC_REF
is an instruction that wraps anIRStaticVariable
, in the same way that anIR_ALLOCA
wraps anIRStackAllocation
. TheIRStaticVariable
is the variable, theIR_STATIC_REF
contains a pointer to that variable. The type of anIR_STATIC_REF
is a pointer to whatever the type of the static variable is, for the same reason that the type of anIR_ALLOCA
is a pointer to the allocated storage.The
IR_STATIC_REF
is just a way to refer to anIRStaticVariable
in IR. Only one is needed for each variable as just like theIR_STATIC_REF
holds a pointer to theIRStaticVariable
, so does theIRStaticVariable
contain a pointer to itsIR_STATIC_REF
. This is why the (not ‘a’)IR_STATIC_REF
for a static variable is created together with that variable