1313}
1414"""
1515
16- terminal_init = """
17- const terminal = new Terminal();
18- const fitAddon = new FitAddon.FitAddon();
19- terminal.loadAddon(fitAddon);
20- window.terminal = terminal;
21- console.log("Terminal initialized");
22- """
23-
24- print_script = """
25- window.customPrint = function(text) {
26- console.log(text);
27- if (window.terminal) {
28- window.terminal.writeln(text);
29- } else {
30- console.warn("Terminal not initialized");
31- }
32- };
33- createModule().then((Module) => {
34- Module.print = window.customPrint;
35- Module.printErr = window.customPrint;
36- window.Module = Module;
37- console.log("Initial module created");
38- });
39- """
40-
4116bind_terminal = """
4217 window.terminal.open(document.getElementById('output'));
4318 fitAddon.fit();
6035}
6136""" .strip ()
6237
63- cpp_code = """
64- static constexpr size_t N = 4;
65- Tensor a = createTensor(ctx, {N}, kf32, makeData<N>().data());
66- Tensor output = createTensor(ctx, {N}, kf32);
67- Kernel op = createKernel(ctx, {kPuzzle1, N}, Bindings{a, output},
68- /*nWorkgroups */ {1, 1, 1});
69-
70- std::promise<void> promise;
71- std::future<void> future = promise.get_future();
72- dispatchKernel(ctx, op, promise);
73- std::array<float, R * C> outputArr;
74- wait(ctx, future);
75- toCPU(ctx, output, outputArr.data(), sizeof(outputArr));
76- printf("%s", show<float, R, C>(outputArr, "output").c_str());
77- """ .strip ()
78-
79-
8038def controls ():
8139 # left and right buttons
8240 return Div (
@@ -202,13 +160,21 @@ def CodeEditor(initial_content: str):
202160 # cls="flex flex-col h-screen w-full", style="height: 100vh; overflow: hidden;"
203161 style = "height: 33vh; overflow: hidden;" ,
204162 ),
205- # Script(editor_script(initial_content)),
163+ Script (editor_script (initial_content )),
206164 )
207165
208166
209167# TODO(avh) : Global state handling of terminal binding, module creation, etc.
210168# could be improved
211169
170+ init_app = """
171+ document.addEventListener('DOMContentLoaded', () => {
172+ window.AppState = Object.create(State);
173+ const AppState = window.AppState;
174+ initializeApp();
175+ });
176+ """ .strip ()
177+
212178HDRS = (
213179 picolink ,
214180 # ace code editor
@@ -217,15 +183,13 @@ def CodeEditor(initial_content: str):
217183 Link (rel = "stylesheet" , href = "https://cdn.jsdelivr.net/npm/xterm/css/xterm.css" ),
218184 Script (src = "https://cdn.jsdelivr.net/npm/xterm/lib/xterm.js" ),
219185 Script (src = "https://cdn.jsdelivr.net/npm/xterm-addon-fit/lib/xterm-addon-fit.js" ),
220- # Script(terminal_init),
221186 Script (src = "/build/run.js" ), # gpu.cpp runtime
222- # Script(print_script),
223187 Style (global_style ),
224188 Link (rel = "stylesheet" , href = "https://unpkg.com/tippy.js@6/dist/tippy.css" ),
225189 Script (src = "https://unpkg.com/@popperjs/core@2" ),
226190 Script (src = "https://unpkg.com/tippy.js@6" ),
227191 Script (src = "/client.js" ),
228- Script ("document.addEventListener('DOMContentLoaded', () => { initializeApp(); });" ),
192+ Script (init_app ),
229193 * Socials (
230194 title = "gpu.cpp gpu puzzles" ,
231195 description = "" ,
0 commit comments