xbintsc 0.5.31 → 0.5.32

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 (181) hide show
  1. package/README.md +16 -10
  2. package/dist/src/binder/references.js +14 -1
  3. package/dist/src/binder/references.js.map +1 -1
  4. package/dist/src/cli/help.d.ts +1 -1
  5. package/dist/src/codegen/generator/module.d.ts +1 -0
  6. package/dist/src/codegen/generator/module.js +54 -0
  7. package/dist/src/codegen/generator/module.js.map +1 -1
  8. package/dist/src/codegen/generator/statements/variables.js +6 -4
  9. package/dist/src/codegen/generator/statements/variables.js.map +1 -1
  10. package/dist/src/driver/version.d.ts +1 -1
  11. package/dist/src/driver/version.js +1 -1
  12. package/dist/src/extensions/gui/css.d.ts +26 -0
  13. package/dist/src/extensions/gui/css.js +100 -0
  14. package/dist/src/extensions/gui/css.js.map +1 -0
  15. package/dist/src/extensions/gui/html.js +9 -2
  16. package/dist/src/extensions/gui/html.js.map +1 -1
  17. package/dist/src/extensions/gui/index.js +16 -2
  18. package/dist/src/extensions/gui/index.js.map +1 -1
  19. package/dist/src/extensions/gui/three.d.ts +16 -0
  20. package/dist/src/extensions/gui/three.js +22 -0
  21. package/dist/src/extensions/gui/three.js.map +1 -0
  22. package/dist/src/extensions/media/index.d.ts +6 -5
  23. package/dist/src/extensions/media/index.js +12 -14
  24. package/dist/src/extensions/media/index.js.map +1 -1
  25. package/dist/tests/e2e/compile-builtins.test.js +24 -0
  26. package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
  27. package/dist/tests/e2e/compile-objects-classes.test.js +23 -0
  28. package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
  29. package/dist/tests/e2e/gui-browser.test.js +1 -1
  30. package/dist/tests/e2e/gui-browser.test.js.map +1 -1
  31. package/dist/tests/e2e/gui-effects.test.d.ts +6 -0
  32. package/dist/tests/e2e/gui-effects.test.js +262 -0
  33. package/dist/tests/e2e/gui-effects.test.js.map +1 -0
  34. package/dist/tests/e2e/gui-example-webgl.test.d.ts +10 -0
  35. package/dist/tests/e2e/gui-example-webgl.test.js +75 -0
  36. package/dist/tests/e2e/gui-example-webgl.test.js.map +1 -0
  37. package/dist/tests/e2e/gui-example-webgl2.test.d.ts +8 -0
  38. package/dist/tests/e2e/gui-example-webgl2.test.js +72 -0
  39. package/dist/tests/e2e/gui-example-webgl2.test.js.map +1 -0
  40. package/dist/tests/e2e/gui-layout.test.js +48 -0
  41. package/dist/tests/e2e/gui-layout.test.js.map +1 -1
  42. package/dist/tests/e2e/gui-media.test.js +5 -4
  43. package/dist/tests/e2e/gui-media.test.js.map +1 -1
  44. package/dist/tests/e2e/gui-webgl.test.d.ts +11 -0
  45. package/dist/tests/e2e/gui-webgl.test.js +179 -0
  46. package/dist/tests/e2e/gui-webgl.test.js.map +1 -0
  47. package/dist/tests/e2e/gui-webgl2.test.d.ts +10 -0
  48. package/dist/tests/e2e/gui-webgl2.test.js +238 -0
  49. package/dist/tests/e2e/gui-webgl2.test.js.map +1 -0
  50. package/dist/tests/extensions/gui.test.js +41 -0
  51. package/dist/tests/extensions/gui.test.js.map +1 -1
  52. package/dist/tests/extensions/media.test.js +7 -3
  53. package/dist/tests/extensions/media.test.js.map +1 -1
  54. package/doc/ai/extensions.md +29 -9
  55. package/doc/ai/troubleshooting.md +12 -8
  56. package/doc/ai/zh-CN/extensions.md +26 -8
  57. package/doc/ai/zh-CN/troubleshooting.md +10 -6
  58. package/doc/gui/api.md +3 -2
  59. package/doc/gui/build.md +72 -16
  60. package/doc/gui/canvas.md +11 -3
  61. package/doc/gui/dom.md +33 -18
  62. package/doc/gui/known-issues.md +57 -24
  63. package/doc/gui/layout.md +18 -0
  64. package/doc/gui/media.md +17 -13
  65. package/doc/gui/rendering.md +50 -3
  66. package/doc/gui/webgl.md +256 -0
  67. package/doc/gui.md +108 -17
  68. package/doc/npm-package.md +6 -4
  69. package/doc/requirements.md +18 -9
  70. package/doc/zh-CN/gui/api.md +3 -2
  71. package/doc/zh-CN/gui/build.md +64 -15
  72. package/doc/zh-CN/gui/canvas.md +9 -2
  73. package/doc/zh-CN/gui/dom.md +20 -7
  74. package/doc/zh-CN/gui/known-issues.md +45 -19
  75. package/doc/zh-CN/gui/layout.md +14 -0
  76. package/doc/zh-CN/gui/media.md +15 -11
  77. package/doc/zh-CN/gui/rendering.md +41 -4
  78. package/doc/zh-CN/gui/webgl.md +115 -0
  79. package/doc/zh-CN/gui.md +89 -14
  80. package/doc/zh-CN/npm-package.md +9 -6
  81. package/doc/zh-CN/requirements.md +12 -6
  82. package/llms.txt +2 -0
  83. package/package.json +1 -1
  84. package/runtime/ext_gui/browser.cpp +39 -13
  85. package/runtime/ext_gui/canvas.cpp +3 -18
  86. package/runtime/ext_gui/canvas_internal.h +10 -0
  87. package/runtime/ext_gui/canvas_raster.cpp +60 -0
  88. package/runtime/ext_gui/clip_values.cpp +246 -0
  89. package/runtime/ext_gui/css.cpp +94 -0
  90. package/runtime/ext_gui/css.h +22 -1
  91. package/runtime/ext_gui/css_match.cpp +3 -0
  92. package/runtime/ext_gui/css_selector.cpp +9 -0
  93. package/runtime/ext_gui/css_sheet.cpp +89 -45
  94. package/runtime/ext_gui/document.cpp +4 -1
  95. package/runtime/ext_gui/document.h +2 -0
  96. package/runtime/ext_gui/dom.h +16 -0
  97. package/runtime/ext_gui/dom_api.cpp +1 -0
  98. package/runtime/ext_gui/dom_api_canvas.cpp +17 -80
  99. package/runtime/ext_gui/dom_api_canvas_extra.cpp +130 -1
  100. package/runtime/ext_gui/dom_api_canvas_pending.cpp +41 -0
  101. package/runtime/ext_gui/dom_api_internal.h +259 -0
  102. package/runtime/ext_gui/dom_api_webgl.cpp +376 -0
  103. package/runtime/ext_gui/dom_api_webgl2.cpp +434 -0
  104. package/runtime/ext_gui/dom_api_webgl2_draw.cpp +269 -0
  105. package/runtime/ext_gui/dom_api_webgl_buffer.cpp +212 -0
  106. package/runtime/ext_gui/dom_api_webgl_rt.h +30 -0
  107. package/runtime/ext_gui/dom_api_webgl_shader.cpp +443 -0
  108. package/runtime/ext_gui/dom_api_webgl_state.cpp +444 -0
  109. package/runtime/ext_gui/dom_api_webgl_texture.cpp +445 -0
  110. package/runtime/ext_gui/effect_values.cpp +312 -0
  111. package/runtime/ext_gui/gradient_values.cpp +476 -0
  112. package/runtime/ext_gui/grid_values.cpp +230 -0
  113. package/runtime/ext_gui/gui_canvas.cpp +50 -2
  114. package/runtime/ext_gui/gui_engine.h +27 -0
  115. package/runtime/ext_gui/gui_events.cpp +4 -1
  116. package/runtime/ext_gui/gui_media.cpp +1 -1
  117. package/runtime/ext_gui/gui_webgl.cpp +83 -0
  118. package/runtime/ext_gui/layout.cpp +21 -0
  119. package/runtime/ext_gui/layout_flow.cpp +81 -4
  120. package/runtime/ext_gui/layout_flow_internal.h +31 -0
  121. package/runtime/ext_gui/layout_grid.cpp +374 -0
  122. package/runtime/ext_gui/media.h +1 -1
  123. package/runtime/ext_gui/media_api.h +2 -2
  124. package/runtime/ext_gui/media_query.cpp +211 -0
  125. package/runtime/ext_gui/paint.cpp +111 -77
  126. package/runtime/ext_gui/paint.h +33 -3
  127. package/runtime/ext_gui/paint_background.cpp +229 -0
  128. package/runtime/ext_gui/paint_clip.cpp +268 -0
  129. package/runtime/ext_gui/paint_effects.cpp +324 -0
  130. package/runtime/ext_gui/paint_internal.h +85 -0
  131. package/runtime/ext_gui/renderer.cpp +8 -31
  132. package/runtime/ext_gui/renderer_clip.cpp +196 -0
  133. package/runtime/ext_gui/renderer_image.cpp +13 -8
  134. package/runtime/ext_gui/renderer_internal.h +15 -8
  135. package/runtime/ext_gui/renderer_text.cpp +6 -31
  136. package/runtime/ext_gui/style.cpp +343 -20
  137. package/runtime/ext_gui/style.h +144 -3
  138. package/runtime/ext_gui/style_print.cpp +134 -1
  139. package/runtime/ext_gui/style_values.cpp +152 -126
  140. package/runtime/ext_gui/style_values_internal.h +35 -0
  141. package/runtime/ext_gui/webgl.h +466 -0
  142. package/runtime/ext_gui/webgl2_constants.h +274 -0
  143. package/runtime/ext_gui/webgl_buffer.cpp +565 -0
  144. package/runtime/ext_gui/webgl_constants.h +317 -0
  145. package/runtime/ext_gui/webgl_context.cpp +466 -0
  146. package/runtime/ext_gui/webgl_draw.cpp +495 -0
  147. package/runtime/ext_gui/webgl_glsl.h +125 -0
  148. package/runtime/ext_gui/webgl_glsl_compile.cpp +431 -0
  149. package/runtime/ext_gui/webgl_glsl_rewrite.cpp +349 -0
  150. package/runtime/ext_gui/webgl_glsl_scan.cpp +581 -0
  151. package/runtime/ext_gui/webgl_msl.cpp +62 -0
  152. package/runtime/ext_gui/webgl_msl.h +33 -0
  153. package/runtime/ext_gui/webgl_pipeline.cpp +274 -0
  154. package/runtime/ext_gui/webgl_program_internal.h +18 -0
  155. package/runtime/ext_gui/webgl_shader.cpp +582 -0
  156. package/runtime/ext_gui/webgl_texture.cpp +293 -0
  157. package/runtime/ext_gui/webgl_uniform.cpp +167 -0
  158. package/runtime/ext_gui/webgl_webgl2.cpp +224 -0
  159. package/runtime/ext_media/media.cpp +1 -1
  160. package/runtime/ext_media/media_bridge.c +9 -3
  161. package/runtime/rt_internal.h +1 -0
  162. package/runtime/xt_containers/access.inc +8 -0
  163. package/runtime/xt_regex/api.inc +2 -0
  164. package/runtime/xt_regex/matcher.inc +16 -3
  165. package/runtime/xt_regex/parser.inc +8 -2
  166. package/runtime/xt_regex/types.inc +3 -0
  167. package/runtime/xt_stdlib2/regexp-match.inc +60 -21
  168. package/runtime/xt_stdlib2/regexp.inc +1 -0
  169. package/runtime/xt_typed_array.c +1 -1
  170. package/scripts/build-gui.ts +90 -3
  171. package/scripts/build-media.ts +323 -58
  172. package/scripts/setup-vs-toolchain.ps1 +152 -0
  173. package/src/binder/references.ts +13 -1
  174. package/src/codegen/generator/module.ts +50 -0
  175. package/src/codegen/generator/statements/variables.ts +6 -3
  176. package/src/driver/version.ts +1 -1
  177. package/src/extensions/gui/css.ts +113 -0
  178. package/src/extensions/gui/html.ts +9 -2
  179. package/src/extensions/gui/index.ts +16 -2
  180. package/src/extensions/gui/three.ts +25 -0
  181. package/src/extensions/media/index.ts +13 -16
