@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.
Files changed (60) hide show
  1. package/LICENSE +674 -0
  2. package/MIT-LICENSE.txt +21 -0
  3. package/README.md +1677 -2
  4. package/UNICODE-LICENSE.txt +39 -0
  5. package/dist/index.d.ts +7 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +269 -0
  8. package/dist/index.js.map +1 -0
  9. package/native/oseo_runtime.h +2594 -0
  10. package/native/runtime_agent.c +1693 -0
  11. package/native/runtime_arguments.c +355 -0
  12. package/native/runtime_array.c +5742 -0
  13. package/native/runtime_array_buffer.c +1724 -0
  14. package/native/runtime_async_generator.c +948 -0
  15. package/native/runtime_atomics.c +1259 -0
  16. package/native/runtime_bigint.c +1363 -0
  17. package/native/runtime_bigint_object.c +602 -0
  18. package/native/runtime_binding.c +1005 -0
  19. package/native/runtime_boolean.c +296 -0
  20. package/native/runtime_clock.c +157 -0
  21. package/native/runtime_clock_posix.c +575 -0
  22. package/native/runtime_core.c +464 -0
  23. package/native/runtime_data_view.c +1111 -0
  24. package/native/runtime_date.c +1973 -0
  25. package/native/runtime_descriptor.c +1080 -0
  26. package/native/runtime_disposal.c +1643 -0
  27. package/native/runtime_enumeration.c +612 -0
  28. package/native/runtime_error.c +973 -0
  29. package/native/runtime_event_loop.c +629 -0
  30. package/native/runtime_function.c +3643 -0
  31. package/native/runtime_generator.c +1096 -0
  32. package/native/runtime_internal.h +5554 -0
  33. package/native/runtime_iterator.c +5355 -0
  34. package/native/runtime_json.c +1968 -0
  35. package/native/runtime_map.c +1539 -0
  36. package/native/runtime_math.c +894 -0
  37. package/native/runtime_memory.c +1341 -0
  38. package/native/runtime_module.c +860 -0
  39. package/native/runtime_number.c +2053 -0
  40. package/native/runtime_object.c +399 -0
  41. package/native/runtime_object_builtin.c +3877 -0
  42. package/native/runtime_primitive.c +2244 -0
  43. package/native/runtime_process.c +720 -0
  44. package/native/runtime_promise.c +3354 -0
  45. package/native/runtime_property.c +791 -0
  46. package/native/runtime_proxy.c +1533 -0
  47. package/native/runtime_realm.c +411 -0
  48. package/native/runtime_reflect.c +624 -0
  49. package/native/runtime_regexp.c +3495 -0
  50. package/native/runtime_regexp_matcher.c +3535 -0
  51. package/native/runtime_regexp_symbol.c +1471 -0
  52. package/native/runtime_set.c +1751 -0
  53. package/native/runtime_string.c +2862 -0
  54. package/native/runtime_string_match.c +1161 -0
  55. package/native/runtime_symbol.c +986 -0
  56. package/native/runtime_typed_array.c +5113 -0
  57. package/native/runtime_unicode_tables.h +14647 -0
  58. package/native/runtime_uri.c +676 -0
  59. package/native/runtime_weak_collection.c +1275 -0
  60. package/package.json +38 -3
