Skip to content

Commit

Permalink
example make files now no longer use -cc1
Browse files Browse the repository at this point in the history
  • Loading branch information
twiddlingbits committed Mar 24, 2024
1 parent 6089b92 commit bf2d158
Show file tree
Hide file tree
Showing 50 changed files with 219 additions and 131 deletions.
Binary file modified azure/examples/balls/balls-a.wasm
Binary file not shown.
Binary file modified azure/examples/balls/balls.wasm
Binary file not shown.
Binary file modified azure/examples/balls/dist/balls-a.wasm
Binary file not shown.
Binary file modified azure/examples/balls/dist/balls.wasm
Binary file not shown.
Binary file modified azure/examples/fft/dist/kiss_fft.wasm
Binary file not shown.
Binary file modified azure/examples/fft/kiss_fft.wasm
Binary file not shown.
6 changes: 4 additions & 2 deletions azure/examples/function-calls/async.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

console.log("twrWasmModuleAsync");

let amod;

try {
const amod = new twrWasmModuleAsync();
amod = new twrWasmModuleAsync();

document.getElementById("twr_iodiv").innerHTML ="<br>";

Expand All @@ -44,7 +46,7 @@

amod.divLog("function_calls() returned: "+r);
amod.divLog("as string: ", amod.getString(r));
if (amod.getString(r)!="fourty-two - if only it were that simple") throw new Error("error");
if (amod.getString(r)!="forty-two - if only it were that simple") throw new Error("42 error");

r=await amod.executeC(["get_structu32"]);
amod.divLog("get_struct32() returned: "+r);
Expand Down
2 changes: 1 addition & 1 deletion azure/examples/function-calls/dist/async.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"whatkey": "../../lib-js/whatkey.js"
}
}
</script> <script type="module">var e=globalThis,t={},r={},i=e.parcelRequire94c2;null==i&&((i=function(e){if(e in t)return t[e].exports;if(e in r){var i=r[e];delete r[e];var o={id:e,exports:{}};return t[e]=o,i.call(o.exports,o,o.exports),o.exports}var n=Error("Cannot find module '"+e+"'");throw n.code="MODULE_NOT_FOUND",n}).register=function(e,t){r[e]=t},e.parcelRequire94c2=i),(0,i.register)("ecOAF",function(e,t){e.exports=new URL("test-file.fabefebd.txt",import.meta.url).toString()});var o=i("4mNsm");console.log("twrWasmModuleAsync");try{let e=new o.twrWasmModuleAsync;document.getElementById("twr_iodiv").innerHTML="<br>",await e.loadWasm("./function-calls-a.wasm"),await e.executeC(["twr_wasm_print_mem_debug_stats"]);let t=new Uint8Array(4);t[0]=99,t[1]=98,t[2]=97,t[3]=6;let r=new URL(i("ecOAF"));e.divLog("module type is twrWasmModuleAsync\n"),e.divLog("--- begin C call ---");let n=await e.executeC(["function_calls","This is a string.",t.buffer,t.length,r]);if(e.divLog("--- end C call ---\n"),e.divLog("function_calls() returned: "+n),e.divLog("as string: ",e.getString(n)),"fourty-two - if only it were that simple"!=e.getString(n))throw Error("error");n=await e.executeC(["get_structu32"]),e.divLog("get_struct32() returned: "+n);let a=e.getU32Arr(n);if(e.divLog("three 32 bit ints are: ",a[0],a[1],a[2]),1!=a[0]||2e3!=a[1]||3!=a[2])throw Error("error");n=await e.executeC(["get_structu8"]),e.divLog("get_struct8() returned: "+n);let l=e.getU8Arr(n);if(e.divLog("three 8 bit ints are: ",l[0],l[1],l[2]),100!=l[0]||101!=l[1]||102!=l[2])throw Error("error")}catch(e){throw amod.divLog("unexpected exception"),e}</script> </body>
</script> <script type="module">let e;var t=globalThis,r={},i={},o=t.parcelRequire94c2;null==o&&((o=function(e){if(e in r)return r[e].exports;if(e in i){var t=i[e];delete i[e];var o={id:e,exports:{}};return r[e]=o,t.call(o.exports,o,o.exports),o.exports}var n=Error("Cannot find module '"+e+"'");throw n.code="MODULE_NOT_FOUND",n}).register=function(e,t){i[e]=t},t.parcelRequire94c2=o),(0,o.register)("ecOAF",function(e,t){e.exports=new URL("test-file.fabefebd.txt",import.meta.url).toString()});var n=o("4mNsm");console.log("twrWasmModuleAsync");try{e=new n.twrWasmModuleAsync,document.getElementById("twr_iodiv").innerHTML="<br>",await e.loadWasm("./function-calls-a.wasm"),await e.executeC(["twr_wasm_print_mem_debug_stats"]);let t=new Uint8Array(4);t[0]=99,t[1]=98,t[2]=97,t[3]=6;let r=new URL(o("ecOAF"));e.divLog("module type is twrWasmModuleAsync\n"),e.divLog("--- begin C call ---");let i=await e.executeC(["function_calls","This is a string.",t.buffer,t.length,r]);if(e.divLog("--- end C call ---\n"),e.divLog("function_calls() returned: "+i),e.divLog("as string: ",e.getString(i)),"forty-two - if only it were that simple"!=e.getString(i))throw Error("42 error");i=await e.executeC(["get_structu32"]),e.divLog("get_struct32() returned: "+i);let a=e.getU32Arr(i);if(e.divLog("three 32 bit ints are: ",a[0],a[1],a[2]),1!=a[0]||2e3!=a[1]||3!=a[2])throw Error("error");i=await e.executeC(["get_structu8"]),e.divLog("get_struct8() returned: "+i);let l=e.getU8Arr(i);if(e.divLog("three 8 bit ints are: ",l[0],l[1],l[2]),100!=l[0]||101!=l[1]||102!=l[2])throw Error("error")}catch(t){throw e.divLog("unexpected exception"),t}</script> </body>
Binary file modified azure/examples/function-calls/dist/function-calls-a.wasm
Binary file not shown.
Binary file modified azure/examples/function-calls/dist/function-calls.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion azure/examples/function-calls/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"whatkey": "../../lib-js/whatkey.js"
}
}
</script> <script type="module">var e=globalThis,t={},r={},i=e.parcelRequire94c2;null==i&&((i=function(e){if(e in t)return t[e].exports;if(e in r){var i=r[e];delete r[e];var o={id:e,exports:{}};return t[e]=o,i.call(o.exports,o,o.exports),o.exports}var n=Error("Cannot find module '"+e+"'");throw n.code="MODULE_NOT_FOUND",n}).register=function(e,t){r[e]=t},e.parcelRequire94c2=i),(0,i.register)("ecOAF",function(e,t){e.exports=new URL("test-file.fabefebd.txt",import.meta.url).toString()});var o=i("4mNsm");try{let e=new o.twrWasmModule;document.getElementById("twr_iodiv").innerHTML="<br>",await e.loadWasm("./function-calls.wasm"),await e.executeC(["twr_wasm_print_mem_debug_stats"]);let t=new Uint8Array(4);t[0]=99,t[1]=98,t[2]=97,t[3]=6;let r=new URL(i("ecOAF"));e.divLog("module type is twrWasmModule\n"),e.divLog("--- begin C call ---");let n=await e.executeC(["function_calls","This is a string.",t.buffer,t.length,r]);if(e.divLog("--- end C call ---\n"),e.divLog("function_calls() returned: "+n),e.divLog("as string: ",e.getString(n)),"fourty-two - if only it were that simple"!=e.getString(n))throw Error("error");n=await e.executeC(["get_structu32"]),e.divLog("get_struct32() returned: "+n);let a=e.getU32Arr(n);if(e.divLog("three 32 bit ints are: ",a[0],a[1],a[2]),1!=a[0]||2e3!=a[1]||3!=a[2])throw Error("error");n=await e.executeC(["get_structu8"]),e.divLog("get_struct8() returned: "+n);let l=e.getU8Arr(n);if(e.divLog("three 8 bit ints are: ",l[0],l[1],l[2]),100!=l[0]||101!=l[1]||102!=l[2])throw Error("error")}catch(e){throw amod.divLog("unexpected exception"),e}</script> </body>
</script> <script type="module">let e;var t=globalThis,r={},i={},o=t.parcelRequire94c2;null==o&&((o=function(e){if(e in r)return r[e].exports;if(e in i){var t=i[e];delete i[e];var o={id:e,exports:{}};return r[e]=o,t.call(o.exports,o,o.exports),o.exports}var n=Error("Cannot find module '"+e+"'");throw n.code="MODULE_NOT_FOUND",n}).register=function(e,t){i[e]=t},t.parcelRequire94c2=o),(0,o.register)("ecOAF",function(e,t){e.exports=new URL("test-file.fabefebd.txt",import.meta.url).toString()});var n=o("4mNsm");try{e=new n.twrWasmModule,document.getElementById("twr_iodiv").innerHTML="<br>",await e.loadWasm("./function-calls.wasm"),await e.executeC(["twr_wasm_print_mem_debug_stats"]);let t=new Uint8Array(4);t[0]=99,t[1]=98,t[2]=97,t[3]=6;let r=new URL(o("ecOAF"));e.divLog("module type is twrWasmModule\n"),e.divLog("--- begin C call ---");let i=await e.executeC(["function_calls","This is a string.",t.buffer,t.length,r]);if(e.divLog("--- end C call ---\n"),e.divLog("function_calls() returned: "+i),e.divLog("as string: ",e.getString(i)),"forty-two - if only it were that simple"!=e.getString(i))throw Error("42 error");i=await e.executeC(["get_structu32"]),e.divLog("get_struct32() returned: "+i);let a=e.getU32Arr(i);if(e.divLog("three 32 bit ints are: ",a[0],a[1],a[2]),1!=a[0]||2e3!=a[1]||3!=a[2])throw Error("error");i=await e.executeC(["get_structu8"]),e.divLog("get_struct8() returned: "+i);let l=e.getU8Arr(i);if(e.divLog("three 8 bit ints are: ",l[0],l[1],l[2]),100!=l[0]||101!=l[1]||102!=l[2])throw Error("error")}catch(t){throw e.divLog("unexpected exception"),t}</script> </body>
Binary file modified azure/examples/function-calls/function-calls-a.wasm
Binary file not shown.
Binary file modified azure/examples/function-calls/function-calls.wasm
Binary file not shown.
40 changes: 21 additions & 19 deletions azure/examples/function-calls/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
<script type="module">
import {twrWasmModule} from "tiny-wasm-runtime";

