Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.wasm binary
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,42 @@ Then `$dest` would be available for use.

In case you are still in doubt, refer to the output of `moon run --dry-run`.

## Use Wasm-based MoonBit Compiler

First, you need to install Node.js and curl. Then, run the following commands in a temp directory:

```shell
curl -fSL -O https://github.com/moonbitlang/moonbit-compiler/releases/latest/download/moonbit-wasm.tar.gz
tar -zxvf moonbit-wasm.tar.gz
mkdir -p $HOME/.moon
MOON_VERSION=$(cat ./moon_version)
MOON_HOME="$HOME/.moon"
BIN_DIR="$MOON_HOME/bin"
mkdir -p "$BIN_DIR"
git clone https://github.com/moonbitlang/moon
cd moon
git reset --hard "$MOON_VERSION"
cargo build --release
cp target/release/moon "$BIN_DIR"
cp target/release/moonrun "$BIN_DIR"
cd ..
sed -i '1 i #!/usr/bin/env -S node --stack-size=4096' moonc.js
sed -i '1 i #!/usr/bin/env -S node --stack-size=4096' moonfmt.js
sed -i '1 i #!/usr/bin/env -S node --stack-size=4096' mooninfo.js
cp moonc.js moonfmt.js mooninfo.js moonc.assets moonfmt.assets mooninfo.assets "$BIN_DIR" -r
mv "$BIN_DIR/moonc.js" "$BIN_DIR/moonc"
mv "$BIN_DIR/moonfmt.js" "$BIN_DIR/moonfmt"
mv "$BIN_DIR/mooninfo.js" "$BIN_DIR/mooninfo"
chmod +x "$BIN_DIR/moonc"
chmod +x "$BIN_DIR/moonfmt"
chmod +x "$BIN_DIR/mooninfo"
cp lib include "$MOON_HOME"
CORE_VERSION=$(cat ./core_version)
git clone https://github.com/moonbitlang/core "$MOON_HOME/lib/core"
cd "$MOON_HOME/lib/core"
git reset --hard "$CORE_VERSION"
moon bundle --target all
```
## Contributing

The project is evolving extremely fast that it is not yet ready for massive community contributions.
Expand Down
38 changes: 37 additions & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ moon bundle --source-dir $core
bundled=$core/target/wasm-gc/release/bundle

# 这里 main.mbt 是一个含有 `fn main` 的文件。
moonc build-package $src/main.mbt -is-main -std-path $core/target/$bundled -o $obj -target $target
moonc build-package $src/main.mbt -is-main -std-path $bundled -o $obj

# 如果有不止一个包,别忘了在 -pkg-sources 里指定所有包的路径。
moonc link-core $bundled/core.core $obj -o $dest -pkg-config-path $src/moon.pkg.json -pkg-sources $core:$src -target $target
Expand All @@ -85,6 +85,42 @@ moonc link-core $bundled/core.core $obj -o $dest -pkg-config-path $src/moon.pkg.

如果你仍有疑问,可以参考 `moon run --dry-run` 的输出。

## 使用wasm版的MoonBit编译器

首先需要安装nodejs和curl, 然后在任意的临时目录下执行以下命令

```shell
curl -fSL -O https://github.com/moonbitlang/moonbit-compiler/releases/latest/download/moonbit-wasm.tar.gz
tar -zxvf moonbit-wasm.tar.gz
mkdir -p $HOME/.moon
MOON_VERSION=$(cat ./moon_version)
MOON_HOME="$HOME/.moon"
BIN_DIR="$MOON_HOME/bin"
mkdir -p "$BIN_DIR"
git clone https://github.com/moonbitlang/moon
cd moon
git reset --hard "$MOON_VERSION"
cargo build --release
cp target/release/moon "$BIN_DIR"
cp target/release/moonrun "$BIN_DIR"
cd ..
sed -i '1 i #!/usr/bin/env -S node --stack-size=4096' moonc.js
sed -i '1 i #!/usr/bin/env -S node --stack-size=4096' moonfmt.js
sed -i '1 i #!/usr/bin/env -S node --stack-size=4096' mooninfo.js
cp moonc.js moonfmt.js mooninfo.js moonc.assets moonfmt.assets mooninfo.assets "$BIN_DIR" -r
mv "$BIN_DIR/moonc.js" "$BIN_DIR/moonc"
mv "$BIN_DIR/moonfmt.js" "$BIN_DIR/moonfmt"
mv "$BIN_DIR/mooninfo.js" "$BIN_DIR/mooninfo"
chmod +x "$BIN_DIR/moonc"
chmod +x "$BIN_DIR/moonfmt"
chmod +x "$BIN_DIR/mooninfo"
cp lib include "$MOON_HOME"
CORE_VERSION=$(cat ./core_version)
git clone https://github.com/moonbitlang/core "$MOON_HOME/lib/core"
cd "$MOON_HOME/lib/core"
git reset --hard "$CORE_VERSION"
moon bundle --target all
```
## 贡献

这个项目正在快速演进,因此还没有准备好接受大量社区贡献。
Expand Down
47 changes: 0 additions & 47 deletions src/addr_table.ml

This file was deleted.

137 changes: 72 additions & 65 deletions src/alerts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ include struct
let _ = sexp_of_alert_id

