Skip to content

Commit

Permalink
Correction des blocs déférés n’ayant pas accès à la portée de la fonc…
Browse files Browse the repository at this point in the history
…tion parente
  • Loading branch information
Enalye committed Feb 26, 2024
1 parent 6b6f2bc commit da9e652
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions source/grimoire/compiler/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,7 @@ final class GrParser {
current = func.lexPosition;
parseWhereStatement(func.templateVariables);
openDeferrableSection();
parseBlock(false, true);
parseBlock(false, false, true);
if (func.isTask || func.isEvent) {
if (!currentFunction.instructions.length ||
currentFunction.instructions[$ - 1].opcode != GrOpcode.die)
Expand Down Expand Up @@ -3314,7 +3314,7 @@ final class GrParser {
preBeginFunction("$anon", nameLexPosition, get().fileId, inSignature,
inputs, isTask, outSignature, true, isEvent);
openDeferrableSection();
parseBlock();
parseBlock(false);

if (isTask || isEvent) {
if (!currentFunction.instructions.length ||
Expand Down Expand Up @@ -3349,7 +3349,8 @@ final class GrParser {
/**
Parse either multiple lines between `{` and `}` or a single expression.
*/
private void parseBlock(bool changeOptimizationBlockLevel = false, bool mustBeMultiline = false) {
private void parseBlock(bool createScope = true,
bool changeOptimizationBlockLevel = false, bool mustBeMultiline = false) {
if (changeOptimizationBlockLevel)
_isAssignationOptimizable = false;
bool isMultiline;
Expand All @@ -3365,7 +3366,9 @@ final class GrParser {
getPrettyLexemeType(GrLexeme.Type.leftCurlyBrace),
getPrettyLexemeType(get().type)));
}
openBlock();

if (createScope)
openBlock();

void parseStatement() {
switch (get().type) with (GrLexeme.Type) {
Expand Down Expand Up @@ -3459,7 +3462,10 @@ final class GrParser {
getPrettyLexemeType(get().type)));
checkAdvance();
}
closeBlock();

if (createScope)
closeBlock();

if (changeOptimizationBlockLevel)
_isAssignationOptimizable = false;
}
Expand Down Expand Up @@ -3691,7 +3697,7 @@ final class GrParser {
addInstruction(GrOpcode.globalPop);
addSetInstruction(errVariable, fileId, grString);

parseBlock(true);
parseBlock(true, true);

const auto endPosition = currentFunction.instructions.length;

Expand Down Expand Up @@ -3777,7 +3783,7 @@ final class GrParser {
scopeLevel = deferBlock.scopeLevel;

currentFunction.isDeferrableSectionLocked[$ - 1] = true;
parseBlock(true);
parseBlock(true, true);
currentFunction.isDeferrableSectionLocked[$ - 1] = false;

addInstruction(GrOpcode.unwind);
Expand Down Expand Up @@ -3939,7 +3945,7 @@ final class GrParser {
uint jumpPosition = cast(uint) currentFunction.instructions.length;
addInstruction(isNegative ? GrOpcode.jumpNotEqual : GrOpcode.jumpEqual);

parseBlock(true); //{ .. }
parseBlock(true, true); //{ .. }

// Si des `else` sont présent, alors on doit pouvoir sortir du bloc avec un saut
uint[] exitJumps;
Expand Down Expand Up @@ -3977,7 +3983,7 @@ final class GrParser {
// Si le `if` ou `unless` n’est pas vérifié, on saute vers la fin du bloc
addInstruction(isNegative ? GrOpcode.jumpNotEqual : GrOpcode.jumpEqual);

parseBlock(true); //{ .. }
parseBlock(true, true); //{ .. }

// On sort du bloc avec un saut
exitJumps ~= cast(uint) currentFunction.instructions.length;
Expand All @@ -3988,7 +3994,7 @@ final class GrParser {
cast(int)(currentFunction.instructions.length - jumpPosition), true);
}
else
parseBlock(true);
parseBlock(true, true);
}
}
while (isElseIf);
Expand Down Expand Up @@ -4109,7 +4115,7 @@ final class GrParser {
jumpPosition = cast(uint) currentFunction.instructions.length;
addInstruction(GrOpcode.jumpEqual);

parseBlock(true);
parseBlock(true, true);

exitJumps ~= cast(uint) currentFunction.instructions.length;
addInstruction(GrOpcode.jump);
Expand All @@ -4122,7 +4128,7 @@ final class GrParser {
if (hasDefaultCase) {
const uint tmp = current;
current = defaultCasePosition;
parseBlock(true);
parseBlock(true, true);
current = tmp;
}

Expand Down Expand Up @@ -4182,7 +4188,7 @@ final class GrParser {

addInstruction(GrOpcode.checkChannel);

parseBlock(true);
parseBlock(true, true);

exitJumps ~= cast(uint) currentFunction.instructions.length;
addInstruction(GrOpcode.jump);
Expand All @@ -4196,7 +4202,7 @@ final class GrParser {
// De même, ça rend l’opération `select` non-bloquante care au moins un cas est garanti de s’exécuter.
const uint tmp = current;
current = defaultCasePosition;
parseBlock(true);
parseBlock(true, true);
current = tmp;
}
else {
Expand Down Expand Up @@ -4254,7 +4260,7 @@ final class GrParser {
conditionPosition = cast(uint) currentFunction.instructions.length;
addInstruction(GrOpcode.jumpEqual);

parseBlock(true);
parseBlock(true, true);

if (isYieldable)
addInstruction(GrOpcode.yield);
Expand Down Expand Up @@ -4290,7 +4296,7 @@ final class GrParser {

uint blockPosition = cast(uint) currentFunction.instructions.length;

parseBlock(true);
parseBlock(true, true);

bool isNegative;
if (get().type == GrLexeme.Type.until)
Expand Down Expand Up @@ -4439,7 +4445,7 @@ final class GrParser {
convertType(subType, variable.type, fileId);
addSetInstruction(variable, fileId);

parseBlock(true);
parseBlock(true, true);

if (isYieldable)
addInstruction(GrOpcode.yield);
Expand Down Expand Up @@ -4764,7 +4770,7 @@ final class GrParser {
}
}

parseBlock(true);
parseBlock(true, true);

if (isYieldable)
addInstruction(GrOpcode.yield);
Expand Down

0 comments on commit da9e652

Please sign in to comment.