@geastack/compiler 1.0.65 → 1.0.66
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/ir/host-template-conversions.js +4 -2
- package/dist/ir/object-value-conversions.d.ts +1 -1
- package/dist/ir/object-value-conversions.js +6 -2
- package/dist/targets/cpp/emit-live-field-view.js +13 -8
- package/dist/targets/cpp/host/emit-host-object.js +52 -1
- package/package.json +1 -1
- package/src/targets/cpp/runtime/gea_runtime.h +5 -1
|
@@ -5,6 +5,7 @@ import { declaredRecordFieldOf, nativeBaseFieldOf, recordFieldsOfShape } from '.
|
|
|
5
5
|
import { canonicalIndexLiteral } from '../representation/array-index.js';
|
|
6
6
|
import { isNativeCallableCarrier } from '../representation/callable-object.js';
|
|
7
7
|
import { storedCarrier } from '../representation/primitives.js';
|
|
8
|
+
import { isNativeError } from '../representation/prototype-domains.js';
|
|
8
9
|
import { hostReceiverProtocolOf } from '../representation/host-templates.js';
|
|
9
10
|
import { isCanonicalNumberPropertyKeyText, representationKey } from '../representation/model.js';
|
|
10
11
|
import { hostMemberOf } from '../targets/cpp/host/host-members.js';
|
|
@@ -403,9 +404,10 @@ export const hostObjectWalkPlanOf = (operation, definitionOf, deriver, classes,
|
|
|
403
404
|
const target = source.kind === 'optional' ? source.payload : source;
|
|
404
405
|
const shared = 'ownership' in target && target.ownership === 'shared-refcount';
|
|
405
406
|
const fields = knownFieldsOf(deriver, target);
|
|
407
|
+
const boxed = target.kind === 'dynamic' || isNativeError(target);
|
|
406
408
|
const targets = target.kind === 'dictionary'
|
|
407
409
|
? [target.value]
|
|
408
|
-
:
|
|
410
|
+
: boxed
|
|
409
411
|
? []
|
|
410
412
|
: shared && fields !== null
|
|
411
413
|
? [
|
|
@@ -419,7 +421,7 @@ export const hostObjectWalkPlanOf = (operation, definitionOf, deriver, classes,
|
|
|
419
421
|
for (const operand of operation.arguments.slice(1))
|
|
420
422
|
for (const value of leavesOf(operand.representation))
|
|
421
423
|
if (knownFieldsOf(deriver, value) !== null && 'ownership' in value && value.ownership === 'shared-refcount')
|
|
422
|
-
admit(value,
|
|
424
|
+
admit(value, boxed ? 'assign:dynamic' : `assign:${representationKey(target)}`, targets);
|
|
423
425
|
}
|
|
424
426
|
if (source !== undefined && host.member === 'getOwnPropertyDescriptor') {
|
|
425
427
|
const into = descriptorValueOf(deriver, result);
|
|
@@ -4,7 +4,7 @@ import type { RepresentationDeriver } from '../representation/derive.js';
|
|
|
4
4
|
import { type Representation } from '../representation/model.js';
|
|
5
5
|
import type { IrOperand } from './model.js';
|
|
6
6
|
export interface ObjectValueConversionInput {
|
|
7
|
-
readonly role: 'descriptor-value' | 'callable-property';
|
|
7
|
+
readonly role: 'descriptor-value' | 'callable-property' | 'error-property';
|
|
8
8
|
readonly argument: number;
|
|
9
9
|
readonly field: string;
|
|
10
10
|
readonly source: Representation;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isNativeCallableCarrier } from '../representation/callable-object.js';
|
|
2
|
+
import { isNativeError } from '../representation/prototype-domains.js';
|
|
2
3
|
import { recordFieldsOfShape } from '../projection/fields.js';
|
|
3
4
|
import { representationKey } from '../representation/model.js';
|
|
4
5
|
export const objectValueConversionInputsOf = (intrinsic, args, deriver) => {
|
|
@@ -36,10 +37,13 @@ export const objectValueConversionInputsOf = (intrinsic, args, deriver) => {
|
|
|
36
37
|
];
|
|
37
38
|
}
|
|
38
39
|
const target = args[0]?.representation;
|
|
39
|
-
if (intrinsic !== 'object-assign' || !target
|
|
40
|
+
if (intrinsic !== 'object-assign' || !target)
|
|
41
|
+
return [];
|
|
42
|
+
const role = isNativeCallableCarrier(target.kind) ? 'callable-property' : isNativeError(target) ? 'error-property' : null;
|
|
43
|
+
if (role === null)
|
|
40
44
|
return [];
|
|
41
45
|
return args.slice(1).flatMap((argument, index) => fieldsOf(argument.representation).map((field) => ({
|
|
42
|
-
role
|
|
46
|
+
role,
|
|
43
47
|
argument: index + 1,
|
|
44
48
|
field: field.key,
|
|
45
49
|
source: field.value,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { cppRecordStructName,
|
|
1
|
+
import { cppRecordStructName, cppStringViewLiteral, cppTypeOf } from './types.js';
|
|
2
2
|
import { nativeFieldPolicyType } from './records.js';
|
|
3
3
|
/** Callbacks retain an immediate native source; no accessor runs while the view is allocated. */
|
|
4
4
|
export const liveFieldViewText = (plan, text, accesses) => {
|
|
5
5
|
const readArms = accesses.map((access) => {
|
|
6
6
|
if (access.descriptorForward)
|
|
7
|
-
return `if (
|
|
7
|
+
return `if (gea_name == ${cppStringViewLiteral(access.key)}) return gea::nativeObjectDataReadNative(gea_live_source, gea_key, gea_read);`;
|
|
8
8
|
if (access.read === null)
|
|
9
9
|
throw new Error('a native live field route has no read protocol');
|
|
10
10
|
const type = cppTypeOf(access.read.value);
|
|
@@ -13,7 +13,7 @@ export const liveFieldViewText = (plan, text, accesses) => {
|
|
|
13
13
|
? ''
|
|
14
14
|
: `if (gea_read.accepts<${cppTypeOf(access.declared.value)}, ${nativeFieldPolicyType(access.declared.value)}>()) ` +
|
|
15
15
|
`return gea_read.assign<${nativeFieldPolicyType(access.declared.value)}>(${access.declared.text}); `;
|
|
16
|
-
return (`if (
|
|
16
|
+
return (`if (gea_name == ${cppStringViewLiteral(access.key)}) { ` +
|
|
17
17
|
`if (!gea_read.accepts<${type}, ${policy}>()) ${declared === '' ? 'return false;' : `{ ${declared}return false; }`} ` +
|
|
18
18
|
`return gea_read.assign<${policy}>(${access.read.text}); }`);
|
|
19
19
|
});
|
|
@@ -23,24 +23,29 @@ export const liveFieldViewText = (plan, text, accesses) => {
|
|
|
23
23
|
// source by a write naming its carrier (`nativeLiveViewForwardedWrite`),
|
|
24
24
|
// as its read already answers from the source's expando.
|
|
25
25
|
if (access.write === null && access.descriptorForward && nativeExtensions)
|
|
26
|
-
return `if (
|
|
26
|
+
return `if (gea_name == ${cppStringViewLiteral(access.key)}) return gea::nativeLiveViewForwardedWrite(gea_live_source, gea_key, gea_write);`;
|
|
27
27
|
if (access.write === null)
|
|
28
|
-
return `if (
|
|
28
|
+
return `if (gea_name == ${cppStringViewLiteral(access.key)}) return false;`;
|
|
29
29
|
const type = cppTypeOf(access.write.value);
|
|
30
30
|
const policy = nativeFieldPolicyType(access.write.value);
|
|
31
|
-
return (`if (
|
|
31
|
+
return (`if (gea_name == ${cppStringViewLiteral(access.key)}) { ` +
|
|
32
32
|
`std::optional<${type}> gea_value; if (!gea_write.read<${policy}>(gea_value)) return false; ${access.write.statement} }`);
|
|
33
33
|
});
|
|
34
|
+
// One view of the key for every arm, compared with its length known: a
|
|
35
|
+
// `std::string == "literal"` measures the literal again at each arm, and a
|
|
36
|
+
// method read through a view of a module's function table walks the arms
|
|
37
|
+
// on every call (bson's ByteUtils, once per decoded field).
|
|
38
|
+
const keyName = accesses.length === 0 ? '' : 'const std::string_view gea_name = gea_key.text(); ';
|
|
34
39
|
const sourceType = cppTypeOf(plan.source);
|
|
35
40
|
const source = `const auto gea_live_source = gea_immediate.staticCast<typename ${sourceType}::element_type>();`;
|
|
36
41
|
const ordinaryRead = `return gea::nativeLiveViewSourceRead<${nativeExtensions}>(gea_live_source, gea_key, gea_read);`;
|
|
37
42
|
const ordinaryWrite = 'return gea::nativeLiveViewSourceWrite(gea_live_source, gea_key, gea_write);';
|
|
38
43
|
const read = '+[](const gea::Ref<void>& gea_immediate, const gea::PropertyKey& gea_key, const gea::NativeFieldRead& gea_read) -> bool { ' +
|
|
39
44
|
'if (gea::record::hasLiveFieldView(gea_immediate)) return gea::record::readFieldView(gea_immediate, gea_key, gea_read); ' +
|
|
40
|
-
`${source} if (gea_key.isSymbol()) return false; ${readArms.join(' ')} ${ordinaryRead} }`;
|
|
45
|
+
`${source} if (gea_key.isSymbol()) return false; ${keyName}${readArms.join(' ')} ${ordinaryRead} }`;
|
|
41
46
|
const write = '+[](const gea::Ref<void>& gea_immediate, const gea::PropertyKey& gea_key, const gea::NativeFieldWrite& gea_write) -> bool { ' +
|
|
42
47
|
'if (gea::record::hasLiveFieldView(gea_immediate)) return gea::record::writeFieldView(gea_immediate, gea_key, gea_write); ' +
|
|
43
|
-
`${source} if (gea_key.isSymbol()) return false; ${writeArms.join(' ')} ${ordinaryWrite} }`;
|
|
48
|
+
`${source} if (gea_key.isSymbol()) return false; ${keyName}${writeArms.join(' ')} ${ordinaryWrite} }`;
|
|
44
49
|
const define = '+[](const gea::Ref<void>& gea_immediate, const gea::PropertyKey& gea_key, const gea::PropertyDescriptor& gea_descriptor) -> bool { ' +
|
|
45
50
|
'if (gea::record::hasLiveFieldView(gea_immediate)) return gea::record::defineFieldView(gea_immediate, gea_key, gea_descriptor); ' +
|
|
46
51
|
`${source} return gea::nativeDynamicDefineProperty(gea_live_source, gea_key, gea_descriptor); }`;
|
|
@@ -20,7 +20,7 @@ import { isNativeError } from '../error-types.js';
|
|
|
20
20
|
import { nativeBaseFieldOf, nativeFieldPolicyType, recordFieldsOfShape, recordIndexesOfShape } from '../records.js';
|
|
21
21
|
import { keyOrderUnobservedIn } from '../key-order-tracking.js';
|
|
22
22
|
import { indexedRecordViewOf } from '../../../ir/certify/carrier-keys.js';
|
|
23
|
-
import { cppArrayExtensionStructName, cppBodyName, cppClassName, cppRecordFieldAttributesName, cppRecordFieldName, cppRecordFieldPresenceName, cppRecordStructName, cppStringLiteral, cppTypeOf, cppUndefinedValue, unitFunctionName } from '../types.js';
|
|
23
|
+
import { cppArrayExtensionStructName, cppBodyName, cppClassName, cppRecordFieldAttributesName, cppRecordFieldName, cppRecordFieldPresenceName, cppRecordStructName, cppStringLiteral, cppTypeOf, cppUndefinedValue, fieldPropertyKeyText, unitFunctionName } from '../types.js';
|
|
24
24
|
import { isNativeCallableCarrier, ownershipOfGeneratedCarrier, propertyKeyText as propertyKeyOperandText, stringKeyPreludeText } from '../emit-dynamic-properties.js';
|
|
25
25
|
import { regexpRoleOf } from '../prototype/emit-prototype-regexp.js';
|
|
26
26
|
import { ownPropertySymbolsText } from './emit-host-reflect.js';
|
|
@@ -2185,6 +2185,55 @@ const assignIntoCallableText = (ctx, operation, target) => {
|
|
|
2185
2185
|
return `([&]() { ${body} })()`;
|
|
2186
2186
|
return `([&]() { ${body} return ${targetText}; })()`;
|
|
2187
2187
|
};
|
|
2188
|
+
const assignIntoNativeErrorText = (ctx, operation, target) => {
|
|
2189
|
+
const result = operation.result?.representation;
|
|
2190
|
+
if (result !== undefined && representationKey(result) !== representationKey(target.representation)) {
|
|
2191
|
+
throw createCppEmitBlockedError('host-member-call:Object.assign', `"Object.assign" is typed "T & U" and this call's result carries "${representationKey(result)}", which is not the ` +
|
|
2192
|
+
`native Error target's own "${representationKey(target.representation)}" -- the copy writes into the target and ` +
|
|
2193
|
+
'returns it, so a result carrying anything else is a second answer this renderer may not invent');
|
|
2194
|
+
}
|
|
2195
|
+
const store = (key, value) => `if (!gea::nativeDynamicSet(gea_assign_error, ${key}, ${value})) ` +
|
|
2196
|
+
'gea::host::throwRuntimeError("TypeError", "Cannot assign to read only property");';
|
|
2197
|
+
const copyText = (sourceView, sourceIndex, representation) => {
|
|
2198
|
+
if (sourceView.kind !== 'known')
|
|
2199
|
+
return refuseObjectCarrier('assign', representation, 'the target is a native Error, whose added properties this backend writes one key at a time, and only a source ' +
|
|
2200
|
+
'whose own keys the checker knows is copied into one');
|
|
2201
|
+
const storeText = (field, snapshot = null) => {
|
|
2202
|
+
const value = getOwnValue(ctx, sourceView, field);
|
|
2203
|
+
const boxed = objectValueConversionText(ctx, operation, 'error-property', sourceIndex + 1, field.key, value.representation, value.text);
|
|
2204
|
+
const presence = ownKeyPresenceText('assign', sourceView, field);
|
|
2205
|
+
const enumerable = `${sourceView.receiver}${sourceView.accessor}${cppRecordFieldAttributesName(field.key)}.enumerable`;
|
|
2206
|
+
const condition = [snapshot, presence, enumerable].filter((term) => term !== null).join(' && ');
|
|
2207
|
+
return `if (${condition}) ${store(fieldPropertyKeyText(field.key), boxed)}`;
|
|
2208
|
+
};
|
|
2209
|
+
const fields = assignedKeyFields(ctx, sourceView);
|
|
2210
|
+
const stringStores = fields.filter((field) => !field.key.startsWith('sym(')).map((field) => storeText(field));
|
|
2211
|
+
const symbolFields = fields.filter((field) => field.key.startsWith('sym('));
|
|
2212
|
+
const snapshots = symbolFields.map((field, at) => {
|
|
2213
|
+
const presence = ownKeyPresenceText('assign', sourceView, field);
|
|
2214
|
+
return presence === null ? null : { name: `gea_assign_had_${sourceIndex}_${at}`, presence };
|
|
2215
|
+
});
|
|
2216
|
+
const captured = snapshots.flatMap((snapshot) => (snapshot === null ? [] : [`const bool ${snapshot.name} = ${snapshot.presence};`]));
|
|
2217
|
+
const symbolStores = symbolFields.map((field, at) => storeText(field, snapshots[at]?.name ?? null));
|
|
2218
|
+
const creationOrdered = creationOrderedOwnCopyText(ctx, sourceView, 'assign:dynamic', (key, value) => store(`gea::PropertyKey::string(${key})`, value));
|
|
2219
|
+
const strings = creationOrdered === null ? stringStores.join(' ') : `if (!${creationOrdered}) { ${stringStores.join(' ')} }`;
|
|
2220
|
+
return [...captured, strings, ...symbolStores].join(' ');
|
|
2221
|
+
};
|
|
2222
|
+
const copies = operation.arguments.slice(1).map((source, sourceIndex) => {
|
|
2223
|
+
const representation = source.representation;
|
|
2224
|
+
if (representation.kind === 'null' || representation.kind === 'undefined')
|
|
2225
|
+
return '';
|
|
2226
|
+
if (representation.kind !== 'optional')
|
|
2227
|
+
return copyText(objectViewOf(ctx, 'assign', source, 'source'), sourceIndex, representation);
|
|
2228
|
+
const receiver = operandText(ctx, source);
|
|
2229
|
+
const payload = objectViewFrom(ctx, 'assign', representation.payload, `(*(${receiver}))`, 'source');
|
|
2230
|
+
return `if ((${receiver}).has_value()) { ${copyText(payload, sourceIndex, representation)} }`;
|
|
2231
|
+
});
|
|
2232
|
+
const body = `const auto& gea_assign_error = ${operandText(ctx, target)}; ${copies.join(' ')}`;
|
|
2233
|
+
if (operation.result === null)
|
|
2234
|
+
return `([&]() { ${body} })()`;
|
|
2235
|
+
return `([&]() { ${body} return gea_assign_error; })()`;
|
|
2236
|
+
};
|
|
2188
2237
|
const assignText = (ctx, operation) => {
|
|
2189
2238
|
const native = nativeOwnAssignmentText(ctx, operation);
|
|
2190
2239
|
if (native !== null)
|
|
@@ -2196,6 +2245,8 @@ const assignText = (ctx, operation) => {
|
|
|
2196
2245
|
throw createCppEmitBlockedError('host-member-call:Object.assign', '"Object.assign" takes a source object, and this call passes none');
|
|
2197
2246
|
if (isNativeCallableCarrier(target.representation.kind))
|
|
2198
2247
|
return assignIntoCallableText(ctx, operation, target);
|
|
2248
|
+
if (isNativeError(target.representation))
|
|
2249
|
+
return assignIntoNativeErrorText(ctx, operation, target);
|
|
2199
2250
|
const targetView = objectViewOf(ctx, 'assign', target, 'target');
|
|
2200
2251
|
if (targetView.kind === 'known') {
|
|
2201
2252
|
const result = operation.result?.representation;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/compiler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.66",
|
|
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": {
|
|
@@ -32503,7 +32503,11 @@ bool copyOwnPropertiesInCreationOrder(const gea::Ref<T>& source, Each&& each, bo
|
|
|
32503
32503
|
if constexpr (detail::NativeFieldTable<T>) {
|
|
32504
32504
|
if (source && (always || detail::NativeOwnAccessors<T> || detail::findNativeOwnKeyOrder(source.get()) != nullptr ||
|
|
32505
32505
|
detail::copiesThroughNativeView(source))) {
|
|
32506
|
-
for (const PropertyKey& key :
|
|
32506
|
+
for (const PropertyKey& key : nativeOwnPropertyKeys(source)) {
|
|
32507
|
+
if (key.isSymbol()) continue;
|
|
32508
|
+
const Optional<PropertyDescriptor> descriptor = nativeOwnPropertyDescriptor(source, key);
|
|
32509
|
+
if (descriptor.has_value() && descriptor->enumerable) each(key.text(), nativeDynamicGet(source, key));
|
|
32510
|
+
}
|
|
32507
32511
|
return true;
|
|
32508
32512
|
}
|
|
32509
32513
|
} else {
|