@oseo/runtime-c 0.0.0-stage → 0.1.0-canary.370

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