wasm-idle 1.1.2 → 1.2.0

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 (121) hide show
  1. package/README.md +134 -82
  2. package/dist/container/bash-profile.d.ts +80 -0
  3. package/dist/container/bash-profile.js +328 -0
  4. package/dist/{playground/container → container}/binding.d.ts +21 -8
  5. package/dist/{playground/container → container}/binding.js +109 -25
  6. package/dist/{playground/container → container}/clang-runtime.d.ts +11 -7
  7. package/dist/container/clang-runtime.js +561 -0
  8. package/dist/container/client.d.ts +14 -0
  9. package/dist/{playground/container → container}/client.js +2 -6
  10. package/dist/{playground/container → container}/explorer.d.ts +1 -1
  11. package/dist/container/index.d.ts +11 -0
  12. package/dist/container/index.js +11 -0
  13. package/dist/container/owner-worker.d.ts +19 -0
  14. package/dist/container/owner-worker.js +464 -0
  15. package/dist/{playground/container → container}/protocol.d.ts +12 -1
  16. package/dist/{playground/container → container}/runtime-adapter.d.ts +13 -11
  17. package/dist/{playground/container → container}/runtime-adapter.js +104 -41
  18. package/dist/{playground/container → container}/shell-control.d.ts +2 -2
  19. package/dist/{playground/container → container}/shell-control.js +93 -36
  20. package/dist/{playground/container → container}/workspace.d.ts +5 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/playground/assetBridge.js +5 -2
  23. package/dist/playground/assets.d.ts +8 -0
  24. package/dist/playground/clang.d.ts +5 -1
  25. package/dist/playground/clang.js +61 -5
  26. package/dist/playground/compiledLldb.d.ts +41 -0
  27. package/dist/playground/compiledLldb.js +167 -0
  28. package/dist/playground/d.d.ts +4 -1
  29. package/dist/playground/d.js +78 -9
  30. package/dist/playground/debugDeadline.d.ts +12 -0
  31. package/dist/playground/debugDeadline.js +34 -0
  32. package/dist/playground/debugMailbox.d.ts +12 -0
  33. package/dist/playground/debugMailbox.js +77 -0
  34. package/dist/playground/go.js +9 -4
  35. package/dist/playground/goDebugInstrumentation.js +24 -44
  36. package/dist/playground/java-debug-FMHDKUN6.js +124 -0
  37. package/dist/playground/java-debug-notices.txt +492 -0
  38. package/dist/playground/java.d.ts +17 -1
  39. package/dist/playground/java.js +159 -3
  40. package/dist/playground/javaDebug.d.ts +62 -0
  41. package/dist/playground/javaDebug.js +305 -0
  42. package/dist/playground/javaDebugBridge.d.ts +6 -0
  43. package/dist/playground/javaDebugBridge.js +250 -0
  44. package/dist/playground/javaDebugSource.d.ts +9 -0
  45. package/dist/playground/javaDebugSource.js +4 -0
  46. package/dist/playground/javaRuntimeErrors.js +34 -1
  47. package/dist/playground/lean4Assets.d.ts +1 -25
  48. package/dist/playground/lean4Assets.js +2 -123
  49. package/dist/playground/lfortranAssets.d.ts +2 -2
  50. package/dist/playground/lldbSession.d.ts +23 -2
  51. package/dist/playground/lldbSession.js +278 -58
  52. package/dist/playground/lldbSourcePath.d.ts +2 -0
  53. package/dist/playground/lldbSourcePath.js +9 -0
  54. package/dist/playground/lua.d.ts +20 -1
  55. package/dist/playground/lua.js +190 -8
  56. package/dist/playground/luaDebug.d.ts +1 -0
  57. package/dist/playground/luaDebug.js +1 -0
  58. package/dist/playground/nim.d.ts +1 -0
  59. package/dist/playground/nim.js +8 -0
  60. package/dist/playground/objectivec.d.ts +7 -6
  61. package/dist/playground/objectivec.js +75 -9
  62. package/dist/playground/options.d.ts +10 -4
  63. package/dist/playground/python.d.ts +8 -1
  64. package/dist/playground/python.js +81 -6
  65. package/dist/playground/ruby.d.ts +10 -1
  66. package/dist/playground/ruby.js +66 -1
  67. package/dist/playground/rubyDebug.d.ts +21 -0
  68. package/dist/playground/rubyDebug.js +128 -0
  69. package/dist/playground/rust.d.ts +5 -1
  70. package/dist/playground/rust.js +128 -46
  71. package/dist/playground/sandbox.d.ts +8 -1
  72. package/dist/playground/staticWorkerRuntime.js +8 -2
  73. package/dist/playground/stdinBuffer.d.ts +1 -1
  74. package/dist/playground/stdinBuffer.js +19 -2
  75. package/dist/playground/tinygo.js +7 -0
  76. package/dist/playground/typescript.js +8 -0
  77. package/dist/playground/v.d.ts +3 -2
  78. package/dist/playground/v.js +66 -12
  79. package/dist/playground/wasmC3Version.d.ts +2 -2
  80. package/dist/playground/wasmC3Version.js +2 -2
  81. package/dist/playground/wasmLean4Version.d.ts +1 -110
  82. package/dist/playground/wasmLean4Version.js +2 -111
  83. package/dist/playground/wasmLfortranVersion.d.ts +2 -2
  84. package/dist/playground/wasmLfortranVersion.js +2 -2
  85. package/dist/playground/wasmLuaVersion.d.ts +1 -1
  86. package/dist/playground/wasmLuaVersion.js +1 -1
  87. package/dist/playground/wasmRustVersion.d.ts +26 -38
  88. package/dist/playground/wasmRustVersion.js +25 -40
  89. package/dist/playground/worker/clang.js +1 -1
  90. package/dist/playground/worker/cobol.js +1 -1
  91. package/dist/playground/worker/d.js +51 -2
  92. package/dist/playground/worker/fortran.js +1 -1
  93. package/dist/playground/worker/java.js +188 -35
  94. package/dist/playground/worker/javaDebugEvaluator.d.ts +16 -0
  95. package/dist/playground/worker/javaDebugEvaluator.js +44 -0
  96. package/dist/playground/worker/javaDebugRuntime.d.ts +24 -0
  97. package/dist/playground/worker/javaDebugRuntime.js +315 -0
  98. package/dist/playground/worker/javaOutput.d.ts +11 -0
  99. package/dist/playground/worker/javaOutput.js +54 -0
  100. package/dist/playground/worker/lua.js +13 -0
  101. package/dist/playground/worker/python.js +57 -22
  102. package/dist/playground/worker/ruby.js +13 -0
  103. package/dist/playground/worker/rubyDebugPreview.d.ts +2 -0
  104. package/dist/playground/worker/rubyDebugPreview.js +80 -0
  105. package/dist/playground/worker/rubyTracepoint.d.ts +16 -0
  106. package/dist/playground/worker/rubyTracepoint.js +162 -0
  107. package/dist/playground/worker/rust.js +4 -1
  108. package/dist/playground/worker/v.js +30 -5
  109. package/dist/playground/zig.js +4 -0
  110. package/package.json +55 -11
  111. package/dist/playground/container/ContainerExplorer.svelte +0 -307
  112. package/dist/playground/container/ContainerExplorer.svelte.d.ts +0 -14
  113. package/dist/playground/container/clang-runtime.js +0 -343
  114. package/dist/playground/container/client.d.ts +0 -15
  115. package/dist/playground/container/owner.worker.d.ts +0 -1
  116. package/dist/playground/container/owner.worker.js +0 -390
  117. package/dist/playground/container/release.d.ts +0 -31
  118. package/dist/playground/container/release.js +0 -612
  119. /package/dist/{playground/container → container}/explorer.js +0 -0
  120. /package/dist/{playground/container → container}/protocol.js +0 -0
  121. /package/dist/{playground/container → container}/workspace.js +0 -0
