@oseo/runtime-c 0.0.0-stage → 0.1.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/MIT-LICENSE.txt +21 -0
- package/README.md +1677 -2
- package/UNICODE-LICENSE.txt +39 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +269 -0
- package/dist/index.js.map +1 -0
- package/native/oseo_runtime.h +2594 -0
- package/native/runtime_agent.c +1693 -0
- package/native/runtime_arguments.c +355 -0
- package/native/runtime_array.c +5742 -0
- package/native/runtime_array_buffer.c +1724 -0
- package/native/runtime_async_generator.c +948 -0
- package/native/runtime_atomics.c +1259 -0
- package/native/runtime_bigint.c +1363 -0
- package/native/runtime_bigint_object.c +602 -0
- package/native/runtime_binding.c +1005 -0
- package/native/runtime_boolean.c +296 -0
- package/native/runtime_clock.c +157 -0
- package/native/runtime_clock_posix.c +575 -0
- package/native/runtime_core.c +464 -0
- package/native/runtime_data_view.c +1111 -0
- package/native/runtime_date.c +1973 -0
- package/native/runtime_descriptor.c +1080 -0
- package/native/runtime_disposal.c +1643 -0
- package/native/runtime_enumeration.c +612 -0
- package/native/runtime_error.c +973 -0
- package/native/runtime_event_loop.c +629 -0
- package/native/runtime_function.c +3643 -0
- package/native/runtime_generator.c +1096 -0
- package/native/runtime_internal.h +5554 -0
- package/native/runtime_iterator.c +5355 -0
- package/native/runtime_json.c +1968 -0
- package/native/runtime_map.c +1539 -0
- package/native/runtime_math.c +894 -0
- package/native/runtime_memory.c +1341 -0
- package/native/runtime_module.c +860 -0
- package/native/runtime_number.c +2053 -0
- package/native/runtime_object.c +399 -0
- package/native/runtime_object_builtin.c +3877 -0
- package/native/runtime_primitive.c +2244 -0
- package/native/runtime_process.c +720 -0
- package/native/runtime_promise.c +3354 -0
- package/native/runtime_property.c +791 -0
- package/native/runtime_proxy.c +1533 -0
- package/native/runtime_realm.c +411 -0
- package/native/runtime_reflect.c +624 -0
- package/native/runtime_regexp.c +3495 -0
- package/native/runtime_regexp_matcher.c +3535 -0
- package/native/runtime_regexp_symbol.c +1471 -0
- package/native/runtime_set.c +1751 -0
- package/native/runtime_string.c +2862 -0
- package/native/runtime_string_match.c +1161 -0
- package/native/runtime_symbol.c +986 -0
- package/native/runtime_typed_array.c +5113 -0
- package/native/runtime_unicode_tables.h +14647 -0
- package/native/runtime_uri.c +676 -0
- package/native/runtime_weak_collection.c +1275 -0
- package/package.json +38 -3
|
@@ -0,0 +1,1751 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
|
2
|
+
/* Copyright (c) 2026 Hong Minhee; see ../MIT-LICENSE.txt. */
|
|
3
|
+
|
|
4
|
+
#include "runtime_internal.h"
|
|
5
|
+
|
|
6
|
+
#include <math.h>
|
|
7
|
+
#include <stdlib.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Set construction, insertion-ordered element storage, core prototype
|
|
12
|
+
* methods, and %SetIteratorPrototype%.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
static void initialize_ordinary(
|
|
16
|
+
OseoContext *context,
|
|
17
|
+
OseoOrdinaryObject *object,
|
|
18
|
+
OseoValue prototype
|
|
19
|
+
) {
|
|
20
|
+
object->prototype = prototype;
|
|
21
|
+
object->properties = NULL;
|
|
22
|
+
object->property_capacity = 0u;
|
|
23
|
+
object->property_count = 0u;
|
|
24
|
+
oseo_internal_init_dense_index(object);
|
|
25
|
+
object->private_elements = NULL;
|
|
26
|
+
object->private_element_capacity = 0u;
|
|
27
|
+
object->private_element_count = 0u;
|
|
28
|
+
object->shape_id = context->next_shape_id;
|
|
29
|
+
context->next_shape_id += 1u;
|
|
30
|
+
object->array_length = 0u;
|
|
31
|
+
object->dictionary = false;
|
|
32
|
+
object->length_writable = false;
|
|
33
|
+
object->extensible = true;
|
|
34
|
+
object->module_namespace = false;
|
|
35
|
+
object->immutable_prototype = false;
|
|
36
|
+
object->global_object = false;
|
|
37
|
+
object->error_data = false;
|
|
38
|
+
object->number_data = false;
|
|
39
|
+
object->number_value = oseo_undefined();
|
|
40
|
+
object->primitive_data = false;
|
|
41
|
+
object->primitive_value = oseo_undefined();
|
|
42
|
+
object->primitive_wrapper_methods_initialized = false;
|
|
43
|
+
object->virtual_string_iterator = false;
|
|
44
|
+
object->virtual_string_iterator_configurable = false;
|
|
45
|
+
object->virtual_string_iterator_enumerable = false;
|
|
46
|
+
object->virtual_string_iterator_writable = false;
|
|
47
|
+
object->iterator_kind = OSEO_ITERATOR_NONE;
|
|
48
|
+
object->iterator_target = oseo_undefined();
|
|
49
|
+
object->iterator_index = 0u;
|
|
50
|
+
object->regexp_string_iterator = false;
|
|
51
|
+
object->regexp_iterator_regexp = oseo_undefined();
|
|
52
|
+
object->regexp_iterator_subject = oseo_undefined();
|
|
53
|
+
object->regexp_iterator_global = false;
|
|
54
|
+
object->regexp_iterator_unicode = false;
|
|
55
|
+
object->regexp_iterator_complete = false;
|
|
56
|
+
object->async_from_sync = false;
|
|
57
|
+
object->async_sync_iterator = oseo_undefined();
|
|
58
|
+
object->wrap_for_valid_iterator = false;
|
|
59
|
+
object->wrapped_iterator = oseo_undefined();
|
|
60
|
+
object->wrapped_next = oseo_undefined();
|
|
61
|
+
object->arguments_object = false;
|
|
62
|
+
object->mapped_arguments = false;
|
|
63
|
+
object->generator = NULL;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static OseoResult set_receiver(
|
|
67
|
+
OseoContext *context,
|
|
68
|
+
OseoValue receiver
|
|
69
|
+
) {
|
|
70
|
+
if (is_set(receiver)) return normal(receiver);
|
|
71
|
+
return oseo_internal_throw_error(
|
|
72
|
+
context,
|
|
73
|
+
OSEO_ERROR_TYPE,
|
|
74
|
+
"Set method receiver is not a Set."
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* Set normalizes either zero sign to the realm's canonical positive zero. */
|
|
79
|
+
static OseoValue normalize_set_value(OseoValue value) {
|
|
80
|
+
return is_number(value) && number_value(value) == 0.0
|
|
81
|
+
? oseo_number(0.0)
|
|
82
|
+
: value;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* Searches the live slots by the shared SameValueZero, skipping the
|
|
86
|
+
* tombstones a prior delete or clear left behind. */
|
|
87
|
+
static size_t set_find(const OseoSet *set, OseoValue value) {
|
|
88
|
+
for (size_t index = 0u; index < set->element_count; index += 1u) {
|
|
89
|
+
if (set->elements[index].present &&
|
|
90
|
+
oseo_internal_same_value_zero(set->elements[index].value, value)) {
|
|
91
|
+
return index;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return SIZE_MAX;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* Reserving element storage is a safepoint. The Set value stays rooted by
|
|
98
|
+
* every caller, and the record is reacquired after collection. */
|
|
99
|
+
static OseoResult grow_set(OseoContext *context, OseoValue set_value) {
|
|
100
|
+
OseoSet *set = set_object(set_value);
|
|
101
|
+
if (set->element_count < set->element_capacity) {
|
|
102
|
+
return normal(set_value);
|
|
103
|
+
}
|
|
104
|
+
size_t capacity = set->element_capacity == 0u
|
|
105
|
+
? 4u
|
|
106
|
+
: set->element_capacity * 2u;
|
|
107
|
+
if (capacity < set->element_capacity ||
|
|
108
|
+
capacity > SIZE_MAX / sizeof(OseoSetElement)) {
|
|
109
|
+
return failure(context, "OSEO2001", "Set storage is too large.");
|
|
110
|
+
}
|
|
111
|
+
if (context->collect_every_safepoint) oseo_collect(context);
|
|
112
|
+
set = set_object(set_value);
|
|
113
|
+
context->allocation_attempts += 1u;
|
|
114
|
+
if (context->fail_allocation_at != 0u &&
|
|
115
|
+
context->allocation_attempts == context->fail_allocation_at) {
|
|
116
|
+
return failure(context, "OSEO2001", "Set storage allocation failed.");
|
|
117
|
+
}
|
|
118
|
+
OseoSetElement *elements = malloc(capacity * sizeof(*elements));
|
|
119
|
+
if (elements == NULL) {
|
|
120
|
+
return failure(context, "OSEO2001", "Set storage allocation failed.");
|
|
121
|
+
}
|
|
122
|
+
if (set->element_count > 0u) {
|
|
123
|
+
memcpy(
|
|
124
|
+
elements,
|
|
125
|
+
set->elements,
|
|
126
|
+
set->element_count * sizeof(*elements)
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
free(set->elements);
|
|
130
|
+
set->elements = elements;
|
|
131
|
+
set->element_capacity = capacity;
|
|
132
|
+
return normal(set_value);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
static OseoResult set_allocate(
|
|
136
|
+
OseoContext *context,
|
|
137
|
+
OseoValue prototype
|
|
138
|
+
) {
|
|
139
|
+
OseoValue slot = prototype;
|
|
140
|
+
OseoRootFrame frame = {NULL, &slot, 1u};
|
|
141
|
+
oseo_roots_push(context, &frame);
|
|
142
|
+
OseoSet *set = oseo_internal_allocate_heap_bytes(context, sizeof(*set));
|
|
143
|
+
if (set == NULL) {
|
|
144
|
+
oseo_roots_pop(context, &frame);
|
|
145
|
+
return failure(context, "OSEO2001", "Set allocation failed.");
|
|
146
|
+
}
|
|
147
|
+
initialize_ordinary(context, &set->ordinary, slot);
|
|
148
|
+
set->elements = NULL;
|
|
149
|
+
set->element_capacity = 0u;
|
|
150
|
+
set->element_count = 0u;
|
|
151
|
+
set->size = 0u;
|
|
152
|
+
OseoResult result = oseo_internal_publish_heap(
|
|
153
|
+
context,
|
|
154
|
+
&set->ordinary.header,
|
|
155
|
+
OSEO_HEAP_SET
|
|
156
|
+
);
|
|
157
|
+
oseo_roots_pop(context, &frame);
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* OrdinaryCreateFromConstructor(newTarget, "%Set.prototype%"). */
|
|
162
|
+
static OseoResult set_prototype_from_target(
|
|
163
|
+
OseoContext *context,
|
|
164
|
+
OseoValue new_target,
|
|
165
|
+
OseoValue *prototype
|
|
166
|
+
) {
|
|
167
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
168
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 2u);
|
|
169
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
170
|
+
frame.slots[0] = new_target;
|
|
171
|
+
result = oseo_internal_constructor_prototype(context, frame.slots[0]);
|
|
172
|
+
frame.slots[1] = result.value;
|
|
173
|
+
if (result.status == OSEO_STATUS_NORMAL && !is_object(frame.slots[1])) {
|
|
174
|
+
result = oseo_internal_constructor_realm_default(
|
|
175
|
+
context,
|
|
176
|
+
frame.slots[0],
|
|
177
|
+
OSEO_INTRINSIC_SET_PROTOTYPE
|
|
178
|
+
);
|
|
179
|
+
frame.slots[1] = result.value;
|
|
180
|
+
}
|
|
181
|
+
if (result.status == OSEO_STATUS_NORMAL) *prototype = frame.slots[1];
|
|
182
|
+
oseo_roots_release(context, &frame);
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* Appends a value the caller has already found absent. Growing the vector
|
|
187
|
+
* is a safepoint, so both values are rooted across it. */
|
|
188
|
+
static OseoResult set_append(
|
|
189
|
+
OseoContext *context,
|
|
190
|
+
OseoValue set_value,
|
|
191
|
+
OseoValue value
|
|
192
|
+
) {
|
|
193
|
+
OseoValue slots[2] = {set_value, value};
|
|
194
|
+
OseoRootFrame frame = {NULL, slots, 2u};
|
|
195
|
+
oseo_roots_push(context, &frame);
|
|
196
|
+
/* An element stores this realm's own representative of a registered
|
|
197
|
+
* symbol, so [[SetData]] never holds a value another realm owns. */
|
|
198
|
+
OseoResult result = oseo_internal_local_symbol(context, slots[1]);
|
|
199
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
200
|
+
slots[1] = result.value;
|
|
201
|
+
result = grow_set(context, slots[0]);
|
|
202
|
+
}
|
|
203
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
204
|
+
OseoSet *set = set_object(slots[0]);
|
|
205
|
+
OseoSetElement *element = &set->elements[set->element_count];
|
|
206
|
+
element->value = slots[1];
|
|
207
|
+
element->present = true;
|
|
208
|
+
set->element_count += 1u;
|
|
209
|
+
set->size += 1u;
|
|
210
|
+
result = normal(slots[0]);
|
|
211
|
+
}
|
|
212
|
+
oseo_roots_pop(context, &frame);
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/* Replaces one live slot with a tombstone. */
|
|
217
|
+
static void set_remove_at(OseoSet *set, size_t index) {
|
|
218
|
+
set->elements[index].present = false;
|
|
219
|
+
set->elements[index].value = oseo_undefined();
|
|
220
|
+
set->size -= 1u;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
static OseoResult set_add(
|
|
224
|
+
OseoContext *context,
|
|
225
|
+
OseoValue receiver,
|
|
226
|
+
OseoValue value
|
|
227
|
+
) {
|
|
228
|
+
OseoResult checked = set_receiver(context, receiver);
|
|
229
|
+
if (checked.status != OSEO_STATUS_NORMAL) return checked;
|
|
230
|
+
value = normalize_set_value(value);
|
|
231
|
+
if (set_find(set_object(receiver), value) != SIZE_MAX) {
|
|
232
|
+
return normal(receiver);
|
|
233
|
+
}
|
|
234
|
+
return set_append(context, receiver, value);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
static OseoResult set_clear(OseoContext *context, OseoValue receiver) {
|
|
238
|
+
OseoResult checked = set_receiver(context, receiver);
|
|
239
|
+
if (checked.status != OSEO_STATUS_NORMAL) return checked;
|
|
240
|
+
OseoSet *set = set_object(receiver);
|
|
241
|
+
for (size_t index = 0u; index < set->element_count; index += 1u) {
|
|
242
|
+
set->elements[index].present = false;
|
|
243
|
+
set->elements[index].value = oseo_undefined();
|
|
244
|
+
}
|
|
245
|
+
set->size = 0u;
|
|
246
|
+
return normal(oseo_undefined());
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
static OseoResult set_delete(
|
|
250
|
+
OseoContext *context,
|
|
251
|
+
OseoValue receiver,
|
|
252
|
+
OseoValue value
|
|
253
|
+
) {
|
|
254
|
+
OseoResult checked = set_receiver(context, receiver);
|
|
255
|
+
if (checked.status != OSEO_STATUS_NORMAL) return checked;
|
|
256
|
+
OseoSet *set = set_object(receiver);
|
|
257
|
+
size_t index = set_find(set, value);
|
|
258
|
+
if (index == SIZE_MAX) return normal(oseo_boolean(false));
|
|
259
|
+
set_remove_at(set, index);
|
|
260
|
+
return normal(oseo_boolean(true));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
static OseoResult set_has(
|
|
264
|
+
OseoContext *context,
|
|
265
|
+
OseoValue receiver,
|
|
266
|
+
OseoValue value
|
|
267
|
+
) {
|
|
268
|
+
OseoResult checked = set_receiver(context, receiver);
|
|
269
|
+
if (checked.status != OSEO_STATUS_NORMAL) return checked;
|
|
270
|
+
bool present = set_find(set_object(receiver), value) != SIZE_MAX;
|
|
271
|
+
return normal(oseo_boolean(present));
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
static OseoResult set_size(OseoContext *context, OseoValue receiver) {
|
|
275
|
+
OseoResult checked = set_receiver(context, receiver);
|
|
276
|
+
if (checked.status != OSEO_STATUS_NORMAL) return checked;
|
|
277
|
+
return normal(oseo_number((double)set_object(receiver)->size));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
static OseoResult set_iterator_create(
|
|
281
|
+
OseoContext *context,
|
|
282
|
+
OseoValue set,
|
|
283
|
+
OseoSetIteratorKind kind
|
|
284
|
+
) {
|
|
285
|
+
OseoValue slots[2] = {set, oseo_undefined()};
|
|
286
|
+
OseoRootFrame frame = {NULL, slots, 2u};
|
|
287
|
+
oseo_roots_push(context, &frame);
|
|
288
|
+
OseoResult result = oseo_internal_intrinsic(
|
|
289
|
+
context,
|
|
290
|
+
OSEO_INTRINSIC_SET_ITERATOR_PROTOTYPE
|
|
291
|
+
);
|
|
292
|
+
slots[1] = result.value;
|
|
293
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
294
|
+
OseoSetIterator *iterator =
|
|
295
|
+
oseo_internal_allocate_heap_bytes(context, sizeof(*iterator));
|
|
296
|
+
if (iterator == NULL) {
|
|
297
|
+
result = failure(
|
|
298
|
+
context,
|
|
299
|
+
"OSEO2001",
|
|
300
|
+
"Set iterator allocation failed."
|
|
301
|
+
);
|
|
302
|
+
} else {
|
|
303
|
+
initialize_ordinary(context, &iterator->ordinary, slots[1]);
|
|
304
|
+
iterator->set = slots[0];
|
|
305
|
+
iterator->index = 0u;
|
|
306
|
+
iterator->kind = kind;
|
|
307
|
+
iterator->done = false;
|
|
308
|
+
result = oseo_internal_publish_heap(
|
|
309
|
+
context,
|
|
310
|
+
&iterator->ordinary.header,
|
|
311
|
+
OSEO_HEAP_SET_ITERATOR
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
oseo_roots_pop(context, &frame);
|
|
316
|
+
return result;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
static OseoResult set_entries(OseoContext *context, OseoValue receiver) {
|
|
320
|
+
OseoResult checked = set_receiver(context, receiver);
|
|
321
|
+
if (checked.status != OSEO_STATUS_NORMAL) return checked;
|
|
322
|
+
return set_iterator_create(context, receiver, OSEO_SET_ITERATOR_ENTRY);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
static OseoResult set_values(OseoContext *context, OseoValue receiver) {
|
|
326
|
+
OseoResult checked = set_receiver(context, receiver);
|
|
327
|
+
if (checked.status != OSEO_STATUS_NORMAL) return checked;
|
|
328
|
+
return set_iterator_create(context, receiver, OSEO_SET_ITERATOR_VALUE);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
static OseoResult set_iterator_next(
|
|
332
|
+
OseoContext *context,
|
|
333
|
+
OseoValue receiver
|
|
334
|
+
) {
|
|
335
|
+
if (!is_set_iterator(receiver)) {
|
|
336
|
+
return oseo_internal_throw_error(
|
|
337
|
+
context,
|
|
338
|
+
OSEO_ERROR_TYPE,
|
|
339
|
+
"Set iterator next requires a Set iterator receiver."
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
OseoValue slots[3] = {receiver, oseo_undefined(), oseo_undefined()};
|
|
343
|
+
OseoRootFrame frame = {NULL, slots, 3u};
|
|
344
|
+
oseo_roots_push(context, &frame);
|
|
345
|
+
OseoSetIterator *iterator = set_iterator_object(slots[0]);
|
|
346
|
+
if (iterator->done || !is_set(iterator->set)) {
|
|
347
|
+
iterator->done = true;
|
|
348
|
+
iterator->set = oseo_undefined();
|
|
349
|
+
oseo_roots_pop(context, &frame);
|
|
350
|
+
return oseo_internal_iterator_result(context, oseo_undefined(), true);
|
|
351
|
+
}
|
|
352
|
+
slots[1] = iterator->set;
|
|
353
|
+
OseoSet *set = set_object(slots[1]);
|
|
354
|
+
while (iterator->index < set->element_count) {
|
|
355
|
+
size_t index = iterator->index;
|
|
356
|
+
iterator->index += 1u;
|
|
357
|
+
if (!set->elements[index].present) continue;
|
|
358
|
+
slots[2] = set->elements[index].value;
|
|
359
|
+
OseoResult result = normal(slots[2]);
|
|
360
|
+
if (iterator->kind == OSEO_SET_ITERATOR_ENTRY) {
|
|
361
|
+
result = oseo_array_create(context, 0u);
|
|
362
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
363
|
+
OseoValue pair = result.value;
|
|
364
|
+
OseoRootFrame pair_frame = {NULL, &pair, 1u};
|
|
365
|
+
oseo_roots_push(context, &pair_frame);
|
|
366
|
+
result = oseo_array_append(context, pair, slots[2]);
|
|
367
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
368
|
+
result = oseo_array_append(context, pair, slots[2]);
|
|
369
|
+
}
|
|
370
|
+
oseo_roots_pop(context, &pair_frame);
|
|
371
|
+
if (result.status == OSEO_STATUS_NORMAL) slots[2] = pair;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
375
|
+
result = oseo_internal_iterator_result(context, slots[2], false);
|
|
376
|
+
}
|
|
377
|
+
oseo_roots_pop(context, &frame);
|
|
378
|
+
return result;
|
|
379
|
+
}
|
|
380
|
+
iterator = set_iterator_object(slots[0]);
|
|
381
|
+
iterator->done = true;
|
|
382
|
+
iterator->set = oseo_undefined();
|
|
383
|
+
oseo_roots_pop(context, &frame);
|
|
384
|
+
return oseo_internal_iterator_result(context, oseo_undefined(), true);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
static OseoResult set_for_each(
|
|
388
|
+
OseoContext *context,
|
|
389
|
+
OseoValue receiver,
|
|
390
|
+
size_t argument_count,
|
|
391
|
+
const OseoValue *arguments
|
|
392
|
+
) {
|
|
393
|
+
OseoResult checked = set_receiver(context, receiver);
|
|
394
|
+
if (checked.status != OSEO_STATUS_NORMAL) return checked;
|
|
395
|
+
OseoValue callback = argument_count > 0u
|
|
396
|
+
? arguments[0]
|
|
397
|
+
: oseo_undefined();
|
|
398
|
+
if (!is_callable(callback)) {
|
|
399
|
+
return oseo_internal_throw_error(
|
|
400
|
+
context,
|
|
401
|
+
OSEO_ERROR_TYPE,
|
|
402
|
+
"Set.prototype.forEach callback is not callable."
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
406
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 6u);
|
|
407
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
408
|
+
frame.slots[0] = receiver;
|
|
409
|
+
frame.slots[1] = callback;
|
|
410
|
+
frame.slots[2] = argument_count > 1u
|
|
411
|
+
? arguments[1]
|
|
412
|
+
: oseo_undefined();
|
|
413
|
+
size_t index = 0u;
|
|
414
|
+
while (result.status == OSEO_STATUS_NORMAL) {
|
|
415
|
+
OseoSet *set = set_object(frame.slots[0]);
|
|
416
|
+
while (index < set->element_count &&
|
|
417
|
+
!set->elements[index].present) {
|
|
418
|
+
index += 1u;
|
|
419
|
+
}
|
|
420
|
+
if (index >= set->element_count) break;
|
|
421
|
+
frame.slots[3] = set->elements[index].value;
|
|
422
|
+
index += 1u;
|
|
423
|
+
frame.slots[4] = frame.slots[3];
|
|
424
|
+
frame.slots[5] = frame.slots[0];
|
|
425
|
+
result = oseo_call_function(
|
|
426
|
+
context,
|
|
427
|
+
frame.slots[1],
|
|
428
|
+
frame.slots[2],
|
|
429
|
+
3u,
|
|
430
|
+
&frame.slots[3],
|
|
431
|
+
oseo_undefined()
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
435
|
+
result = normal(oseo_undefined());
|
|
436
|
+
}
|
|
437
|
+
oseo_roots_release(context, &frame);
|
|
438
|
+
return result;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/* AddEntriesFromIterable with the Set instance's observable `add` method. */
|
|
442
|
+
static OseoResult set_constructor(
|
|
443
|
+
OseoContext *context,
|
|
444
|
+
size_t argument_count,
|
|
445
|
+
const OseoValue *arguments,
|
|
446
|
+
OseoValue new_target
|
|
447
|
+
) {
|
|
448
|
+
if (tag_of(new_target) == OSEO_TAG_UNDEFINED) {
|
|
449
|
+
return oseo_internal_throw_error(
|
|
450
|
+
context,
|
|
451
|
+
OSEO_ERROR_TYPE,
|
|
452
|
+
"Set must be called with new."
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
456
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 6u);
|
|
457
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
458
|
+
frame.slots[0] = new_target;
|
|
459
|
+
frame.slots[1] = argument_count > 0u
|
|
460
|
+
? arguments[0]
|
|
461
|
+
: oseo_undefined();
|
|
462
|
+
result = set_prototype_from_target(
|
|
463
|
+
context,
|
|
464
|
+
frame.slots[0],
|
|
465
|
+
&frame.slots[2]
|
|
466
|
+
);
|
|
467
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
468
|
+
result = set_allocate(context, frame.slots[2]);
|
|
469
|
+
frame.slots[2] = result.value;
|
|
470
|
+
}
|
|
471
|
+
if (result.status != OSEO_STATUS_NORMAL || is_nullish(frame.slots[1])) {
|
|
472
|
+
if (result.status == OSEO_STATUS_NORMAL) result.value = frame.slots[2];
|
|
473
|
+
oseo_roots_release(context, &frame);
|
|
474
|
+
return result;
|
|
475
|
+
}
|
|
476
|
+
result = oseo_internal_ascii_string(context, "add");
|
|
477
|
+
frame.slots[3] = result.value;
|
|
478
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
479
|
+
result = oseo_object_get(context, frame.slots[2], frame.slots[3]);
|
|
480
|
+
frame.slots[3] = result.value;
|
|
481
|
+
}
|
|
482
|
+
if (result.status == OSEO_STATUS_NORMAL &&
|
|
483
|
+
!is_callable(frame.slots[3])) {
|
|
484
|
+
result = oseo_internal_throw_error(
|
|
485
|
+
context,
|
|
486
|
+
OSEO_ERROR_TYPE,
|
|
487
|
+
"The Set add property is not callable."
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
491
|
+
result = oseo_iterator_get(
|
|
492
|
+
context,
|
|
493
|
+
frame.slots[1],
|
|
494
|
+
&frame.slots[5]
|
|
495
|
+
);
|
|
496
|
+
frame.slots[4] = result.value;
|
|
497
|
+
}
|
|
498
|
+
bool done = false;
|
|
499
|
+
while (result.status == OSEO_STATUS_NORMAL && !done) {
|
|
500
|
+
result = oseo_iterator_next(
|
|
501
|
+
context,
|
|
502
|
+
frame.slots[4],
|
|
503
|
+
frame.slots[5],
|
|
504
|
+
&frame.slots[1],
|
|
505
|
+
&done
|
|
506
|
+
);
|
|
507
|
+
bool close_iterator = false;
|
|
508
|
+
if (result.status == OSEO_STATUS_NORMAL && !done) {
|
|
509
|
+
close_iterator = true;
|
|
510
|
+
result = oseo_call_function(
|
|
511
|
+
context,
|
|
512
|
+
frame.slots[3],
|
|
513
|
+
frame.slots[2],
|
|
514
|
+
1u,
|
|
515
|
+
&frame.slots[1],
|
|
516
|
+
oseo_undefined()
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
if (close_iterator && result.status == OSEO_STATUS_THROW &&
|
|
520
|
+
!context->has_diagnostic && is_object(frame.slots[4])) {
|
|
521
|
+
OseoResult completion = result;
|
|
522
|
+
frame.slots[1] = result.value;
|
|
523
|
+
oseo_context_clear_language_error(context);
|
|
524
|
+
OseoResult closed = oseo_iterator_close(
|
|
525
|
+
context,
|
|
526
|
+
frame.slots[4],
|
|
527
|
+
true
|
|
528
|
+
);
|
|
529
|
+
result = closed.status == OSEO_STATUS_THROW &&
|
|
530
|
+
context->has_diagnostic
|
|
531
|
+
? closed
|
|
532
|
+
: completion;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
if (result.status == OSEO_STATUS_NORMAL) result.value = frame.slots[2];
|
|
536
|
+
oseo_roots_release(context, &frame);
|
|
537
|
+
return result;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/*
|
|
541
|
+
* Root frame layout shared by the seven methods that combine or compare a
|
|
542
|
+
* Set with a set-like argument. Every value one of them reads back after
|
|
543
|
+
* calling user code lives in one of these slots.
|
|
544
|
+
*/
|
|
545
|
+
enum {
|
|
546
|
+
SET_OPERATION_RECEIVER = 0,
|
|
547
|
+
SET_OPERATION_OTHER = 1,
|
|
548
|
+
SET_OPERATION_HAS = 2,
|
|
549
|
+
SET_OPERATION_KEYS = 3,
|
|
550
|
+
SET_OPERATION_RESULT = 4,
|
|
551
|
+
SET_OPERATION_ITERATOR = 5,
|
|
552
|
+
SET_OPERATION_NEXT = 6,
|
|
553
|
+
SET_OPERATION_VALUE = 7,
|
|
554
|
+
SET_OPERATION_SCRATCH = 8,
|
|
555
|
+
SET_OPERATION_SLOT_COUNT = 9,
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
/* Reads one named property of the set-like argument into a rooted slot. */
|
|
559
|
+
static OseoResult set_record_property(
|
|
560
|
+
OseoContext *context,
|
|
561
|
+
OseoValue *slots,
|
|
562
|
+
const char *name,
|
|
563
|
+
size_t slot
|
|
564
|
+
) {
|
|
565
|
+
OseoResult result = oseo_internal_ascii_string(context, name);
|
|
566
|
+
slots[slot] = result.value;
|
|
567
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
568
|
+
result = oseo_object_get(
|
|
569
|
+
context,
|
|
570
|
+
slots[SET_OPERATION_OTHER],
|
|
571
|
+
slots[slot]
|
|
572
|
+
);
|
|
573
|
+
slots[slot] = result.value;
|
|
574
|
+
}
|
|
575
|
+
return result;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/*
|
|
579
|
+
* GetSetRecord(other). The size is read and converted before `has` and
|
|
580
|
+
* `keys` are read, and ToIntegerOrInfinity keeps an infinite size, so the
|
|
581
|
+
* record's size is a non-negative integral double rather than a count.
|
|
582
|
+
*/
|
|
583
|
+
static OseoResult set_record_get(
|
|
584
|
+
OseoContext *context,
|
|
585
|
+
OseoValue *slots,
|
|
586
|
+
double *size
|
|
587
|
+
) {
|
|
588
|
+
if (!is_object(slots[SET_OPERATION_OTHER])) {
|
|
589
|
+
return oseo_internal_throw_error(
|
|
590
|
+
context,
|
|
591
|
+
OSEO_ERROR_TYPE,
|
|
592
|
+
"The Set method argument is not an object."
|
|
593
|
+
);
|
|
594
|
+
}
|
|
595
|
+
OseoResult result = set_record_property(
|
|
596
|
+
context,
|
|
597
|
+
slots,
|
|
598
|
+
"size",
|
|
599
|
+
SET_OPERATION_SCRATCH
|
|
600
|
+
);
|
|
601
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
602
|
+
result = oseo_internal_to_number(
|
|
603
|
+
context,
|
|
604
|
+
slots[SET_OPERATION_SCRATCH]
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
608
|
+
double number = number_value(result.value);
|
|
609
|
+
if (isnan(number)) {
|
|
610
|
+
return oseo_internal_throw_error(
|
|
611
|
+
context,
|
|
612
|
+
OSEO_ERROR_TYPE,
|
|
613
|
+
"The set-like size is not a number."
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
if (isfinite(number)) number = trunc(number);
|
|
617
|
+
if (number < 0.0) {
|
|
618
|
+
return oseo_internal_throw_error(
|
|
619
|
+
context,
|
|
620
|
+
OSEO_ERROR_RANGE,
|
|
621
|
+
"The set-like size is negative."
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
*size = number == 0.0 ? 0.0 : number;
|
|
625
|
+
result = set_record_property(context, slots, "has", SET_OPERATION_HAS);
|
|
626
|
+
if (result.status == OSEO_STATUS_NORMAL &&
|
|
627
|
+
!is_callable(slots[SET_OPERATION_HAS])) {
|
|
628
|
+
result = oseo_internal_throw_error(
|
|
629
|
+
context,
|
|
630
|
+
OSEO_ERROR_TYPE,
|
|
631
|
+
"The set-like has property is not callable."
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
635
|
+
result = set_record_property(
|
|
636
|
+
context,
|
|
637
|
+
slots,
|
|
638
|
+
"keys",
|
|
639
|
+
SET_OPERATION_KEYS
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
if (result.status == OSEO_STATUS_NORMAL &&
|
|
643
|
+
!is_callable(slots[SET_OPERATION_KEYS])) {
|
|
644
|
+
result = oseo_internal_throw_error(
|
|
645
|
+
context,
|
|
646
|
+
OSEO_ERROR_TYPE,
|
|
647
|
+
"The set-like keys property is not callable."
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
return result;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/*
|
|
654
|
+
* RequireInternalSlot(O, [[SetData]]) followed by GetSetRecord(other). On
|
|
655
|
+
* a normal completion the caller owns the allocated frame and releases it.
|
|
656
|
+
*/
|
|
657
|
+
static OseoResult set_operation_begin(
|
|
658
|
+
OseoContext *context,
|
|
659
|
+
OseoValue receiver,
|
|
660
|
+
size_t argument_count,
|
|
661
|
+
const OseoValue *arguments,
|
|
662
|
+
OseoRootFrame *frame,
|
|
663
|
+
double *other_size
|
|
664
|
+
) {
|
|
665
|
+
OseoResult result = set_receiver(context, receiver);
|
|
666
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
667
|
+
result = oseo_roots_allocate(context, frame, SET_OPERATION_SLOT_COUNT);
|
|
668
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
669
|
+
frame->slots[SET_OPERATION_RECEIVER] = receiver;
|
|
670
|
+
frame->slots[SET_OPERATION_OTHER] = argument_count > 0u
|
|
671
|
+
? arguments[0]
|
|
672
|
+
: oseo_undefined();
|
|
673
|
+
result = set_record_get(context, frame->slots, other_size);
|
|
674
|
+
if (result.status != OSEO_STATUS_NORMAL) {
|
|
675
|
+
oseo_roots_release(context, frame);
|
|
676
|
+
}
|
|
677
|
+
return result;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/*
|
|
681
|
+
* GetIteratorFromMethod(other, keys). The next method is read once and
|
|
682
|
+
* reused by every step; a non-callable one throws when the first step
|
|
683
|
+
* calls it.
|
|
684
|
+
*/
|
|
685
|
+
static OseoResult set_keys_iterator(OseoContext *context, OseoValue *slots) {
|
|
686
|
+
OseoResult result = oseo_call_function(
|
|
687
|
+
context,
|
|
688
|
+
slots[SET_OPERATION_KEYS],
|
|
689
|
+
slots[SET_OPERATION_OTHER],
|
|
690
|
+
0u,
|
|
691
|
+
NULL,
|
|
692
|
+
oseo_undefined()
|
|
693
|
+
);
|
|
694
|
+
slots[SET_OPERATION_ITERATOR] = result.value;
|
|
695
|
+
if (result.status == OSEO_STATUS_NORMAL &&
|
|
696
|
+
!is_object(slots[SET_OPERATION_ITERATOR])) {
|
|
697
|
+
result = oseo_internal_throw_error(
|
|
698
|
+
context,
|
|
699
|
+
OSEO_ERROR_TYPE,
|
|
700
|
+
"The set-like keys iterator is not an object."
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
704
|
+
result = oseo_internal_ascii_string(context, "next");
|
|
705
|
+
slots[SET_OPERATION_SCRATCH] = result.value;
|
|
706
|
+
}
|
|
707
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
708
|
+
result = oseo_object_get(
|
|
709
|
+
context,
|
|
710
|
+
slots[SET_OPERATION_ITERATOR],
|
|
711
|
+
slots[SET_OPERATION_SCRATCH]
|
|
712
|
+
);
|
|
713
|
+
slots[SET_OPERATION_NEXT] = result.value;
|
|
714
|
+
}
|
|
715
|
+
return result;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/* IteratorStepValue over the captured keys iterator. */
|
|
719
|
+
static OseoResult set_keys_step(
|
|
720
|
+
OseoContext *context,
|
|
721
|
+
OseoValue *slots,
|
|
722
|
+
bool *done
|
|
723
|
+
) {
|
|
724
|
+
return oseo_iterator_next(
|
|
725
|
+
context,
|
|
726
|
+
slots[SET_OPERATION_ITERATOR],
|
|
727
|
+
slots[SET_OPERATION_NEXT],
|
|
728
|
+
&slots[SET_OPERATION_VALUE],
|
|
729
|
+
done
|
|
730
|
+
);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/* Call(otherRec.[[Has]], otherRec.[[SetObject]], « value »), as a Boolean. */
|
|
734
|
+
static OseoResult set_other_has(
|
|
735
|
+
OseoContext *context,
|
|
736
|
+
OseoValue *slots,
|
|
737
|
+
bool *present
|
|
738
|
+
) {
|
|
739
|
+
OseoResult result = oseo_call_function(
|
|
740
|
+
context,
|
|
741
|
+
slots[SET_OPERATION_HAS],
|
|
742
|
+
slots[SET_OPERATION_OTHER],
|
|
743
|
+
1u,
|
|
744
|
+
&slots[SET_OPERATION_VALUE],
|
|
745
|
+
oseo_undefined()
|
|
746
|
+
);
|
|
747
|
+
*present = result.status == OSEO_STATUS_NORMAL &&
|
|
748
|
+
oseo_to_boolean(result.value);
|
|
749
|
+
return result;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/* OrdinaryObjectCreate(%Set.prototype%) with an empty element vector. The
|
|
753
|
+
* result never consults the receiver's constructor or Symbol.species. */
|
|
754
|
+
static OseoResult set_result_create(OseoContext *context, OseoValue *slots) {
|
|
755
|
+
OseoResult result = oseo_internal_intrinsic(
|
|
756
|
+
context,
|
|
757
|
+
OSEO_INTRINSIC_SET_PROTOTYPE
|
|
758
|
+
);
|
|
759
|
+
slots[SET_OPERATION_RESULT] = result.value;
|
|
760
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
761
|
+
result = set_allocate(context, slots[SET_OPERATION_RESULT]);
|
|
762
|
+
slots[SET_OPERATION_RESULT] = result.value;
|
|
763
|
+
}
|
|
764
|
+
return result;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/* Copies the receiver's live elements into the fresh result in order.
|
|
768
|
+
* Tombstones are not copied: the result is unobservable until returned,
|
|
769
|
+
* so its slot positions carry no meaning. */
|
|
770
|
+
static OseoResult set_result_copy(OseoContext *context, OseoValue *slots) {
|
|
771
|
+
OseoResult result = normal(slots[SET_OPERATION_RESULT]);
|
|
772
|
+
size_t count = set_object(slots[SET_OPERATION_RECEIVER])->element_count;
|
|
773
|
+
for (size_t index = 0u;
|
|
774
|
+
result.status == OSEO_STATUS_NORMAL && index < count;
|
|
775
|
+
index += 1u) {
|
|
776
|
+
OseoSet *source = set_object(slots[SET_OPERATION_RECEIVER]);
|
|
777
|
+
if (!source->elements[index].present) continue;
|
|
778
|
+
slots[SET_OPERATION_VALUE] = source->elements[index].value;
|
|
779
|
+
result = set_append(
|
|
780
|
+
context,
|
|
781
|
+
slots[SET_OPERATION_RESULT],
|
|
782
|
+
slots[SET_OPERATION_VALUE]
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
return result;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/* Releases an operation frame and reports either its abrupt completion or
|
|
789
|
+
* the given normal value. */
|
|
790
|
+
static OseoResult set_operation_end(
|
|
791
|
+
OseoContext *context,
|
|
792
|
+
OseoRootFrame *frame,
|
|
793
|
+
OseoResult result,
|
|
794
|
+
OseoValue value
|
|
795
|
+
) {
|
|
796
|
+
if (result.status == OSEO_STATUS_NORMAL) result = normal(value);
|
|
797
|
+
oseo_roots_release(context, frame);
|
|
798
|
+
return result;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
static OseoResult set_union(
|
|
802
|
+
OseoContext *context,
|
|
803
|
+
OseoValue receiver,
|
|
804
|
+
size_t argument_count,
|
|
805
|
+
const OseoValue *arguments
|
|
806
|
+
) {
|
|
807
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
808
|
+
double other_size = 0.0;
|
|
809
|
+
OseoResult result = set_operation_begin(
|
|
810
|
+
context,
|
|
811
|
+
receiver,
|
|
812
|
+
argument_count,
|
|
813
|
+
arguments,
|
|
814
|
+
&frame,
|
|
815
|
+
&other_size
|
|
816
|
+
);
|
|
817
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
818
|
+
OseoValue *slots = frame.slots;
|
|
819
|
+
result = set_keys_iterator(context, slots);
|
|
820
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
821
|
+
result = set_result_create(context, slots);
|
|
822
|
+
}
|
|
823
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
824
|
+
result = set_result_copy(context, slots);
|
|
825
|
+
}
|
|
826
|
+
bool done = false;
|
|
827
|
+
while (result.status == OSEO_STATUS_NORMAL && !done) {
|
|
828
|
+
result = set_keys_step(context, slots, &done);
|
|
829
|
+
if (result.status != OSEO_STATUS_NORMAL || done) break;
|
|
830
|
+
slots[SET_OPERATION_VALUE] =
|
|
831
|
+
normalize_set_value(slots[SET_OPERATION_VALUE]);
|
|
832
|
+
if (set_find(
|
|
833
|
+
set_object(slots[SET_OPERATION_RESULT]),
|
|
834
|
+
slots[SET_OPERATION_VALUE]
|
|
835
|
+
) == SIZE_MAX) {
|
|
836
|
+
result = set_append(
|
|
837
|
+
context,
|
|
838
|
+
slots[SET_OPERATION_RESULT],
|
|
839
|
+
slots[SET_OPERATION_VALUE]
|
|
840
|
+
);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
return set_operation_end(
|
|
844
|
+
context,
|
|
845
|
+
&frame,
|
|
846
|
+
result,
|
|
847
|
+
slots[SET_OPERATION_RESULT]
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/* What a receiver-driven visit does with each `has` answer. */
|
|
852
|
+
typedef enum {
|
|
853
|
+
SET_VISIT_INTERSECT = 0,
|
|
854
|
+
SET_VISIT_SUBSET = 1,
|
|
855
|
+
SET_VISIT_DISJOINT = 2,
|
|
856
|
+
} OseoSetVisitKind;
|
|
857
|
+
|
|
858
|
+
/*
|
|
859
|
+
* Visits the receiver's live elements by index while `has` may mutate it.
|
|
860
|
+
* The loop rereads the vector length after every call, as the
|
|
861
|
+
* specification's thisSize does, so an element appended during a call is
|
|
862
|
+
* visited and a deleted then re-added one can be visited twice.
|
|
863
|
+
*/
|
|
864
|
+
static OseoResult set_visit_receiver(
|
|
865
|
+
OseoContext *context,
|
|
866
|
+
OseoValue *slots,
|
|
867
|
+
OseoSetVisitKind kind,
|
|
868
|
+
bool *answer
|
|
869
|
+
) {
|
|
870
|
+
OseoResult result = normal(oseo_undefined());
|
|
871
|
+
*answer = true;
|
|
872
|
+
size_t index = 0u;
|
|
873
|
+
while (result.status == OSEO_STATUS_NORMAL) {
|
|
874
|
+
OseoSet *set = set_object(slots[SET_OPERATION_RECEIVER]);
|
|
875
|
+
if (index >= set->element_count) break;
|
|
876
|
+
bool live = set->elements[index].present;
|
|
877
|
+
slots[SET_OPERATION_VALUE] = set->elements[index].value;
|
|
878
|
+
index += 1u;
|
|
879
|
+
if (!live) continue;
|
|
880
|
+
bool in_other = false;
|
|
881
|
+
result = set_other_has(context, slots, &in_other);
|
|
882
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
883
|
+
if (kind == SET_VISIT_SUBSET && !in_other) {
|
|
884
|
+
*answer = false;
|
|
885
|
+
break;
|
|
886
|
+
}
|
|
887
|
+
if (kind == SET_VISIT_DISJOINT && in_other) {
|
|
888
|
+
*answer = false;
|
|
889
|
+
break;
|
|
890
|
+
}
|
|
891
|
+
if (kind == SET_VISIT_INTERSECT && in_other &&
|
|
892
|
+
set_find(
|
|
893
|
+
set_object(slots[SET_OPERATION_RESULT]),
|
|
894
|
+
slots[SET_OPERATION_VALUE]
|
|
895
|
+
) == SIZE_MAX) {
|
|
896
|
+
result = set_append(
|
|
897
|
+
context,
|
|
898
|
+
slots[SET_OPERATION_RESULT],
|
|
899
|
+
slots[SET_OPERATION_VALUE]
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
return result;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
static OseoResult set_intersection(
|
|
907
|
+
OseoContext *context,
|
|
908
|
+
OseoValue receiver,
|
|
909
|
+
size_t argument_count,
|
|
910
|
+
const OseoValue *arguments
|
|
911
|
+
) {
|
|
912
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
913
|
+
double other_size = 0.0;
|
|
914
|
+
OseoResult result = set_operation_begin(
|
|
915
|
+
context,
|
|
916
|
+
receiver,
|
|
917
|
+
argument_count,
|
|
918
|
+
arguments,
|
|
919
|
+
&frame,
|
|
920
|
+
&other_size
|
|
921
|
+
);
|
|
922
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
923
|
+
OseoValue *slots = frame.slots;
|
|
924
|
+
result = set_result_create(context, slots);
|
|
925
|
+
if (result.status == OSEO_STATUS_NORMAL &&
|
|
926
|
+
(double)set_object(slots[SET_OPERATION_RECEIVER])->size <=
|
|
927
|
+
other_size) {
|
|
928
|
+
bool unused = true;
|
|
929
|
+
result = set_visit_receiver(
|
|
930
|
+
context,
|
|
931
|
+
slots,
|
|
932
|
+
SET_VISIT_INTERSECT,
|
|
933
|
+
&unused
|
|
934
|
+
);
|
|
935
|
+
} else if (result.status == OSEO_STATUS_NORMAL) {
|
|
936
|
+
result = set_keys_iterator(context, slots);
|
|
937
|
+
bool done = false;
|
|
938
|
+
while (result.status == OSEO_STATUS_NORMAL && !done) {
|
|
939
|
+
result = set_keys_step(context, slots, &done);
|
|
940
|
+
if (result.status != OSEO_STATUS_NORMAL || done) break;
|
|
941
|
+
slots[SET_OPERATION_VALUE] =
|
|
942
|
+
normalize_set_value(slots[SET_OPERATION_VALUE]);
|
|
943
|
+
if (set_find(
|
|
944
|
+
set_object(slots[SET_OPERATION_RECEIVER]),
|
|
945
|
+
slots[SET_OPERATION_VALUE]
|
|
946
|
+
) != SIZE_MAX &&
|
|
947
|
+
set_find(
|
|
948
|
+
set_object(slots[SET_OPERATION_RESULT]),
|
|
949
|
+
slots[SET_OPERATION_VALUE]
|
|
950
|
+
) == SIZE_MAX) {
|
|
951
|
+
result = set_append(
|
|
952
|
+
context,
|
|
953
|
+
slots[SET_OPERATION_RESULT],
|
|
954
|
+
slots[SET_OPERATION_VALUE]
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
return set_operation_end(
|
|
960
|
+
context,
|
|
961
|
+
&frame,
|
|
962
|
+
result,
|
|
963
|
+
slots[SET_OPERATION_RESULT]
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
static OseoResult set_difference(
|
|
968
|
+
OseoContext *context,
|
|
969
|
+
OseoValue receiver,
|
|
970
|
+
size_t argument_count,
|
|
971
|
+
const OseoValue *arguments
|
|
972
|
+
) {
|
|
973
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
974
|
+
double other_size = 0.0;
|
|
975
|
+
OseoResult result = set_operation_begin(
|
|
976
|
+
context,
|
|
977
|
+
receiver,
|
|
978
|
+
argument_count,
|
|
979
|
+
arguments,
|
|
980
|
+
&frame,
|
|
981
|
+
&other_size
|
|
982
|
+
);
|
|
983
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
984
|
+
OseoValue *slots = frame.slots;
|
|
985
|
+
result = set_result_create(context, slots);
|
|
986
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
987
|
+
result = set_result_copy(context, slots);
|
|
988
|
+
}
|
|
989
|
+
if (result.status == OSEO_STATUS_NORMAL &&
|
|
990
|
+
(double)set_object(slots[SET_OPERATION_RECEIVER])->size <=
|
|
991
|
+
other_size) {
|
|
992
|
+
/* The copy fixes the visited elements, so a call that mutates the
|
|
993
|
+
* receiver changes neither the count nor the values visited. */
|
|
994
|
+
size_t count = set_object(slots[SET_OPERATION_RESULT])->element_count;
|
|
995
|
+
for (size_t index = 0u;
|
|
996
|
+
result.status == OSEO_STATUS_NORMAL && index < count;
|
|
997
|
+
index += 1u) {
|
|
998
|
+
slots[SET_OPERATION_VALUE] =
|
|
999
|
+
set_object(slots[SET_OPERATION_RESULT])->elements[index].value;
|
|
1000
|
+
bool in_other = false;
|
|
1001
|
+
result = set_other_has(context, slots, &in_other);
|
|
1002
|
+
if (result.status == OSEO_STATUS_NORMAL && in_other) {
|
|
1003
|
+
set_remove_at(set_object(slots[SET_OPERATION_RESULT]), index);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
} else if (result.status == OSEO_STATUS_NORMAL) {
|
|
1007
|
+
result = set_keys_iterator(context, slots);
|
|
1008
|
+
bool done = false;
|
|
1009
|
+
while (result.status == OSEO_STATUS_NORMAL && !done) {
|
|
1010
|
+
result = set_keys_step(context, slots, &done);
|
|
1011
|
+
if (result.status != OSEO_STATUS_NORMAL || done) break;
|
|
1012
|
+
OseoSet *copy = set_object(slots[SET_OPERATION_RESULT]);
|
|
1013
|
+
size_t index = set_find(copy, slots[SET_OPERATION_VALUE]);
|
|
1014
|
+
if (index != SIZE_MAX) set_remove_at(copy, index);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
return set_operation_end(
|
|
1018
|
+
context,
|
|
1019
|
+
&frame,
|
|
1020
|
+
result,
|
|
1021
|
+
slots[SET_OPERATION_RESULT]
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
static OseoResult set_symmetric_difference(
|
|
1026
|
+
OseoContext *context,
|
|
1027
|
+
OseoValue receiver,
|
|
1028
|
+
size_t argument_count,
|
|
1029
|
+
const OseoValue *arguments
|
|
1030
|
+
) {
|
|
1031
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
1032
|
+
double other_size = 0.0;
|
|
1033
|
+
OseoResult result = set_operation_begin(
|
|
1034
|
+
context,
|
|
1035
|
+
receiver,
|
|
1036
|
+
argument_count,
|
|
1037
|
+
arguments,
|
|
1038
|
+
&frame,
|
|
1039
|
+
&other_size
|
|
1040
|
+
);
|
|
1041
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
1042
|
+
OseoValue *slots = frame.slots;
|
|
1043
|
+
result = set_keys_iterator(context, slots);
|
|
1044
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1045
|
+
result = set_result_create(context, slots);
|
|
1046
|
+
}
|
|
1047
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1048
|
+
result = set_result_copy(context, slots);
|
|
1049
|
+
}
|
|
1050
|
+
bool done = false;
|
|
1051
|
+
while (result.status == OSEO_STATUS_NORMAL && !done) {
|
|
1052
|
+
result = set_keys_step(context, slots, &done);
|
|
1053
|
+
if (result.status != OSEO_STATUS_NORMAL || done) break;
|
|
1054
|
+
slots[SET_OPERATION_VALUE] =
|
|
1055
|
+
normalize_set_value(slots[SET_OPERATION_VALUE]);
|
|
1056
|
+
OseoSet *copy = set_object(slots[SET_OPERATION_RESULT]);
|
|
1057
|
+
size_t index = set_find(copy, slots[SET_OPERATION_VALUE]);
|
|
1058
|
+
bool in_receiver = set_find(
|
|
1059
|
+
set_object(slots[SET_OPERATION_RECEIVER]),
|
|
1060
|
+
slots[SET_OPERATION_VALUE]
|
|
1061
|
+
) != SIZE_MAX;
|
|
1062
|
+
if (in_receiver) {
|
|
1063
|
+
if (index != SIZE_MAX) set_remove_at(copy, index);
|
|
1064
|
+
} else if (index == SIZE_MAX) {
|
|
1065
|
+
result = set_append(
|
|
1066
|
+
context,
|
|
1067
|
+
slots[SET_OPERATION_RESULT],
|
|
1068
|
+
slots[SET_OPERATION_VALUE]
|
|
1069
|
+
);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
return set_operation_end(
|
|
1073
|
+
context,
|
|
1074
|
+
&frame,
|
|
1075
|
+
result,
|
|
1076
|
+
slots[SET_OPERATION_RESULT]
|
|
1077
|
+
);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
/*
|
|
1081
|
+
* The keys-iterator half of isSupersetOf and isDisjointFrom. The walk
|
|
1082
|
+
* stops at the first value whose receiver membership equals `stop_when`
|
|
1083
|
+
* and closes the iterator with a normal completion, so an abrupt return
|
|
1084
|
+
* method replaces the Boolean answer.
|
|
1085
|
+
*/
|
|
1086
|
+
static OseoResult set_scan_keys(
|
|
1087
|
+
OseoContext *context,
|
|
1088
|
+
OseoValue *slots,
|
|
1089
|
+
bool stop_when,
|
|
1090
|
+
bool *answer
|
|
1091
|
+
) {
|
|
1092
|
+
*answer = true;
|
|
1093
|
+
OseoResult result = set_keys_iterator(context, slots);
|
|
1094
|
+
bool done = false;
|
|
1095
|
+
while (result.status == OSEO_STATUS_NORMAL && !done) {
|
|
1096
|
+
result = set_keys_step(context, slots, &done);
|
|
1097
|
+
if (result.status != OSEO_STATUS_NORMAL || done) break;
|
|
1098
|
+
bool in_receiver = set_find(
|
|
1099
|
+
set_object(slots[SET_OPERATION_RECEIVER]),
|
|
1100
|
+
slots[SET_OPERATION_VALUE]
|
|
1101
|
+
) != SIZE_MAX;
|
|
1102
|
+
if (in_receiver == stop_when) {
|
|
1103
|
+
*answer = false;
|
|
1104
|
+
result = oseo_iterator_close(
|
|
1105
|
+
context,
|
|
1106
|
+
slots[SET_OPERATION_ITERATOR],
|
|
1107
|
+
false
|
|
1108
|
+
);
|
|
1109
|
+
break;
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
return result;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
static OseoResult set_is_subset_of(
|
|
1116
|
+
OseoContext *context,
|
|
1117
|
+
OseoValue receiver,
|
|
1118
|
+
size_t argument_count,
|
|
1119
|
+
const OseoValue *arguments
|
|
1120
|
+
) {
|
|
1121
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
1122
|
+
double other_size = 0.0;
|
|
1123
|
+
OseoResult result = set_operation_begin(
|
|
1124
|
+
context,
|
|
1125
|
+
receiver,
|
|
1126
|
+
argument_count,
|
|
1127
|
+
arguments,
|
|
1128
|
+
&frame,
|
|
1129
|
+
&other_size
|
|
1130
|
+
);
|
|
1131
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
1132
|
+
bool answer = false;
|
|
1133
|
+
if ((double)set_object(frame.slots[SET_OPERATION_RECEIVER])->size <=
|
|
1134
|
+
other_size) {
|
|
1135
|
+
result = set_visit_receiver(
|
|
1136
|
+
context,
|
|
1137
|
+
frame.slots,
|
|
1138
|
+
SET_VISIT_SUBSET,
|
|
1139
|
+
&answer
|
|
1140
|
+
);
|
|
1141
|
+
}
|
|
1142
|
+
return set_operation_end(
|
|
1143
|
+
context,
|
|
1144
|
+
&frame,
|
|
1145
|
+
result,
|
|
1146
|
+
oseo_boolean(answer)
|
|
1147
|
+
);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
static OseoResult set_is_superset_of(
|
|
1151
|
+
OseoContext *context,
|
|
1152
|
+
OseoValue receiver,
|
|
1153
|
+
size_t argument_count,
|
|
1154
|
+
const OseoValue *arguments
|
|
1155
|
+
) {
|
|
1156
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
1157
|
+
double other_size = 0.0;
|
|
1158
|
+
OseoResult result = set_operation_begin(
|
|
1159
|
+
context,
|
|
1160
|
+
receiver,
|
|
1161
|
+
argument_count,
|
|
1162
|
+
arguments,
|
|
1163
|
+
&frame,
|
|
1164
|
+
&other_size
|
|
1165
|
+
);
|
|
1166
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
1167
|
+
bool answer = false;
|
|
1168
|
+
if ((double)set_object(frame.slots[SET_OPERATION_RECEIVER])->size >=
|
|
1169
|
+
other_size) {
|
|
1170
|
+
result = set_scan_keys(context, frame.slots, false, &answer);
|
|
1171
|
+
}
|
|
1172
|
+
return set_operation_end(
|
|
1173
|
+
context,
|
|
1174
|
+
&frame,
|
|
1175
|
+
result,
|
|
1176
|
+
oseo_boolean(answer)
|
|
1177
|
+
);
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
static OseoResult set_is_disjoint_from(
|
|
1181
|
+
OseoContext *context,
|
|
1182
|
+
OseoValue receiver,
|
|
1183
|
+
size_t argument_count,
|
|
1184
|
+
const OseoValue *arguments
|
|
1185
|
+
) {
|
|
1186
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
1187
|
+
double other_size = 0.0;
|
|
1188
|
+
OseoResult result = set_operation_begin(
|
|
1189
|
+
context,
|
|
1190
|
+
receiver,
|
|
1191
|
+
argument_count,
|
|
1192
|
+
arguments,
|
|
1193
|
+
&frame,
|
|
1194
|
+
&other_size
|
|
1195
|
+
);
|
|
1196
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
1197
|
+
bool answer = true;
|
|
1198
|
+
if ((double)set_object(frame.slots[SET_OPERATION_RECEIVER])->size <=
|
|
1199
|
+
other_size) {
|
|
1200
|
+
result = set_visit_receiver(
|
|
1201
|
+
context,
|
|
1202
|
+
frame.slots,
|
|
1203
|
+
SET_VISIT_DISJOINT,
|
|
1204
|
+
&answer
|
|
1205
|
+
);
|
|
1206
|
+
} else {
|
|
1207
|
+
result = set_scan_keys(context, frame.slots, true, &answer);
|
|
1208
|
+
}
|
|
1209
|
+
return set_operation_end(
|
|
1210
|
+
context,
|
|
1211
|
+
&frame,
|
|
1212
|
+
result,
|
|
1213
|
+
oseo_boolean(answer)
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
OseoResult oseo_internal_set_builtin_dispatch(
|
|
1218
|
+
OseoContext *context,
|
|
1219
|
+
size_t code_id,
|
|
1220
|
+
OseoValue callee,
|
|
1221
|
+
OseoValue receiver,
|
|
1222
|
+
size_t argument_count,
|
|
1223
|
+
const OseoValue *arguments,
|
|
1224
|
+
OseoValue new_target
|
|
1225
|
+
) {
|
|
1226
|
+
(void)callee;
|
|
1227
|
+
if (code_id == OSEO_SET_CONSTRUCTOR_CODE_ID) {
|
|
1228
|
+
return set_constructor(
|
|
1229
|
+
context,
|
|
1230
|
+
argument_count,
|
|
1231
|
+
arguments,
|
|
1232
|
+
new_target
|
|
1233
|
+
);
|
|
1234
|
+
}
|
|
1235
|
+
OseoValue value = argument_count > 0u
|
|
1236
|
+
? arguments[0]
|
|
1237
|
+
: oseo_undefined();
|
|
1238
|
+
if (code_id == OSEO_SET_ADD_CODE_ID) {
|
|
1239
|
+
return set_add(context, receiver, value);
|
|
1240
|
+
}
|
|
1241
|
+
if (code_id == OSEO_SET_CLEAR_CODE_ID) {
|
|
1242
|
+
return set_clear(context, receiver);
|
|
1243
|
+
}
|
|
1244
|
+
if (code_id == OSEO_SET_DELETE_CODE_ID) {
|
|
1245
|
+
return set_delete(context, receiver, value);
|
|
1246
|
+
}
|
|
1247
|
+
if (code_id == OSEO_SET_ENTRIES_CODE_ID) {
|
|
1248
|
+
return set_entries(context, receiver);
|
|
1249
|
+
}
|
|
1250
|
+
if (code_id == OSEO_SET_FOR_EACH_CODE_ID) {
|
|
1251
|
+
return set_for_each(context, receiver, argument_count, arguments);
|
|
1252
|
+
}
|
|
1253
|
+
if (code_id == OSEO_SET_HAS_CODE_ID) {
|
|
1254
|
+
return set_has(context, receiver, value);
|
|
1255
|
+
}
|
|
1256
|
+
if (code_id == OSEO_SET_SIZE_CODE_ID) {
|
|
1257
|
+
return set_size(context, receiver);
|
|
1258
|
+
}
|
|
1259
|
+
if (code_id == OSEO_SET_VALUES_CODE_ID) {
|
|
1260
|
+
return set_values(context, receiver);
|
|
1261
|
+
}
|
|
1262
|
+
if (code_id == OSEO_SET_ITERATOR_NEXT_CODE_ID) {
|
|
1263
|
+
return set_iterator_next(context, receiver);
|
|
1264
|
+
}
|
|
1265
|
+
if (code_id == OSEO_SET_SPECIES_CODE_ID) return normal(receiver);
|
|
1266
|
+
if (code_id == OSEO_SET_UNION_CODE_ID) {
|
|
1267
|
+
return set_union(context, receiver, argument_count, arguments);
|
|
1268
|
+
}
|
|
1269
|
+
if (code_id == OSEO_SET_INTERSECTION_CODE_ID) {
|
|
1270
|
+
return set_intersection(context, receiver, argument_count, arguments);
|
|
1271
|
+
}
|
|
1272
|
+
if (code_id == OSEO_SET_DIFFERENCE_CODE_ID) {
|
|
1273
|
+
return set_difference(context, receiver, argument_count, arguments);
|
|
1274
|
+
}
|
|
1275
|
+
if (code_id == OSEO_SET_SYMMETRIC_DIFFERENCE_CODE_ID) {
|
|
1276
|
+
return set_symmetric_difference(
|
|
1277
|
+
context,
|
|
1278
|
+
receiver,
|
|
1279
|
+
argument_count,
|
|
1280
|
+
arguments
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
if (code_id == OSEO_SET_IS_SUBSET_OF_CODE_ID) {
|
|
1284
|
+
return set_is_subset_of(context, receiver, argument_count, arguments);
|
|
1285
|
+
}
|
|
1286
|
+
if (code_id == OSEO_SET_IS_SUPERSET_OF_CODE_ID) {
|
|
1287
|
+
return set_is_superset_of(
|
|
1288
|
+
context,
|
|
1289
|
+
receiver,
|
|
1290
|
+
argument_count,
|
|
1291
|
+
arguments
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1294
|
+
if (code_id == OSEO_SET_IS_DISJOINT_FROM_CODE_ID) {
|
|
1295
|
+
return set_is_disjoint_from(
|
|
1296
|
+
context,
|
|
1297
|
+
receiver,
|
|
1298
|
+
argument_count,
|
|
1299
|
+
arguments
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
return oseo_unknown_function(context, code_id);
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
static OseoResult create_set_builtin(
|
|
1306
|
+
OseoContext *context,
|
|
1307
|
+
size_t code_id,
|
|
1308
|
+
const char *name,
|
|
1309
|
+
size_t length,
|
|
1310
|
+
OseoFunctionKind kind,
|
|
1311
|
+
OseoFunctionNamePrefix prefix
|
|
1312
|
+
) {
|
|
1313
|
+
size_t name_length = strlen(name);
|
|
1314
|
+
if (name_length > 31u) {
|
|
1315
|
+
return failure(context, "OSEO2001", "Built-in name is too long.");
|
|
1316
|
+
}
|
|
1317
|
+
uint16_t units[31];
|
|
1318
|
+
for (size_t index = 0u; index < name_length; index += 1u) {
|
|
1319
|
+
units[index] = (uint16_t)(unsigned char)name[index];
|
|
1320
|
+
}
|
|
1321
|
+
OseoValue environment = oseo_undefined();
|
|
1322
|
+
OseoRootFrame frame = {NULL, &environment, 1u};
|
|
1323
|
+
oseo_roots_push(context, &frame);
|
|
1324
|
+
OseoResult result = oseo_environment_create(context, 0u);
|
|
1325
|
+
environment = result.value;
|
|
1326
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1327
|
+
result = oseo_function_create(
|
|
1328
|
+
context,
|
|
1329
|
+
code_id,
|
|
1330
|
+
environment,
|
|
1331
|
+
units,
|
|
1332
|
+
name_length,
|
|
1333
|
+
length,
|
|
1334
|
+
kind,
|
|
1335
|
+
oseo_undefined(),
|
|
1336
|
+
oseo_undefined(),
|
|
1337
|
+
prefix
|
|
1338
|
+
);
|
|
1339
|
+
}
|
|
1340
|
+
oseo_roots_pop(context, &frame);
|
|
1341
|
+
return result;
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
static OseoResult define_set_property(
|
|
1345
|
+
OseoContext *context,
|
|
1346
|
+
OseoValue object,
|
|
1347
|
+
OseoValue key,
|
|
1348
|
+
OseoValue value,
|
|
1349
|
+
OseoPropertyAttributes attributes
|
|
1350
|
+
) {
|
|
1351
|
+
OseoValue slots[3] = {object, key, value};
|
|
1352
|
+
OseoRootFrame frame = {NULL, slots, 3u};
|
|
1353
|
+
oseo_roots_push(context, &frame);
|
|
1354
|
+
OseoResult result = oseo_object_define(
|
|
1355
|
+
context,
|
|
1356
|
+
slots[0],
|
|
1357
|
+
slots[1],
|
|
1358
|
+
slots[2],
|
|
1359
|
+
attributes
|
|
1360
|
+
);
|
|
1361
|
+
oseo_roots_pop(context, &frame);
|
|
1362
|
+
return result;
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
static OseoResult define_set_ascii_property(
|
|
1366
|
+
OseoContext *context,
|
|
1367
|
+
OseoValue object,
|
|
1368
|
+
const char *name,
|
|
1369
|
+
OseoValue value,
|
|
1370
|
+
OseoPropertyAttributes attributes
|
|
1371
|
+
) {
|
|
1372
|
+
OseoValue slots[3] = {object, value, oseo_undefined()};
|
|
1373
|
+
OseoRootFrame frame = {NULL, slots, 3u};
|
|
1374
|
+
oseo_roots_push(context, &frame);
|
|
1375
|
+
OseoResult result = oseo_internal_ascii_string(context, name);
|
|
1376
|
+
slots[2] = result.value;
|
|
1377
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1378
|
+
result = oseo_object_define(
|
|
1379
|
+
context,
|
|
1380
|
+
slots[0],
|
|
1381
|
+
slots[2],
|
|
1382
|
+
slots[1],
|
|
1383
|
+
attributes
|
|
1384
|
+
);
|
|
1385
|
+
}
|
|
1386
|
+
oseo_roots_pop(context, &frame);
|
|
1387
|
+
return result;
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
static OseoResult set_intrinsic_build(OseoContext *context) {
|
|
1391
|
+
OseoValue *marker = &context->realm->intrinsics[OSEO_INTRINSIC_SET_SPECIES];
|
|
1392
|
+
if (tag_of(*marker) == OSEO_TAG_UNINITIALIZED) {
|
|
1393
|
+
return failure(
|
|
1394
|
+
context,
|
|
1395
|
+
"OSEO2001",
|
|
1396
|
+
"The Set intrinsic cluster is already being built."
|
|
1397
|
+
);
|
|
1398
|
+
}
|
|
1399
|
+
if (tag_of(*marker) != OSEO_TAG_UNDEFINED) return normal(*marker);
|
|
1400
|
+
size_t entry_allocations = context->allocations;
|
|
1401
|
+
OseoRootFrame frame = {NULL, NULL, 0u};
|
|
1402
|
+
OseoResult result = oseo_roots_allocate(context, &frame, 7u);
|
|
1403
|
+
if (result.status != OSEO_STATUS_NORMAL) return result;
|
|
1404
|
+
*marker = oseo_uninitialized();
|
|
1405
|
+
result = oseo_internal_intrinsic(
|
|
1406
|
+
context,
|
|
1407
|
+
OSEO_INTRINSIC_OBJECT_PROTOTYPE
|
|
1408
|
+
);
|
|
1409
|
+
frame.slots[0] = result.value;
|
|
1410
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1411
|
+
result = oseo_object_create(context, frame.slots[0]);
|
|
1412
|
+
frame.slots[1] = result.value;
|
|
1413
|
+
}
|
|
1414
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1415
|
+
context->realm->intrinsics[OSEO_INTRINSIC_SET_PROTOTYPE] =
|
|
1416
|
+
frame.slots[1];
|
|
1417
|
+
result = oseo_internal_intrinsic(
|
|
1418
|
+
context,
|
|
1419
|
+
OSEO_INTRINSIC_ITERATOR_PROTOTYPE
|
|
1420
|
+
);
|
|
1421
|
+
frame.slots[2] = result.value;
|
|
1422
|
+
}
|
|
1423
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1424
|
+
result = oseo_object_create(context, frame.slots[2]);
|
|
1425
|
+
frame.slots[2] = result.value;
|
|
1426
|
+
}
|
|
1427
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1428
|
+
context->realm->intrinsics[OSEO_INTRINSIC_SET_ITERATOR_PROTOTYPE] =
|
|
1429
|
+
frame.slots[2];
|
|
1430
|
+
result = create_set_builtin(
|
|
1431
|
+
context,
|
|
1432
|
+
OSEO_SET_CONSTRUCTOR_CODE_ID,
|
|
1433
|
+
"Set",
|
|
1434
|
+
0u,
|
|
1435
|
+
OSEO_FUNCTION_ORDINARY,
|
|
1436
|
+
OSEO_FUNCTION_NAME_PREFIX_NONE
|
|
1437
|
+
);
|
|
1438
|
+
frame.slots[3] = result.value;
|
|
1439
|
+
}
|
|
1440
|
+
const OseoPropertyAttributes method = {true, false, true, false};
|
|
1441
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1442
|
+
context->realm->intrinsics[OSEO_INTRINSIC_SET] = frame.slots[3];
|
|
1443
|
+
OseoFunction *constructor = function_object(frame.slots[3]);
|
|
1444
|
+
constructor->prototype_object = frame.slots[1];
|
|
1445
|
+
constructor->prototype_writable = false;
|
|
1446
|
+
result = define_set_ascii_property(
|
|
1447
|
+
context,
|
|
1448
|
+
frame.slots[1],
|
|
1449
|
+
"constructor",
|
|
1450
|
+
frame.slots[3],
|
|
1451
|
+
method
|
|
1452
|
+
);
|
|
1453
|
+
}
|
|
1454
|
+
static const OseoIntrinsic method_intrinsics[] = {
|
|
1455
|
+
OSEO_INTRINSIC_SET_ADD,
|
|
1456
|
+
OSEO_INTRINSIC_SET_CLEAR,
|
|
1457
|
+
OSEO_INTRINSIC_SET_DELETE,
|
|
1458
|
+
OSEO_INTRINSIC_SET_ENTRIES,
|
|
1459
|
+
OSEO_INTRINSIC_SET_FOR_EACH,
|
|
1460
|
+
OSEO_INTRINSIC_SET_HAS,
|
|
1461
|
+
};
|
|
1462
|
+
static const size_t method_codes[] = {
|
|
1463
|
+
OSEO_SET_ADD_CODE_ID,
|
|
1464
|
+
OSEO_SET_CLEAR_CODE_ID,
|
|
1465
|
+
OSEO_SET_DELETE_CODE_ID,
|
|
1466
|
+
OSEO_SET_ENTRIES_CODE_ID,
|
|
1467
|
+
OSEO_SET_FOR_EACH_CODE_ID,
|
|
1468
|
+
OSEO_SET_HAS_CODE_ID,
|
|
1469
|
+
};
|
|
1470
|
+
static const char *const method_names[] = {
|
|
1471
|
+
"add", "clear", "delete", "entries", "forEach", "has",
|
|
1472
|
+
};
|
|
1473
|
+
static const size_t method_lengths[] = {1u, 0u, 1u, 0u, 1u, 1u};
|
|
1474
|
+
for (size_t index = 0u;
|
|
1475
|
+
result.status == OSEO_STATUS_NORMAL && index < 6u;
|
|
1476
|
+
index += 1u) {
|
|
1477
|
+
result = create_set_builtin(
|
|
1478
|
+
context,
|
|
1479
|
+
method_codes[index],
|
|
1480
|
+
method_names[index],
|
|
1481
|
+
method_lengths[index],
|
|
1482
|
+
OSEO_FUNCTION_INTERNAL,
|
|
1483
|
+
OSEO_FUNCTION_NAME_PREFIX_NONE
|
|
1484
|
+
);
|
|
1485
|
+
frame.slots[4] = result.value;
|
|
1486
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
1487
|
+
context->realm->intrinsics[method_intrinsics[index]] = frame.slots[4];
|
|
1488
|
+
result = define_set_ascii_property(
|
|
1489
|
+
context,
|
|
1490
|
+
frame.slots[1],
|
|
1491
|
+
method_names[index],
|
|
1492
|
+
frame.slots[4],
|
|
1493
|
+
method
|
|
1494
|
+
);
|
|
1495
|
+
}
|
|
1496
|
+
/* The composition methods own no realm intrinsic slot: nothing in the
|
|
1497
|
+
* runtime refers to them except their prototype properties. */
|
|
1498
|
+
static const size_t composition_codes[] = {
|
|
1499
|
+
OSEO_SET_UNION_CODE_ID,
|
|
1500
|
+
OSEO_SET_INTERSECTION_CODE_ID,
|
|
1501
|
+
OSEO_SET_DIFFERENCE_CODE_ID,
|
|
1502
|
+
OSEO_SET_SYMMETRIC_DIFFERENCE_CODE_ID,
|
|
1503
|
+
OSEO_SET_IS_SUBSET_OF_CODE_ID,
|
|
1504
|
+
OSEO_SET_IS_SUPERSET_OF_CODE_ID,
|
|
1505
|
+
OSEO_SET_IS_DISJOINT_FROM_CODE_ID,
|
|
1506
|
+
};
|
|
1507
|
+
static const char *const composition_names[] = {
|
|
1508
|
+
"union",
|
|
1509
|
+
"intersection",
|
|
1510
|
+
"difference",
|
|
1511
|
+
"symmetricDifference",
|
|
1512
|
+
"isSubsetOf",
|
|
1513
|
+
"isSupersetOf",
|
|
1514
|
+
"isDisjointFrom",
|
|
1515
|
+
};
|
|
1516
|
+
for (size_t index = 0u;
|
|
1517
|
+
result.status == OSEO_STATUS_NORMAL && index < 7u;
|
|
1518
|
+
index += 1u) {
|
|
1519
|
+
result = create_set_builtin(
|
|
1520
|
+
context,
|
|
1521
|
+
composition_codes[index],
|
|
1522
|
+
composition_names[index],
|
|
1523
|
+
1u,
|
|
1524
|
+
OSEO_FUNCTION_INTERNAL,
|
|
1525
|
+
OSEO_FUNCTION_NAME_PREFIX_NONE
|
|
1526
|
+
);
|
|
1527
|
+
frame.slots[4] = result.value;
|
|
1528
|
+
if (result.status != OSEO_STATUS_NORMAL) break;
|
|
1529
|
+
result = define_set_ascii_property(
|
|
1530
|
+
context,
|
|
1531
|
+
frame.slots[1],
|
|
1532
|
+
composition_names[index],
|
|
1533
|
+
frame.slots[4],
|
|
1534
|
+
method
|
|
1535
|
+
);
|
|
1536
|
+
}
|
|
1537
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1538
|
+
result = create_set_builtin(
|
|
1539
|
+
context,
|
|
1540
|
+
OSEO_SET_SIZE_CODE_ID,
|
|
1541
|
+
"size",
|
|
1542
|
+
0u,
|
|
1543
|
+
OSEO_FUNCTION_INTERNAL,
|
|
1544
|
+
OSEO_FUNCTION_NAME_PREFIX_GET
|
|
1545
|
+
);
|
|
1546
|
+
frame.slots[4] = result.value;
|
|
1547
|
+
}
|
|
1548
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1549
|
+
context->realm->intrinsics[OSEO_INTRINSIC_SET_SIZE] = frame.slots[4];
|
|
1550
|
+
result = oseo_internal_ascii_string(context, "size");
|
|
1551
|
+
frame.slots[5] = result.value;
|
|
1552
|
+
}
|
|
1553
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1554
|
+
result = oseo_object_define_accessor(
|
|
1555
|
+
context,
|
|
1556
|
+
frame.slots[1],
|
|
1557
|
+
frame.slots[5],
|
|
1558
|
+
frame.slots[4],
|
|
1559
|
+
oseo_undefined(),
|
|
1560
|
+
true,
|
|
1561
|
+
false,
|
|
1562
|
+
(OseoPropertyAttributes){true, false, false, true}
|
|
1563
|
+
);
|
|
1564
|
+
}
|
|
1565
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1566
|
+
result = create_set_builtin(
|
|
1567
|
+
context,
|
|
1568
|
+
OSEO_SET_VALUES_CODE_ID,
|
|
1569
|
+
"values",
|
|
1570
|
+
0u,
|
|
1571
|
+
OSEO_FUNCTION_INTERNAL,
|
|
1572
|
+
OSEO_FUNCTION_NAME_PREFIX_NONE
|
|
1573
|
+
);
|
|
1574
|
+
frame.slots[4] = result.value;
|
|
1575
|
+
}
|
|
1576
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1577
|
+
context->realm->intrinsics[OSEO_INTRINSIC_SET_VALUES] = frame.slots[4];
|
|
1578
|
+
result = define_set_ascii_property(
|
|
1579
|
+
context,
|
|
1580
|
+
frame.slots[1],
|
|
1581
|
+
"values",
|
|
1582
|
+
frame.slots[4],
|
|
1583
|
+
method
|
|
1584
|
+
);
|
|
1585
|
+
}
|
|
1586
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1587
|
+
result = define_set_ascii_property(
|
|
1588
|
+
context,
|
|
1589
|
+
frame.slots[1],
|
|
1590
|
+
"keys",
|
|
1591
|
+
frame.slots[4],
|
|
1592
|
+
method
|
|
1593
|
+
);
|
|
1594
|
+
}
|
|
1595
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1596
|
+
result = oseo_internal_well_known_symbol(
|
|
1597
|
+
context,
|
|
1598
|
+
OSEO_WELL_KNOWN_ITERATOR
|
|
1599
|
+
);
|
|
1600
|
+
frame.slots[5] = result.value;
|
|
1601
|
+
}
|
|
1602
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1603
|
+
result = define_set_property(
|
|
1604
|
+
context,
|
|
1605
|
+
frame.slots[1],
|
|
1606
|
+
frame.slots[5],
|
|
1607
|
+
frame.slots[4],
|
|
1608
|
+
method
|
|
1609
|
+
);
|
|
1610
|
+
}
|
|
1611
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1612
|
+
result = oseo_internal_well_known_symbol(
|
|
1613
|
+
context,
|
|
1614
|
+
OSEO_WELL_KNOWN_TO_STRING_TAG
|
|
1615
|
+
);
|
|
1616
|
+
frame.slots[5] = result.value;
|
|
1617
|
+
}
|
|
1618
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1619
|
+
result = oseo_internal_ascii_string(context, "Set");
|
|
1620
|
+
frame.slots[6] = result.value;
|
|
1621
|
+
}
|
|
1622
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1623
|
+
result = define_set_property(
|
|
1624
|
+
context,
|
|
1625
|
+
frame.slots[1],
|
|
1626
|
+
frame.slots[5],
|
|
1627
|
+
frame.slots[6],
|
|
1628
|
+
(OseoPropertyAttributes){true, false, false, false}
|
|
1629
|
+
);
|
|
1630
|
+
}
|
|
1631
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1632
|
+
result = create_set_builtin(
|
|
1633
|
+
context,
|
|
1634
|
+
OSEO_SET_ITERATOR_NEXT_CODE_ID,
|
|
1635
|
+
"next",
|
|
1636
|
+
0u,
|
|
1637
|
+
OSEO_FUNCTION_INTERNAL,
|
|
1638
|
+
OSEO_FUNCTION_NAME_PREFIX_NONE
|
|
1639
|
+
);
|
|
1640
|
+
frame.slots[4] = result.value;
|
|
1641
|
+
}
|
|
1642
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1643
|
+
context->realm->intrinsics[OSEO_INTRINSIC_SET_ITERATOR_NEXT] =
|
|
1644
|
+
frame.slots[4];
|
|
1645
|
+
result = define_set_ascii_property(
|
|
1646
|
+
context,
|
|
1647
|
+
frame.slots[2],
|
|
1648
|
+
"next",
|
|
1649
|
+
frame.slots[4],
|
|
1650
|
+
method
|
|
1651
|
+
);
|
|
1652
|
+
}
|
|
1653
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1654
|
+
result = oseo_internal_well_known_symbol(
|
|
1655
|
+
context,
|
|
1656
|
+
OSEO_WELL_KNOWN_TO_STRING_TAG
|
|
1657
|
+
);
|
|
1658
|
+
frame.slots[5] = result.value;
|
|
1659
|
+
}
|
|
1660
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1661
|
+
result = oseo_internal_ascii_string(context, "Set Iterator");
|
|
1662
|
+
frame.slots[6] = result.value;
|
|
1663
|
+
}
|
|
1664
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1665
|
+
result = define_set_property(
|
|
1666
|
+
context,
|
|
1667
|
+
frame.slots[2],
|
|
1668
|
+
frame.slots[5],
|
|
1669
|
+
frame.slots[6],
|
|
1670
|
+
(OseoPropertyAttributes){true, false, false, false}
|
|
1671
|
+
);
|
|
1672
|
+
}
|
|
1673
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1674
|
+
result = create_set_builtin(
|
|
1675
|
+
context,
|
|
1676
|
+
OSEO_SET_SPECIES_CODE_ID,
|
|
1677
|
+
"[Symbol.species]",
|
|
1678
|
+
0u,
|
|
1679
|
+
OSEO_FUNCTION_INTERNAL,
|
|
1680
|
+
OSEO_FUNCTION_NAME_PREFIX_GET
|
|
1681
|
+
);
|
|
1682
|
+
frame.slots[4] = result.value;
|
|
1683
|
+
}
|
|
1684
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1685
|
+
result = oseo_internal_well_known_symbol(
|
|
1686
|
+
context,
|
|
1687
|
+
OSEO_WELL_KNOWN_SPECIES
|
|
1688
|
+
);
|
|
1689
|
+
frame.slots[5] = result.value;
|
|
1690
|
+
}
|
|
1691
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1692
|
+
result = oseo_object_define_accessor(
|
|
1693
|
+
context,
|
|
1694
|
+
frame.slots[3],
|
|
1695
|
+
frame.slots[5],
|
|
1696
|
+
frame.slots[4],
|
|
1697
|
+
oseo_undefined(),
|
|
1698
|
+
true,
|
|
1699
|
+
false,
|
|
1700
|
+
(OseoPropertyAttributes){true, false, false, true}
|
|
1701
|
+
);
|
|
1702
|
+
}
|
|
1703
|
+
if (result.status != OSEO_STATUS_NORMAL) {
|
|
1704
|
+
for (size_t index = OSEO_INTRINSIC_SET_PROTOTYPE;
|
|
1705
|
+
index <= OSEO_INTRINSIC_SET_SPECIES;
|
|
1706
|
+
index += 1u) {
|
|
1707
|
+
context->realm->intrinsics[index] = oseo_undefined();
|
|
1708
|
+
}
|
|
1709
|
+
oseo_roots_release(context, &frame);
|
|
1710
|
+
return result;
|
|
1711
|
+
}
|
|
1712
|
+
OseoValue species = frame.slots[4];
|
|
1713
|
+
context->realm->intrinsics[OSEO_INTRINSIC_SET_SPECIES] = species;
|
|
1714
|
+
if (context->observe_specialization) {
|
|
1715
|
+
context->allocations = entry_allocations;
|
|
1716
|
+
}
|
|
1717
|
+
oseo_roots_release(context, &frame);
|
|
1718
|
+
return normal(species);
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
OseoResult oseo_internal_set_intrinsic(OseoContext *context) {
|
|
1722
|
+
OseoResult built = set_intrinsic_build(context);
|
|
1723
|
+
if (built.status != OSEO_STATUS_NORMAL) return built;
|
|
1724
|
+
return normal(context->realm->intrinsics[OSEO_INTRINSIC_SET]);
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
OseoResult oseo_internal_install_set_global(
|
|
1728
|
+
OseoContext *context,
|
|
1729
|
+
OseoValue global
|
|
1730
|
+
) {
|
|
1731
|
+
OseoValue slots[3] = {global, oseo_undefined(), oseo_undefined()};
|
|
1732
|
+
OseoRootFrame frame = {NULL, slots, 3u};
|
|
1733
|
+
oseo_roots_push(context, &frame);
|
|
1734
|
+
OseoResult result = oseo_internal_set_intrinsic(context);
|
|
1735
|
+
slots[1] = result.value;
|
|
1736
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1737
|
+
result = oseo_internal_ascii_string(context, "Set");
|
|
1738
|
+
slots[2] = result.value;
|
|
1739
|
+
}
|
|
1740
|
+
if (result.status == OSEO_STATUS_NORMAL) {
|
|
1741
|
+
result = oseo_object_define(
|
|
1742
|
+
context,
|
|
1743
|
+
slots[0],
|
|
1744
|
+
slots[2],
|
|
1745
|
+
slots[1],
|
|
1746
|
+
(OseoPropertyAttributes){true, false, true, false}
|
|
1747
|
+
);
|
|
1748
|
+
}
|
|
1749
|
+
oseo_roots_pop(context, &frame);
|
|
1750
|
+
return result.status == OSEO_STATUS_NORMAL ? normal(slots[0]) : result;
|
|
1751
|
+
}
|