Skip to content

Commit

Permalink
fix: support UTF-8 in the playground
Browse files Browse the repository at this point in the history
  • Loading branch information
sno2 committed Nov 2, 2024
1 parent d873c16 commit 80cc77c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 4 additions & 4 deletions playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
href="https://fonts.bunny.net/css?family=archivo:400,500,800|roboto-mono:400"
rel="stylesheet"
/>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/base64.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/xterm.min.js"></script>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/css/xterm.min.css "
Expand Down Expand Up @@ -272,8 +273,7 @@ <h2>Examples</h2>
<div id="examples-list"></div>
</div>
</dialog>

<script type="module">
<script>
require.config({
paths: { vs: "https://cdn.jsdelivr.net/npm/monaco-editor/min/vs" },
});
Expand Down Expand Up @@ -458,7 +458,7 @@ <h2>Examples</h2>
try {
flavor.value = flavorCode[hash[0]];
executionMode.value = executionModeCode[hash[2]];
editor.setValue(atob(hash.slice(3)));
editor.setValue(Base64.decode(hash.slice(3)));
} catch (e) {
console.error("failed to load program", e);
}
Expand Down Expand Up @@ -552,7 +552,7 @@ <h2>Examples</h2>
}
waiting_execution = true;
const mode = executionMode.value;
const newHash = `${flavor.value[0]}L${mode[0]}${btoa(
const newHash = `${flavor.value[0]}L${mode[0]}${Base64.encode(
editor.getValue()
)}`;
if (location.hash !== "#" + newHash) {
Expand Down
8 changes: 3 additions & 5 deletions playground/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ addEventListener("message", async (e) => {
const exports = await promise;
const data = e.data;
if (data.type === "codegen") {
const ptr = exports.allocSource(data.source.length);
enc.encodeInto(
data.source,
new Uint8Array(exports.memory.buffer, ptr, data.source.length)
);
const sourceBuf = enc.encode(data.source);
const ptr = exports.allocSource(sourceBuf.length);
new Uint8Array(exports.memory.buffer, ptr, sourceBuf.length).set(sourceBuf);
const error_ptr = exports.codeGen(data.flavor, data.mode);
if (error_ptr) {
const error_info = new Uint32Array(exports.memory.buffer, error_ptr, 4);
Expand Down

0 comments on commit 80cc77c

Please sign in to comment.