@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,1185 @@
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 <stdlib.h>
32
+ #include <string.h>
33
+
34
+ /*
35
+ * String.prototype methods whose first operand may dispatch through a
36
+ * well-known symbol. String-only fallbacks stay separate from the core
37
+ * String value and wrapper implementation so neighboring M5b nodes do not
38
+ * need to edit the same algorithm body.
39
+ */
40
+
41
+ static OseoValue match_argument(
42
+ size_t argument_count,
43
+ const OseoValue *arguments,
44
+ size_t index
45
+ ) {
46
+ return index < argument_count ? arguments[index] : oseo_undefined();
47
+ }
48
+
49
+ static OseoResult match_subject(
50
+ OseoContext *context,
51
+ OseoValue receiver
52
+ ) {
53
+ if (is_nullish(receiver)) {
54
+ return oseo_internal_throw_error(
55
+ context,
56
+ OSEO_ERROR_TYPE,
57
+ "String method receiver is nullish."
58
+ );
59
+ }
60
+ return oseo_internal_value_string(context, receiver);
61
+ }
62
+
63
+ static bool match_matches_at(
64
+ const OseoString *subject,
65
+ const OseoString *search,
66
+ size_t position
67
+ ) {
68
+ if (position > subject->length ||
69
+ search->length > subject->length - position) return false;
70
+ return search->length == 0u ||
71
+ memcmp(
72
+ subject->units + position,
73
+ search->units,
74
+ search->length * sizeof(uint16_t)
75
+ ) == 0;
76
+ }
77
+
78
+ static OseoResult match_is_regexp(
79
+ OseoContext *context,
80
+ OseoValue value,
81
+ bool *regexp
82
+ ) {
83
+ return oseo_internal_is_regexp(context, value, regexp);
84
+ }
85
+
86
+ static bool string_find(
87
+ OseoValue subject_value,
88
+ OseoValue search_value,
89
+ size_t start,
90
+ size_t *position
91
+ ) {
92
+ const OseoString *subject = string_object(subject_value);
93
+ const OseoString *search = string_object(search_value);
94
+ if (start > subject->length || search->length > subject->length) {
95
+ return false;
96
+ }
97
+ size_t last = subject->length - search->length;
98
+ for (size_t index = start; index <= last; index += 1u) {
99
+ if (match_matches_at(subject, search, index)) {
100
+ *position = index;
101
+ return true;
102
+ }
103
+ }
104
+ return false;
105
+ }
106
+
107
+ static size_t string_symbol_index(size_t code_id) {
108
+ if (code_id == OSEO_STRING_MATCH_CODE_ID) return OSEO_WELL_KNOWN_MATCH;
109
+ if (code_id == OSEO_STRING_MATCH_ALL_CODE_ID) {
110
+ return OSEO_WELL_KNOWN_MATCH_ALL;
111
+ }
112
+ if (code_id == OSEO_STRING_SEARCH_CODE_ID) return OSEO_WELL_KNOWN_SEARCH;
113
+ if (code_id == OSEO_STRING_REPLACE_CODE_ID ||
114
+ code_id == OSEO_STRING_REPLACE_ALL_CODE_ID) {
115
+ return OSEO_WELL_KNOWN_REPLACE;
116
+ }
117
+ return OSEO_WELL_KNOWN_SPLIT;
118
+ }
119
+
120
+ /* The two methods whose operand must name a global RegExp when it is one. */
121
+ static bool string_requires_global_flags(size_t code_id) {
122
+ return code_id == OSEO_STRING_MATCH_ALL_CODE_ID ||
123
+ code_id == OSEO_STRING_REPLACE_ALL_CODE_ID;
124
+ }
125
+
126
+ /* The methods that forward a second argument to their symbol method. */
127
+ static bool string_forwards_second_argument(size_t code_id) {
128
+ return code_id == OSEO_STRING_SPLIT_CODE_ID ||
129
+ code_id == OSEO_STRING_REPLACE_CODE_ID ||
130
+ code_id == OSEO_STRING_REPLACE_ALL_CODE_ID;
131
+ }
132
+
133
+ /*
134
+ * The `flags` observation String.prototype.matchAll and replaceAll share
135
+ * once IsRegExp reports true for their operand: the value must be
136
+ * object-coercible and its String form must contain `g`.
137
+ */
138
+ static OseoResult string_require_global_flags(
139
+ OseoContext *context,
140
+ size_t code_id,
141
+ OseoValue regexp
142
+ ) {
143
+ bool match_all = code_id == OSEO_STRING_MATCH_ALL_CODE_ID;
144
+ OseoValue slots[3] = {regexp, oseo_undefined(), oseo_undefined()};
145
+ OseoRootFrame frame = {NULL, slots, 3u};
146
+ oseo_roots_push(context, &frame);
147
+ OseoResult result = oseo_internal_ascii_string(context, "flags");
148
+ slots[1] = result.value;
149
+ if (result.status == OSEO_STATUS_NORMAL) {
150
+ result = oseo_object_get(context, slots[0], slots[1]);
151
+ slots[2] = result.value;
152
+ }
153
+ if (result.status == OSEO_STATUS_NORMAL && is_nullish(slots[2])) {
154
+ result = oseo_internal_throw_error(
155
+ context,
156
+ OSEO_ERROR_TYPE,
157
+ match_all
158
+ ? "String.prototype.matchAll flags are nullish."
159
+ : "String.prototype.replaceAll flags are nullish."
160
+ );
161
+ }
162
+ if (result.status == OSEO_STATUS_NORMAL) {
163
+ result = oseo_internal_value_string(context, slots[2]);
164
+ slots[2] = result.value;
165
+ }
166
+ bool global = false;
167
+ if (result.status == OSEO_STATUS_NORMAL) {
168
+ const OseoString *flags = string_object(slots[2]);
169
+ for (size_t index = 0u; index < flags->length; index += 1u) {
170
+ if (flags->units[index] == UINT16_C(0x67)) {
171
+ global = true;
172
+ break;
173
+ }
174
+ }
175
+ if (!global) {
176
+ result = oseo_internal_throw_error(
177
+ context,
178
+ OSEO_ERROR_TYPE,
179
+ match_all
180
+ ? "String.prototype.matchAll requires a global RegExp."
181
+ : "String.prototype.replaceAll requires a global RegExp."
182
+ );
183
+ }
184
+ }
185
+ oseo_roots_pop(context, &frame);
186
+ return result;
187
+ }
188
+
189
+ static OseoResult string_protocol_method(
190
+ OseoContext *context,
191
+ size_t code_id,
192
+ OseoValue receiver,
193
+ size_t argument_count,
194
+ const OseoValue *arguments,
195
+ bool *dispatched
196
+ ) {
197
+ *dispatched = false;
198
+ if (is_nullish(receiver)) {
199
+ return oseo_internal_throw_error(
200
+ context,
201
+ OSEO_ERROR_TYPE,
202
+ "String method receiver is nullish."
203
+ );
204
+ }
205
+ OseoRootFrame frame = {NULL, NULL, 0u};
206
+ OseoResult result = oseo_roots_allocate(context, &frame, 4u);
207
+ if (result.status != OSEO_STATUS_NORMAL) return result;
208
+ frame.slots[0] = receiver;
209
+ frame.slots[1] = match_argument(
210
+ argument_count,
211
+ arguments,
212
+ 0u
213
+ );
214
+ frame.slots[2] = match_argument(
215
+ argument_count,
216
+ arguments,
217
+ 1u
218
+ );
219
+ frame.slots[3] = oseo_undefined();
220
+ bool regexp = false;
221
+ /*
222
+ * Every one of these methods observes its operand only when the operand
223
+ * is an Object, so a primitive never reaches IsRegExp, the `flags` read,
224
+ * or the symbol lookup.
225
+ */
226
+ if (string_requires_global_flags(code_id) && is_object(frame.slots[1])) {
227
+ result = match_is_regexp(context, frame.slots[1], &regexp);
228
+ if (result.status == OSEO_STATUS_NORMAL && regexp) {
229
+ result = string_require_global_flags(
230
+ context,
231
+ code_id,
232
+ frame.slots[1]
233
+ );
234
+ }
235
+ }
236
+ if (result.status == OSEO_STATUS_NORMAL &&
237
+ is_object(frame.slots[1])) {
238
+ result = oseo_internal_well_known_symbol(
239
+ context,
240
+ string_symbol_index(code_id)
241
+ );
242
+ frame.slots[3] = result.value;
243
+ }
244
+ if (result.status == OSEO_STATUS_NORMAL &&
245
+ is_object(frame.slots[1])) {
246
+ result = oseo_object_get(
247
+ context,
248
+ frame.slots[1],
249
+ frame.slots[3]
250
+ );
251
+ frame.slots[3] = result.value;
252
+ }
253
+ if (result.status == OSEO_STATUS_NORMAL &&
254
+ !is_nullish(frame.slots[3])) {
255
+ if (!is_callable(frame.slots[3])) {
256
+ result = oseo_internal_throw_error(
257
+ context,
258
+ OSEO_ERROR_TYPE,
259
+ "String symbol protocol method is not callable."
260
+ );
261
+ } else {
262
+ size_t call_count =
263
+ string_forwards_second_argument(code_id) ? 2u : 1u;
264
+ OseoValue call_arguments[2] = {
265
+ frame.slots[0],
266
+ frame.slots[2],
267
+ };
268
+ result = oseo_call_function(
269
+ context,
270
+ frame.slots[3],
271
+ frame.slots[1],
272
+ call_count,
273
+ call_arguments,
274
+ oseo_undefined()
275
+ );
276
+ *dispatched = true;
277
+ }
278
+ }
279
+ oseo_roots_release(context, &frame);
280
+ return result;
281
+ }
282
+
283
+ /*
284
+ * The shared tail of String.prototype match, matchAll, and search once
285
+ * GetMethod found no symbol method on the operand: RegExpCreate over the
286
+ * raw operand, then Invoke of the same well-known symbol on the created
287
+ * RegExp. The created object is an ordinary %RegExp.prototype% instance,
288
+ * so the invoked method is the built-in one unless the program replaced
289
+ * it, which is exactly what the specification observes here.
290
+ */
291
+ static OseoResult string_regexp_dispatch(
292
+ OseoContext *context,
293
+ size_t code_id,
294
+ OseoValue receiver,
295
+ OseoValue pattern,
296
+ const char *flags
297
+ ) {
298
+ OseoRootFrame frame = {NULL, NULL, 0u};
299
+ OseoResult result = oseo_roots_allocate(context, &frame, 4u);
300
+ if (result.status != OSEO_STATUS_NORMAL) return result;
301
+ /* 0: subject, 1: pattern, 2: created RegExp, 3: symbol then method */
302
+ frame.slots[1] = pattern;
303
+ result = match_subject(context, receiver);
304
+ frame.slots[0] = result.value;
305
+ if (result.status == OSEO_STATUS_NORMAL && flags != NULL) {
306
+ result = oseo_internal_ascii_string(context, flags);
307
+ frame.slots[2] = result.value;
308
+ }
309
+ if (result.status == OSEO_STATUS_NORMAL) {
310
+ result = oseo_internal_regexp_create(
311
+ context,
312
+ frame.slots[1],
313
+ flags == NULL ? oseo_undefined() : frame.slots[2]
314
+ );
315
+ frame.slots[2] = result.value;
316
+ }
317
+ if (result.status == OSEO_STATUS_NORMAL) {
318
+ result = oseo_internal_well_known_symbol(
319
+ context,
320
+ string_symbol_index(code_id)
321
+ );
322
+ frame.slots[3] = result.value;
323
+ }
324
+ if (result.status == OSEO_STATUS_NORMAL) {
325
+ result = oseo_object_get(context, frame.slots[2], frame.slots[3]);
326
+ frame.slots[3] = result.value;
327
+ }
328
+ if (result.status == OSEO_STATUS_NORMAL && !is_callable(frame.slots[3])) {
329
+ result = oseo_internal_throw_error(
330
+ context,
331
+ OSEO_ERROR_TYPE,
332
+ "String symbol protocol method is not callable."
333
+ );
334
+ }
335
+ if (result.status == OSEO_STATUS_NORMAL) {
336
+ result = oseo_call_function(
337
+ context,
338
+ frame.slots[3],
339
+ frame.slots[2],
340
+ 1u,
341
+ &frame.slots[0],
342
+ oseo_undefined()
343
+ );
344
+ }
345
+ oseo_roots_release(context, &frame);
346
+ return result;
347
+ }
348
+
349
+ /*
350
+ * String.prototype.match (22.1.3.13), matchAll (22.1.3.14), and search
351
+ * (22.1.3.16). Each observes an Object operand through IsRegExp where the
352
+ * specification says so and through GetMethod of its own well-known
353
+ * symbol; a nullish method reaches RegExpCreate, where matchAll alone
354
+ * supplies the `g` flag.
355
+ */
356
+ static OseoResult string_match_or_search(
357
+ OseoContext *context,
358
+ size_t code_id,
359
+ OseoValue receiver,
360
+ size_t argument_count,
361
+ const OseoValue *arguments
362
+ ) {
363
+ bool dispatched = false;
364
+ OseoResult result = string_protocol_method(
365
+ context,
366
+ code_id,
367
+ receiver,
368
+ argument_count,
369
+ arguments,
370
+ &dispatched
371
+ );
372
+ if (result.status != OSEO_STATUS_NORMAL || dispatched) return result;
373
+ return string_regexp_dispatch(
374
+ context,
375
+ code_id,
376
+ receiver,
377
+ match_argument(argument_count, arguments, 0u),
378
+ code_id == OSEO_STRING_MATCH_ALL_CODE_ID ? "g" : NULL
379
+ );
380
+ }
381
+
382
+ static OseoResult regexp_iterator_function(
383
+ OseoContext *context,
384
+ size_t code_id,
385
+ const char *name,
386
+ size_t length
387
+ ) {
388
+ size_t name_length = strlen(name);
389
+ uint16_t units[8];
390
+ if (name_length > sizeof(units) / sizeof(*units)) {
391
+ return failure(context, "OSEO2001", "Built-in name is too long.");
392
+ }
393
+ for (size_t index = 0u; index < name_length; index += 1u) {
394
+ units[index] = (uint16_t)(unsigned char)name[index];
395
+ }
396
+ OseoValue environment = oseo_undefined();
397
+ OseoRootFrame frame = {NULL, &environment, 1u};
398
+ oseo_roots_push(context, &frame);
399
+ OseoResult result = oseo_environment_create(context, 0u);
400
+ environment = result.value;
401
+ if (result.status == OSEO_STATUS_NORMAL) {
402
+ result = oseo_function_create(
403
+ context,
404
+ code_id,
405
+ environment,
406
+ units,
407
+ name_length,
408
+ length,
409
+ OSEO_FUNCTION_INTERNAL,
410
+ oseo_undefined(),
411
+ oseo_undefined(),
412
+ OSEO_FUNCTION_NAME_PREFIX_NONE
413
+ );
414
+ }
415
+ oseo_roots_pop(context, &frame);
416
+ return result;
417
+ }
418
+
419
+ static OseoResult regexp_iterator_property(
420
+ OseoContext *context,
421
+ OseoValue object,
422
+ OseoValue key,
423
+ OseoValue value,
424
+ OseoPropertyAttributes attributes
425
+ ) {
426
+ OseoValue slots[3] = {object, key, value};
427
+ OseoRootFrame frame = {NULL, slots, 3u};
428
+ oseo_roots_push(context, &frame);
429
+ OseoResult result = oseo_object_define(
430
+ context,
431
+ slots[0],
432
+ slots[1],
433
+ slots[2],
434
+ attributes
435
+ );
436
+ oseo_roots_pop(context, &frame);
437
+ return result;
438
+ }
439
+
440
+ OseoResult oseo_internal_regexp_string_iterator_prototype(
441
+ OseoContext *context
442
+ ) {
443
+ OseoValue *prototype_cache = &context->realm->intrinsics[
444
+ OSEO_INTRINSIC_REGEXP_STRING_ITERATOR_PROTOTYPE
445
+ ];
446
+ OseoValue *next_cache = &context->realm->intrinsics[
447
+ OSEO_INTRINSIC_REGEXP_STRING_ITERATOR_NEXT
448
+ ];
449
+ if (is_object(*prototype_cache) && is_function(*next_cache)) {
450
+ return normal(*prototype_cache);
451
+ }
452
+ size_t entry_allocations = context->allocations;
453
+ OseoRootFrame frame = {NULL, NULL, 0u};
454
+ OseoResult result = oseo_roots_allocate(context, &frame, 6u);
455
+ if (result.status != OSEO_STATUS_NORMAL) return result;
456
+ result = oseo_internal_intrinsic(
457
+ context,
458
+ OSEO_INTRINSIC_ITERATOR_PROTOTYPE
459
+ );
460
+ frame.slots[0] = result.value;
461
+ if (result.status == OSEO_STATUS_NORMAL) {
462
+ result = oseo_object_create(context, frame.slots[0]);
463
+ frame.slots[1] = result.value;
464
+ }
465
+ if (result.status == OSEO_STATUS_NORMAL) {
466
+ result = regexp_iterator_function(
467
+ context,
468
+ OSEO_REGEXP_STRING_ITERATOR_NEXT_CODE_ID,
469
+ "next",
470
+ 0u
471
+ );
472
+ frame.slots[2] = result.value;
473
+ }
474
+ if (result.status == OSEO_STATUS_NORMAL) {
475
+ result = oseo_internal_ascii_string(context, "next");
476
+ frame.slots[3] = result.value;
477
+ }
478
+ if (result.status == OSEO_STATUS_NORMAL) {
479
+ result = regexp_iterator_property(
480
+ context,
481
+ frame.slots[1],
482
+ frame.slots[3],
483
+ frame.slots[2],
484
+ (OseoPropertyAttributes){true, false, true, false}
485
+ );
486
+ }
487
+ if (result.status == OSEO_STATUS_NORMAL) {
488
+ result = oseo_internal_well_known_symbol(
489
+ context,
490
+ OSEO_WELL_KNOWN_TO_STRING_TAG
491
+ );
492
+ frame.slots[4] = result.value;
493
+ }
494
+ if (result.status == OSEO_STATUS_NORMAL) {
495
+ result = oseo_internal_ascii_string(
496
+ context,
497
+ "RegExp String Iterator"
498
+ );
499
+ frame.slots[5] = result.value;
500
+ }
501
+ if (result.status == OSEO_STATUS_NORMAL) {
502
+ result = regexp_iterator_property(
503
+ context,
504
+ frame.slots[1],
505
+ frame.slots[4],
506
+ frame.slots[5],
507
+ (OseoPropertyAttributes){true, false, false, false}
508
+ );
509
+ }
510
+ if (result.status == OSEO_STATUS_NORMAL) {
511
+ *prototype_cache = frame.slots[1];
512
+ *next_cache = frame.slots[2];
513
+ result = normal(frame.slots[1]);
514
+ if (context->observe_specialization) {
515
+ context->allocations = entry_allocations;
516
+ }
517
+ } else {
518
+ *prototype_cache = oseo_undefined();
519
+ *next_cache = oseo_undefined();
520
+ }
521
+ oseo_roots_release(context, &frame);
522
+ return result;
523
+ }
524
+
525
+ OseoResult oseo_internal_regexp_string_iterator_create(
526
+ OseoContext *context,
527
+ OseoValue regexp,
528
+ OseoValue subject,
529
+ bool global,
530
+ bool unicode
531
+ ) {
532
+ OseoValue slots[3] = {regexp, subject, oseo_undefined()};
533
+ OseoRootFrame frame = {NULL, slots, 3u};
534
+ oseo_roots_push(context, &frame);
535
+ OseoResult result = oseo_internal_regexp_string_iterator_prototype(
536
+ context
537
+ );
538
+ slots[2] = result.value;
539
+ if (result.status == OSEO_STATUS_NORMAL) {
540
+ result = oseo_object_create(context, slots[2]);
541
+ }
542
+ if (result.status == OSEO_STATUS_NORMAL) {
543
+ OseoOrdinaryObject *iterator = ordinary_object(result.value);
544
+ iterator->regexp_string_iterator = true;
545
+ iterator->regexp_iterator_regexp = slots[0];
546
+ iterator->regexp_iterator_subject = slots[1];
547
+ iterator->regexp_iterator_global = global;
548
+ iterator->regexp_iterator_unicode = unicode;
549
+ iterator->regexp_iterator_complete = false;
550
+ }
551
+ oseo_roots_pop(context, &frame);
552
+ return result;
553
+ }
554
+
555
+ /*
556
+ * %RegExpStringIteratorPrototype%.next (22.2.9.2.1). A non-global
557
+ * iterator finishes on its first match, and a global one that matched the
558
+ * empty string advances `lastIndex` on the iterating RegExp itself, which
559
+ * is where the cursor lives.
560
+ */
561
+ static OseoResult regexp_string_iterator_next(
562
+ OseoContext *context,
563
+ OseoValue receiver
564
+ ) {
565
+ if (!is_regexp_string_iterator(receiver)) {
566
+ return oseo_internal_throw_error(
567
+ context,
568
+ OSEO_ERROR_TYPE,
569
+ "RegExp String iterator next requires its iterator receiver."
570
+ );
571
+ }
572
+ OseoOrdinaryObject *state = ordinary_object(receiver);
573
+ if (state->regexp_iterator_complete) {
574
+ return oseo_internal_iterator_result(
575
+ context,
576
+ oseo_undefined(),
577
+ true
578
+ );
579
+ }
580
+ bool global = state->regexp_iterator_global;
581
+ bool unicode = state->regexp_iterator_unicode;
582
+ OseoValue slots[4] = {
583
+ receiver,
584
+ state->regexp_iterator_regexp,
585
+ state->regexp_iterator_subject,
586
+ oseo_undefined(),
587
+ };
588
+ OseoRootFrame frame = {NULL, slots, 4u};
589
+ oseo_roots_push(context, &frame);
590
+ OseoResult result = oseo_internal_regexp_exec(
591
+ context,
592
+ slots[1],
593
+ slots[2]
594
+ );
595
+ slots[3] = result.value;
596
+ bool finished = result.status == OSEO_STATUS_NORMAL &&
597
+ tag_of(slots[3]) == OSEO_TAG_NULL;
598
+ if (finished || (result.status == OSEO_STATUS_NORMAL && !global)) {
599
+ state = ordinary_object(slots[0]);
600
+ state->regexp_iterator_complete = true;
601
+ state->regexp_iterator_regexp = oseo_undefined();
602
+ state->regexp_iterator_subject = oseo_undefined();
603
+ }
604
+ if (result.status == OSEO_STATUS_NORMAL && !finished && global) {
605
+ result = oseo_internal_regexp_iteration_step(
606
+ context,
607
+ slots[1],
608
+ slots[2],
609
+ slots[3],
610
+ unicode
611
+ );
612
+ }
613
+ if (result.status == OSEO_STATUS_NORMAL) {
614
+ result = oseo_internal_iterator_result(
615
+ context,
616
+ finished ? oseo_undefined() : slots[3],
617
+ finished
618
+ );
619
+ }
620
+ oseo_roots_pop(context, &frame);
621
+ return result;
622
+ }
623
+
624
+ static uint32_t string_to_uint32(double number) {
625
+ if (!isfinite(number) || number == 0.0) return 0u;
626
+ double modulo = fmod(trunc(number), 4294967296.0);
627
+ if (modulo < 0.0) modulo += 4294967296.0;
628
+ return (uint32_t)modulo;
629
+ }
630
+
631
+ static OseoResult string_append_slice(
632
+ OseoContext *context,
633
+ OseoValue array,
634
+ OseoValue subject,
635
+ size_t start,
636
+ size_t end
637
+ ) {
638
+ OseoValue slots[3] = {array, subject, oseo_undefined()};
639
+ OseoRootFrame frame = {NULL, slots, 3u};
640
+ oseo_roots_push(context, &frame);
641
+ const OseoString *string = string_object(slots[1]);
642
+ OseoResult result = oseo_internal_allocate_string(
643
+ context,
644
+ string->units + start,
645
+ end - start
646
+ );
647
+ slots[2] = result.value;
648
+ if (result.status == OSEO_STATUS_NORMAL) {
649
+ result = oseo_array_append(context, slots[0], slots[2]);
650
+ }
651
+ oseo_roots_pop(context, &frame);
652
+ return result;
653
+ }
654
+
655
+ static OseoResult string_split(
656
+ OseoContext *context,
657
+ OseoValue receiver,
658
+ size_t argument_count,
659
+ const OseoValue *arguments
660
+ ) {
661
+ bool dispatched = false;
662
+ OseoResult result = string_protocol_method(
663
+ context,
664
+ OSEO_STRING_SPLIT_CODE_ID,
665
+ receiver,
666
+ argument_count,
667
+ arguments,
668
+ &dispatched
669
+ );
670
+ if (result.status != OSEO_STATUS_NORMAL || dispatched) return result;
671
+ OseoRootFrame frame = {NULL, NULL, 0u};
672
+ result = oseo_roots_allocate(context, &frame, 4u);
673
+ if (result.status != OSEO_STATUS_NORMAL) return result;
674
+ frame.slots[0] = match_argument(argument_count, arguments, 0u);
675
+ frame.slots[1] = match_argument(argument_count, arguments, 1u);
676
+ result = match_subject(context, receiver);
677
+ frame.slots[2] = result.value;
678
+ if (result.status == OSEO_STATUS_NORMAL) {
679
+ result = oseo_array_create(context, 0u);
680
+ frame.slots[3] = result.value;
681
+ }
682
+ uint32_t limit = UINT32_MAX;
683
+ bool separator_undefined =
684
+ tag_of(frame.slots[0]) == OSEO_TAG_UNDEFINED;
685
+ if (result.status == OSEO_STATUS_NORMAL &&
686
+ tag_of(frame.slots[1]) != OSEO_TAG_UNDEFINED) {
687
+ result = oseo_internal_to_number(context, frame.slots[1]);
688
+ if (result.status == OSEO_STATUS_NORMAL) {
689
+ limit = string_to_uint32(number_value(result.value));
690
+ }
691
+ }
692
+ if (result.status == OSEO_STATUS_NORMAL && !separator_undefined) {
693
+ result = oseo_internal_value_string(context, frame.slots[0]);
694
+ frame.slots[0] = result.value;
695
+ }
696
+ if (result.status == OSEO_STATUS_NORMAL && limit == 0u) {
697
+ result = normal(frame.slots[3]);
698
+ } else if (result.status == OSEO_STATUS_NORMAL &&
699
+ separator_undefined) {
700
+ result = oseo_array_append(
701
+ context,
702
+ frame.slots[3],
703
+ frame.slots[2]
704
+ );
705
+ }
706
+ if (result.status == OSEO_STATUS_NORMAL &&
707
+ !separator_undefined && limit != 0u) {
708
+ size_t subject_length = string_object(frame.slots[2])->length;
709
+ size_t separator_length = string_object(frame.slots[0])->length;
710
+ if (subject_length == 0u) {
711
+ if (separator_length != 0u) {
712
+ result = string_append_slice(
713
+ context,
714
+ frame.slots[3],
715
+ frame.slots[2],
716
+ 0u,
717
+ 0u
718
+ );
719
+ }
720
+ } else if (separator_length == 0u) {
721
+ for (size_t index = 0u;
722
+ result.status == OSEO_STATUS_NORMAL &&
723
+ index < subject_length && index < (size_t)limit;
724
+ index += 1u) {
725
+ result = string_append_slice(
726
+ context,
727
+ frame.slots[3],
728
+ frame.slots[2],
729
+ index,
730
+ index + 1u
731
+ );
732
+ }
733
+ } else {
734
+ size_t start = 0u;
735
+ while (result.status == OSEO_STATUS_NORMAL &&
736
+ ordinary_object(frame.slots[3])->array_length < limit) {
737
+ size_t position = 0u;
738
+ if (!string_find(
739
+ frame.slots[2],
740
+ frame.slots[0],
741
+ start,
742
+ &position
743
+ )) break;
744
+ result = string_append_slice(
745
+ context,
746
+ frame.slots[3],
747
+ frame.slots[2],
748
+ start,
749
+ position
750
+ );
751
+ start = position + separator_length;
752
+ }
753
+ if (result.status == OSEO_STATUS_NORMAL &&
754
+ ordinary_object(frame.slots[3])->array_length < limit) {
755
+ result = string_append_slice(
756
+ context,
757
+ frame.slots[3],
758
+ frame.slots[2],
759
+ start,
760
+ subject_length
761
+ );
762
+ }
763
+ }
764
+ }
765
+ if (result.status == OSEO_STATUS_NORMAL) result.value = frame.slots[3];
766
+ oseo_roots_release(context, &frame);
767
+ return result;
768
+ }
769
+
770
+
771
+ /* The decimal value of one ASCII digit, or `UINT16_MAX` for anything else. */
772
+ static uint16_t substitution_digit(uint16_t unit) {
773
+ return unit >= UINT16_C(0x30) && unit <= UINT16_C(0x39)
774
+ ? (uint16_t)(unit - UINT16_C(0x30))
775
+ : UINT16_MAX;
776
+ }
777
+
778
+ /*
779
+ * The `$n`, `$nn`, and `$<name>` reference forms of GetSubstitution.
780
+ * `reference` receives how many code units the reference spans, and
781
+ * `capture` receives the substituted text or `oseo_uninitialized()` when
782
+ * the reference has no referent and copies its own text instead.
783
+ */
784
+ static OseoResult substitution_reference(
785
+ OseoContext *context,
786
+ OseoValue replacement,
787
+ size_t index,
788
+ OseoValue captures,
789
+ OseoValue named_captures,
790
+ size_t *reference,
791
+ OseoValue *capture
792
+ ) {
793
+ const OseoString *pattern = string_object(replacement);
794
+ uint16_t next = pattern->units[index + 1u];
795
+ *capture = oseo_uninitialized();
796
+ if (next == UINT16_C(0x3c)) {
797
+ *reference = 2u;
798
+ if (tag_of(named_captures) == OSEO_TAG_UNDEFINED) {
799
+ return normal(oseo_undefined());
800
+ }
801
+ size_t close = index + 2u;
802
+ while (close < pattern->length &&
803
+ pattern->units[close] != UINT16_C(0x3e)) {
804
+ close += 1u;
805
+ }
806
+ if (close == pattern->length) return normal(oseo_undefined());
807
+ *reference = close + 1u - index;
808
+ OseoValue slots[3] = {replacement, named_captures, oseo_undefined()};
809
+ OseoRootFrame frame = {NULL, slots, 3u};
810
+ oseo_roots_push(context, &frame);
811
+ OseoResult result = oseo_internal_allocate_string(
812
+ context,
813
+ string_object(slots[0])->units + index + 2u,
814
+ close - index - 2u
815
+ );
816
+ slots[2] = result.value;
817
+ if (result.status == OSEO_STATUS_NORMAL) {
818
+ result = oseo_object_get(context, slots[1], slots[2]);
819
+ slots[2] = result.value;
820
+ }
821
+ if (result.status == OSEO_STATUS_NORMAL &&
822
+ tag_of(slots[2]) == OSEO_TAG_UNDEFINED) {
823
+ result = oseo_internal_allocate_string(context, NULL, 0u);
824
+ slots[2] = result.value;
825
+ } else if (result.status == OSEO_STATUS_NORMAL) {
826
+ result = oseo_internal_value_string(context, slots[2]);
827
+ slots[2] = result.value;
828
+ }
829
+ if (result.status == OSEO_STATUS_NORMAL) *capture = slots[2];
830
+ oseo_roots_pop(context, &frame);
831
+ return result;
832
+ }
833
+ uint16_t first = substitution_digit(next);
834
+ if (first == UINT16_MAX) {
835
+ *reference = 1u;
836
+ return normal(oseo_undefined());
837
+ }
838
+ uint16_t second = index + 2u < pattern->length
839
+ ? substitution_digit(pattern->units[index + 2u])
840
+ : UINT16_MAX;
841
+ size_t capture_count = tag_of(captures) == OSEO_TAG_UNDEFINED
842
+ ? 0u
843
+ : ordinary_object(captures)->array_length;
844
+ size_t digits = second == UINT16_MAX ? 1u : 2u;
845
+ size_t number = digits == 1u
846
+ ? (size_t)first
847
+ : (size_t)first * 10u + (size_t)second;
848
+ /*
849
+ * A two-digit reference past the capture count is one digit followed
850
+ * by a literal digit, so the second digit is left for the scan that
851
+ * resumes after this reference.
852
+ */
853
+ if (number > capture_count && digits == 2u) {
854
+ digits = 1u;
855
+ number = (size_t)first;
856
+ }
857
+ *reference = digits + 1u;
858
+ if (number < 1u || number > capture_count) {
859
+ return normal(oseo_undefined());
860
+ }
861
+ OseoValue slots[2] = {captures, oseo_undefined()};
862
+ OseoRootFrame frame = {NULL, slots, 2u};
863
+ oseo_roots_push(context, &frame);
864
+ OseoResult result = oseo_internal_value_string(
865
+ context,
866
+ oseo_number((double)(number - 1u))
867
+ );
868
+ slots[1] = result.value;
869
+ if (result.status == OSEO_STATUS_NORMAL) {
870
+ result = oseo_object_get(context, slots[0], slots[1]);
871
+ slots[1] = result.value;
872
+ }
873
+ if (result.status == OSEO_STATUS_NORMAL &&
874
+ tag_of(slots[1]) == OSEO_TAG_UNDEFINED) {
875
+ result = oseo_internal_allocate_string(context, NULL, 0u);
876
+ slots[1] = result.value;
877
+ }
878
+ if (result.status == OSEO_STATUS_NORMAL) *capture = slots[1];
879
+ oseo_roots_pop(context, &frame);
880
+ return result;
881
+ }
882
+
883
+ OseoResult oseo_internal_get_substitution(
884
+ OseoContext *context,
885
+ OseoStringBuilder *builder,
886
+ OseoValue matched,
887
+ OseoValue subject,
888
+ size_t position,
889
+ OseoValue captures,
890
+ OseoValue named_captures,
891
+ OseoValue replacement
892
+ ) {
893
+ OseoValue slots[6] = {
894
+ matched,
895
+ subject,
896
+ captures,
897
+ named_captures,
898
+ replacement,
899
+ oseo_undefined(),
900
+ };
901
+ OseoRootFrame frame = {NULL, slots, 6u};
902
+ oseo_roots_push(context, &frame);
903
+ OseoResult result = normal(oseo_undefined());
904
+ size_t index = 0u;
905
+ while (result.status == OSEO_STATUS_NORMAL) {
906
+ const OseoString *pattern = string_object(slots[4]);
907
+ if (index >= pattern->length) break;
908
+ uint16_t unit = pattern->units[index];
909
+ if (unit != UINT16_C(0x24) || index + 1u >= pattern->length) {
910
+ result = oseo_internal_string_builder_append(
911
+ context,
912
+ builder,
913
+ &unit,
914
+ 1u
915
+ );
916
+ index += 1u;
917
+ continue;
918
+ }
919
+ uint16_t next = pattern->units[index + 1u];
920
+ if (next == UINT16_C(0x24)) {
921
+ uint16_t dollar = UINT16_C(0x24);
922
+ result = oseo_internal_string_builder_append(
923
+ context,
924
+ builder,
925
+ &dollar,
926
+ 1u
927
+ );
928
+ index += 2u;
929
+ continue;
930
+ }
931
+ if (next == UINT16_C(0x26)) {
932
+ const OseoString *match = string_object(slots[0]);
933
+ result = oseo_internal_string_builder_append(
934
+ context,
935
+ builder,
936
+ match->units,
937
+ match->length
938
+ );
939
+ index += 2u;
940
+ continue;
941
+ }
942
+ if (next == UINT16_C(0x60)) {
943
+ const OseoString *string = string_object(slots[1]);
944
+ result = oseo_internal_string_builder_append(
945
+ context,
946
+ builder,
947
+ string->units,
948
+ position
949
+ );
950
+ index += 2u;
951
+ continue;
952
+ }
953
+ if (next == UINT16_C(0x27)) {
954
+ const OseoString *string = string_object(slots[1]);
955
+ size_t tail = position + string_object(slots[0])->length;
956
+ if (tail > string->length) tail = string->length;
957
+ result = oseo_internal_string_builder_append(
958
+ context,
959
+ builder,
960
+ string->units + tail,
961
+ string->length - tail
962
+ );
963
+ index += 2u;
964
+ continue;
965
+ }
966
+ size_t reference = 1u;
967
+ result = substitution_reference(
968
+ context,
969
+ slots[4],
970
+ index,
971
+ slots[2],
972
+ slots[3],
973
+ &reference,
974
+ &slots[5]
975
+ );
976
+ if (result.status != OSEO_STATUS_NORMAL) break;
977
+ if (tag_of(slots[5]) == OSEO_TAG_UNINITIALIZED) {
978
+ /* The reference has no referent, so it copies its own text. */
979
+ result = oseo_internal_string_builder_append(
980
+ context,
981
+ builder,
982
+ string_object(slots[4])->units + index,
983
+ reference
984
+ );
985
+ } else {
986
+ const OseoString *text = string_object(slots[5]);
987
+ result = oseo_internal_string_builder_append(
988
+ context,
989
+ builder,
990
+ text->units,
991
+ text->length
992
+ );
993
+ slots[5] = oseo_undefined();
994
+ }
995
+ index += reference;
996
+ }
997
+ oseo_roots_pop(context, &frame);
998
+ return result;
999
+ }
1000
+
1001
+ /*
1002
+ * String.prototype.replace (22.1.3.19) and replaceAll (22.1.3.20). The two
1003
+ * share one body: `replace` stops after the first match, while `replaceAll`
1004
+ * continues from each match end and advances by one code unit for an empty
1005
+ * search string. Neither converts a callable replacer, and a String
1006
+ * replacer is converted before the subject is searched.
1007
+ */
1008
+ static OseoResult string_replace(
1009
+ OseoContext *context,
1010
+ size_t code_id,
1011
+ OseoValue receiver,
1012
+ size_t argument_count,
1013
+ const OseoValue *arguments
1014
+ ) {
1015
+ bool all = code_id == OSEO_STRING_REPLACE_ALL_CODE_ID;
1016
+ bool dispatched = false;
1017
+ OseoResult result = string_protocol_method(
1018
+ context,
1019
+ code_id,
1020
+ receiver,
1021
+ argument_count,
1022
+ arguments,
1023
+ &dispatched
1024
+ );
1025
+ if (result.status != OSEO_STATUS_NORMAL || dispatched) return result;
1026
+ OseoRootFrame frame = {NULL, NULL, 0u};
1027
+ result = oseo_roots_allocate(context, &frame, 4u);
1028
+ if (result.status != OSEO_STATUS_NORMAL) return result;
1029
+ /* 0: subject, 1: search string, 2: replacer, 3: replacement text */
1030
+ frame.slots[2] = match_argument(argument_count, arguments, 1u);
1031
+ result = match_subject(context, receiver);
1032
+ frame.slots[0] = result.value;
1033
+ if (result.status == OSEO_STATUS_NORMAL) {
1034
+ result = oseo_internal_value_string(
1035
+ context,
1036
+ match_argument(argument_count, arguments, 0u)
1037
+ );
1038
+ frame.slots[1] = result.value;
1039
+ }
1040
+ bool functional = is_callable(frame.slots[2]);
1041
+ if (result.status == OSEO_STATUS_NORMAL && !functional) {
1042
+ result = oseo_internal_value_string(context, frame.slots[2]);
1043
+ frame.slots[2] = result.value;
1044
+ }
1045
+ size_t position = 0u;
1046
+ bool found = result.status == OSEO_STATUS_NORMAL &&
1047
+ string_find(frame.slots[0], frame.slots[1], 0u, &position);
1048
+ if (result.status != OSEO_STATUS_NORMAL || !found) {
1049
+ if (result.status == OSEO_STATUS_NORMAL) {
1050
+ result = normal(frame.slots[0]);
1051
+ }
1052
+ oseo_roots_release(context, &frame);
1053
+ return result;
1054
+ }
1055
+ size_t search_length = string_object(frame.slots[1])->length;
1056
+ size_t advance = search_length == 0u ? 1u : search_length;
1057
+ size_t consumed = 0u;
1058
+ OseoStringBuilder builder = {NULL, 0u, 0u};
1059
+ while (result.status == OSEO_STATUS_NORMAL && found) {
1060
+ /*
1061
+ * The replacer runs before the preceding subject slice is staged.
1062
+ * The specification computes the replacement and only then builds
1063
+ * the concatenation, so a staged slice that would exceed the
1064
+ * runtime's string ceiling must not suppress this match's call.
1065
+ */
1066
+ if (functional) {
1067
+ OseoValue call_arguments[3] = {
1068
+ frame.slots[1],
1069
+ oseo_number((double)position),
1070
+ frame.slots[0],
1071
+ };
1072
+ result = oseo_call_function(
1073
+ context,
1074
+ frame.slots[2],
1075
+ oseo_undefined(),
1076
+ 3u,
1077
+ call_arguments,
1078
+ oseo_undefined()
1079
+ );
1080
+ frame.slots[3] = result.value;
1081
+ if (result.status == OSEO_STATUS_NORMAL) {
1082
+ result = oseo_internal_value_string(context, frame.slots[3]);
1083
+ frame.slots[3] = result.value;
1084
+ }
1085
+ }
1086
+ if (result.status == OSEO_STATUS_NORMAL) {
1087
+ const OseoString *subject = string_object(frame.slots[0]);
1088
+ result = oseo_internal_string_builder_append(
1089
+ context,
1090
+ &builder,
1091
+ subject->units + consumed,
1092
+ position - consumed
1093
+ );
1094
+ }
1095
+ if (result.status == OSEO_STATUS_NORMAL && functional) {
1096
+ const OseoString *text = string_object(frame.slots[3]);
1097
+ result = oseo_internal_string_builder_append(
1098
+ context,
1099
+ &builder,
1100
+ text->units,
1101
+ text->length
1102
+ );
1103
+ } else if (result.status == OSEO_STATUS_NORMAL) {
1104
+ result = oseo_internal_get_substitution(
1105
+ context,
1106
+ &builder,
1107
+ frame.slots[1],
1108
+ frame.slots[0],
1109
+ position,
1110
+ oseo_undefined(),
1111
+ oseo_undefined(),
1112
+ frame.slots[2]
1113
+ );
1114
+ }
1115
+ if (result.status != OSEO_STATUS_NORMAL) break;
1116
+ consumed = position + search_length;
1117
+ found = all && string_find(
1118
+ frame.slots[0],
1119
+ frame.slots[1],
1120
+ position + advance,
1121
+ &position
1122
+ );
1123
+ }
1124
+ if (result.status == OSEO_STATUS_NORMAL) {
1125
+ const OseoString *subject = string_object(frame.slots[0]);
1126
+ result = oseo_internal_string_builder_append(
1127
+ context,
1128
+ &builder,
1129
+ subject->units + consumed,
1130
+ subject->length - consumed
1131
+ );
1132
+ }
1133
+ if (result.status == OSEO_STATUS_NORMAL) {
1134
+ result = oseo_internal_allocate_string(
1135
+ context,
1136
+ builder.units,
1137
+ builder.length
1138
+ );
1139
+ }
1140
+ oseo_internal_string_builder_release(&builder);
1141
+ oseo_roots_release(context, &frame);
1142
+ return result;
1143
+ }
1144
+
1145
+ OseoResult oseo_internal_string_protocol_dispatch(
1146
+ OseoContext *context,
1147
+ size_t code_id,
1148
+ OseoValue receiver,
1149
+ size_t argument_count,
1150
+ const OseoValue *arguments
1151
+ ) {
1152
+ if (code_id == OSEO_REGEXP_STRING_ITERATOR_NEXT_CODE_ID) {
1153
+ return regexp_string_iterator_next(context, receiver);
1154
+ }
1155
+ if (code_id == OSEO_STRING_MATCH_CODE_ID ||
1156
+ code_id == OSEO_STRING_MATCH_ALL_CODE_ID ||
1157
+ code_id == OSEO_STRING_SEARCH_CODE_ID) {
1158
+ return string_match_or_search(
1159
+ context,
1160
+ code_id,
1161
+ receiver,
1162
+ argument_count,
1163
+ arguments
1164
+ );
1165
+ }
1166
+ if (code_id == OSEO_STRING_SPLIT_CODE_ID) {
1167
+ return string_split(
1168
+ context,
1169
+ receiver,
1170
+ argument_count,
1171
+ arguments
1172
+ );
1173
+ }
1174
+ if (code_id == OSEO_STRING_REPLACE_CODE_ID ||
1175
+ code_id == OSEO_STRING_REPLACE_ALL_CODE_ID) {
1176
+ return string_replace(
1177
+ context,
1178
+ code_id,
1179
+ receiver,
1180
+ argument_count,
1181
+ arguments
1182
+ );
1183
+ }
1184
+ return oseo_unknown_function(context, code_id);
1185
+ }