@@ -1,7 +1,8 @@
1
1
  /*
2
2
  * xbintsc media extension — registration bridge.
3
3
  *
4
- * The decoders live in `media.a`, a prebuilt C++ archive. A static archive is
4
+ * The decoders live in `media.a` (`media.lib` with the MSVC ABI on Windows), a
5
+ * prebuilt C++ archive. A static archive is
5
6
  * only searched for members that satisfy an undefined symbol, so a backend that
6
7
  * merely had a constructor would never be extracted. This tiny C translation
7
8
  * unit is compiled and linked *directly* (it is the media extension's
@@ -24,12 +25,17 @@ static const XtMediaApi kMediaApi = {
24
25
  };
25
26
 
26
27
  #if defined(__GNUC__) || defined(__clang__)
28
+ /* clang targeting Windows (the toolchain xbintsc uses there) implements this
29
+ * attribute with a `.CRT$XCU` entry, which the MSVC CRT runs before `main`. */
27
30
  __attribute__((constructor)) static void xt_media_register(void) {
28
31
  xt_media_install(&kMediaApi);
29
32
  }
30
33
  #elif defined(_MSC_VER)
31
- /* COFF has no `constructor` attribute. `media.lib` is not produced on Windows
32
- * yet; keep the table referenced so the translation unit is not empty. */
34
+ /* A plain MSVC build has no constructor attribute; put the function pointer in
35
+ * the CRT's initializer table by hand. `media.lib` itself is built with
36
+ * clang-cl, so this branch is only for a cl.exe-built bridge. */
33
37
  void xt_media_register(void);