@@ -0,0 +1,250 @@
1
+ /** Values stay in the real Java VM while a stopped hook services inspection requests. */
2
+ export function createJavaDebugBridge(className, packageName = 'wasm_idle_debug') {
3
+ if (![className, packageName].every((name) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(name)))
4
+ throw new Error('Invalid Java debugger helper name');
5
+ return {
6
+ qualifiedName: `${packageName}.${className}`,
7
+ sourceFileName: `${className}.java`,
8
+ source: String.raw `package ${packageName};
9
+ import org.teavm.jso.JSObject;
10
+ import org.teavm.jso.browser.Window;
11
+ import org.teavm.jso.core.JSFunction;
12
+ import org.teavm.jso.core.JSMapLike;
13
+ import org.teavm.jso.core.JSString;
14
+ import org.teavm.jso.core.JSNumber;
15
+ import java.util.ArrayList;
16
+ import java.lang.String;
17
+ import java.lang.StringBuilder;
18
+ import java.lang.Throwable;
19
+ import java.lang.StackTraceElement;
20
+
21
+ public final class ${className} {
22
+ private static final class Captured {
23
+ final String kind;
24
+ final Object value;
25
+ Captured(String kind, Object value) { this.kind = kind; this.value = value; }
26
+ }
27
+ public static Object capture(boolean value) { return new Captured("boolean", value); }
28
+ public static Object capture(byte value) { return new Captured("byte", value); }
29
+ public static Object capture(short value) { return new Captured("short", value); }
30
+ public static Object capture(char value) { return new Captured("char", value); }
31
+ public static Object capture(int value) { return new Captured("int", value); }
32
+ public static Object capture(long value) { return new Captured("long", value); }
33
+ public static Object capture(float value) { return new Captured("float", value); }
34
+ public static Object capture(double value) { return new Captured("double", value); }
35
+ public static Object capture(String value) { return new Captured("java.lang.String", value); }
36
+ public static Object capture(Object value) { return new Captured("reference", value); }
37
+ private static String quote(String value) {
38
+ if (value == null) return "null";
39
+ StringBuilder text = new StringBuilder("\"");
40
+ String hex = "0123456789abcdef";
41
+ for (int i = 0; i < value.length(); i++) {
42
+ char c = value.charAt(i);
43
+ if (c == '\\' || c == '"') text.append('\\').append(c);
44
+ else if (c < 32 || (c >= 0xd800 && c <= 0xdfff)) {
45
+ text.append("\\u").append(hex.charAt((c >>> 12) & 15))
46
+ .append(hex.charAt((c >>> 8) & 15)).append(hex.charAt((c >>> 4) & 15))
47
+ .append(hex.charAt(c & 15));
48
+ } else text.append(c);
49
+ }
50
+ return text.append('"').toString();
51
+ }
52
+ private static JSObject target() {
53
+ Window window = Window.current();
54
+ if (window == null) return null;
55
+ JSMapLike<JSObject> globals = window.cast();
56
+ return globals.get("wasmIdleJavaDebug");
57
+ }
58
+ public static boolean poll(String source, int line, int column) {
59
+ JSObject target = target();
60
+ if (target == null) return false;
61
+ JSMapLike<JSObject> methods = target.cast();
62
+ JSFunction poll = methods.get("poll").cast();
63
+ return poll.call(target, JSString.valueOf(source), JSNumber.valueOf(line), JSNumber.valueOf(column)) != null;
64
+ }
65
+ public static void hit(String source, int line, int column) {
66
+ if (poll(source, line, column)) hit(source, line, column, new String[0], new String[0], new Object[0]);
67
+ }
68
+ public static void hit(String source, int line, int column, String[] names, String[] types, Object[] values) {
69
+ JSObject target = target();
70
+ if (target == null) return;
71
+ JSMapLike<JSObject> methods = target.cast();
72
+ Snapshot snapshot = new Snapshot(names, types, values);
73
+ StackTraceElement[] frames = new Throwable().getStackTrace();
74
+ StringBuilder result = new StringBuilder("[");
75
+ for (int i = 0; i < frames.length && i < 64; i++) {
76
+ if (i > 0) result.append(',');
77
+ StackTraceElement frame = frames[i];
78
+ result.append('[').append(quote(frame.getClassName())).append(',')
79
+ .append(quote(frame.getMethodName())).append(',')
80
+ .append(quote(frame.getFileName())).append(',')
81
+ .append(frame.getLineNumber()).append(']');
82
+ }
83
+ result.append(']');
84
+ JSFunction pause = methods.get("pause").cast();
85
+ JSObject request = (JSObject) pause.call(target, JSString.valueOf(source), JSNumber.valueOf(line),
86
+ JSNumber.valueOf(column), JSString.valueOf(result.toString()), JSNumber.valueOf(frames.length),
87
+ JSString.valueOf(snapshot.variables(0, 0, 50)), JSNumber.valueOf(names.length));
88
+ while (request != null) {
89
+ JSMapLike<JSObject> fields = request.cast();
90
+ int id = ((JSNumber) fields.get("id")).intValue();
91
+ int stopId = ((JSNumber) fields.get("stopId")).intValue();
92
+ String op = ((JSString) fields.get("op")).stringValue();
93
+ String response = null;
94
+ String error = null;
95
+ try {
96
+ if (op.equals("context")) response = snapshot.context();
97
+ else if (op.equals("variables")) response = snapshot.variables(
98
+ ((JSNumber) fields.get("reference")).intValue(),
99
+ ((JSNumber) fields.get("start")).intValue(),
100
+ ((JSNumber) fields.get("count")).intValue());
101
+ else throw new IllegalArgumentException("Unknown Java inspection request");
102
+ } catch (Throwable failure) {
103
+ error = failure.getClass().getName() + ": " + failure.getMessage();
104
+ }
105
+ JSFunction reply = methods.get("reply").cast();
106
+ request = (JSObject) reply.call(target, JSNumber.valueOf(id), JSNumber.valueOf(stopId),
107
+ response == null ? null : JSString.valueOf(response),
108
+ error == null ? null : JSString.valueOf(error));
109
+ }
110
+ }
111
+
112
+ private static final class Snapshot {
113
+ final String[] names;
114
+ final String[] types;
115
+ final String[] kinds;
116
+ final Object[] values;
117
+ final ArrayList<Object> handles = new ArrayList<Object>();
118
+ Snapshot(String[] names, String[] types, Object[] values) {
119
+ if (names.length != types.length || names.length != values.length || names.length > 1024)
120
+ throw new IllegalArgumentException("Invalid Java local snapshot");
121
+ this.names = names;
122
+ this.types = types;
123
+ this.values = new Object[values.length];
124
+ this.kinds = new String[values.length];
125
+ for (int i = 0; i < values.length; i++) {
126
+ if (!(values[i] instanceof Captured)) throw new IllegalArgumentException("Missing Java static capture type");
127
+ Captured captured = (Captured) values[i];
128
+ this.values[i] = captured.value;
129
+ this.kinds[i] = captured.kind;
130
+ }
131
+ }
132
+ int handle(Object value) {
133
+ for (int i = 0; i < handles.size(); i++) if (handles.get(i) == value) return i + 1;
134
+ if (handles.size() >= 4096) return 0;
135
+ handles.add(value);
136
+ return handles.size();
137
+ }
138
+ int length(Object value) {
139
+ if (value instanceof Object[]) return ((Object[]) value).length;
140
+ if (value instanceof int[]) return ((int[]) value).length;
141
+ if (value instanceof long[]) return ((long[]) value).length;
142
+ if (value instanceof byte[]) return ((byte[]) value).length;
143
+ if (value instanceof short[]) return ((short[]) value).length;
144
+ if (value instanceof char[]) return ((char[]) value).length;
145
+ if (value instanceof boolean[]) return ((boolean[]) value).length;
146
+ if (value instanceof float[]) return ((float[]) value).length;
147
+ if (value instanceof double[]) return ((double[]) value).length;
148
+ return -1;
149
+ }
150
+ Object element(Object value, int index) {
151
+ if (value instanceof Object[]) return ((Object[]) value)[index];
152
+ if (value instanceof int[]) return ((int[]) value)[index];
153
+ if (value instanceof long[]) return ((long[]) value)[index];
154
+ if (value instanceof byte[]) return ((byte[]) value)[index];
155
+ if (value instanceof short[]) return ((short[]) value)[index];
156
+ if (value instanceof char[]) return ((char[]) value)[index];
157
+ if (value instanceof boolean[]) return ((boolean[]) value)[index];
158
+ if (value instanceof float[]) return ((float[]) value)[index];
159
+ if (value instanceof double[]) return ((double[]) value)[index];
160
+ throw new IllegalArgumentException("Java object has no indexed children");
161
+ }
162
+ String scalarType(Object value) {
163
+ if (value instanceof String) return "java.lang.String";
164
+ if (value instanceof Boolean) return "boolean";
165
+ if (value instanceof Character) return "char";
166
+ if (value instanceof Byte) return "byte";
167
+ if (value instanceof Short) return "short";
168
+ if (value instanceof Integer) return "int";
169
+ if (value instanceof Long) return "long";
170
+ if (value instanceof Float) return "float";
171
+ if (value instanceof Double) return "double";
172
+ return value == null ? "null" : value.getClass().getName();
173
+ }
174
+ String scalar(Object value) {
175
+ if (value instanceof String) return (String) value;
176
+ if (value instanceof Boolean) return Boolean.toString(((Boolean) value).booleanValue());
177
+ if (value instanceof Character) return Integer.toString(((Character) value).charValue());
178
+ if (value instanceof Byte) return Byte.toString(((Byte) value).byteValue());
179
+ if (value instanceof Short) return Short.toString(((Short) value).shortValue());
180
+ if (value instanceof Integer) return Integer.toString(((Integer) value).intValue());
181
+ if (value instanceof Long) return Long.toString(((Long) value).longValue());
182
+ if (value instanceof Float) return Float.toString(((Float) value).floatValue());
183
+ if (value instanceof Double) return Double.toString(((Double) value).doubleValue());
184
+ return null;
185
+ }
186
+ String describe(String name, String declaredType, Object value) {
187
+ String type = declaredType.equals("var") || declaredType.length() == 0 ? scalarType(value) : declaredType;
188
+ String display;
189
+ int reference = 0;
190
+ int size = length(value);
191
+ if (value == null) display = "null";
192
+ else if (value instanceof String) {
193
+ String text = (String) value;
194
+ display = quote(text.length() > 1024 ? text.substring(0, 1024) + "…" : text);
195
+ } else if (value instanceof Character) {
196
+ String text = quote(String.valueOf(((Character) value).charValue()));
197
+ display = "'" + text.substring(1, text.length() - 1).replace("'", "\\'") + "'";
198
+ }
199
+ else if (scalar(value) != null) display = scalar(value);
200
+ else if (size >= 0) {
201
+ reference = handle(value);
202
+ display = value.getClass().getName() + " (" + size + ")";
203
+ } else display = value.getClass().getName() + "@" + handle(value);
204
+ return "{\"name\":" + quote(name) + ",\"type\":" + quote(type)
205
+ + ",\"value\":" + quote(display) + ",\"variablesReference\":" + reference
206
+ + (size >= 0 ? ",\"indexedVariables\":" + size : "") + "}";
207
+ }
208
+ String variables(int reference, int start, int count) {
209
+ if (start < 0 || count < 0 || count > 1000 || reference < 0 || reference > handles.size())
210
+ throw new IllegalArgumentException("Invalid Java variable page");
211
+ Object array = reference == 0 ? null : handles.get(reference - 1);
212
+ int size = reference == 0 ? names.length : length(array);
213
+ if (size < 0) throw new IllegalArgumentException("Java object has no indexed children");
214
+ StringBuilder result = new StringBuilder("[");
215
+ int end = start >= size ? size : start + Math.min(count, size - start);
216
+ for (int i = start; i < end; i++) {
217
+ if (i > start) result.append(',');
218
+ String type = reference == 0 && types[i].equals("var")
219
+ ? (kinds[i].equals("reference") ? (values[i] == null ? "null" : values[i].getClass().getName()) : kinds[i])
220
+ : reference == 0 ? types[i] : "";
221
+ result.append(reference == 0 ? describe(names[i], type, values[i])
222
+ : describe("[" + i + "]", "", element(array, i)));
223
+ }
224
+ return result.append(']').toString();
225
+ }
226
+ String context() {
227
+ StringBuilder result = new StringBuilder("{\"bindings\":[");
228
+ int written = 0;
229
+ for (int i = 0; i < names.length; i++) {
230
+ if (names[i].equals("this")) continue;
231
+ if (written++ > 0) result.append(',');
232
+ Object value = values[i];
233
+ String type = kinds[i].equals("reference") ? types[i] : kinds[i];
234
+ String text = scalar(value);
235
+ String unavailable = null;
236
+ if (kinds[i].equals("reference")) unavailable = "Live Java reference expressions are not supported";
237
+ else if (value instanceof String && ((String) value).length() > 65536) unavailable = "Java String exceeds the evaluation snapshot limit";
238
+ result.append("{\"name\":").append(quote(names[i])).append(",\"type\":").append(quote(type))
239
+ .append(",\"value\":").append(quote(unavailable == null ? text : null));
240
+ if (unavailable != null) result.append(",\"unavailable\":").append(quote(unavailable));
241
+ result.append('}');
242
+ if (result.length() > 900000) throw new IllegalArgumentException("Java evaluation context exceeds its limit");
243
+ }
244
+ return result.append("]}").toString();
245
+ }
246
+ }
247
+ }
248
+ `
249
+ };
250
+ }
@@ -0,0 +1,9 @@
1
+ export interface JavaDebugLocation {
2
+ line: number;
3
+ column: number;
4
+ }
5
+ /** Add statement callbacks using the upstream Java CST; javac/TeaVM still execute the program. */
6
+ export declare function instrumentJavaDebugSource(source: string, sourcePath: string, bridgeClass: string): {
7
+ code: string;
8
+ locations: JavaDebugLocation[];
9
+ };
@@ -0,0 +1,4 @@
1
+ // Third-party license texts: java-debug-notices.txt beside the shared parser.
2
+ import{a as l,c as B}from"./java-debug-FMHDKUN6.js";var I=new Set(["methodDeclaration","interfaceMethodDeclaration","constructorDeclaration","compactConstructorDeclaration","lambdaExpression","staticInitializer","instanceInitializer"]);function k(c,u){return Object.values(u?{[u]:c.children[u]??[]}:c.children).flat().filter(s=>"children"in s)}l(k,"nodes");function i(c,u){return k(c,u)[0]}l(i,"firstNode");function $(c,u){let s=c.children[u]?.[0];return s&&!("children"in s)?s:void 0}l($,"firstToken");function J(c,u){let s=new Map,g=[],v=l(e=>{g.push(e);for(let n of k(e))s.set(n,e),v(n)},"index");v(c);let m=l(e=>e?u.slice(e.location.startOffset,e.location.endOffset+1):"","text"),y=l((e,n)=>{for(let t=e;t;t=s.get(t))if(n(t))return t},"nearest"),S=new Set(["classBody","interfaceBody","enumBody","recordBody"]),w=l(e=>{for(let n=e;n;n=s.get(n)){if(I.has(n.name))return n;if(S.has(n.name))return}},"contextOf"),b=l((e,n)=>n.has(e.name)?[e]:k(e).flatMap(t=>b(t,n)),"descendants"),D=l((e,n)=>Object.entries(e.children).some(([t,a])=>t.endsWith("Modifier")&&a.some(r=>"children"in r&&$(r,n)!==void 0)),"hasModifier"),C=new Set(g.filter(e=>e.name==="methodDeclaration"&&m(i(i(e,"methodHeader"),"result")).trim()==="record")),O=new Set(["normalClassDeclaration","normalInterfaceDeclaration","enumDeclaration","recordDeclaration"]),N=[],o=l((e,n,t,a,r=a.location.startOffset)=>{let d=i(e,"variableDeclaratorId"),h=$(d??e,"Identifier")?.image;!h||h==="_"||N.push({name:h,type:n+m(d?i(d,"dims"):void 0),context:t,scope:a,availableFrom:r})},"add");for(let e of g.filter(n=>I.has(n.name))){if(C.has(e))continue;let n,t;if(e.name==="methodDeclaration"||e.name==="interfaceMethodDeclaration"){let a=i(e,"methodHeader");n=a?i(a,"methodDeclarator"):void 0,t=i(e,"methodBody")}else if(e.name==="constructorDeclaration")n=i(e,"constructorDeclarator"),t=i(e,"constructorBody");else if(e.name==="compactConstructorDeclaration"){let a=y(s.get(e),r=>r.name==="recordDeclaration");n=a?i(a,"recordHeader"):void 0,t=i(e,"constructorBody")}else e.name==="lambdaExpression"?(n=i(e,"lambdaParameters"),t=i(e,"lambdaBody")):t=i(e,"block");if(t){if(n){let a=new Set(["variableParaRegularParameter","variableArityParameter","regularLambdaParameter","conciseLambdaParameter","recordComponent"]);for(let r of b(n,a)){let d=m(i(r,"unannType")??i(r,"lambdaParameterType"));o(r,(d||"var")+(r.children.DotDotDot?"[]":""),e,t)}e.name==="lambdaExpression"&&n.children.Identifier&&o(n,"var",e,t)}if(e.name!=="lambdaExpression"&&e.name!=="staticInitializer"&&!D(e,"Static")){let a=y(s.get(e),h=>S.has(h.name)),r=a?s.get(a):void 0,d=r&&O.has(r.name)?m(i(r,"typeIdentifier")):"this";N.push({name:"this",type:d,context:e,scope:t,availableFrom:(i(t,"explicitConstructorInvocation")?.location.endOffset??t.location.startOffset-1)+1})}}}for(let e of g){let n=w(e);if(!n||C.has(n))continue;let t=s.get(e);if(e.name==="catchFormalParameter"&&t?.name==="catchClause"){let f=i(t,"block");f&&o(e,m(i(e,"catchType")),n,f);continue}if(e.name!=="localVariableDeclaration")continue;let a,r,d=!1;if(t?.name==="enhancedForStatement")a=i(t,"statement"),d=!0;else if(t?.name==="forInit"){let f=s.get(t);a=f?i(f,"statement"):void 0}else if(t?.name==="resource"){let f=y(t,p=>p.name==="tryWithResourcesStatement");a=f?i(f,"block"):void 0}else if(t?.name==="localVariableDeclarationStatement")a=y(t,f=>["block","constructorBody","switchBlockStatementGroup"].includes(f.name));else continue;if(!a)continue;r=Math.max(a.location.startOffset,e.location.endOffset+1);let h=i(e,"variableDeclaratorList"),x=m(i(e,"localVariableType"));for(let f of h?k(h,"variableDeclarator"):[])(d||f.children.variableInitializer)&&o(f,x,n,a,r)}return{recordLikeMethods:C,at(e,n){let t=w(e);return N.filter(a=>a.context===t&&n>=a.availableFrom&&n>=a.scope.location.startOffset&&n<=a.scope.location.endOffset)}}}l(J,"collectDebugBindings");var E=new Set(["ifStatement","whileStatement","doStatement","basicForStatement","enhancedForStatement"]);function j(c,u,s){if(s.trim()!==s||!/^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*$/.test(s))throw new Error("Invalid Java debugger helper name");if(/[\u0000-\u001f\u007f]/.test(u))throw new Error("Unsupported Java debug source path");if(/\\u+[0-9a-fA-F]{4}/.test(c))throw new Error("Java Debug does not support Unicode preprocessing escapes; use Run for this source.");let g;try{g=B(c)}catch(o){throw new Error(`Java Debug parser cannot safely instrument this syntax; use Run for this source. ${o instanceof Error?o.message:String(o)}`)}let v=J(g,c),m=[0];for(let o=0;o<c.length;o++)c[o]==="\r"?(c[o+1]===`
3
+ `&&o++,m.push(o+1)):c[o]===`
4
+ `&&m.push(o+1);let y=[],S=new Set,w=new Map,b=l((o,e,n=!1)=>{let t=w.get(o)??[];t.push({text:e,closing:n}),w.set(o,t)},"insert"),D=l((o,e)=>{if(S.has(e))return"";S.add(e);let n=0,t=m.length;for(;n+1<t;){let p=n+t>>>1;m[p]<=e?n=p:t=p}let a={line:n+1,column:e-m[n]+1};y.push(a);let r=v.at(o,e),d=`${JSON.stringify(u)},${a.line},${a.column}`,h=r.map(p=>JSON.stringify(p.name)).join(","),x=r.map(p=>JSON.stringify(p.type)).join(","),f=r.map(p=>`${s}.capture(${p.name})`).join(",");return`if(${s}.poll(${d}))${s}.hit(${d},new java.lang.String[]{${h}},new java.lang.String[]{${x}},new java.lang.Object[]{${f}});`},"hook"),C=l((o,e)=>{let n=o.children.LCurly?.[0];if(!n)throw new Error("Java Debug parser returned a block without its opening token");let t=e??n.endOffset+1;b(t,D(o,t))},"blockEntry"),O=l((o,e)=>{if(v.recordLikeMethods.has(o))return;let n=e[e.length-1];if(o.name==="constructorBody"){let t=o.children.explicitConstructorInvocation?.[0];C(o,t?t.location.endOffset+1:void 0)}else if(o.name==="block"&&(n?.name==="methodBody"||n?.name==="lambdaBody"||n?.name==="switchRule"))C(o);else if(o.name==="blockStatement"&&(o.children.statement||o.children.localVariableDeclarationStatement))b(o.location.startOffset,D(o,o.location.startOffset));else if(o.name==="statement"&&E.has(n?.name??"")){let a=o.children.statementWithoutTrailingSubstatement?.[0]?.children.block?.[0];a?C(a):(b(o.location.startOffset,`{${D(o,o.location.startOffset)}`),b(o.location.endOffset+1,"}",!0))}else if(o.name==="switchRule"){let t=o.children.expression?.[0],a=o.children.throwStatement?.[0],r=t??a;if(r){let d=e.findLastIndex(x=>x.name==="switchStatement"),h=e[d-1]?.name==="primaryPrefix";b(r.location.startOffset,`{${D(r,r.location.startOffset)}${t&&h?"yield ":""}`),b(o.location.endOffset+1,"}",!0)}}for(let t of Object.values(o.children))for(let a of t)"children"in a&&O(a,[...e,o])},"visit");O(g,[]);let N=c;for(let[o,e]of[...w].sort(([n],[t])=>t-n)){let n=e.sort((t,a)=>Number(a.closing)-Number(t.closing)).map(t=>t.text).join("");N=N.slice(0,o)+n+N.slice(o)}return{code:N,locations:y}}l(j,"instrumentJavaDebugSource");export{j as instrumentJavaDebugSource};
@@ -33,9 +33,14 @@ export function prepareJavaExceptionBridge(mainClass, sourceTexts, classFiles) {
33
33
  import java.lang.Throwable;
34
34
  import java.io.StringWriter;
35
35
  import java.io.PrintWriter;
36
+ import java.io.PrintStream;
36
37
  import org.teavm.jso.JSExport;
37
38
  import org.teavm.jso.JSObject;
38
39
  import org.teavm.jso.JSExceptions;
40
+ import org.teavm.jso.browser.Window;
41
+ import org.teavm.jso.core.JSFunction;
42
+ import org.teavm.jso.core.JSMapLike;
43
+ import org.teavm.jso.core.JSObjects;
39
44
 
40
45
  final class ${formatterClass} {
41
46
  interface Program {
@@ -43,7 +48,35 @@ final class ${formatterClass} {
43
48
  }
44
49
 
45
50
  public static void main(String[] args) throws Throwable {
46
- ${className}.program().run(args);
51
+ PrintStream out = System.out;
52
+ PrintStream err = System.err;
53
+ System.setOut(new Output(out));
54
+ System.setErr(new Output(err));
55
+ try {
56
+ ${className}.program().run(args);
57
+ } finally {
58
+ System.out.flush();
59
+ System.err.flush();
60
+ }
61
+ }
62
+
63
+ // A real PrintStream keeps Java formatting/encoding semantics. Only an
64
+ // explicit flush crosses the host batch boundary; println is not auto-flushed.
65
+ private static final class Output extends PrintStream {
66
+ Output(PrintStream delegate) { super(delegate, false); }
67
+
68
+ @Override
69
+ public void flush() {
70
+ super.flush();
71
+ Window current = Window.current();
72
+ if (current == null || !JSObjects.hasProperty(current, "wasmIdleJavaOutput")) return;
73
+ JSMapLike<JSObject> globals = current.cast();
74
+ JSObject output = globals.get("wasmIdleJavaOutput");
75
+ if (output == null) return;
76
+ JSMapLike<JSObject> bridge = output.cast();
77
+ JSFunction flush = bridge.get("flush").cast();
78
+ flush.call(output);
79
+ }
47
80
  }
48
81
 
49
82
  @JSExport
@@ -1,25 +1 @@
1
- import { type ExecutionLimits, type RuntimeAssetCacheOptions } from '@wasm-idle/core';
2
- import type { PlaygroundRuntimeAssets } from './assets';
3
- /** Linear memory needed to start Lean, import Init, and interpret a small program. */
4
- export declare const LEAN4_INITIAL_MEMORY_BYTES: number;
5
- /** Default limit: importing the 277 MB Init library grows the heap to about 370 MiB. */
6
- export declare const LEAN4_DEFAULT_WASM_MEMORY_BYTES: number;
7
- export declare const LEAN4_RUNTIME_MANIFEST: import("@wasm-idle/core").RuntimeRegistryManifest;
8
- export declare function resolveLean4RuntimeAssetConfig(runtimeAssets: string | PlaygroundRuntimeAssets, currentUrl: string): {
9
- baseUrl: string;
10
- workerUrl: string;
11
- manifestFingerprint: "335bd6e1720371fc161859cb7c2858600ec12314c30da1f0e5e503e324a96d42";
12
- workerReceipt: {
13
- readonly bytes: 16049;
14
- readonly sha256: "3611a263c4304246c9ee2967c07be2a1c70764a39d642db87ba0b86bfbe9d519";
15
- };
16
- };
17
- export declare function preflightLean4RuntimeAssets(baseUrl: string, options: {
18
- limits: ExecutionLimits;
19
- persistentCache?: RuntimeAssetCacheOptions;
20
- signal?: AbortSignal;
21
- reportProgress?: (value: number, stage: string) => void;
22
- fetch?: typeof globalThis.fetch;
23
- }): Promise<Readonly<{
24
- fingerprint: "335bd6e1720371fc161859cb7c2858600ec12314c30da1f0e5e503e324a96d42";
25
- }>>;
1
+ export { LEAN4_RUNTIME_MANIFEST, LEAN4_INITIAL_MEMORY_BYTES, LEAN4_DEFAULT_WASM_MEMORY_BYTES, resolveLean4RuntimeAssetConfig, preflightLean4RuntimeAssets } from '@wasm-idle/lsp/lean4';
@@ -1,123 +1,2 @@
1
- import { defineRuntimeRegistryManifest, preflightRuntimeAssets, ResourceLimitError, RuntimeConfigurationError } from '@wasm-idle/core';
2
- import { WASM_LEAN4_PROFILE as profile } from './wasmLean4Version';
3
- /** Linear memory needed to start Lean, import Init, and interpret a small program. */
4
- export const LEAN4_INITIAL_MEMORY_BYTES = 256 * 1024 * 1024;
5
- /** Default limit: importing the 277 MB Init library grows the heap to about 370 MiB. */
6
- export const LEAN4_DEFAULT_WASM_MEMORY_BYTES = 1024 ** 3;
7
- const assets = Object.entries(profile.assets);
8
- function mediaType(name) {
9
- if (name.endsWith('.mjs'))
10
- return 'text/javascript';
11
- if (name.endsWith('.json'))
12
- return 'application/json';
13
- if (name.startsWith('lean.wasm'))
14
- return 'application/wasm';
15
- return 'application/octet-stream';
16
- }
17
- export const LEAN4_RUNTIME_MANIFEST = defineRuntimeRegistryManifest({
18
- schemaVersion: 2,
19
- manifestId: 'wasm-idle/lean4',
20
- revision: profile.assets['producer-receipt.json'].sha256,
21
- runtimes: [
22
- {
23
- runtimeId: 'LEAN4',
24
- identity: {
25
- languageId: 'LEAN4',
26
- implementationId: 'lean4-emscripten',
27
- implementationVersion: profile.version,
28
- profile: {
29
- profileId: profile.profileId,
30
- manifestSchemaVersion: 1,
31
- manifestSha256: profile.assets['producer-receipt.json'].sha256,
32
- protocolVersion: 1,
33
- trustProfileId: profile.profileId,
34
- trustProfileSchemaVersion: 1
35
- }
36
- },
37
- capabilities: {
38
- stdin: 'streaming',
39
- workspace: true,
40
- abort: true,
41
- artifacts: false,
42
- streamingOutput: true
43
- },
44
- workerLifetime: { mode: 'per-run' },
45
- requiredBrowserFeatures: ['wasm', 'wasm-exceptions', 'shared-array-buffer'],
46
- assetRoot: '.',
47
- assets: assets.map(([name, receipt]) => ({
48
- key: name,
49
- path: name,
50
- compressedSha256: receipt.sha256,
51
- uncompressedSha256: receipt.uncompressed?.sha256 ?? receipt.sha256,
52
- compressedBytes: receipt.bytes,
53
- uncompressedBytes: receipt.uncompressed?.bytes ?? receipt.bytes,
54
- encoding: receipt.encoding ?? 'identity',
55
- mediaType: mediaType(name)
56
- })),
57
- contracts: {
58
- routeId: 'LEAN4',
59
- runtimeAssetKey: 'lean4',
60
- documentationId: 'lean4',
61
- syncTarget: 'sync:wasm-lean4',
62
- browserTestId: 'LEAN4'
63
- }
64
- }
65
- ]
66
- });
67
- export function resolveLean4RuntimeAssetConfig(runtimeAssets, currentUrl) {
68
- const root = typeof runtimeAssets === 'string' ? runtimeAssets : runtimeAssets.rootUrl || '';
69
- const override = typeof runtimeAssets === 'string' ? undefined : runtimeAssets.lean4?.baseUrl;
70
- const baseUrl = new URL(override ?? `${root.replace(/\/+$/, '')}/wasm-lean4/`, currentUrl);
71
- if (!['http:', 'https:'].includes(baseUrl.protocol) ||
72
- baseUrl.username ||
73
- baseUrl.password ||
74
- baseUrl.search ||
75
- baseUrl.hash) {
76
- throw new RuntimeConfigurationError('Lean 4 requires a credential-free HTTP(S) asset directory.', { runtimeId: 'LEAN4' });
77
- }
78
- if (!baseUrl.pathname.endsWith('/'))
79
- baseUrl.pathname += '/';
80
- const workerUrl = new URL('runner-worker.js', baseUrl);
81
- workerUrl.searchParams.set('v', profile.workerReceipt.sha256);
82
- return {
83
- baseUrl: baseUrl.href,
84
- workerUrl: workerUrl.href,
85
- manifestFingerprint: profile.assets['producer-receipt.json'].sha256,
86
- workerReceipt: profile.workerReceipt
87
- };
88
- }
89
- export async function preflightLean4RuntimeAssets(baseUrl, options) {
90
- if (options.limits.maxWasmMemoryBytes < LEAN4_INITIAL_MEMORY_BYTES) {
91
- throw new ResourceLimitError('Lean 4 needs at least 256 MiB of Wasm memory.', {
92
- runtimeId: 'LEAN4',
93
- phase: 'asset',
94
- resource: 'wasm-memory',
95
- actual: LEAN4_INITIAL_MEMORY_BYTES,
96
- limit: options.limits.maxWasmMemoryBytes
97
- });
98
- }
99
- const loaded = new Map();
100
- const total = assets.reduce((sum, [, asset]) => sum + asset.bytes, 0);
101
- const result = await preflightRuntimeAssets({
102
- manifest: LEAN4_RUNTIME_MANIFEST,
103
- runtimeId: 'LEAN4',
104
- rootUrl: baseUrl,
105
- assetUrls: Object.fromEntries(assets.map(([name, asset]) => [name, new URL(`${name}?v=${asset.sha256}`, baseUrl)])),
106
- limits: options.limits,
107
- persistentCache: options.persistentCache,
108
- signal: options.signal,
109
- fetch: options.fetch,
110
- redirect: 'error',
111
- requireExactResponseUrl: true,
112
- maxConcurrentDownloads: 3,
113
- maxTotalDeliveryBytes: total,
114
- reportProgress(progress) {
115
- loaded.set(progress.assetKey, progress.loadedBytes);
116
- options.reportProgress?.(0.04 + (0.13 * [...loaded.values()].reduce((a, b) => a + b, 0)) / total, `Downloading Lean 4 ${progress.assetKey}`);
117
- }
118
- });
119
- return Object.freeze({
120
- fingerprint: profile.assets['producer-receipt.json'].sha256,
121
- ...Object.fromEntries(Object.entries(result.assets).map(([name, asset]) => [name, asset.bytes]))
122
- });
123
- }
1
+ // Keep execution and editor asset verification, URL policy, and persistent-cache identity aligned.
2
+ export { LEAN4_RUNTIME_MANIFEST, LEAN4_INITIAL_MEMORY_BYTES, LEAN4_DEFAULT_WASM_MEMORY_BYTES, resolveLean4RuntimeAssetConfig, preflightLean4RuntimeAssets } from '@wasm-idle/lsp/lean4';
@@ -7,8 +7,8 @@ export declare function resolveLfortranRuntimeAssetConfig(assets: string | Playg
7
7
  workerUrl: string;
8
8
  manifestFingerprint: "11c9baef85c5221440edc4462690312cda62b48998a133b9a397ce32c6a97c45";
9
9
  workerReceipt: {
10
- readonly bytes: 13875;
11
- readonly sha256: "6443226c53cdadbbfdc25d43d1c07c4f13d8855cfe5cfd609f45ca9b29a96cdf";
10
+ readonly bytes: 14002;
11
+ readonly sha256: "c6de6d9cabadc5f5ad40a688d97b64239db8594e7723cadd9ed533fb6c6e0de5";
12
12
  };
13
13
  };
14
14
  export declare function preflightLfortranRuntimeAssets(baseUrl: string, options: {
@@ -1,5 +1,6 @@
1
1
  import type { DebugCommand, DebugDataBreakpoint, DebugDataBreakpointInfo, DebugDataBreakpointInfoArguments, DebugMemory, DebugScope, DebugSessionEvent, DebugResolvedDataBreakpoint, DebugVariable } from './options';
2
- import { type RuntimeAssetIntegrityEntry } from '@wasm-idle/core';
2
+ import { type DebugSourceBreakpoint, type DebugSteppingOptions, type DebugEvaluateOptions, type DebugEvaluateResult, type RuntimeAssetIntegrityEntry } from '@wasm-idle/core';
3
+ import { type BrowserLldbSessionOptions } from '@wasm-idle/llvm-core/debug';
3
4
  export interface LldbArtifactPayload {
4
5
  bytes: Uint8Array | ArrayBuffer;
5
6
  descriptor?: {
@@ -19,6 +20,9 @@ export interface LldbArtifactPayload {
19
20
  }>;
20
21
  }
21
22
  export interface LldbSandboxSessionOptions {
23
+ /** Opt in to producer-gated immutable module reuse; disabled by default. */
24
+ compiledModuleCache?: boolean;
25
+ workerFactory?: BrowserLldbSessionOptions['workerFactory'];
22
26
  persistentCache?: import('@wasm-idle/core').RuntimeAssetCacheOptions;
23
27
  manifestUrl: string;
24
28
  manifestReceipt?: Readonly<RuntimeAssetIntegrityEntry>;
@@ -29,10 +33,13 @@ export interface LldbSandboxSessionOptions {
29
33
  sourceBreakpoints?: Array<{
30
34
  sourcePath: `/workspace/${string}`;
31
35
  lines: number[];
36
+ breakpoints?: DebugSourceBreakpoint[];
32
37
  }>;
38
+ debugSteppingOptions?: DebugSteppingOptions;
33
39
  pauseOnEntry: boolean;
34
- /** C/C++ source entry; the low-level runtime still stops safely before _start executes. */
40
+ /** Source entry; the low-level runtime still stops safely before _start executes. */
35
41
  pauseAtMain?: boolean;
42
+ entryFunctionName?: string;
36
43
  programArgs?: string[];
37
44
  stdin?: string;
38
45
  onDebugEvent: (event: DebugSessionEvent) => void;
@@ -41,6 +48,14 @@ export interface LldbSandboxSessionOptions {
41
48
  }
42
49
  export declare class LldbSandboxSession {
43
50
  private readonly options;
51
+ private readonly sessionIdentity;
52
+ private stopId;
53
+ private supportsConditionalBreakpoints;
54
+ private supportsHitConditionalBreakpoints;
55
+ private supportsLogPoints;
56
+ private supportsSkipLibraryCode;
57
+ private supportsEvaluateForHovers;
58
+ private readonly breakpointSpecificationsBySource;
44
59
  private session?;
45
60
  private startupAbortController?;
46
61
  private activeThreadId;
@@ -80,7 +95,11 @@ export declare class LldbSandboxSession {
80
95
  debugCommand(command: DebugCommand): Promise<void>;
81
96
  pause(): Promise<void>;
82
97
  setBreakpoints(lines: number[], sourcePath?: `/workspace/${string}`): Promise<void>;
98
+ setSourceBreakpoints(breakpoints: DebugSourceBreakpoint[], sourcePath?: `/workspace/${string}`): Promise<void>;
99
+ setSteppingOptions(options: DebugSteppingOptions): Promise<void>;
100
+ private updateSourceBreakpoints;
83
101
  evaluate(expression: string): Promise<string>;
102
+ evaluateValue(expression: string, options?: DebugEvaluateOptions): Promise<DebugEvaluateResult>;
84
103
  variables(variablesReference: number, start?: number, count?: number): Promise<DebugVariable[]>;
85
104
  /** Ask the adapter to format one stopped frame, without changing evaluation selection. */
86
105
  formattedFrameName(frameId: number): Promise<string | null>;
@@ -97,6 +116,8 @@ export declare class LldbSandboxSession {
97
116
  setDataBreakpoints(breakpoints: DebugDataBreakpoint[]): Promise<DebugResolvedDataBreakpoint[]>;
98
117
  disconnect(): Promise<void>;
99
118
  private handleDapEvent;
119
+ private requestStackPage;
120
+ private debugFrames;
100
121
  private resolveStoppedState;
101
122
  private setMainEntryBreakpoint;
102
123
  private requestScopes;