Skip to content

Commit

Permalink
asm: disassemble unterminated instructions at end of file as .dat opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
db47h committed Aug 23, 2016
1 parent 8d23dd0 commit 0ba3ee0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion asm/asm.go
Expand Up @@ -112,7 +112,9 @@ func Disassemble(i []vm.Cell, pc int, w io.Writer) (next int, err error) {
_, err = w.Write(b)
return pc + 1, err
}
b = append(b, "???"...)
// unterminated, it must be a .dat ...
b = append(b[:0], ".dat "...)
b = strconv.AppendInt(b, int64(int(op)), 10)
}
_, err = w.Write(b)
return pc, err
Expand Down
5 changes: 3 additions & 2 deletions asm/example_test.go
Expand Up @@ -110,7 +110,8 @@ func ExampleDisassemble() {
pop
:1 loop 0- ( local label back )
swap drop ;
lit ( lit deliberately unterminated at end of image for testing purposes )
lit ( lit deliberately unterminated at end of image for testing purposes.
should disassemble unequivocally as .dat 1 )
`
img, err := asm.Assemble("fib", strings.NewReader(fibS))
if err != nil {
Expand Down Expand Up @@ -148,7 +149,7 @@ func ExampleDisassemble() {
// 17 swap
// 18 drop
// 19 ;
// 20 ???
// 20 .dat 1
// Partial disassembly with DisassembleAll:
// 15 loop 8
// 17 swap
Expand Down

0 comments on commit 0ba3ee0

Please sign in to comment.