-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
thread.go
126 lines (98 loc) · 3.17 KB
/
thread.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package containers
import (
"github.com/inoxlang/inox/internal/core/symbolic"
pprint "github.com/inoxlang/inox/internal/prettyprint"
)
var (
THREAD_PROPNAMES = []string{"add"}
THREAD_ADD_METHOD_ARG_NAMES = []string{"message"}
ANY_THREAD = NewThread(symbolic.ANY_OBJECT_PATTERN)
_ = []symbolic.Iterable{(*MessageThread)(nil)}
_ = []symbolic.Collection{(*MessageThread)(nil)}
_ = []symbolic.Serializable{(*MessageThread)(nil)}
_ = []symbolic.PotentiallySharable{(*MessageThread)(nil)}
_ = []symbolic.UrlHolder{(*MessageThread)(nil)}
_ = []symbolic.IProps{(*MessageThread)(nil)}
_ = []symbolic.PotentiallyConcretizable{(*MessageThreadPattern)(nil)}
_ = []symbolic.MigrationInitialValueCapablePattern{(*MessageThreadPattern)(nil)}
)
type MessageThread struct {
elementPattern *symbolic.ObjectPattern
element *symbolic.Object
url *symbolic.URL
addMethodParamsCache *[]symbolic.Value
symbolic.CollectionMixin
symbolic.SerializableMixin
symbolic.UnassignablePropsMixin
}
func NewThread(elementPattern *symbolic.ObjectPattern) *MessageThread {
t := &MessageThread{
elementPattern: elementPattern,
element: elementPattern.SymbolicValue().(*symbolic.Object),
}
t.addMethodParamsCache = &[]symbolic.Value{t.element}
return t
}
func (t *MessageThread) Test(v symbolic.Value, state symbolic.RecTestCallState) bool {
state.StartCall()
defer state.FinishCall()
otherThread, ok := v.(*MessageThread)
return ok && t.elementPattern.Test(otherThread.elementPattern, symbolic.RecTestCallState{})
}
func (t *MessageThread) GetGoMethod(name string) (*symbolic.GoFunction, bool) {
switch name {
case "add":
return symbolic.WrapGoMethod(t.Add), true
}
return nil, false
}
func (t *MessageThread) Prop(name string) symbolic.Value {
return symbolic.GetGoMethodOrPanic(name, t)
}
func (*MessageThread) PropertyNames() []string {
return THREAD_PROPNAMES
}
func (t *MessageThread) IsSharable() (bool, string) {
return true, ""
}
func (t *MessageThread) Share(originState *symbolic.State) symbolic.PotentiallySharable {
return t
}
func (t *MessageThread) IsShared() bool {
return true
}
func (t *MessageThread) WithURL(url *symbolic.URL) symbolic.UrlHolder {
copy := *t
copy.url = url
elementURL := copy.url.WithAdditionalPathPatternSegment("*")
copy.element = t.element.WithURL(elementURL).(*symbolic.Object)
return ©
}
func (s *MessageThread) URL() (*symbolic.URL, bool) {
if s.url != nil {
return s.url, true
}
return nil, false
}
func (t *MessageThread) Contains(value symbolic.Serializable) (yes bool, possible bool) {
if !t.element.Test(value, symbolic.RecTestCallState{}) {
return
}
possible = true
return
}
func (t *MessageThread) Add(ctx *symbolic.Context, elem *symbolic.Object) {
ctx.SetSymbolicGoFunctionParameters(t.addMethodParamsCache, THREAD_ADD_METHOD_ARG_NAMES)
}
func (*MessageThread) PrettyPrint(w pprint.PrettyPrintWriter, config *pprint.PrettyPrintConfig) {
w.WriteName("thread")
}
func (t *MessageThread) IteratorElementKey() symbolic.Value {
return symbolic.ANY_ULID
}
func (t *MessageThread) IteratorElementValue() symbolic.Value {
return t.element
}
func (*MessageThread) WidestOfType() symbolic.Value {
return ANY_THREAD
}