@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,457 @@
1
+ /*
2
+ * C utilities
3
+ *
4
+ * Copyright (c) 2017 Fabrice Bellard
5
+ * Copyright (c) 2018 Charlie Gordon
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ */
25
+ #ifndef CUTILS_H
26
+ #define CUTILS_H
27
+
28
+ #include <stdlib.h>
29
+ #include <string.h>
30
+ #include <inttypes.h>
31
+
32
+ #define likely(x) __builtin_expect(!!(x), 1)
33
+ #define unlikely(x) __builtin_expect(!!(x), 0)
34
+ #define force_inline inline __attribute__((always_inline))
35
+ #define no_inline __attribute__((noinline))
36
+ #define __maybe_unused __attribute__((unused))
37
+
38
+ #define xglue(x, y) x ## y
39
+ #define glue(x, y) xglue(x, y)
40
+ #define stringify(s) tostring(s)
41
+ #define tostring(s) #s
42
+
43
+ #ifndef offsetof
44
+ #define offsetof(type, field) ((size_t) &((type *)0)->field)
45
+ #endif
46
+ #ifndef countof
47
+ #define countof(x) (sizeof(x) / sizeof((x)[0]))
48
+ #endif
49
+ #ifndef container_of
50
+ /* return the pointer of type 'type *' containing 'ptr' as field 'member' */
51
+ #define container_of(ptr, type, member) ((type *)((uint8_t *)(ptr) - offsetof(type, member)))
52
+ #endif
53
+
54
+ #if !defined(_MSC_VER) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
55
+ #define minimum_length(n) static n
56
+ #else
57
+ #define minimum_length(n) n
58
+ #endif
59
+
60
+ typedef int BOOL;
61
+
62
+ #ifndef FALSE
63
+ enum {
64
+ FALSE = 0,
65
+ TRUE = 1,
66
+ };
67
+ #endif
68
+
69
+ void pstrcpy(char *buf, int buf_size, const char *str);
70
+ char *pstrcat(char *buf, int buf_size, const char *s);
71
+ int strstart(const char *str, const char *val, const char **ptr);
72
+ int has_suffix(const char *str, const char *suffix);
73
+
74
+ /* Prevent UB when n == 0 and (src == NULL or dest == NULL) */
75
+ static inline void memcpy_no_ub(void *dest, const void *src, size_t n) {
76
+ if (n)
77
+ memcpy(dest, src, n);
78
+ }
79
+
80
+ static inline int max_int(int a, int b)
81
+ {
82
+ if (a > b)
83
+ return a;
84
+ else
85
+ return b;
86
+ }
87
+
88
+ static inline int min_int(int a, int b)
89
+ {
90
+ if (a < b)
91
+ return a;
92
+ else
93
+ return b;
94
+ }
95
+
96
+ static inline uint32_t max_uint32(uint32_t a, uint32_t b)
97
+ {
98
+ if (a > b)
99
+ return a;
100
+ else
101
+ return b;
102
+ }
103
+
104
+ static inline uint32_t min_uint32(uint32_t a, uint32_t b)
105
+ {
106
+ if (a < b)
107
+ return a;
108
+ else
109
+ return b;
110
+ }
111
+
112
+ static inline int64_t max_int64(int64_t a, int64_t b)
113
+ {
114
+ if (a > b)
115
+ return a;
116
+ else
117
+ return b;
118
+ }
119
+
120
+ static inline int64_t min_int64(int64_t a, int64_t b)
121
+ {
122
+ if (a < b)
123
+ return a;
124
+ else
125
+ return b;
126
+ }
127
+
128
+ /* WARNING: undefined if a = 0 */
129
+ static inline int clz32(unsigned int a)
130
+ {
131
+ return __builtin_clz(a);
132
+ }
133
+
134
+ /* WARNING: undefined if a = 0 */
135
+ static inline int clz64(uint64_t a)
136
+ {
137
+ return __builtin_clzll(a);
138
+ }
139
+
140
+ /* WARNING: undefined if a = 0 */
141
+ static inline int ctz32(unsigned int a)
142
+ {
143
+ return __builtin_ctz(a);
144
+ }
145
+
146
+ /* WARNING: undefined if a = 0 */
147
+ static inline int ctz64(uint64_t a)
148
+ {
149
+ return __builtin_ctzll(a);
150
+ }
151
+
152
+ struct __attribute__((packed)) packed_u64 {
153
+ uint64_t v;
154
+ };
155
+
156
+ struct __attribute__((packed)) packed_u32 {
157
+ uint32_t v;
158
+ };
159
+
160
+ struct __attribute__((packed)) packed_u16 {
161
+ uint16_t v;
162
+ };
163
+
164
+ static inline uint64_t get_u64(const uint8_t *tab)
165
+ {
166
+ return ((const struct packed_u64 *)tab)->v;
167
+ }
168
+
169
+ static inline int64_t get_i64(const uint8_t *tab)
170
+ {
171
+ return (int64_t)((const struct packed_u64 *)tab)->v;
172
+ }
173
+
174
+ static inline void put_u64(uint8_t *tab, uint64_t val)
175
+ {
176
+ ((struct packed_u64 *)tab)->v = val;
177
+ }
178
+
179
+ static inline uint32_t get_u32(const uint8_t *tab)
180
+ {
181
+ return ((const struct packed_u32 *)tab)->v;
182
+ }
183
+
184
+ static inline int32_t get_i32(const uint8_t *tab)
185
+ {
186
+ return (int32_t)((const struct packed_u32 *)tab)->v;
187
+ }
188
+
189
+ static inline void put_u32(uint8_t *tab, uint32_t val)
190
+ {
191
+ ((struct packed_u32 *)tab)->v = val;
192
+ }
193
+
194
+ static inline uint32_t get_u16(const uint8_t *tab)
195
+ {
196
+ return ((const struct packed_u16 *)tab)->v;
197
+ }
198
+
199
+ static inline int32_t get_i16(const uint8_t *tab)
200
+ {
201
+ return (int16_t)((const struct packed_u16 *)tab)->v;
202
+ }
203
+
204
+ static inline void put_u16(uint8_t *tab, uint16_t val)
205
+ {
206
+ ((struct packed_u16 *)tab)->v = val;
207
+ }
208
+
209
+ static inline uint32_t get_u8(const uint8_t *tab)
210
+ {
211
+ return *tab;
212
+ }
213
+
214
+ static inline int32_t get_i8(const uint8_t *tab)
215
+ {
216
+ return (int8_t)*tab;
217
+ }
218
+
219
+ static inline void put_u8(uint8_t *tab, uint8_t val)
220
+ {
221
+ *tab = val;
222
+ }
223
+
224
+ #ifndef bswap16
225
+ static inline uint16_t bswap16(uint16_t x)
226
+ {
227
+ return (x >> 8) | (x << 8);
228
+ }
229
+ #endif
230
+
231
+ #ifndef bswap32
232
+ static inline uint32_t bswap32(uint32_t v)
233
+ {
234
+ return ((v & 0xff000000) >> 24) | ((v & 0x00ff0000) >> 8) |
235
+ ((v & 0x0000ff00) << 8) | ((v & 0x000000ff) << 24);
236
+ }
237
+ #endif
238
+
239
+ #ifndef bswap64
240
+ static inline uint64_t bswap64(uint64_t v)
241
+ {
242
+ return ((v & ((uint64_t)0xff << (7 * 8))) >> (7 * 8)) |
243
+ ((v & ((uint64_t)0xff << (6 * 8))) >> (5 * 8)) |
244
+ ((v & ((uint64_t)0xff << (5 * 8))) >> (3 * 8)) |
245
+ ((v & ((uint64_t)0xff << (4 * 8))) >> (1 * 8)) |
246
+ ((v & ((uint64_t)0xff << (3 * 8))) << (1 * 8)) |
247
+ ((v & ((uint64_t)0xff << (2 * 8))) << (3 * 8)) |
248
+ ((v & ((uint64_t)0xff << (1 * 8))) << (5 * 8)) |
249
+ ((v & ((uint64_t)0xff << (0 * 8))) << (7 * 8));
250
+ }
251
+ #endif
252
+
253
+ /* XXX: should take an extra argument to pass slack information to the caller */
254
+ typedef void *DynBufReallocFunc(void *opaque, void *ptr, size_t size);
255
+
256
+ typedef struct DynBuf {
257
+ uint8_t *buf;
258
+ size_t size;
259
+ size_t allocated_size;
260
+ BOOL error; /* true if a memory allocation error occurred */
261
+ DynBufReallocFunc *realloc_func;
262
+ void *opaque; /* for realloc_func */
263
+ } DynBuf;
264
+
265
+ void dbuf_init(DynBuf *s);
266
+ void dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func);
267
+ int dbuf_claim(DynBuf *s, size_t len);
268
+ int dbuf_put(DynBuf *s, const uint8_t *data, size_t len);
269
+ int dbuf_put_self(DynBuf *s, size_t offset, size_t len);
270
+ int dbuf_putstr(DynBuf *s, const char *str);
271
+ int __dbuf_putc(DynBuf *s, uint8_t c);
272
+ int __dbuf_put_u16(DynBuf *s, uint16_t val);
273
+ int __dbuf_put_u32(DynBuf *s, uint32_t val);
274
+ int __dbuf_put_u64(DynBuf *s, uint64_t val);
275
+
276
+ static inline int dbuf_putc(DynBuf *s, uint8_t val)
277
+ {
278
+ if (unlikely((s->allocated_size - s->size) < 1)) {
279
+ return __dbuf_putc(s, val);
280
+ } else {
281
+ s->buf[s->size++] = val;
282
+ return 0;
283
+ }
284
+ }
285
+
286
+ static inline int dbuf_put_u16(DynBuf *s, uint16_t val)
287
+ {
288
+ if (unlikely((s->allocated_size - s->size) < 2)) {
289
+ return __dbuf_put_u16(s, val);
290
+ } else {
291
+ put_u16(s->buf + s->size, val);
292
+ s->size += 2;
293
+ return 0;
294
+ }
295
+ }
296
+
297
+ static inline int dbuf_put_u32(DynBuf *s, uint32_t val)
298
+ {
299
+ if (unlikely((s->allocated_size - s->size) < 4)) {
300
+ return __dbuf_put_u32(s, val);
301
+ } else {
302
+ put_u32(s->buf + s->size, val);
303
+ s->size += 4;
304
+ return 0;
305
+ }
306
+ }
307
+
308
+ static inline int dbuf_put_u64(DynBuf *s, uint64_t val)
309
+ {
310
+ if (unlikely((s->allocated_size - s->size) < 8)) {
311
+ return __dbuf_put_u64(s, val);
312
+ } else {
313
+ put_u64(s->buf + s->size, val);
314
+ s->size += 8;
315
+ return 0;
316
+ }
317
+ }
318
+
319
+ int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
320
+ const char *fmt, ...);
321
+ void dbuf_free(DynBuf *s);
322
+ static inline BOOL dbuf_error(DynBuf *s) {
323
+ return s->error;
324
+ }
325
+ static inline void dbuf_set_error(DynBuf *s)
326
+ {
327
+ s->error = TRUE;
328
+ }
329
+
330
+ #define UTF8_CHAR_LEN_MAX 6
331
+
332
+ int unicode_to_utf8(uint8_t *buf, unsigned int c);
333
+ int unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp);
334
+
335
+ static inline BOOL is_surrogate(uint32_t c)
336
+ {
337
+ return (c >> 11) == (0xD800 >> 11); // 0xD800-0xDFFF
338
+ }
339
+
340
+ static inline BOOL is_hi_surrogate(uint32_t c)
341
+ {
342
+ return (c >> 10) == (0xD800 >> 10); // 0xD800-0xDBFF
343
+ }
344
+
345
+ static inline BOOL is_lo_surrogate(uint32_t c)
346
+ {
347
+ return (c >> 10) == (0xDC00 >> 10); // 0xDC00-0xDFFF
348
+ }
349
+
350
+ static inline uint32_t get_hi_surrogate(uint32_t c)
351
+ {
352
+ return (c >> 10) - (0x10000 >> 10) + 0xD800;
353
+ }
354
+
355
+ static inline uint32_t get_lo_surrogate(uint32_t c)
356
+ {
357
+ return (c & 0x3FF) | 0xDC00;
358
+ }
359
+
360
+ static inline uint32_t from_surrogate(uint32_t hi, uint32_t lo)
361
+ {
362
+ return 0x10000 + 0x400 * (hi - 0xD800) + (lo - 0xDC00);
363
+ }
364
+
365
+ static inline int from_hex(int c)
366
+ {
367
+ if (c >= '0' && c <= '9')
368
+ return c - '0';
369
+ else if (c >= 'A' && c <= 'F')
370
+ return c - 'A' + 10;
371
+ else if (c >= 'a' && c <= 'f')
372
+ return c - 'a' + 10;
373
+ else
374
+ return -1;
375
+ }
376
+
377
+ void rqsort(void *base, size_t nmemb, size_t size,
378
+ int (*cmp)(const void *, const void *, void *),
379
+ void *arg);
380
+
381
+ static inline uint64_t float64_as_uint64(double d)
382
+ {
383
+ union {
384
+ double d;
385
+ uint64_t u64;
386
+ } u;
387
+ u.d = d;
388
+ return u.u64;
389
+ }
390
+
391
+ static inline double uint64_as_float64(uint64_t u64)
392
+ {
393
+ union {
394
+ double d;
395
+ uint64_t u64;
396
+ } u;
397
+ u.u64 = u64;
398
+ return u.d;
399
+ }
400
+
401
+ static inline double fromfp16(uint16_t v)
402
+ {
403
+ double d;
404
+ uint32_t v1;
405
+ v1 = v & 0x7fff;
406
+ if (unlikely(v1 >= 0x7c00))
407
+ v1 += 0x1f8000; /* NaN or infinity */
408
+ d = uint64_as_float64(((uint64_t)(v >> 15) << 63) | ((uint64_t)v1 << (52 - 10)));
409
+ return d * 0x1p1008;
410
+ }
411
+
412
+ static inline uint16_t tofp16(double d)
413
+ {
414
+ uint64_t a, addend;
415
+ uint32_t v, sgn;
416
+ int shift;
417
+
418
+ a = float64_as_uint64(d);
419
+ sgn = a >> 63;
420
+ a = a & 0x7fffffffffffffff;
421
+ if (unlikely(a > 0x7ff0000000000000)) {
422
+ /* nan */
423
+ v = 0x7c01;
424
+ } else if (a < 0x3f10000000000000) { /* 0x1p-14 */
425
+ /* subnormal f16 number or zero */
426
+ if (a <= 0x3e60000000000000) { /* 0x1p-25 */
427
+ v = 0x0000; /* zero */
428
+ } else {
429
+ shift = 1051 - (a >> 52);
430
+ a = ((uint64_t)1 << 52) | (a & (((uint64_t)1 << 52) - 1));
431
+ addend = ((a >> shift) & 1) + (((uint64_t)1 << (shift - 1)) - 1);
432
+ v = (a + addend) >> shift;
433
+ }
434
+ } else {
435
+ /* normal number or infinity */
436
+ a -= 0x3f00000000000000; /* adjust the exponent */
437
+ /* round */
438
+ addend = ((a >> (52 - 10)) & 1) + (((uint64_t)1 << (52 - 11)) - 1);
439
+ v = (a + addend) >> (52 - 10);
440
+ /* overflow ? */
441
+ if (unlikely(v > 0x7c00))
442
+ v = 0x7c00;
443
+ }
444
+ return v | (sgn << 15);
445
+ }
446
+
447
+ static inline int isfp16nan(uint16_t v)
448
+ {
449
+ return (v & 0x7FFF) > 0x7C00;
450
+ }
451
+
452
+ static inline int isfp16zero(uint16_t v)
453
+ {
454
+ return (v & 0x7FFF) == 0;
455
+ }
456
+
457
+ #endif /* CUTILS_H */
@@ -0,0 +1,73 @@
1
+ /*
2
+ * Regular Expression Engine
3
+ *
4
+ * Copyright (c) 2017-2018 Fabrice Bellard
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ #ifdef DEF
26
+
27
+ DEF(invalid, 1) /* never used */
28
+ DEF(char, 3)
29
+ DEF(char_i, 3)
30
+ DEF(char32, 5)
31
+ DEF(char32_i, 5)
32
+ DEF(dot, 1)
33
+ DEF(any, 1) /* same as dot but match any character including line terminator */
34
+ DEF(space, 1)
35
+ DEF(not_space, 1) /* must come after */
36
+ DEF(line_start, 1)
37
+ DEF(line_start_m, 1)
38
+ DEF(line_end, 1)
39
+ DEF(line_end_m, 1)
40
+ DEF(goto, 5)
41
+ DEF(split_goto_first, 5)
42
+ DEF(split_next_first, 5)
43
+ DEF(match, 1)
44
+ DEF(lookahead_match, 1)
45
+ DEF(negative_lookahead_match, 1) /* must come after */
46
+ DEF(save_start, 2) /* save start position */
47
+ DEF(save_end, 2) /* save end position, must come after saved_start */
48
+ DEF(save_reset, 3) /* reset save positions */
49
+ DEF(loop, 6) /* decrement the top the stack and goto if != 0 */
50
+ DEF(loop_split_goto_first, 10) /* loop and then split */
51
+ DEF(loop_split_next_first, 10)
52
+ DEF(loop_check_adv_split_goto_first, 10) /* loop and then check advance and split */
53
+ DEF(loop_check_adv_split_next_first, 10)
54
+ DEF(set_i32, 6) /* store the immediate value to a register */
55
+ DEF(word_boundary, 1)
56
+ DEF(word_boundary_i, 1)
57
+ DEF(not_word_boundary, 1)
58
+ DEF(not_word_boundary_i, 1)
59
+ DEF(back_reference, 2) /* variable length */
60
+ DEF(back_reference_i, 2) /* must come after */
61
+ DEF(backward_back_reference, 2) /* must come after */
62
+ DEF(backward_back_reference_i, 2) /* must come after */
63
+ DEF(range, 3) /* variable length */
64
+ DEF(range_i, 3) /* variable length */
65
+ DEF(range32, 3) /* variable length */
66
+ DEF(range32_i, 3) /* variable length */
67
+ DEF(lookahead, 5)
68
+ DEF(negative_lookahead, 5) /* must come after */
69
+ DEF(set_char_pos, 2) /* store the character position to a register */
70
+ DEF(check_advance, 2) /* check that the register is different from the character position */
71
+ DEF(prev, 1) /* go to the previous char */
72
+
73
+ #endif /* DEF */