-
Notifications
You must be signed in to change notification settings - Fork 22
/
peek.go
69 lines (51 loc) · 2.13 KB
/
peek.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package macros
import (
. "github.com/kocircuit/kocircuit/lang/circuit/eval"
. "github.com/kocircuit/kocircuit/lang/circuit/model"
. "github.com/kocircuit/kocircuit/lang/go/eval"
. "github.com/kocircuit/kocircuit/lang/go/eval/symbol"
. "github.com/kocircuit/kocircuit/lang/go/kit/util"
)
func init() {
RegisterEvalMacro("Peek", EvalPeekMacro{})
RegisterEvalMacro("PeekType", EvalPeekTypeMacro{})
}
type EvalPeekMacro struct{}
func (m EvalPeekMacro) MacroID() string { return m.Help() }
func (m EvalPeekMacro) Label() string { return "peek" }
func (m EvalPeekMacro) MacroSheathString() *string { return PtrString("Peek") }
func (m EvalPeekMacro) Help() string { return "Peek" }
const peekDoc = `
Ko provides two builtin functions, Peek and PeekType, to enable
convenient integration of debugging into your program flow.
These functions are the "printf" of Ko, for debugging purposes.
Peek and PeekType are essentially identical to their counterparts Show and ShowType,
described in the previous article on logging.
The only difference is that Peek and PeekType
also print the program stack, describing the location from which they were invoked
as well as source code location information.`
func (m EvalPeekMacro) Doc() string { return peekDoc }
func (EvalPeekMacro) Invoke(span *Span, arg Arg) (returns Return, effect Effect, err error) {
join := EvalJoinMacro{}
if returns, effect, err = join.Invoke(span, arg); err != nil {
return nil, nil, err
} else {
span.Printf("%v\n", returns)
return
}
}
type EvalPeekTypeMacro struct{}
func (m EvalPeekTypeMacro) MacroID() string { return m.Help() }
func (m EvalPeekTypeMacro) Label() string { return "peektype" }
func (m EvalPeekTypeMacro) MacroSheathString() *string { return PtrString("PeekType") }
func (m EvalPeekTypeMacro) Help() string { return "PeekType" }
func (m EvalPeekTypeMacro) Doc() string { return peekDoc }
func (EvalPeekTypeMacro) Invoke(span *Span, arg Arg) (returns Return, effect Effect, err error) {
join := EvalJoinMacro{}
if returns, effect, err = join.Invoke(span, arg); err != nil {
return nil, nil, err
} else {
span.Printf("%v\n", returns.(Symbol).Type())
return
}
}