You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| File I/O (`open`, `read`, `write`) | No filesystem in browser |
128
+
| Networking (`HTTP`, sockets) | Browser security model |
129
+
| Multi-threading (`Threads`, `@spawn`) | JS is single-threaded (use Web Workers separately) |
130
+
| Metaprogramming (`@eval`, `eval`, `Meta.parse`) | No Julia runtime in browser |
131
+
| C interop (`ccall`, `@ccall`) | No native binaries |
132
+
| Package loading (`using`, `import` at runtime) | Static transpilation only |
43
133
44
134
## Arrays and Broadcasting
45
135
@@ -58,90 +148,26 @@ end
58
148
result = JST.compile(make_data, (Int, Float64); optimize=false)
59
149
```
60
150
61
-
Produces:
62
-
```javascript
63
-
functionmake_data(n, freq) {
64
-
x = [];
65
-
// ... for loop with x.push() ...
66
-
y =x.map(_b=> _b * freq).map(_b=>Math.sin(_b));
67
-
return [x, y];
68
-
}
69
-
```
70
-
71
-
JST auto-detects when `optimize=false` is needed (when the optimized IR contains Julia's internal memory management) and falls back automatically when used via [Therapy.jl](https://github.com/GroupTherapyOrg/Therapy.jl).
151
+
JST auto-detects when `optimize=false` is needed and falls back automatically when used via [Therapy.jl](https://github.com/GroupTherapyOrg/Therapy.jl).
72
152
73
153
## Package Compilation Registry
74
154
75
-
JST can transpile calls to registered Julia packages into their JavaScript equivalents — instead of transpiling the package's internal implementation.
76
-
77
-
### Registering a Package
155
+
Register custom JS output for any Julia package function:
78
156
79
157
```julia
80
158
import JavaScriptTarget as JST
81
159
82
-
# Register a function: (module, function_name) → JS compiler
83
-
JST.register_package_compilation!(MyPlotLib, :scatter) do ctx, kwargs, pos_args
JST.register_package_compilation!(@__MODULE__, :my_chart) do ctx, kwargs, pos_args
125
-
JST.build_js_object_from_kwargs(kwargs)
126
-
end
127
-
end
160
+
JST.register_package_compilation!(MyPkg, :my_func) do ctx, kwargs, pos_args
161
+
# Return JS code string
162
+
JST.build_js_object_from_kwargs(kwargs)
128
163
end
129
164
```
130
165
131
-
When JST encounters `MyPackage.my_chart(data=x, options=cfg)` in compiled code, it emits `{"data": x, "options": cfg}` instead of trying to compile the function's Julia implementation.
132
-
133
-
### How It Works
134
-
135
-
1. Julia's `code_typed` lowers keyword calls to `Core.kwcall(NamedTuple{names}(values), func)`
136
-
2. JST extracts the kwarg names from the NamedTuple type parameters
137
-
3. The registered compiler function receives the compiled kwarg values
138
-
4. The compiler emits the JS equivalent (object literals, function calls, etc.)
139
-
140
-
The registry is checked for both keyword calls (`Core.kwcall`) and positional calls. Functions are matched by `(parentmodule(fn), nameof(fn))`.
0 commit comments