From 9e207cfe7b32a03612fd4d176eaf704dbca9c720 Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Thu, 11 Jul 2024 15:42:08 -0400 Subject: [PATCH] Update moon compiler and examples Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- README.md | 2 +- examples/count-vowels/index.html | 7 +++---- examples/greet/index.html | 3 +-- moon.mod.json | 2 +- pdk/extism/env.mbt | 4 ---- pdk/host/host.mbt | 11 +++-------- scripts/python-server.sh | 3 ++- 7 files changed, 11 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index d1e14b5..22f3919 100644 --- a/README.md +++ b/README.md @@ -544,7 +544,7 @@ To run the examples, type: The code has been updated to support compiler `moon version`: ```bash -moon 0.1.20240708 (4e51712 2024-07-08) +moon 0.1.20240711 (84f6b86 2024-07-11) ``` ## Reach Out! diff --git a/examples/count-vowels/index.html b/examples/count-vowels/index.html index 23d33e9..fcd02d3 100644 --- a/examples/count-vowels/index.html +++ b/examples/count-vowels/index.html @@ -13,7 +13,6 @@ WebAssembly.instantiateStreaming(fetch(wasmUnderTest), importObject).then( (obj) => { console.log('Using simulated Extism SDK...') - obj.instance.exports._initialize() // configs.vowels = 'aeiouyAEIOUY' inputString.value = 'Once upon a dream' obj.instance.exports['count_vowels']() @@ -34,10 +33,10 @@ console.log('Using official Extism JavaScript SDK...') let out = await plugin.call('count_vowels', 'from official Extism JavaScript SDK') - console.log(out.text()); + console.log(out.text()) out = await plugin.call('count_vowels', 'eight more vowels yo ho') - console.log(out.text()); + console.log(out.text()) - + \ No newline at end of file diff --git a/examples/greet/index.html b/examples/greet/index.html index caad08f..c6953ec 100644 --- a/examples/greet/index.html +++ b/examples/greet/index.html @@ -12,7 +12,6 @@ // First, use the simulated Extism SDK written in JavaScript: WebAssembly.instantiateStreaming(fetch(wasmUnderTest), importObject).then( (obj) => { - obj.instance.exports._initialize() inputString.value = 'from simulated Extism SDK' obj.instance.exports['greet']() flush() @@ -29,7 +28,7 @@ ) let out = await plugin.call('greet', 'from official Extism JavaScript SDK') - console.log(out.text()); + console.log(out.text()) diff --git a/moon.mod.json b/moon.mod.json index 79f99ba..2d1789d 100644 --- a/moon.mod.json +++ b/moon.mod.json @@ -1,6 +1,6 @@ { "name": "extism/moonbit-pdk", - "version": "0.18.0", + "version": "0.19.0", "deps": { "gmlewis/json": "0.11.0" }, diff --git a/pdk/extism/env.mbt b/pdk/extism/env.mbt index 9a4735d..75f5de7 100644 --- a/pdk/extism/env.mbt +++ b/pdk/extism/env.mbt @@ -98,7 +98,3 @@ pub fn log_debug(offset : Int64) = "extism:host/env" "log_debug" /// `log_error` logs an "error" string to the host from the previously-written UTF-8 string written to `offset`. /// The user of this PDK will typically not call this method directly. pub fn log_error(offset : Int64) = "extism:host/env" "log_error" - -// /// `log_trace` logs a "trace" string to the host from the previously-written UTF-8 string written to `offset`. -// /// The user of this PDK will typically not call this method directly. -// pub fn log_trace(offset : Int64) = "extism:host/env" "log_trace" diff --git a/pdk/host/host.mbt b/pdk/host/host.mbt index a83e64f..b0bc44c 100644 --- a/pdk/host/host.mbt +++ b/pdk/host/host.mbt @@ -27,7 +27,9 @@ fn output_bytes_to_memory(b : Bytes) -> Memory { pub fn output(b : Bytes) -> Unit { let mem = output_bytes_to_memory(b) @extism.output_set(mem.offset, mem.length) - mem.free() + // 2024-07-11: There is currently an issue with the JS SDK where if memory is + // freed in the next line, the host receives a null from the `await plugin.call` function. + // mem.free() } /// `output_string` converts a MoonBit String (UTF-16) to an Extism string (UTF-8) @@ -81,13 +83,6 @@ pub fn log_debug_str(s : String) -> Unit { @extism.free(offset) } -// /// `log_trace_str` is a helper function to log a trace string to the host. -// pub fn log_trace_str(s : String) -> Unit { -// let { offset, .. } = @pdk.ToUtf8::to_utf8(s) |> output_bytes_to_memory() -// @extism.log_trace(offset) -// @extism.free(offset) -// } - /// `log_error_str` is a helper function to log an error string to the host. pub fn log_error_str(s : String) -> Unit { let { offset, .. } = @pdk.ToUtf8::to_utf8(s) |> output_bytes_to_memory() diff --git a/scripts/python-server.sh b/scripts/python-server.sh index 97469b9..717e716 100755 --- a/scripts/python-server.sh +++ b/scripts/python-server.sh @@ -1,2 +1,3 @@ -#!/bin/bash -ex +#!/bin/bash -e +echo "Please visit in your browser: http://localhost:8080/examples/count-vowels or http://localhost:8080/examples/greet and open the DevTools console to see the output" python3 -m http.server 8080