let mod;

try {
const amod = new twrWasmModule();
mod = new twrWasmModule();

document.getElementById("twr_iodiv").innerHTML ="<br>";

await amod.loadWasm("./function-calls.wasm");
await mod.loadWasm("./function-calls.wasm");

// this output goes to the console
await amod.executeC(["twr_wasm_print_mem_debug_stats"]);
await mod.executeC(["twr_wasm_print_mem_debug_stats"]);

const s="This is a string.";

Expand All @@ -35,29 +37,29 @@

const url=new URL('test-file.txt', import.meta.url);

amod.divLog("module type is twrWasmModule\n");
amod.divLog("--- begin C call ---");
let r=await amod.executeC(["function_calls", s, ba.buffer, ba.length, url]);
amod.divLog("--- end C call ---\n");
mod.divLog("module type is twrWasmModule\n");
mod.divLog("--- begin C call ---");
let r=await mod.executeC(["function_calls", s, ba.buffer, ba.length, url]);
mod.divLog("--- end C call ---\n");

amod.divLog("function_calls() returned: "+r);
amod.divLog("as string: ", amod.getString(r));
if (amod.getString(r)!="fourty-two - if only it were that simple") throw new Error("error");
mod.divLog("function_calls() returned: "+r);
mod.divLog("as string: ", mod.getString(r));
if (mod.getString(r)!="forty-two - if only it were that simple") throw new Error("42 error");

r=await amod.executeC(["get_structu32"]);
amod.divLog("get_struct32() returned: "+r);
const ba32=amod.getU32Arr(r);
amod.divLog("three 32 bit ints are: ", ba32[0], ba32[1], ba32[2]);
r=await mod.executeC(["get_structu32"]);
mod.divLog("get_struct32() returned: "+r);
const ba32=mod.getU32Arr(r);
mod.divLog("three 32 bit ints are: ", ba32[0], ba32[1], ba32[2]);
if (ba32[0]!=1 || ba32[1]!=2000 || ba32[2]!=3) throw new Error("error");

r=await amod.executeC(["get_structu8"]);
amod.divLog("get_struct8() returned: "+r);
const ba8=amod.getU8Arr(r);
amod.divLog("three 8 bit ints are: ", ba8[0], ba8[1], ba8[2]);
r=await mod.executeC(["get_structu8"]);
mod.divLog("get_struct8() returned: "+r);
const ba8=mod.getU8Arr(r);
mod.divLog("three 8 bit ints are: ", ba8[0], ba8[1], ba8[2]);
if (ba8[0]!=100 || ba8[1]!=101 || ba8[2]!=102) throw new Error("error");
}
catch(ex) {
amod.divLog("unexpected exception");
mod.divLog("unexpected exception");
throw ex;
}

