-
Notifications
You must be signed in to change notification settings - Fork 1
/
vector.go
118 lines (93 loc) · 2 KB
/
vector.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
package prism
import (
"github.com/llir/llvm/ir/types"
)
type VectorType struct {
Type
}
// IsVector is shorthand for vector interface check
func IsVector(t Type) bool {
_, ok := t.(VectorType)
return ok
}
func VectorDepth(t Type) int {
if !IsVector(t) {
return 0
}
return 1 + VectorDepth(t.(VectorType).Type)
}
func QueryAutoVector(atom, vec Type) bool {
if !IsVector(vec) {
return false
}
if VectorDepth(atom) == VectorDepth(vec) {
return false
}
t := vec.(VectorType).Type
_, err := Delegate(atom, t)
if err != nil {
panic(*err)
}
return true
}
// Interface prism.Type algebraic predicate
func (a VectorType) IsAlgebraic() bool {
return a.Type.IsAlgebraic()
}
// Vec shorthand
func Vec(t Type) Type {
return VectorType{Type: t}
}
func (v VectorType) SubIsVoid() bool {
return v.Type.Kind() == VoidType.ID
}
func (v VectorType) Realise() types.Type {
if v.SubIsVoid() {
return types.Void
}
return types.NewStruct(
types.I32, types.I32,
types.NewPointer(v.Type.Realise()))
}
type Vector struct {
ElementType VectorType
Body *[]Expression
}
// Resolve composes Integrate with Derive,
// Fills in sum/generic type based on a concrete type
func (v VectorType) Resolve(t Type) Type {
return VectorType{Type: Integrate(v.Type, Derive(v, t))}
}
// String function for interface
func (v Vector) String() string {
var s string
for _, v := range *v.Body {
s += v.String() + " "
}
return s
}
// String function for interface
func (v VectorType) String() string {
return "[" + v.Type.String() + "]"
}
// Type property for interface
func (v Vector) Type() Type {
return v.ElementType
}
// Interface prism.Type width for LLVM codegen
func (v VectorType) Width() int64 {
return 16
// (32 + 32 + 64) / 8
// len + cap + ptr
}
// Interface prism.Type comparison
func (a VectorType) Equals(b Type) bool {
if t, ok := b.(VectorType); ok {
return a.Type.Equals(t.Type)
}
return false
}
func (v VectorType) Kind() int {
return TypeKindVector
}
func (t Vector) _atomicflag() {}