Skip to content

Commit

Permalink
fix while bytecode generation and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Dec 29, 2021
1 parent 2420cf4 commit 815db22
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 26 additions & 0 deletions ParserTests/samples/IndentedWhileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,32 @@ public void TestIfThenElse()
Assert.Equal("world", (elseAssign.Value as StringConstant).Value);
}

[Fact]
public void TestNestedIfThenElse()
{
var program = @"
# TestIfThenElse
a := -111
if true then
if true then
a := 1
else
a := 2
else
a := 3
b := ""world""
return a
";
var compiler = new IndentedWhileCompiler();
var func = compiler.CompileToFunction(program,true);
Assert.NotNull(func);
var f = func();
Assert.Equal(1, f);


}


[Fact]
public void TestInfiniteWhile()
{
Expand Down
4 changes: 2 additions & 2 deletions samples/while/compiler/SemanticChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ private void SemanticCheck(IfStatement ast, CompilerContext context)
ast.CompilerScope = context.CurrentScope;

context.OpenNewScope();
SemanticCheck(ast.ThenStmt);
SemanticCheck(ast.ThenStmt,context);
context.CloseScope();

context.OpenNewScope();
SemanticCheck(ast.ElseStmt);
SemanticCheck(ast.ElseStmt,context);
context.CloseScope();
}

Expand Down

0 comments on commit 815db22

Please sign in to comment.