@lucent-lang/lucent 0.0.4

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.
Files changed (125) hide show
  1. package/app.plugin.js +92 -0
  2. package/bin/lucent.cjs +16 -0
  3. package/core/index.cjs +11 -0
  4. package/dist/bench-CR3E7e2e.js +304 -0
  5. package/dist/build-CAIrRSYA.js +7 -0
  6. package/dist/build-check-QozuNJm5.js +92 -0
  7. package/dist/check-1SCmYlqA.js +7 -0
  8. package/dist/clean-BVwpbJ5K.js +35 -0
  9. package/dist/cli.js +406 -0
  10. package/dist/codes-CIuwXt1S.js +260 -0
  11. package/dist/compiler.js +4 -0
  12. package/dist/confirm-BYF5eY3q.js +34 -0
  13. package/dist/dashboard-B-NzjjaN.js +91 -0
  14. package/dist/dev-BYWMP7oC.js +221 -0
  15. package/dist/diagnostic-BM9sXmwl.js +30 -0
  16. package/dist/diff-BTDo3Sro.js +44 -0
  17. package/dist/doctor-C0PrfWT6.js +230 -0
  18. package/dist/doctor-DdR4JnVc.js +30 -0
  19. package/dist/explain--vV1oaRl.js +35 -0
  20. package/dist/format-D9fnIMEx.js +53 -0
  21. package/dist/init-gIabu1S_.js +207 -0
  22. package/dist/live-steps-BGcWFM9M.js +79 -0
  23. package/dist/new-module-C2mtb0op.js +66 -0
  24. package/dist/package-manager-BnxwCySi.js +30 -0
  25. package/dist/package.json +3 -0
  26. package/dist/packages-HyskKIsY.js +150 -0
  27. package/dist/pipeline-CH7-2cxu.js +232 -0
  28. package/dist/project-D8tEet0k.js +150 -0
  29. package/dist/sdk-coverage-BoW_3Efd.js +64 -0
  30. package/dist/sdk-prefetch-mo04JDZV.js +89 -0
  31. package/dist/sdk-search-Iv4K3-8a.js +124 -0
  32. package/dist/sdk-show-CkrdlqlP.js +74 -0
  33. package/dist/sdks-Xoyiy2E4.js +28 -0
  34. package/dist/src-BD7f1_aZ.js +11493 -0
  35. package/dist/steps--_h-FFS7.js +24 -0
  36. package/dist/theme-uv5bc0aK.js +134 -0
  37. package/dist/tsconfig-S4uyLNzf.js +59 -0
  38. package/dist/version-bqpIO5sP.js +26 -0
  39. package/gradle/lucent-classpath.gradle +38 -0
  40. package/gradle/lucent-classpath.init.gradle +6 -0
  41. package/gradle/lucent.gradle +24 -0
  42. package/lib/core.cjs +106 -0
  43. package/lib/globals.d.ts +36 -0
  44. package/lib/sdk/android.d.ts +8 -0
  45. package/lib/sdk/core.d.ts +23 -0
  46. package/lib/sdk/ios.d.ts +33 -0
  47. package/lib/sdk/platform.d.ts +8 -0
  48. package/lib/sdk/thread.d.ts +8 -0
  49. package/metro/index.cjs +72 -0
  50. package/metro/index.d.ts +6 -0
  51. package/metro/transformer.cjs +70 -0
  52. package/package.json +61 -0
  53. package/runtime/cpp/lucent/abort.cpp +61 -0
  54. package/runtime/cpp/lucent/abort.h +54 -0
  55. package/runtime/cpp/lucent/array.h +442 -0
  56. package/runtime/cpp/lucent/async.h +236 -0
  57. package/runtime/cpp/lucent/builtins.cpp +163 -0
  58. package/runtime/cpp/lucent/bytes.h +129 -0
  59. package/runtime/cpp/lucent/console.h +17 -0
  60. package/runtime/cpp/lucent/core.h +129 -0
  61. package/runtime/cpp/lucent/date.cpp +441 -0
  62. package/runtime/cpp/lucent/date.h +82 -0
  63. package/runtime/cpp/lucent/equality.h +87 -0
  64. package/runtime/cpp/lucent/function.h +61 -0
  65. package/runtime/cpp/lucent/generator.h +244 -0
  66. package/runtime/cpp/lucent/helpers.h +226 -0
  67. package/runtime/cpp/lucent/jserror.cpp +51 -0
  68. package/runtime/cpp/lucent/jserror.h +66 -0
  69. package/runtime/cpp/lucent/jsi/convert.cpp +202 -0
  70. package/runtime/cpp/lucent/jsi/convert.h +612 -0
  71. package/runtime/cpp/lucent/jsi/host.cpp +322 -0
  72. package/runtime/cpp/lucent/jsi/host.h +166 -0
  73. package/runtime/cpp/lucent/json.cpp +243 -0
  74. package/runtime/cpp/lucent/json.h +164 -0
  75. package/runtime/cpp/lucent/json_parse.h +138 -0
  76. package/runtime/cpp/lucent/jsstring.cpp +874 -0
  77. package/runtime/cpp/lucent/jsstring.h +152 -0
  78. package/runtime/cpp/lucent/lucent.h +24 -0
  79. package/runtime/cpp/lucent/map.h +344 -0
  80. package/runtime/cpp/lucent/native.cpp +76 -0
  81. package/runtime/cpp/lucent/native.h +116 -0
  82. package/runtime/cpp/lucent/number.cpp +545 -0
  83. package/runtime/cpp/lucent/number.h +190 -0
  84. package/runtime/cpp/lucent/ops.h +165 -0
  85. package/runtime/cpp/lucent/platform/android.cpp +437 -0
  86. package/runtime/cpp/lucent/platform/android.h +117 -0
  87. package/runtime/cpp/lucent/platform/ios.h +297 -0
  88. package/runtime/cpp/lucent/platform/ios.mm +31 -0
  89. package/runtime/cpp/lucent/regexp.cpp +440 -0
  90. package/runtime/cpp/lucent/regexp.h +107 -0
  91. package/runtime/cpp/lucent/scheduler.cpp +153 -0
  92. package/runtime/cpp/lucent/scheduler.h +160 -0
  93. package/runtime/cpp/lucent/unicode_data.inc +4051 -0
  94. package/runtime/cpp/rn/LucentModule.cpp +35 -0
  95. package/runtime/cpp/rn/LucentModule.h +37 -0
  96. package/runtime/cpp/third_party/quickjs/LICENSE +22 -0
  97. package/runtime/cpp/third_party/quickjs/README.md +11 -0
  98. package/runtime/cpp/third_party/quickjs/cutils.c +641 -0
  99. package/runtime/cpp/third_party/quickjs/cutils.h +457 -0
  100. package/runtime/cpp/third_party/quickjs/libregexp-opcode.h +73 -0
  101. package/runtime/cpp/third_party/quickjs/libregexp.c +3448 -0
  102. package/runtime/cpp/third_party/quickjs/libregexp.h +65 -0
  103. package/runtime/cpp/third_party/quickjs/libunicode-table.h +5206 -0
  104. package/runtime/cpp/third_party/quickjs/libunicode.c +2124 -0
  105. package/runtime/cpp/third_party/quickjs/libunicode.h +196 -0
  106. package/runtime/js/index.d.ts +7 -0
  107. package/runtime/js/index.js +60 -0
  108. package/runtime/native/LucentNative.podspec +28 -0
  109. package/runtime/native/android/CMakeLists.txt +51 -0
  110. package/runtime/native/android/build.gradle +22 -0
  111. package/runtime/native/android/include/lucentnative.h +16 -0
  112. package/runtime/native/android/src/main/java/dev/lucent/LucentPackage.java +25 -0
  113. package/runtime/native/android/src/main/java/dev/lucent/NativeProxy.java +132 -0
  114. package/runtime/native/ios/LucentRegistration.mm +23 -0
  115. package/runtime/native/package.json +6 -0
  116. package/runtime/native/react-native.config.js +19 -0
  117. package/runtime/test/jsi/harness.cpp +181 -0
  118. package/schemas/build.schema.json +152 -0
  119. package/schemas/check.schema.json +74 -0
  120. package/schemas/doctor.schema.json +40 -0
  121. package/schemas/lucent.schema.json +43 -0
  122. package/schemas/sdk-prefetch.schema.json +37 -0
  123. package/schemas/sdk-search.schema.json +54 -0
  124. package/ts-plugin/index.d.ts +4 -0
  125. package/ts-plugin/index.js +99 -0
