@geastack/compiler 1.0.41 → 1.0.43
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/conversion/nodes.js +5 -2
- package/dist/ir/certify.js +1 -1
- package/dist/ir/facts.d.ts +3 -1
- package/dist/ir/facts.js +1 -0
- package/dist/ir/host-template-conversions.d.ts +2 -2
- package/dist/ir/host-template-conversions.js +73 -2
- package/dist/ir/integers.d.ts +6 -0
- package/dist/ir/integers.js +133 -0
- package/dist/ir/lower-destructuring.js +22 -3
- package/dist/ir/lower-operands.js +24 -0
- 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/projection/dispatch.d.ts +19 -1
- package/dist/projection/dispatch.js +34 -0
- package/dist/representation/value-records.js +182 -13
- 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/source-value-session.d.ts +9 -2
- package/dist/semantics/normalize/flow/source-value-session.js +538 -94
- package/dist/semantics/normalize/local-bindings.js +23 -1
- package/dist/semantics/normalize/producers/allocations.js +5 -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-parts.js +13 -8
- package/dist/semantics/normalize/structural.js +25 -1
- package/dist/targets/cpp/class-properties/emit-class-properties.js +5 -1
- package/dist/targets/cpp/emit-callable.js +19 -10
- package/dist/targets/cpp/emit-context.d.ts +3 -0
- package/dist/targets/cpp/emit-context.js +3 -0
- 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/emit.js +7 -1
- package/dist/targets/cpp/host/emit-host-invoke.js +16 -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.js +39 -16
- package/dist/targets/cpp/translation-unit.js +23 -2
- package/package.json +1 -1
- package/src/targets/cpp/runtime/gea_dynamic_proxy.h +17 -1
- package/src/targets/cpp/runtime/gea_runtime.h +312 -51
|
@@ -166,6 +166,17 @@ namespace gea {
|
|
|
166
166
|
return value;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
/** `float32Product`'s pin for a double product: `Math.hypot` squares and sums
|
|
170
|
+
* in one expression, and Clang's default fuses that pair into one rounding. */
|
|
171
|
+
[[gnu::always_inline]] inline double float64Product(double value) {
|
|
172
|
+
#if defined(__aarch64__)
|
|
173
|
+
__asm__("" : "+w"(value));
|
|
174
|
+
#elif (defined(__x86_64__) || defined(__i386__)) && defined(__SSE2__)
|
|
175
|
+
__asm__("" : "+x"(value));
|
|
176
|
+
#endif
|
|
177
|
+
return value;
|
|
178
|
+
}
|
|
179
|
+
|
|
169
180
|
namespace detail {
|
|
170
181
|
|
|
171
182
|
inline void collectReferenceCycles(bool full);
|
|
@@ -6112,6 +6123,20 @@ template <typename Left, typename Right>
|
|
|
6112
6123
|
return divisor == 0 ? Common{0} : static_cast<Common>(std::fmod(static_cast<Common>(dividend), static_cast<Common>(divisor)));
|
|
6113
6124
|
}
|
|
6114
6125
|
}
|
|
6126
|
+
/**
|
|
6127
|
+
* `integerModulo` for a divisor the compiler proved odd (`oddValuesOf`), so
|
|
6128
|
+
* never zero. The zero test is the one that costs: clang lays a trial-division
|
|
6129
|
+
* loop out around it, 8% slower on Haswell, where the `MIN % -1` test hoists
|
|
6130
|
+
* out as the dividend's and costs nothing -- and -1 is odd, so it stays.
|
|
6131
|
+
*/
|
|
6132
|
+
template <typename Left, typename Right>
|
|
6133
|
+
[[gnu::always_inline]] inline auto integerModuloNonZero(Left dividend, Right divisor) {
|
|
6134
|
+
using Common = std::common_type_t<Left, Right>;
|
|
6135
|
+
static_assert(std::is_integral_v<Common>, "a proved-odd divisor is an integer");
|
|
6136
|
+
if constexpr (std::is_signed_v<Common>)
|
|
6137
|
+
if (static_cast<Common>(dividend) == std::numeric_limits<Common>::min() && divisor == -1) [[unlikely]] return Common{0};
|
|
6138
|
+
return static_cast<Common>(static_cast<Common>(dividend) % static_cast<Common>(divisor));
|
|
6139
|
+
}
|
|
6115
6140
|
/**
|
|
6116
6141
|
* `+ - *` over an `int`/`i32` binding's values, at the annotation's width.
|
|
6117
6142
|
* They wrap, as an `int32_t` lane of a typed array does: computed in the
|
|
@@ -15956,6 +15981,15 @@ struct ArrayObjectElementOf<ArrayObject<Element>> {
|
|
|
15956
15981
|
using type = Element;
|
|
15957
15982
|
};
|
|
15958
15983
|
|
|
15984
|
+
namespace detail {
|
|
15985
|
+
template <typename Element>
|
|
15986
|
+
ArrayObject<Element> arrayObjectBaseProbe(const ArrayObject<Element>&);
|
|
15987
|
+
template <typename T>
|
|
15988
|
+
using ArrayObjectBaseOf = decltype(arrayObjectBaseProbe(std::declval<const T&>()));
|
|
15989
|
+
template <typename T>
|
|
15990
|
+
concept DerivedArrayObject = !IsArrayObjectStruct<T>::value && requires { typename ArrayObjectBaseOf<T>; };
|
|
15991
|
+
}
|
|
15992
|
+
|
|
15959
15993
|
namespace detail {
|
|
15960
15994
|
template <typename T>
|
|
15961
15995
|
struct DynamicCarrier;
|
|
@@ -20222,6 +20256,8 @@ struct Error;
|
|
|
20222
20256
|
namespace host {
|
|
20223
20257
|
inline gea::Ref<gea::runtime::Error> createRuntimeError(const char* kind, const gea::Optional<std::string>& message);
|
|
20224
20258
|
inline bool isRuntimeError(const gea::Value& value);
|
|
20259
|
+
inline gea::Ref<gea::runtime::Error> runtimeErrorOf(const gea::Value& value);
|
|
20260
|
+
inline bool isErrorValue(const gea::Value& value);
|
|
20225
20261
|
inline bool instanceOfRuntimeError(const gea::Value& value, const char* kind);
|
|
20226
20262
|
inline std::string runtimeErrorString(const gea::Value& value);
|
|
20227
20263
|
[[noreturn]] inline void throwRuntimeError(const char* kind, const std::string& message);
|
|
@@ -24434,6 +24470,20 @@ struct DynamicCallableCarrier<Optional<T>> {
|
|
|
24434
24470
|
}
|
|
24435
24471
|
};
|
|
24436
24472
|
|
|
24473
|
+
/**
|
|
24474
|
+
* The compiler's certified live view of a dynamic object as record `T`, for a
|
|
24475
|
+
* record a boxed callable's frame names (`program-conversions.ts`'s
|
|
24476
|
+
* `dynamic-call-argument`). The generated program specializes it for exactly
|
|
24477
|
+
* the records it published that recipe for; every other `T` has none.
|
|
24478
|
+
*/
|
|
24479
|
+
template <typename T>
|
|
24480
|
+
struct DynamicArgumentView {
|
|
24481
|
+
static constexpr bool installed = false;
|
|
24482
|
+
};
|
|
24483
|
+
|
|
24484
|
+
template <typename Element>
|
|
24485
|
+
gea::Ref<ArrayObject<Element>> dynamicArgumentArrayView(const Value& value);
|
|
24486
|
+
|
|
24437
24487
|
template <typename T>
|
|
24438
24488
|
struct DynamicCarrier<gea::Ref<T>> {
|
|
24439
24489
|
static constexpr bool supported = true;
|
|
@@ -24445,6 +24495,19 @@ struct DynamicCarrier<gea::Ref<T>> {
|
|
|
24445
24495
|
}
|
|
24446
24496
|
static gea::Ref<T> in(const Value& value, std::size_t position) {
|
|
24447
24497
|
if (value.tag() == Value::Tag::Undefined) refuseMissingCallArgument(position);
|
|
24498
|
+
// A caller hands the callee its own object, whatever layout the caller
|
|
24499
|
+
// gave it: `pts.map(([r, y]) => ...)` over `number[]` rows, an options
|
|
24500
|
+
// literal into an `o = {}` parameter. Another layout is read through a
|
|
24501
|
+
// live view of that same object, so the callee's writes reach the caller.
|
|
24502
|
+
if (value.tag() == Value::Tag::Object && !accepts(value)) {
|
|
24503
|
+
if constexpr (IsArrayObjectStruct<T>::value) {
|
|
24504
|
+
using Element = typename ArrayObjectElementOf<T>::type;
|
|
24505
|
+
if constexpr (DynamicCarrier<Element>::supported)
|
|
24506
|
+
if (value.isArrayPayload()) return dynamicArgumentArrayView<Element>(value);
|
|
24507
|
+
} else if constexpr (DynamicArgumentView<T>::installed) {
|
|
24508
|
+
return DynamicArgumentView<T>::in(value);
|
|
24509
|
+
}
|
|
24510
|
+
}
|
|
24448
24511
|
return unboxClassRef<T>(value, "a dynamic call argument");
|
|
24449
24512
|
}
|
|
24450
24513
|
};
|
|
@@ -29407,6 +29470,14 @@ using ::gea::checkedNativeArrayView;
|
|
|
29407
29470
|
using ::gea::nativeArrayViewAccepts;
|
|
29408
29471
|
using ::gea::nativeArrayViewAcceptsExact;
|
|
29409
29472
|
using ::gea::nativeArrayViewElementsAccept;
|
|
29473
|
+
|
|
29474
|
+
/** Each element crosses by the frame's own rule for its carrier, in both directions. */
|
|
29475
|
+
template <typename Element>
|
|
29476
|
+
gea::Ref<ArrayObject<Element>> dynamicArgumentArrayView(const Value& value) {
|
|
29477
|
+
return checkedNativeArrayView<Element, NativeFieldLeafPolicy>(
|
|
29478
|
+
value, "a dynamic call argument", [](const Value& entry) -> Element { return DynamicCarrier<Element>::in(entry, 0); },
|
|
29479
|
+
[](const Element& entry) -> Value { return DynamicCarrier<Element>::out(entry); });
|
|
29480
|
+
}
|
|
29410
29481
|
}
|
|
29411
29482
|
|
|
29412
29483
|
/** A descriptor query creates a new ordinary object. Its copied native
|
|
@@ -29817,20 +29888,30 @@ bool nativeDynamicRead(const gea::Ref<T>& object, const PropertyKey& key, Value&
|
|
|
29817
29888
|
}
|
|
29818
29889
|
if (const auto read = record::readDocumentView(Ref<void>(object), key, answer)) return *read;
|
|
29819
29890
|
if (const auto read = record::readNativeViewValue(Ref<void>(object), key, answer)) return *read;
|
|
29891
|
+
// OrdinaryGet continues from every own miss to the prototype, exactly as the
|
|
29892
|
+
// boxed twin `Value::getProperty` does: a class's accessors and methods are
|
|
29893
|
+
// answered by its generated prototype hook, never by instance storage.
|
|
29894
|
+
const auto inherited = [&]() -> bool {
|
|
29895
|
+
if constexpr (requires(const T& reader) { reader.gea_readPrototypeProperty(key, answer); })
|
|
29896
|
+
return object->gea_readPrototypeProperty(key, answer);
|
|
29897
|
+
else
|
|
29898
|
+
return false;
|
|
29899
|
+
};
|
|
29820
29900
|
if constexpr (requires(const T& reader) { reader.gea_readOwnField(key, answer); }) {
|
|
29821
29901
|
if (object->gea_readOwnField(key, answer)) return true;
|
|
29822
29902
|
if constexpr (detail::NativeOwnFieldPredicate<T>) {
|
|
29823
29903
|
// A deleted fixed slot is still the layout's slot. Do not let an index
|
|
29824
29904
|
// sidecar or expando shadow it merely because its presence bit is false.
|
|
29825
|
-
if (object->gea_matchesOwnField(key)) return
|
|
29905
|
+
if (object->gea_matchesOwnField(key)) return inherited();
|
|
29826
29906
|
}
|
|
29827
29907
|
}
|
|
29828
29908
|
if constexpr (requires(const T& reader) { reader.gea_readOwnIndex(key, answer); reader.gea_matchesOwnIndex(key); }) {
|
|
29829
29909
|
if (object->gea_readOwnIndex(key, answer)) return true;
|
|
29830
|
-
if (object->gea_matchesOwnIndex(key)) return
|
|
29910
|
+
if (object->gea_matchesOwnIndex(key)) return inherited();
|
|
29831
29911
|
}
|
|
29832
29912
|
const gea::Ref<DynamicObject> expando = detail::expandoFor(nativePropertyAnchor(object), false);
|
|
29833
|
-
|
|
29913
|
+
if (expando && expando->readWithReceiver(key, [&] { return Value::box(Value::Tag::Object, object); }, answer)) return true;
|
|
29914
|
+
return inherited();
|
|
29834
29915
|
}
|
|
29835
29916
|
|
|
29836
29917
|
// A certified missing property still evaluates its receiver/key and throws on
|
|
@@ -32569,6 +32650,26 @@ bool assignOwnPropertiesUnorderedWith(const gea::Ref<T>& source, const gea::Ref<
|
|
|
32569
32650
|
}
|
|
32570
32651
|
|
|
32571
32652
|
/** Array exotic own enumerable string keys, followed by enumerable expandos. */
|
|
32653
|
+
template <typename Element>
|
|
32654
|
+
std::vector<std::string> arrayOwnEnumerableKeys(const gea::Ref<ArrayObject<Element>>& array);
|
|
32655
|
+
template <typename Element>
|
|
32656
|
+
bool arrayHasOwnEnumerableKey(const gea::Ref<ArrayObject<Element>>& array, const std::string& key);
|
|
32657
|
+
template <typename Element>
|
|
32658
|
+
std::vector<std::string> arrayOwnPropertyNames(const gea::Ref<ArrayObject<Element>>& array);
|
|
32659
|
+
|
|
32660
|
+
template <detail::DerivedArrayObject Array>
|
|
32661
|
+
std::vector<std::string> arrayOwnEnumerableKeys(const gea::Ref<Array>& array) {
|
|
32662
|
+
return arrayOwnEnumerableKeys(gea::Ref<detail::ArrayObjectBaseOf<Array>>(array));
|
|
32663
|
+
}
|
|
32664
|
+
template <detail::DerivedArrayObject Array>
|
|
32665
|
+
bool arrayHasOwnEnumerableKey(const gea::Ref<Array>& array, const std::string& key) {
|
|
32666
|
+
return arrayHasOwnEnumerableKey(gea::Ref<detail::ArrayObjectBaseOf<Array>>(array), key);
|
|
32667
|
+
}
|
|
32668
|
+
template <detail::DerivedArrayObject Array>
|
|
32669
|
+
std::vector<std::string> arrayOwnPropertyNames(const gea::Ref<Array>& array) {
|
|
32670
|
+
return arrayOwnPropertyNames(gea::Ref<detail::ArrayObjectBaseOf<Array>>(array));
|
|
32671
|
+
}
|
|
32672
|
+
|
|
32572
32673
|
template <typename Element>
|
|
32573
32674
|
std::vector<std::string> arrayOwnEnumerableKeys(const gea::Ref<ArrayObject<Element>>& array) {
|
|
32574
32675
|
std::vector<std::string> keys;
|
|
@@ -33951,6 +34052,26 @@ inline bool isShortBasicLatin(const std::string &s) {
|
|
|
33951
34052
|
return size == 0 || (static_cast<unsigned char>(s[0]) & 0x80u) == 0;
|
|
33952
34053
|
}
|
|
33953
34054
|
|
|
34055
|
+
// The UTF-8 walks below take eight ASCII bytes (eight code units) per step
|
|
34056
|
+
// with this. A per-byte walk past a string's first non-ASCII byte made every
|
|
34057
|
+
// `length`/`charAt`/`slice` on a long, mostly-ASCII string -- a shader chunk
|
|
34058
|
+
// with one accented comment -- a full byte loop, and three.js's include
|
|
34059
|
+
// resolver calls them once per character.
|
|
34060
|
+
inline bool isAsciiWord(const unsigned char *bytes) {
|
|
34061
|
+
std::uint64_t word;
|
|
34062
|
+
std::memcpy(&word, bytes, 8);
|
|
34063
|
+
return (word & 0x8080808080808080ull) == 0;
|
|
34064
|
+
}
|
|
34065
|
+
|
|
34066
|
+
/** How many of the first `limit` bytes (at most `s.size()`) lead `s` as ASCII. */
|
|
34067
|
+
inline std::size_t asciiPrefixLength(const std::string &s, std::size_t limit) {
|
|
34068
|
+
const unsigned char *d = reinterpret_cast<const unsigned char *>(s.data());
|
|
34069
|
+
std::size_t i = 0;
|
|
34070
|
+
while (i + 8 <= limit && isAsciiWord(d + i)) i += 8;
|
|
34071
|
+
while (i < limit && !(d[i] & 0x80)) ++i;
|
|
34072
|
+
return i;
|
|
34073
|
+
}
|
|
34074
|
+
|
|
33954
34075
|
inline Utf16Metadata utf16Metadata(const std::string &s) {
|
|
33955
34076
|
// A short name answers from two loads; `OnDemandDocument.isElementName`
|
|
33956
34077
|
// takes the metadata of the name it compares once per element.
|
|
@@ -33975,12 +34096,17 @@ inline Utf16Metadata utf16Metadata(const std::string &s) {
|
|
|
33975
34096
|
std::size_t n = len;
|
|
33976
34097
|
if (!basicLatin) {
|
|
33977
34098
|
n = i; // ASCII prefix: one unit per byte so far
|
|
33978
|
-
|
|
33979
|
-
|
|
33980
|
-
if ((byte & 0xC0) == 0x80) continue;
|
|
34099
|
+
const auto count = [&](unsigned char byte) {
|
|
34100
|
+
if ((byte & 0xC0) == 0x80) return;
|
|
33981
34101
|
if ((byte & 0xF8) == 0xF0) n += 2;
|
|
33982
34102
|
else n += 1;
|
|
34103
|
+
};
|
|
34104
|
+
// Each byte counts on its own, so whole words can be classified at once.
|
|
34105
|
+
for (; i + 8 <= len; i += 8) {
|
|
34106
|
+
if (isAsciiWord(d + i)) n += 8;
|
|
34107
|
+
else for (std::size_t k = 0; k < 8; ++k) count(d[i + k]);
|
|
33983
34108
|
}
|
|
34109
|
+
for (; i < len; ++i) count(d[i]);
|
|
33984
34110
|
}
|
|
33985
34111
|
return {n, basicLatin, {}};
|
|
33986
34112
|
}
|
|
@@ -34024,9 +34150,15 @@ inline std::uint32_t decodeCodePointAt(const std::string &s, std::size_t i, std:
|
|
|
34024
34150
|
/** Map a JavaScript UTF-16 code-unit offset onto this runtime's UTF-8 storage. */
|
|
34025
34151
|
inline std::size_t byteOffsetFromUtf16(const std::string &s, std::size_t target) {
|
|
34026
34152
|
if (isShortBasicLatin(s)) return std::min(target, s.size());
|
|
34153
|
+
const unsigned char *d = reinterpret_cast<const unsigned char *>(s.data());
|
|
34027
34154
|
std::size_t byte = 0;
|
|
34028
34155
|
std::size_t units = 0;
|
|
34029
34156
|
while (byte < s.size() && units < target) {
|
|
34157
|
+
if (units + 8 <= target && byte + 8 <= s.size() && isAsciiWord(d + byte)) {
|
|
34158
|
+
byte += 8;
|
|
34159
|
+
units += 8;
|
|
34160
|
+
continue;
|
|
34161
|
+
}
|
|
34030
34162
|
std::size_t width = 1;
|
|
34031
34163
|
const std::uint32_t codePoint = decodeCodePointAt(s, byte, width);
|
|
34032
34164
|
byte += width;
|
|
@@ -34038,10 +34170,16 @@ inline std::size_t byteOffsetFromUtf16(const std::string &s, std::size_t target)
|
|
|
34038
34170
|
/** Map a matcher byte boundary back to the UTF-16 index ECMAScript exposes. */
|
|
34039
34171
|
inline std::size_t utf16OffsetFromByte(const std::string &s, std::size_t target) {
|
|
34040
34172
|
if (isShortBasicLatin(s)) return std::min(target, s.size());
|
|
34173
|
+
const unsigned char *d = reinterpret_cast<const unsigned char *>(s.data());
|
|
34041
34174
|
std::size_t byte = 0;
|
|
34042
34175
|
std::size_t units = 0;
|
|
34043
34176
|
const std::size_t stop = std::min(target, s.size());
|
|
34044
34177
|
while (byte < stop) {
|
|
34178
|
+
if (byte + 8 <= stop && isAsciiWord(d + byte)) {
|
|
34179
|
+
byte += 8;
|
|
34180
|
+
units += 8;
|
|
34181
|
+
continue;
|
|
34182
|
+
}
|
|
34045
34183
|
std::size_t width = 1;
|
|
34046
34184
|
const std::uint32_t codePoint = decodeCodePointAt(s, byte, width);
|
|
34047
34185
|
byte += width;
|
|
@@ -34149,24 +34287,28 @@ inline std::string substringUtf16(const std::string &s, std::size_t startUnit, s
|
|
|
34149
34287
|
// ASCII fast path: if every byte up to `endUnit` is ASCII, UTF-16 indices
|
|
34150
34288
|
// equal byte indices, so the slice is a plain byte substr -- no
|
|
34151
34289
|
// per-code-point surrogate accounting and no quadratic walk.
|
|
34152
|
-
|
|
34153
|
-
|
|
34154
|
-
|
|
34155
|
-
const std::size_t
|
|
34156
|
-
|
|
34157
|
-
|
|
34158
|
-
if (i == scanLimit) {
|
|
34159
|
-
const std::size_t b0 = startUnit < size ? startUnit : size;
|
|
34160
|
-
const std::size_t b1 = endUnit < size ? endUnit : size;
|
|
34161
|
-
if (b0 >= b1) return std::string();
|
|
34162
|
-
return s.substr(b0, b1 - b0);
|
|
34163
|
-
}
|
|
34290
|
+
const std::size_t scanLimit = endUnit < s.size() ? endUnit : s.size();
|
|
34291
|
+
const std::size_t asciiPrefix = asciiPrefixLength(s, scanLimit);
|
|
34292
|
+
if (asciiPrefix == scanLimit) {
|
|
34293
|
+
const std::size_t b0 = startUnit < s.size() ? startUnit : s.size();
|
|
34294
|
+
if (b0 >= scanLimit) return std::string();
|
|
34295
|
+
return s.substr(b0, scanLimit - b0);
|
|
34164
34296
|
}
|
|
34297
|
+
const unsigned char *d = reinterpret_cast<const unsigned char *>(s.data());
|
|
34165
34298
|
std::string out;
|
|
34166
34299
|
out.reserve((endUnit - startUnit) * 2);
|
|
34167
|
-
|
|
34168
|
-
std::size_t
|
|
34300
|
+
// The prefix just scanned is one unit per byte: resume the walk there.
|
|
34301
|
+
std::size_t unitPosition = asciiPrefix < startUnit ? asciiPrefix : startUnit;
|
|
34302
|
+
std::size_t i = unitPosition;
|
|
34169
34303
|
while (i < s.size() && unitPosition < endUnit) {
|
|
34304
|
+
// An ASCII word is eight units: counted wholly before the range, copied wholly inside it.
|
|
34305
|
+
if (i + 8 <= s.size() && (unitPosition + 8 <= startUnit || (unitPosition >= startUnit && unitPosition + 8 <= endUnit)) &&
|
|
34306
|
+
isAsciiWord(d + i)) {
|
|
34307
|
+
if (unitPosition >= startUnit) out.append(s, i, 8);
|
|
34308
|
+
i += 8;
|
|
34309
|
+
unitPosition += 8;
|
|
34310
|
+
continue;
|
|
34311
|
+
}
|
|
34170
34312
|
unsigned char b = static_cast<unsigned char>(s[i]);
|
|
34171
34313
|
std::size_t length;
|
|
34172
34314
|
bool astral = false;
|
|
@@ -34374,6 +34516,11 @@ inline std::string charAt(const std::string &s, double position) {
|
|
|
34374
34516
|
position = integerPosition(position);
|
|
34375
34517
|
// The first unit of a string whose first byte is ASCII is that byte, without scanning for its UTF-16 length.
|
|
34376
34518
|
if (position == 0.0 && !s.empty() && static_cast<unsigned char>(s[0]) < 0x80) return std::string(1, s[0]);
|
|
34519
|
+
// So is any unit inside the ASCII prefix: a scan to it, not the whole string's length.
|
|
34520
|
+
if (position > 0.0 && position < static_cast<double>(s.size())) {
|
|
34521
|
+
const std::size_t index = static_cast<std::size_t>(position);
|
|
34522
|
+
if (asciiPrefixLength(s, index + 1) > index) return std::string(1, s[index]);
|
|
34523
|
+
}
|
|
34377
34524
|
const std::size_t length = utf16Length(s);
|
|
34378
34525
|
if (!std::isfinite(position) || position < 0.0 || position >= static_cast<double>(length)) return std::string();
|
|
34379
34526
|
const std::size_t index = static_cast<std::size_t>(position);
|
|
@@ -37323,6 +37470,44 @@ struct Pattern {
|
|
|
37323
37470
|
// `test`: 0 unknown, 1 compiled, -1 outside the subset.
|
|
37324
37471
|
mutable signed char simpleState = 0;
|
|
37325
37472
|
mutable std::shared_ptr<const simple::Program> simpleProgram;
|
|
37473
|
+
// The unit every match must open with, for `matchAt`'s search: -1 unknown,
|
|
37474
|
+
// 0 none.
|
|
37475
|
+
mutable int leadingUnitState = -1;
|
|
37476
|
+
|
|
37477
|
+
/**
|
|
37478
|
+
* The ASCII character a match of `compiledSource` must begin with: its
|
|
37479
|
+
* first atom, when that is a plain character no quantifier can skip and no
|
|
37480
|
+
* top-level `|` routes around -- `/#pragma unroll_loop_start\s+…/`. 0 when
|
|
37481
|
+
* the pattern does not pin one.
|
|
37482
|
+
*/
|
|
37483
|
+
int leadingUnit() const {
|
|
37484
|
+
if (leadingUnitState >= 0) return leadingUnitState;
|
|
37485
|
+
leadingUnitState = 0;
|
|
37486
|
+
const std::string &text = compiledSource;
|
|
37487
|
+
if (ignoreCase || unicode || text.empty()) return 0;
|
|
37488
|
+
const unsigned char first = static_cast<unsigned char>(text[0]);
|
|
37489
|
+
if (first == 0 || first >= 0x80 || std::string_view("\\^$.|?*+()[]{}").find(static_cast<char>(first)) != std::string_view::npos) return 0;
|
|
37490
|
+
if (text.size() > 1 && std::string_view("*?{").find(text[1]) != std::string_view::npos) return 0;
|
|
37491
|
+
int depth = 0;
|
|
37492
|
+
bool inClass = false;
|
|
37493
|
+
for (std::size_t i = 0; i < text.size(); ++i) {
|
|
37494
|
+
const char c = text[i];
|
|
37495
|
+
if (c == '\\') {
|
|
37496
|
+
++i;
|
|
37497
|
+
} else if (inClass) {
|
|
37498
|
+
if (c == ']') inClass = false;
|
|
37499
|
+
} else if (c == '[') {
|
|
37500
|
+
inClass = true;
|
|
37501
|
+
} else if (c == '(') {
|
|
37502
|
+
++depth;
|
|
37503
|
+
} else if (c == ')') {
|
|
37504
|
+
--depth;
|
|
37505
|
+
} else if (c == '|' && depth == 0) {
|
|
37506
|
+
return 0;
|
|
37507
|
+
}
|
|
37508
|
+
}
|
|
37509
|
+
return leadingUnitState = first;
|
|
37510
|
+
}
|
|
37326
37511
|
|
|
37327
37512
|
const simple::Program *simplePattern() const {
|
|
37328
37513
|
if (simpleState == 0) {
|
|
@@ -37883,6 +38068,28 @@ struct Pattern {
|
|
|
37883
38068
|
if (stateful) resetLastIndex();
|
|
37884
38069
|
return MatchSlice{};
|
|
37885
38070
|
}
|
|
38071
|
+
// An ASCII literal (`/NUM_DIR_LIGHTS/g`) is a byte search, as in `test`:
|
|
38072
|
+
// no byte of a multi-byte sequence is ASCII, so the bytes match exactly
|
|
38073
|
+
// where the code units do, and a start inside a surrogate pair cannot
|
|
38074
|
+
// begin a match. Transcoding the whole input for `std::regex` on every
|
|
38075
|
+
// match made each `replace` of three.js's shader constants O(n) per match
|
|
38076
|
+
// on top of libc++'s matcher. Sticky stays below: it must not slide off a
|
|
38077
|
+
// half pair.
|
|
38078
|
+
if (!sticky && !unicode && literalPattern() && !literalUtf8.empty() && gea::runtime::string::asciiOnly(literalUtf8)) {
|
|
38079
|
+
const std::size_t from = gea::runtime::string::byteOffsetFromUtf16(input, startPublicUnits);
|
|
38080
|
+
const std::size_t at = input.find(literalUtf8, from);
|
|
38081
|
+
if (at == std::string::npos) {
|
|
38082
|
+
if (stateful) resetLastIndex();
|
|
38083
|
+
return MatchSlice{};
|
|
38084
|
+
}
|
|
38085
|
+
MatchSlice out;
|
|
38086
|
+
out.matched = true;
|
|
38087
|
+
out.position = gea::runtime::string::utf16OffsetFromByte(input, at);
|
|
38088
|
+
out.length = literalUtf8.size();
|
|
38089
|
+
if (stateful) setLastIndexUnits(out.position + out.length);
|
|
38090
|
+
out.captures.push_back(gea::Optional<std::string>(literalUtf8));
|
|
38091
|
+
return out;
|
|
38092
|
+
}
|
|
37886
38093
|
// A caller may write lastIndex into the middle of a surrogate pair. In
|
|
37887
38094
|
// Unicode mode CodePointAt sees the trailing surrogate there as a lone
|
|
37888
38095
|
// code point; preserving this exact boundary keeps sticky/global matching
|
|
@@ -37901,11 +38108,30 @@ struct Pattern {
|
|
|
37901
38108
|
const Utf16Regex &compiled = compiledRegex();
|
|
37902
38109
|
Utf16Match match;
|
|
37903
38110
|
auto searchBegin = inputUnits.cbegin() + static_cast<std::ptrdiff_t>(startUnits);
|
|
37904
|
-
|
|
38111
|
+
bool found = false;
|
|
38112
|
+
if (const int lead = sticky ? 0 : leadingUnit()) {
|
|
38113
|
+
// libc++ allocates and frees its matcher state at every start it tries,
|
|
38114
|
+
// which made one walk over a shader source (`#pragma unroll_loop_start`)
|
|
38115
|
+
// cost milliseconds. A match can only start at `lead`: try only there,
|
|
38116
|
+
// in order, so the first success is still the leftmost match.
|
|
38117
|
+
for (auto at = searchBegin; (at = std::find(at, inputUnits.cend(), static_cast<RegexUnit>(lead))) != inputUnits.cend(); ++at) {
|
|
38118
|
+
const auto flags =
|
|
38119
|
+
searchFlagsFrom(inputUnits, static_cast<std::size_t>(at - inputUnits.cbegin())) | std::regex_constants::match_continuous;
|
|
38120
|
+
if (std::regex_search(at, inputUnits.cend(), match, compiled, flags)) {
|
|
38121
|
+
searchBegin = at;
|
|
38122
|
+
found = true;
|
|
38123
|
+
break;
|
|
38124
|
+
}
|
|
38125
|
+
}
|
|
38126
|
+
} else {
|
|
38127
|
+
found = std::regex_search(searchBegin, inputUnits.cend(), match, compiled, searchFlagsFrom(inputUnits, startUnits));
|
|
38128
|
+
}
|
|
38129
|
+
if (!found) {
|
|
37905
38130
|
if (stateful) resetLastIndex();
|
|
37906
38131
|
return MatchSlice{};
|
|
37907
38132
|
}
|
|
37908
|
-
const std::size_t matchStartUnits =
|
|
38133
|
+
const std::size_t matchStartUnits =
|
|
38134
|
+
static_cast<std::size_t>(searchBegin - inputUnits.cbegin()) + static_cast<std::size_t>(match.position(0));
|
|
37909
38135
|
#endif
|
|
37910
38136
|
if (sticky && matchStartUnits != startUnits) {
|
|
37911
38137
|
resetLastIndex();
|
|
@@ -43051,7 +43277,7 @@ inline std::string typeOf(const gea::Value &value) {
|
|
|
43051
43277
|
// without that dynamic boundary still refuses by name inside `dynamicToString`:
|
|
43052
43278
|
// manufacturing "[object Object]" would bypass a possible native `toString`.
|
|
43053
43279
|
inline std::string toString(const gea::Value &value) {
|
|
43054
|
-
if (gea::host::
|
|
43280
|
+
if (gea::host::isErrorValue(value)) return gea::host::runtimeErrorString(value);
|
|
43055
43281
|
switch (value.tag()) {
|
|
43056
43282
|
case gea::Value::Tag::Undefined:
|
|
43057
43283
|
return toStringUndefined();
|
|
@@ -43310,9 +43536,15 @@ inline double min_invoke(void*, gea::Ref<gea::ArrayObject<double>> values) {
|
|
|
43310
43536
|
* another argument is NaN*; any NaN with no infinity makes it NaN; no
|
|
43311
43537
|
* arguments at all is +0. And squaring before summing overflows to +Infinity
|
|
43312
43538
|
* for magnitudes above ~1.34e154 whose true hypotenuse is finite, and flushes
|
|
43313
|
-
* to +0 below ~1.5e-162. Scaling every term by the largest magnitude first
|
|
43314
|
-
*
|
|
43315
|
-
*
|
|
43539
|
+
* to +0 below ~1.5e-162. Scaling every term by the largest magnitude first
|
|
43540
|
+
* removes both, and is exact on the cases that should be exact (hypot(3, 4)
|
|
43541
|
+
* is 5).
|
|
43542
|
+
*
|
|
43543
|
+
* The sum is V8's: Kahan-compensated, in argument order, then
|
|
43544
|
+
* `sqrt(sum) * largest`, each square rounded on its own. ECMA-262 lets the
|
|
43545
|
+
* result be approximated, so this is for parity with the browser: a plain sum
|
|
43546
|
+
* differs from V8 on about 6% of three-operand calls, and a fused
|
|
43547
|
+
* square-and-add on about 1% of two-operand calls.
|
|
43316
43548
|
*/
|
|
43317
43549
|
inline double hypot_invoke(void*, gea::Ref<gea::ArrayObject<double>> values) {
|
|
43318
43550
|
bool sawNaN = false;
|
|
@@ -43329,13 +43561,17 @@ inline double hypot_invoke(void*, gea::Ref<gea::ArrayObject<double>> values) {
|
|
|
43329
43561
|
}
|
|
43330
43562
|
if (sawNaN) return std::numeric_limits<double>::quiet_NaN();
|
|
43331
43563
|
if (largest == 0.0) return 0.0;
|
|
43332
|
-
double
|
|
43564
|
+
double sum = 0.0;
|
|
43565
|
+
double compensation = 0.0;
|
|
43333
43566
|
for (const auto& slot : values->slots()) {
|
|
43334
43567
|
if (!slot.present) continue;
|
|
43335
|
-
const double scaled = slot.value / largest;
|
|
43336
|
-
|
|
43568
|
+
const double scaled = std::fabs(slot.value) / largest;
|
|
43569
|
+
const double summand = gea::float64Product(scaled * scaled) - compensation;
|
|
43570
|
+
const double preliminary = sum + summand;
|
|
43571
|
+
compensation = (preliminary - sum) - summand;
|
|
43572
|
+
sum = preliminary;
|
|
43337
43573
|
}
|
|
43338
|
-
return
|
|
43574
|
+
return std::sqrt(sum) * largest;
|
|
43339
43575
|
}
|
|
43340
43576
|
|
|
43341
43577
|
// ---------------------------------------------------------------------------
|
|
@@ -43995,7 +44231,7 @@ inline void registerErrorRecordType(const char* name) {
|
|
|
43995
44231
|
*/
|
|
43996
44232
|
inline bool instanceOfError(const gea::Value& value, const char* name) {
|
|
43997
44233
|
if (value.tag() != gea::Value::Tag::Object) return false;
|
|
43998
|
-
if (gea::host::
|
|
44234
|
+
if (gea::host::isErrorValue(value)) return gea::host::instanceOfRuntimeError(value, name);
|
|
43999
44235
|
const auto found = detail::errorPayloadTypes().find(name);
|
|
44000
44236
|
if (found == detail::errorPayloadTypes().end()) return false;
|
|
44001
44237
|
const void* payload = value.payloadType();
|
|
@@ -44815,7 +45051,7 @@ inline void log(const std::string& text) {
|
|
|
44815
45051
|
std::fputc('\n', stdout);
|
|
44816
45052
|
}
|
|
44817
45053
|
|
|
44818
|
-
/** Node routes both `console.warn` and `console.error` to stderr;
|
|
45054
|
+
/** Node routes both `console.warn` and `console.error` to stderr; `warn` below delegates here. */
|
|
44819
45055
|
inline void error(const std::string& text) {
|
|
44820
45056
|
std::fputs(text.c_str(), stderr);
|
|
44821
45057
|
std::fputc('\n', stderr);
|
|
@@ -44941,6 +45177,23 @@ inline void info(const std::vector<gea::Value>& values) { log(values); }
|
|
|
44941
45177
|
|
|
44942
45178
|
inline void info(const gea::Ref<gea::ArrayObject<gea::Value>>& values) { log(values); }
|
|
44943
45179
|
|
|
45180
|
+
/**
|
|
45181
|
+
* `console.warn` -- stderr, byte for byte what `console.error` writes.
|
|
45182
|
+
*
|
|
45183
|
+
* Node's `warn` and `error` (`lib/internal/console/constructor.js`) both write
|
|
45184
|
+
* `kFormatForStderr(args)` to `kUseStderr`; they differ only in which
|
|
45185
|
+
* diagnostics channel they publish to, which this runtime does not have. So
|
|
45186
|
+
* `warn` delegates to `error`, as `info` delegates to `log` above, and restates
|
|
45187
|
+
* the same four overloads for the same reason: the arity shape picks the one.
|
|
45188
|
+
*/
|
|
45189
|
+
inline void warn(const std::string& text) { error(text); }
|
|
45190
|
+
|
|
45191
|
+
inline void warn(const gea::Value& first, const std::vector<gea::Value>& rest) { error(first, rest); }
|
|
45192
|
+
|
|
45193
|
+
inline void warn(const std::vector<gea::Value>& values) { error(values); }
|
|
45194
|
+
|
|
45195
|
+
inline void warn(const gea::Ref<gea::ArrayObject<gea::Value>>& values) { error(values); }
|
|
45196
|
+
|
|
44944
45197
|
} // namespace console
|
|
44945
45198
|
|
|
44946
45199
|
} // namespace gea::host
|
|
@@ -50515,17 +50768,13 @@ inline void gea_json_read(gea::json::Reader& reader, gea::embedded::ui::Signal<T
|
|
|
50515
50768
|
// and `new TextDecoder(label)` for a label this implementation does not
|
|
50516
50769
|
// support (`RangeError`).
|
|
50517
50770
|
//
|
|
50518
|
-
//
|
|
50519
|
-
//
|
|
50520
|
-
//
|
|
50521
|
-
//
|
|
50522
|
-
//
|
|
50523
|
-
//
|
|
50524
|
-
//
|
|
50525
|
-
// TypeError and `detail::refuseOmittedArgument` already do for the same
|
|
50526
|
-
// reason. That is a real difference from ECMAScript -- a `try { atob(x) }
|
|
50527
|
-
// catch {}` cannot recover -- and it is stated here rather than papered over
|
|
50528
|
-
// with a plausible empty string.
|
|
50771
|
+
// `decodeURI`/`decodeURIComponent` throw a catchable `URIError` through
|
|
50772
|
+
// `gea::host::throwRuntimeError`, the runtime-owned Error carrier. `btoa`,
|
|
50773
|
+
// `atob` and the TextDecoder label check still abort BY NAME with the
|
|
50774
|
+
// specification's message: they predate that carrier and have not been moved
|
|
50775
|
+
// onto it, so a `try { atob(x) } catch {}` cannot recover yet. That is a real
|
|
50776
|
+
// difference from ECMAScript, stated here rather than papered over with a
|
|
50777
|
+
// plausible empty string.
|
|
50529
50778
|
// ===========================================================================
|
|
50530
50779
|
|
|
50531
50780
|
namespace gea::runtime::text {
|
|
@@ -50841,11 +51090,7 @@ inline void appendPercentU(std::string& out, std::uint32_t codeUnit) {
|
|
|
50841
51090
|
out.push_back(hexDigit(codeUnit & 0x0F));
|
|
50842
51091
|
}
|
|
50843
51092
|
|
|
50844
|
-
|
|
50845
|
-
[[noreturn]] inline void refuseMalformedUri() {
|
|
50846
|
-
std::fprintf(stderr, "gea: URIError: URI malformed (ECMA-262 19.2.6.5 Decode, step 4.b / 19.2.6.4 Encode, step 4.b)\n");
|
|
50847
|
-
gea::detail::abortAfterFlush();
|
|
50848
|
-
}
|
|
51093
|
+
[[noreturn]] inline void refuseMalformedUri() { gea::host::throwRuntimeError("URIError", "URI malformed"); }
|
|
50849
51094
|
|
|
50850
51095
|
/** v1: `gea::uri::is_unescaped` (uri.cpp). ECMA-262 19.2.6.1.1's `uriUnescaped` = `uriAlpha` + DecimalDigit + `uriMark`. */
|
|
50851
51096
|
inline bool isUnescaped(std::uint32_t codePoint) {
|
|
@@ -51082,15 +51327,19 @@ inline std::string unescapeImpl(const std::string& input) {
|
|
|
51082
51327
|
* than through a second copy.
|
|
51083
51328
|
*/
|
|
51084
51329
|
inline std::string encodeUri(const std::string& value) { return encodeImpl(value, false); }
|
|
51330
|
+
inline std::string encodeUri(const char* value) { return encodeUri(std::string(value)); }
|
|
51085
51331
|
inline std::string encodeUri(double value) { return encodeImpl(gea::host::detail::toString(value), false); }
|
|
51086
51332
|
inline std::string encodeUri(bool value) { return encodeImpl(gea::host::detail::toString(value), false); }
|
|
51087
51333
|
inline std::string encodeUriComponent(const std::string& value) { return encodeImpl(value, true); }
|
|
51334
|
+
inline std::string encodeUriComponent(const char* value) { return encodeUriComponent(std::string(value)); }
|
|
51088
51335
|
inline std::string encodeUriComponent(double value) { return encodeImpl(gea::host::detail::toString(value), true); }
|
|
51089
51336
|
inline std::string encodeUriComponent(bool value) { return encodeImpl(gea::host::detail::toString(value), true); }
|
|
51090
51337
|
inline std::string decodeUri(const std::string& value) { return decodeImpl(value, false); }
|
|
51338
|
+
inline std::string decodeUri(const char* value) { return decodeUri(std::string(value)); }
|
|
51091
51339
|
inline std::string decodeUri(double value) { return decodeImpl(gea::host::detail::toString(value), false); }
|
|
51092
51340
|
inline std::string decodeUri(bool value) { return decodeImpl(gea::host::detail::toString(value), false); }
|
|
51093
51341
|
inline std::string decodeUriComponent(const std::string& value) { return decodeImpl(value, true); }
|
|
51342
|
+
inline std::string decodeUriComponent(const char* value) { return decodeUriComponent(std::string(value)); }
|
|
51094
51343
|
inline std::string decodeUriComponent(double value) { return decodeImpl(gea::host::detail::toString(value), true); }
|
|
51095
51344
|
inline std::string decodeUriComponent(bool value) { return decodeImpl(gea::host::detail::toString(value), true); }
|
|
51096
51345
|
|
|
@@ -51693,11 +51942,23 @@ inline bool isRuntimeError(const gea::Value& value) {
|
|
|
51693
51942
|
return value.tag() == gea::Value::Tag::Object &&
|
|
51694
51943
|
value.payloadType() == gea::detail::payloadTypeTagFor<gea::Ref<gea::runtime::Error>>();
|
|
51695
51944
|
}
|
|
51945
|
+
inline gea::Ref<gea::runtime::Error> runtimeErrorOf(const gea::Value& value) {
|
|
51946
|
+
if (value.tag() != gea::Value::Tag::Object) return {};
|
|
51947
|
+
if (value.payloadType() == gea::detail::payloadTypeTagFor<gea::Ref<gea::runtime::Error>>()) return value.as<gea::Ref<gea::runtime::Error>>();
|
|
51948
|
+
if (value.classObject() && gea::detail::classIdentityExtends(value.classIdentity(), &gea::detail::RefOperationsFor<gea::runtime::Error>::table))
|
|
51949
|
+
return value.classObject().template staticCast<gea::runtime::Error>();
|
|
51950
|
+
return {};
|
|
51951
|
+
}
|
|
51952
|
+
inline bool isErrorValue(const gea::Value& value) { return static_cast<bool>(runtimeErrorOf(value)); }
|
|
51696
51953
|
inline bool instanceOfRuntimeError(const gea::Value& value, const char* kind) {
|
|
51697
|
-
|
|
51954
|
+
const auto error = runtimeErrorOf(value);
|
|
51955
|
+
return error && error->instanceOf(kind);
|
|
51698
51956
|
}
|
|
51699
51957
|
inline std::string runtimeErrorString(const gea::Value& value) {
|
|
51700
|
-
|
|
51958
|
+
const auto error = runtimeErrorOf(value);
|
|
51959
|
+
if (!error) return gea::detail::unboxAs<gea::Ref<gea::runtime::Error>>(value, gea::Value::Tag::Object, "Error ToString")->toString();
|
|
51960
|
+
if (value.classObject() && value.getProperty(gea::PropertyKey::string("toString")).tag() == gea::Value::Tag::Function) return gea::dynamicToString(value);
|
|
51961
|
+
return error->toString();
|
|
51701
51962
|
}
|
|
51702
51963
|
[[noreturn]] inline void throwRuntimeError(const char* kind, const std::string& message) {
|
|
51703
51964
|
#if defined(GEA_RUNTIME_THROW_ENDS_PROGRAM) && GEA_RUNTIME_THROW_ENDS_PROGRAM
|
|
@@ -51722,7 +51983,7 @@ inline const bool uncaughtDescriberInstalled = [] {
|
|
|
51722
51983
|
std::rethrow_exception(current);
|
|
51723
51984
|
} catch (const gea::Value& value) {
|
|
51724
51985
|
try {
|
|
51725
|
-
text = gea::host::
|
|
51986
|
+
text = gea::host::isErrorValue(value) ? gea::host::runtimeErrorString(value) : gea::dynamicToString(value);
|
|
51726
51987
|
} catch (...) {
|
|
51727
51988
|
text = "<a value whose ToString threw>";
|
|
51728
51989
|
}
|