-
Notifications
You must be signed in to change notification settings - Fork 93
Operator '__addressof' #445
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ef49529
Symbol suggestions: distinguish native functions and Pawn functions
Daniel-Cortez 65070b6
Allow symbols to be referenced from outside functions
Daniel-Cortez 1d3b231
Implement operator '__addressof'
Daniel-Cortez 50d54b9
Add tests
Daniel-Cortez 18b6df7
Merge branch 'dev' into __addrof
Y-Less File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| 'test_type': 'output_check', | ||
| 'errors': """ | ||
| __addressof.pwn(3) : error 017: undefined symbol "Func1" | ||
| __addressof.pwn(16) : error 093: "__addressof" operator is invalid in preprocessor expressions | ||
| __addressof.pwn(21) : error 001: expected token: "-variable, array, array cell, label or function-", but found "-numeric value-" | ||
| __addressof.pwn(24) : error 001: expected token: "-variable, array, array cell, label or function-", but found "-native function-" | ||
| """ | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #include <console> | ||
|
|
||
| const func1_addr = __addressof(Func1); // error | ||
|
|
||
| Func1() {} | ||
| Func2() {} | ||
| Func3() {} | ||
|
|
||
| new const functions[3] = | ||
| { | ||
| __addressof(Func1), | ||
| __addressof(Func2), | ||
| __addressof(Func3) | ||
| }; | ||
|
|
||
| #if __addressof Func1 > 0 // error | ||
| #endif | ||
|
|
||
| main() | ||
| { | ||
| const a = __addressof func1_addr; // error | ||
| #pragma unused a | ||
|
|
||
| const b = __addressof printf; // error | ||
| #pragma unused b | ||
|
|
||
| lbl: | ||
| const c = __addressof lbl; | ||
| #pragma unused c | ||
|
|
||
| const d = __addressof functions; | ||
| #pragma unused d | ||
|
|
||
| const e = __addressof functions[1]; | ||
| #pragma unused e | ||
|
|
||
| static x = 0; | ||
| const f = __addressof x; | ||
| #pragma unused f | ||
|
|
||
| static arr1[3][2] = { { 0, ... }, ... }; | ||
| const g = __addressof arr1[2][1]; | ||
| #pragma unused g | ||
|
|
||
| new y = 0; | ||
| new const h = __addressof y; | ||
| #pragma unused h | ||
|
|
||
| new arr2[3][2] = { { 0, ... }, ... }; | ||
| new const i = __addressof arr2; | ||
| #pragma unused i | ||
| } | ||
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.
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 is a little surprising. Functions can otherwise be used before declaration. Would this work if it were forwarded?
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 is because in order to call functions the compiler outputs
call .funcname, so it could look up the function and obtain its address later, when assembling the code. But__addressofworks as an expression, and expressions are handled at the first two compilation stages (parsing), and the compiler can't know a function/label address until it parses its definition at the 2'nd pass; it doesn't keep function addresses obtained at the 1'st pass since at the 2'nd one the generated code can change (e.g. because of#if defined <func>being used for conditional compilation). I think the only solution for this is to add an ability to force a "second" second pass, but this sounds more like a work for a separate PR, IMO.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.
You could build up a list of unresolved addressof calls, just as
CONST.prilocations (or however it is actually implemented), then iterate through them once the function is resolved. A third compiler pass would very probably break a lot of stuff.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.
Or, as I said, would
forwardfix this? I somewhat doubt it as address isn't in the metadata that could be stored in that way. But maybe the pending addresses could be added to the metadata for a function, thus requireforwardfor this case as well (for something like consistency).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 just realised this works:
Uh oh!
There was an error while loading. Please reload this page.
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.
Indeed. As I already mentioned,
__emitimplements its own code generation mechanism, so it isn't bound by the limits of the standard codegen. But either way it generates code, so it can't be used to initialize constants and/or global variables.