@geastack/compiler 1.0.42 → 1.0.44
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.js +8 -2
- package/dist/conversion/nodes.js +5 -2
- package/dist/ir/callable-class-flow.js +48 -13
- package/dist/ir/certify.js +1 -1
- package/dist/ir/host-template-conversions.d.ts +2 -2
- package/dist/ir/host-template-conversions.js +73 -2
- package/dist/ir/lower-destructuring.js +22 -3
- package/dist/ir/lower-operands.js +30 -1
- package/dist/ir/native-field-view-facts.d.ts +8 -1
- package/dist/ir/native-field-view-facts.js +13 -3
- package/dist/ir/operation-conversions.js +1 -1
- package/dist/ir/program-conversions.d.ts +1 -1
- package/dist/ir/program-conversions.js +68 -1
- package/dist/ir/property-read-conversions.js +7 -1
- package/dist/ir/publish-native-field-view-facts.js +4 -0
- package/dist/ir/reflection-demand.js +29 -3
- package/dist/ir/shake.js +21 -0
- package/dist/projection/dispatch.d.ts +19 -1
- package/dist/projection/dispatch.js +34 -0
- package/dist/representation/value-records.js +182 -13
- package/dist/semantics/frontend.js +18 -14
- package/dist/semantics/normalize/collection-bindings.d.ts +7 -0
- package/dist/semantics/normalize/collection-bindings.js +35 -1
- package/dist/semantics/normalize/derived-expression-type.js +49 -0
- package/dist/semantics/normalize/field-bindings.js +6 -1
- package/dist/semantics/normalize/flow/component-solver.js +37 -2
- package/dist/semantics/normalize/flow/source-value-session.d.ts +12 -2
- package/dist/semantics/normalize/flow/source-value-session.js +861 -212
- package/dist/semantics/normalize/global-host-mutations.js +14 -6
- package/dist/semantics/normalize/implicit-arguments-tuple.d.ts +11 -10
- package/dist/semantics/normalize/implicit-arguments-tuple.js +15 -3
- package/dist/semantics/normalize/local-bindings.js +23 -1
- package/dist/semantics/normalize/producers/references.js +26 -18
- package/dist/semantics/normalize/structural-array-element.d.ts +7 -0
- package/dist/semantics/normalize/structural-array-element.js +24 -1
- package/dist/semantics/normalize/structural-layout-type.js +5 -1
- package/dist/semantics/normalize/structural-mutable-method.js +88 -2
- package/dist/semantics/normalize/structural-parts.js +13 -8
- package/dist/semantics/normalize/structural.js +25 -1
- package/dist/targets/cpp/borrowed-call-entry.d.ts +41 -2
- package/dist/targets/cpp/borrowed-call-entry.js +91 -6
- package/dist/targets/cpp/class-properties/emit-class-properties.js +5 -1
- package/dist/targets/cpp/emit-callable.js +81 -39
- package/dist/targets/cpp/emit-native-field-view.d.ts +2 -0
- package/dist/targets/cpp/emit-native-field-view.js +1 -1
- package/dist/targets/cpp/emit-properties.js +114 -12
- package/dist/targets/cpp/host/emit-host-invoke.js +16 -2
- package/dist/targets/cpp/host/emit-host-object.js +69 -2
- package/dist/targets/cpp/host/host-members.js +4 -0
- package/dist/targets/cpp/prototype/emit-prototype-array.d.ts +42 -0
- package/dist/targets/cpp/prototype/emit-prototype-array.js +31 -9
- package/dist/targets/cpp/records.d.ts +1 -0
- package/dist/targets/cpp/records.js +40 -17
- package/dist/targets/cpp/translation-unit.js +82 -24
- package/dist/targets/cpp/virtual-methods.js +9 -4
- package/package.json +1 -1
- package/src/targets/cpp/runtime/gea_dynamic_proxy.h +17 -1
- package/src/targets/cpp/runtime/gea_runtime.h +485 -64
|
@@ -15,7 +15,7 @@ import { nativePromiseBaseInitializeStatements } from './native-promise-base.js'
|
|
|
15
15
|
import { classFieldStorageOwnerOf, classMemberOf, classMethodOverrideOf } from '../../projection/fields.js';
|
|
16
16
|
import { balanceCppUnits, chunkCppItems, cppChunkFileName, cppUnitByteBudget } from './balanced-units.js';
|
|
17
17
|
import { readonlyBorrowFormalsOf } from '../../ir/borrowed-call-arguments.js';
|
|
18
|
-
import { stableBorrowEntryOf } from './borrowed-call-entry.js';
|
|
18
|
+
import { borrowForwardedArgumentsOf, stableBorrowEntryOf, withoutDyingArguments } from './borrowed-call-entry.js';
|
|
19
19
|
import { programFactsOf } from '../../ir/program-facts.js';
|
|
20
20
|
import { integrityRestrictionsOf } from '../../ir/integrity-restrictions.js';
|
|
21
21
|
import { keyOrderObservationOf, nothingProvenUnobserved } from '../../ir/key-order-observation.js';
|
|
@@ -43,7 +43,7 @@ import { classesConstructedUnobservably, functionsIgnoringTheirReceiver } from '
|
|
|
43
43
|
import { renderJsonStructDeclarations } from './emit-json.js';
|
|
44
44
|
import { programConversionText } from './emit-narrowing.js';
|
|
45
45
|
import { recordLayoutPolicyOf } from '../../projection/fields.js';
|
|
46
|
-
import { cppAbiParameterType, cppAbiType, cppStringLiteral, cppBodyName, cppCallableDeclarationTagName, cppCommonJsModuleName, cppCommonJsRecordName, cppNarrowedIntegerType, cppRefcountedReceiver, cppBoxedType, cppClassName, cppConstructName, cppGlobalName, cppInitializeName, cppRecordFieldName, cppRecordStructName, cppResultTypeOf, cppTypeOf, publishNarrowedStorageSlots, sanitizeForCppIdentifier } from './types.js';
|
|
46
|
+
import { cppAbiParameterType, cppAbiType, cppStringLiteral, cppBodyName, cppCallableDeclarationTagName, cppCommonJsModuleName, cppCommonJsRecordName, cppNarrowedIntegerType, cppRefcountedReceiver, cppBoxedType, cppClassName, cppConstructName, cppGlobalName, cppInitializeName, cppRecordFieldName, cppRecordStructName, cppResultTypeOf, cppTypeOf, publishNarrowedStorageSlots, sanitizeForCppIdentifier, unitFunctionName } from './types.js';
|
|
47
47
|
import { buildHostMethodAliasIndex } from './host/host-method-aliases.js';
|
|
48
48
|
import { constructionOnlyFieldsOf, reflectiveFieldWritesOf } from '../../ir/construction-only-fields.js';
|
|
49
49
|
import { cppRecursiveContainerDeclarations, cppRecursiveContainerTraceEdges } from './recursive-containers.js';
|
|
@@ -752,7 +752,7 @@ const signatureOf = (body, captures, narrowed = new Set(), narrowedResult = fals
|
|
|
752
752
|
const formals = bodyFormalsOf(cppEnvironmentStructOf(captures, body.sourceOwner), effectiveAbi, admission, narrowed, borrowsReceiver(body), borrowed, isCoroutineBody(body));
|
|
753
753
|
return `${result} ${name}(${formals.join(', ')})`;
|
|
754
754
|
};
|
|
755
|
-
const thunkOf = (body, captures, narrowed, narrowedResult, linkage, taskResult = false) => {
|
|
755
|
+
const thunkOf = (body, captures, narrowed, narrowedResult, linkage, taskResult = false, stableEntry = undefined) => {
|
|
756
756
|
if (!body.abi)
|
|
757
757
|
return null;
|
|
758
758
|
const abi = body.abi;
|
|
@@ -783,7 +783,12 @@ const thunkOf = (body, captures, narrowed, narrowedResult, linkage, taskResult =
|
|
|
783
783
|
: admission.kind === 'ok' && admission.layout.receiver !== null
|
|
784
784
|
? [`${cppEnvironmentLocalName}->${cppCaptureReceiverFieldName}`]
|
|
785
785
|
: [];
|
|
786
|
-
|
|
786
|
+
// The thunk's by-value formals are slots of its own frame that nothing else
|
|
787
|
+
// can name, so they are stable actuals for the borrowed entry: entering it
|
|
788
|
+
// directly binds them in place, where the owning entry moved each one into a
|
|
789
|
+
// formal of its own and released the emptied shell on the way out.
|
|
790
|
+
const borrowedEntry = stableEntry !== undefined && !hasEnvironment && !isCoroutineBody(body) ? stableEntry : undefined;
|
|
791
|
+
const call = `${borrowedEntry?.name ?? cppBodyName(body.sourceOwner)}(${[
|
|
787
792
|
...(hasEnvironment ? [isCoroutineBody(body) ? `*${cppEnvironmentLocalName}` : cppEnvironmentLocalName] : []),
|
|
788
793
|
...receiverActual,
|
|
789
794
|
// The thunk's own formals stay the ABI's, so the carrier's function-pointer
|
|
@@ -791,7 +796,9 @@ const thunkOf = (body, captures, narrowed, narrowedResult, linkage, taskResult =
|
|
|
791
796
|
// boundary where the two spellings meet.
|
|
792
797
|
...abi.parameters.map((parameter, ordinal) => narrowed.has(ordinal)
|
|
793
798
|
? `static_cast<${cppNarrowedIntegerType}>(${cppFormalName(ordinal)})`
|
|
794
|
-
:
|
|
799
|
+
: borrowedEntry?.formals.has(ordinal)
|
|
800
|
+
? cppFormalName(ordinal)
|
|
801
|
+
: `std::forward<${cppAbiParameterType(parameter)}>(${cppFormalName(ordinal)})`)
|
|
795
802
|
].join(', ')})`;
|
|
796
803
|
// The thunk's own result stays the ABI's, so the carrier's function-pointer
|
|
797
804
|
// type is unchanged; a narrowed body result converts back here.
|
|
@@ -1938,22 +1945,45 @@ const renderTranslationUnitSession = (input) => {
|
|
|
1938
1945
|
const physicalCounts = new Map();
|
|
1939
1946
|
for (const body of input.bodies)
|
|
1940
1947
|
physicalCounts.set(String(body.sourceOwner), (physicalCounts.get(String(body.sourceOwner)) ?? 0) + 1);
|
|
1948
|
+
const stableEntryOf = (body, dying) => isRegionId(body.sourceOwner) || constructorBodies.has(String(body.sourceOwner))
|
|
1949
|
+
? null
|
|
1950
|
+
: stableBorrowEntryOf(body, body.sourceOwner, (declaration) => {
|
|
1951
|
+
const placement = input.placements.get(declaration);
|
|
1952
|
+
return placement?.storage.kind === 'local' && placement.storage.owner === body.sourceOwner && !captures.isBoxed(declaration)
|
|
1953
|
+
? placement.representation
|
|
1954
|
+
: null;
|
|
1955
|
+
}, formalsBorrowedIn(body.sourceOwner), dying, {
|
|
1956
|
+
captureFree: captures.of(body.sourceOwner).kind === 'none',
|
|
1957
|
+
synchronous: !isCoroutineBody(body),
|
|
1958
|
+
singleBody: physicalCounts.get(String(body.sourceOwner)) === 1,
|
|
1959
|
+
narrowedNumericAbi: formalsNarrowedIn(body.sourceOwner).size > 0 || resultNarrowedIn(body.sourceOwner)
|
|
1960
|
+
});
|
|
1961
|
+
// A formal handed on as the last use of its cell is "dying", and a dying
|
|
1962
|
+
// read keeps its formal owning so the read can move. Into a position the
|
|
1963
|
+
// callee's own borrowed entry takes by reference, nothing moves: the entry
|
|
1964
|
+
// binds the slot in place. So such reads stop counting as dying, which can
|
|
1965
|
+
// admit the caller's formal to its own entry, which can in turn release the
|
|
1966
|
+
// read that forwards IT -- a fixed point, growing until no entry gains a
|
|
1967
|
+
// formal. A chain of setters forwarding one union or handle down to a
|
|
1968
|
+
// read-only leaf then passes it by reference at every level instead of
|
|
1969
|
+
// moving it once per level.
|
|
1970
|
+
let borrowDying = dyingArguments;
|
|
1971
|
+
for (;;) {
|
|
1972
|
+
const entries = new Map();
|
|
1973
|
+
for (const body of input.bodies) {
|
|
1974
|
+
const entry = stableEntryOf(body, borrowDying);
|
|
1975
|
+
if (entry)
|
|
1976
|
+
entries.set(cppBodyName(body.sourceOwner), entry);
|
|
1977
|
+
}
|
|
1978
|
+
const forwarded = borrowForwardedArgumentsOf(input.bodies, entries, dyingArguments);
|
|
1979
|
+
if ([...forwarded].every((value) => !borrowDying.has(value)))
|
|
1980
|
+
break;
|
|
1981
|
+
borrowDying = withoutDyingArguments(dyingArguments, forwarded);
|
|
1982
|
+
}
|
|
1941
1983
|
for (const body of input.bodies) {
|
|
1942
1984
|
if (isRegionId(body.sourceOwner))
|
|
1943
1985
|
continue;
|
|
1944
|
-
const entry =
|
|
1945
|
-
? null
|
|
1946
|
-
: stableBorrowEntryOf(body, body.sourceOwner, (declaration) => {
|
|
1947
|
-
const placement = input.placements.get(declaration);
|
|
1948
|
-
return placement?.storage.kind === 'local' && placement.storage.owner === body.sourceOwner && !captures.isBoxed(declaration)
|
|
1949
|
-
? placement.representation
|
|
1950
|
-
: null;
|
|
1951
|
-
}, formalsBorrowedIn(body.sourceOwner), dyingArguments, {
|
|
1952
|
-
captureFree: captures.of(body.sourceOwner).kind === 'none',
|
|
1953
|
-
synchronous: !isCoroutineBody(body),
|
|
1954
|
-
singleBody: physicalCounts.get(String(body.sourceOwner)) === 1,
|
|
1955
|
-
unchangedNumericAbi: formalsNarrowedIn(body.sourceOwner).size === 0 && !resultNarrowedIn(body.sourceOwner)
|
|
1956
|
-
});
|
|
1986
|
+
const entry = stableEntryOf(body, borrowDying);
|
|
1957
1987
|
if (entry)
|
|
1958
1988
|
stableBorrowEntries.set(cppBodyName(body.sourceOwner), entry);
|
|
1959
1989
|
if (process.env.GEA_BORROW_DEBUG) {
|
|
@@ -1965,7 +1995,7 @@ const renderTranslationUnitSession = (input) => {
|
|
|
1965
1995
|
return placement?.storage.kind === 'local' && placement.storage.owner === body.sourceOwner && !captures.isBoxed(declaration)
|
|
1966
1996
|
? placement.representation
|
|
1967
1997
|
: null;
|
|
1968
|
-
},
|
|
1998
|
+
}, borrowDying).size
|
|
1969
1999
|
: 0;
|
|
1970
2000
|
const flags = [
|
|
1971
2001
|
`entry=${entry ? 'yes' : 'no'}`,
|
|
@@ -1988,13 +2018,18 @@ const renderTranslationUnitSession = (input) => {
|
|
|
1988
2018
|
const signatures = input.bodies.flatMap((body) => {
|
|
1989
2019
|
const original = `${signatureOf(body, captures, formalsNarrowedIn(body.sourceOwner), resultNarrowedIn(body.sourceOwner), formalsBorrowedIn(body.sourceOwner), cppBodyName(body.sourceOwner), taskResultOf(body))};`;
|
|
1990
2020
|
const entry = stableBorrowEntries.get(cppBodyName(body.sourceOwner));
|
|
1991
|
-
return entry === undefined
|
|
2021
|
+
return entry === undefined
|
|
2022
|
+
? [original]
|
|
2023
|
+
: [
|
|
2024
|
+
original,
|
|
2025
|
+
`${signatureOf(body, captures, formalsNarrowedIn(body.sourceOwner), resultNarrowedIn(body.sourceOwner), entry.formals, entry.name)};`
|
|
2026
|
+
];
|
|
1992
2027
|
});
|
|
1993
2028
|
const thunks = new Map();
|
|
1994
2029
|
// The functions whose minted values publish a `[[Construct]]` entry.
|
|
1995
2030
|
const constructEntries = new Set();
|
|
1996
2031
|
for (const body of input.bodies) {
|
|
1997
|
-
const thunk = thunkOf(body, captures, formalsNarrowedIn(body.sourceOwner), resultNarrowedIn(body.sourceOwner), linkage, taskResultOf(body));
|
|
2032
|
+
const thunk = thunkOf(body, captures, formalsNarrowedIn(body.sourceOwner), resultNarrowedIn(body.sourceOwner), linkage, taskResultOf(body), isRegionId(body.sourceOwner) ? undefined : stableBorrowEntries.get(cppBodyName(body.sourceOwner)));
|
|
1998
2033
|
if (thunk)
|
|
1999
2034
|
thunks.set(body, thunk);
|
|
2000
2035
|
if (thunk?.publishesConstruct && !isRegionId(body.sourceOwner))
|
|
@@ -2074,7 +2109,7 @@ const renderTranslationUnitSession = (input) => {
|
|
|
2074
2109
|
// The formals this body's signature takes by reference: their objects
|
|
2075
2110
|
// outlive the call, which `emit.ts`'s stable field reads rely on.
|
|
2076
2111
|
const borrowed = stableEntry?.formals ?? formalsBorrowedIn(body.sourceOwner);
|
|
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,
|
|
2112
|
+
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, borrowDying, 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);
|
|
2078
2113
|
const commonJsScope = [
|
|
2079
2114
|
...coroutineEnvironmentPrologueOf(promiseView ?? body, captures),
|
|
2080
2115
|
...(commonJsOwner === null || commonJsOwner.nativeRecord
|
|
@@ -2098,7 +2133,9 @@ const renderTranslationUnitSession = (input) => {
|
|
|
2098
2133
|
...(stableEntry === undefined
|
|
2099
2134
|
? []
|
|
2100
2135
|
: [
|
|
2101
|
-
|
|
2136
|
+
// The wrapper keeps the declared signature's narrowed integer formals and
|
|
2137
|
+
// result, so it forwards them to the entry without a conversion.
|
|
2138
|
+
plain(`${signatureOf(body, captures, formalsNarrowedIn(body.sourceOwner), resultNarrowedIn(body.sourceOwner), formalsBorrowedIn(body.sourceOwner))} {`),
|
|
2102
2139
|
plain(
|
|
2103
2140
|
// The stable entry's own signature always states `gea_this`
|
|
2104
2141
|
// first when the body has a receiver (`formalsOf` spells it
|
|
@@ -2185,7 +2222,27 @@ const renderTranslationUnitSession = (input) => {
|
|
|
2185
2222
|
const unionAliasMarker = '// gea-union-aliases';
|
|
2186
2223
|
const unitFunctionMarker = '// gea-unit-functions';
|
|
2187
2224
|
const unitFunctionLinkage = perFile ? 'inline ' : '[[maybe_unused]] static ';
|
|
2225
|
+
// A boxed frame's record argument of another layout is read through the
|
|
2226
|
+
// certified live view (`dynamic-call-argument`, gea_runtime.h's
|
|
2227
|
+
// `DynamicArgumentView`). Each reader is a unit function, recorded while
|
|
2228
|
+
// the session is open and named by address, which needs only its
|
|
2229
|
+
// declaration: the struct it returns is incomplete where the hook is.
|
|
2230
|
+
const dynamicArgumentViews = () => (input.programConversionRecipes ?? []).flatMap((recipe) => {
|
|
2231
|
+
if (recipe.role !== 'dynamic-call-argument' || !('shapeId' in recipe.target))
|
|
2232
|
+
return [];
|
|
2233
|
+
const { role, owner, slot, source, target } = recipe;
|
|
2234
|
+
const load = programConversionText(programSite, role, owner, slot, source, target, 'gea_value');
|
|
2235
|
+
const name = unitFunctionName('gea_dynamic_argument', (named) => `${cppTypeOf(target)} ${named}(const gea::Value& gea_value)`, `return ${load};`);
|
|
2236
|
+
if (name === null)
|
|
2237
|
+
throw createCppEmitBlockedError('runtime-helper:program-conversion-recipes', `${owner} has no unit for its argument view`);
|
|
2238
|
+
const qualifier = isolate && namespaceName !== null ? `${namespaceName}::` : '';
|
|
2239
|
+
const struct = `${qualifier}${cppRecordStructName(target.shapeId)}`;
|
|
2240
|
+
return [
|
|
2241
|
+
`template <> struct DynamicArgumentView<${struct}> { static constexpr bool installed = true; static constexpr auto in = &${qualifier}${name}; };`
|
|
2242
|
+
];
|
|
2243
|
+
});
|
|
2188
2244
|
const spliceUnionAliases = (source) => {
|
|
2245
|
+
const argumentViews = dynamicArgumentViews();
|
|
2189
2246
|
const { aliases, functions } = endUnionAliasing();
|
|
2190
2247
|
const forwards = [...recursiveContainers, ...structs.declarations, ...jsonStructs.declarations].filter((declaration) => declaration.startsWith('struct ') && declaration.endsWith(';') && !declaration.includes('{'));
|
|
2191
2248
|
// Spelled after the alias session ends, so each is its full type.
|
|
@@ -2194,12 +2251,13 @@ const renderTranslationUnitSession = (input) => {
|
|
|
2194
2251
|
...forwards,
|
|
2195
2252
|
...aliases.map(({ name, spelling }) => `using ${name} = ${spelling};`),
|
|
2196
2253
|
...functions.map(({ signature }) => `${unitFunctionLinkage}${signature};`),
|
|
2197
|
-
...(omitted.length === 0
|
|
2254
|
+
...(omitted.length === 0 && argumentViews.length === 0
|
|
2198
2255
|
? []
|
|
2199
2256
|
: [
|
|
2200
2257
|
...(isolate ? [namespaceClose] : []),
|
|
2201
2258
|
'namespace gea::detail {',
|
|
2202
2259
|
...omitted.map((type) => `template <> inline constexpr bool dynamicProtocolOmitted<${type}> = true;`),
|
|
2260
|
+
...argumentViews,
|
|
2203
2261
|
'} // namespace gea::detail',
|
|
2204
2262
|
...(isolate ? [namespaceOpen] : [])
|
|
2205
2263
|
])
|
|
@@ -5,7 +5,7 @@ import { prototypeSetterValue, virtualConversionOwnerOf } from '../../ir/program
|
|
|
5
5
|
import { extendsClass, virtualDispatchKey, virtualMethodFamiliesOf } from '../../projection/dispatch.js';
|
|
6
6
|
export { extendsClass, virtualDispatchKey, virtualMethodFamiliesOf };
|
|
7
7
|
import { cppFormalName } from './emit-context.js';
|
|
8
|
-
import { nativeFieldPolicyType, wellKnownSymbolEnumNameOf } from './records.js';
|
|
8
|
+
import { nativeFieldPolicyType, switchedByKeyLength, wellKnownSymbolEnumNameOf } from './records.js';
|
|
9
9
|
import { cppAbiParameterType, cppBodyName, cppCallableDeclarationTagName, cppClassName, cppRecordFieldKeyIsSymbol, cppRecordFieldName, cppResultTypeOf, cppStringLiteral, cppTypeOf, cppUndefinedIn } from './types.js';
|
|
10
10
|
import { programConversionText, dynamicCarrierBoxText } from './emit-narrowing.js';
|
|
11
11
|
/**
|
|
@@ -515,7 +515,7 @@ export const prototypeReadHooks = (classes, abiOf, capturesNothing, readDynamica
|
|
|
515
515
|
: [
|
|
516
516
|
`(!gea_key.isSymbol() && (${keys
|
|
517
517
|
.filter((key) => !cppRecordFieldKeyIsSymbol(key))
|
|
518
|
-
.map((key) => `gea_key.text() == ${cppStringLiteral(key)}`)
|
|
518
|
+
.map((key) => `std::string_view{gea_key.text()} == ${cppStringLiteral(key)}`)
|
|
519
519
|
.join(' || ')}))`
|
|
520
520
|
]),
|
|
521
521
|
...(keys?.some(cppRecordFieldKeyIsSymbol)
|
|
@@ -531,8 +531,13 @@ export const prototypeReadHooks = (classes, abiOf, capturesNothing, readDynamica
|
|
|
531
531
|
? []
|
|
532
532
|
: [
|
|
533
533
|
' if (!gea_key.isSymbol()) {',
|
|
534
|
-
|
|
535
|
-
|
|
534
|
+
// A `string_view` under a switch on the length, as the
|
|
535
|
+
// record field dispatchers do (`switchedByKeyLength`): a
|
|
536
|
+
// class with seventy methods answered a read of a name it
|
|
537
|
+
// does not have -- an optional member probed on an object
|
|
538
|
+
// of a sibling class -- with seventy `strlen`+`memcmp`s.
|
|
539
|
+
' const std::string_view gea_name = gea_key.text();',
|
|
540
|
+
...switchedByKeyLength(texts.map((getter) => ` if (gea_name == ${cppStringLiteral(getter.key)}) { gea_out = ${getter.text}; return true; }`)),
|
|
536
541
|
' }'
|
|
537
542
|
]),
|
|
538
543
|
...(symbols.length === 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/compiler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.44",
|
|
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": {
|
|
@@ -361,7 +361,7 @@ inline Value dynamicStringPrototypeGet(const PropertyKey& key) {
|
|
|
361
361
|
static const std::map<std::string, Value> methods = [] {
|
|
362
362
|
std::map<std::string, Value> result;
|
|
363
363
|
for (const char* name : {"toLowerCase", "toUpperCase", "toLocaleLowerCase", "toLocaleUpperCase", "trim", "trimStart", "trimEnd",
|
|
364
|
-
"toString", "valueOf", "includes", "startsWith", "endsWith", "indexOf", "slice", "charAt"}) {
|
|
364
|
+
"toString", "valueOf", "includes", "startsWith", "endsWith", "indexOf", "slice", "charAt", "replace"}) {
|
|
365
365
|
auto callable = Method(+[](void* environment, Value receiver, Args args) -> Value {
|
|
366
366
|
alignas(void*) unsigned char slot[sizeof(void*)];
|
|
367
367
|
const std::string& method = *gea::unpackEnvironment<std::string>(environment, slot);
|
|
@@ -384,6 +384,22 @@ inline Value dynamicStringPrototypeGet(const PropertyKey& key) {
|
|
|
384
384
|
if (method == "toString" || method == "valueOf") return string(text);
|
|
385
385
|
if (method == "slice") return string(runtime::string::slice(text, position(first, 0.0), position(second, std::numeric_limits<double>::infinity())));
|
|
386
386
|
if (method == "charAt") return string(runtime::string::charAt(text, position(first, 0.0)));
|
|
387
|
+
if (method == "replace") {
|
|
388
|
+
// ECMA-262 22.1.3.19: a RegExp searchValue replaces through its own
|
|
389
|
+
// @@replace, the walk the typed path renders as `replaceByPattern`;
|
|
390
|
+
// any other searchValue and replaceValue are ToString'd, in that
|
|
391
|
+
// order, into the typed path's string/string `replace`. A callable
|
|
392
|
+
// replaceValue has no boxed-callback arm in either native replace,
|
|
393
|
+
// so it is refused by name rather than ToString'd into a wrong answer.
|
|
394
|
+
if (second.tag() == Value::Tag::Function)
|
|
395
|
+
host::throwRuntimeError("TypeError", "String.prototype.replace through a dynamic receiver does not take a callable replaceValue");
|
|
396
|
+
if (host::instanceOfRegExp(first)) {
|
|
397
|
+
const auto& pattern = detail::unboxAs<Ref<runtime::regex::Pattern>>(first, Value::Tag::Object, "String.prototype.replace's RegExp searchValue");
|
|
398
|
+
return string(runtime::string::replaceByPattern(text, *pattern, dynamicToString(second)));
|
|
399
|
+
}
|
|
400
|
+
const std::string searchValue = dynamicToString(first);
|
|
401
|
+
return string(runtime::string::replace(text, searchValue, dynamicToString(second)));
|
|
402
|
+
}
|
|
387
403
|
const std::string needle = dynamicToString(first);
|
|
388
404
|
if (method == "indexOf") return Value::box(Value::Tag::Number, runtime::string::indexOf(text, needle, position(second, 0.0)));
|
|
389
405
|
if (method == "includes") return Value::box(Value::Tag::Boolean, runtime::string::includes(text, needle, position(second, 0.0)));
|