Build with current MoonBit toolchain

Migrate to moon.mod/moon.pkg, update suberror and Json construction
syntax, import @json, annotate FFI params #borrow, and clear all
deprecation warnings. Builds cleanly, tests pass, and the CLI was
smoke-tested against a local registry:2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hhm28fFg1zAegJABvu
This commit is contained in:
Claude committed 2026-11-27 01:33:28 +00:00
1 parent efeaa326c8
commit 5a91e87d64
11 files changed
+236 -131

No files matched your search

+31 -18
View File
@@ -3,28 +3,35 @@
// String APIs that have changed between MoonBit releases.
///|
suberror OrbitError String
suberror OrbitError {
OrbitError(String)
}
///|
extern "C" fn c_run(cmd : Bytes) -> Int = "orbit_run"
#borrow(cmd)
extern "C" fn c_run(cmd : Bytes) -> Int32 = "orbit_run"
///|
#borrow(cmd)
extern "C" fn c_capture(cmd : Bytes) -> Bytes = "orbit_capture"
///|
extern "C" fn c_last_status() -> Int = "orbit_last_status"
extern "C" fn c_last_status() -> Int32 = "orbit_last_status"
///|
#borrow(path)
extern "C" fn c_read_file(path : Bytes) -> Bytes = "orbit_read_file"
///|
extern "C" fn c_write_file(path : Bytes, data : Bytes) -> Int = "orbit_write_file"
#borrow(path, data)
extern "C" fn c_write_file(path : Bytes, data : Bytes) -> Int32 = "orbit_write_file"
///|
#borrow(name)
extern "C" fn c_getenv(name : Bytes) -> Bytes = "orbit_getenv"
///|
extern "C" fn c_exit(code : Int) = "orbit_exit"
extern "C" fn c_exit(code : Int32) = "orbit_exit"
// ---------------------------------------------------------------- UTF-8
@@ -54,30 +61,30 @@ fn utf8_encode(s : String) -> Bytes {
///|
fn utf8_decode(b : Bytes) -> String {
let sb = StringBuilder::new()
let sb = StringBuilder()
let n = b.length()
let mut i = 0
while i < n {
let c0 = b[i].to_int()
if c0 < 0x80 {
sb.write_char(Int::unsafe_to_char(c0))
sb.write_char(Int32::unsafe_to_char(c0))
i = i + 1
} else if c0 >= 0xC0 && c0 < 0xE0 && i + 1 < n {
let cp = ((c0 & 0x1F) << 6) | (b[i + 1].to_int() & 0x3F)
sb.write_char(Int::unsafe_to_char(cp))
sb.write_char(Int32::unsafe_to_char(cp))
i = i + 2
} else if c0 >= 0xE0 && c0 < 0xF0 && i + 2 < n {
let cp = ((c0 & 0x0F) << 12) |
((b[i + 1].to_int() & 0x3F) << 6) |
(b[i + 2].to_int() & 0x3F)
sb.write_char(Int::unsafe_to_char(cp))
sb.write_char(Int32::unsafe_to_char(cp))
i = i + 3
} else if c0 >= 0xF0 && i + 3 < n {
let cp = ((c0 & 0x07) << 18) |
((b[i + 1].to_int() & 0x3F) << 12) |
((b[i + 2].to_int() & 0x3F) << 6) |
(b[i + 3].to_int() & 0x3F)
sb.write_char(Int::unsafe_to_char(cp))
sb.write_char(Int32::unsafe_to_char(cp))
i = i + 4
} else {
sb.write_char('\u{FFFD}')
@@ -99,8 +106,8 @@ fn chars(s : String) -> Array[Char] {
}
///|
fn slice(a : Array[Char], start : Int, end : Int) -> String {
let sb = StringBuilder::new()
fn slice(a : Array[Char], start : Int32, end : Int32) -> String {
let sb = StringBuilder()
for i = start; i < end; i = i + 1 {
sb.write_char(a[i])
}
@@ -108,7 +115,7 @@ fn slice(a : Array[Char], start : Int, end : Int) -> String {
}
///|
fn drop_chars(s : String, n : Int) -> String {
fn drop_chars(s : String, n : Int32) -> String {
let a = chars(s)
if n >= a.length() {
""
@@ -167,12 +174,12 @@ fn contains_str(s : String, sub : String) -> Bool {
///|
fn split_on(s : String, sep : Char) -> Array[String] {
let out : Array[String] = []
let sb = StringBuilder::new()
let sb = StringBuilder()
let mut cur = sb
for c in s {
if c == sep {
out.push(cur.to_string())
cur = StringBuilder::new()
cur = StringBuilder()
} else {
cur.write_char(c)
}
@@ -181,6 +188,7 @@ fn split_on(s : String, sep : Char) -> Array[String] {
out
}
///|
/// Split at the first `sep`; the second part is "" when `sep` is absent.
fn split_first(s : String, sep : Char) -> (String, String) {
let a = chars(s)
@@ -211,6 +219,7 @@ fn trim(s : String) -> String {
slice(a, start, end)
}
///|
/// Non-empty, trimmed lines.
fn lines(s : String) -> Array[String] {
let out : Array[String] = []
@@ -225,7 +234,7 @@ fn lines(s : String) -> Array[String] {
///|
fn join(xs : Array[String], sep : String) -> String {
let sb = StringBuilder::new()
let sb = StringBuilder()
for i = 0; i < xs.length(); i = i + 1 {
if i > 0 {
sb.write_string(sep)
@@ -241,9 +250,10 @@ fn basename(p : String) -> String {
parts[parts.length() - 1]
}
///|
/// Single-quote a string for /bin/sh.
fn sq(s : String) -> String {
let sb = StringBuilder::new()
let sb = StringBuilder()
sb.write_char('\'')
for c in s {
if c == '\'' {
@@ -259,7 +269,7 @@ fn sq(s : String) -> String {
// ---------------------------------------------------------------- process / fs
///|
fn sh(cmd : String) -> Int {
fn sh(cmd : String) -> Int32 {
c_run(utf8_encode(cmd))
}
@@ -271,6 +281,7 @@ fn sh_ok(cmd : String) -> Unit raise OrbitError {
}
}
///|
/// Run a command and return its stdout; stderr goes to the terminal.
fn capture(cmd : String) -> String raise OrbitError {
let out = utf8_decode(c_capture(utf8_encode(cmd)))
@@ -296,6 +307,7 @@ fn read_text(path : String) -> String? {
}
}
///|
/// Write via a temp file and rename, so readers never see a half-written file.
fn write_text_atomic(path : String, text : String) -> Unit raise OrbitError {
let tmp = path + ".tmp"
@@ -310,6 +322,7 @@ fn getenv(name : String) -> String {
utf8_decode(c_getenv(utf8_encode(name)))
}
///|
/// Command-line arguments without the program name (Linux: /proc/self/cmdline).
fn cli_args() -> Array[String] {
let raw = c_read_file(utf8_encode("/proc/self/cmdline"))