@@ -0,0 +1,190 @@
1
+ // Lucent runtime — ECMAScript number semantics.
2
+ #pragma once
3
+
4
+ #include <charconv>
5
+ #include <cmath>
6
+ #include <cstdint>
7
+ #include <limits>
8
+ #include <type_traits>
9
+
10
+ #include "jsstring.h"
11
+
12
+ namespace lucent {
13
+
14
+ inline constexpr double kNaN = std::numeric_limits<double>::quiet_NaN();
15
+ inline constexpr double kInfinity = std::numeric_limits<double>::infinity();
16
+
17
+ /// ECMAScript ToInt32.
18
+ inline int32_t toInt32(double v) {
19
+ if (v >= -2147483648.0 && v <= 2147483647.0) return static_cast<int32_t>(v); // fast path, truncates
20
+ if (v >= 0 && v < 4294967296.0) return static_cast<int32_t>(static_cast<uint32_t>(v)); // results of >>> 0
21
+ if (!std::isfinite(v)) return 0;
22
+ double m = std::fmod(std::trunc(v), 4294967296.0);
23
+ if (m < 0) m += 4294967296.0;
24
+ return static_cast<int32_t>(static_cast<uint32_t>(m));
25
+ }
26
+ inline uint32_t toUint32(double v) { return static_cast<uint32_t>(toInt32(v)); }
27
+
28
+ inline double jsMod(double a, double b) {
29
+ // Exact integer operands with a positive divisor: an integer remainder,
30
+ // keeping the dividend's sign (including -0) as JavaScript does.
31
+ constexpr double kExact = 9007199254740992.0; // 2^53
32
+ if (a >= -kExact && a <= kExact && b >= 1.0 && b <= kExact) {
33
+ auto ia = static_cast<int64_t>(a);
34
+ auto ib = static_cast<int64_t>(b);
35
+ if (static_cast<double>(ia) == a && static_cast<double>(ib) == b) {
36
+ int64_t r = ia % ib;
37
+ return r == 0 && std::signbit(a) ? -0.0 : static_cast<double>(r);
38
+ }
39
+ }
40
+ return std::fmod(a, b);
41
+ }
42
+ inline double jsShl(double a, double b) { return static_cast<double>(static_cast<int32_t>(toUint32(a) << (toUint32(b) & 31))); }
43
+ inline double jsSar(double a, double b) { return static_cast<double>(toInt32(a) >> (toUint32(b) & 31)); }
44
+ inline double jsShr(double a, double b) { return static_cast<double>(toUint32(a) >> (toUint32(b) & 31)); }
45
+ inline double jsAnd(double a, double b) { return static_cast<double>(toInt32(a) & toInt32(b)); }
46
+ inline double jsOr(double a, double b) { return static_cast<double>(toInt32(a) | toInt32(b)); }
47
+ inline double jsXor(double a, double b) { return static_cast<double>(toInt32(a) ^ toInt32(b)); }
48
+ inline double jsNot(double a) { return static_cast<double>(~toInt32(a)); }
49
+ double jsPow(double a, double b);
50
+
51
+ /// Number.prototype.toString() / String(number).
52
+ String numberToString(double v);
53
+ String numberToString(double v, double radix);
54
+ String numberToFixed(double v, double digits);
55
+ String numberToPrecision(double v, double precision);
56
+ String numberToExponential(double v, double digits);
57
+ String numberToExponential(double v);
58
+ /// Number(string) / unary plus.
59
+ double stringToNumber(const String& s);
60
+ double parseFloat(const String& s);
61
+ double parseInt(const String& s);
62
+ double parseInt(const String& s, double radix);
63
+
64
+ inline String toJsString(double v) { return numberToString(v); }
65
+ inline String toJsString(bool v) { return String::fromLatin1(v ? "true" : "false"); }
66
+ inline String toJsString(const String& v) { return v; }
67
+ inline String toJsString(Undefined) { return String::fromLatin1("undefined"); }
68
+ inline String toJsString(Null) { return String::fromLatin1("null"); }
69
+
70
+ inline bool isInteger(double v) { return std::isfinite(v) && std::trunc(v) == v; }
71
+ inline bool isSafeInteger(double v) { return isInteger(v) && std::fabs(v) <= 9007199254740991.0; }
72
+
73
+ namespace math {
74
+ inline double abs(double v) { return std::fabs(v); }
75
+ inline double floor(double v) { return std::floor(v); }
76
+ inline double ceil(double v) { return std::ceil(v); }
77
+ inline double trunc(double v) { return std::trunc(v); }
78
+ double round(double v);
79
+ inline double sign(double v) { return std::isnan(v) ? v : (v > 0 ? 1.0 : (v < 0 ? -1.0 : v)); }
80
+ inline double sqrt(double v) { return std::sqrt(v); }
81
+ /// fdlibm's cbrt (exact for perfect cubes, like JavaScript engines).
82
+ double cbrt(double v);
83
+ inline double exp(double v) { return std::exp(v); }
84
+ inline double expm1(double v) { return std::expm1(v); }
85
+ inline double log(double v) { return std::log(v); }
86
+ inline double log2(double v) { return std::log2(v); }
87
+ inline double log10(double v) { return std::log10(v); }
88
+ inline double log1p(double v) { return std::log1p(v); }
89
+ inline double sin(double v) { return std::sin(v); }
90
+ inline double cos(double v) { return std::cos(v); }
91
+ inline double tan(double v) { return std::tan(v); }
92
+ inline double asin(double v) { return std::asin(v); }
93
+ inline double acos(double v) { return std::acos(v); }
94
+ inline double atan(double v) { return std::atan(v); }
95
+ inline double atan2(double y, double x) { return std::atan2(y, x); }
96
+ inline double sinh(double v) { return std::sinh(v); }
97
+ inline double cosh(double v) { return std::cosh(v); }
98
+ inline double tanh(double v) { return std::tanh(v); }
99
+ inline double asinh(double v) { return std::asinh(v); }
100
+ inline double acosh(double v) { return std::acosh(v); }
101
+ inline double atanh(double v) { return std::atanh(v); }
102
+ inline double pow(double a, double b) { return jsPow(a, b); }
103
+ inline double fround(double v) { return static_cast<double>(static_cast<float>(v)); }
104
+ inline double imul(double a, double b) {
105
+ return static_cast<double>(static_cast<int32_t>(toUint32(a) * toUint32(b)));
106
+ }
107
+ inline double clz32(double v) {
108
+ uint32_t x = toUint32(v);
109
+ if (x == 0) return 32;
110
+ double n = 0;
111
+ while (!(x & 0x80000000u)) {
112
+ x <<= 1;
113
+ n++;
114
+ }
115
+ return n;
116
+ }
117
+ double hypot(double a, double b);
118
+ double hypot(double a, double b, double c);
119
+ double random();
120
+ double min();
121
+ double max();
122
+ double min(double a);
123
+ double max(double a);
124
+ double min(double a, double b);
125
+ double max(double a, double b);
126
+ template <class... Rest>
127
+ double min(double a, double b, double c, Rest... rest) {
128
+ return min(min(a, b), c, rest...);
129
+ }
130
+ template <class... Rest>
131
+ double max(double a, double b, double c, Rest... rest) {
132
+ return max(max(a, b), c, rest...);
133
+ }
134
+ } // namespace math
135
+
136
+ namespace detail {
137
+ /// One part of a concatenation: a string, or a number already formatted
138
+ /// into `digits`, so the total length is known before allocating.
139
+ struct ConcatPiece {
140
+ const String* s = nullptr;
141
+ String formatted; // numbers without a short form (fractions, exponents)
142
+ char digits[24];
143
+ uint8_t n = 0;
144
+ const String* string() const { return s ? s : formatted.empty() ? nullptr : &formatted; }
145
+ size_t length() const { return string() ? string()->length() : n; }
146
+ bool oneByte() const { return !string() || string()->isOneByte(); }
147
+ void appendTo(StringBuilder& b) const {
148
+ if (auto* str = string()) b.append(*str);
149
+ else b.appendAscii(std::string_view(digits, n));
150
+ }
151
+ };
152
+ void formatNumber(double v, ConcatPiece& out);
153
+
154
+ template <class P>
155
+ ConcatPiece concatPiece(const P& p) {
156
+ ConcatPiece piece;
157
+ if constexpr (std::is_floating_point_v<P>) {
158
+ formatNumber(static_cast<double>(p), piece);
159
+ } else if constexpr (std::is_arithmetic_v<P> && !std::is_same_v<P, bool>) {
160
+ // Exact integers (from integer inference) print as their digits.
161
+ auto r = std::to_chars(piece.digits, piece.digits + sizeof piece.digits, p);
162
+ piece.n = static_cast<uint8_t>(r.ptr - piece.digits);
163
+ } else {
164
+ piece.s = &p;
165
+ }
166
+ return piece;
167
+ }
168
+ } // namespace detail
169
+
170
+ /// A template literal: strings and numbers joined into one string, allocating
171
+ /// only the result.
172
+ template <class... P>
173
+ String concat(const P&... parts) {
174
+ if constexpr (sizeof...(P) == 1 && (std::is_same_v<P, String> && ...)) {
175
+ return (parts, ...);
176
+ } else {
177
+ detail::ConcatPiece pieces[] = {detail::concatPiece(parts)...};
178
+ size_t length = 0;
179
+ bool oneByte = true;
180
+ for (auto& p : pieces) {
181
+ length += p.length();
182
+ oneByte = oneByte && p.oneByte();
183
+ }
184
+ StringBuilder b(length, oneByte);
185
+ for (auto& p : pieces) p.appendTo(b);
186
+ return std::move(b).build();
187
+ }
188
+ }
189
+
190
+ } // namespace lucent
@@ -0,0 +1,165 @@
1
+ // Lucent runtime — generic operations the compiler emits: truthiness,
2
+ // string conversion, typeof, and conversions between union representations.
3
+ #pragma once
4
+
5
+ #include <cmath>
6
+ #include <variant>
7
+
8
+ #include "array.h"
9
+ #include "async.h"
10
+ #include "bytes.h"
11
+ #include "core.h"
12
+ #include "jserror.h"
13
+ #include "function.h"
14
+ #include "map.h"
15
+ #include "number.h"
16
+ #include "jsstring.h"
17
+
18
+ namespace lucent {
19
+
20
+ // --- truthiness ----------------------------------------------------------
21
+ inline bool truthy(bool v) { return v; }
22
+ inline bool truthy(double v) { return v != 0 && !std::isnan(v); }
23
+ inline bool truthy(const String& s) { return !s.empty(); }
24
+ inline bool truthy(Undefined) { return false; }
25
+ inline bool truthy(Null) { return false; }
26
+ template <class T>
27
+ bool truthy(const Ref<T>& r) {
28
+ return r != nullptr;
29
+ }
30
+ template <class T>
31
+ bool truthy(const Opt<T>& v) {
32
+ return v.has() && truthy(v.get());
33
+ }
34
+ template <class... Ts>
35
+ bool truthy(const std::variant<Ts...>& v) {
36
+ return std::visit([](const auto& x) { return truthy(x); }, v);
37
+ }
38
+ template <class T>
39
+ bool truthy(const T&) {
40
+ return true; // arrays, maps, functions, promises, bytes: objects are truthy
41
+ }
42
+
43
+ // --- String(x) -------------------------------------------------------------
44
+ template <class T, std::enable_if_t<std::is_base_of_v<Object, T> && !std::is_base_of_v<ErrorObject, T>, int> = 0>
45
+ String toJsString(const Ref<T>&) {
46
+ return String::fromLatin1("[object Object]");
47
+ }
48
+ inline String toJsString(const Error& e) { return errorToString(e); }
49
+ template <class Sig>
50
+ String toJsString(const Fn<Sig>&) {
51
+ return String::fromLatin1("function () { [native code] }");
52
+ }
53
+ template <class... Ts>
54
+ String toJsString(const std::variant<Ts...>& v) {
55
+ return std::visit([](const auto& x) { return toJsString(x); }, v);
56
+ }
57
+
58
+ // --- typeof -----------------------------------------------------------------
59
+ inline String typeOf(double) { return String::fromLatin1("number"); }
60
+ inline String typeOf(bool) { return String::fromLatin1("boolean"); }
61
+ inline String typeOf(const String&) { return String::fromLatin1("string"); }
62
+ inline String typeOf(Undefined) { return String::fromLatin1("undefined"); }
63
+ inline String typeOf(Null) { return String::fromLatin1("object"); }
64
+ template <class Sig>
65
+ String typeOf(const Fn<Sig>&) {
66
+ return String::fromLatin1("function");
67
+ }
68
+ template <class T>
69
+ String typeOf(const Opt<T>& v) {
70
+ if (v.isUndefined()) return String::fromLatin1("undefined");
71
+ if (v.isNull()) return String::fromLatin1("object");
72
+ return typeOf(v.get());
73
+ }
74
+ template <class... Ts>
75
+ String typeOf(const std::variant<Ts...>& v) {
76
+ return std::visit([](const auto& x) { return typeOf(x); }, v);
77
+ }
78
+ template <class T>
79
+ String typeOf(const T&) {
80
+ return String::fromLatin1("object");
81
+ }
82
+
83
+ // --- unions -------------------------------------------------------------------
84
+ template <class T>
85
+ struct IsVariant : std::false_type {};
86
+ template <class... Ts>
87
+ struct IsVariant<std::variant<Ts...>> : std::true_type {};
88
+
89
+ template <class T, class V>
90
+ constexpr bool variantHolds() {
91
+ if constexpr (IsVariant<V>::value) {
92
+ return []<class... Ts>(std::variant<Ts...>*) { return (std::is_same_v<T, Ts> || ...); }(static_cast<V*>(nullptr));
93
+ } else {
94
+ return false;
95
+ }
96
+ }
97
+
98
+ /// Converts between value representations the type checker has proven
99
+ /// compatible: member → union, union → wider union, union → narrower union,
100
+ /// union → member (after narrowing), and T ↔ Opt<T>.
101
+ template <class To, class From>
102
+ To convert(From&& from);
103
+
104
+ namespace detail {
105
+ template <class To, class From>
106
+ To convertImpl(const From& from) {
107
+ using F = std::decay_t<From>;
108
+ if constexpr (std::is_same_v<To, F>) {
109
+ return from;
110
+ } else if constexpr (IsOpt<To>::value) {
111
+ using Inner = typename To::ValueType;
112
+ if constexpr (IsOpt<F>::value) {
113
+ if (from.isUndefined()) return To(undefined);
114
+ if (from.isNull()) return To(null);
115
+ return To(convert<Inner>(from.get()));
116
+ } else if constexpr (std::is_same_v<F, Undefined>) {
117
+ return To(undefined);
118
+ } else if constexpr (std::is_same_v<F, Null>) {
119
+ return To(null);
120
+ } else {
121
+ return To(convert<Inner>(from));
122
+ }
123
+ } else if constexpr (IsOpt<F>::value) {
124
+ // Proven present by narrowing; still checked.
125
+ return convert<To>(from.value());
126
+ } else if constexpr (IsVariant<F>::value) {
127
+ return std::visit(
128
+ [](const auto& x) -> To {
129
+ using X = std::decay_t<decltype(x)>;
130
+ if constexpr (std::is_same_v<X, To> || std::is_constructible_v<To, X>) {
131
+ if constexpr (IsVariant<To>::value && !variantHolds<X, To>()) {
132
+ throwTypeError("Value does not match the expected union member");
133
+ } else {
134
+ return To(x);
135
+ }
136
+ } else {
137
+ throwTypeError("Value does not match the expected type");
138
+ }
139
+ },
140
+ from);
141
+ } else if constexpr (IsVariant<To>::value) {
142
+ return To(from);
143
+ } else {
144
+ return To(from);
145
+ }
146
+ }
147
+ } // namespace detail
148
+
149
+ template <class To, class From>
150
+ To convert(From&& from) {
151
+ return detail::convertImpl<To>(from);
152
+ }
153
+
154
+ /// Narrows a union to one member; the checker proved it holds.
155
+ template <class T, class... Ts>
156
+ const T& narrow(const std::variant<Ts...>& v) {
157
+ if (const T* p = std::get_if<T>(&v)) return *p;
158
+ throwTypeError("Value does not match the narrowed type");
159
+ }
160
+ template <class T, class... Ts>
161
+ bool holds(const std::variant<Ts...>& v) {
162
+ return std::holds_alternative<T>(v);
163
+ }
164
+
165
+ } // namespace lucent