Skip to content

Commit

Permalink
Update to moonc v0.1.20241202+8756d160d
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Lewis <[email protected]>
  • Loading branch information
gmlewis committed Dec 3, 2024
1 parent 8928309 commit 17d19ea
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 98 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,9 @@ The code has been updated to support compiler:

```bash
$ moon version --all
moon 0.1.20241115 (67c2b06 2024-11-15) ~/.moon/bin/moon
moonc v0.1.20241115+351cfb074 ~/.moon/bin/moonc
moonrun 0.1.20241115 (67c2b06 2024-11-15) ~/.moon/bin/moonrun
moon 0.1.20241202 (28bfce6 2024-12-02) ~/.moon/bin/moon
moonc v0.1.20241202+8756d160d ~/.moon/bin/moonc
moonrun 0.1.20241202 (28bfce6 2024-12-02) ~/.moon/bin/moonrun
```

Use `moonup` to manage `moon` compiler versions:
Expand Down
6 changes: 6 additions & 0 deletions examples/add/add.mbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
///|
struct Add {
a : Int
b : Int
}

///|
pub fn Add::from_json(value : Json) -> Add? {
// From: https://github.com/moonbitlang/core/issues/892#issuecomment-2306068783
match value {
Expand All @@ -11,8 +13,10 @@ pub fn Add::from_json(value : Json) -> Add? {
}
}

///|
type! ParseError String derive(Show)

///|
pub fn Add::parse(s : String) -> Add!ParseError {
match @json.parse?(s) {
Ok(jv) =>
Expand All @@ -24,10 +28,12 @@ pub fn Add::parse(s : String) -> Add!ParseError {
}
}

///|
struct Sum {
sum : Int
} derive(ToJson)

///|
pub fn add() -> Int {
let input = @host.input_string()
let params = try {
Expand Down
4 changes: 2 additions & 2 deletions examples/arrays/all-three.mbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/// `AllThree` represents a JSON object with all three array types.
///| `AllThree` represents a JSON object with all three array types.
pub(all) struct AllThree {
ints : Array[Int]
floats : Array[Double]
strings : Array[String]
} derive(Eq, Show, ToJson)

/// `process_all_three` processes all three array types.
///| `process_all_three` processes all three array types.
pub fn process_all_three(all3 : AllThree) -> AllThree {
{
ints: process_ints(all3.ints),
Expand Down
2 changes: 1 addition & 1 deletion examples/arrays/floats.mbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// `process_floats` sums up an array of floats.
///| `process_floats` sums up an array of floats.
pub fn process_floats(floats : Array[Double]) -> Array[Double] {
let mut sum = 0.0
floats.eachi(
Expand Down
2 changes: 1 addition & 1 deletion examples/arrays/ints.mbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// `process_ints` sums up an array of ints.
///| `process_ints` sums up an array of ints.
pub fn process_ints(ints : Array[Int]) -> Array[Int] {
let mut sum = 0
ints.eachi(
Expand Down
8 changes: 4 additions & 4 deletions examples/arrays/plugin-functions.mbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// `progressive_sum_ints` tests passing arrays of ints.
///| `progressive_sum_ints` tests passing arrays of ints.
pub fn progressive_sum_ints() -> Int {
let s = @host.input_string()
let jv = try {
Expand All @@ -25,7 +25,7 @@ pub fn progressive_sum_ints() -> Int {
0 // success
}

/// `progressive_sum_floats` tests passing arrays of floats.
///| `progressive_sum_floats` tests passing arrays of floats.
pub fn progressive_sum_floats() -> Int {
let s = @host.input_string()
let jv = try {
Expand All @@ -52,7 +52,7 @@ pub fn progressive_sum_floats() -> Int {
0 // success
}

/// `progressive_concat_strings` tests passing arrays of strings.
///| `progressive_concat_strings` tests passing arrays of strings.
pub fn progressive_concat_strings() -> Int {
let s = @host.input_string()
let jv = try {
Expand All @@ -79,7 +79,7 @@ pub fn progressive_concat_strings() -> Int {
0 // success
}

/// `all_three_object` tests passing an object of all three arrays.
///| `all_three_object` tests passing an object of all three arrays.
pub fn all_three_object() -> Int {
let s = @host.input_string()
let jv = try {
Expand Down
2 changes: 1 addition & 1 deletion examples/arrays/strings.mbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// `process_strings` concatenates an array of strings.
///| `process_strings` concatenates an array of strings.
pub fn process_strings(strings : Array[String]) -> Array[String] {
let parts = []
strings.eachi(
Expand Down
9 changes: 6 additions & 3 deletions examples/count-vowels/count-vowels.mbt
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
/// `default_vowels` represents the default set of vowels
///| `default_vowels` represents the default set of vowels
/// if the host provides no "config.vowels" string.
let default_vowels = "aeiouAEIOU"

/// `VowelReport` represents the JSON struct returned to the host.
///| `VowelReport` represents the JSON struct returned to the host.
pub(all) struct VowelReport {
count : Int
total : Int
vowels : String
} derive(Show, Eq, ToJson)

///|
fn get_total() -> Int {
@var.get_int("total").or_default()
}

///|
fn store_total(total : Int) -> Unit {
@var.set_int("total", total)
}

///|
fn get_vowels() -> String {
@config.get("vowels").or(default_vowels)
}

/// `count_vowels` reads the input string from the host, reads the "vowels"
///| `count_vowels` reads the input string from the host, reads the "vowels"
/// config from the host, then counts the number of vowels in the input
/// string and keeps a running total (over multiple iterations)
/// in the host's "total" var.
Expand Down
2 changes: 1 addition & 1 deletion examples/greet/greet.mbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// `greet` reads the input string from the host and writes a
///| `greet` reads the input string from the host and writes a
/// greeting to the host's output string.
/// It returns 0 to the host on success.
pub fn greet() -> Int {
Expand Down
2 changes: 1 addition & 1 deletion examples/http-get/http-get.mbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// `http_get` makes a GET HTTP request through the Extism host, gets
///| `http_get` makes a GET HTTP request through the Extism host, gets
/// the response back, then sends it (unmodified) to the Extism host output.
/// It returns 0 to the host on success.
pub fn http_get() -> Int {
Expand Down
1 change: 1 addition & 0 deletions examples/kitchen-sink/kitchen-sink.mbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
///|
pub fn kitchen_sink() -> Int {
// Input
let input = @host.input_string()
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.43.0",
"version": "0.44.0",
"deps": {},
"readme": "README.md",
"repository": "https://github.com/extism/moonbit-pdk",
Expand Down
6 changes: 3 additions & 3 deletions pdk/config/config.mbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// `Config` provides methods to get "config" data from the host.
///| `Config` provides methods to get "config" data from the host.
pub(all) struct Config {}

/// `Config::get_memory` returns a "config" Memory block from the host that is keyed by `key`.
///| `Config::get_memory` returns a "config" Memory block from the host that is keyed by `key`.
/// Note that no processing is performed on this block of memory.
pub fn Config::get_memory(key : String) -> @host.Memory? {
let key_mem = @host.allocate_string(key)
Expand All @@ -17,7 +17,7 @@ pub fn Config::get_memory(key : String) -> @host.Memory? {
Some({ offset, length })
}

/// `Config::get` returns a "config" String from the host that is keyed by `key`.
///| `Config::get` returns a "config" String from the host that is keyed by `key`.
/// Note that the Extism host strings are UTF-8 and therefore the returned
/// String is encoded as UTF-16 in compliance with MoonBit Strings.
pub fn Config::get(key : String) -> String? {
Expand Down
42 changes: 21 additions & 21 deletions pdk/extism/env.mbt
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
/// `input_length` returns the number of (unprocessed) bytes provided by the host via its input methods.
///| `input_length` returns the number of (unprocessed) bytes provided by the host via its input methods.
/// The user of this PDK will typically not call this method directly.
pub fn input_length() -> Int64 = "extism:host/env" "input_length"

/// `input_load_u8` returns the byte at location `offset` of the "input" data from the host.
///| `input_load_u8` returns the byte at location `offset` of the "input" data from the host.
/// The user of this PDK will typically not call this method directly.
pub fn input_load_u8(offset : Int64) -> Byte = "extism:host/env" "input_load_u8"

/// `input_load_u64` returns the 64-bit unsigned integer of the "input" data from the host.
///| `input_load_u64` returns the 64-bit unsigned integer of the "input" data from the host.
/// Note that MoonBit has no unsigned integers,
/// so the result is returned as an Int64.
/// Also note that `offset` must lie on an 8-byte boundary.
/// The user of this PDK will typically not call this method directly.
pub fn input_load_u64(offset : Int64) -> Int64 = "extism:host/env" "input_load_u64"

/// `length` returns the number of bytes associated with the block of host memory
///| `length` returns the number of bytes associated with the block of host memory
/// located at `offset`.
/// The user of this PDK will typically not call this method directly.
pub fn length(offset : Int64) -> Int64 = "extism:host/env" "length"

/// `alloc` allocates `length` bytes of data with host memory for use by the plugin
///| `alloc` allocates `length` bytes of data with host memory for use by the plugin
/// and returns its `offset` within the host memory block.
/// The user of this PDK will typically not call this method directly.
pub fn alloc(length : Int64) -> Int64 = "extism:host/env" "alloc"

/// `free` releases the bytes previously allocated with `alloc` at the given `offset`.
///| `free` releases the bytes previously allocated with `alloc` at the given `offset`.
/// The user of this PDK will typically not call this method directly.
pub fn free(offset : Int64) = "extism:host/env" "free"

/// `output_set` sets the "output" data from the plugin to the host to be the memory that
///| `output_set` sets the "output" data from the plugin to the host to be the memory that
/// has been written at `offset` with the given `length`.
/// The user of this PDK will typically not call this method directly.
pub fn output_set(offset : Int64, length : Int64) = "extism:host/env" "output_set"

/// `error_set` sets the "error" data from the plugin to the host to be the memory that
///| `error_set` sets the "error" data from the plugin to the host to be the memory that
/// has been written at `offset`.
/// The user of this PDK will typically not call this method directly.
pub fn error_set(offset : Int64) = "extism:host/env" "error_set"

/// `config_get` returns the host memory block offset for the "config" data associated with
///| `config_get` returns the host memory block offset for the "config" data associated with
/// the key which is represented by the UTF-8 string which as been previously
/// written at `offset`.
/// The user of this PDK will typically not call this method directly.
pub fn config_get(offset : Int64) -> Int64 = "extism:host/env" "config_get"

/// `var_get` returns the host memory block offset for the "var" data associated with
///| `var_get` returns the host memory block offset for the "var" data associated with
/// the key which is represented by the UTF-8 string which as been previously
/// written at `offset`.
/// The user of this PDK will typically not call this method directly.
pub fn var_get(offset : Int64) -> Int64 = "extism:host/env" "var_get"

/// `var_set` sets the host "var" memory keyed by the UTF-8 string located at `offset`
///| `var_set` sets the host "var" memory keyed by the UTF-8 string located at `offset`
/// to be the value which has been previously written at `value_offset`.
/// The user of this PDK will typically not call this method directly.
pub fn var_set(offset : Int64, value_offset : Int64) = "extism:host/env" "var_set"

/// `store_u8` stores the Byte `b` at location `offset` in the host memory block.
///| `store_u8` stores the Byte `b` at location `offset` in the host memory block.
/// The user of this PDK will typically not call this method directly.
pub fn store_u8(offset : Int64, b : Byte) = "extism:host/env" "store_u8"

/// `load_u8` returns the Byte located at `offset` in the host memory block.
///| `load_u8` returns the Byte located at `offset` in the host memory block.
/// The user of this PDK will typically not call this method directly.
pub fn load_u8(offset : Int64) -> Byte = "extism:host/env" "load_u8"

/// `store_u64` stores the Int64 value `v` at location `offset` in the host memory block.
///| `store_u64` stores the Int64 value `v` at location `offset` in the host memory block.
/// Note that MoonBit does not have unsigned integers, but the host interprets
/// the provided `v` value as an unsigned 64-bit integer.
/// Also note that `offset` must lie on an 8-byte boundary.
/// The user of this PDK will typically not call this method directly.
pub fn store_u64(offset : Int64, v : Int64) = "extism:host/env" "store_u64"

/// `load_u64` returns the 64-bit unsigned integer at location `offset` in the host memory block.
///| `load_u64` returns the 64-bit unsigned integer at location `offset` in the host memory block.
/// Note that MoonBit has no unsigned integers,
/// so the result is returned as an Int64.
/// Also note that `offset` must lie on an 8-byte boundary.
/// The user of this PDK will typically not call this method directly.
pub fn load_u64(offset : Int64) -> Int64 = "extism:host/env" "load_u64"

/// `http_request` sends the HTTP request to the Extism host and returns back the
///| `http_request` sends the HTTP request to the Extism host and returns back the
/// memory offset to the response body.
pub fn http_request(req : Int64, body : Int64) -> Int64 = "extism:host/env" "http_request"

/// `http_status_code` returns the status code for the last-sent `http_request` call.
///| `http_status_code` returns the status code for the last-sent `http_request` call.
pub fn http_status_code() -> Int = "extism:host/env" "http_status_code"

/// `log_warn` logs a "warning" string to the host from the previously-written UTF-8 string written to `offset`.
///| `log_warn` logs a "warning" 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_warn(offset : Int64) = "extism:host/env" "log_warn"

/// `log_info` logs an "info" string to the host from the previously-written UTF-8 string written to `offset`.
///| `log_info` logs an "info" 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_info(offset : Int64) = "extism:host/env" "log_info"

/// `log_debug` logs a "debug" string to the host from the previously-written UTF-8 string written to `offset`.
///| `log_debug` logs a "debug" 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_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`.
///| `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"
Loading

0 comments on commit 17d19ea

Please sign in to comment.