Skip to content

Commit 64b708c

Browse files
committed
Addes tracing for symbol resolving
1 parent 8285a28 commit 64b708c

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

Assembler/Document.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ public void SetOrigin(long value) {
137137
/// Writes the values as bytes to output
138138
/// </summary>
139139
/// <param name="values"></param>
140-
public void PutByte(IValue[] values) {
140+
public void PutByte(IValue[] values, Trace trace) {
141141
foreach (IValue value in values) {
142142
IConstant constant = value as IConstant;
143143

144144
if (constant == null) {
145-
symbolTable.Add(writer.FileOffset, value);
145+
symbolTable.Add(writer.FileOffset, value, trace);
146146
writer.WriteByte(0);
147147
continue;
148148
}
@@ -157,7 +157,7 @@ public void PutByte(IValue[] values) {
157157
continue;
158158
}
159159

160-
throw new Exception("This shouldn't happen");
160+
throw new BadProgrammerException("Don't know how to convert value to bytes");
161161
}
162162
}
163163

@@ -170,10 +170,10 @@ public void Resolve() {
170170
foreach (SymbolTable.Entry entry in symbolTable) {
171171
IConstant value = entry.Reference.GetValue(referenceTable) as Number;
172172
if (value == null)
173-
throw new AssemblerException(string.Format("Unknown symbol in '{0}'", entry.Reference), Trace.Empty);
173+
throw new AssemblerException("Unknown symbol in '{0}'", entry.Trace, entry.Reference);
174174

175175
if (!(value is Number number))
176-
throw new AssemblerException("Invalid data type for symbol", Trace.Empty);
176+
throw new AssemblerException("Invalid data type for symbol", entry.Trace);
177177

178178
writer.Seek(entry.Offset);
179179
writer.SetByte(number.Value);

Assembler/Interpreters/BaseInterpreter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected virtual void PutByte(AssemblyLine line) {
7373
return constant;
7474

7575
return Translate(argument).Resolve(scope);
76-
}).ToArray());
76+
}).ToArray(), trace.Create(line));
7777
}
7878

7979
private Exception Throw(AssemblyLine line) {

Assembler/SymbolTable.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ public SymbolTable() {
1414
entries = new List<Entry>();
1515
}
1616

17-
public void Add(long offset, IValue reference) {
17+
public void Add(long offset, IValue reference, Trace trace) {
1818
entries.Add(new Entry {
1919
Offset = offset,
20-
Reference = reference
20+
Reference = reference,
21+
Trace = trace
2122
});
2223
}
2324

@@ -42,6 +43,7 @@ IEnumerator IEnumerable.GetEnumerator() {
4243
public class Entry {
4344
public long Offset { get; set; }
4445
public IValue Reference { get; set; }
46+
public Trace Trace { get; internal set; }
4547
}
4648
}
4749
}

0 commit comments

Comments
 (0)