forked from go-python/gpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compile: add line numbers to compiler and create line number table (l…
…notab)
- Loading branch information
Showing
5 changed files
with
168 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package compile | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func TestLnotab(t *testing.T) { | ||
for i, test := range []struct { | ||
instrs Instructions | ||
want []byte | ||
}{ | ||
{ | ||
instrs: Instructions{}, | ||
want: []byte{}, | ||
}, | ||
{ | ||
instrs: Instructions{ | ||
&Op{pos: pos{n: 1, p: 10, lineno: 1}}, | ||
&Op{pos: pos{n: 0, p: 10, lineno: 0}}, | ||
&Op{pos: pos{n: 1, p: 102, lineno: 1}}, | ||
}, | ||
want: []byte{}, | ||
}, | ||
{ | ||
instrs: Instructions{ | ||
&Op{pos: pos{n: 1, p: 0, lineno: 1}}, | ||
&Op{pos: pos{n: 1, p: 1, lineno: 2}}, | ||
&Op{pos: pos{n: 1, p: 2, lineno: 3}}, | ||
}, | ||
want: []byte{1, 1, 1, 1}, | ||
}, | ||
{ | ||
// Example from lnotab.txt | ||
instrs: Instructions{ | ||
&Op{pos: pos{n: 1, p: 0, lineno: 1}}, | ||
&Op{pos: pos{n: 1, p: 6, lineno: 2}}, | ||
&Op{pos: pos{n: 1, p: 50, lineno: 7}}, | ||
&Op{pos: pos{n: 1, p: 350, lineno: 307}}, | ||
&Op{pos: pos{n: 1, p: 361, lineno: 308}}, | ||
}, | ||
want: []byte{ | ||
6, 1, | ||
44, 5, | ||
255, 0, | ||
45, 255, | ||
0, 45, | ||
11, 1}, | ||
}, | ||
} { | ||
got := test.instrs.Lnotab() | ||
if bytes.Compare(test.want, got) != 0 { | ||
t.Errorf("%d: want %d got %d", i, test.want, got) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters