From aaf89e2cab5edc141fd6e9e820cf93b862cc7e96 Mon Sep 17 00:00:00 2001 From: Andrew Morris Date: Tue, 28 Mar 2023 16:25:30 +1100 Subject: [PATCH] Add and use run_linked --- Cargo.lock | 31 ++--- valuescript_compiler/src/gather_modules.rs | 6 +- valuescript_compiler/src/resolve_path.rs | 33 ++++- valuescript_wasm/Cargo.toml | 1 + valuescript_wasm/src/lib.rs | 86 ++++++++++++- website/src/playground/files.ts | 34 ++--- website/src/playground/index.ts | 74 ++++++----- website/src/playground/vslib/VslibPool.ts | 33 ++++- website/src/playground/vslib/index.ts | 138 ++++++++++++++++++++- website/update-wasm.sh | 12 ++ 10 files changed, 367 insertions(+), 81 deletions(-) create mode 100755 website/update-wasm.sh diff --git a/Cargo.lock b/Cargo.lock index f946e24..29a3818 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -533,9 +533,9 @@ checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" [[package]] name = "js-sys" -version = "0.3.57" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" dependencies = [ "wasm-bindgen", ] @@ -809,9 +809,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.10.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "ordered-float" @@ -2244,6 +2244,7 @@ name = "valuescript_wasm" version = "0.1.0" dependencies = [ "console_error_panic_hook", + "js-sys", "serde", "serde_json", "valuescript_compiler", @@ -2284,9 +2285,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.80" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ "cfg-if 1.0.0", "serde", @@ -2296,13 +2297,13 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.80" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", - "lazy_static", "log", + "once_cell", "proc-macro2", "quote", "syn", @@ -2323,9 +2324,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.80" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2333,9 +2334,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.80" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", @@ -2346,9 +2347,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.80" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] name = "wasm-bindgen-test" diff --git a/valuescript_compiler/src/gather_modules.rs b/valuescript_compiler/src/gather_modules.rs index 7636341..77ce67d 100644 --- a/valuescript_compiler/src/gather_modules.rs +++ b/valuescript_compiler/src/gather_modules.rs @@ -16,7 +16,7 @@ enum DependencyReason { ImportedBy(ResolvedPath), } -#[derive(Clone)] +#[derive(Clone, Debug)] struct Dependency { path: ResolvedPath, reason: DependencyReason, @@ -94,7 +94,9 @@ where module: compiler_output.module, }; - for imported_path in get_imported_paths(&path_and_module) { + let imported_paths = get_imported_paths(&path_and_module); + + for imported_path in imported_paths { if gm.modules.contains_key(&imported_path) { continue; } diff --git a/valuescript_compiler/src/resolve_path.rs b/valuescript_compiler/src/resolve_path.rs index 4209c6e..c4c5a8a 100644 --- a/valuescript_compiler/src/resolve_path.rs +++ b/valuescript_compiler/src/resolve_path.rs @@ -5,6 +5,12 @@ pub struct ResolvedPath { pub path: String, } +impl ResolvedPath { + pub fn from(path: String) -> Self { + Self { path } + } +} + impl std::fmt::Display for ResolvedPath { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.path) @@ -16,12 +22,31 @@ pub fn resolve_path(importer_path: &ResolvedPath, path: &String) -> ResolvedPath let parent = importer_path_buf.parent().unwrap_or_else(|| Path::new("/")); ResolvedPath { - path: parent - .join(path) - .canonicalize() - .expect("Failed to canonicalize path") + path: normalize_path(parent.join(path)) .to_str() .expect("Failed to convert path to string") .to_string(), } } + +fn normalize_path(path_buf: PathBuf) -> PathBuf { + let mut dir_stack = Vec::new(); + + for component in path_buf.components() { + match component { + std::path::Component::ParentDir => { + // TODO: Error if we're at the root dir + dir_stack.pop(); + } + std::path::Component::CurDir => {} + _ => { + dir_stack.push(component); + } + } + } + + let mut path_buf = PathBuf::new(); + path_buf.extend(dir_stack); + + path_buf +} diff --git a/valuescript_wasm/Cargo.toml b/valuescript_wasm/Cargo.toml index 9b13c53..ee7c9be 100644 --- a/valuescript_wasm/Cargo.toml +++ b/valuescript_wasm/Cargo.toml @@ -17,6 +17,7 @@ valuescript_vm = { path = "../valuescript_vm" } # wasm-related wasm-bindgen = "0.2.63" +js-sys = "0.3.61" # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires diff --git a/valuescript_wasm/src/lib.rs b/valuescript_wasm/src/lib.rs index 664f736..48d90f5 100644 --- a/valuescript_wasm/src/lib.rs +++ b/valuescript_wasm/src/lib.rs @@ -1,6 +1,10 @@ +use std::collections::HashMap; + use wasm_bindgen::prelude::*; -use valuescript_compiler::{CompilerOutput, Diagnostic, DiagnosticLevel}; +use valuescript_compiler::{ + assemble, compile as compile_internal, CompilerOutput, Diagnostic, DiagnosticLevel, ResolvedPath, +}; use valuescript_vm::ValTrait; // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global @@ -9,9 +13,15 @@ use valuescript_vm::ValTrait; #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; +#[wasm_bindgen] +extern "C" { + fn js_get_error_message(e: &JsValue) -> String; + fn js_console_log(s: &str); +} + #[derive(serde::Serialize)] struct RunResult { - diagnostics: Vec, + diagnostics: HashMap>, output: Result, } @@ -30,7 +40,9 @@ fn run_to_result(source: &str) -> RunResult { if have_compiler_errors { return RunResult { - diagnostics: compiler_output.diagnostics, + diagnostics: vec![("(unknown)".into(), compiler_output.diagnostics)] + .into_iter() + .collect(), output: Err("Compile failed".into()), }; } @@ -41,7 +53,9 @@ fn run_to_result(source: &str) -> RunResult { let result = vm.run(&bytecode, &[]); RunResult { - diagnostics: compiler_output.diagnostics, + diagnostics: vec![("(unknown)".into(), compiler_output.diagnostics)] + .into_iter() + .collect(), output: match result { Ok(result) => Ok(result.codify()), Err(err) => Err(err.codify()), @@ -51,14 +65,16 @@ fn run_to_result(source: &str) -> RunResult { #[derive(serde::Serialize)] struct CompilerOutputWasm { - diagnostics: Vec, + diagnostics: HashMap>, assembly: Vec, } impl CompilerOutputWasm { fn from_compiler_output(output: CompilerOutput) -> CompilerOutputWasm { CompilerOutputWasm { - diagnostics: output.diagnostics, + diagnostics: vec![("(unknown)".into(), output.diagnostics)] + .into_iter() + .collect(), assembly: output.module.as_lines(), } } @@ -77,3 +93,61 @@ pub fn run(source: &str) -> String { let result = run_to_result(source); serde_json::to_string(&result).expect("Failed json serialization") } + +fn run_linked_to_result(entry_point: &str, read_file: &js_sys::Function) -> RunResult { + let compile_result = compile_internal(ResolvedPath::from(entry_point.to_string()), |path| { + let call_result = read_file.call1(&JsValue::UNDEFINED, &JsValue::from_str(path)); + + match call_result { + Ok(result) => result + .as_string() + .ok_or_else(|| "read_file from JS produced non-string".into()), + Err(err) => Err(js_get_error_message(&err)), + } + }); + + let diagnostic_len = compile_result + .diagnostics + .iter() + .map(|(_, v)| v.len()) + .sum::(); + + if diagnostic_len > 0 { + return RunResult { + diagnostics: compile_result + .diagnostics // TODO: Avoid conversion + .into_iter() + .map(|(path, diagnostics)| (path.to_string(), diagnostics)) + .collect(), + output: Err("Compile failed".into()), + }; + } + + let module = match compile_result.module { + Some(module) => module, + None => { + return RunResult { + diagnostics: HashMap::default(), + output: Err("Compilation did not emit module".into()), + } + } + }; + + let mut vm = valuescript_vm::VirtualMachine::new(); + + let vm_result = vm.run(&assemble(&module), &[]); + + RunResult { + diagnostics: HashMap::default(), + output: match vm_result { + Ok(result) => Ok(result.codify()), + Err(err) => Err(err.codify()), + }, + } +} + +#[wasm_bindgen] +pub fn run_linked(entry_point: &str, read_file: &js_sys::Function) -> String { + let result = run_linked_to_result(entry_point, read_file); + serde_json::to_string(&result).expect("Failed json serialization") +} diff --git a/website/src/playground/files.ts b/website/src/playground/files.ts index 14e7971..0e00984 100644 --- a/website/src/playground/files.ts +++ b/website/src/playground/files.ts @@ -33,7 +33,7 @@ function blockTrim(text: string) { } const files: Record = { - 'tutorial/hello.ts': blockTrim(` + '/tutorial/hello.ts': blockTrim(` // Welcome to the ValueScript playground! // // This playground also acts as a tutorial by describing a variety of @@ -48,7 +48,7 @@ const files: Record = { // When you're ready to continue, click next below. `), - 'tutorial/valueSemantics.ts': blockTrim(` + '/tutorial/valueSemantics.ts': blockTrim(` export default function main() { const leftBowl = ['apple', 'mango']; @@ -66,7 +66,7 @@ const files: Record = { // and therefore \`leftBowl\` doesn't change. `), - 'tutorial/revertOnCatch.ts': blockTrim(` + '/tutorial/revertOnCatch.ts': blockTrim(` export default function () { let x = 0; @@ -87,7 +87,7 @@ const files: Record = { // local - nothing else can be affected. `), - 'examples/factorial.ts': blockTrim(` + '/examples/factorial.ts': blockTrim(` export default function main() { return factorial(5); } @@ -101,7 +101,7 @@ const files: Record = { } `), - 'examples/counter.ts': blockTrim(` + '/examples/counter.ts': blockTrim(` export default function main() { let c = new Counter(); @@ -117,7 +117,7 @@ const files: Record = { } `), - 'examples/reverse.ts': blockTrim(` + '/examples/reverse.ts': blockTrim(` export default function main() { const values = ['a', 'b', 'c']; @@ -143,7 +143,7 @@ const files: Record = { } `), - 'examples/binaryTree.ts': blockTrim(` + '/examples/binaryTree.ts': blockTrim(` export default function main() { let tree = new BinaryTree(); @@ -199,7 +199,7 @@ const files: Record = { } `), - 'examples/mergeSort.ts': blockTrim(` + '/examples/mergeSort.ts': blockTrim(` export default function main() { const x = [7, 18, 9, 11, 16, 3, 8, 2, 5, 4, 6, 14, 15, 17, 10, 12, 1, 13]; @@ -253,7 +253,7 @@ const files: Record = { } `), - 'examples/quickSort.ts': blockTrim(` + '/examples/quickSort.ts': blockTrim(` export default function main() { const x = [7, 18, 9, 11, 16, 3, 8, 2, 5, 4, 6, 14, 15, 17, 10, 12, 1, 13]; @@ -325,7 +325,7 @@ const files: Record = { } `), - 'examples/idGenerationError.ts': blockTrim(` + '/examples/idGenerationError.ts': blockTrim(` export default function main() { let nextId = 1; @@ -344,7 +344,7 @@ const files: Record = { } `), - 'examples/idGeneration.ts': blockTrim(` + '/examples/idGeneration.ts': blockTrim(` export default function main() { let idGen = new IdGenerator(); @@ -371,7 +371,7 @@ const files: Record = { } `), - 'examples/sideEffectsArticle/enablePirateError.ts': blockTrim(` + '/examples/sideEffectsArticle/enablePirateError.ts': blockTrim(` export default function main() { let pirateEnabled = false; @@ -396,7 +396,7 @@ const files: Record = { } `), - 'examples/sideEffectsArticle/lyingAboutA.ts': blockTrim(` + '/examples/sideEffectsArticle/lyingAboutA.ts': blockTrim(` export default function main() { let a = 5; a += 2; @@ -405,7 +405,7 @@ const files: Record = { } `), - 'examples/sideEffectsArticle/add1To50WithMutation.ts': blockTrim(` + '/examples/sideEffectsArticle/add1To50WithMutation.ts': blockTrim(` export default function main() { let sum = 0; @@ -417,7 +417,7 @@ const files: Record = { } `), - 'examples/sideEffectsArticle/add1To50WithoutMutation.ts': blockTrim(` + '/examples/sideEffectsArticle/add1To50WithoutMutation.ts': blockTrim(` export default function main() { return makeRange(1, 51) .reduce((a, b) => a + b); @@ -434,7 +434,7 @@ const files: Record = { } `), - 'examples/sideEffectsArticle/enablePirateWorkaround.ts': blockTrim(` + '/examples/sideEffectsArticle/enablePirateWorkaround.ts': blockTrim(` export default function main() { let pirateEnabled = false; @@ -468,7 +468,7 @@ const files: Record = { } `), - 'examples/sideEffectsArticle/actorEnablePirate.ts': blockTrim(` + '/examples/sideEffectsArticle/actorEnablePirate.ts': blockTrim(` export default function main() { let actor = new Actor(); diff --git a/website/src/playground/index.ts b/website/src/playground/index.ts index 91627b2..aa08be4 100644 --- a/website/src/playground/index.ts +++ b/website/src/playground/index.ts @@ -74,7 +74,7 @@ let currentFile = ''; const result = await openEditorBase(input, source); if (result === null) { - changeFile(input.resource.path.slice(1)); + changeFile(input.resource.path); editor.setSelection(input.options.selection); } @@ -82,10 +82,10 @@ let currentFile = ''; }; } - setTimeout(() => changeFile(location.hash.slice(1))); + setTimeout(() => changeFile(location.hash)); globalThis.addEventListener('hashchange', () => { - changeFile(location.hash.slice(1)); + changeFile(location.hash); }); globalThis.addEventListener('resize', () => editor.layout()); @@ -164,7 +164,7 @@ let currentFile = ''; fs.write(currentFile, source); compileJob = vslibPool.compile(source); - runJob = vslibPool.run(source); + runJob = vslibPool.runLinked(currentFile, fs.files); renderJob( compileJob, @@ -188,18 +188,20 @@ let currentFile = ''; diagnosticsEl.innerHTML = ''; - for (const diagnostic of runResult.diagnostics) { - const diagnosticEl = document.createElement('div'); + for (const [file, diagnostics] of Object.entries(runResult.diagnostics)) { + for (const diagnostic of diagnostics) { + const diagnosticEl = document.createElement('div'); - diagnosticEl.classList.add( - 'diagnostic', - toKebabCase(diagnostic.level), - ); - - const { line, col } = toLineCol(source, diagnostic.span.start); - diagnosticEl.textContent = `${line}:${col}: ${diagnostic.message}`; - - diagnosticsEl.appendChild(diagnosticEl); + diagnosticEl.classList.add( + 'diagnostic', + toKebabCase(diagnostic.level), + ); + + const { line, col } = toLineCol(source, diagnostic.span.start); + diagnosticEl.textContent = `${file}:${line}:${col}: ${diagnostic.message}`; + + diagnosticsEl.appendChild(diagnosticEl); + } } const model = editor.getModel(); @@ -208,22 +210,28 @@ let currentFile = ''; monaco.editor.setModelMarkers( model, 'valuescript', - runResult.diagnostics.map((diagnostic) => { - const { line, col } = toLineCol(source, diagnostic.span.start); - const { line: endLine, col: endCol } = toLineCol( - source, - diagnostic.span.end, - ); + Object.entries(runResult.diagnostics).map(([file, diagnostics]) => { + if (file !== currentFile) { + return []; // TODO + } - return { - severity: toMonacoSeverity(diagnostic.level), - startLineNumber: line, - startColumn: col, - endLineNumber: endLine, - endColumn: endCol, - message: diagnostic.message, - }; - }), + return diagnostics.map((diagnostic) => { + const { line, col } = toLineCol(source, diagnostic.span.start); + const { line: endLine, col: endCol } = toLineCol( + source, + diagnostic.span.end, + ); + + return { + severity: toMonacoSeverity(diagnostic.level), + startLineNumber: line, + startColumn: col, + endLineNumber: endLine, + endColumn: endCol, + message: diagnostic.message, + }; + }); + }).flat(), ); }, ); @@ -285,7 +293,8 @@ let currentFile = ''; }); if (typeof popup.value === 'string' && popup.value !== '') { - const newFile = popup.value.endsWith('.ts') ? popup.value : `${popup.value}.ts`; + let newFile = popup.value.endsWith('.ts') ? popup.value : `${popup.value}.ts`; + newFile = newFile.startsWith('/') ? newFile : `/${newFile}`; fs.write(newFile, '', currentFile); changeFile(newFile); } @@ -318,7 +327,8 @@ let currentFile = ''; }); if (typeof popup.value === 'string' && popup.value !== '') { - const newFile = popup.value.endsWith('.ts') ? popup.value : `${popup.value}.ts`; + let newFile = popup.value.endsWith('.ts') ? popup.value : `${popup.value}.ts`; + newFile = newFile.startsWith('/') ? newFile : `/${newFile}`; fs.rename(currentFile, newFile); changeFile(newFile); } diff --git a/website/src/playground/vslib/VslibPool.ts b/website/src/playground/vslib/VslibPool.ts index 5ca943b..a63532b 100644 --- a/website/src/playground/vslib/VslibPool.ts +++ b/website/src/playground/vslib/VslibPool.ts @@ -4,6 +4,7 @@ import { initVslib } from './index'; async function main() { const vslib = await initVslib(); + const nil = undefined; self.postMessage('ready'); @@ -25,6 +26,30 @@ async function main() { self.postMessage({ err }); } } + + if (method === 'runLinked') { + const [entryPoint, files] = args; + + try { + self.postMessage({ + ok: vslib.runLinked(entryPoint, filePath => { + let content = files[filePath]; + + if (content === nil && !filePath.endsWith('.ts')) { + content = files[`${filePath}.ts`]; + } + + if (content === nil) { + throw new Error('Not found'); + } + + return content; + }), + }); + } catch (err) { + self.postMessage({ err }); + } + } }; } @@ -48,12 +73,12 @@ export type Diagnostic = { }; export type CompilerOutput = { - diagnostics: Diagnostic[]; + diagnostics: Record; assembly: string[]; }; export type RunResult = { - diagnostics: Diagnostic[]; + diagnostics: Record; output: | { Ok: string } | { Err: string }; @@ -78,6 +103,10 @@ export default class VslibPool { return this.#Job('run', [source]) as Job; } + runLinked(entryPoint: string, files: Record) { + return this.#Job('runLinked', [entryPoint, files]) as Job; + } + compile(source: string) { return this.#Job('compile', [source]) as Job; } diff --git a/website/src/playground/vslib/index.ts b/website/src/playground/vslib/index.ts index c7d7f13..6c95c77 100644 --- a/website/src/playground/vslib/index.ts +++ b/website/src/playground/vslib/index.ts @@ -1,9 +1,18 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + export async function initVslib() { - // deno-lint-ignore no-explicit-any const wasm: Record = (await WebAssembly.instantiateStreaming( fetch(`${location.origin}/value_script_bg.wasm`), { - './valuescript_wasm_bg.js': { __wbindgen_throw }, + './valuescript_wasm_bg.js': { + __wbindgen_throw, + __wbindgen_string_new, + __wbindgen_object_drop_ref, + __wbindgen_string_get, + __wbg_call_9495de66fdbe016b, + __wbg_jsgeterrormessage_11e1f21ab8a95c33, + __wbg_jsconsolelog_64bb2dc407556512, + }, }, )).instance.exports; @@ -60,6 +69,7 @@ export async function initVslib() { const view = getUint8Memory0().subarray(ptr + offset, ptr + len); const ret = encodeString(arg, view); + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion offset += ret.written!; } @@ -131,12 +141,134 @@ export async function initVslib() { } } + function run_linked(entry_point: string, read_file: (path: string) => string) { + let r0 = undefined; + let r1 = undefined; + + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + wasm.run_linked(retptr, ptr0, len0, addBorrowedObject(read_file)); + r0 = getInt32Memory0()[retptr / 4 + 0]; + r1 = getInt32Memory0()[retptr / 4 + 1]; + return getStringFromWasm0(r0, r1); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + heap[stack_pointer++] = undefined; + wasm.__wbindgen_free(r0, r1); + } + } + + let stack_pointer = 128; + + function addBorrowedObject(obj: unknown) { + if (stack_pointer == 1) throw new Error('out of js stack'); + heap[--stack_pointer] = obj; + return stack_pointer; + } + function __wbindgen_throw(arg0: number, arg1: number) { throw new Error(getStringFromWasm0(arg0, arg1)); } + function __wbg_jsgeterrormessage_11e1f21ab8a95c33(arg0: number, arg1: number) { + const ret = js_get_error_message(getObject(arg1)); + const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len0; + getInt32Memory0()[arg0 / 4 + 0] = ptr0; + } + + function js_get_error_message(e: Error) { + return e.message; + } + + function getObject(idx: number) { + return heap[idx]; + } + + const heap = new Array(128).fill(undefined); + + heap.push(undefined, null, true, false); + + let heap_next = heap.length; + + function __wbindgen_string_new(arg0: number, arg1: number) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); + } + + function addHeapObject(obj: unknown) { + if (heap_next === heap.length) heap.push(heap.length + 1); + const idx = heap_next; + heap_next = heap[idx]; + + heap[idx] = obj; + return idx; + } + + function __wbindgen_object_drop_ref(arg0: number) { + takeObject(arg0); + } + + function takeObject(idx: number) { + const ret = getObject(idx); + dropObject(idx); + return ret; + } + + function dropObject(idx: number) { + if (idx < 132) return; + heap[idx] = heap_next; + heap_next = idx; + } + + function __wbindgen_string_get(arg0: number, arg1: number) { + const obj = getObject(arg1); + const ret = typeof (obj) === 'string' ? obj : undefined; + const ptr0 = isLikeNone(ret) ? 0 : passStringToWasm0( + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + ret!, + wasm.__wbindgen_malloc, + wasm.__wbindgen_realloc, + ); + const len0 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len0; + getInt32Memory0()[arg0 / 4 + 0] = ptr0; + } + + function isLikeNone(x: unknown) { + return x === undefined || x === null; + } + + function __wbg_call_9495de66fdbe016b() { + return handleError(function (arg0: number, arg1: number, arg2: number) { + const ret = getObject(arg0).call(getObject(arg1), getObject(arg2)); + return addHeapObject(ret); + // eslint-disable-next-line prefer-rest-params + }, arguments as any); + } + + function handleError(this: any, f: any, args: unknown[]) { + try { + return f.apply(this, args); + } catch (e) { + wasm.__wbindgen_exn_store(addHeapObject(e)); + } + } + + function __wbg_jsconsolelog_64bb2dc407556512(arg0: number, arg1: number) { + js_console_log(getStringFromWasm0(arg0, arg1)); + } + + function js_console_log(arg0: string) { + console.log(arg0); + } + return { compile, run, + runLinked: run_linked, }; -}; +} diff --git a/website/update-wasm.sh b/website/update-wasm.sh new file mode 100755 index 0000000..0fc351d --- /dev/null +++ b/website/update-wasm.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -euo pipefail + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd "$SCRIPT_DIR" + +pushd ../valuescript_wasm + wasm-pack build +popd + +cp ../valuescript_wasm/pkg/valuescript_wasm_bg.wasm public/value_script_bg.wasm