Expand Down
Binary file modified azure/examples/helloworld/dist/helloworld.wasm
Binary file not shown.
Binary file modified azure/examples/helloworld/helloworld.wasm
Binary file not shown.
2 changes: 2 additions & 0 deletions azure/examples/helloworld/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
</script>

<script type="module">
"use strict"
import {twrWasmModule} from "tiny-wasm-runtime";

const mod = new twrWasmModule();
await mod.loadWasm("./helloworld.wasm");
//await mod.executeC(["twr_wasm_print_mem_debug_stats"]);
await mod.executeC(["hello"]);
</script>
</body>
Expand Down
Binary file modified azure/examples/maze/dist/maze.wasm
Binary file not shown.
Binary file modified azure/examples/maze/maze.wasm
Binary file not shown.
Binary file modified azure/examples/stdio-canvas/dist/stdio-canvas.wasm
Binary file not shown.
Binary file modified azure/examples/stdio-canvas/stdio-canvas.wasm
Binary file not shown.
Binary file modified azure/examples/stdio-div/dist/stdio-div.wasm
Binary file not shown.
Binary file modified azure/examples/stdio-div/stdio-div.wasm
Binary file not shown.
Binary file modified azure/examples/tests/dist/tests.wasm
Binary file not shown.
Binary file modified azure/examples/tests/tests.wasm
Binary file not shown.
25 changes: 16 additions & 9 deletions examples/balls/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@

