/
mapping.go
96 lines (74 loc) · 1.76 KB
/
mapping.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package symbolic
import (
"errors"
pprint "github.com/inoxlang/inox/internal/prettyprint"
)
var (
ANY_MAPPING = &Mapping{}
MAPPING_PROPNAMES = []string{"compute"}
)
//TODO: implement PotentiallySharable interface
// A Mapping represents a symbolic Mapping.
type Mapping struct {
shared bool
SerializableMixin
}
func NewMapping() *Mapping {
return &Mapping{}
}
func (m *Mapping) Test(v Value, state RecTestCallState) bool {
state.StartCall()
defer state.FinishCall()
_, ok := v.(*Mapping)
return ok
}
func (m *Mapping) PrettyPrint(w pprint.PrettyPrintWriter, config *pprint.PrettyPrintConfig) {
w.WriteName("mapping")
return
}
func (m *Mapping) WidestOfType() Value {
return &Mapping{}
}
func (m *Mapping) IteratorElementKey() Value {
return ANY
}
func (m *Mapping) IteratorElementValue() Value {
return ANY
}
func (m *Mapping) IsSharable() (bool, string) {
//TODO: reconcilate with concrete version
return true, ""
}
func (m *Mapping) Share(originState *State) PotentiallySharable {
if m.shared {
return m
}
return &Mapping{
shared: true,
}
}
func (m *Mapping) IsShared() bool {
return m.shared
}
func (m *Mapping) GetGoMethod(name string) (*GoFunction, bool) {
switch name {
case "compute":
return WrapGoMethod(m.Compute), true
}
return nil, false
}
func (m *Mapping) Prop(name string) Value {
return GetGoMethodOrPanic(name, m)
}
func (m *Mapping) SetProp(name string, value Value) (IProps, error) {
return nil, errors.New(FmtCannotAssignPropertyOf(m))
}
func (m *Mapping) WithExistingPropReplaced(name string, value Value) (IProps, error) {
return nil, errors.New(FmtCannotAssignPropertyOf(m))
}
func (*Mapping) PropertyNames() []string {
return MAPPING_PROPNAMES
}
func (m *Mapping) Compute(ctx *Context, key Value) Value {
return ANY
}