38
+ #pragma section(".CRT$XCU", read)
39
+ __declspec(allocate(".CRT$XCU")) static void (*const xt_media_register_ctor)(void) = xt_media_register;
34
40
  void xt_media_register(void) { xt_media_install(&kMediaApi); }
35
41
  #endif
@@ -547,6 +547,7 @@ typedef struct {
547
547
  xt_header header;
548
548
  xt_value source;
549
549
  xt_value flags;
550
+ double last_index;
550
551
  } xt_regexp;
551
552
 
552
553
  /* Extended method dispatch (xt_stdlib2.c). `*handled` is set when the method
@@ -375,6 +375,14 @@ xt_value xt_set(xt_value target, xt_value key, xt_value value) {
375
375
  return value;
376
376
  }
377
377
  }
378
+ if (((xt_object *)XT_GET_PTR(target))->header.kind == XT_OBJECT_KIND_REGEXP &&
379
+ XT_IS_STRING(key)) {
380
+ xt_string *k = xt_as_string(key);
381
+ if (k->length == 9 && memcmp(xt_string_bytes(k), "lastIndex", 9) == 0) {
382
+ ((xt_regexp *)XT_GET_PTR(target))->last_index = xt_to_number(value);
383
+ return value;
384
+ }
385
+ }
378
386
  return xt_object_set(target, key, value);
379
387
  }
380
388
  return value;
@@ -16,6 +16,7 @@ static int regcomp(regex_t *preg, const char *pattern, int cflags) {
16
16
  }
17
17
  preg->root = root;
18
18
  preg->icase = (cflags & REG_ICASE) ? 1 : 0;
19
+ preg->multiline = (cflags & REG_MULTILINE) ? 1 : 0;
19
20
  return 0;
20
21
  }
21
22
 
@@ -35,6 +36,7 @@ static int regexec(const regex_t *preg, const char *string, size_t nmatch,
35
36
  in.text = string;
36
37
  in.len = strlen(string);
37
38
  in.icase = preg->icase;
39
+ in.multiline = preg->multiline;
38
40
  for (start = 0; start <= in.len; start++) {
39
41
  xt_re_match_result result;
40
42
  result.end = 0;
@@ -4,6 +4,7 @@ typedef struct {
4
4
  const char *text;
5
5
  size_t len;
6
6
  int icase;
7
+ int multiline;
7
8
  } xt_re_input;
8
9
 
9
10
  /* One capture on the immutable chain of the current search path. `parent`
@@ -90,9 +91,13 @@ static int xt_re_match_atom(xt_re_node *node, const xt_re_input *in, size_t pos,
90
91
  return cont(ctx, pos + 1, caps);
91
92
  return 0;
92
93
  case XT_RE_BOL:
93
- return pos == 0 ? cont(ctx, pos, caps) : 0;
94
+ return (pos == 0 || (in->multiline && pos > 0 && in->text[pos - 1] == '\n'))
95
+ ? cont(ctx, pos, caps)
96
+ : 0;
94
97
  case XT_RE_EOL:
95
- return pos == in->len ? cont(ctx, pos, caps) : 0;
98
+ return (pos == in->len || (in->multiline && pos < in->len && in->text[pos] == '\n'))
99
+ ? cont(ctx, pos, caps)
100
+ : 0;
96
101
  case XT_RE_GROUP: {
97
102
  xt_re_cap frame;
98
103
  xt_re_group_state state;
@@ -115,6 +120,7 @@ typedef struct {
115
120
  const xt_re_input *in;
116
121
  int min;
117
122
  int max; /* -1 == unbounded */
