Skip to content

Commit

Permalink
Update to moonc v0.1.20240806+533ed16a3
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com>
  • Loading branch information
gmlewis committed Aug 7, 2024
1 parent b182a21 commit aa9be69
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 31 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Now paste this into your `main/main.mbt` file:
```rust
pub fn greet() -> Int {
let name = @host.input_string()
let greeting = "Hello, \(name)!"
let greeting = "Hello, \{name}!"
@host.output_string(greeting)
0 // success
}
Expand Down Expand Up @@ -141,7 +141,7 @@ pub fn greet() -> Int {
@host.set_error("Sorry, we don't greet Benjamins!")
return 1 // failure
}
let greeting = "Hello, \(name)!"
let greeting = "Hello, \{name}!"
@host.output_string(greeting)
0 // success
}
Expand Down Expand Up @@ -190,11 +190,11 @@ pub fn Add::parse(s : String) -> Add!String {
match Add::from_json(jv) {
Some(value) => value
None => {
raise "unable to parse Add \(s)"
raise "unable to parse Add \{s}"
}
}
Err(e) => {
raise "unable to parse Add \(s): \(e)"
raise "unable to parse Add \{s}: \{e}"
}
}
}
Expand Down Expand Up @@ -277,7 +277,7 @@ pub fn greet() -> Int {
return 1 // failure
}
}
let greeting = "Hello, \(user)!"
let greeting = "Hello, \{user}!"
@host.output_string(greeting)
0 // success
}
Expand Down Expand Up @@ -542,8 +542,8 @@ The code has been updated to support compiler:

```bash
$ moon version --all
moon 0.1.20240802 (be3ee4c 2024-08-02) ~/.moon/bin/moon
moonc v0.1.20240802+b0ab1523a ~/.moon/bin/moonc
moon 0.1.20240807 (235e4bc 2024-08-07) ~/.moon/bin/moon
moonc v0.1.20240807+41236f720 ~/.moon/bin/moonc
moonrun 0.1.20240716 (08bce9c 2024-07-16) ~/.moon/bin/moonrun
```

Expand Down
31 changes: 17 additions & 14 deletions examples/arrays/plugin-functions.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn progressive_sum_ints() -> Int {
@json.parse!(s)
} catch {
e => {
@host.set_error("unable to parse input: \(e)")
@host.set_error("unable to parse input: \{e}")
return 1 // failure
}
}
Expand All @@ -32,7 +32,7 @@ pub fn progressive_sum_floats() -> Int {
@json.parse!(s)
} catch {
e => {
@host.set_error("unable to parse input: \(e)")
@host.set_error("unable to parse input: \{e}")
return 1 // failure
}
}
Expand All @@ -59,7 +59,7 @@ pub fn progressive_concat_strings() -> Int {
@json.parse!(s)
} catch {
e => {
@host.set_error("unable to parse input: \(e)")
@host.set_error("unable to parse input: \{e}")
return 1 // failure
}
}
Expand All @@ -86,7 +86,7 @@ pub fn all_three_object() -> Int {
@json.parse!(s)
} catch {
e => {
@host.set_error("unable to parse input: \(e)")
@host.set_error("unable to parse input: \{e}")
return 1 // failure
}
}
Expand All @@ -99,19 +99,22 @@ pub fn all_three_object() -> Int {
"strings": Array(strings),
}
) => {
let ints : Array[Int] = ints.map(fn { n => n.as_number() }).filter(
fn { n => not(n.is_empty()) },
).map(fn { n => n.unwrap().to_int() })
let floats : Array[Double] = floats.map(fn { n => n.as_number() }).filter(
fn { n => not(n.is_empty()) },
).map(fn { n => n.unwrap() })
let strings : Array[String] = strings.map(fn { n => n.as_string() }).filter(
fn { n => not(n.is_empty()) },
).map(fn { n => n.unwrap() })
let ints : Array[Int] = ints
.map(fn { n => n.as_number() })
.filter(fn { n => not(n.is_empty()) })
.map(fn { n => n.unwrap().to_int() })
let floats : Array[Double] = floats
.map(fn { n => n.as_number() })
.filter(fn { n => not(n.is_empty()) })
.map(fn { n => n.unwrap() })
let strings : Array[String] = strings
.map(fn { n => n.as_string() })
.filter(fn { n => not(n.is_empty()) })
.map(fn { n => n.unwrap() })
{ ints, floats, strings }
}
_ => {
@host.set_error("unable to parse input: \(s)")
@host.set_error("unable to parse input: \{s}")
return 1 // failure
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/greet/greet.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// It returns 0 to the host on success.
pub fn greet() -> Int {
let input = @host.input_string()
let greeting = "Hello, \(input)!"
let greeting = "Hello, \{input}!"
@host.output_string(greeting)
0 // success
}
4 changes: 2 additions & 2 deletions moon.mod.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "gmlewis/moonbit-pdk",
"version": "0.31.0",
"version": "0.32.0",
"deps": {
"gmlewis/jsonutil": "0.21.0"
"gmlewis/jsonutil": "0.22.0"
},
"readme": "README.md",
"repository": "https://github.com/gmlewis/moonbit-pdk",
Expand Down
6 changes: 3 additions & 3 deletions pdk/host/memory.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ pub fn to_string(self : Memory) -> String {
/// to a MoonBit Int.
pub fn to_int(self : Memory) -> Int {
let bytes = self.to_bytes()
bytes[0].to_int() + bytes[1].to_int().lsl(8) + bytes[2].to_int().lsl(16) + bytes[3].to_int().lsl(
24,
)
bytes[0].to_int() + bytes[1].to_int().lsl(8) + bytes[2].to_int().lsl(16) + bytes[3]
.to_int()
.lsl(24)
}

/// `to_bytes` reads the (unprocessed) bytes residing in the host memory
Expand Down
9 changes: 5 additions & 4 deletions pdk/http/header.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ pub fn Header::new() -> Header {
}

impl @jsonutil.ToJson for Header with to_json(self) {
let pairs = self.0.iter().map(
fn { (k, v) => (k, @json.JsonValue::String(v)) },
).collect()
let pairs = self.0
.iter()
.map(fn { (k, v) => (k, @json.JsonValue::String(v)) })
.collect()
|> Map::from_array()
@json.JsonValue::Object(pairs)
}
Expand All @@ -19,7 +20,7 @@ impl @jsonutil.ToJson for Header with to_json(self) {
/// If the header key already exists, the value is appended after a comma.
pub fn add(self : Header, key : String, value : String) -> Unit {
match self.0.get(key) {
Some(v) => self.0[key] = "\(v),\(value)"
Some(v) => self.0[key] = "\{v},\{value}"
None => self.0[key] = value
}
}
Expand Down

0 comments on commit aa9be69

Please sign in to comment.