Skip to content

Commit fa0d7dd

Browse files
authored
Merge pull request EvilBeaver#1665 from Diversus23/develop
fix EvilBeaver#1468 EvilBeaver#6 EvilBeaver#1329: Реализация оператора Перейти / Goto
2 parents 144fc70 + 4f4ebff commit fa0d7dd

5 files changed

Lines changed: 879 additions & 23 deletions

File tree

src/ScriptEngine/Compiler/CodeGeneratorPrivateTypes.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,35 @@ public static NestedLoopInfo New()
4242
public List<int> breakStatements;
4343
public int tryNesting;
4444
}
45+
46+
private enum BlockType
47+
{
48+
While,
49+
ForEach,
50+
For,
51+
If,
52+
ElseIf,
53+
Else,
54+
Try,
55+
Except
56+
}
57+
58+
private class LabelInfo
59+
{
60+
public int codeIndex = DUMMY_ADDRESS;
61+
public List<(BlockType type, int id)> blockStack;
62+
public int tryNesting;
63+
}
64+
65+
private struct PendingGoto
66+
{
67+
public int commandIndex;
68+
public int exitTryIndex;
69+
public string labelName;
70+
public List<(BlockType type, int id)> blockStack;
71+
public List<(int commandIndex, BlockType loopType, int blockId)> loopCleanupSlots;
72+
public CodeRange location;
73+
public int tryNesting;
74+
}
4575
}
4676
}

src/ScriptEngine/Compiler/CompilerErrors.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ public static CodeError MissedImport(string symbol, string libName) =>
2929
Create($"Свойство {symbol} принадлежит пакету {libName}, который не импортирован в данном модуле",
3030
$"Property {symbol} belongs to package {libName} which is not imported in this module");
3131

32+
public static CodeError DuplicateLabelDefinition(string name) =>
33+
Create($"Дублирование определения метки ~{name}",
34+
$"Duplicate label definition ~{name}");
35+
36+
public static CodeError UndefinedLabel(string name) =>
37+
Create($"Метка не определена ~{name}",
38+
$"Undefined label ~{name}");
39+
40+
public static CodeError InvalidGotoTarget(string name) =>
41+
Create($"На метку с указанным именем имеется недопустимый переход (~{name})",
42+
$"Invalid goto target (~{name})");
43+
3244
private static CodeError Create(string ru, string en, [CallerMemberName] string errorId = default)
3345
{
3446
return new CodeError

0 commit comments

Comments
 (0)