-
Notifications
You must be signed in to change notification settings - Fork 31
scriptcomp: add initializers to for, while, switch statements #136
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
base: master
Are you sure you want to change the base?
Conversation
|
How does it handle nested loops that use the same variable name? Are they scoped properly? for (int x = 0; x < 100; x++)
{
for (int x = 0; x < 10; x++)
{
}
} |
mtijanic
left a comment
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.
Just leaving a few nits here while I actually make sense of the bigger change. This will take a while.
Ran a nested scope test. Results are on discord, but I'll put there here for record-keeping purposes. Test code snippet: for (int x = 0; x < 5; x++)
{
Debug(c(" start outer loop -> x = " + _i(x), COLOR_ORANGE));
for (int x = 3; x > 0; x--)
{
Debug(c(" inner loop -> x = " + _i(x), COLOR_RED_LIGHT));
}
Debug(c(" end outer loop -> x = " + _i(x), COLOR_GREEN_LIGHT));
}I think it meets your intent, but if this test is too simple, let me know. |
a1f56c3 to
9e1cba8
Compare
|
I've run all the tests I can think of here, but I also know how it's supposed to work, so I'm probably missing some ideas on how to break it. If you guys have any tests you'd like run against this PR, let me know and I'll run 'em. |
|
I ran a test on the scrips from my PW, about 1300 files, some are includes of course. % ./nwn_script_comp --version
...
neverwinter 2.0.2 (master/f407d7, nim 2.2.2)
% ./nwn_script_comp -d ~/sfee/out_master -c ~/sfee/unpacked/nss
I [2025-03-14T18:17:16] 1210 successful, 91 skipped, 0 errored
% ./nwn_script_comp --version
...
neverwinter 2.0.2 (initializers-incrementers/efd9bf, nim 2.2.2)
% ./nwn_script_comp -d ~/sfee/out_tinygiant -c ~/sfee/unpacked/nss
I [2025-03-14T18:24:09] 1210 successful, 91 skipped, 0 errored
% diff ~/sfee/out_master ~/sfee/out_tinygiantNo output from diff, all ncs files are the same. I rebased tinygiants PR branch on master for this test, there were no conflicts. Otherwise I got some errors during compile, I think possibly because of a newer nim version. |
|
Compiling the scripts from the frozen north also shows no differences. neverwinter 2.0.2 (initializers-incrementers/efd9bf, nim 2.2.2)
% ./nwn_script_comp -d ~/git/tfn-module/out_tinygiant -c ~/git/tfn-module/src/nss
I [2025-03-14T18:47:11] 2099 successful, 165 skipped, 0 errored
neverwinter 2.0.2 (master/f407d7, nim 2.2.2)
% ./nwn_script_comp -d ~/git/tfn-module/out_master -c ~/git/tfn-module/src/nss
I [2025-03-14T18:50:23] 2099 successful, 165 skipped, 0 errored
% diff out_master out_tinygiant
% |
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.
Hello and thank you for this submission, I had a lot of fun looking through this code and really appreciate all the hard work everyone's putting in to make NWN a better game.
Given that I would also like to contribute to this project I figured I'd share some thoughts an opinions on the code herein:
General feedback and nitpicks submitted. Just some thoughts and opinions on code quality more than anything. Reasoning about the changes herein is very difficult as a newcomer and even harder with the amount of magic numbers that pervade this change.
There is significant complexity in these changes with various cases that are difficult to understand given they all look identical except for the magic numbers. Naming those magic numbers would go a long way to explaining 'what' is going and why each case is unique.
Though I could be wrong and that may not be the case. If that's so, then perhaps comments or some additional helper functions with names might help elevate this issue.
If you have any questions about the contents of this code review, please reach out :) I'm in the official discord as cHackz18 but I will also check in here too.
Thanks again,
Tom W
|
If you resolve the merge conflicts and fix the whitespace nits above, I'll click merge. |
|
Ok, will try to clean all that up this week. |
|
@cHackz18 There really aren't any magic numbers in the parser. The parser is broken up into grammar sections and each section has a set of numbered rules that are usually defined in the comments above the grammar section. Within each rule are a set of terms which are essentially just an ordered set of operations based on the possible token combinations under that rule. If you include me, I believe there are a total of zero people that really understand the compiler in full. If you're interested in understanding more about the parser methodologies, contact me on Discord and we can muddle through it. |
…crementers to for statements This change add the ability to use initialization and arbitrary statements within for, while and switch statements. Any variables defined or initialized within a for, while or switch statement will be scoped within the associated compound statement and any child scopes. add add comment back
9e1cba8 to
498a08a
Compare

This change adds the ability to use initialization and arbitrary statements within for, while and switch statements. Any variables defined or initialized within a for, while or switch statement will be scoped within the associated compound statement and any child scopes.
All legacy constructs are supported. Initialization statements are optional in
for,whileorswitchstatements.Testing
Simple initializer in
forstatement:Initializer/declaration list and comma-separated increment statements in
forstatement:Function calls in initializer and increments statements in
forstatement:Function calls in nested
forloops:Arbitrary statements in initializers and incrementers in
forstatement:Simple initializer in
whilestatement:Function call in initializer for
switchstatementChangelog
Added
for,whileandswitchstatements.forstatements.Licence