xbintsc 0.6.12 → 0.6.13
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/src/ast/expressions.d.ts +6 -0
- package/dist/src/checker/type-infer.js +1 -1
- package/dist/src/checker/type-infer.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/codegen/generator/calls/literals.js +4 -1
- package/dist/src/codegen/generator/calls/literals.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +3 -1
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/operators.js +2 -6
- package/dist/src/codegen/generator/expressions/operators.js.map +1 -1
- package/dist/src/codegen/generator/expressions/primary.d.ts +9 -0
- package/dist/src/codegen/generator/expressions/primary.js +44 -7
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/driver/bundler/commonjs.js +1 -1
- package/dist/src/driver/bundler/commonjs.js.map +1 -1
- package/dist/src/driver/bundler/symbols.js +6 -0
- package/dist/src/driver/bundler/symbols.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/node/index.js +2 -0
- package/dist/src/extensions/node/index.js.map +1 -1
- package/dist/src/extensions/node/readline/index.d.ts +12 -0
- package/dist/src/extensions/node/readline/index.js +27 -0
- package/dist/src/extensions/node/readline/index.js.map +1 -0
- package/dist/src/parser/declarations/functions.js +6 -0
- package/dist/src/parser/declarations/functions.js.map +1 -1
- package/dist/src/parser/literals.js +1 -1
- package/dist/src/parser/literals.js.map +1 -1
- package/dist/tests/e2e/compile-modules.test.js +22 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- package/dist/tests/e2e/date-parse.test.js +17 -0
- package/dist/tests/e2e/date-parse.test.js.map +1 -1
- package/dist/tests/e2e/gui-browser.test.js +61 -0
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-css-coverage.test.js +39 -0
- package/dist/tests/e2e/gui-css-coverage.test.js.map +1 -1
- package/dist/tests/e2e/gui-css-features.test.js +100 -0
- package/dist/tests/e2e/gui-css-features.test.js.map +1 -1
- package/dist/tests/e2e/gui-dom.test.js +34 -0
- package/dist/tests/e2e/gui-dom.test.js.map +1 -1
- package/dist/tests/e2e/gui-errors.test.d.ts +11 -0
- package/dist/tests/e2e/gui-errors.test.js +68 -0
- package/dist/tests/e2e/gui-errors.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-shadow-sampler.test.js +7 -1
- package/dist/tests/e2e/gui-webgl2-shadow-sampler.test.js.map +1 -1
- package/dist/tests/e2e/harness.d.ts +4 -0
- package/dist/tests/e2e/harness.js +2 -0
- package/dist/tests/e2e/harness.js.map +1 -1
- package/dist/tests/e2e/readline.test.d.ts +7 -0
- package/dist/tests/e2e/readline.test.js +73 -0
- package/dist/tests/e2e/readline.test.js.map +1 -0
- package/doc/gui/api.md +15 -0
- package/doc/gui/dom.md +7 -2
- package/doc/gui/known-issues.md +2 -1
- package/doc/gui/layout.md +5 -1
- package/doc/implemented/node/readline.md +34 -0
- package/doc/implemented/node.md +1 -0
- package/doc/unimplemented/node/modules.md +2 -3
- package/doc/unimplemented/node.md +2 -2
- package/doc/zh-CN/gui/api.md +11 -0
- package/doc/zh-CN/gui/dom.md +6 -2
- package/doc/zh-CN/gui/known-issues.md +2 -1
- package/doc/zh-CN/gui/layout.md +4 -1
- package/doc/zh-CN/implemented/node/readline.md +33 -0
- package/doc/zh-CN/implemented/node.md +1 -0
- package/doc/zh-CN/unimplemented/node/modules.md +1 -2
- package/doc/zh-CN/unimplemented/node.md +2 -2
- package/package.json +7 -7
- package/runtime/ext_gui/browser_abort.cpp +2 -2
- package/runtime/ext_gui/browser_loop.cpp +1 -0
- package/runtime/ext_gui/browser_media.cpp +1 -1
- package/runtime/ext_gui/dom_api_canvas_image.cpp +2 -1
- package/runtime/ext_gui/dom_api_events.cpp +1 -1
- package/runtime/ext_gui/dom_api_internal.h +2 -0
- package/runtime/ext_gui/dom_api_node.cpp +18 -12
- package/runtime/ext_gui/dom_api_node_read.cpp +27 -0
- package/runtime/ext_gui/dom_api_proto.cpp +2 -0
- package/runtime/ext_gui/error_report.cpp +166 -0
- package/runtime/ext_gui/gui.cpp +16 -0
- package/runtime/ext_gui/gui_engine.h +13 -0
- package/runtime/ext_gui/gui_events.cpp +4 -1
- package/runtime/ext_gui/layout_inline.cpp +46 -14
- package/runtime/ext_gui/paint.cpp +22 -0
- package/runtime/ext_gui/script.cpp +1 -1
- package/runtime/ext_gui/style.cpp +1 -0
- package/runtime/ext_gui/style.h +13 -0
- package/runtime/ext_gui/style_print.cpp +99 -0
- package/runtime/ext_gui/style_text.cpp +79 -0
- package/runtime/ext_gui/webgl_texture.cpp +0 -8
- package/runtime/ext_gui/window.cpp +22 -8
- package/runtime/ext_gui/window_emit.cpp +1 -1
- package/runtime/ext_node/fs/parts/platform.inc +2 -0
- package/runtime/ext_node/readline/readline.c +572 -0
- package/runtime/rt.h +15 -0
- package/runtime/rt_internal.h +3 -2
- package/runtime/xt_io/exception.inc +29 -6
- package/runtime/xt_loop.c +36 -1
- package/runtime/xt_promise.c +26 -2
- package/runtime/xt_stdlib2/date.inc +2 -2
- package/runtime/xt_typed_array/elements.inc +0 -9
- package/runtime/xt_url.c +0 -6
- package/runtime/xt_url_object.c +1 -1
- package/src/ast/expressions.ts +6 -0
- package/src/checker/type-infer.ts +1 -1
- package/src/codegen/generator/calls/literals.ts +4 -1
- package/src/codegen/generator/expressions/assignment.ts +3 -1
- package/src/codegen/generator/expressions/operators.ts +2 -6
- package/src/codegen/generator/expressions/primary.ts +58 -6
- package/src/driver/bundler/commonjs.ts +1 -1
- package/src/driver/bundler/symbols.ts +6 -0
- package/src/driver/version.ts +1 -1
- package/src/extensions/node/index.ts +2 -0
- package/src/extensions/node/readline/index.ts +31 -0
- package/src/parser/declarations/functions.ts +6 -0
- package/src/parser/literals.ts +1 -1
package/runtime/xt_loop.c
CHANGED
|
@@ -108,6 +108,25 @@ double xt_monotonic_ms(void) {
|
|
|
108
108
|
#endif
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
/* Wall-clock milliseconds since the Unix epoch, for `Date.now()` and
|
|
112
|
+
* `new Date()`. `time(NULL)` only has second resolution, which silently broke
|
|
113
|
+
* elapsed-time math; this keeps the milliseconds the language exposes. */
|
|
114
|
+
double xt_wallclock_ms(void) {
|
|
115
|
+
#if defined(_WIN32)
|
|
116
|
+
FILETIME file_time;
|
|
117
|
+
GetSystemTimeAsFileTime(&file_time);
|
|
118
|
+
ULARGE_INTEGER ticks;
|
|
119
|
+
ticks.LowPart = file_time.dwLowDateTime;
|
|
120
|
+
ticks.HighPart = file_time.dwHighDateTime;
|
|
121
|
+
/* 100-ns ticks between 1601-01-01 and 1970-01-01. */
|
|
122
|
+
return (double)(int64_t)((ticks.QuadPart - 116444736000000000ULL) / 10000);
|
|
123
|
+
#else
|
|
124
|
+
struct timespec ts;
|
|
125
|
+
clock_gettime(CLOCK_REALTIME, &ts);
|
|
126
|
+
return (double)((int64_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
|
|
127
|
+
#endif
|
|
128
|
+
}
|
|
129
|
+
|
|
111
130
|
static void xt_loop_sleep_ms(int ms) { if (ms <= 0) return;
|
|
112
131
|
#if defined(_WIN32)
|
|
113
132
|
Sleep((DWORD)ms);
|
|
@@ -222,6 +241,22 @@ static void xt_loop_gc_register(void) {
|
|
|
222
241
|
xt_gc_register_root_provider(xt_loop_gc_scan_roots);
|
|
223
242
|
}
|
|
224
243
|
|
|
244
|
+
/* Run one timer callback under a host boundary. Without it an exception from a
|
|
245
|
+
* `setTimeout` callback terminates the process, which in a GUI program looks
|
|
246
|
+
* like the window vanishing; `xt_uncaught_exception` hands it to the host when
|
|
247
|
+
* one is installed and keeps the Node-like fatal default otherwise. */
|
|
248
|
+
static void xt_timer_invoke(xt_value callback, int32_t argc, xt_value *args) {
|
|
249
|
+
void *frame = xt_try_enter();
|
|
250
|
+
if (xt_try_setjmp(frame) == 0) {
|
|
251
|
+
xt_closure_call(callback, argc, args);
|
|
252
|
+
xt_try_leave(frame);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
xt_value error = xt_try_exception(frame);
|
|
256
|
+
xt_try_leave(frame);
|
|
257
|
+
xt_uncaught_exception(error);
|
|
258
|
+
}
|
|
259
|
+
|
|
225
260
|
/* Invoke every timer whose deadline has passed. Timers scheduled by a callback
|
|
226
261
|
* (or by a microtask) are left for the next reactor iteration, so a recursive
|
|
227
262
|
* `setTimeout(fn, 0)` cannot spin forever inside a single call. */
|
|
@@ -240,7 +275,7 @@ static void xt_timer_run_due(void) {
|
|
|
240
275
|
} else {
|
|
241
276
|
timer->active = 0;
|
|
242
277
|
}
|
|
243
|
-
if (XT_IS_FUNCTION(callback))
|
|
278
|
+
if (XT_IS_FUNCTION(callback)) xt_timer_invoke(callback, argc, args);
|
|
244
279
|
}
|
|
245
280
|
}
|
|
246
281
|
|
package/runtime/xt_promise.c
CHANGED
|
@@ -532,11 +532,30 @@ xt_value xt_queue_microtask(int32_t argc, xt_value *argv) {
|
|
|
532
532
|
|
|
533
533
|
/* -- reporting ------------------------------------------------------------ */
|
|
534
534
|
|
|
535
|
+
static xt_unhandled_rejection_handler g_unhandled_rejection_handler = NULL;
|
|
536
|
+
|
|
537
|
+
void xt_set_unhandled_rejection_handler(xt_unhandled_rejection_handler handler) {
|
|
538
|
+
g_unhandled_rejection_handler = handler;
|
|
539
|
+
}
|
|
540
|
+
|
|
535
541
|
int xt_promise_report_unhandled(void) {
|
|
542
|
+
if (xt_unhandled_count == 0) return 0;
|
|
543
|
+
/* The host handler runs JavaScript, which may observe promises and mutate
|
|
544
|
+
* the queue (removing entries and swapping in the tail). Iterate a snapshot
|
|
545
|
+
* and clear the queue afterwards, so every rejection is reported once. */
|
|
546
|
+
uint32_t count = xt_unhandled_count;
|
|
547
|
+
xt_promise **snapshot = (xt_promise **)malloc(sizeof(xt_promise *) * count);
|
|
548
|
+
if (!snapshot) abort();
|
|
549
|
+
memcpy(snapshot, xt_unhandled, sizeof(xt_promise *) * count);
|
|
536
550
|
int reported = 0;
|
|
537
|
-
for (uint32_t i = 0; i <
|
|
538
|
-
xt_promise *promise =
|
|
551
|
+
for (uint32_t i = 0; i < count; i++) {
|
|
552
|
+
xt_promise *promise = snapshot[i];
|
|
539
553
|
if (!promise || promise->observed) continue;
|
|
554
|
+
int consumed = 0;
|
|
555
|
+
if (g_unhandled_rejection_handler != NULL) {
|
|
556
|
+
consumed = g_unhandled_rejection_handler(promise->value, xt_promise_value(promise));
|
|
557
|
+
}
|
|
558
|
+
if (consumed) continue;
|
|
540
559
|
reported++;
|
|
541
560
|
/* `Error` (and its subclasses) carry a captured stack; everything else is
|
|
542
561
|
* stringified the way Node prints a rejection reason. */
|
|
@@ -549,5 +568,10 @@ int xt_promise_report_unhandled(void) {
|
|
|
549
568
|
fprintf(stderr, "Unhandled promise rejection\n");
|
|
550
569
|
}
|
|
551
570
|
}
|
|
571
|
+
free(snapshot);
|
|
572
|
+
for (uint32_t i = 0; i < xt_unhandled_count; i++) {
|
|
573
|
+
if (xt_unhandled[i]) xt_unhandled[i]->report_index = XT_PROMISE_UNLISTED;
|
|
574
|
+
}
|
|
575
|
+
xt_unhandled_count = 0;
|
|
552
576
|
return reported;
|
|
553
577
|
}
|
|
@@ -101,7 +101,7 @@ static double xt_date_parse_text(const char *text) {
|
|
|
101
101
|
|
|
102
102
|
xt_value xt_date_ctor(int32_t argc, xt_value *argv) {
|
|
103
103
|
xt_date *date = (xt_date *)xt_alloc(sizeof(xt_date), XT_OBJECT_KIND_DATE);
|
|
104
|
-
if (argc == 0) date->time = (
|
|
104
|
+
if (argc == 0) date->time = xt_wallclock_ms();
|
|
105
105
|
else if (argc == 1) {
|
|
106
106
|
if (XT_IS_STRING(argv[0])) {
|
|
107
107
|
date->time = xt_date_parse_text(xt_string_data(argv[0]));
|
|
@@ -126,7 +126,7 @@ xt_value xt_date_ctor(int32_t argc, xt_value *argv) {
|
|
|
126
126
|
xt_value xt_date_static(xt_value name, int32_t argc, xt_value *argv) {
|
|
127
127
|
const char *fn = xt_string_data(name);
|
|
128
128
|
if (!fn) return XT_UNDEFINED;
|
|
129
|
-
if (strcmp(fn, "now") == 0) return xt_number((
|
|
129
|
+
if (strcmp(fn, "now") == 0) return xt_number(xt_wallclock_ms());
|
|
130
130
|
if (strcmp(fn, "parse") == 0) {
|
|
131
131
|
xt_value input = xt_arg_at(argc, argv, 0);
|
|
132
132
|
if (!XT_IS_STRING(input)) return xt_number(NAN);
|
|
@@ -254,15 +254,6 @@ static int32_t xt_ta_relative(int32_t index, int32_t length) {
|
|
|
254
254
|
return index;
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
static xt_value xt_ta_append(xt_value array, int kind, xt_value value) {
|
|
258
|
-
uint32_t length = xt_ta_length(array);
|
|
259
|
-
xt_object_set(array, xt_string_from_cstr("length"), xt_number((double)(length + 1)));
|
|
260
|
-
xt_object_set(array, xt_string_from_cstr("byteLength"),
|
|
261
|
-
xt_number((double)(length + 1) * xt_ta_bytes[kind]));
|
|
262
|
-
xt_ta_store(array, kind, length, xt_to_number(value));
|
|
263
|
-
return array;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
257
|
uint32_t xt_typed_array_length(xt_value value) {
|
|
267
258
|
return xt_typed_array_kind_of(value) >= 0 ? xt_ta_length(value) : 0;
|
|
268
259
|
}
|
package/runtime/xt_url.c
CHANGED
|
@@ -99,12 +99,6 @@ static void xt_url_append_pair(xt_value entries, xt_value key, xt_value value) {
|
|
|
99
99
|
xt_array_push(entries, pair);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
static xt_value xt_url_string_at(xt_value text, size_t start, size_t length) {
|
|
103
|
-
xt_string *string = xt_as_string(text);
|
|
104
|
-
const char *bytes = xt_string_bytes(string);
|
|
105
|
-
return xt_string_new(bytes + start, length);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
102
|
/* Split a query string on `&`, then each item on the first `=`; decode both
|
|
109
103
|
* halves and append them. A leading `?` is ignored. */
|
|
110
104
|
static void xt_url_parse_into(xt_value params, xt_value input) {
|
package/runtime/xt_url_object.c
CHANGED
|
@@ -339,11 +339,11 @@ xt_value xt_url_ctor(int32_t argc, xt_value *argv) {
|
|
|
339
339
|
/* A reference without a scheme is a filesystem path. With no explicit base
|
|
340
340
|
* it resolves against the working directory, so `new URL("./a.txt")` is a
|
|
341
341
|
* `file://` URL rather than an unparseable relative one. */
|
|
342
|
-
char adjusted[XT_URL_MAX];
|
|
343
342
|
if (base[0] == 0 && xt_url_scheme_length(inputText) == 0) {
|
|
344
343
|
xt_url_cwd_base(base, sizeof(base));
|
|
345
344
|
}
|
|
346
345
|
#if defined(_WIN32)
|
|
346
|
+
char adjusted[XT_URL_MAX];
|
|
347
347
|
if (xt_url_scheme_length(inputText) == 0 && isalpha((unsigned char)inputText[0]) &&
|
|
348
348
|
inputText[1] == ':' && (inputText[2] == '\\' || inputText[2] == '/')) {
|
|
349
349
|
/* `C:\dir\file` -> `/C:/dir/file`, the path part of a file URL. */
|
package/src/ast/expressions.ts
CHANGED
|
@@ -122,6 +122,12 @@ export interface PropertyAssignment extends Node {
|
|
|
122
122
|
export interface ShorthandPropertyAssignment extends Node {
|
|
123
123
|
readonly kind: SyntaxKind.ShorthandPropertyAssignment;
|
|
124
124
|
readonly name: Identifier;
|
|
125
|
+
/**
|
|
126
|
+
* The literal property key as written (`"a"` in `{ a }`). Kept separate from
|
|
127
|
+
* `name.text`, which the bundler rewrites when it renames the binding: the
|
|
128
|
+
* key is part of the object shape, not a reference to the binding.
|
|
129
|
+
*/
|
|
130
|
+
readonly propertyName: string;
|
|
125
131
|
/** Present for `{ a = default }` when used as a destructuring target. */
|
|
126
132
|
readonly initializer?: Expression;
|
|
127
133
|
}
|
|
@@ -156,7 +156,7 @@ function objectLiteralType(context: InferenceContext, literal: ObjectLiteralExpr
|
|
|
156
156
|
if (!(property.accessor === "set" && properties.has(name))) properties.set(name, { type, optional: false });
|
|
157
157
|
} else if (element.kind === SyntaxKind.ShorthandPropertyAssignment) {
|
|
158
158
|
const shorthand = element as ShorthandPropertyAssignment;
|
|
159
|
-
properties.set(shorthand.
|
|
159
|
+
properties.set(shorthand.propertyName, { type: inferTypeOfExpression(context, shorthand.name), optional: false });
|
|
160
160
|
} else {
|
|
161
161
|
return ANY; // spread: the shape is not static
|
|
162
162
|
}
|
|
@@ -68,7 +68,10 @@ export const literalCallMethods: LiteralCallMethods = {
|
|
|
68
68
|
continue;
|
|
69
69
|
}
|
|
70
70
|
const identifier = property.name;
|
|
71
|
-
|
|
71
|
+
/* The key is the spelling in the source; `identifier.text` may have
|
|
72
|
+
* been rewritten to a bundler-mangled name when the variable itself is
|
|
73
|
+
* renamed. */
|
|
74
|
+
const key = this.stringValue(property.propertyName);
|
|
72
75
|
const value = this.emitIdentifier(identifier);
|
|
73
76
|
this.emit(` call i64 @xt_set(i64 ${object}, i64 ${key}, i64 ${value})`);
|
|
74
77
|
} else if (property.kind === SyntaxKind.SpreadElement) {
|
|
@@ -217,7 +217,9 @@ export const assignmentExpressionMethods: AssignmentExpressionMethods = {
|
|
|
217
217
|
continue;
|
|
218
218
|
}
|
|
219
219
|
const shorthand = property as ShorthandPropertyAssignment;
|
|
220
|
-
|
|
220
|
+
/* A destructuring target reads the source key, not the (possibly
|
|
221
|
+
* bundler-renamed) binding name. */
|
|
222
|
+
const key = this.stringValue(shorthand.propertyName);
|
|
221
223
|
excludedKeys.push(key);
|
|
222
224
|
let elementValue = this.reg();
|
|
223
225
|
this.emit(` ${elementValue} = call i64 @xt_get(i64 ${value}, i64 ${key})`);
|
|
@@ -184,12 +184,8 @@ export const operatorExpressionMethods: OperatorExpressionMethods = {
|
|
|
184
184
|
this.emit(` ${result} = call i64 @xt_bit_not(i64 ${operand})`);
|
|
185
185
|
return result;
|
|
186
186
|
}
|
|
187
|
-
case PrefixUnaryOperator.TypeOf:
|
|
188
|
-
|
|
189
|
-
const result = this.reg();
|
|
190
|
-
this.emit(` ${result} = call i64 @xt_typeof(i64 ${operand})`);
|
|
191
|
-
return result;
|
|
192
|
-
}
|
|
187
|
+
case PrefixUnaryOperator.TypeOf:
|
|
188
|
+
return this.emitTypeOf(node.operand);
|
|
193
189
|
case PrefixUnaryOperator.Void:
|
|
194
190
|
if (node.operand) this.emitExpression(node.operand);
|
|
195
191
|
return i64(XT_UNDEFINED);
|
|
@@ -34,6 +34,9 @@ import {
|
|
|
34
34
|
CTOR_FUNCTIONS,
|
|
35
35
|
ERROR_CONSTRUCTORS,
|
|
36
36
|
FIRST_CLASS_CONSTRUCTORS,
|
|
37
|
+
GLOBAL_FUNCTIONS,
|
|
38
|
+
NAMESPACE_PROPERTIES,
|
|
39
|
+
NAMESPACE_STATICS,
|
|
37
40
|
NAMESPACE_VALUES,
|
|
38
41
|
} from "../tables.js";
|
|
39
42
|
import type { GlobalValue } from "../../../extensions/registry.js";
|
|
@@ -42,6 +45,15 @@ import type { Generator } from "../generator.js";
|
|
|
42
45
|
export interface PrimaryExpressionMethods {
|
|
43
46
|
emitExpression(this: Generator, node: Expression): string;
|
|
44
47
|
emitIdentifier(this: Generator, identifier: Identifier): string;
|
|
48
|
+
/**
|
|
49
|
+
* `typeof` lowering. Host globals the compiler knows about but that have no
|
|
50
|
+
* first-class value (the console object, `JSON`, `performance`, extension
|
|
51
|
+
* builtins such as `requestAnimationFrame`) used to lower their operand as
|
|
52
|
+
* an undefined constant, so `typeof` reported "undefined" for a global the
|
|
53
|
+
* program could call. Answer these from the known global kinds instead.
|
|
54
|
+
*/
|
|
55
|
+
emitTypeOf(this: Generator, operand: Expression): string;
|
|
56
|
+
globalTypeOf(this: Generator, name: string): string | undefined;
|
|
45
57
|
emitGlobalValue(this: Generator, value: GlobalValue): string;
|
|
46
58
|
emitFunctionValue(this: Generator, symbol: SymbolInfo): string;
|
|
47
59
|
emitTemplate(this: Generator, node: TemplateLiteral): string;
|
|
@@ -111,12 +123,8 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
111
123
|
return this.emitExpression((node as { expression: Expression }).expression);
|
|
112
124
|
case SyntaxKind.DeleteExpression:
|
|
113
125
|
return this.emitDelete(node as DeleteExpression);
|
|
114
|
-
case SyntaxKind.TypeOfExpression:
|
|
115
|
-
|
|
116
|
-
const result = this.reg();
|
|
117
|
-
this.emit(` ${result} = call i64 @xt_typeof(i64 ${operand})`);
|
|
118
|
-
return result;
|
|
119
|
-
}
|
|
126
|
+
case SyntaxKind.TypeOfExpression:
|
|
127
|
+
return this.emitTypeOf((node as { expression: Expression }).expression);
|
|
120
128
|
case SyntaxKind.VoidExpression:
|
|
121
129
|
this.emitExpression((node as { expression: Expression }).expression);
|
|
122
130
|
return i64(XT_UNDEFINED);
|
|
@@ -166,6 +174,50 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
166
174
|
}
|
|
167
175
|
},
|
|
168
176
|
|
|
177
|
+
emitTypeOf(operand: Expression): string {
|
|
178
|
+
if (operand.kind === SyntaxKind.Identifier) {
|
|
179
|
+
const identifier = operand as Identifier;
|
|
180
|
+
/* A real binding (including an import) shadows the global, so lower it
|
|
181
|
+
* normally. Only an unresolved name can be a host global. */
|
|
182
|
+
if (!this.binding.symbolOfIdentifier.get(identifier)) {
|
|
183
|
+
const kind = this.globalTypeOf(identifier.text);
|
|
184
|
+
if (kind !== undefined) return this.stringValue(kind);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const value = this.emitExpression(operand);
|
|
188
|
+
const result = this.reg();
|
|
189
|
+
this.emit(` ${result} = call i64 @xt_typeof(i64 ${value})`);
|
|
190
|
+
return result;
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
/** Known kind of an unresolved global name, or undefined when the runtime
|
|
194
|
+
* getter should answer (`window`, `document`, `localStorage`, …). */
|
|
195
|
+
globalTypeOf(this: Generator, name: string): string | undefined {
|
|
196
|
+
/* A host extension function has no object value yet, but it is callable. */
|
|
197
|
+
if (this.builtins[name]) return "function";
|
|
198
|
+
/* Extension values are real host objects (or deliberately undefined for an
|
|
199
|
+
* unsupported type), so let `xt_typeof` inspect the getter's result. */
|
|
200
|
+
if (this.globalValues[name]) return undefined;
|
|
201
|
+
if (
|
|
202
|
+
ERROR_CONSTRUCTORS[name] ||
|
|
203
|
+
FIRST_CLASS_CONSTRUCTORS.has(name) ||
|
|
204
|
+
CTOR_FUNCTIONS[name] ||
|
|
205
|
+
BUILTIN_FUNCTION_VALUES[name] ||
|
|
206
|
+
GLOBAL_FUNCTIONS[name]
|
|
207
|
+
) {
|
|
208
|
+
return "function";
|
|
209
|
+
}
|
|
210
|
+
if (
|
|
211
|
+
name === "console" ||
|
|
212
|
+
NAMESPACE_STATICS[name] ||
|
|
213
|
+
NAMESPACE_VALUES[name] ||
|
|
214
|
+
NAMESPACE_PROPERTIES[name]
|
|
215
|
+
) {
|
|
216
|
+
return "object";
|
|
217
|
+
}
|
|
218
|
+
return undefined;
|
|
219
|
+
},
|
|
220
|
+
|
|
169
221
|
emitIdentifier(identifier: Identifier): string {
|
|
170
222
|
const symbol = this.binding.symbolOfIdentifier.get(identifier);
|
|
171
223
|
if (symbol) {
|
|
@@ -292,7 +292,7 @@ function isModuleExports(expression: Expression, bind: BindResult): boolean {
|
|
|
292
292
|
|
|
293
293
|
function literalPropertyName(property: ObjectLiteralElementLike): string | undefined {
|
|
294
294
|
if (property.kind === SyntaxKind.ShorthandPropertyAssignment) {
|
|
295
|
-
return (property as unknown as {
|
|
295
|
+
return (property as unknown as { propertyName: string }).propertyName;
|
|
296
296
|
}
|
|
297
297
|
if (property.kind === SyntaxKind.PropertyAssignment) {
|
|
298
298
|
const name = (property as unknown as { name: Node }).name;
|
|
@@ -14,6 +14,12 @@ export function hasModifier(node: Node, kind: ModifierKind): boolean {
|
|
|
14
14
|
|
|
15
15
|
export function declarationName(node: Node): Identifier | undefined {
|
|
16
16
|
switch (node.kind) {
|
|
17
|
+
/* Destructured bindings are declared with their identifier node (see
|
|
18
|
+
* `Binder.declareBinding`), so renaming must accept a bare Identifier too;
|
|
19
|
+
* otherwise the declaration keeps its old name while references are
|
|
20
|
+
* rewritten and the merged program fails to resolve it. */
|
|
21
|
+
case SyntaxKind.Identifier:
|
|
22
|
+
return node as Identifier;
|
|
17
23
|
case SyntaxKind.FunctionDeclaration:
|
|
18
24
|
case SyntaxKind.ClassDeclaration:
|
|
19
25
|
case SyntaxKind.EnumDeclaration:
|
package/src/driver/version.ts
CHANGED
|
@@ -33,6 +33,7 @@ import { utilModule } from "./util/index.js";
|
|
|
33
33
|
import { querystringModule } from "./querystring/index.js";
|
|
34
34
|
import { assertModule } from "./assert/index.js";
|
|
35
35
|
import { testModule } from "./test/index.js";
|
|
36
|
+
import { readlineModule } from "./readline/index.js";
|
|
36
37
|
|
|
37
38
|
/** Every Node module the extension currently provides. */
|
|
38
39
|
const modules: readonly NodeModule[] = [
|
|
@@ -57,6 +58,7 @@ const modules: readonly NodeModule[] = [
|
|
|
57
58
|
querystringModule,
|
|
58
59
|
assertModule,
|
|
59
60
|
testModule,
|
|
61
|
+
readlineModule,
|
|
60
62
|
];
|
|
61
63
|
|
|
62
64
|
export const nodeExtension: Extension = {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's `readline` module.
|
|
3
|
+
*
|
|
4
|
+
* `createInterface` (and the `Interface` constructor) return a line reader over
|
|
5
|
+
* standard input. The implementation offloads the blocking stdin read to the
|
|
6
|
+
* runtime's async I/O pool, so `question` and `on("line")` do not block timers
|
|
7
|
+
* or the event loop; it lives in
|
|
8
|
+
* `runtime/ext_node/readline/readline.c`. The cursor helpers write the same
|
|
9
|
+
* ANSI sequences Node emits.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { NodeModule } from "../module.js";
|
|
13
|
+
import { resolveFrom } from "../module.js";
|
|
14
|
+
import type { ModuleExports } from "../../registry.js";
|
|
15
|
+
|
|
16
|
+
const exports: ModuleExports = {
|
|
17
|
+
createInterface: { symbol: "xt_readline_create_interface" },
|
|
18
|
+
Interface: { symbol: "xt_readline_interface_ctor", isConstructor: true },
|
|
19
|
+
cursorTo: { symbol: "xt_readline_cursor_to" },
|
|
20
|
+
moveCursor: { symbol: "xt_readline_move_cursor" },
|
|
21
|
+
clearLine: { symbol: "xt_readline_clear_line" },
|
|
22
|
+
clearScreenDown: { symbol: "xt_readline_clear_screen_down" },
|
|
23
|
+
emitKeypressEvents: { symbol: "xt_readline_emit_keypress_events" },
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const readlineModule: NodeModule = {
|
|
27
|
+
name: "readline",
|
|
28
|
+
runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/readline/readline.c")],
|
|
29
|
+
builtins: () => ({}),
|
|
30
|
+
exports: () => exports,
|
|
31
|
+
};
|
|
@@ -227,6 +227,12 @@ export const declarationFunctionMethods: DeclarationFunctionMethods = {
|
|
|
227
227
|
name = this.parseBindingName();
|
|
228
228
|
} else {
|
|
229
229
|
name = first;
|
|
230
|
+
/* `{ a }` reads the key `a`; record it in a separate node so a later
|
|
231
|
+
* rename of the binding does not change which property is read. */
|
|
232
|
+
propertyName =
|
|
233
|
+
first.kind === SyntaxKind.Identifier
|
|
234
|
+
? { kind: SyntaxKind.Identifier, text: first.text, escaped: first.escaped, start: first.start, end: first.end }
|
|
235
|
+
: first;
|
|
230
236
|
}
|
|
231
237
|
} else {
|
|
232
238
|
// Array element, or a nested pattern used as an object value.
|
package/src/parser/literals.ts
CHANGED
|
@@ -144,7 +144,7 @@ export const literalMethods: LiteralMethods = {
|
|
|
144
144
|
initializer = this.parseAssignmentExpression();
|
|
145
145
|
end = initializer.end;
|
|
146
146
|
}
|
|
147
|
-
const shorthand: ShorthandPropertyAssignment = { kind: SyntaxKind.ShorthandPropertyAssignment, name, initializer, start, end };
|
|
147
|
+
const shorthand: ShorthandPropertyAssignment = { kind: SyntaxKind.ShorthandPropertyAssignment, name, propertyName: name.text, initializer, start, end };
|
|
148
148
|
properties.push(shorthand);
|
|
149
149
|
} else {
|
|
150
150
|
this.error(DiagnosticCode.UnexpectedToken, "Invalid object literal member");
|