@geastack/compiler 1.0.63 → 1.0.64
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/dist/cli-emit.js +14 -5
- package/dist/conversion/dictionary-view.js +13 -2
- package/dist/conversion/document-record-view.d.ts +0 -1
- package/dist/conversion/document-record-view.js +30 -3
- package/dist/conversion/impossible-field-read.d.ts +9 -0
- package/dist/conversion/impossible-field-read.js +26 -0
- package/dist/conversion/nodes.d.ts +12 -0
- package/dist/conversion/nodes.js +106 -2
- package/dist/conversion/record-view.js +21 -0
- package/dist/ir/build.d.ts +5 -2
- package/dist/ir/build.js +9 -2
- package/dist/ir/callable-class-flow.js +233 -13
- package/dist/ir/certify/parallel-region.js +1 -0
- package/dist/ir/certify.js +32 -2
- package/dist/ir/hoist.js +15 -1
- package/dist/ir/host-template-conversions.js +12 -0
- package/dist/ir/lower-invocation.js +42 -2
- package/dist/ir/lower-property.js +2 -2
- package/dist/ir/model.d.ts +18 -6
- package/dist/ir/native-callable-data-reads.js +15 -2
- package/dist/ir/native-field-view-domains.d.ts +8 -0
- package/dist/ir/native-field-view-domains.js +44 -3
- package/dist/ir/native-field-view-facts.d.ts +2 -2
- package/dist/ir/native-field-view-facts.js +57 -13
- package/dist/ir/native-own-assignment.js +20 -2
- package/dist/ir/program-conversions.js +38 -7
- package/dist/ir/property-read-conversions.js +14 -5
- package/dist/ir/publish-native-field-view-facts.js +1 -1
- package/dist/ir/queries.js +2 -0
- package/dist/ir/read-only-dictionary.js +138 -15
- package/dist/ir/reflection-demand.js +7 -1
- package/dist/ir/shake.js +26 -6
- package/dist/ir/typed-property-access.d.ts +20 -0
- package/dist/ir/typed-property-access.js +56 -0
- package/dist/projection/bindings.js +14 -19
- package/dist/projection/fields.js +7 -1
- package/dist/projection/native-object-data.d.ts +8 -1
- package/dist/projection/native-object-data.js +16 -4
- package/dist/representation/derive.js +67 -1
- package/dist/representation/proxy-carriers.js +17 -2
- package/dist/representation/publish.js +34 -0
- package/dist/semantics/callable-own-data-slots.js +71 -6
- package/dist/semantics/model/operations.d.ts +15 -4
- package/dist/semantics/native-own-assignment.d.ts +3 -0
- package/dist/semantics/normalize/collection-bindings.js +2 -2
- package/dist/semantics/normalize/flow/array-element-continuation.d.ts +1 -1
- package/dist/semantics/normalize/flow/array-element-continuation.js +32 -9
- package/dist/semantics/normalize/flow/callable-reach.d.ts +3 -5
- package/dist/semantics/normalize/flow/callable-reach.js +3 -5
- package/dist/semantics/normalize/flow/component-solver.d.ts +2 -0
- package/dist/semantics/normalize/flow/component-solver.js +32 -6
- package/dist/semantics/normalize/flow/computed-key-set.js +53 -1
- package/dist/semantics/normalize/flow/source-value-session.js +16 -14
- package/dist/semantics/normalize/producers/invocations.js +40 -1
- package/dist/semantics/normalize/producers/native-own-assignment.js +12 -4
- package/dist/semantics/normalize/reachability.js +18 -8
- package/dist/semantics/normalize/structural-mutable-field.d.ts +1 -0
- package/dist/semantics/normalize/structural-mutable-field.js +170 -4
- package/dist/semantics/normalize/structural-parts.js +6 -1
- package/dist/semantics/normalize/structural-self-reference.d.ts +1 -1
- package/dist/semantics/normalize/structural-self-reference.js +9 -1
- package/dist/semantics/normalize/structural.js +10 -1
- package/dist/semantics/program.js +102 -1
- package/dist/targets/cpp/class-properties/emit-class-properties.js +9 -0
- package/dist/targets/cpp/emit-allocation.js +22 -1
- package/dist/targets/cpp/emit-exceptions.js +6 -0
- package/dist/targets/cpp/emit-narrowing.js +24 -2
- package/dist/targets/cpp/emit-native-field-view.d.ts +1 -1
- package/dist/targets/cpp/emit-native-field-view.js +37 -5
- package/dist/targets/cpp/emit-native-own-assignment.js +5 -1
- package/dist/targets/cpp/emit-record-view.js +6 -1
- package/dist/targets/cpp/emit-tonumber.d.ts +22 -11
- package/dist/targets/cpp/emit-tonumber.js +86 -25
- package/dist/targets/cpp/emit.js +3 -0
- package/dist/targets/cpp/host/emit-host-invoke.js +6 -6
- package/dist/targets/cpp/prototype/emit-prototype-array.js +13 -1
- package/dist/targets/cpp/records.js +15 -7
- package/dist/targets/cpp/recursive-containers.js +5 -1
- package/dist/targets/cpp/translation-unit.js +17 -2
- package/package.json +4 -2
- package/src/targets/cpp/runtime/gea_runtime.h +212 -7
|
@@ -686,7 +686,16 @@ export const computedClassPrototypeMethodText = (ctx, operation) => {
|
|
|
686
686
|
};
|
|
687
687
|
const methods = [];
|
|
688
688
|
const overriddenKeys = [];
|
|
689
|
+
// A proven key domain (`GetOperation.provenKeyTexts`, the key's own literal
|
|
690
|
+
// set when its type is one) is the set the method-frame census publishes
|
|
691
|
+
// (`native-method-frames.ts`): a method outside it -- a `clone(): Request`
|
|
692
|
+
// or `bytes()` whose frame happens to convert into the joined result of
|
|
693
|
+
// `raw[key]()` over `keyof Body` -- has no certified frame and is no value
|
|
694
|
+
// this read takes.
|
|
695
|
+
const domain = operation.provenKeyTexts === undefined ? null : new Set(operation.provenKeyTexts);
|
|
689
696
|
for (const { key: methodKey, method } of reachableClassMethodsOf(ctx.classes, receiver.declaration)) {
|
|
697
|
+
if (domain !== null && !domain.has(methodKey))
|
|
698
|
+
continue;
|
|
690
699
|
if (method === null) {
|
|
691
700
|
overriddenKeys.push(methodKey);
|
|
692
701
|
continue;
|
|
@@ -937,6 +937,12 @@ orderless = false) => {
|
|
|
937
937
|
// (unconditional) branch.
|
|
938
938
|
const sourceFields = fields ?? [];
|
|
939
939
|
const skipMarks = [];
|
|
940
|
+
// A shared source may be a live view whose struct slots are inert: its
|
|
941
|
+
// own keys and values live behind its routes. The same stores, each read
|
|
942
|
+
// through the view in the field's declared carrier, with presence from
|
|
943
|
+
// the view's own-key route (`copiesThroughNativeView`).
|
|
944
|
+
const viewSource = 'ownership' in from && from.ownership === 'shared-refcount' && (from.kind === 'record' || from.kind === 'native-record-ref');
|
|
945
|
+
const viewLines = [];
|
|
940
946
|
// The outlined line of each source field by layout position (null: no store).
|
|
941
947
|
const outlinedByPosition = [];
|
|
942
948
|
for (const field of sourceFields) {
|
|
@@ -960,6 +966,17 @@ orderless = false) => {
|
|
|
960
966
|
if (write === null)
|
|
961
967
|
throw createCppEmitBlockedError('runtime-helper:protocol:spread:next:unrepresented-own-key', `a spread cannot preserve the source's own key "${field.key}" in a receiver with no field or sidecar for it`);
|
|
962
968
|
staticLines.push(field.required ? write : `if (${member}${cppRecordFieldPresenceName(field.key)}) { ${write} }`);
|
|
969
|
+
if (viewSource) {
|
|
970
|
+
const plain = tailAwareFieldReadText(sourceFields, field.key, member);
|
|
971
|
+
const type = cppTypeOf(field.value);
|
|
972
|
+
const read = `gea::record::readDeclaredField<${type}, ${nativeFieldPolicyType(field.value)}>(${text}, ${cppStringLiteral(field.key)}, ` +
|
|
973
|
+
`[&]() -> ${type} { return ${plain}; })`;
|
|
974
|
+
const viewWrite = staticWrite(receiverText, field.key, field.value, read);
|
|
975
|
+
if (viewWrite !== null)
|
|
976
|
+
viewLines.push(field.required
|
|
977
|
+
? viewWrite
|
|
978
|
+
: `if (gea::record::hasOwnFieldView(gea::Ref<void>(${text}), gea::PropertyKey::string(${cppStringLiteral(field.key)}))) { ${viewWrite} }`);
|
|
979
|
+
}
|
|
963
980
|
const outlined = staticWrite('gea_spread_target', field.key, field.value, tailAwareFieldReadText(sourceFields, field.key, outlinedMember));
|
|
964
981
|
if (outlined !== null) {
|
|
965
982
|
const line = field.required ? outlined : `if (${outlinedMember}${cppRecordFieldPresenceName(field.key)}) { ${outlined} }`;
|
|
@@ -973,6 +990,7 @@ orderless = false) => {
|
|
|
973
990
|
// source and receiver carrier and each site calls it (`unitFunctionName`),
|
|
974
991
|
// as the walk's key routing already is: the same stores, one copy of the
|
|
975
992
|
// code instead of one per site in the instruction cache.
|
|
993
|
+
const viewComplete = viewLines.length === staticLines.length;
|
|
976
994
|
const outlinedCall = receiver.ownership === 'shared-refcount' &&
|
|
977
995
|
ownershipOfSpreadSource(from) === 'shared-refcount' &&
|
|
978
996
|
staticLines.length >= outlinedCopyMinimumFields &&
|
|
@@ -993,8 +1011,11 @@ orderless = false) => {
|
|
|
993
1011
|
throw createCppEmitBlockedError('runtime-helper:protocol:spread:next:record(accessors-without-walk)', 'a spread of an object literal with accessors copies them only through the runtime creation-order walk, ' +
|
|
994
1012
|
'and this source/receiver pair has none; a static copy would drop the accessor keys');
|
|
995
1013
|
}
|
|
996
|
-
const copyLines = [...staticLines, ...skipMarks];
|
|
997
1014
|
const indexes = view?.indexes ?? [];
|
|
1015
|
+
const viewAware = viewSource && ordered === null && indexes.length === 0 && viewComplete;
|
|
1016
|
+
const copyLines = viewAware
|
|
1017
|
+
? [`if (gea::detail::copiesThroughNativeView(${text})) {`, ...viewLines, '} else {', ...staticLines, '}', ...skipMarks]
|
|
1018
|
+
: [...staticLines, ...skipMarks];
|
|
998
1019
|
for (const sourceIndex of indexes) {
|
|
999
1020
|
const table = `${member}${cppRecordIndexSidecarNameFor(sourceIndex, indexes)}`;
|
|
1000
1021
|
const attributes = `${member}${cppRecordIndexAttributesNameFor(sourceIndex, indexes)}`;
|
|
@@ -543,6 +543,12 @@ export const renderTryRegion = (ctx, lines, body, region, rendering) => {
|
|
|
543
543
|
lines.push('}');
|
|
544
544
|
lines.push(`if (${finallyPendingName(region)}) std::rethrow_exception(${finallyPendingName(region)});`);
|
|
545
545
|
lines.push('}');
|
|
546
|
+
// No side of the statement completes normally (`join` is null: every try
|
|
547
|
+
// and catch path returns or throws), so control never falls past the
|
|
548
|
+
// rethrow. Without saying so, a body whose last statement this is ends
|
|
549
|
+
// with no return and clang warns -Wreturn-type.
|
|
550
|
+
if (region.join === null)
|
|
551
|
+
lines.push('__builtin_unreachable();');
|
|
546
552
|
}
|
|
547
553
|
return [...tryPart.owned, ...(catchPart?.owned ?? []), ...(finallyPart?.owned ?? [])];
|
|
548
554
|
};
|
|
@@ -12,11 +12,11 @@ import { abiKey, arrayExtensionKey, containsUnresolved, isCanonicalNumberPropert
|
|
|
12
12
|
import { programConversionKey } from '../../ir/program-conversions.js';
|
|
13
13
|
import { transferOf } from '../../ir/transfer.js';
|
|
14
14
|
import { coercionText } from './emit-coercion.js';
|
|
15
|
-
import { ARM_VIEW_MATERIALIZER, ASSERTED_UNION_MATERIALIZER, ASSERTED_UNION_COPY_MATERIALIZER, FRAME_ARGUMENT_UNION_MATERIALIZER, ASSERTED_VIEW_MATERIALIZER, EXACT_ARM_MATERIALIZER, FAMILY_MEMBER_VIEW_MATERIALIZER, CAUGHT_HANDOFF_MATERIALIZER, ASSERTED_CLASS_DOWNCAST_MATERIALIZER, NULLISH_OPTIONAL_MATERIALIZER, NATIVE_BASE_VIEW_MATERIALIZER, IMPOSSIBLE_INDEX_READ, exactArmIndexOf, isNativeCollectionUpcast } from '../../conversion/nodes.js';
|
|
15
|
+
import { ARM_VIEW_MATERIALIZER, ASSERTED_UNION_MATERIALIZER, ASSERTED_UNION_COPY_MATERIALIZER, FRAME_ARGUMENT_UNION_MATERIALIZER, ASSERTED_VIEW_MATERIALIZER, EXACT_ARM_MATERIALIZER, FAMILY_MEMBER_VIEW_MATERIALIZER, CAUGHT_HANDOFF_MATERIALIZER, ASSERTED_CLASS_DOWNCAST_MATERIALIZER, NULLISH_OPTIONAL_MATERIALIZER, PRESENT_PAYLOAD_MATERIALIZER, NATIVE_BASE_VIEW_MATERIALIZER, IMPOSSIBLE_INDEX_READ, exactArmIndexOf, isNativeCollectionUpcast } from '../../conversion/nodes.js';
|
|
16
16
|
import { certifiedRecordViewText, familyMemberViewText, structuralRecordViewText } from './emit-record-view.js';
|
|
17
17
|
import { documentRecordViewText } from './emit-document-record-view.js';
|
|
18
18
|
import { dynamicRecordLoadNeedsPlan } from '../../conversion/document-record-view.js';
|
|
19
|
-
import { IMPOSSIBLE_FIELD_READ } from '../../conversion/impossible-field-read.js';
|
|
19
|
+
import { ABSENT_ONLY_FIELD_READ, IMPOSSIBLE_FIELD_READ } from '../../conversion/impossible-field-read.js';
|
|
20
20
|
import { checkedNativeFieldReadMismatchOf } from '../../conversion/checked-native-field-read.js';
|
|
21
21
|
import { callablePayloadText, callableViewText } from './emit-callable-view.js';
|
|
22
22
|
import { dictionaryReadText, dictionaryViewText } from './emit-dictionary-view.js';
|
|
@@ -5235,6 +5235,11 @@ const renderedRecipeText = (ctx, node, text) => {
|
|
|
5235
5235
|
}
|
|
5236
5236
|
if (materializer.id === IMPOSSIBLE_FIELD_READ || materializer.id === IMPOSSIBLE_INDEX_READ)
|
|
5237
5237
|
return `((void)(${text}), gea::host::unreachableValue<${cppTypeOf(node.target)}>())`;
|
|
5238
|
+
if (materializer.id === ABSENT_ONLY_FIELD_READ && node.target.kind === 'optional') {
|
|
5239
|
+
const optionalType = cppTypeOf(node.target);
|
|
5240
|
+
return (`[](const auto& gea_absent_only) -> ${optionalType} { if (gea_absent_only.has_value()) ` +
|
|
5241
|
+
`return gea::host::unreachableValue<${optionalType}>(); return ${optionalType}(); }(${text})`);
|
|
5242
|
+
}
|
|
5238
5243
|
}
|
|
5239
5244
|
if (node.capability.kind === 'coercion')
|
|
5240
5245
|
return coercionText(node.capability.operation, text, node.source, ctx.layouts);
|
|
@@ -5294,6 +5299,23 @@ const renderedRecipeText = (ctx, node, text) => {
|
|
|
5294
5299
|
return (`[](const gea::Value& gea_nullish) -> ${optionalType} { return gea_nullish.tag() == gea::Value::Tag::Null || ` +
|
|
5295
5300
|
`gea_nullish.tag() == gea::Value::Tag::Undefined ? ${optionalType}() : ${optionalType}(${payload}); }(${text})`);
|
|
5296
5301
|
}
|
|
5302
|
+
// The census's checked read of a present payload (`nodes.ts`'s `presentPayloadFor`).
|
|
5303
|
+
if (node.capability.kind === 'static' &&
|
|
5304
|
+
node.capability.materializer.id === PRESENT_PAYLOAD_MATERIALIZER &&
|
|
5305
|
+
node.source.kind === 'optional') {
|
|
5306
|
+
const payloadNode = node.capability.materializer.dependencies?.[0];
|
|
5307
|
+
if (!payloadNode || ctx.conversions.nodeById(payloadNode.id) !== payloadNode)
|
|
5308
|
+
return null;
|
|
5309
|
+
const payload = recipeText(ctx, payloadNode, '(*gea_present)');
|
|
5310
|
+
if (payload === null)
|
|
5311
|
+
return null;
|
|
5312
|
+
// The parameter names the source's own type: the payload recipe calls
|
|
5313
|
+
// member templates on it (`.is<1>()`), which a generic `auto` parameter
|
|
5314
|
+
// makes dependent names that need `.template` -- and this text may itself
|
|
5315
|
+
// sit inside another generic lambda (a native field-view write).
|
|
5316
|
+
return (`[&](const ${cppTypeOf(node.source)}& gea_present) -> ${cppTypeOf(node.target)} { if (!gea_present.has_value()) ` +
|
|
5317
|
+
`gea::host::throwRuntimeError("TypeError", "a value the program proved present was absent"); return ${payload}; }(${text})`);
|
|
5318
|
+
}
|
|
5297
5319
|
// The census's checked class downcast for an `as Derived` receiver
|
|
5298
5320
|
// (`nodes.ts`'s `assertedClassDowncastFor`).
|
|
5299
5321
|
if (node.capability.kind === 'static' &&
|
|
@@ -3,7 +3,7 @@ import type { NativeFieldViewRead } from '../../ir/native-field-view-facts.js';
|
|
|
3
3
|
import { type Representation } from '../../representation/model.js';
|
|
4
4
|
import { type EmitContext } from './emit-context.js';
|
|
5
5
|
/** Carrier wrappers select a native allocation; the route itself is never inferred from its copied fields. */
|
|
6
|
-
export declare const withFieldReceiver: (value: Representation, text: string, emit: (carrier: Representation) => string, dynamic?: (carrier: Representation, text: string) => string, nativeData?: (carrier: Representation, text: string) => string) => string;
|
|
6
|
+
export declare const withFieldReceiver: (value: Representation, text: string, emit: (carrier: Representation) => string, dynamic?: (carrier: Representation, text: string) => string, nativeData?: (carrier: Representation, text: string) => string, array?: (carrier: Representation, text: string) => string, dictionary?: (carrier: Representation, text: string) => string) => string;
|
|
7
7
|
/** Bind deferred operands once before either the live route or an ordinary allocation is observed. */
|
|
8
8
|
export declare const nativeFieldViewOperandContext: (ctx: EmitContext, operation: GetOperation | SetOperation) => EmitContext;
|
|
9
9
|
export declare const nativeFieldViewReadForText: (ctx: EmitContext, receiver: IrOperand, target: Representation, receipt: NativeFieldViewRead, ordinaryReadOf: (carrier: Representation, key: string) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { representationKey } from '../../representation/model.js';
|
|
2
|
+
import { canonicalIndexLiteral } from '../../representation/array-index.js';
|
|
2
3
|
import { createCppEmitBlockedError, operandText } from './emit-context.js';
|
|
3
4
|
import { recipeText } from './emit-narrowing.js';
|
|
4
5
|
import { nativeFieldPolicyType, staticKeyOrderText } from './records.js';
|
|
@@ -29,23 +30,29 @@ const renderedLeaf = (ctx, id, text) => {
|
|
|
29
30
|
return rendered;
|
|
30
31
|
};
|
|
31
32
|
/** Carrier wrappers select a native allocation; the route itself is never inferred from its copied fields. */
|
|
32
|
-
export const withFieldReceiver = (value, text, emit, dynamic, nativeData) => {
|
|
33
|
+
export const withFieldReceiver = (value, text, emit, dynamic, nativeData, array, dictionary) => {
|
|
33
34
|
if (value.kind === 'borrowed-ref')
|
|
34
|
-
return withFieldReceiver(value.referent, text, emit, dynamic, nativeData);
|
|
35
|
+
return withFieldReceiver(value.referent, text, emit, dynamic, nativeData, array, dictionary);
|
|
35
36
|
if (value.kind === 'optional')
|
|
36
37
|
return (`if (!${text}.has_value()) gea::host::throwRuntimeError("TypeError", "Cannot access a nullish native view"); ` +
|
|
37
|
-
withFieldReceiver(value.payload, `(*${text})`, emit, dynamic, nativeData));
|
|
38
|
+
withFieldReceiver(value.payload, `(*${text})`, emit, dynamic, nativeData, array, dictionary));
|
|
38
39
|
// A `dynamic` arm is a `gea::Value` already; its own [[Get]] is the read.
|
|
39
40
|
if (value.kind === 'dynamic' && dynamic !== undefined)
|
|
40
41
|
return dynamic(value, text);
|
|
42
|
+
// A `Record<string, any>` arm answers a named key with its own entry.
|
|
43
|
+
if (value.kind === 'dictionary' && dictionary !== undefined)
|
|
44
|
+
return dictionary(value, text);
|
|
41
45
|
// A binary-view arm reads its own internal slot (`nativeData` routes).
|
|
42
46
|
if ((value.kind === 'typed-array' || value.kind === 'data-view' || value.kind === 'array-buffer') && nativeData !== undefined)
|
|
43
47
|
return nativeData(value, text);
|
|
48
|
+
// An Array arm reads its own element (`arrayElement` routes).
|
|
49
|
+
if (value.kind === 'array-object' && array !== undefined)
|
|
50
|
+
return array(value, text);
|
|
44
51
|
if (value.kind === 'tagged-union')
|
|
45
52
|
return (value.arms
|
|
46
53
|
// `text` is a generic lambda's `const auto&` parameter, so its member
|
|
47
54
|
// templates are dependent names.
|
|
48
|
-
.map((arm, index) => `if (${text}.template is<${index}>()) { ${withFieldReceiver(arm.value, `${text}.template get<${index}>()`, emit, dynamic, nativeData)} }`)
|
|
55
|
+
.map((arm, index) => `if (${text}.template is<${index}>()) { ${withFieldReceiver(arm.value, `${text}.template get<${index}>()`, emit, dynamic, nativeData, array, dictionary)} }`)
|
|
49
56
|
.join(' ') + ' gea::host::throwRuntimeError("TypeError", "No native field-view receiver arm");');
|
|
50
57
|
if ((value.kind === 'record' || value.kind === 'record-with-index' || value.kind === 'class-ref' || value.kind === 'native-record-ref') &&
|
|
51
58
|
value.ownership === 'shared-refcount')
|
|
@@ -101,6 +108,29 @@ export const nativeFieldViewReadForText = (ctx, receiver, target, receipt, ordin
|
|
|
101
108
|
? 'gea::host::throwRuntimeError("TypeError", "a binary view arm has no certified native data route");'
|
|
102
109
|
: `return ${renderedLeaf(ctx, route.conversion, read)};`;
|
|
103
110
|
};
|
|
111
|
+
const arrayRead = (key) => (carrier, text) => {
|
|
112
|
+
if (carrier.kind !== 'array-object' || canonicalIndexLiteral(key) === null)
|
|
113
|
+
return 'gea::host::throwRuntimeError("TypeError", "an Array arm has no certified element route");';
|
|
114
|
+
const source = { kind: 'optional', payload: carrier.element, absence: 'undefined' };
|
|
115
|
+
const route = receipt.sources.find((entry) => representationKey(entry.source) === representationKey(source));
|
|
116
|
+
const optional = cppTypeOf(source);
|
|
117
|
+
return route === undefined
|
|
118
|
+
? 'gea::host::throwRuntimeError("TypeError", "an Array arm has no certified element route");'
|
|
119
|
+
: `return ${renderedLeaf(ctx, route.conversion,
|
|
120
|
+
// `readElement`, not `elementAt`: a Document arm's Array may be a live
|
|
121
|
+
// view over a dynamic array, whose cells only its source answers.
|
|
122
|
+
`(${text}->hasElementValue(${key}) ? ${optional}(${text}->readElement(${key})) : ${optional}())`)};`;
|
|
123
|
+
};
|
|
124
|
+
// `gea::Dictionary<gea::Value>::read`'s value-initialized miss IS `undefined`,
|
|
125
|
+
// so the entry read is the whole answer, routed like a `dynamic` arm's.
|
|
126
|
+
const dictionaryRead = (key) => (carrier, text) => {
|
|
127
|
+
const route = carrier.kind === 'dictionary'
|
|
128
|
+
? receipt.sources.find((entry) => representationKey(entry.source) === representationKey(carrier.value))
|
|
129
|
+
: undefined;
|
|
130
|
+
return route === undefined
|
|
131
|
+
? 'gea::host::throwRuntimeError("TypeError", "a dictionary arm has no certified entry route");'
|
|
132
|
+
: `return ${renderedLeaf(ctx, route.conversion, `${text}->read(${cppStringLiteral(key)})`)};`;
|
|
133
|
+
};
|
|
104
134
|
const forKey = (key) => withFieldReceiver(receiver.representation, 'gea_field_input', (carrier) => {
|
|
105
135
|
const actual = ordinaryReadOf(carrier, key);
|
|
106
136
|
const ordinary = actual && receipt.sources.find((entry) => representationKey(entry.source) === representationKey(actual.source));
|
|
@@ -154,7 +184,7 @@ export const nativeFieldViewReadForText = (ctx, receiver, target, receipt, ordin
|
|
|
154
184
|
'gea::host::throwRuntimeError("TypeError", "a native allocation read has no certified carrier route"); ';
|
|
155
185
|
return (`return gea::record::readLiveField<${result}>(gea_field_receiver, ${liveKeyText(key)}, ` +
|
|
156
186
|
`${adapter}, ${accepted}, [&]() -> ${result} { ${getterAnswer ?? `${presentMember}${native}${plain}`} });`);
|
|
157
|
-
}, dynamicRead(key), nativeDataRead(key));
|
|
187
|
+
}, dynamicRead(key), nativeDataRead(key), arrayRead(key), dictionaryRead(key));
|
|
158
188
|
// The receiver is the statement-lambda's ARGUMENT, not a local bound inside
|
|
159
189
|
// it: a withheld receiver can be `(*presentOrThrow(<element read>))`, a
|
|
160
190
|
// reference into a temporary `Optional`. A local `const auto&` outlives that
|
|
@@ -193,6 +223,8 @@ export const nativeFieldViewReadForText = (ctx, receiver, target, receipt, ordin
|
|
|
193
223
|
return route === undefined
|
|
194
224
|
? 'gea::host::throwRuntimeError("TypeError", "Cannot access a non-object native view receiver");'
|
|
195
225
|
: `return ${renderedLeaf(ctx, route.conversion, `${text}.getProperty(gea_field_key)`)};`;
|
|
226
|
+
}, undefined, undefined, () => {
|
|
227
|
+
throw createCppEmitBlockedError('property-access:native-field-view-open-key', 'a dictionary arm has no open-key entry route');
|
|
196
228
|
})
|
|
197
229
|
: 'gea::host::throwRuntimeError("TypeError", "No admitted native field-view key");';
|
|
198
230
|
return (`([&](const auto& gea_field_input) -> ${result} { ` +
|
|
@@ -82,8 +82,12 @@ export const nativeOwnAssignmentText = (ctx, operation) => {
|
|
|
82
82
|
// A described source's run-time key outside its typed fields is a Value
|
|
83
83
|
// already (an expando, a document entry): it is copied as one, through
|
|
84
84
|
// the target's own [[Set]] dispatch.
|
|
85
|
+
// A declared-any table's entry is that Value, read live off the table.
|
|
86
|
+
const unknownValue = source.protocol === 'dictionary-entry'
|
|
87
|
+
? 'gea_assign_source->read(gea_assign_key.text())'
|
|
88
|
+
: 'gea::nativeDynamicGet(gea_assign_source, gea_assign_key)';
|
|
85
89
|
const unknown = source.described === true
|
|
86
|
-
? `if (!gea::nativeDynamicSet(${owner}, gea_assign_key,
|
|
90
|
+
? `if (!gea::nativeDynamicSet(${owner}, gea_assign_key, ${unknownValue})) ` +
|
|
87
91
|
'gea::host::throwRuntimeError("TypeError", "Cannot assign to read only property");'
|
|
88
92
|
: 'gea::host::throwRuntimeError("TypeError", "a closed native copy source acquired an unauthenticated key");';
|
|
89
93
|
const enumeration = source.protocol === 'dictionary-entry'
|
|
@@ -681,7 +681,12 @@ const liveRecordFieldsText = (ctx, plan, live, text) => {
|
|
|
681
681
|
? `${type}{}`
|
|
682
682
|
: undefinedArm >= 0
|
|
683
683
|
? `${type}::ofArm<${undefinedArm}>(gea::Undefined{})`
|
|
684
|
-
:
|
|
684
|
+
: route.read.kind === 'dynamic'
|
|
685
|
+
? // An optional `any` field carries no `Optional` wrapper, but the
|
|
686
|
+
// source may still lack it (net's `signal` on a connect options
|
|
687
|
+
// literal that never named it): absence reads `undefined`.
|
|
688
|
+
'gea::Value{}'
|
|
689
|
+
: null;
|
|
685
690
|
const absence = !read.held.required && absentValue !== null
|
|
686
691
|
? `bool gea_origin_present = false; if (!${actual}->gea_ownFieldPresent(gea_key, gea_origin_present)) ` +
|
|
687
692
|
'gea::host::throwRuntimeError("TypeError", "a live native field has no source presence protocol"); ' +
|
|
@@ -29,20 +29,31 @@ export declare const toNumberText: (text: string, carrier: Representation,
|
|
|
29
29
|
/** ToPrimitive(hint number) of an object carrier, where the caller can call a program method (`classToNumberText`). */
|
|
30
30
|
objectToNumber?: ObjectToNumber) => string | null;
|
|
31
31
|
export type ObjectToNumber = (text: string, carrier: Representation) => string | null;
|
|
32
|
+
/** The conversion that consumes ToPrimitive's answer, applied to a primitive's text and carrier; `type` is its C++ result. */
|
|
33
|
+
export type PrimitiveFinish = {
|
|
34
|
+
readonly convert: (text: string, carrier: Representation) => string | null;
|
|
35
|
+
readonly type: string;
|
|
36
|
+
};
|
|
32
37
|
/**
|
|
33
|
-
* ToPrimitive(hint "number") of a program class instance
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
38
|
+
* ToPrimitive(hint "number") of a program class instance `receiver`, finished
|
|
39
|
+
* by `finish` -- ToNumber and `BigInt(value)` (ECMA-262 21.2.1.1) both start
|
|
40
|
+
* here. Decided at compile time: the class's own direct `valueOf`, answering a
|
|
41
|
+
* primitive, with no `@@toPrimitive` on its chain (the admission rules
|
|
42
|
+
* `classToNumberText` states).
|
|
43
|
+
*
|
|
44
|
+
* A runtime-keyed write may put an own `valueOf` in the instance's expando
|
|
45
|
+
* table (`ClassLayout.dynamicMethodShadows`), and then OrdinaryToPrimitive
|
|
46
|
+
* (7.1.1.1) runs in full on the slow path: the own `valueOf` is called only if
|
|
47
|
+
* it is callable and its answer kept only if it is not an object; otherwise
|
|
48
|
+
* `toString` -- the instance's own expando entry, callable-checked the same
|
|
49
|
+
* way, or the prototype's -- and a TypeError when neither yields a primitive.
|
|
50
|
+
* What the shadow holds and answers is a `gea::Value` because the expando
|
|
51
|
+
* table stores exactly that: a function the program wrote under a computed
|
|
52
|
+
* key has no static type to recover. The prototype path stays native.
|
|
39
53
|
*/
|
|
40
|
-
export declare const
|
|
54
|
+
export declare const classToPrimitiveTextOf: (ctx: EmitContext, carrier: Extract<Representation, {
|
|
41
55
|
kind: "class-ref";
|
|
42
|
-
}
|
|
43
|
-
readonly call: (receiver: string) => string;
|
|
44
|
-
readonly result: Representation;
|
|
45
|
-
} | null;
|
|
56
|
+
}>, receiver: string, finish: PrimitiveFinish) => string | null;
|
|
46
57
|
/**
|
|
47
58
|
* ToNumber of a program class instance: ECMA-262 7.1.4 step 2, ToPrimitive
|
|
48
59
|
* with hint "number" (7.1.1), which for an ordinary object with no
|
|
@@ -101,39 +101,100 @@ objectToNumber) => {
|
|
|
101
101
|
return objectToNumber?.(text, carrier) ?? null;
|
|
102
102
|
};
|
|
103
103
|
const nullableClassReceiver = 'gea_to_number_receiver';
|
|
104
|
+
const isPrimitiveCarrier = (carrier) => carrier.kind === 'scalar' || carrier.kind === 'string' || carrier.kind === 'undefined' || carrier.kind === 'null';
|
|
104
105
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* states). `call` renders the `valueOf` call on a receiver spelling; `result`
|
|
109
|
-
* is the primitive's carrier. Shared by every conversion that starts with
|
|
110
|
-
* ToPrimitive(number) -- ToNumber and `BigInt(value)` (ECMA-262 21.2.1.1).
|
|
106
|
+
* A class's own direct method `key`, called with no arguments, when it is the
|
|
107
|
+
* method [[Get]] finds on every instance (no subclass override, no own slot
|
|
108
|
+
* written over it) and it answers a primitive carrier.
|
|
111
109
|
*/
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
if (direct === null ||
|
|
116
|
-
classMethodOverrideOf(ctx.classes, carrier.declaration, 'valueOf') !== null ||
|
|
117
|
-
classDynamicMethodShadowOf(ctx.classes, carrier.declaration, 'valueOf'))
|
|
110
|
+
const directPrimitiveMethodOf = (ctx, declaration, key) => {
|
|
111
|
+
const direct = ctx.layouts.classDirectMethodFor?.(declaration, key) ?? null;
|
|
112
|
+
if (direct === null || classMethodOverrideOf(ctx.classes, declaration, key) !== null || !isPrimitiveCarrier(direct.result))
|
|
118
113
|
return null;
|
|
114
|
+
// Each declared parameter is default-constructed, which for every carrier
|
|
115
|
+
// `classDirectMethodFor` admits IS the `undefined` a no-argument call binds.
|
|
116
|
+
const absent = direct.absentParameters.map((parameter) => `, ${cppTypeOf(parameter)}{}`).join('');
|
|
117
|
+
return { call: (receiver) => `${cppBodyName(direct.callable)}(${receiver}${absent})`, result: direct.result };
|
|
118
|
+
};
|
|
119
|
+
/** Whether any class on the chain declares a member keyed by the well-known symbol; `null` when a layout is missing. */
|
|
120
|
+
const chainDeclaresWellKnown = (ctx, declaration, symbol) => {
|
|
119
121
|
const seen = new Set();
|
|
120
|
-
for (let current =
|
|
122
|
+
for (let current = declaration; current !== null && !seen.has(current);) {
|
|
121
123
|
seen.add(current);
|
|
122
124
|
const layout = ctx.classes.get(current);
|
|
123
125
|
if (layout === undefined)
|
|
124
126
|
return null;
|
|
125
127
|
const members = [...layout.methods, ...layout.fields, ...layout.accessors];
|
|
126
|
-
if (members.some((member) => layouts.wellKnownSymbolOfKey?.(member.key) ===
|
|
127
|
-
return
|
|
128
|
+
if (members.some((member) => ctx.layouts.wellKnownSymbolOfKey?.(member.key) === symbol))
|
|
129
|
+
return true;
|
|
128
130
|
current = layout.base;
|
|
129
131
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
return false;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* ToPrimitive(hint "number") of a program class instance `receiver`, finished
|
|
136
|
+
* by `finish` -- ToNumber and `BigInt(value)` (ECMA-262 21.2.1.1) both start
|
|
137
|
+
* here. Decided at compile time: the class's own direct `valueOf`, answering a
|
|
138
|
+
* primitive, with no `@@toPrimitive` on its chain (the admission rules
|
|
139
|
+
* `classToNumberText` states).
|
|
140
|
+
*
|
|
141
|
+
* A runtime-keyed write may put an own `valueOf` in the instance's expando
|
|
142
|
+
* table (`ClassLayout.dynamicMethodShadows`), and then OrdinaryToPrimitive
|
|
143
|
+
* (7.1.1.1) runs in full on the slow path: the own `valueOf` is called only if
|
|
144
|
+
* it is callable and its answer kept only if it is not an object; otherwise
|
|
145
|
+
* `toString` -- the instance's own expando entry, callable-checked the same
|
|
146
|
+
* way, or the prototype's -- and a TypeError when neither yields a primitive.
|
|
147
|
+
* What the shadow holds and answers is a `gea::Value` because the expando
|
|
148
|
+
* table stores exactly that: a function the program wrote under a computed
|
|
149
|
+
* key has no static type to recover. The prototype path stays native.
|
|
150
|
+
*/
|
|
151
|
+
export const classToPrimitiveTextOf = (ctx, carrier, receiver, finish) => {
|
|
152
|
+
const valueOf = directPrimitiveMethodOf(ctx, carrier.declaration, 'valueOf');
|
|
153
|
+
if (valueOf === null || chainDeclaresWellKnown(ctx, carrier.declaration, 'toPrimitive') !== false)
|
|
134
154
|
return null;
|
|
135
|
-
|
|
136
|
-
|
|
155
|
+
if (!classDynamicMethodShadowOf(ctx.classes, carrier.declaration, 'valueOf'))
|
|
156
|
+
return finish.convert(valueOf.call(receiver), valueOf.result);
|
|
157
|
+
const self = 'gea_to_primitive_receiver';
|
|
158
|
+
const prototypeAnswer = finish.convert(valueOf.call(self), valueOf.result);
|
|
159
|
+
const dynamicAnswer = finish.convert('gea_primitive', { kind: 'dynamic', reason: 'untyped-callable' });
|
|
160
|
+
const prototypeToString = classPrototypeToStringOf(ctx, carrier, self, finish);
|
|
161
|
+
if (prototypeAnswer === null || dynamicAnswer === null || prototypeToString === null)
|
|
162
|
+
return null;
|
|
163
|
+
// An own entry that is not callable, or whose answer is an object, falls
|
|
164
|
+
// through to the next method name rather than failing.
|
|
165
|
+
const ownStep = (local) => `if (${local}->tag() == gea::Value::Tag::Function) { ` +
|
|
166
|
+
`const gea::Value gea_primitive = ${local}->callWithReceiver(gea::NativeCallReceiver::object(${self}), {}); ` +
|
|
167
|
+
`if (gea_primitive.tag() != gea::Value::Tag::Object && gea_primitive.tag() != gea::Value::Tag::Function) return ${dynamicAnswer}; } `;
|
|
168
|
+
return (`[&](const auto& ${self}) -> ${finish.type} { if (gea::detail::nativeExpandoPresent(${self})) [[unlikely]] { ` +
|
|
169
|
+
`if (const auto gea_own_value_of = gea::detail::nativeExpandoOwnValue(${self}, "valueOf")) { ` +
|
|
170
|
+
ownStep('gea_own_value_of') +
|
|
171
|
+
`if (const auto gea_own_to_string = gea::detail::nativeExpandoOwnValue(${self}, "toString")) { ` +
|
|
172
|
+
ownStep('gea_own_to_string') +
|
|
173
|
+
`} else { ${prototypeToString} } ` +
|
|
174
|
+
`gea::host::throwRuntimeError("TypeError", "Cannot convert object to primitive value"); } } ` +
|
|
175
|
+
`return ${prototypeAnswer}; }(${receiver})`);
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* The `toString` step of OrdinaryToPrimitive reached through the prototype
|
|
179
|
+
* chain, as statements that return a finished answer or fall through when the
|
|
180
|
+
* method's answer is an object. A class with no `toString` anywhere on its
|
|
181
|
+
* chain inherits `Object.prototype.toString`, whose answer for a `class-ref`
|
|
182
|
+
* is "[object Object]" unless `@@toStringTag` changes it (`emit-tostring.ts`
|
|
183
|
+
* states why no other builtin tag can apply); a native base declines, since
|
|
184
|
+
* its own `toString` is the intrinsic's.
|
|
185
|
+
*/
|
|
186
|
+
const classPrototypeToStringOf = (ctx, carrier, self, finish) => {
|
|
187
|
+
if (carrier.nativeBase !== undefined || chainDeclaresWellKnown(ctx, carrier.declaration, 'toStringTag') !== false)
|
|
188
|
+
return null;
|
|
189
|
+
if (!(ctx.layouts.classMethodFor?.(carrier.declaration, 'toString') ?? false)) {
|
|
190
|
+
const answer = finish.convert('std::string("[object Object]")', { kind: 'string' });
|
|
191
|
+
return answer === null ? null : `return ${answer};`;
|
|
192
|
+
}
|
|
193
|
+
const toString = directPrimitiveMethodOf(ctx, carrier.declaration, 'toString');
|
|
194
|
+
if (toString === null)
|
|
195
|
+
return null;
|
|
196
|
+
const answer = finish.convert(toString.call(self), toString.result);
|
|
197
|
+
return answer === null ? null : `return ${answer};`;
|
|
137
198
|
};
|
|
138
199
|
/**
|
|
139
200
|
* ToNumber of a program class instance: ECMA-262 7.1.4 step 2, ToPrimitive
|
|
@@ -159,10 +220,10 @@ export const classToPrimitiveOf = (ctx, carrier) => {
|
|
|
159
220
|
export const classToNumberText = (ctx) => (text, carrier) => {
|
|
160
221
|
if (carrier.kind !== 'class-ref')
|
|
161
222
|
return null;
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
223
|
+
const converted = classToPrimitiveTextOf(ctx, carrier, nullableClassReceiver, {
|
|
224
|
+
convert: (primitive, primitiveCarrier) => toNumberText(primitive, primitiveCarrier),
|
|
225
|
+
type: 'double'
|
|
226
|
+
});
|
|
166
227
|
if (converted === null)
|
|
167
228
|
return null;
|
|
168
229
|
const present = carrier.ownership === 'shared-refcount' ? `static_cast<bool>(${nullableClassReceiver}) ? ` : '';
|
package/dist/targets/cpp/emit.js
CHANGED
|
@@ -1609,6 +1609,9 @@ const emitOperationStatements = (ctx, lines, operation, emitReturn) => {
|
|
|
1609
1609
|
: `gea::commonjs::absentPackage(${cppStringLiteral(operation.absentPackage ?? '')})`};`
|
|
1610
1610
|
: `${defineValue(ctx, operation.result)} = ${cppCommonJsModuleName(operation.target)}();`);
|
|
1611
1611
|
return;
|
|
1612
|
+
case 'module-namespace':
|
|
1613
|
+
lines.push(`${defineValue(ctx, operation.result)} = gea::commonjs::moduleNamespace<&${cppCommonJsModuleName(operation.target)}>(${operandText(ctx, operation.fresh)});`);
|
|
1614
|
+
return;
|
|
1612
1615
|
case 'commonjs-binding':
|
|
1613
1616
|
// Publication forces every unproved wrapper read to `dynamic`; a
|
|
1614
1617
|
// non-dynamic module result is therefore the consumed source proof, not
|
|
@@ -3,7 +3,7 @@ import { isOpenDocument, representationKey } from '../../../representation/model
|
|
|
3
3
|
import { hostMemberTemplateOf, isArrayConstantOf } from '../../../representation/host-templates.js';
|
|
4
4
|
import { createCppEmitBlockedError, internSymbolKey, isFloatStorageValue, operandText, paddedArguments } from '../emit-context.js';
|
|
5
5
|
import { consoleArgumentsText, toStringRefusal, toStringText, toStringTextOver } from '../emit-tostring.js';
|
|
6
|
-
import { classToNumberText,
|
|
6
|
+
import { classToNumberText, classToPrimitiveTextOf, toNumberRefusal, toNumberText } from '../emit-tonumber.js';
|
|
7
7
|
import { booleanTestText } from '../emit-presence.js';
|
|
8
8
|
import { hostArgumentText, hostMemberReceiverText } from './emit-host-arity.js';
|
|
9
9
|
import { fillHostTemplate, hostMemberOf } from './host-members.js';
|
|
@@ -260,7 +260,7 @@ const renderBigInt = ({ ctx, args, role }) => {
|
|
|
260
260
|
* which `gea::host::BigIntConstructor::create`'s overloads are.
|
|
261
261
|
*
|
|
262
262
|
* A program class converts through its own `valueOf` when ToPrimitive is
|
|
263
|
-
* decided statically (`
|
|
263
|
+
* decided statically (`classToPrimitiveTextOf`); a `null`/`undefined` primitive
|
|
264
264
|
* is ToBigInt's TypeError. A tagged union dispatches on the arm it holds, so
|
|
265
265
|
* `BigInt(id)` over `number | bigint | SomeClass` needs no box. `depth`
|
|
266
266
|
* only names the per-arm lambda locals apart.
|
|
@@ -279,10 +279,10 @@ const bigIntText = (ctx, text, carrier, depth) => {
|
|
|
279
279
|
return `([&]() -> gea::BigInt { (void)(${text}); ${failure}; })()`;
|
|
280
280
|
const local = `gea_bigint_source_${depth}`;
|
|
281
281
|
if (carrier.kind === 'class-ref') {
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
282
|
+
const converted = classToPrimitiveTextOf(ctx, carrier, local, {
|
|
283
|
+
convert: (primitive, primitiveCarrier) => bigIntText(ctx, primitive, primitiveCarrier, depth + 1),
|
|
284
|
+
type: 'gea::BigInt'
|
|
285
|
+
});
|
|
286
286
|
if (converted === null)
|
|
287
287
|
return null;
|
|
288
288
|
// A refcounted reference can be the collapsed null of `T | null`.
|
|
@@ -754,11 +754,23 @@ const includesText = (ctx, receiverText, element, args, result, operation) => {
|
|
|
754
754
|
return rangedMethodText('includes', '23.1.3.16', [1, 2], 0)(ctx, receiverText, element, args, result);
|
|
755
755
|
};
|
|
756
756
|
/** The reducers: `reduce(cb)` and `reduce(cb, initialValue)` are two physical arities and two runtime overloads; the no-initial form's empty-array TypeError lives in the runtime. */
|
|
757
|
-
const reduceText = (member, clause) => (ctx, receiverText, _element, args) => {
|
|
757
|
+
const reduceText = (member, clause) => (ctx, receiverText, _element, args, _result, operation) => {
|
|
758
758
|
requireArity(member, clause, [1, 2], args);
|
|
759
759
|
// An integer-spelled Number literal must not let C++ deduce an integer
|
|
760
760
|
// accumulator: JavaScript Number reducers retain fractional results.
|
|
761
761
|
const initial = args[1];
|
|
762
|
+
// The seed in the callback's accumulator carrier, when the two differ
|
|
763
|
+
// (`host-template-conversions.ts` certifies that one conversion).
|
|
764
|
+
const callback = args[0]?.representation;
|
|
765
|
+
const accumulator = callback?.kind === 'function-value-dispatch' && callback.abi.receiver === null ? callback.abi.parameters[0]?.value : undefined;
|
|
766
|
+
if (initial && accumulator && operation && representationKey(accumulator) !== representationKey(initial.representation)) {
|
|
767
|
+
const seeded = operationConversionText(ctx, operation, 'prototype-argument', initial.representation, accumulator, operandText(ctx, initial));
|
|
768
|
+
if (seeded === null) {
|
|
769
|
+
throw createCppEmitBlockedError(`runtime-helper:element:${member}:seed`, `"Array.prototype.${member}" (ECMA-262 ${clause}) seeds a "${representationKey(accumulator)}" accumulator with ` +
|
|
770
|
+
`"${representationKey(initial.representation)}", and no certified conversion carries one into the other`);
|
|
771
|
+
}
|
|
772
|
+
return `gea::runtime::array::${member}(${receiverText}, ${operandText(ctx, args[0])}, ${seeded})`;
|
|
773
|
+
}
|
|
762
774
|
if (initial?.representation.kind === 'scalar' && initial.representation.domain === 'number') {
|
|
763
775
|
return `gea::runtime::array::${member}(${receiverText}, ${operandText(ctx, args[0])}, static_cast<${cppTypeOf(initial.representation)}>(${operandText(ctx, initial)}))`;
|
|
764
776
|
}
|
|
@@ -470,9 +470,9 @@ const valueHeldStructNames = (representation, into, seen, probed = false) => {
|
|
|
470
470
|
const node = representation;
|
|
471
471
|
const ownership = node['ownership'];
|
|
472
472
|
if (typeof ownership === 'string' && ownership !== 'owned') {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
473
|
+
if (probed && ownership === 'shared-refcount')
|
|
474
|
+
for (const element of traceProbedElementsOf(representation))
|
|
475
|
+
valueHeldStructNames(element, into, seen, probed);
|
|
476
476
|
return;
|
|
477
477
|
}
|
|
478
478
|
if (node['abi'] !== undefined) {
|
|
@@ -517,11 +517,19 @@ const valueHeldStructNames = (representation, into, seen, probed = false) => {
|
|
|
517
517
|
for (const value of Object.values(node))
|
|
518
518
|
descend(value);
|
|
519
519
|
};
|
|
520
|
-
/** The
|
|
521
|
-
const
|
|
520
|
+
/** The elements a holder's trace signature instantiates through a `Ref` to this container. */
|
|
521
|
+
const traceProbedElementsOf = (representation) => {
|
|
522
|
+
// `RefTargetIsLeaf` judges a `Ref` to an Array by its element.
|
|
522
523
|
if (representation.kind === 'array-object')
|
|
523
|
-
return representation.recursive === undefined ? representation.element :
|
|
524
|
-
|
|
524
|
+
return representation.recursive === undefined ? [representation.element] : [];
|
|
525
|
+
// `Ref<Map<K, V>>` is judged without its entries, but probing the holder's
|
|
526
|
+
// `geaTraceRefs` looks up the friends of every class among the template
|
|
527
|
+
// arguments, and that instantiates an entry carrier such as
|
|
528
|
+
// `TaggedUnion<double, Record>`, whose inline storage needs `Record`
|
|
529
|
+
// complete (a sort spec's `Map<string, 1 | -1 | { $meta: string }>`).
|
|
530
|
+
if (representation.kind === 'keyed-collection' && representation.recursive === undefined)
|
|
531
|
+
return representation.value ? [representation.key, representation.value] : [representation.key];
|
|
532
|
+
return [];
|
|
525
533
|
};
|
|
526
534
|
/** Every struct one struct's own storage embeds by value -- or, `probed`, every struct its trace signature needs complete. */
|
|
527
535
|
const structValueDependencies = (layout, probed = false) => {
|
|
@@ -104,7 +104,11 @@ export const cppRecursiveContainerDeclarations = (plan, representations = [...pl
|
|
|
104
104
|
...ordered.map(([type, representation]) => {
|
|
105
105
|
const name = cppRecursiveContainerName(type);
|
|
106
106
|
const base = baseTypeOf(representation);
|
|
107
|
-
|
|
107
|
+
// A callable wrapper also converts from its base: a read across the
|
|
108
|
+
// dynamic boundary (`DynamicCarrier<W>`) answers the base callable, and
|
|
109
|
+
// an inherited constructor never covers construction from the base.
|
|
110
|
+
const fromBase = representation.kind === 'function-value-dispatch' ? [` ${name}(const Base& base) : Base(base) {}`] : [];
|
|
111
|
+
return [`struct ${name} final : ${base} {`, ` using Base = ${base};`, ' using Base::Base;', ...fromBase, '};'].join('\n');
|
|
108
112
|
})
|
|
109
113
|
];
|
|
110
114
|
};
|
|
@@ -2282,10 +2282,25 @@ const renderTranslationUnitSession = (input) => {
|
|
|
2282
2282
|
// the session is open and named by address, which needs only its
|
|
2283
2283
|
// declaration: the struct it returns is incomplete where the hook is.
|
|
2284
2284
|
const dynamicArgumentViews = () => (input.programConversionRecipes ?? []).flatMap((recipe) => {
|
|
2285
|
-
if (recipe.role !== 'dynamic-call-argument' || !('shapeId' in recipe.target))
|
|
2285
|
+
if (recipe.role !== 'dynamic-call-argument' || recipe.slot !== '' || !('shapeId' in recipe.target))
|
|
2286
2286
|
return [];
|
|
2287
2287
|
const { role, owner, slot, source, target } = recipe;
|
|
2288
|
-
|
|
2288
|
+
// A view boxed as its original arrives as the original's layout: each
|
|
2289
|
+
// origin the program views as this record reads back through that view.
|
|
2290
|
+
const origins = (input.programConversionRecipes ?? []).flatMap((candidate) => {
|
|
2291
|
+
if (candidate.role !== role || candidate.owner !== owner || !candidate.slot.startsWith('origin:'))
|
|
2292
|
+
return [];
|
|
2293
|
+
const type = cppTypeOf(candidate.source);
|
|
2294
|
+
const unboxed = `gea::detail::unboxValue<${type}>(gea_value, gea::Value::Tag::Object, "a dynamic call argument")`;
|
|
2295
|
+
const viewed = programConversionText(programSite, role, owner, candidate.slot, candidate.source, target, unboxed);
|
|
2296
|
+
if (viewed === null)
|
|
2297
|
+
throw createCppEmitBlockedError('runtime-helper:program-conversion-recipes', `${owner} has no view from ${type}`);
|
|
2298
|
+
return [
|
|
2299
|
+
`if (gea_value.tag() == gea::Value::Tag::Object && gea_value.payloadType() == gea::detail::payloadTypeTagFor<${type}>()) return ${viewed};`
|
|
2300
|
+
];
|
|
2301
|
+
});
|
|
2302
|
+
const exact = programConversionText(programSite, role, owner, slot, source, target, 'gea_value');
|
|
2303
|
+
const load = exact === null ? null : origins.length === 0 ? exact : `([&]() -> ${cppTypeOf(target)} { ${origins.join(' ')} return ${exact}; })()`;
|
|
2289
2304
|
const name = unitFunctionName('gea_dynamic_argument', (named) => `${cppTypeOf(target)} ${named}(const gea::Value& gea_value)`, `return ${load};`);
|
|
2290
2305
|
if (name === null)
|
|
2291
2306
|
throw createCppEmitBlockedError('runtime-helper:program-conversion-recipes', `${owner} has no unit for its argument view`);
|