forked from APrioriInvestments/typed_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathType.cpp
More file actions
146 lines (112 loc) · 3.4 KB
/
Copy pathType.cpp
File metadata and controls
146 lines (112 loc) · 3.4 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "AllTypes.hpp"
void Type::repr(instance_ptr self, ReprAccumulator& out) {
assertForwardsResolved();
this->check([&](auto& subtype) {
subtype.repr(self, out);
});
}
bool Type::cmp(instance_ptr left, instance_ptr right, int pyComparisonOp) {
assertForwardsResolved();
return this->check([&](auto& subtype) {
return subtype.cmp(left, right, pyComparisonOp);
});
}
int32_t Type::hash32(instance_ptr left) {
assertForwardsResolved();
return this->check([&](auto& subtype) {
return subtype.hash32(left);
});
}
void Type::swap(instance_ptr left, instance_ptr right) {
assertForwardsResolved();
if (left == right) {
return;
}
size_t remaining = m_size;
while (remaining >= 8) {
int64_t temp = *(int64_t*)left;
*(int64_t*)left = *(int64_t*)right;
*(int64_t*)right = temp;
remaining -= 8;
left += 8;
right += 8;
}
while (remaining > 0) {
int8_t temp = *(int8_t*)left;
*(int8_t*)left = *(int8_t*)right;
*(int8_t*)right = temp;
remaining -= 1;
left += 1;
right += 1;
}
}
// static
char Type::byteCompare(uint8_t* l, uint8_t* r, size_t count) {
while (count >= 8 && *(uint64_t*)l == *(uint64_t*)r) {
l += 8;
r += 8;
count -= 8;
}
for (long k = 0; k < count; k++) {
if (l[k] < r[k]) {
return -1;
}
if (l[k] > r[k]) {
return 1;
}
}
return 0;
}
void Type::constructor(instance_ptr self) {
assertForwardsResolved();
this->check([&](auto& subtype) { subtype.constructor(self); } );
}
void Type::destroy(instance_ptr self) {
assertForwardsResolved();
this->check([&](auto& subtype) { subtype.destroy(self); } );
}
void Type::forwardTypesMayHaveChanged() {
m_references_unresolved_forwards = false;
visitReferencedTypes([&](Type* t) {
if (t->references_unresolved_forwards()) {
m_references_unresolved_forwards = true;
}
});
this->check([&](auto& subtype) {
subtype._forwardTypesMayHaveChanged();
});
if (mTypeRep) {
updateTypeRepForType(this, mTypeRep);
}
}
void Type::copy_constructor(instance_ptr self, instance_ptr other) {
assertForwardsResolved();
this->check([&](auto& subtype) { subtype.copy_constructor(self, other); } );
}
void Type::assign(instance_ptr self, instance_ptr other) {
assertForwardsResolved();
this->check([&](auto& subtype) { subtype.assign(self, other); } );
}
bool Type::isBinaryCompatibleWith(Type* other) {
if (other == this) {
return true;
}
while (other->getTypeCategory() == TypeCategory::catPythonSubclass) {
other = other->getBaseType();
}
auto it = mIsBinaryCompatible.find(other);
if (it != mIsBinaryCompatible.end()) {
return it->second != BinaryCompatibilityCategory::Incompatible;
}
//mark that we are recursing through this datastructure. we don't want to
//loop indefinitely.
mIsBinaryCompatible[other] = BinaryCompatibilityCategory::Checking;
bool isCompatible = this->check([&](auto& subtype) {
return subtype.isBinaryCompatibleWithConcrete(other);
});
mIsBinaryCompatible[other] = isCompatible ?
BinaryCompatibilityCategory::Compatible :
BinaryCompatibilityCategory::Incompatible
;
return isCompatible;
}