123
+ int lazy;
118
124
  xt_re_cont cont;
119
125
  void *ctx;
120
126
  } xt_re_repeat;
@@ -134,6 +140,12 @@ static int xt_re_repeat_next(void *v, size_t newpos, const xt_re_cap *caps) {
134
140
  }
135
141
 
136
142
  static int xt_re_repeat_try(xt_re_repeat *rep, size_t pos, int count, const xt_re_cap *caps) {
143
+ /* A lazy quantifier prefers the continuation (i.e. the shortest match) and
144
+ * only repeats when the rest of the pattern cannot match. This also keeps
145
+ * `[\s\S]+?` over a long shader from recursing once per byte. */
146
+ if (rep->lazy && count >= rep->min) {
147
+ if (rep->cont(rep->ctx, pos, caps)) return 1;
148
+ }
137
149
  if (rep->max < 0 || count < rep->max) {
138
150
  xt_re_repeat_step step;
139
151
  step.rep = rep;
@@ -141,13 +153,14 @@ static int xt_re_repeat_try(xt_re_repeat *rep, size_t pos, int count, const xt_r
141
153
  step.count = count;
142
154
  if (xt_re_match_atom(rep->atom, rep->in, pos, xt_re_repeat_next, &step, caps)) return 1;
143
155
  }
144
- if (count >= rep->min) return rep->cont(rep->ctx, pos, caps);
156
+ if (!rep->lazy && count >= rep->min) return rep->cont(rep->ctx, pos, caps);
145
157
  return 0;
146
158
  }
147
159
 
148
160
  static int xt_re_match_piece(xt_re_piece *piece, const xt_re_input *in, size_t pos,
149
161
  xt_re_cont cont, void *ctx, const xt_re_cap *caps) {
150
162
  xt_re_repeat rep;
163
+ rep.lazy = piece->lazy;
151
164
  switch (piece->quant) {
152
165
  case XT_RE_Q_STAR:
153
166
  rep.atom = piece->node;
@@ -33,7 +33,7 @@ static xt_re_node *xt_re_new_class(const unsigned char *bits) {
33
33
  return n;
34
34
  }
35
35
 
36
- static void xt_re_push_piece(xt_re_concat *c, xt_re_node *node, int quant) {
36
+ static void xt_re_push_piece(xt_re_concat *c, xt_re_node *node, int quant, int lazy) {
37
37
  if (c->count == c->capacity) {
38
38
  int next = c->capacity ? c->capacity * 2 : 4;
39
39
  xt_re_piece *grown = (xt_re_piece *)realloc(c->pieces, (size_t)next * sizeof(xt_re_piece));
@@ -43,6 +43,7 @@ static void xt_re_push_piece(xt_re_concat *c, xt_re_node *node, int quant) {
43
43
  }
44
44
  c->pieces[c->count].node = node;
45
45
  c->pieces[c->count].quant = quant;
46
+ c->pieces[c->count].lazy = lazy;
46
47
  c->count++;
47
48
  }
48
49
 
@@ -191,6 +192,7 @@ static void xt_re_parse_concat(xt_re_parser *p, xt_re_concat *out) {
191
192
  while (p->s[p->i] && p->s[p->i] != '|' && p->s[p->i] != ')') {
192
193
  xt_re_node *node = xt_re_parse_atom(p);
193
194
  int quant = XT_RE_Q_NONE;
195
+ int lazy = 0;
194
196
  if (p->error || !node) {
195
197
  p->error = 1;
196
198
  return;
@@ -205,7 +207,11 @@ static void xt_re_parse_concat(xt_re_parser *p, xt_re_concat *out) {
205
207
  quant = XT_RE_Q_QUEST;
206
208
  p->i++;
207
209
  }
208
- xt_re_push_piece(out, node, quant);
210
+ if (quant != XT_RE_Q_NONE && p->s[p->i] == '?') {
211
+ lazy = 1;
212
+ p->i++;
213
+ }
214
+ xt_re_push_piece(out, node, quant, lazy);
209
215
  }
210
216
  }
211
217
 
@@ -1,6 +1,7 @@
1
1
  #define REG_EXTENDED 1
2
2
  #define REG_ICASE 2
3
3
  #define REG_NOSUB 4
4
+ #define REG_MULTILINE 8
4
5
 
5
6
  typedef struct {
6
7
  int rm_so;
@@ -38,6 +39,7 @@ typedef struct {
38
39
  typedef struct {
39
40
  xt_re_node *node;
40
41
  int quant;
42
+ int lazy;
41
43
  } xt_re_piece;
42
44
 
43
45
  typedef struct {
@@ -55,4 +57,5 @@ struct xt_re_alt {
55
57
  typedef struct {
56
58
  xt_re_alt *root;
57
59
  int icase;
60
+ int multiline;
58
61
  } regex_t;
@@ -1,3 +1,9 @@
1
+ #if defined(_WIN32)
2
+ #define XT_REG_MULTILINE REG_MULTILINE
3
+ #else
4
+ #define XT_REG_MULTILINE REG_NEWLINE
5
+ #endif
6
+
1
7
  /* RegExp support built on POSIX ERE. JavaScript patterns are translated to
2
8
  * their POSIX equivalents, capturing groups are tracked so the JS capture
3
9
  * indices stay correct even after `(?:` groups are lowered, and the resulting
@@ -38,25 +44,41 @@ static char *xt_regexp_translate_js(const char *pattern, int *jsGroups, int *gro
38
44
  int consume = 0;
39
45
  if (c == '\\') {
40
46
  char next = (i + 1 < length) ? pattern[i + 1] : '\0';
41
- switch (next) {
42
- case 'r': literal = '\r'; consume = 1; break;
43
- case 'n': literal = '\n'; consume = 1; break;
44
- case 't': literal = '\t'; consume = 1; break;
45
- case 'f': literal = '\f'; consume = 1; break;
46
- case 'v': literal = '\v'; consume = 1; break;
47
- case 'd': replacement = "[0-9]"; consume = 1; break;
48
- case 'D': replacement = "[^0-9]"; consume = 1; break;
49
- case 'w': replacement = "[A-Za-z0-9_]"; consume = 1; break;
50
- case 'W': replacement = "[^A-Za-z0-9_]"; consume = 1; break;
51
- case 's': replacement = "[ \t\n\r\f\v]"; consume = 1; break;
52
- case 'S': replacement = "[^ \t\n\r\f\v]"; consume = 1; break;
53
- case 'x': {
54
- int hi = (i + 2 < length) ? xt_regex_hex_digit(pattern[i + 2]) : -1;
55
- int lo = (i + 3 < length) ? xt_regex_hex_digit(pattern[i + 3]) : -1;
56
- if (hi >= 0 && lo >= 0) { literal = (char)(hi * 16 + lo); consume = 3; }
57
- break;
47
+ if (inClass) {
48
+ /* Inside a class POSIX takes the contents without the brackets; a
49
+ * replacement like `[0-9]` would turn `[\d]` into `[[0-9]]`. */
50
+ switch (next) {
51
+ case 'r': literal = '\r'; consume = 1; break;
52
+ case 'n': literal = '\n'; consume = 1; break;
53
+ case 't': literal = '\t'; consume = 1; break;
54
+ case 'f': literal = '\f'; consume = 1; break;
55
+ case 'v': literal = '\v'; consume = 1; break;
56
+ case 'd': replacement = "0-9"; consume = 1; break;
57
+ case 'w': replacement = "A-Za-z0-9_"; consume = 1; break;
58
+ case 's': replacement = " \t\n\r\f\v"; consume = 1; break;
59
+ default: break;
60
+ }
61
+ } else {
62
+ switch (next) {
63
+ case 'r': literal = '\r'; consume = 1; break;
64
+ case 'n': literal = '\n'; consume = 1; break;
65
+ case 't': literal = '\t'; consume = 1; break;
66
+ case 'f': literal = '\f'; consume = 1; break;
67
+ case 'v': literal = '\v'; consume = 1; break;
68
+ case 'd': replacement = "[0-9]"; consume = 1; break;
69
+ case 'D': replacement = "[^0-9]"; consume = 1; break;
70
+ case 'w': replacement = "[A-Za-z0-9_]"; consume = 1; break;
71
+ case 'W': replacement = "[^A-Za-z0-9_]"; consume = 1; break;
72
+ case 's': replacement = "[ \t\n\r\f\v]"; consume = 1; break;
73
+ case 'S': replacement = "[^ \t\n\r\f\v]"; consume = 1; break;
74
+ case 'x': {
75
+ int hi = (i + 2 < length) ? xt_regex_hex_digit(pattern[i + 2]) : -1;
76
+ int lo = (i + 3 < length) ? xt_regex_hex_digit(pattern[i + 3]) : -1;
77
+ if (hi >= 0 && lo >= 0) { literal = (char)(hi * 16 + lo); consume = 3; }
78
+ break;
79
+ }
80
+ default: break;
58
81
  }
59
- default: break;
60
82
  }
61
83
  } else if (c == '[') {
62
84
  inClass = 1;
@@ -111,7 +133,10 @@ static int xt_regexp_run(xt_value regexpValue, xt_value input, int32_t start,
111
133
  xt_string *f = xt_as_string(regexp->flags);
112
134
  if (f) {
113
135
  const char *flagBytes = xt_string_bytes(f);
114
- for (uint32_t i = 0; i < f->length; i++) if (flagBytes[i] == 'i') flags |= REG_ICASE;
136
+ for (uint32_t i = 0; i < f->length; i++) {
137
+ if (flagBytes[i] == 'i') flags |= REG_ICASE;
138
+ if (flagBytes[i] == 'm') flags |= XT_REG_MULTILINE;
139
+ }
115
140
  }
116
141
  char *translated = xt_regexp_translate_js(xt_string_bytes(pattern), jsGroups, groupCount);
117
142
  if (!translated) return 0;
@@ -182,12 +207,26 @@ xt_value xt_regexp_exec(xt_value target, xt_value input) {
182
207
  xt_value textValue = xt_to_string(input);
183
208
  xt_string *text = xt_as_string(textValue);
184
209
  const char *textBytes = xt_string_bytes(text);
210
+ const int global = xt_regexp_is_global(target);
211
+ int32_t start = 0;
212
+ if (global) {
213
+ if (regexp->last_index < 0) regexp->last_index = 0;
214
+ start = (int32_t)regexp->last_index;
215
+ if ((size_t)start > text->length) {
216
+ regexp->last_index = 0;
217
+ free(matches);
218
+ free(groups);
219
+ return XT_NULL;
220
+ }
221
+ }
185
222
  int groupCount = 0;
186
- if (!xt_regexp_run(target, input, 0, matches, cap, groups, &groupCount)) {
223
+ if (!xt_regexp_run(target, input, start, matches, cap, groups, &groupCount)) {
224
+ if (global) regexp->last_index = 0;
187
225
  free(matches);
188
226
  free(groups);
189
227
  return XT_NULL;
190
228
  }
229
+ if (global) regexp->last_index = (double)xt_string_unit_offset(text, matches[0].rm_eo);
191
230
  int jsTotal = 0;
192
231
  for (int i = 0; i < groupCount; i++) if (groups[i] > jsTotal) jsTotal = groups[i];
193
232
  xt_value out = xt_array_new(0, NULL);
@@ -446,7 +485,7 @@ xt_value xt_regexp_get_property(xt_value target, xt_value key) {
446
485
  int flag = 0;
447
486
  if (k->length == 6 && memcmp(keyBytes, "source", 6) == 0) return regexp->source;
448
487
  if (k->length == 5 && memcmp(keyBytes, "flags", 5) == 0) return regexp->flags;
449
- if (k->length == 9 && memcmp(keyBytes, "lastIndex", 9) == 0) return xt_number(0);
488
+ if (k->length == 9 && memcmp(keyBytes, "lastIndex", 9) == 0) return xt_number(regexp->last_index);
450
489
  if (k->length == 6 && memcmp(keyBytes, "global", 6) == 0) flag = 'g';
451
490
  else if (k->length == 10 && memcmp(keyBytes, "ignoreCase", 10) == 0) flag = 'i';
452
491
  else if (k->length == 9 && memcmp(keyBytes, "multiline", 9) == 0) flag = 'm';
@@ -6,6 +6,7 @@ int xt_is_regexp(xt_value value) {
6
6
 
7
7
  xt_value xt_regexp_ctor(int32_t argc, xt_value *argv) {
8
8
  xt_regexp *regexp = (xt_regexp *)xt_alloc(sizeof(xt_regexp), XT_OBJECT_KIND_REGEXP);
9
+ regexp->last_index = 0;
9
10
  xt_value source = xt_arg_at(argc, argv, 0);
10
11
  xt_value flags = xt_arg_at(argc, argv, 1);
11
12
  if (XT_IS_OBJECT(source) && ((xt_object *)XT_GET_PTR(source))->header.kind == XT_OBJECT_KIND_REGEXP) {
@@ -10,9 +10,9 @@
10
10
  */
11
11
 
12
12
  #include "rt_internal.h"
13
+ #include <stdio.h>
13
14
 
14
15
  #include <math.h>
15
- #include <stdio.h>
16
16
  #include <stdlib.h>
17
17
  #include <string.h>
18
18
 
@@ -13,6 +13,8 @@
13
13
  * 1. fetch the pinned SDL3 source into `vendor/SDL` (gitignored),
14
14
  * 2. build `libSDL3.a` with CMake,
15
15
  * 2b. fetch + build static FreeType and HarfBuzz for text,
16
+ * 2c. fetch + build static glslang (GLSL ES -> SPIR-V) and SPIRV-Cross
17
+ * (SPIR-V -> Metal Shading Language),
16
18
  * 3. compile the engine translation units,
17
19
  * 4. merge everything into `gui.a` (libtool on macOS, `ar -M` elsewhere;
18
20
  * `gui.lib` on Windows, built from MSVC-compatible COFF objects).
@@ -28,6 +30,7 @@
28
30
  * SDL3_TAG SDL3 git tag to check out (default: release-3.2.10)
29
31
  * FREETYPE_VERSION FreeType version (default: 2.13.3)
30
32
  * HARFBUZZ_VERSION HarfBuzz version (default: 10.1.0)
33
+ * SPIRV_CROSS_VERSION SPIRV-Cross tag (default: vulkan-sdk-1.4.313.0)
31
34
  *
32
35
  * The C/C++ compiler is the same clang the driver resolves (see
33
36
  * `src/driver/toolchain-provider.ts`), so the archive always matches the ABI of
@@ -63,6 +66,17 @@ const freetypeSrc = join(vendorDir, "freetype");
63
66
  const freetypeBuild = join(vendorDir, "freetype-build");
64
67
  const harfbuzzSrc = join(vendorDir, "harfbuzz");
65
68
  const harfbuzzBuild = join(vendorDir, "harfbuzz-build");
69
+ /* glslang translates the GLSL ES that WebGL programs supply at run time; it is
70
+ * built statically and merged into the archive, so a compiled binary needs no
71
+ * Vulkan SDK. The SPIR-V headers are its only external dependency. */
72
+ const glslangSrc = join(vendorDir, "glslang");
73
+ const glslangBuild = join(vendorDir, "glslang-build");
74
+ const spirvHeadersSrc = join(glslangSrc, "External", "spirv-headers");
75
+ /* SPIRV-Cross turns the same SPIR-V into the Metal Shading Language that
76
+ * SDL_GPU's Metal backend consumes at run time (macOS). It needs no external
77
+ * headers: its own parser reads the module that glslang produced. */
78
+ const spirvCrossSrc = join(vendorDir, "spirv-cross");
79
+ const spirvCrossBuild = join(vendorDir, "spirv-cross-build");
66
80
  const objDir = join(root, "build", "gui-obj");
67
81
  const outDir = join(runtimeDir, "lib", platformSlug());
68
82
 
@@ -108,8 +122,14 @@ function cmakeToolchainArgs(): string[] {
108
122
  const SDL_TAG = process.env.SDL3_TAG || "release-3.2.10";
109
123
  const FREETYPE_VERSION = process.env.FREETYPE_VERSION || "2.13.3";
110
124
  const HARFBUZZ_VERSION = process.env.HARFBUZZ_VERSION || "10.1.0";
125
+ const GLSLANG_VERSION = process.env.GLSLANG_VERSION || "16.6.0";
126
+ const SPIRV_HEADERS_VERSION = process.env.SPIRV_HEADERS_VERSION || "vulkan-sdk-1.4.363.0";
127
+ const SPIRV_CROSS_VERSION = process.env.SPIRV_CROSS_VERSION || "vulkan-sdk-1.4.313.0";
111
128
  const FREETYPE_URL = `https://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VERSION}.tar.xz`;
112
129
  const HARFBUZZ_URL = `https://github.com/harfbuzz/harfbuzz/releases/download/${HARFBUZZ_VERSION}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz`;
130
+ const GLSLANG_URL = `https://codeload.github.com/KhronosGroup/glslang/tar.gz/refs/tags/${GLSLANG_VERSION}`;
131
+ const SPIRV_HEADERS_URL = `https://codeload.github.com/KhronosGroup/SPIRV-Headers/tar.gz/refs/tags/${SPIRV_HEADERS_VERSION}`;
132
+ const SPIRV_CROSS_URL = `https://codeload.github.com/KhronosGroup/SPIRV-Cross/tar.gz/refs/tags/${SPIRV_CROSS_VERSION}`;
113
133
 
114
134
  function fail(message: string): never {
115
135
  console.error(`xbintsc: ${message}`);
@@ -326,6 +346,17 @@ function freetypeArchive(): string | undefined {
326
346
  function harfbuzzArchive(): string | undefined {
327
347
  return builtLibrary(harfbuzzBuild, ["libharfbuzz.a", "harfbuzz.lib"], /^harfbuzz[-\d.]*\.lib$/);
328
348
  }
349
+ function glslangArchive(): string | undefined {
350
+ return builtLibrary(join(glslangBuild, "glslang"), ["libglslang.a", "glslang.lib"]);
351
+ }
352
+ function glslangLimitsArchive(): string | undefined {
353
+ return builtLibrary(join(glslangBuild, "glslang"),
354
+ ["libglslang-default-resource-limits.a", "glslang-default-resource-limits.lib"]);
355
+ }
356
+ /* SPIRV-Cross's MSL target pulls in its GLSL base class and the core module. */
357
+ function spirvCrossArchive(name: string): string | undefined {
358
+ return builtLibrary(spirvCrossBuild, [`lib${name}.a`, `${name}.lib`]);
359
+ }
329
360
 
330
361
  /* -- 1. SDL3 source ------------------------------------------------------- */
331
362
 
@@ -434,6 +465,50 @@ if (!existsSync(harfbuzzArchive() ?? "")) {
434
465
  console.log(`xbintsc: reusing existing ${harfbuzzArchive()}`);
435
466
  }
436
467
 
468
+ /* -- 2c. glslang (WebGL GLSL ES -> SPIR-V) -------------------------------- */
469
+
470
+ ensureTarballSource("glslang", GLSLANG_URL, `glslang-${GLSLANG_VERSION}`);
471
+ ensureTarballSource(join("glslang", "External", "spirv-headers"), SPIRV_HEADERS_URL,
472
+ `SPIRV-Headers-${SPIRV_HEADERS_VERSION}`);
473
+
474
+ if (!existsSync(glslangArchive() ?? "")) {
475
+ const cmake = configureCmake("glslang", glslangSrc, glslangBuild, [
476
+ "-DCMAKE_BUILD_TYPE=Release",
477
+ "-DBUILD_SHARED_LIBS=OFF",
478
+ "-DENABLE_OPT=OFF",
479
+ "-DENABLE_HLSL=OFF",
480
+ "-DENABLE_GLSLANG_BINARIES=OFF",
481
+ "-DGLSLANG_TESTS=OFF",
482
+ ]);
483
+ console.log("xbintsc: building static glslang");
484
+ run(cmake, ["--build", glslangBuild, "--config", "Release", "--parallel"]);
485
+ } else {
486
+ console.log(`xbintsc: reusing existing ${glslangArchive()}`);
487
+ }
488
+
489
+ /* -- 2d. SPIRV-Cross (SPIR-V -> Metal Shading Language) ------------------- */
490
+
491
+ ensureTarballSource("spirv-cross", SPIRV_CROSS_URL, `SPIRV-Cross-${SPIRV_CROSS_VERSION}`);
492
+
493
+ if (!existsSync(spirvCrossArchive("spirv-cross-msl") ?? "")) {
494
+ const cmake = configureCmake("SPIRV-Cross", spirvCrossSrc, spirvCrossBuild, [
495
+ "-DCMAKE_BUILD_TYPE=Release",
496
+ "-DSPIRV_CROSS_CLI=OFF",
497
+ "-DSPIRV_CROSS_ENABLE_TESTS=OFF",
498
+ /* Only the MSL target is used; skip the C++, HLSL, reflection and C APIs
499
+ * so the archive stays small. MSL links against the GLSL base class. */
500
+ "-DSPIRV_CROSS_ENABLE_HLSL=OFF",
501
+ "-DSPIRV_CROSS_ENABLE_CPP=OFF",
502
+ "-DSPIRV_CROSS_ENABLE_REFLECT=OFF",
503
+ "-DSPIRV_CROSS_ENABLE_UTIL=OFF",
504
+ "-DSPIRV_CROSS_ENABLE_C_API=OFF",
505
+ ]);
506
+ console.log("xbintsc: building static SPIRV-Cross");
507
+ run(cmake, ["--build", spirvCrossBuild, "--config", "Release", "--parallel"]);
508
+ } else {
509
+ console.log(`xbintsc: reusing existing ${spirvCrossArchive("spirv-cross-msl")}`);
510
+ }
511
+
437
512
  /* -- 3. engine objects ---------------------------------------------------- */
438
513
 
439
514
  mkdirSync(objDir, { recursive: true });
@@ -443,6 +518,9 @@ const includeFlags = [
443
518
  "-I", join(freetypeSrc, "include"),
444
519
  "-I", join(freetypeBuild, "include"),
445
520
  "-I", join(harfbuzzSrc, "src"),
521
+ "-I", glslangSrc,
522
+ "-I", join(spirvHeadersSrc, "include"),
523
+ "-I", spirvCrossSrc,
446
524
  ];
447
525
  const sources = readdirSync(engineDir)
448
526
  .filter((entry) => entry.endsWith(".cpp"))
@@ -470,10 +548,19 @@ for (const source of sources) {
470
548
  const sdl = sdlArchive();
471
549
  const freetype = freetypeArchive();
472
550
  const harfbuzz = harfbuzzArchive();
473
- if (!sdl || !freetype || !harfbuzz) {
474
- fail("one of the SDL3/FreeType/HarfBuzz archives was not found after building");
551
+ const glslang = glslangArchive();
552
+ const glslangLimits = glslangLimitsArchive();
553
+ const spirvCrossCore = spirvCrossArchive("spirv-cross-core");
554
+ const spirvCrossGlsl = spirvCrossArchive("spirv-cross-glsl");
555
+ const spirvCrossMsl = spirvCrossArchive("spirv-cross-msl");
556
+ if (!sdl || !freetype || !harfbuzz || !glslang || !glslangLimits ||
557
+ !spirvCrossCore || !spirvCrossGlsl || !spirvCrossMsl) {
558
+ fail("one of the SDL3/FreeType/HarfBuzz/glslang/SPIRV-Cross archives was not found after building");
475
559
  }
476
- const libraries = [sdl, freetype, harfbuzz];
560
+ const libraries = [
561
+ sdl, freetype, harfbuzz, glslang, glslangLimits,
562
+ spirvCrossCore, spirvCrossGlsl, spirvCrossMsl,
563
+ ];
477
564
 
478
565
  mkdirSync(outDir, { recursive: true });
479
566
  rmSync(output, { force: true });