@@ -0,0 +1,602 @@
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 <string.h>
8
+
9
+ /*
10
+ * The BigInt object model: the callable %BigInt% intrinsic, its
11
+ * fixed-width statics, %BigInt.prototype% and its methods, and the
12
+ * value conversions ECMA-262 shares with every consumer of the
13
+ * primitive. Nothing here reads a limb; the representation stays behind
14
+ * the private operations runtime_bigint.c exports.
15
+ */
16
+
17
+ /* 2**53 - 1, the largest integer ToIndex admits. */
18
+ #define BIGINT_INDEX_LIMIT 9007199254740991.0
19
+
20
+ static OseoValue bigint_argument(
21
+ size_t argument_count,
22
+ const OseoValue *arguments,
23
+ size_t index
24
+ ) {
25
+ return index < argument_count ? arguments[index] : oseo_undefined();
26
+ }
27
+
28
+ /*
29
+ * ToBigInt over an already primitive value. Both the callable
30
+ * intrinsic and ToBigInt itself reach this after their own
31
+ * ToPrimitive, so neither observes the operand's conversion twice.
32
+ */
33
+ static OseoResult bigint_from_primitive(
34
+ OseoContext *context,
35
+ OseoValue value
36
+ ) {
37
+ if (is_bigint(value)) return normal(value);
38
+ uint64_t tag = tag_of(value);
39
+ if (tag == OSEO_TAG_BOOLEAN) {
40
+ const char *digit = (value & 1u) != 0u ? "1" : "0";
41
+ return oseo_bigint_literal(context, digit, 10u);
42
+ }
43
+ if (is_string(value)) {
44
+ OseoValue slot = value;
45
+ OseoRootFrame frame = {NULL, &slot, 1u};
46
+ oseo_roots_push(context, &frame);
47
+ bool valid = false;
48
+ OseoResult result = oseo_internal_string_to_bigint(
49
+ context,
50
+ string_object(slot),
51
+ &valid
52
+ );
53
+ oseo_roots_pop(context, &frame);
54
+ if (result.status != OSEO_STATUS_NORMAL) return result;
55
+ if (!valid) {
56
+ return oseo_internal_throw_error(
57
+ context,
58
+ OSEO_ERROR_SYNTAX,
59
+ "Cannot convert this string to a BigInt."
60
+ );
61
+ }
62
+ return result;
63
+ }
64
+ const char *message = is_number(value)
65
+ ? "Cannot convert a number to a BigInt."
66
+ : is_symbol(value)
67
+ ? "Cannot convert a symbol to a BigInt."
68
+ : tag == OSEO_TAG_UNDEFINED
69
+ ? "Cannot convert undefined to a BigInt."
70
+ : tag == OSEO_TAG_NULL
71
+ ? "Cannot convert null to a BigInt."
72
+ : NULL;
73
+ if (message == NULL) {
74
+ return failure(context, "OSEO2001", "Value is not a BigInt operand.");
75
+ }
76
+ return oseo_internal_throw_error(context, OSEO_ERROR_TYPE, message);
77
+ }
78
+
79
+ OseoResult oseo_internal_to_bigint(OseoContext *context, OseoValue value) {
80
+ OseoValue slot = value;
81
+ OseoRootFrame frame = {NULL, &slot, 1u};
82
+ oseo_roots_push(context, &frame);
83
+ OseoResult result = oseo_internal_to_primitive(
84
+ context,
85
+ slot,
86
+ OSEO_TO_PRIMITIVE_NUMBER
87
+ );
88
+ slot = result.value;
89
+ if (result.status == OSEO_STATUS_NORMAL) {
90
+ result = bigint_from_primitive(context, slot);
91
+ }
92
+ oseo_roots_pop(context, &frame);
93
+ return result;
94
+ }
95
+
96
+ /*
97
+ * NumberToBigInt(number), 7.1.14. Only an integral Number has an exact
98
+ * BigInt, so NaN, an infinity, and a fractional value are the specified
99
+ * RangeError rather than a rounded result.
100
+ */
101
+ static OseoResult bigint_from_number(OseoContext *context, double number) {
102
+ if (!isfinite(number) || trunc(number) != number) {
103
+ return oseo_internal_throw_error(
104
+ context,
105
+ OSEO_ERROR_RANGE,
106
+ "Cannot convert a non-integral number to a BigInt."
107
+ );
108
+ }
109
+ return oseo_internal_bigint_from_integral_number(context, number);
110
+ }
111
+
112
+ /*
113
+ * BigInt ( value ), 21.2.1.1. Its [[Construct]] path always throws before
114
+ * conversion. Its [[Call]] path uses the ToPrimitive result to choose the
115
+ * Number branch or shared ToBigInt without converting the operand again.
116
+ */
117
+ static OseoResult bigint_call(
118
+ OseoContext *context,
119
+ size_t argument_count,
120
+ const OseoValue *arguments,
121
+ bool constructing
122
+ ) {
123
+ if (constructing) {
124
+ return oseo_internal_throw_error(
125
+ context,
126
+ OSEO_ERROR_TYPE,
127
+ "BigInt is not a constructor."
128
+ );
129
+ }
130
+ OseoValue slot = bigint_argument(argument_count, arguments, 0u);
131
+ OseoRootFrame frame = {NULL, &slot, 1u};
132
+ oseo_roots_push(context, &frame);
133
+ OseoResult result = oseo_internal_to_primitive(
134
+ context,
135
+ slot,
136
+ OSEO_TO_PRIMITIVE_NUMBER
137
+ );
138
+ slot = result.value;
139
+ if (result.status == OSEO_STATUS_NORMAL) {
140
+ result = is_number(slot)
141
+ ? bigint_from_number(context, number_value(slot))
142
+ : bigint_from_primitive(context, slot);
143
+ }
144
+ oseo_roots_pop(context, &frame);
145
+ return result;
146
+ }
147
+
148
+ /* ToIndex(value), 7.1.22, reported as the integer it admits. */
149
+ static OseoResult bigint_to_index(
150
+ OseoContext *context,
151
+ OseoValue value,
152
+ double *index
153
+ ) {
154
+ OseoResult number = oseo_internal_to_number(context, value);
155
+ if (number.status != OSEO_STATUS_NORMAL) return number;
156
+ double integer = number_value(number.value);
157
+ if (isnan(integer) || integer == 0.0) integer = 0.0;
158
+ else if (isfinite(integer)) integer = trunc(integer);
159
+ if (!(integer >= 0.0) || integer > BIGINT_INDEX_LIMIT) {
160
+ return oseo_internal_throw_error(
161
+ context,
162
+ OSEO_ERROR_RANGE,
163
+ "BigInt fixed-width bit count is outside the index range."
164
+ );
165
+ }
166
+ *index = integer;
167
+ return normal(oseo_number(integer));
168
+ }
169
+
170
+ /*
171
+ * BigInt.asIntN ( bits, bigint ) and BigInt.asUintN ( bits, bigint ),
172
+ * 21.2.2.1 and 21.2.2.2. The width converts before the operand, so a
173
+ * bad width is observed first even when both arguments have side
174
+ * effects.
175
+ */
176
+ static OseoResult bigint_as_width(
177
+ OseoContext *context,
178
+ size_t argument_count,
179
+ const OseoValue *arguments,
180
+ bool signed_result
181
+ ) {
182
+ OseoValue slots[2] = {
183
+ bigint_argument(argument_count, arguments, 0u),
184
+ bigint_argument(argument_count, arguments, 1u),
185
+ };
186
+ OseoRootFrame frame = {NULL, slots, 2u};
187
+ oseo_roots_push(context, &frame);
188
+ double bits = 0.0;
189
+ OseoResult result = bigint_to_index(context, slots[0], &bits);
190
+ if (result.status == OSEO_STATUS_NORMAL) {
191
+ result = oseo_internal_to_bigint(context, slots[1]);
192
+ slots[1] = result.value;
193
+ }
194
+ if (result.status == OSEO_STATUS_NORMAL) {
195
+ result = oseo_internal_bigint_as_width(
196
+ context,
197
+ slots[1],
198
+ bits,
199
+ signed_result
200
+ );
201
+ }
202
+ oseo_roots_pop(context, &frame);
203
+ return result;
204
+ }
205
+
206
+ /*
207
+ * thisBigIntValue(value), 21.2.3. %BigInt.prototype% is an ordinary
208
+ * object without a [[BigIntData]] slot, so calling a method directly on
209
+ * it is the same TypeError as calling it on any other receiver.
210
+ */
211
+ static OseoResult bigint_this_value(
212
+ OseoContext *context,
213
+ OseoValue receiver
214
+ ) {
215
+ if (is_bigint(receiver)) return normal(receiver);
216
+ if (is_object(receiver) && ordinary_object(receiver)->primitive_data &&
217
+ is_bigint(ordinary_object(receiver)->primitive_value)) {
218
+ return normal(ordinary_object(receiver)->primitive_value);
219
+ }
220
+ return oseo_internal_throw_error(
221
+ context,
222
+ OSEO_ERROR_TYPE,
223
+ "BigInt.prototype method requires a BigInt receiver."
224
+ );
225
+ }
226
+
227
+ /*
228
+ * BigInt.prototype.toString ( [ radix ] ), 21.2.3.3. The receiver brand
229
+ * check precedes the radix conversion, so an unbranded receiver reports
230
+ * its TypeError even when the radix is also invalid.
231
+ */
232
+ static OseoResult bigint_to_string(
233
+ OseoContext *context,
234
+ OseoValue receiver,
235
+ size_t argument_count,
236
+ const OseoValue *arguments
237
+ ) {
238
+ OseoRootFrame frame = {NULL, NULL, 0u};
239
+ OseoResult result = oseo_roots_allocate(context, &frame, 2u);
240
+ if (result.status != OSEO_STATUS_NORMAL) return result;
241
+ frame.slots[0] = receiver;
242
+ result = bigint_this_value(context, frame.slots[0]);
243
+ frame.slots[1] = result.value;
244
+ OseoValue radix_argument = bigint_argument(argument_count, arguments, 0u);
245
+ uint32_t radix = 10u;
246
+ if (result.status == OSEO_STATUS_NORMAL &&
247
+ tag_of(radix_argument) != OSEO_TAG_UNDEFINED) {
248
+ frame.slots[0] = radix_argument;
249
+ OseoResult number = oseo_internal_to_number(context, frame.slots[0]);
250
+ if (number.status != OSEO_STATUS_NORMAL) {
251
+ result = number;
252
+ } else {
253
+ double value = number_value(number.value);
254
+ if (isnan(value) || value == 0.0) value = 0.0;
255
+ else if (isfinite(value)) value = trunc(value);
256
+ if (!(value >= 2.0 && value <= 36.0)) {
257
+ result = oseo_internal_throw_error(
258
+ context,
259
+ OSEO_ERROR_RANGE,
260
+ "BigInt.prototype.toString radix must be within 2..36."
261
+ );
262
+ } else {
263
+ radix = (uint32_t)value;
264
+ }
265
+ }
266
+ }
267
+ if (result.status == OSEO_STATUS_NORMAL) {
268
+ result = oseo_internal_bigint_radix_string(
269
+ context,
270
+ frame.slots[1],
271
+ radix
272
+ );
273
+ }
274
+ oseo_roots_release(context, &frame);
275
+ return result;
276
+ }
277
+
278
+ /*
279
+ * BigInt.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ),
280
+ * 21.2.3.2. Without the ECMA-402 Internationalization API, the base
281
+ * specification's own recommended behavior is thisBigIntValue followed
282
+ * by ToString, so the reserved positions are ignored rather than read.
283
+ */
284
+ static OseoResult bigint_to_locale_string(
285
+ OseoContext *context,
286
+ OseoValue receiver
287
+ ) {
288
+ OseoResult result = bigint_this_value(context, receiver);
289
+ if (result.status != OSEO_STATUS_NORMAL) return result;
290
+ return oseo_internal_bigint_string(context, result.value);
291
+ }
292
+
293
+ OseoResult oseo_internal_bigint_builtin_dispatch(
294
+ OseoContext *context,
295
+ size_t code_id,
296
+ OseoValue callee,
297
+ OseoValue receiver,
298
+ size_t argument_count,
299
+ const OseoValue *arguments,
300
+ OseoValue new_target
301
+ ) {
302
+ (void)callee;
303
+ bool constructing = tag_of(new_target) != OSEO_TAG_UNDEFINED;
304
+ if (code_id == OSEO_BIGINT_CONSTRUCTOR_CODE_ID) {
305
+ return bigint_call(context, argument_count, arguments, constructing);
306
+ }
307
+ if (constructing) {
308
+ return oseo_internal_throw_error(
309
+ context,
310
+ OSEO_ERROR_TYPE,
311
+ "BigInt method is not a constructor."
312
+ );
313
+ }
314
+ if (code_id == OSEO_BIGINT_AS_INT_N_CODE_ID) {
315
+ return bigint_as_width(context, argument_count, arguments, true);
316
+ }
317
+ if (code_id == OSEO_BIGINT_AS_UINT_N_CODE_ID) {
318
+ return bigint_as_width(context, argument_count, arguments, false);
319
+ }
320
+ if (code_id == OSEO_BIGINT_TO_STRING_CODE_ID) {
321
+ return bigint_to_string(context, receiver, argument_count, arguments);
322
+ }
323
+ if (code_id == OSEO_BIGINT_TO_LOCALE_STRING_CODE_ID) {
324
+ return bigint_to_locale_string(context, receiver);
325
+ }
326
+ if (code_id == OSEO_BIGINT_VALUE_OF_CODE_ID) {
327
+ return bigint_this_value(context, receiver);
328
+ }
329
+ return oseo_unknown_function(context, code_id);
330
+ }
331
+
332
+ static OseoResult create_bigint_builtin(
333
+ OseoContext *context,
334
+ size_t code_id,
335
+ const char *name,
336
+ size_t length
337
+ ) {
338
+ size_t name_length = strlen(name);
339
+ if (name_length > 31u) {
340
+ return failure(context, "OSEO2001", "Built-in name is too long.");
341
+ }
342
+ uint16_t units[31];
343
+ for (size_t index = 0u; index < name_length; index += 1u) {
344
+ units[index] = (uint16_t)(unsigned char)name[index];
345
+ }
346
+ OseoValue environment = oseo_undefined();
347
+ OseoRootFrame frame = {NULL, &environment, 1u};
348
+ oseo_roots_push(context, &frame);
349
+ OseoResult result = oseo_environment_create(context, 0u);
350
+ environment = result.value;
351
+ if (result.status == OSEO_STATUS_NORMAL) {
352
+ OseoFunctionKind kind = code_id == OSEO_BIGINT_CONSTRUCTOR_CODE_ID
353
+ ? OSEO_FUNCTION_ORDINARY
354
+ : OSEO_FUNCTION_INTERNAL;
355
+ result = oseo_function_create(
356
+ context,
357
+ code_id,
358
+ environment,
359
+ units,
360
+ name_length,
361
+ length,
362
+ kind,
363
+ oseo_undefined(),
364
+ oseo_undefined(),
365
+ OSEO_FUNCTION_NAME_PREFIX_NONE
366
+ );
367
+ }
368
+ oseo_roots_pop(context, &frame);
369
+ return result;
370
+ }
371
+
372
+ static OseoResult define_bigint_property(
373
+ OseoContext *context,
374
+ OseoValue object,
375
+ const char *name,
376
+ OseoValue value,
377
+ OseoPropertyAttributes attributes
378
+ ) {
379
+ OseoValue slots[3] = {object, value, oseo_undefined()};
380
+ OseoRootFrame frame = {NULL, slots, 3u};
381
+ oseo_roots_push(context, &frame);
382
+ OseoResult result = oseo_internal_ascii_string(context, name);
383
+ slots[2] = result.value;
384
+ if (result.status == OSEO_STATUS_NORMAL) {
385
+ result = oseo_object_define(
386
+ context,
387
+ slots[0],
388
+ slots[2],
389
+ slots[1],
390
+ attributes
391
+ );
392
+ }
393
+ oseo_roots_pop(context, &frame);
394
+ return result;
395
+ }
396
+
397
+ /*
398
+ * Materializes %BigInt% and %BigInt.prototype% together, so a BigInt
399
+ * wrapper reached without naming `BigInt` still finds every specified
400
+ * own property on its prototype chain.
401
+ *
402
+ * `OSEO_INTRINSIC_BIGINT_VALUE_OF` is filled last, so it doubles as the
403
+ * completion marker: a partially built cluster leaves it undefined and
404
+ * the failure path clears every slot the attempt filled, while the
405
+ * uninitialized sentinel reports a reentrant build attempt instead of
406
+ * splitting identities across two concurrent attempts.
407
+ */
408
+ static OseoResult bigint_intrinsic_build(OseoContext *context) {
409
+ OseoValue *marker =
410
+ &context->realm->intrinsics[OSEO_INTRINSIC_BIGINT_VALUE_OF];
411
+ if (tag_of(*marker) == OSEO_TAG_UNINITIALIZED) {
412
+ return failure(
413
+ context,
414
+ "OSEO2001",
415
+ "The BigInt intrinsic cluster is already being built."
416
+ );
417
+ }
418
+ if (tag_of(*marker) != OSEO_TAG_UNDEFINED) return normal(*marker);
419
+ size_t entry_allocations = context->allocations;
420
+ OseoRootFrame frame = {NULL, NULL, 0u};
421
+ OseoResult result = oseo_roots_allocate(context, &frame, 5u);
422
+ if (result.status != OSEO_STATUS_NORMAL) return result;
423
+ *marker = oseo_uninitialized();
424
+
425
+ result = create_bigint_builtin(
426
+ context,
427
+ OSEO_BIGINT_CONSTRUCTOR_CODE_ID,
428
+ "BigInt",
429
+ 1u
430
+ );
431
+ frame.slots[0] = result.value;
432
+ if (result.status == OSEO_STATUS_NORMAL) {
433
+ /*
434
+ * The ordinary function kind supplies [[Construct]] and its synthetic
435
+ * `prototype` property. Dispatch still rejects every construction
436
+ * before conversion, while IsConstructor consumers can observe the
437
+ * specified slot. %BigInt.prototype% remains an ordinary object with
438
+ * no [[BigIntData]] slot.
439
+ */
440
+ frame.slots[1] = function_object(frame.slots[0])->prototype_object;
441
+ OseoFunction *constructor = function_object(frame.slots[0]);
442
+ constructor->prototype_writable = false;
443
+ context->realm->intrinsics[OSEO_INTRINSIC_BIGINT] = frame.slots[0];
444
+ context->realm->intrinsics[OSEO_INTRINSIC_BIGINT_PROTOTYPE] =
445
+ frame.slots[1];
446
+ }
447
+ static const OseoIntrinsic static_intrinsics[] = {
448
+ OSEO_INTRINSIC_BIGINT_AS_INT_N,
449
+ OSEO_INTRINSIC_BIGINT_AS_UINT_N,
450
+ };
451
+ static const size_t static_codes[] = {
452
+ OSEO_BIGINT_AS_INT_N_CODE_ID,
453
+ OSEO_BIGINT_AS_UINT_N_CODE_ID,
454
+ };
455
+ static const char *const static_names[] = {"asIntN", "asUintN"};
456
+ for (size_t index = 0u;
457
+ result.status == OSEO_STATUS_NORMAL && index < 2u;
458
+ index += 1u) {
459
+ result = create_bigint_builtin(
460
+ context,
461
+ static_codes[index],
462
+ static_names[index],
463
+ 2u
464
+ );
465
+ frame.slots[2] = result.value;
466
+ if (result.status == OSEO_STATUS_NORMAL) {
467
+ context->realm->intrinsics[static_intrinsics[index]] =
468
+ frame.slots[2];
469
+ result = define_bigint_property(
470
+ context,
471
+ frame.slots[0],
472
+ static_names[index],
473
+ frame.slots[2],
474
+ (OseoPropertyAttributes){true, false, true, false}
475
+ );
476
+ }
477
+ }
478
+ if (result.status == OSEO_STATUS_NORMAL) {
479
+ result = define_bigint_property(
480
+ context,
481
+ frame.slots[1],
482
+ "constructor",
483
+ frame.slots[0],
484
+ (OseoPropertyAttributes){true, false, true, false}
485
+ );
486
+ }
487
+ static const size_t method_codes[] = {
488
+ OSEO_BIGINT_TO_STRING_CODE_ID,
489
+ OSEO_BIGINT_TO_LOCALE_STRING_CODE_ID,
490
+ };
491
+ static const OseoIntrinsic method_intrinsics[] = {
492
+ OSEO_INTRINSIC_BIGINT_TO_STRING,
493
+ OSEO_INTRINSIC_BIGINT_TO_LOCALE_STRING,
494
+ };
495
+ static const char *const method_names[] = {"toString", "toLocaleString"};
496
+ for (size_t index = 0u;
497
+ result.status == OSEO_STATUS_NORMAL && index < 2u;
498
+ index += 1u) {
499
+ result = create_bigint_builtin(
500
+ context,
501
+ method_codes[index],
502
+ method_names[index],
503
+ 0u
504
+ );
505
+ frame.slots[2] = result.value;
506
+ if (result.status == OSEO_STATUS_NORMAL) {
507
+ context->realm->intrinsics[method_intrinsics[index]] =
508
+ frame.slots[2];
509
+ result = define_bigint_property(
510
+ context,
511
+ frame.slots[1],
512
+ method_names[index],
513
+ frame.slots[2],
514
+ (OseoPropertyAttributes){true, false, true, false}
515
+ );
516
+ }
517
+ }
518
+ if (result.status == OSEO_STATUS_NORMAL) {
519
+ result = oseo_internal_well_known_symbol(
520
+ context,
521
+ OSEO_WELL_KNOWN_TO_STRING_TAG
522
+ );
523
+ frame.slots[3] = result.value;
524
+ }
525
+ if (result.status == OSEO_STATUS_NORMAL) {
526
+ result = oseo_internal_ascii_string(context, "BigInt");
527
+ frame.slots[4] = result.value;
528
+ }
529
+ if (result.status == OSEO_STATUS_NORMAL) {
530
+ result = oseo_object_define(
531
+ context,
532
+ frame.slots[1],
533
+ frame.slots[3],
534
+ frame.slots[4],
535
+ (OseoPropertyAttributes){true, false, false, false}
536
+ );
537
+ }
538
+ if (result.status == OSEO_STATUS_NORMAL) {
539
+ result = create_bigint_builtin(
540
+ context,
541
+ OSEO_BIGINT_VALUE_OF_CODE_ID,
542
+ "valueOf",
543
+ 0u
544
+ );
545
+ frame.slots[2] = result.value;
546
+ }
547
+ if (result.status == OSEO_STATUS_NORMAL) {
548
+ result = define_bigint_property(
549
+ context,
550
+ frame.slots[1],
551
+ "valueOf",
552
+ frame.slots[2],
553
+ (OseoPropertyAttributes){true, false, true, false}
554
+ );
555
+ }
556
+ if (result.status != OSEO_STATUS_NORMAL) {
557
+ context->realm->intrinsics[OSEO_INTRINSIC_BIGINT_PROTOTYPE] =
558
+ oseo_undefined();
559
+ for (size_t index = OSEO_INTRINSIC_BIGINT;
560
+ index <= OSEO_INTRINSIC_BIGINT_VALUE_OF;
561
+ index += 1u) {
562
+ context->realm->intrinsics[index] = oseo_undefined();
563
+ }
564
+ oseo_roots_release(context, &frame);
565
+ return result;
566
+ }
567
+ OseoValue value_of = frame.slots[2];
568
+ context->realm->intrinsics[OSEO_INTRINSIC_BIGINT_VALUE_OF] = value_of;
569
+ if (context->observe_specialization) {
570
+ context->allocations = entry_allocations;
571
+ }
572
+ oseo_roots_release(context, &frame);
573
+ return normal(value_of);
574
+ }
575
+
576
+ OseoResult oseo_internal_bigint_intrinsic(OseoContext *context) {
577
+ OseoResult built = bigint_intrinsic_build(context);
578
+ if (built.status != OSEO_STATUS_NORMAL) return built;
579
+ return normal(context->realm->intrinsics[OSEO_INTRINSIC_BIGINT]);
580
+ }
581
+
582
+ OseoResult oseo_internal_install_bigint_global(
583
+ OseoContext *context,
584
+ OseoValue global
585
+ ) {
586
+ OseoValue slots[2] = {global, oseo_undefined()};
587
+ OseoRootFrame frame = {NULL, slots, 2u};
588
+ oseo_roots_push(context, &frame);
589
+ OseoResult result = oseo_internal_bigint_intrinsic(context);
590
+ slots[1] = result.value;
591
+ if (result.status == OSEO_STATUS_NORMAL) {
592
+ result = define_bigint_property(
593
+ context,
594
+ slots[0],
595
+ "BigInt",
596
+ slots[1],
597
+ (OseoPropertyAttributes){true, false, true, false}
598
+ );
599
+ }
600
+ oseo_roots_pop(context, &frame);
601
+ return result.status == OSEO_STATUS_NORMAL ? normal(slots[0]) : result;
602
+ }