let compare_alert_id =
(fun a__001_ b__002_ -> Stdlib.compare (a__001_ : string) b__002_
(fun a__001_ -> fun b__002_ -> Stdlib.compare (a__001_ : string) b__002_
: alert_id -> alert_id -> int)

let _ = compare_alert_id

let equal_alert_id =
(fun a__003_ b__004_ -> Stdlib.( = ) (a__003_ : string) b__004_
(fun a__003_ -> fun b__004_ -> Stdlib.( = ) (a__003_ : string) b__004_
: alert_id -> alert_id -> bool)

let _ = equal_alert_id
Expand Down Expand Up @@ -58,7 +58,8 @@ include struct
let _ = fun (_ : t) -> ()

let sexp_of_t =
(fun { loc = loc__010_; category = category__012_; message = message__014_ } ->
(fun { loc = loc__010_; category = category__012_; message = message__014_ }
->
let bnds__009_ = ([] : _ Stdlib.List.t) in
let bnds__009_ =
let arg__015_ = Moon_sexp_conv.sexp_of_string message__014_ in
Expand All @@ -80,41 +81,46 @@ include struct
let _ = sexp_of_t

let compare =
(fun a__016_ b__017_ ->
if Stdlib.( == ) a__016_ b__017_ then 0
else
match Loc.compare a__016_.loc b__017_.loc with
| 0 -> (
match compare_alert_id a__016_.category b__017_.category with
| 0 -> Stdlib.compare (a__016_.message : string) b__017_.message
| n -> n)
| n -> n
(fun a__016_ ->
fun b__017_ ->
if Stdlib.( == ) a__016_ b__017_ then 0
else
match Loc.compare a__016_.loc b__017_.loc with
| 0 -> (
match compare_alert_id a__016_.category b__017_.category with
| 0 -> Stdlib.compare (a__016_.message : string) b__017_.message
| n -> n)
| n -> n
: t -> t -> int)

let _ = compare

let equal =
(fun a__018_ b__019_ ->
if Stdlib.( == ) a__018_ b__019_ then true
else
Stdlib.( && )
(Loc.equal a__018_.loc b__019_.loc)
(Stdlib.( && )
(equal_alert_id a__018_.category b__019_.category)
(Stdlib.( = ) (a__018_.message : string) b__019_.message))
(fun a__018_ ->
fun b__019_ ->
if Stdlib.( == ) a__018_ b__019_ then true
else
Stdlib.( && )
(Loc.equal a__018_.loc b__019_.loc)
(Stdlib.( && )
(equal_alert_id a__018_.category b__019_.category)
(Stdlib.( = ) (a__018_.message : string) b__019_.message))
: t -> t -> bool)

let _ = equal
end

let message ~as_error t : string =
let padding len m = String.make (Int.max 0 (len - String.length m)) '0' ^ m in
let id = t.category in
let leading =
if as_error then "Error (Alert " ^ padding 3 id ^ "): "
else "Warning (Alert " ^ padding 3 id ^ "): "
in
leading ^ t.message
let message ~as_error t =
(let padding len m =
String.make (Int.max 0 (len - String.length m)) '0' ^ m
in
let id = t.category in
let leading =
if as_error then "Error (Alert " ^ padding 3 id ^ "): "
else "Warning (Alert " ^ padding 3 id ^ "): "
in
leading ^ t.message
: string)

let alerts = Hashtbl.create 10
let post_process = ref None
Expand All @@ -134,43 +140,44 @@ let register_alert id =
Hashtbl.add alerts id Warning;
match !post_process with Some f -> f id | None -> ())

let parse_options s : unit =
let enable id =
match Hashtbl.find_opt alerts id with
| Some Disabled | None -> Hashtbl.replace alerts id Warning
| _ -> ()
in
let disable id = Hashtbl.replace alerts id Disabled in
let enable_as_error id = Hashtbl.replace alerts id Error in
let error msg = raise (Arg.Bad ("Ill-formed list of alerts: " ^ msg)) in
let unknown_token c = error ("Unexpected token '" ^ String.make 1 c ^ "'") in
let rec ident i acc =
if i < String.length s then
let c = s.[i] in
match c with
| '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' | '_' ->
ident (i + 1) (acc ^ String.make 1 c)
| _ -> (i, acc)
else (i, acc)
in
let rec loop i =
if i < String.length s then (
let f =
match s.[i] with
| '+' -> enable
| '-' -> disable
| '@' -> enable_as_error
| _ -> unknown_token s.[i]
in
let i, id = ident (i + 1) "" in
(match id with
| "all" | "All" ->
Hashtbl.iter (fun k _ -> f k) alerts;
post_process := Some f
| _ -> f id);
loop i)
in
loop 0
let parse_options s =
(let enable id =
match Hashtbl.find_opt alerts id with
| Some Disabled | None -> Hashtbl.replace alerts id Warning
| _ -> ()
in
let disable id = Hashtbl.replace alerts id Disabled in
let enable_as_error id = Hashtbl.replace alerts id Error in
let error msg = raise (Arg.Bad ("Ill-formed list of alerts: " ^ msg)) in
let unknown_token c = error ("Unexpected token '" ^ String.make 1 c ^ "'") in
let rec ident i acc =
if i < String.length s then
let c = s.[i] in
match c with
| '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' | '_' ->
ident (i + 1) (acc ^ String.make 1 c)
| _ -> (i, acc)
else (i, acc)
in
let rec loop i =
if i < String.length s then (
let f =
match s.[i] with
| '+' -> enable
| '-' -> disable
| '@' -> enable_as_error
| _ -> unknown_token s.[i]
in
let i, id = ident (i + 1) "" in
(match id with
| "all" | "All" ->
Hashtbl.iter (fun k -> fun _ -> f k) alerts;
post_process := Some f
| _ -> f id);
loop i)
in
loop 0
: unit)

let default_alerts = "+all-raise-throw-unsafe+deprecated"
let () = parse_options default_alerts
Loading
Loading