Refactored break/continue compilation.

I didn't like the null overload usage. I might remove the overload
completely later.
This commit is contained in:
arookas 2016-01-31 21:25:50 -05:00
parent eb3e679fc7
commit b2330dfa6c

View file

@ -155,7 +155,14 @@ namespace arookas {
public override void Compile(sunCompiler compiler) {
var point = compiler.Binary.WriteJMP();
if (!compiler.Context.Loops.AddBreak(point, IsNamed ? NameLabel.Value : null)) {
var success = true;
if (IsNamed) {
success = compiler.Context.Loops.AddBreak(point, NameLabel.Value);
}
else {
success = compiler.Context.Loops.AddBreak(point);
}
if (!success) {
throw new sunBreakException(this);
}
}
@ -170,7 +177,14 @@ namespace arookas {
public override void Compile(sunCompiler compiler) {
var point = compiler.Binary.WriteJMP();
if (!compiler.Context.Loops.AddContinue(point, IsNamed ? NameLabel.Value : null)) {
var success = true;
if (IsNamed) {
success = compiler.Context.Loops.AddContinue(point, NameLabel.Value);
}
else {
success = compiler.Context.Loops.AddContinue(point);
}
if (!success) {
throw new sunContinueException(this);
}
}