Skip to content

Commit 5ae07bc

Browse files
committed
feat(machine): pretty-print Fn and Cmd
1 parent 236591b commit 5ae07bc

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

machine/cmd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package machine
22

3+
import "fmt"
4+
35
// Cmd (a.k.a. "Command") is a
46
//
57
// 1. sequence of executable instructions
@@ -61,3 +63,7 @@ func (cmd Cmd) call() Object {
6163

6264
return cmd.stack.Pop()
6365
}
66+
67+
func (cmd Cmd) String() string {
68+
return fmt.Sprintf("Cmd<%d>(%d/%d)", cmd.ip, len(cmd.args), cmd.argc)
69+
}

machine/fn.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package machine
22

3+
import "fmt"
4+
35
// Fn (a.k.a "Builtin Function") is a special type that implement the Function
46
// interface. It is used to carry stdlib functions.
57
type Fn struct {
@@ -28,3 +30,7 @@ func (fn Fn) Feed(arg Object) Object {
2830
func (fn Fn) call() Object {
2931
return fn.eval(fn.args)
3032
}
33+
34+
func (fn Fn) String() string {
35+
return fmt.Sprintf("Fn(%d/%d)", len(fn.args), fn.argc)
36+
}

0 commit comments

Comments
 (0)