Skip to content

Commit

Permalink
IR refactor, const folding & debug mode (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
pufferfish101007 committed Apr 9, 2024
1 parent b0d76f4 commit 3098f08
Show file tree
Hide file tree
Showing 7 changed files with 1,591 additions and 790 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ If you experience runtime stack overflow errors in debug mode, try using the `-O
| 0x00 | float64 | `f64` | a float |
| 0x01 | bool64 | `i64` | an integer - only the least significant bit is used |
| 0x02 | externref string (64 bit) | `i64` | wrapped to a 32 bit pointer to an `externref` value in the `anyref` table |
| 0x03 | int32 | `i32` | a 32-bit integer |

### Memory layout guarantees

Expand Down
2 changes: 1 addition & 1 deletion playground/components/ProjectPlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
//console.log(file, data);
return data;
}
return await (await fetch(`https://assets.scratch.mit.edu/${md5ext}`)).text();
return await (await fetch(`https://assets.scratch.mit.edu/internalapi/asset/${md5ext}/get/`)).text();
} catch (e) {
error.value = `failed to load asset ${md5ext}\n${e.stack}`
}
Expand Down
5 changes: 4 additions & 1 deletion playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HyperQuark</title>
<script src="//cdn.jsdelivr.net/npm/eruda"></script>
<script>eruda.init();</script>
<script>
window.debug = typeof new URLSearchParams(window.location.search).get('debug') === 'string';
if (window.debug) eruda.init();
</script>
</head>
<body>
<div id="app"></div>
Expand Down
25 changes: 13 additions & 12 deletions playground/lib/project-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default async (
framerate: 30,
}
) => {
if (window.debug) window.open(URL.createObjectURL(new Blob([wasm_bytes], { type: 'application/wasm' })));
const framerate_wait = Math.round(1000 / framerate);
let assert;
let exit;
Expand Down Expand Up @@ -144,10 +145,10 @@ export default async (
},
runtime: {
looks_say: (ty, val, targetIndex) => {
targetOutput(targetIndex, "say", wasm_val_to_js(ty, val));
targetOutput(targetIndex, "say", wasm_val_to_js(ty, val).toString());
},
looks_think: (ty, val, targetIndex) => {
targetOutput(targetIndex, "think", wasm_val_to_js(ty, val));
targetOutput(targetIndex, "think", wasm_val_to_js(ty, val).toString());
},
operator_equals: (ty1, val1, ty2, val2) => {
if (ty1 === ty2 && val1 === val2) return true;
Expand All @@ -159,17 +160,17 @@ export default async (
},
operator_random: (lower, upper) =>
Math.random() * (upper - lower) + lower,
operator_join: (ty1, val1, ty2, val2) =>
wasm_val_to_js(ty1, val1).toString() +
wasm_val_to_js(ty2, val2).toString(),
operator_letterof: (idx, ty, val) =>
wasm_val_to_js(ty, val).toString()[idx - 1] ?? "",
operator_length: (ty, val) => wasm_val_to_js(ty, val).toString().length,
operator_contains: (ty1, val1, ty2, val2) =>
wasm_val_to_js(ty1, val1)
operator_join: (str1, str2) =>
str1.toString() +
str2.toString(),
operator_letterof: (idx, str) =>
str.toString()[idx - 1] ?? "",
operator_length: (str) => str.length,
operator_contains: (str1, str2) =>
str1
.toString()
.toLowerCase()
.includes(wasm_val_to_js(ty2, val2).toString().toLowerCase()),
.includes(str2.toString().toLowerCase()),
mathop_sin: (n) =>
parseFloat(Math.sin((Math.PI * n) / 180).toFixed(10)),
mathop_cos: (n) =>
Expand Down Expand Up @@ -284,7 +285,7 @@ export default async (
cast: {
stringtofloat: parseFloat,
stringtobool: Boolean,
floattostring: Number.prototype.toString,
floattostring: (i) => i.toString(),
},
};
try {
Expand Down
Loading

0 comments on commit 3098f08

Please sign in to comment.