Skip to content

Commit

Permalink
Update moon compiler and examples
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Lewis <[email protected]>
  • Loading branch information
gmlewis committed Jul 11, 2024
1 parent c7b2a16 commit 9e207cf
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
7 changes: 3 additions & 4 deletions examples/count-vowels/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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']()
Expand All @@ -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())
</script>
</body>

</html>
</html>
3 changes: 1 addition & 2 deletions examples/greet/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -29,7 +28,7 @@
)

let out = await plugin.call('greet', 'from official Extism JavaScript SDK')
console.log(out.text());
console.log(out.text())
</script>
</body>

Expand Down
2 changes: 1 addition & 1 deletion moon.mod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "extism/moonbit-pdk",
"version": "0.18.0",
"version": "0.19.0",
"deps": {
"gmlewis/json": "0.11.0"
},
Expand Down
4 changes: 0 additions & 4 deletions pdk/extism/env.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
11 changes: 3 additions & 8 deletions pdk/host/host.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion scripts/python-server.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9e207cf

Please sign in to comment.