Skip to content

Commit

Permalink
scriptcomp: add initializers to for, while, switch statements; add in…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
tinygiant98 committed Oct 12, 2024
1 parent 94e6cbd commit 9e1cba8
Show file tree
Hide file tree
Showing 6 changed files with 358 additions and 55 deletions.
1 change: 1 addition & 0 deletions neverwinter/nwscript/compiler.nim
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const
OptimizationFlagsO2* = fullSet(OptimizationFlag)

const CompileErrorTlk* = {
559: "ERROR: CONDITIONAL EXPRESSION MISSING",
560: "ERROR: UNEXPECTED CHARACTER",
561: "ERROR: FATAL COMPILER ERROR",
562: "ERROR: PROGRAM COMPOUND STATEMENT AT START",
Expand Down
2 changes: 2 additions & 0 deletions neverwinter/nwscript/native/scriptcomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,8 @@ class CScriptCompiler
int32_t DetermineLocationOfCode();
int32_t ResolveLabels();
int32_t WriteResolvedOutput();
//int32_t CloseVariableScope(int32_t nStackPointer);
void CloseVariableScope();

int32_t m_nFinalBinarySize;

Expand Down
1 change: 1 addition & 0 deletions neverwinter/nwscript/native/scriptcompcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,7 @@ const char *GrammarToString(int nGrammar)
case CSCRIPTCOMPILER_GRAMMAR_POST_EXPRESSION: return "POST_EXPRESSION";
case CSCRIPTCOMPILER_GRAMMAR_PRIMARY_EXPRESSION: return "PRIMARY_EXPRESSION";
case CSCRIPTCOMPILER_GRAMMAR_CONSTANT: return "CONSTANT";
case CSCRIPTCOMPILER_GRAMMAR_WITHIN_STATEMENT_GROUP: return "WITHIN_STATEMENT_GROUP";
}
return "(unknown grammar)";
}
Expand Down
11 changes: 8 additions & 3 deletions neverwinter/nwscript/native/scriptcompfinalcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2357,8 +2357,6 @@ int32_t CScriptCompiler::InVisitGenerateCode(CScriptParseTreeNode *pNode)
}

}


}

if (pNode->nOperation == CSCRIPTCOMPILER_OPERATION_COND_CHOICE)
Expand Down Expand Up @@ -3485,6 +3483,7 @@ int32_t CScriptCompiler::PostVisitGenerateCode(CScriptParseTreeNode *pNode)
{
// Handled in the InVisit call, so we don't need to do anything
// here to handle this case.

return 0;
}

Expand All @@ -3497,11 +3496,17 @@ int32_t CScriptCompiler::PostVisitGenerateCode(CScriptParseTreeNode *pNode)

if (pNode->nOperation == CSCRIPTCOMPILER_OPERATION_COMPOUND_STATEMENT)
{

// We keep track of all of the variables added at this recursion level, and
// peel them off one by one. This is actually done within the script itself
// as well, since we need to keep track of what's happening. However, we
// don't need to worry about the address of a variable.

// Experiement - gatekeeping at a point other than this node.
if (pNode->nIntegerData4 == -1)
{
return 0;
}


int32_t nStackAtStart = m_nStackCurrentDepth;

Expand Down
Loading

0 comments on commit 9e1cba8

Please sign in to comment.