Skip to content

Commit

Permalink
Update to moonc v0.1.20250224+e2253638a
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Lewis <[email protected]>
  • Loading branch information
gmlewis committed Mar 4, 2025
1 parent 36e3720 commit fb8e039
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 63 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.20250210 (da67b3c 2025-02-10) ~/.moon/bin/moon
moonc v0.1.20250210+7be093d1f ~/.moon/bin/moonc
moonrun 0.1.20250210 (da67b3c 2025-02-10) ~/.moon/bin/moonrun
moon 0.1.20250224 (d4d8b07 2025-02-24) ~/.moon/bin/moon
moonc v0.1.20250224+e2253638a ~/.moon/bin/moonc
moonrun 0.1.20250224 (d4d8b07 2025-02-24) ~/.moon/bin/moonrun
```

Use `moonup` to manage `moon` compiler versions:
Expand Down
41 changes: 8 additions & 33 deletions examples/add/add.mbt
Original file line number Diff line number Diff line change
@@ -1,53 +1,28 @@
///|
struct Add {
priv 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 {
{ "a": Number(a), "b": Number(b) } => Some({ a: a.to_int(), b: b.to_int() })
_ => None
}
}

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

///|
pub fn Add::parse(s : String) -> Add!ParseError {
match @json.parse?(s) {
Ok(jv) =>
match Add::from_json(jv) {
Some(value) => value
None => raise ParseError("unable to parse Add \{s}")
}
Err(e) => raise ParseError("unable to parse Add \{s}: \{e}")
}
}
} derive(FromJson)

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

///|
pub fn add() -> Int {
let input = @host.input_string()
let params = try {
Add::parse!(input)
let params : Add = try {
@json.from_json!(@json.parse!(input))
} catch {
ParseError(e) => {
@host.set_error(e)
e => {
@host.set_error(e.to_string())
return 1
}
}
//
let sum = { sum: params.a + params.b }
let json_value = sum.to_json()
@host.output_json_value(json_value)
@host.output_json_value(sum.to_json())
0 // success
}

Expand Down
11 changes: 0 additions & 11 deletions examples/add/add.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@ package extism/moonbit-pdk/examples/add
fn add() -> Int

// Types and methods
type Add
impl Add {
from_json(Json) -> Self?
parse(String) -> Self!ParseError
}

type ParseError
impl Show for ParseError

type Sum
impl ToJson for Sum

// Type aliases

Expand Down
1 change: 1 addition & 0 deletions examples/arrays/plugin-functions.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub fn all_three_object() -> Int {
"ints": Array(ints),
"floats": Array(floats),
"strings": Array(strings),
..
}
) => {
let ints : Array[Int] = ints
Expand Down
11 changes: 0 additions & 11 deletions examples/draw-on-canvas/draw-on-canvas.mbti

This file was deleted.

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.47.1",
"version": "0.47.2",
"deps": {},
"readme": "README.md",
"repository": "https://github.com/extism/moonbit-pdk",
Expand Down
4 changes: 1 addition & 3 deletions pdk/http/http.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ pub(all) enum Method {
TRACE
PATCH
}
impl Method {
to_json(Self) -> Json
}
impl Show for Method
impl ToJson for Method

pub(all) struct Request {
http_method : Method
Expand Down
2 changes: 1 addition & 1 deletion pdk/http/method.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ pub(all) enum Method {
} derive(Show)

///| `Method::to_json` is required because `derive(ToJson)` generates `{"$tag":"GET"}` here instead of `"GET"`.
pub fn to_json(self : Method) -> Json {
pub impl ToJson for Method with to_json(self) {
self.to_string().to_json()
}

0 comments on commit fb8e039

Please sign in to comment.