Skip to content

Commit 6be479b

Browse files
committed
Added traceing for ifelse condition evaluation
1 parent 64b708c commit 6be479b

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Assembler/ConditionalSectionTranscriber.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public ConditionalSectionTranscriber(IScope scope, IInterpreter interpreter) {
1616
this.interpreter = interpreter;
1717
}
1818

19-
public void Transcribe(ConditionalSection section) {
19+
public void Transcribe(ConditionalSection section, Trace trace) {
2020
bool success = true;
2121

2222
if (section.Condition != null) {
2323
IConstant result = interpreter.Translate(section.Condition).GetValue(scope);
2424

2525
if (!(result is Number number))
26-
throw new Exception(string.Format("Failed to resolve condition '{0}'", section.Condition));
26+
throw new AssemblerException("Failed to resolve condition '{0}'", trace, section.Condition);
2727

2828
success = number.Value != 0;
2929
}
@@ -32,7 +32,7 @@ public void Transcribe(ConditionalSection section) {
3232
foreach (AssemblyLine line in section)
3333
interpreter.Process(line);
3434
} else if (section.Next != null) {
35-
Transcribe(section.Next);
35+
Transcribe(section.Next, trace);
3636
}
3737
}
3838
}

Assembler/Interpreters/MacroInterpreter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected override void StartEnum(AssemblyLine line) {
6161

6262
protected override void ProcessSection(AssemblyLine line) {
6363
ConditionalSectionTranscriber transcriber = new ConditionalSectionTranscriber(scope, this);
64-
transcriber.Transcribe(line.Section);
64+
transcriber.Transcribe(line.Section, trace.Create(line));
6565
}
6666

6767
protected override void StartInclude(AssemblyLine line) {

Assembler/Values/Expression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ private IConstant Execute(Number left, Number right) {
8080
case Operation.NotEqual: return new Number(left.Value != right.Value ? 1 : 0, NumberFormat.Decimal);
8181
case Operation.LessOrEqual: return new Number(left.Value <= right.Value ? 1 : 0, NumberFormat.Decimal);
8282
case Operation.GreaterOrEqual: return new Number(left.Value >= right.Value ? 1 : 0, NumberFormat.Decimal);
83-
default: throw new Exception("Unsupported operation");
83+
default: throw new BadProgrammerException("Unsupported operation");
8484
}
8585
}
8686

8787
private IConstant Execute(Text left, Text right) {
8888
switch (operation) {
8989
case Operation.Equal: return new Number(left.Value == right.Value ? 1 : 0, NumberFormat.Decimal);
90-
default: throw new Exception("Unsupported operation");
90+
default: throw new BadProgrammerException("Unsupported operation");
9191
}
9292
}
9393

0 commit comments

Comments
 (0)