@geastack/compiler 1.0.32 → 1.0.34
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/README.md +1 -1
- package/dist/cli-coverage.js +2 -4
- package/dist/cli-emit.js +1 -1
- package/dist/cli-module-graph.js +1 -1
- package/dist/cli.js +2 -1
- package/dist/compiler.js +35 -28
- package/dist/conversion/array-view.js +9 -0
- package/dist/conversion/build.js +15 -8
- package/dist/conversion/dictionary-view.js +2 -2
- package/dist/conversion/nodes.d.ts +7 -0
- package/dist/conversion/nodes.js +58 -11
- package/dist/identity/ids.d.ts +4 -0
- package/dist/identity/ids.js +4 -0
- package/dist/ir/build.d.ts +4 -3
- package/dist/ir/build.js +14 -5
- package/dist/ir/call-dispatch.js +67 -7
- package/dist/ir/call-entry.js +1 -1
- package/dist/ir/callable-class-flow.d.ts +4 -0
- package/dist/ir/callable-class-flow.js +123 -1
- package/dist/ir/certify/parallel-region.js +698 -20
- package/dist/ir/certify.d.ts +3 -0
- package/dist/ir/certify.js +44 -9
- package/dist/ir/class-allocation-domain.js +2 -2
- package/dist/ir/class-construction-status.d.ts +10 -0
- package/dist/ir/class-construction-status.js +36 -0
- package/dist/ir/convert-carriers.d.ts +10 -1
- package/dist/ir/convert-carriers.js +18 -1
- package/dist/ir/dynamic-constructor-conversions.js +4 -2
- package/dist/ir/finite-iterator-close.d.ts +14 -0
- package/dist/ir/finite-iterator-close.js +50 -0
- package/dist/ir/host-template-conversions.js +9 -0
- package/dist/ir/lower-allocation.js +1 -1
- package/dist/ir/lower-flow.js +24 -3
- package/dist/ir/lower-operands.js +88 -7
- package/dist/ir/lower-protocol.js +1 -1
- package/dist/ir/lower.js +22 -6
- package/dist/ir/model.d.ts +41 -1
- package/dist/ir/native-accessor-definition.d.ts +3 -2
- package/dist/ir/native-accessor-definition.js +29 -10
- package/dist/ir/native-array-transport.js +2 -2
- package/dist/ir/native-field-view-domains.d.ts +23 -0
- package/dist/ir/native-field-view-domains.js +115 -9
- package/dist/ir/native-field-view-facts.d.ts +46 -2
- package/dist/ir/native-field-view-facts.js +159 -4
- package/dist/ir/native-iterable.d.ts +17 -0
- package/dist/ir/native-iterable.js +72 -0
- package/dist/ir/native-key-query.js +1 -1
- package/dist/ir/operation-conversions.js +15 -3
- package/dist/ir/program-conversions.js +2 -2
- package/dist/ir/publish-native-field-view-facts.js +9 -4
- package/dist/ir/pure-conversion-reuse.d.ts +58 -0
- package/dist/ir/pure-conversion-reuse.js +263 -0
- package/dist/ir/queries.js +1 -0
- package/dist/ir/reflection-demand.js +70 -18
- package/dist/ir/shake.js +2 -2
- package/dist/ir/unobserved-callable-inputs.d.ts +37 -0
- package/dist/ir/unobserved-callable-inputs.js +111 -0
- package/dist/native-signatures.d.ts +1 -1
- package/dist/native-signatures.js +27 -2
- package/dist/plugins/gea/component-classes.d.ts +2 -1
- package/dist/plugins/gea/component-classes.js +3 -3
- package/dist/plugins/gea/contract.d.ts +26 -3
- package/dist/plugins/gea/contract.js +42 -43
- package/dist/plugins/gea/host.d.ts +9 -0
- package/dist/plugins/gea/host.js +25 -4
- package/dist/plugins/gea/plugin.js +12 -6
- package/dist/plugins/gea/producer.d.ts +2 -2
- package/dist/plugins/gea/producer.js +2 -2
- package/dist/plugins/load.js +18 -1
- package/dist/plugins/model.d.ts +5 -0
- package/dist/plugins/native-iterable-providers.d.ts +18 -0
- package/dist/plugins/native-iterable-providers.js +51 -0
- package/dist/project-preparation.d.ts +8 -0
- package/dist/project-preparation.js +49 -7
- package/dist/projection/bindings.d.ts +13 -0
- package/dist/projection/bindings.js +20 -1
- package/dist/projection/classes.d.ts +4 -2
- package/dist/projection/classes.js +12 -5
- package/dist/representation/collections.js +2 -0
- package/dist/representation/derive.js +1 -0
- package/dist/representation/model.d.ts +2 -0
- package/dist/representation/model.js +1 -0
- package/dist/representation/policies.d.ts +2 -0
- package/dist/representation/primitive-domain.d.ts +1 -1
- package/dist/representation/primitive-domain.js +1 -1
- package/dist/representation/unassigned-binding-cells.d.ts +4 -3
- package/dist/representation/unassigned-binding-cells.js +19 -2
- package/dist/representation/union.js +6 -6
- package/dist/semantics/frontend.d.ts +2 -0
- package/dist/semantics/frontend.js +34 -5
- package/dist/semantics/host-methods.js +4 -1
- package/dist/semantics/jsx-runtime-provider.d.ts +5 -0
- package/dist/semantics/jsx-runtime-provider.js +16 -0
- package/dist/semantics/model/native-iterable.d.ts +14 -0
- package/dist/semantics/model/native-iterable.js +7 -0
- package/dist/semantics/model/operands.d.ts +30 -0
- package/dist/semantics/model/operations.d.ts +15 -0
- package/dist/semantics/model/primitive-domain.d.ts +15 -0
- package/dist/semantics/model/primitive-domain.js +27 -4
- package/dist/semantics/module-resolution.js +13 -2
- package/dist/semantics/normalize/any-cast-member-call.d.ts +1 -1
- package/dist/semantics/normalize/callback-parameter-contracts.d.ts +32 -4
- package/dist/semantics/normalize/callback-parameter-contracts.js +66 -6
- package/dist/semantics/normalize/census.d.ts +3 -0
- package/dist/semantics/normalize/census.js +17 -12
- package/dist/semantics/normalize/deferred-intrinsic-protocols.d.ts +4 -1
- package/dist/semantics/normalize/deferred-intrinsic-protocols.js +29 -9
- package/dist/semantics/normalize/flow/callable-reach.js +94 -3
- package/dist/semantics/normalize/flow/component-solver.js +144 -55
- package/dist/semantics/normalize/flow/member-call-forwarding.d.ts +9 -0
- package/dist/semantics/normalize/flow/member-call-forwarding.js +30 -4
- package/dist/semantics/normalize/flow/proof-hypotheses.d.ts +2 -0
- package/dist/semantics/normalize/flow/proof-hypotheses.js +27 -0
- package/dist/semantics/normalize/flow/source-callable-own-data.js +87 -14
- package/dist/semantics/normalize/flow/source-commonjs-exports.d.ts +2 -0
- package/dist/semantics/normalize/flow/source-commonjs-exports.js +2 -0
- package/dist/semantics/normalize/flow/source-native-iterable-integrity.d.ts +17 -0
- package/dist/semantics/normalize/flow/source-native-iterable-integrity.js +125 -0
- package/dist/semantics/normalize/flow/source-native-origin.d.ts +6 -0
- package/dist/semantics/normalize/flow/source-native-origin.js +38 -0
- package/dist/semantics/normalize/flow/source-proxy-operation.d.ts +37 -0
- package/dist/semantics/normalize/flow/source-proxy-operation.js +201 -0
- package/dist/semantics/normalize/flow/source-raw-constructor-entry.d.ts +20 -0
- package/dist/semantics/normalize/flow/source-raw-constructor-entry.js +73 -0
- package/dist/semantics/normalize/flow/source-value-session.d.ts +50 -1
- package/dist/semantics/normalize/flow/source-value-session.js +596 -57
- package/dist/semantics/normalize/flow/value-flow.d.ts +17 -0
- package/dist/semantics/normalize/flow/value-flow.js +84 -0
- package/dist/semantics/normalize/fresh-dictionary-storage.js +2 -2
- package/dist/semantics/normalize/fresh-table-last-use.d.ts +52 -0
- package/dist/semantics/normalize/fresh-table-last-use.js +129 -0
- package/dist/semantics/normalize/gating.js +5 -1
- package/dist/semantics/normalize/global-host-mutations.js +190 -13
- package/dist/semantics/normalize/identities.js +20 -1
- package/dist/semantics/normalize/local-bindings.js +2 -2
- package/dist/semantics/normalize/parameter-bindings.js +10 -1
- package/dist/semantics/normalize/producer-context.d.ts +5 -0
- package/dist/semantics/normalize/producers/binding-kind.js +2 -0
- package/dist/semantics/normalize/producers/cited-value-type.d.ts +2 -2
- package/dist/semantics/normalize/producers/cited-value-type.js +2 -2
- package/dist/semantics/normalize/producers/class-lifecycle.js +39 -9
- package/dist/semantics/normalize/producers/computations.js +36 -5
- package/dist/semantics/normalize/producers/conditional-guard.d.ts +6 -0
- package/dist/semantics/normalize/producers/conditional-guard.js +5 -0
- package/dist/semantics/normalize/producers/control.js +7 -1
- package/dist/semantics/normalize/producers/destructuring.js +8 -9
- package/dist/semantics/normalize/producers/invocations.js +55 -2
- package/dist/semantics/normalize/producers/properties.d.ts +13 -0
- package/dist/semantics/normalize/producers/properties.js +21 -3
- package/dist/semantics/normalize/producers/references.js +8 -4
- package/dist/semantics/normalize/reachability.d.ts +15 -3
- package/dist/semantics/normalize/reachability.js +128 -20
- package/dist/semantics/normalize/return-bindings.js +3 -3
- package/dist/semantics/normalize/source-native-iterable.d.ts +19 -0
- package/dist/semantics/normalize/source-native-iterable.js +74 -0
- package/dist/semantics/normalize/structural-any-binding-consumer.d.ts +1 -1
- package/dist/semantics/normalize/structural-declarations.js +1 -1
- package/dist/semantics/normalize/structural-indexed-access.js +9 -0
- package/dist/semantics/normalize/structural.js +11 -0
- package/dist/semantics/normalize/unshared-array-result.d.ts +42 -0
- package/dist/semantics/normalize/unshared-array-result.js +269 -0
- package/dist/semantics/package-sources.js +3 -2
- package/dist/semantics/program.d.ts +8 -0
- package/dist/semantics/program.js +55 -0
- package/dist/semantics/source-transform-exports.d.ts +8 -0
- package/dist/semantics/source-transform-exports.js +145 -0
- package/dist/semantics/source-transform-protocol.d.ts +22 -0
- package/dist/semantics/this-constructor-source-transform.js +19 -1
- package/dist/targets/cpp/class-layout.d.ts +2 -0
- package/dist/targets/cpp/class-layout.js +35 -1
- package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +11 -1
- package/dist/targets/cpp/class-properties/emit-class-properties.js +33 -4
- package/dist/targets/cpp/conversions.js +6 -3
- package/dist/targets/cpp/emit-callable.js +73 -7
- package/dist/targets/cpp/emit-context.d.ts +23 -9
- package/dist/targets/cpp/emit-context.js +19 -8
- package/dist/targets/cpp/emit-equality.js +41 -1
- package/dist/targets/cpp/emit-exceptions.js +29 -11
- package/dist/targets/cpp/emit-iterator-object-view.js +2 -2
- package/dist/targets/cpp/emit-iterator.js +33 -9
- package/dist/targets/cpp/emit-live-field-view.js +6 -1
- package/dist/targets/cpp/emit-narrowing.d.ts +11 -3
- package/dist/targets/cpp/emit-narrowing.js +58 -18
- package/dist/targets/cpp/emit-native-field-view.d.ts +3 -1
- package/dist/targets/cpp/emit-native-field-view.js +84 -8
- package/dist/targets/cpp/emit-properties.d.ts +1 -0
- package/dist/targets/cpp/emit-properties.js +26 -7
- package/dist/targets/cpp/emit-protocol-iterator.js +5 -2
- package/dist/targets/cpp/emit-record-view.js +14 -2
- package/dist/targets/cpp/emit-tostring.js +23 -1
- package/dist/targets/cpp/emit-union-properties.js +1 -1
- package/dist/targets/cpp/emit.d.ts +1 -1
- package/dist/targets/cpp/emit.js +132 -21
- package/dist/targets/cpp/host/emit-host-invoke.js +2 -2
- package/dist/targets/cpp/host/emit-host-object.js +28 -2
- package/dist/targets/cpp/host/emit-host-properties.js +9 -1
- package/dist/targets/cpp/host/emit-host-value.d.ts +1 -1
- package/dist/targets/cpp/host/emit-host-value.js +8 -6
- package/dist/targets/cpp/host/host-members.js +2 -1
- package/dist/targets/cpp/prototype/emit-prototype-array.js +69 -5
- package/dist/targets/cpp/prototype/emit-prototype-invoke.js +9 -9
- package/dist/targets/cpp/prototype/emit-prototype-iterator.js +2 -2
- package/dist/targets/cpp/prototype/emit-prototype-promise.js +7 -7
- package/dist/targets/cpp/records.d.ts +1 -0
- package/dist/targets/cpp/records.js +16 -7
- package/dist/targets/cpp/translation-unit.js +30 -16
- package/package.json +8 -7
- package/src/targets/cpp/runtime/gea_dynamic_proxy.h +42 -3
- package/src/targets/cpp/runtime/gea_eval.h +3 -0
- package/src/targets/cpp/runtime/gea_runtime.h +2407 -684
|
@@ -303,10 +303,38 @@ const sortText = (ctx, receiverText, element, args) => {
|
|
|
303
303
|
// name, so the sort can inline it.
|
|
304
304
|
const comparator = args[0];
|
|
305
305
|
const direct = comparator === undefined ? undefined : ctx.directCallableValues.get(comparator.value);
|
|
306
|
-
if (
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
306
|
+
if (comparator?.representation.kind === 'function-value-dispatch' && comparator.representation.abi.receiver === null) {
|
|
307
|
+
// SortCompare (23.1.3.30.2) calls the comparator with two elements, which
|
|
308
|
+
// the runtime hands over as the element's own C++ type. Only a comparator
|
|
309
|
+
// whose two parameters ARE that carrier takes them as they are; one
|
|
310
|
+
// declared otherwise (`lights.sort( byShadow )` with `any` parameters over
|
|
311
|
+
// a class-instance array) needs each element converted at this boundary,
|
|
312
|
+
// exactly as `elementAdaptedCallbackText` converts for the callback family
|
|
313
|
+
// -- C++ performs no such conversion, and the inlining `DirectCallable`
|
|
314
|
+
// finds no invocable arity at all.
|
|
315
|
+
const abi = comparator.representation.abi;
|
|
316
|
+
const compared = abi.parameters.slice(0, 2);
|
|
317
|
+
const exact = compared.every((parameter) => representationKey(parameter.value) === representationKey(element));
|
|
318
|
+
if (exact) {
|
|
319
|
+
if (direct !== undefined)
|
|
320
|
+
return `gea::runtime::array::sort(${receiverText}, gea::DirectCallable<&${cppThunkName(direct)}>{})`;
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
const refuse = (detail) => {
|
|
324
|
+
throw createCppEmitBlockedError(`runtime-helper:callback:sort:${elementKey(element)}`, `"Array.prototype.sort" (ECMA-262 23.1.3.30) hands its comparator two elements "${elementKey(element)}"; ${detail}`);
|
|
325
|
+
};
|
|
326
|
+
if (abi.restFrom !== null && abi.restFrom < 2)
|
|
327
|
+
refuse('a comparator gathering them into a rest parameter has no runtime call shape');
|
|
328
|
+
const actuals = compared.map((parameter, position) => {
|
|
329
|
+
const converted = alignedValueText(ctx, 'prototype/emit-prototype-array.ts:sortText', element, parameter.value, `__gea_element_${position}`);
|
|
330
|
+
return (converted ??
|
|
331
|
+
refuse(`its parameter ${position} carries "${representationKey(parameter.value)}", and no installed conversion reconciles them`));
|
|
332
|
+
});
|
|
333
|
+
const formals = [0, 1].map((position) => `const ${cppTypeOf(element)}& __gea_element_${position}`);
|
|
334
|
+
const fn = direct !== undefined ? `gea::DirectCallable<&${cppThunkName(direct)}>{}` : operandText(ctx, comparator);
|
|
335
|
+
return `gea::runtime::array::sort(${receiverText}, [__gea_fn = ${fn}](${formals.join(', ')}) { return __gea_fn(${actuals.join(', ')}); })`;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
310
338
|
if (args.length === 1)
|
|
311
339
|
return call(ctx, 'sort', receiverText, args);
|
|
312
340
|
if (element.kind !== 'string' && element.kind !== 'scalar') {
|
|
@@ -579,13 +607,15 @@ const rangedMethodText = (member, clause, arities, elementOrdinal) => (ctx, rece
|
|
|
579
607
|
* against every element, which is a comparison between two VALUES and never a
|
|
580
608
|
* store: the search value is not written into the array, so it need not carry
|
|
581
609
|
* the element's own carrier, only one the comparison can be decided across.
|
|
582
|
-
*
|
|
610
|
+
* These cross-carrier pairs are rendered beyond the exact one `rangedMethodText` gates:
|
|
583
611
|
*
|
|
584
612
|
* - a DYNAMIC search value over a primitive element. 7.2.12 step 1 compares
|
|
585
613
|
* Types first, so the value can only match when its tag is the element's;
|
|
586
614
|
* the tag test decides that, and only then is it unboxed and compared
|
|
587
615
|
* natively. `Object.values(Enum).includes(value as any)` is the
|
|
588
616
|
* shape.
|
|
617
|
+
* - an optional primitive search over its payload element: absence compares
|
|
618
|
+
* equal only to a hole, while present payloads use SameValueZero.
|
|
589
619
|
* - a search value that is the PRESENT arm of an optional element
|
|
590
620
|
* (`(string | undefined)[]`'s `.includes(name)`): an absent element never
|
|
591
621
|
* equals a string, so only present payloads are compared
|
|
@@ -596,6 +626,24 @@ const includesText = (ctx, receiverText, element, args, result, operation) => {
|
|
|
596
626
|
if (search === undefined || elementKey(search.representation) === elementKey(element)) {
|
|
597
627
|
return rangedMethodText('includes', '23.1.3.16', [1, 2], 0)(ctx, receiverText, element, args, result);
|
|
598
628
|
}
|
|
629
|
+
// An optional search is still a value, never a store into the array.
|
|
630
|
+
// Undefined cannot equal a present primitive, but DOES equal a hole (Get
|
|
631
|
+
// returns undefined). Keep both carriers native and use the existing
|
|
632
|
+
// SameValueZero/relativeIndex authorities, evaluating each operand once.
|
|
633
|
+
if (search.representation.kind === 'optional' &&
|
|
634
|
+
search.representation.absence === 'undefined' &&
|
|
635
|
+
elementKey(search.representation.payload) === elementKey(element) &&
|
|
636
|
+
(element.kind === 'string' || (element.kind === 'scalar' && element.domain !== 'bigint'))) {
|
|
637
|
+
requireArity('includes', '23.1.3.16', [1, 2], args);
|
|
638
|
+
if (args[1] !== undefined)
|
|
639
|
+
requireNumber('includes', 1, args);
|
|
640
|
+
const from = args[1] === undefined ? '0.0' : operandText(ctx, args[1]);
|
|
641
|
+
return (`([&]() -> bool { const auto gea_array = ${receiverText}; const auto gea_search = ${operandText(ctx, search)}; ` +
|
|
642
|
+
`const double gea_from = ${from}; if (!gea_array) return false; const std::size_t gea_length = gea_array->size(); ` +
|
|
643
|
+
`for (std::size_t gea_index = gea::runtime::array::relativeIndex(gea_from, gea_length); gea_index < gea_length; ++gea_index) { ` +
|
|
644
|
+
`if (!gea_array->present(gea_index)) { if (!gea_search.has_value()) return true; continue; } ` +
|
|
645
|
+
`if (gea_search.has_value() && gea::sameValueZero(gea_array->readElement(gea_index), *gea_search)) return true; } return false; }())`);
|
|
646
|
+
}
|
|
599
647
|
if (args.length === 1 && search.representation.kind === 'dynamic') {
|
|
600
648
|
const cppElement = cppTypeOf(element);
|
|
601
649
|
// Each carrier here has exactly one C++ spelling (`cppScalarType`), which
|
|
@@ -620,6 +668,22 @@ const includesText = (ctx, receiverText, element, args, result, operation) => {
|
|
|
620
668
|
(element.payload.kind === 'string' || (element.payload.kind === 'scalar' && element.payload.domain !== 'bigint'))) {
|
|
621
669
|
return `gea::runtime::array::includesPresent(${receiverText}, ${operandText(ctx, search)})`;
|
|
622
670
|
}
|
|
671
|
+
// The mirror case: an OPTIONAL search value over the elements of its own
|
|
672
|
+
// payload (`(['a', 'b'] as string[]).includes(value as string)` with `value:
|
|
673
|
+
// string | null`, which a type assertion does not unwrap). A primitive
|
|
674
|
+
// element is never `null` or `undefined`, so an absent search value answers
|
|
675
|
+
// false; a present one compares its payload. The receiver and the search
|
|
676
|
+
// value are evaluated first, in that order, either way.
|
|
677
|
+
if (search.representation.kind === 'optional' &&
|
|
678
|
+
elementKey(search.representation.payload) === elementKey(element) &&
|
|
679
|
+
(element.kind === 'string' || (element.kind === 'scalar' && element.domain !== 'bigint'))) {
|
|
680
|
+
requireArity('includes', '23.1.3.16', [1, 2], args);
|
|
681
|
+
if (args[1] !== undefined)
|
|
682
|
+
requireNumber('includes', 1, args);
|
|
683
|
+
const from = args[1] === undefined ? '' : `, ${operandText(ctx, args[1])}`;
|
|
684
|
+
return (`([&]() -> bool { auto&& gea_receiver = ${receiverText}; const auto& gea_search = ${operandText(ctx, search)}; ` +
|
|
685
|
+
`return gea_search.has_value() && gea::runtime::array::includes(gea_receiver, *gea_search${from}); }())`);
|
|
686
|
+
}
|
|
623
687
|
// A search value whose every arm IS an arm of a union element -- the same
|
|
624
688
|
// arm set spelled in another order, or one member of it -- widens into the
|
|
625
689
|
// element exactly, so the comparison runs over the element's own carrier.
|
|
@@ -481,8 +481,8 @@ const promiseReactionText = (ctx, family, receiverText, onFulfilled, onRejected,
|
|
|
481
481
|
? argumentText(abi, { kind: 'undefined' }, cppUndefinedValue, 'prototype/emit-prototype-invoke.ts:then-void-value', 'value')
|
|
482
482
|
: argumentText(abi, receiverCarrier.value, caughtValueName, 'prototype/emit-prototype-invoke.ts:then-value', 'value');
|
|
483
483
|
return (`[${catchResultName}, ${fulfilledHandlerName}](${fulfilledParameter}) mutable { ` +
|
|
484
|
-
`
|
|
485
|
-
`
|
|
484
|
+
`GEA_EH_TRY_ANY(gea_eh_failed) { ${settledText(abi, fulfilledHandlerName, argument)} } ` +
|
|
485
|
+
`GEA_EH_CATCH_ANY(gea_eh_failed) { ${catchResultName}.reject(GEA_EH_CURRENT(gea_eh_failed)); } GEA_EH_END }`);
|
|
486
486
|
}
|
|
487
487
|
// 27.2.5.1 installs no fulfillment handler, so the receiver's fulfillment
|
|
488
488
|
// value travels through unchanged -- unless nobody can read it, in which
|
|
@@ -515,9 +515,9 @@ const promiseReactionText = (ctx, family, receiverText, onFulfilled, onRejected,
|
|
|
515
515
|
`${caughtSettledName}.observe(` +
|
|
516
516
|
`${fulfilledArm}, ` +
|
|
517
517
|
`[${catchResultName}, ${catchHandlerName}](const std::exception_ptr& gea_catch_rejection) mutable { ` +
|
|
518
|
-
`
|
|
519
|
-
`
|
|
520
|
-
`
|
|
518
|
+
`GEA_EH_TRY_VALUE(gea_catch_caught) { std::rethrow_exception(gea_catch_rejection); } ` +
|
|
519
|
+
`GEA_EH_CATCH_VALUE(gea_catch_caught, ${caughtReasonName}) { GEA_EH_TRY_ANY(gea_eh_failed) { ${rejectedBody} } ` +
|
|
520
|
+
`GEA_EH_CATCH_ANY(gea_eh_failed) { ${catchResultName}.reject(GEA_EH_CURRENT(gea_eh_failed)); } GEA_EH_END } GEA_EH_END }); return ${catchResultName}; }())`);
|
|
521
521
|
};
|
|
522
522
|
const promiseCatchText = (ctx, receiverText, args, result, receiverCarrier, operation) => {
|
|
523
523
|
const onRejected = args[0];
|
|
@@ -593,11 +593,11 @@ const promiseFinallyText = (ctx, receiverText, args, result, receiverCarrier, op
|
|
|
593
593
|
`const auto ${finallyHandlerName} = ${operandText(ctx, onFinally)}; ` +
|
|
594
594
|
`${caughtSettledName}.observe(` +
|
|
595
595
|
`[${catchResultName}, ${finallyHandlerName}](${fulfilledParameter}) mutable { ` +
|
|
596
|
-
`
|
|
597
|
-
`
|
|
596
|
+
`GEA_EH_TRY_ANY(gea_eh_failed) { ${finallyHandlerName}.call(); ${catchResultName}.resolve(${passThrough}); } ` +
|
|
597
|
+
`GEA_EH_CATCH_ANY(gea_eh_failed) { ${catchResultName}.reject(GEA_EH_CURRENT(gea_eh_failed)); } GEA_EH_END }, ` +
|
|
598
598
|
`[${catchResultName}, ${finallyHandlerName}](const std::exception_ptr& gea_finally_rejection) mutable { ` +
|
|
599
|
-
`
|
|
600
|
-
`
|
|
599
|
+
`GEA_EH_TRY_ANY(gea_eh_failed) { ${finallyHandlerName}.call(); ${catchResultName}.reject(gea_finally_rejection); } ` +
|
|
600
|
+
`GEA_EH_CATCH_ANY(gea_eh_failed) { ${catchResultName}.reject(GEA_EH_CURRENT(gea_eh_failed)); } GEA_EH_END }); return ${catchResultName}; }())`);
|
|
601
601
|
};
|
|
602
602
|
/**
|
|
603
603
|
* `p.toString()`.
|
|
@@ -53,8 +53,8 @@ const iteratorResultText = (ctx, receiverText, carrier, result, stepText) => {
|
|
|
53
53
|
if (result.representation.kind === 'promise' && result.representation.value.kind === 'tagged-union') {
|
|
54
54
|
const promiseType = cppTypeOf(result.representation);
|
|
55
55
|
const settled = iteratorResultText(ctx, receiverText, carrier, { ...result, representation: result.representation.value }, stepText);
|
|
56
|
-
return (`([&]() -> ${promiseType} {
|
|
57
|
-
`
|
|
56
|
+
return (`([&]() -> ${promiseType} { GEA_EH_TRY_ANY(gea_eh_failed) { return ${promiseType}(${settled}); } ` +
|
|
57
|
+
`GEA_EH_CATCH_ANY(gea_eh_failed) { return ${promiseType}::rejected_with(GEA_EH_CURRENT(gea_eh_failed)); } GEA_EH_END GEA_EH_UNREACHABLE }())`);
|
|
58
58
|
}
|
|
59
59
|
const union = iteratorResultUnionOf(carrier, result.representation);
|
|
60
60
|
const arms = iteratorResultArmsText(ctx, carrier, union, {
|
|
@@ -194,13 +194,13 @@ const awaitedOptionalText = (ctx, site, carrier, text, target) => {
|
|
|
194
194
|
*/
|
|
195
195
|
export const coroutineAwaitStatements = (ctx, site, carrier, text, target, into) => {
|
|
196
196
|
const cell = into === null || target === null || target.kind === 'void' ? null : { name: into, carrier: target };
|
|
197
|
-
// The
|
|
198
|
-
//
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
197
|
+
// The result cell holds the payload carrier the plan published for this
|
|
198
|
+
// `await` -- except where the operand is narrower than the checker's type:
|
|
199
|
+
// `await value` over an `unknown` parameter every caller passes a
|
|
200
|
+
// `Promise<number>` settles a `double` into the `gea::Value` cell `unknown`
|
|
201
|
+
// keeps, and only the conversion census can enter one into the other.
|
|
202
|
+
if (carrier.kind === 'promise')
|
|
203
|
+
return settleInto(ctx, site, text, carrier.value, cell);
|
|
204
204
|
const nativePromise = nativePromiseCoroutineText(carrier, text);
|
|
205
205
|
if (nativePromise !== null)
|
|
206
206
|
return settleInto(ctx, site, nativePromise.text, nativePromise.payload, cell);
|
|
@@ -927,7 +927,7 @@ const renderableAccessors = (layout) => layout.accessors.filter((accessor) => !c
|
|
|
927
927
|
* a boxed read answers `undefined`: exactly what an unaddressable FIELD
|
|
928
928
|
* already does, rather than a new refusal for a shape that compiles today.
|
|
929
929
|
*/
|
|
930
|
-
const accessorBoxedText = (accessor, call) => {
|
|
930
|
+
const accessorBoxedText = (accessor, structName, call) => {
|
|
931
931
|
if (accessor.value.kind === 'dynamic')
|
|
932
932
|
return call;
|
|
933
933
|
// A member the checker types `undefined` (a getter that only ever throws
|
|
@@ -939,9 +939,10 @@ const accessorBoxedText = (accessor, call) => {
|
|
|
939
939
|
// The three carriers a FIELD reaches through the runtime's typed adapter
|
|
940
940
|
// rather than through a box (`dynamicFieldAccessOf`'s `dynamicCarrier` arm).
|
|
941
941
|
// `boxedText` would `static_cast` them into a payload no reader can name, so
|
|
942
|
-
//
|
|
942
|
+
// the getter's result crosses through the same adapter a field's storage
|
|
943
|
+
// does -- bound once, because the call is the getter's observable effect.
|
|
943
944
|
if (accessor.value.kind === 'optional' || accessor.value.kind === 'tagged-union' || accessor.value.kind === 'dictionary')
|
|
944
|
-
return
|
|
945
|
+
return `gea::detail::readDynamicField(${call}, ${cppStringLiteral(structName)}, ${cppStringLiteral(accessor.key)})`;
|
|
945
946
|
const tag = dynamicTagFor(accessor.value);
|
|
946
947
|
if (tag === null)
|
|
947
948
|
return null;
|
|
@@ -955,7 +956,7 @@ const accessorUnboxText = (accessor, structName, text) => {
|
|
|
955
956
|
if (accessor.value.kind === 'dynamic')
|
|
956
957
|
return text;
|
|
957
958
|
if (accessor.value.kind === 'optional' || accessor.value.kind === 'tagged-union' || accessor.value.kind === 'dictionary')
|
|
958
|
-
return
|
|
959
|
+
return `gea::detail::unboxDynamicField<${cppTypeOf(accessor.value)}>(${text}, ${cppStringLiteral(structName)}, ${cppStringLiteral(accessor.key)})`;
|
|
959
960
|
const tag = dynamicTagFor(accessor.value);
|
|
960
961
|
if (tag === null)
|
|
961
962
|
return null;
|
|
@@ -2029,7 +2030,9 @@ unaddressableDemands = undefined, indexProtocol = true, dynamicFieldLoad, cellPa
|
|
|
2029
2030
|
const setEnvironment = environmentOf('setter', accessor.setter, '');
|
|
2030
2031
|
const descriptorGetEnvironment = environmentOf('getter', accessor.getter, 'gea_self->');
|
|
2031
2032
|
const descriptorSetEnvironment = environmentOf('setter', accessor.setter, 'gea_self->');
|
|
2032
|
-
const getText = (receiver, environment) => accessor.getter === null
|
|
2033
|
+
const getText = (receiver, environment) => accessor.getter === null
|
|
2034
|
+
? 'gea::Value()'
|
|
2035
|
+
: accessorBoxedText(accessor, structName, `${cppBodyName(accessor.getter)}(${environment}${receiver})`);
|
|
2033
2036
|
const setText = (receiver, written, environment) => {
|
|
2034
2037
|
if (accessor.setter === null)
|
|
2035
2038
|
return null;
|
|
@@ -3821,8 +3824,14 @@ export const classStaticFieldStorageRows = (storage) => {
|
|
|
3821
3824
|
const rows = [];
|
|
3822
3825
|
for (const perClass of storage.values())
|
|
3823
3826
|
rows.push(...perClass.values());
|
|
3824
|
-
|
|
3827
|
+
const uniqueViews = new Map(rows.map((entry) => [entry.viewStruct, entry]));
|
|
3828
|
+
return [...uniqueViews.values()]
|
|
3825
3829
|
.filter((entry) => entry.representation.kind !== 'unresolved' && entry.representation.kind !== 'void')
|
|
3826
3830
|
.sort((left, right) => left.name.localeCompare(right.name))
|
|
3827
|
-
.map((entry) => ({
|
|
3831
|
+
.map((entry) => ({
|
|
3832
|
+
type: cppTypeOf(entry.representation),
|
|
3833
|
+
name: entry.name,
|
|
3834
|
+
storageName: entry.storageName ?? entry.name,
|
|
3835
|
+
viewStruct: entry.viewStruct
|
|
3836
|
+
}));
|
|
3828
3837
|
};
|
|
@@ -616,6 +616,10 @@ staticMethodStateClasses = new Set(), parallelRegions = false) => {
|
|
|
616
616
|
const extended = new Set(ordered.flatMap((layout) => (layout.base === null ? [] : [layout.base])));
|
|
617
617
|
const constructions = [];
|
|
618
618
|
for (const layout of ordered) {
|
|
619
|
+
// Definition effects and static storage remain live independently of any
|
|
620
|
+
// source construction. An absent recipe without this fact still refuses.
|
|
621
|
+
if (layout.constructionDeferred)
|
|
622
|
+
continue;
|
|
619
623
|
const abi = layout.construct;
|
|
620
624
|
const instance = layout.instance;
|
|
621
625
|
if (!abi || !instance || instance.kind !== 'class-ref') {
|
|
@@ -800,6 +804,7 @@ const thunkOf = (body, captures, narrowed, narrowedResult, linkage, taskResult =
|
|
|
800
804
|
const signature = `${linkagePrefix(linkage)}${cppResultTypeOf(abi.result)} ${cppThunkName(body.sourceOwner)}(${formals.join(', ')})`;
|
|
801
805
|
const construct = constructThunkOf(body, abi, hasEnvironment, linkage);
|
|
802
806
|
return {
|
|
807
|
+
...(construct?.publishesConstruct ? { publishesConstruct: true } : {}),
|
|
803
808
|
prototype: [`${signature};`, ...(construct === null ? [] : [construct.prototype])].join('\n'),
|
|
804
809
|
// No `registerSource` beside the thunk any more: the function's
|
|
805
810
|
// `name`/`length`/source text register at the sites that mint a function
|
|
@@ -874,18 +879,20 @@ const constructThunkOf = (body, abi, hasEnvironment, linkage) => {
|
|
|
874
879
|
// question. A body with no environment is called through it just the same,
|
|
875
880
|
// with the `void*` the signature carries either way.
|
|
876
881
|
const entry = `${cppThunkName(body.sourceOwner)}(${actuals.join(', ')});`;
|
|
877
|
-
//
|
|
878
|
-
//
|
|
879
|
-
//
|
|
880
|
-
//
|
|
881
|
-
//
|
|
882
|
-
//
|
|
883
|
-
//
|
|
884
|
-
|
|
885
|
-
|
|
882
|
+
// No registration beside the thunk: every site that mints a value of this
|
|
883
|
+
// function publishes this construct thunk in the value's entry record
|
|
884
|
+
// (`emit-context.ts`'s `cppThunkEntryText`). A value that is later viewed
|
|
885
|
+
// under a type naming its `[[Construct]]` -- `Factory as typeof Factory &
|
|
886
|
+
// (new (v: number) => T)` -- carries that record and nothing else about its
|
|
887
|
+
// declaration, so this is what lets the conversion stay a property of the
|
|
888
|
+
// VALUE rather than a guess about which declaration a cell holds
|
|
889
|
+
// (`gea::withConstructEntry`, gea_runtime.h). Not keyed by the invoke
|
|
890
|
+
// pointer: a release link may fold two declarations' identical invoke
|
|
891
|
+
// thunks into one address.
|
|
886
892
|
return {
|
|
887
893
|
prototype: `${signature};`,
|
|
888
|
-
definition: `${signature} { ${allocation} ${entry} return ${cppReceiverName}; }
|
|
894
|
+
definition: `${signature} { ${allocation} ${entry} return ${cppReceiverName}; }`,
|
|
895
|
+
publishesConstruct: true
|
|
889
896
|
};
|
|
890
897
|
};
|
|
891
898
|
/**
|
|
@@ -1120,8 +1127,9 @@ const commonJsDefinitionsOf = (bodies, realm = false) => {
|
|
|
1120
1127
|
` auto& state = ${stateAccessor}();`,
|
|
1121
1128
|
` if (state.phase != ${stateName}::Phase::fresh) return state.module->${exportField};`,
|
|
1122
1129
|
` state.phase = ${stateName}::Phase::loading;`,
|
|
1123
|
-
`
|
|
1124
|
-
`
|
|
1130
|
+
` GEA_EH_TRY_ANY(gea_eh_failed) { ${cppBodyName(target)}(); state.phase = ${stateName}::Phase::loaded; return state.module->${exportField}; }`,
|
|
1131
|
+
` GEA_EH_CATCH_ANY(gea_eh_failed) { state.phase = ${stateName}::Phase::fresh; state.module = ${recordInit}; GEA_EH_RETHROW_ANY(gea_eh_failed); } GEA_EH_END`,
|
|
1132
|
+
` GEA_EH_UNREACHABLE`,
|
|
1125
1133
|
'}'
|
|
1126
1134
|
].join('\n'));
|
|
1127
1135
|
}
|
|
@@ -1735,7 +1743,10 @@ const renderTranslationUnitSession = (input) => {
|
|
|
1735
1743
|
const classStaticFields = censusClassStaticFieldStorage(input.bodies, input.classes, input.realmStorage);
|
|
1736
1744
|
publishClassStaticFieldStorage(input.classes, classStaticFields.storage);
|
|
1737
1745
|
publishConstructorViewShapes(input.classes, input.bodies);
|
|
1738
|
-
const classStatics = classStaticFieldStorageRows(classStaticFields.storage).map((row) =>
|
|
1746
|
+
const classStatics = classStaticFieldStorageRows(classStaticFields.storage).map((row) => ({
|
|
1747
|
+
declaration: `struct ${row.viewStruct} final { ${row.type} value{}; bool present = false; };`,
|
|
1748
|
+
definition: `struct ${row.viewStruct} final { ${row.type} value{}; bool present = false; };`
|
|
1749
|
+
}));
|
|
1739
1750
|
// The reactive plan, completed with the two answers only this stage has.
|
|
1740
1751
|
//
|
|
1741
1752
|
// `revisions` is the struct renderer's own decision about which reactive
|
|
@@ -1980,10 +1991,14 @@ const renderTranslationUnitSession = (input) => {
|
|
|
1980
1991
|
return entry === undefined ? [original] : [original, `${signatureOf(body, captures, new Set(), false, entry.formals, entry.name)};`];
|
|
1981
1992
|
});
|
|
1982
1993
|
const thunks = new Map();
|
|
1994
|
+
// The functions whose minted values publish a `[[Construct]]` entry.
|
|
1995
|
+
const constructEntries = new Set();
|
|
1983
1996
|
for (const body of input.bodies) {
|
|
1984
1997
|
const thunk = thunkOf(body, captures, formalsNarrowedIn(body.sourceOwner), resultNarrowedIn(body.sourceOwner), linkage, taskResultOf(body));
|
|
1985
1998
|
if (thunk)
|
|
1986
1999
|
thunks.set(body, thunk);
|
|
2000
|
+
if (thunk?.publishesConstruct && !isRegionId(body.sourceOwner))
|
|
2001
|
+
constructEntries.add(body.sourceOwner);
|
|
1987
2002
|
}
|
|
1988
2003
|
// ONE tag object per source declaration, shared by every monomorphic copy of
|
|
1989
2004
|
// it. `gea::identifyCallable<&tag>` instantiates
|
|
@@ -2059,7 +2074,7 @@ const renderTranslationUnitSession = (input) => {
|
|
|
2059
2074
|
// The formals this body's signature takes by reference: their objects
|
|
2060
2075
|
// outlive the call, which `emit.ts`'s stable field reads rely on.
|
|
2061
2076
|
const borrowed = stableEntry?.formals ?? formalsBorrowedIn(body.sourceOwner);
|
|
2062
|
-
const sections = emitBody(promiseView ?? body, input.placements, input.classes, hosts, deriver, input.wellKnownSymbols, captures, symbolKeys, templateObjects, directCallables, virtuals.dispatched, narrowedStorage.factsOf(body.sourceOwner), formalsNarrowedIn(body.sourceOwner), repeatedConstructors, dyingArguments, instantiation, (callable) => abiByBody.get(String(callable)) ?? null, functionFacts, hostMethodAliases, callableMemberCandidates, callableFlowCandidates.get(body.owner) ?? new Map(), borrowableMemberBodies, stableBorrowEntries, printerDrift, input.conversions, selectionHelpers, callableIdentityDemand, nativeIntegrityRestricted, fixedFieldStateConstant, definitionCells, constructionOnlyFields, keyOrderUnobserved, debugSource, borrowed, asyncResults.taskResults, programSite.conversionIsCertified, input.programConversionRecipes, structs.classIndexProtocols);
|
|
2077
|
+
const sections = emitBody(promiseView ?? body, input.placements, input.classes, hosts, deriver, input.wellKnownSymbols, captures, symbolKeys, templateObjects, directCallables, virtuals.dispatched, narrowedStorage.factsOf(body.sourceOwner), formalsNarrowedIn(body.sourceOwner), repeatedConstructors, dyingArguments, instantiation, (callable) => abiByBody.get(String(callable)) ?? null, functionFacts, constructEntries, hostMethodAliases, callableMemberCandidates, callableFlowCandidates.get(body.owner) ?? new Map(), borrowableMemberBodies, stableBorrowEntries, printerDrift, input.conversions, selectionHelpers, callableIdentityDemand, nativeIntegrityRestricted, fixedFieldStateConstant, definitionCells, constructionOnlyFields, keyOrderUnobserved, debugSource, borrowed, asyncResults.taskResults, programSite.conversionIsCertified, input.programConversionRecipes, structs.classIndexProtocols);
|
|
2063
2078
|
const commonJsScope = [
|
|
2064
2079
|
...coroutineEnvironmentPrologueOf(promiseView ?? body, captures),
|
|
2065
2080
|
...(commonJsOwner === null || commonJsOwner.nativeRecord
|
|
@@ -2414,8 +2429,7 @@ const renderTranslationUnitSession = (input) => {
|
|
|
2414
2429
|
program.append(plain(definition.text));
|
|
2415
2430
|
if (isolate)
|
|
2416
2431
|
program.append(plain(namespaceOpen));
|
|
2417
|
-
|
|
2418
|
-
program.append(plain(spelling.definition));
|
|
2432
|
+
// Static own-property view structs are declared once in the shared header.
|
|
2419
2433
|
for (const spelling of globals)
|
|
2420
2434
|
program.append(plain(spelling.definition));
|
|
2421
2435
|
for (const helper of selectionHelpers?.values() ?? [])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/compiler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"description": "The geastack TypeScript-to-C++ compiler: one semantic spine, no source-shaped authority, no boxing of statically typed values.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -45,8 +45,9 @@
|
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"test:cli-plugins": "node --test test/cli-plugins.mjs",
|
|
48
|
-
"test:gea-host-namespace-members": "node --test test/gea-host-namespace-members.mjs",
|
|
48
|
+
"test:gea-host-namespace-members": "node --test test/gea-host-namespace-members.mjs test/host-member-namespace-receiver.mjs",
|
|
49
49
|
"test:allocation-runtime": "node test/allocation-runtime.mjs",
|
|
50
|
+
"test:native-microtask-lifetime": "node test/native-microtask-lifetime.mjs",
|
|
50
51
|
"test:compact-runtime": "node test/compact-runtime.mjs",
|
|
51
52
|
"test:stored-listener-native-flow": "node test/stored-listener-native-flow.mjs",
|
|
52
53
|
"test:native-typed-field-read": "node test/native-typed-field-read.mjs",
|
|
@@ -60,7 +61,7 @@
|
|
|
60
61
|
"test:declared-integers": "node --test dist/conversion/native-selection.test.js && node test/declared-integer-contracts.mjs",
|
|
61
62
|
"test:dynamic-value-metadata": "node test/dynamic-value-metadata.mjs",
|
|
62
63
|
"test:native-field-descriptors": "node test/native-field-descriptors.mjs",
|
|
63
|
-
"test:declaration-overlays": "node --test dist/semantics/declaration-overlay-transform.test.js",
|
|
64
|
+
"test:declaration-overlays": "node --import ./scripts/host-toolchain.mjs --test dist/semantics/declaration-overlay-transform.test.js",
|
|
64
65
|
"test:recursive-native-carriers": "node test/recursive-native-carriers.mjs",
|
|
65
66
|
"test:hot-path-shapes": "node test/hot-path-shapes.mjs",
|
|
66
67
|
"build": "npm run architecture && tsc -p tsconfig.json && node scripts/mark-bins-executable.mjs && node scripts/build-checks.mjs",
|
|
@@ -84,13 +85,13 @@
|
|
|
84
85
|
"fastify": "^5.0.0",
|
|
85
86
|
"find-my-way": "9.6.0",
|
|
86
87
|
"prettier": "^3.8.3",
|
|
87
|
-
"@geastack/core": "0.1.
|
|
88
|
-
"@geastack/host": "0.1.
|
|
89
|
-
"@geastack/engine": "0.1.
|
|
88
|
+
"@geastack/core": "0.1.43",
|
|
89
|
+
"@geastack/host": "0.1.18",
|
|
90
|
+
"@geastack/engine": "0.1.18",
|
|
90
91
|
"@geastack/elements": "0.1.5",
|
|
91
92
|
"@geastack/geaos": "0.1.3",
|
|
92
93
|
"@geastack/apple": "0.2.14",
|
|
93
|
-
"@geastack/geatsc-plugin-gea": "0.1.
|
|
94
|
+
"@geastack/geatsc-plugin-gea": "0.1.24",
|
|
94
95
|
"@geastack/geatsc-plugin-apple-native": "0.1.4",
|
|
95
96
|
"@geastack/native-webgl-angle": "0.1.9"
|
|
96
97
|
},
|
|
@@ -215,13 +215,23 @@ inline Value dynamicAdd(const Value& left, const Value& right) {
|
|
|
215
215
|
|
|
216
216
|
inline bool dynamicArrayPrototypeHas(const PropertyKey& key) {
|
|
217
217
|
if (key.isSymbol()) return false;
|
|
218
|
-
|
|
218
|
+
std::size_t index = 0;
|
|
219
|
+
if (detail::arrayIndexOfKey(key, index)) return arrayPrototypeObject()->present(index);
|
|
220
|
+
for (const char* name : {"push", "pop", "join", "toString", "map", "filter", "forEach", "slice", "some"})
|
|
219
221
|
if (key.text() == name) return true;
|
|
220
222
|
return false;
|
|
221
223
|
}
|
|
222
224
|
|
|
223
|
-
inline Value dynamicArrayPrototypeGet(const PropertyKey& key) {
|
|
225
|
+
inline Value dynamicArrayPrototypeGet(const PropertyKey& key, const Value& receiver) {
|
|
224
226
|
if (key.isSymbol()) return Value();
|
|
227
|
+
std::size_t index = 0;
|
|
228
|
+
if (detail::arrayIndexOfKey(key, index)) {
|
|
229
|
+
const auto prototype = arrayPrototypeObject();
|
|
230
|
+
if (!prototype->present(index)) return Value();
|
|
231
|
+
if (prototype->indexedDescriptors && arrayIndexedDescriptorContains(prototype->indexedDescriptors, index))
|
|
232
|
+
return prototype->indexedDescriptors->getWithNativeReceiver(key, NativeCallReceiver::fromValue(receiver));
|
|
233
|
+
return prototype->readElement(index);
|
|
234
|
+
}
|
|
225
235
|
using Args = gea::Ref<ArrayObject<Value>>;
|
|
226
236
|
using Method = CallableObject<Value(Value, Args)>;
|
|
227
237
|
if (key.text() == "push") {
|
|
@@ -233,6 +243,31 @@ inline Value dynamicArrayPrototypeGet(const PropertyKey& key) {
|
|
|
233
243
|
}, nullptr));
|
|
234
244
|
return method;
|
|
235
245
|
}
|
|
246
|
+
if (key.text() == "some") {
|
|
247
|
+
static const Value method = Value::boxMethod<1>(Method(+[](void*, Value receiver, Args args) -> Value {
|
|
248
|
+
if (receiver.tag() == Value::Tag::Null || receiver.tag() == Value::Tag::Undefined)
|
|
249
|
+
host::throwRuntimeError("TypeError", "Array.prototype.some called on null or undefined");
|
|
250
|
+
if (receiver.tag() != Value::Tag::Object && receiver.tag() != Value::Tag::Function)
|
|
251
|
+
host::throwRuntimeError("TypeError", "Native Array.prototype.some does not support primitive wrappers");
|
|
252
|
+
const double rawLength = dynamicToNumber(receiver.getProperty(PropertyKey::string("length")));
|
|
253
|
+
const std::uint64_t length = rawLength > 0
|
|
254
|
+
? static_cast<std::uint64_t>(std::min(std::floor(rawLength), 9007199254740991.0)) : 0;
|
|
255
|
+
const Value callback = args->size() ? args->readElement(0) : Value();
|
|
256
|
+
if (callback.tag() != Value::Tag::Function)
|
|
257
|
+
host::throwRuntimeError("TypeError", "Array callback must be callable");
|
|
258
|
+
const Value thisArg = args->size() > 1 ? args->readElement(1) : Value();
|
|
259
|
+
for (std::uint64_t i = 0; i < length; ++i) {
|
|
260
|
+
const auto index = PropertyKey::string(std::to_string(i));
|
|
261
|
+
if (!receiver.hasProperty(index)) continue;
|
|
262
|
+
const Value item = receiver.getProperty(index);
|
|
263
|
+
if (host::detail::toBoolean(callback.callWithReceiver(thisArg,
|
|
264
|
+
{item, Value::box(Value::Tag::Number, static_cast<double>(i)), receiver})))
|
|
265
|
+
return Value::box(Value::Tag::Boolean, true);
|
|
266
|
+
}
|
|
267
|
+
return Value::box(Value::Tag::Boolean, false);
|
|
268
|
+
}, nullptr));
|
|
269
|
+
return method;
|
|
270
|
+
}
|
|
236
271
|
if (key.text() == "pop") {
|
|
237
272
|
static const Value method = Value::boxMethod<1>(Method(+[](void*, Value receiver, Args) -> Value {
|
|
238
273
|
double length = dynamicToNumber(receiver.getProperty(PropertyKey::string("length")));
|
|
@@ -306,6 +341,10 @@ inline Value dynamicArrayPrototypeGet(const PropertyKey& key) {
|
|
|
306
341
|
return Value();
|
|
307
342
|
}
|
|
308
343
|
|
|
344
|
+
inline Value dynamicArrayPrototypeGet(const PropertyKey& key) {
|
|
345
|
+
return dynamicArrayPrototypeGet(key, Value());
|
|
346
|
+
}
|
|
347
|
+
|
|
309
348
|
/**
|
|
310
349
|
* `String.prototype`'s methods read off a string the program declared `any`
|
|
311
350
|
* (`name.toLowerCase()` after `name = \`${name}\``). Each is the native
|
|
@@ -365,7 +404,7 @@ inline Value dynamicStringPrototypeGet(const PropertyKey& key) {
|
|
|
365
404
|
inline Ref<ArrayObject<Value>> arrayPrototypeObject() {
|
|
366
405
|
static const Ref<ArrayObject<Value>> prototype = [] {
|
|
367
406
|
auto object = makeRef<ArrayObject<Value>>();
|
|
368
|
-
for (const char* name : {"push", "pop", "join", "toString", "map", "filter", "forEach", "slice"}) {
|
|
407
|
+
for (const char* name : {"push", "pop", "join", "toString", "map", "filter", "forEach", "slice", "some"}) {
|
|
369
408
|
const auto key = PropertyKey::string(name);
|
|
370
409
|
auto descriptor = PropertyDescriptor::assignment(dynamicArrayPrototypeGet(key));
|
|
371
410
|
descriptor.enumerable = false;
|
|
@@ -916,6 +916,9 @@ struct Machine {
|
|
|
916
916
|
for (std::size_t i = 1; i < tree->children.size(); ++i) args.push_back(eval(tree->children[i]));
|
|
917
917
|
if (tree->kind == Node::Construct) {
|
|
918
918
|
if (callee.tag() != Value::Tag::Function) error("TypeError", "Value is not a constructor");
|
|
919
|
+
// An entry comparison that folding cannot mislead: a function the
|
|
920
|
+
// linker folded into this interpreter entry has its code, so it is
|
|
921
|
+
// an eval closure in every respect this construction relies on.
|
|
919
922
|
if (callee.payloadType() != detail::payloadTypeTagFor<Function>() || callee.as<Function>().invoke != invoke)
|
|
920
923
|
unsupported("Constructing an external callable requires a native construct adapter");
|
|
921
924
|
self = Value::object();
|