-
Notifications
You must be signed in to change notification settings - Fork 8
/
wasm_tree.go
64 lines (53 loc) · 1.16 KB
/
wasm_tree.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
//go:build tinywasm
package gtree
import (
"io"
)
type tree struct {
roots []*Node
grower grower
spreader spreader
}
// 関心事は各ノードの枝の形成
type grower interface {
grow([]*Node) error
enableValidation()
}
// 関心事はtreeの出力
type spreader interface {
spread(io.Writer, []*Node) error
}
func newTree(cfg *config, roots []*Node) *tree {
growerFactory := func(lastNodeFormat, intermedialNodeFormat branchFormat, dryrun bool, encode encode) grower {
if encode != encodeDefault {
return newNopGrower()
}
return newGrower(lastNodeFormat, intermedialNodeFormat, dryrun)
}
spreaderFactory := func(encode encode, dryrun bool, fileExtensions []string) spreader {
if dryrun {
return newColorizeSpreader(fileExtensions)
}
return newSpreader(encode)
}
return &tree{
roots: roots,
grower: growerFactory(
cfg.lastNodeFormat,
cfg.intermedialNodeFormat,
cfg.dryrun,
cfg.encode,
),
spreader: spreaderFactory(
cfg.encode,
cfg.dryrun,
cfg.fileExtensions,
),
}
}
func (t *tree) grow() error {
return t.grower.grow(t.roots)
}
func (t *tree) spread(w io.Writer) error {
return t.spreader.spread(w, t.roots)
}