Skip to content

Commit

Permalink
command output
Browse files Browse the repository at this point in the history
  • Loading branch information
trmidboe committed Sep 6, 2021
1 parent d77b7f1 commit c49ef18
Show file tree
Hide file tree
Showing 8 changed files with 3,022 additions and 533 deletions.
22 changes: 14 additions & 8 deletions wasm/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ export function test(keys: string[], values: string[]): string[][] {
}

export function getCommands(): string[][] {
const commands = new Array<string[]>(6);
const commands = new Array<string[]>(7);
commands[0] = ["websocketListen", "tell wasm module to begin listening"];
commands[1] = ["websocketNotify", "tell wasm module to send broadcast"];
commands[2] = [
"websocketCallback",
"an event to which wasm subscribed has fired",
];
commands[3] = ["fibonacci", "calculate fibonacci for a number"];
commands[4] = ["deployModule", "request deployment of a module"];
commands[5] = ["commandEx", "command example"];
commands[4] = ["fibonacciRemote", "calculate fibonacci for a number"];
commands[5] = ["deployModule", "request deployment of a module"];
commands[6] = ["commandEx", "command example"];
return commands;
}

Expand Down Expand Up @@ -76,12 +77,17 @@ export function fibonacci(x: f64): f64 {
return fibonacci(x - 1) + fibonacci(x - 2);
}

export function fibonnacciRemote(keys: string[], vals: string[]): string[][] {
// const x = vals.map((v,i) => keys[i] === 'fibonacci' ? v : null)
export function fibonacciRemote(keys: string[], vals: string[]): string[][] {
let val: number = 0;

for (let i = 0; i < keys.length; i++) {
if (keys[i] === "fibonacci") {
val = parseFloat(vals[i]);
}
}
const r = new Array<string[]>(1);
//if (x.length < 1 || !x[0] || typeof x[0] !== 'number') return r
//const z = parseFloat(x[0])
r[0] = ["duration", fibonacci(10).toString()];
const sum = fibonacci(val);
r[0] = ["result", sum.toString()];
return r;
}

Expand Down
Binary file modified wasm/build/optimized.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion wasm/build/optimized.wasm.map

Large diffs are not rendered by default.

1,945 changes: 1,519 additions & 426 deletions wasm/build/optimized.wat

Large diffs are not rendered by default.

Binary file modified wasm/build/untouched.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion wasm/build/untouched.wasm.map

Large diffs are not rendered by default.

1,578 changes: 1,483 additions & 95 deletions wasm/build/untouched.wat

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions wasm/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ require('..').then(async wasmInstance => {
fibonacci,
onUpdate,
websocketNotify,
portEx
portEx,
fibonacciRemote
// Input,
// Output,
// getInput,
Expand All @@ -36,7 +37,7 @@ require('..').then(async wasmInstance => {
const model = await spec.factory({ a: 'b' })({ c: 'd' })
console.log(model)
adapter.callWasmFunction(onUpdate, model, false)
adapter.callWasmFunction(websocketNotify, "testing", false)
adapter.callWasmFunction(websocketNotify, 'testing', false)

const fib = 20
console.log(
Expand All @@ -45,4 +46,5 @@ require('..').then(async wasmInstance => {
'is',
adapter.callWasmFunction(fibonacci, fib)
)
console.log(adapter.callWasmFunction(fibonacciRemote, { fibonacci: 30.0 }))
})

0 comments on commit c49ef18

Please sign in to comment.