OBJ := gamefield.o ball.o canvas.o heart.o opnew.o

CFLAGS := --target=wasm32-unknown-unknown-wasm -Wall -c -v -O3 -fno-exceptions -fno-trapping-math -I ../../include
# -g for debug symbols
# -nostdinc Disable standard #include directories, provided by tiny-wasm-runtime
# -nostdlib Disable standard c library, provided by tiny-wasm-runtime
# -nostdlibinc tells the compiler to not search the standard system directories or compiler builtin directories for include files, c++ only?
# -fno-exceptions Don't generate stack exception code since we don't use std:: exception handling
TWRCFLAGS := --target=wasm32 -fno-exceptions -nostdlibinc -nostdinc -nostdlib -isystem ../../include

# -O3 Optimization level 3
# -Wall Warn all
# -c compile w/o linking
# -g for debug symbols
# -v verbose
CFLAGS := -c -Wall -O3 $(TWRCFLAGS)

OBJOUTDIR := out
$(info $(shell mkdir -p $(OBJOUTDIR)))
OBJ := $(patsubst %, $(OBJOUTDIR)/%, $(OBJ))
Expand All @@ -17,20 +27,17 @@ $(OBJOUTDIR)/%.o: %.cpp
clang $(CFLAGS) $< -o $@

balls.wasm: $(OBJ)
llvm-link -o $(OBJOUTDIR)/balls.bc ../../lib-c/twr.a
llc -filetype=obj $(OBJOUTDIR)/balls.bc -o $(OBJOUTDIR)/balls-wasm.o

# twrWasmModule version (building both for testing)
wasm-ld $(OBJ) $(OBJOUTDIR)/balls-wasm.o -o balls.wasm \
wasm-ld $(OBJ) ../../lib-c/twr.a -o balls.wasm \
--no-entry --allow-undefined \
--export=memory --initial-memory=1048576 --max-memory=1048576 \
--export=bounce_balls_init --export=bounce_balls_move

# twrWasmModuleAsync version (building both for testing)
wasm-ld $(OBJ) $(OBJOUTDIR)/balls-wasm.o -o balls-a.wasm \
wasm-ld $(OBJ) ../../lib-c/twr.a -o balls-a.wasm \
--no-entry --allow-undefined \
--export=memory --shared-memory --no-check-features --initial-memory=1048576 --max-memory=1048576 \
--export=bounce_balls_init --export=bounce_balls_move
--export=bounce_balls_init --export=bounce_balls_move

PUBLIC_URL:= ./
bundle: default
Expand Down
Binary file modified examples/balls/balls-a.wasm
Binary file not shown.
Binary file modified examples/balls/balls.wasm
Binary file not shown.
23 changes: 14 additions & 9 deletions examples/fft/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@

# default target builds TypeScript and C. Can be executed with Chrome from local filesystem (with flags, see ReadMe)
# bundle target creates a bundle in dist folder that can be executed http://localhost:8000 with python server.py
# default target should be built before bulding bundle target
# tested with mingw32-make using windows

CC := clang
CFLAGS := -cc1 -emit-llvm-bc -triple=wasm32-unknown-unknown-wasm -std=c17 -I ../../include

# -nostdinc Disable standard #include directories, provided by tiny-wasm-runtime
# -nostdlib Disable standard c library, provided by tiny-wasm-runtime
# -nostdlibinc tells the compiler to not search the standard system directories or compiler builtin directories for include files, c++ only?
# -fno-exceptions Don't generate stack exception code since we don't use std:: exception handling
TWRCFLAGS := --target=wasm32 -fno-exceptions -nostdinc -nostdlib -isystem ../../include

# -O3 Optimization level 3
# -Wall Warn all
# -c compile w/o linking
# -g for debug symbols
# -v verbose
CFLAGS := -c -Wall -O3 $(TWRCFLAGS)

default: fft-script.js kiss_fft.wasm

Expand All @@ -16,9 +24,7 @@ kiss_fft.o : kiss_fft.c kiss_fft.h _kiss_fft_guts.h
$(CC) $(CFLAGS) $< -o $@

kiss_fft.wasm: kiss_fft.o
llvm-link -o kiss_fft.bc kiss_fft.o ../../lib-c/twr.a
llc -filetype=obj kiss_fft.bc -o kiss_fft-wasm.o
wasm-ld kiss_fft-wasm.o -o kiss_fft.wasm \
wasm-ld kiss_fft.o ../../lib-c/twr.a -o kiss_fft.wasm \
--no-entry --allow-undefined \
--export=memory --initial-memory=1048576 --max-memory=1048576 \
--export=kiss_fft_alloc --export=kiss_fft --export=twr_free
Expand All @@ -30,7 +36,6 @@ bundle: default

clean:
rm -f *.o
rm -f *.bc
rm -f fft-script.js
rm -f *.wasm
rm -r -f dist
Expand Down
Binary file modified examples/fft/kiss_fft.wasm
Binary file not shown.
26 changes: 15 additions & 11 deletions examples/function-calls/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@

# tested with mingw32-make using windows


CC := clang
CFLAGS := -cc1 -emit-llvm-bc -triple=wasm32-unknown-unknown-wasm -std=c17 -I ../../include

# -nostdinc Disable standard #include directories, provided by tiny-wasm-runtime
# -nostdlib Disable standard c library, provided by tiny-wasm-runtime
# -nostdlibinc tells the compiler to not search the standard system directories or compiler builtin directories for include files, c++ only?
# -fno-exceptions Don't generate stack exception code since we don't use std:: exception handling
TWRCFLAGS := --target=wasm32 -fno-exceptions -nostdinc -nostdlib -isystem ../../include

# -O3 Optimization level 3
# -Wall Warn all
# -c compile w/o linking
# -g for debug symbols
# -v verbose
CFLAGS := -c -Wall -O3 $(TWRCFLAGS)

.PHONY: wasm bundle

Expand All @@ -13,20 +24,14 @@ function-calls.o: function-calls.c
$(CC) $(CFLAGS) $< -o $@

function-calls.wasm: function-calls.o
# llvm-link takes several LLVM bitcode files and links them together into a single LLVM bitcode file.
llvm-link -o function-calls.bc function-calls.o ../../lib-c/twr.a

# llc compiles LLVM source inputs into assembly language for a specified architecture.
llc -filetype=obj function-calls.bc -o function-calls-wasm.o

# wasm-ld takes WebAssembly binaries as inputs and produces a WebAssembly binary as its output. Mimics behavior of the ELF lld.
wasm-ld function-calls-wasm.o -o function-calls.wasm \
wasm-ld function-calls.o ../../lib-c/twr.a -o function-calls.wasm \
--no-entry --allow-undefined \
--export=memory --initial-memory=1048576 --max-memory=1048576 \
--export=function_calls --export=get_structu32 --export=get_structu8 --export=twr_wasm_print_mem_debug_stats

# twrWasmModuleAsync uses shared memory
wasm-ld function-calls-wasm.o -o function-calls-a.wasm \
wasm-ld function-calls.o ../../lib-c/twr.a -o function-calls-a.wasm \
--no-entry --allow-undefined \
--export=memory --shared-memory --no-check-features --initial-memory=1048576 --max-memory=1048576 \
--export=function_calls --export=get_structu32 --export=get_structu8 --export=twr_wasm_print_mem_debug_stats
Expand All @@ -41,7 +46,6 @@ bundle: wasm

clean:
rm -f *.o
rm -f *.bc
rm -f *.wasm
rm -f -r dist
rm -f -r .parcel-cache
Expand Down
6 changes: 4 additions & 2 deletions examples/function-calls/async.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

console.log("twrWasmModuleAsync");

let amod;

try {
const amod = new twrWasmModuleAsync();
amod = new twrWasmModuleAsync();

document.getElementById("twr_iodiv").innerHTML ="<br>";

Expand All @@ -44,7 +46,7 @@

amod.divLog("function_calls() returned: "+r);
amod.divLog("as string: ", amod.getString(r));
if (amod.getString(r)!="fourty-two - if only it were that simple") throw new Error("error");
if (amod.getString(r)!="forty-two - if only it were that simple") throw new Error("42 error");

r=await amod.executeC(["get_structu32"]);
amod.divLog("get_struct32() returned: "+r);
Expand Down
Binary file modified examples/function-calls/function-calls-a.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/function-calls/function-calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const char* function_calls(

printf("\n\nC code run is complete\n");

return "fourty-two - if only it were that simple";
return "forty-two - if only it were that simple";
}

struct return_values {
Expand Down
Binary file modified examples/function-calls/function-calls.wasm
Binary file not shown.
40 changes: 21 additions & 19 deletions examples/function-calls/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
<script type="module">
import {twrWasmModule} from "tiny-wasm-runtime";

let mod;

try {
const amod = new twrWasmModule();
mod = new twrWasmModule();

document.getElementById("twr_iodiv").innerHTML ="<br>";

await amod.loadWasm("./function-calls.wasm");
await mod.loadWasm("./function-calls.wasm");

// this output goes to the console
await amod.executeC(["twr_wasm_print_mem_debug_stats"]);
await mod.executeC(["twr_wasm_print_mem_debug_stats"]);

const s="This is a string.";

Expand All @@ -35,29 +37,29 @@

const url=new URL('test-file.txt', import.meta.url);

amod.divLog("module type is twrWasmModule\n");
amod.divLog("--- begin C call ---");
let r=await amod.executeC(["function_calls", s, ba.buffer, ba.length, url]);
amod.divLog("--- end C call ---\n");
mod.divLog("module type is twrWasmModule\n");
mod.divLog("--- begin C call ---");
let r=await mod.executeC(["function_calls", s, ba.buffer, ba.length, url]);
mod.divLog("--- end C call ---\n");

amod.divLog("function_calls() returned: "+r);
amod.divLog("as string: ", amod.getString(r));
if (amod.getString(r)!="fourty-two - if only it were that simple") throw new Error("error");
mod.divLog("function_calls() returned: "+r);
mod.divLog("as string: ", mod.getString(r));
if (mod.getString(r)!="forty-two - if only it were that simple") throw new Error("42 error");

r=await amod.executeC(["get_structu32"]);
amod.divLog("get_struct32() returned: "+r);
const ba32=amod.getU32Arr(r);
amod.divLog("three 32 bit ints are: ", ba32[0], ba32[1], ba32[2]);
r=await mod.executeC(["get_structu32"]);
mod.divLog("get_struct32() returned: "+r);
const ba32=mod.getU32Arr(r);
mod.divLog("three 32 bit ints are: ", ba32[0], ba32[1], ba32[2]);
if (ba32[0]!=1 || ba32[1]!=2000 || ba32[2]!=3) throw new Error("error");

r=await amod.executeC(["get_structu8"]);
amod.divLog("get_struct8() returned: "+r);
const ba8=amod.getU8Arr(r);
amod.divLog("three 8 bit ints are: ", ba8[0], ba8[1], ba8[2]);
r=await mod.executeC(["get_structu8"]);
mod.divLog("get_struct8() returned: "+r);
const ba8=mod.getU8Arr(r);
mod.divLog("three 8 bit ints are: ", ba8[0], ba8[1], ba8[2]);
if (ba8[0]!=100 || ba8[1]!=101 || ba8[2]!=102) throw new Error("error");
}
catch(ex) {
amod.divLog("unexpected exception");
mod.divLog("unexpected exception");
throw ex;
}

Expand Down
Loading

0 comments on commit bf2d158

Please sign in to comment.