Skip to content

Commit 88108d6

Browse files
authored
Merge pull request #38 from DzmingLi/main
Fix compilation and add Nix flake.
2 parents eda44e2 + 57cf247 commit 88108d6

15 files changed

+238
-32
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ Building a programming language is a long journey. It took Rust 9 years and Go 5
2727
- OCaml 4.14.2
2828
- [OPAM](https://opam.ocaml.org/)
2929

30-
You must update or revert MoonBit to [this version](https://github.com/moonbitlang/core/commit/4660d8b3da6ed79e47462d66d40feff177060699), as the syntax of the language has changed since.
31-
3230
### Build
3331

3432
Build with following scripts:
@@ -57,9 +55,8 @@ To set up the environment, execute these commands (you only need to do it once):
5755
# Remove currently installed MoonBit version
5856
rm -rf $core
5957

60-
# Install the specific version required by the compiler
58+
# Install the latest version of core library
6159
git clone https://github.com/moonbitlang/core.git $core
62-
git checkout 4660d8b
6360

6461
# Compile the core library
6562
moon bundle --source-dir $core

README.zh.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
- OCaml 4.14.2
2828
- [OPAM](https://opam.ocaml.org/)
2929

30-
MoonBit 必须升级/降级到[特定版本](https://github.com/moonbitlang/core/commit/4660d8b3da6ed79e47462d66d40feff177060699),因为语言的语法已经改变。
3130

3231
### 构建
3332

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
{
2+
description = "MoonBit compiler with latest moon and current moonc";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils }:
10+
flake-utils.lib.eachDefaultSystem (system:
11+
let
12+
pkgs = nixpkgs.legacyPackages.${system};
13+
in
14+
{
15+
packages.default = pkgs.stdenv.mkDerivation rec {
16+
pname = "moonbit-hybrid";
17+
version = "latest-moon-plctlab-moonc";
18+
19+
# Use latest moon binary
20+
moonSrc = pkgs.fetchzip {
21+
url = "https://cli.moonbitlang.com/binaries/latest/moonbit-linux-x86_64.tar.gz";
22+
sha256 = "sha256-8AwukSHQ9NlFncAJAdM3ZJOYHWMqzw39L6bcYWw+0rM=";
23+
stripRoot = false;
24+
};
25+
26+
# Use current GitHub repo for moonc
27+
src = ./.;
28+
29+
nativeBuildInputs = with pkgs; [
30+
autoPatchelfHook
31+
patchelf
32+
makeWrapper
33+
dune_3
34+
ocaml
35+
pkg-config
36+
libffi
37+
gmp
38+
];
39+
40+
buildInputs = with pkgs; [
41+
stdenv.cc.cc.lib
42+
];
43+
44+
buildPhase = ''
45+
runHook preBuild
46+
47+
# Build moonc from current repo
48+
dune build --root .
49+
50+
# Prepare moon from latest release
51+
cp -r ${moonSrc}/* ./
52+
chmod -R u+w ./bin || echo "Failed to set write permissions on bin"
53+
chmod +x ./bin/moon || echo "moon binary not found"
54+
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" ./bin/moon || echo "Failed to patch moon"
55+
[ -f ./bin/internal/tcc ] && patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" ./bin/internal/tcc || echo "tcc not found or failed to patch"
56+
57+
# Replace moonc with our built version
58+
cp _build/install/default/bin/moonc ./bin/moonc
59+
chmod +x ./bin/moonc
60+
61+
runHook postBuild
62+
'';
63+
64+
installPhase = ''
65+
runHook preInstall
66+
67+
mkdir -p $out/bin
68+
mkdir -p $out/lib
69+
70+
# Install binaries
71+
cp ./bin/moon $out/bin/
72+
cp ./bin/moonc $out/bin/
73+
cp -r ./bin/internal $out/bin/
74+
75+
# Install lib files if they exist
76+
if [ -d "./lib" ]; then
77+
cp -r ./lib/* $out/lib/
78+
fi
79+
80+
runHook postInstall
81+
'';
82+
83+
postFixup = ''
84+
wrapProgram $out/bin/moon --set MOON_HOME $out
85+
'';
86+
87+
meta = with pkgs.lib; {
88+
description = "MoonBit toolchain with latest moon and current moonc";
89+
homepage = "https://www.moonbitlang.com";
90+
license = licenses.asl20;
91+
mainProgram = "moon";
92+
platforms = platforms.linux;
93+
};
94+
};
95+
96+
devShells.default = pkgs.mkShell {
97+
buildInputs = with pkgs; [
98+
ocaml
99+
dune_3
100+
ocamlPackages.findlib
101+
ocamlPackages.menhir
102+
ocamlPackages.sedlex
103+
ocamlPackages.cmdliner
104+
ocamlPackages.yojson
105+
ocamlPackages.ppx_deriving_yojson
106+
ocamlPackages.zarith
107+
pkg-config
108+
libffi
109+
gmp
110+
];
111+
112+
shellHook = ''
113+
echo "MoonBit development shell"
114+
echo "OCaml version: $(ocaml -version)"
115+
echo "Dune version: $(dune --version)"
116+
'';
117+
};
118+
});
119+
}

src/basic_base64.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ let encode s =
4343
let get = Bytes.get_uint8 arr in
4444
let add c =
4545
Bytes.unsafe_blit alphabet c ret !pos 1;
46-
(incr [@inlined always]) pos
46+
incr pos
4747
[@@inline always]
4848
in
4949
let padding () =
5050
Bytes.unsafe_fill ret !pos 1 pad;
51-
(incr [@inlined always]) pos
51+
incr pos
5252
[@@inline always]
5353
in
5454
while !l > 2 do
@@ -96,7 +96,7 @@ let decode s =
9696
let get i = inv s.![i] [@@inline always] in
9797
let add c =
9898
Bytes.unsafe_set ret !iter (Char.unsafe_chr c);
99-
(incr [@inlined always]) iter
99+
incr iter
100100
[@@inline always]
101101
in
102102
while !pos < len - 4 do

src/checked_attributes.ml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ end
2626
type attribute =
2727
| Tattr_alert of { loc_ : location; category : string; message : string }
2828
| Tattr_intrinsic of { loc_ : location; intrinsic : string }
29+
| Tattr_alias of { loc_ : location; alias_name : string }
2930

3031
include struct
3132
let _ = fun (_ : attribute) -> ()
@@ -66,6 +67,18 @@ include struct
6667
(S.List [ S.Atom "loc_"; arg__010_ ] :: bnds__008_ : _ Stdlib.List.t)
6768
in
6869
S.List (S.Atom "Tattr_intrinsic" :: bnds__008_)
70+
| Tattr_alias { loc_ = loc___014_; alias_name = alias_name__016_ } ->
71+
let bnds__013_ = ([] : _ Stdlib.List.t) in
72+
let bnds__013_ =
73+
let arg__017_ = Moon_sexp_conv.sexp_of_string alias_name__016_ in
74+
(S.List [ S.Atom "alias_name"; arg__017_ ] :: bnds__013_
75+
: _ Stdlib.List.t)
76+
in
77+
let bnds__013_ =
78+
let arg__015_ = sexp_of_location loc___014_ in
79+
(S.List [ S.Atom "loc_"; arg__015_ ] :: bnds__013_ : _ Stdlib.List.t)
80+
in
81+
S.List (S.Atom "Tattr_alias" :: bnds__013_)
6982
: attribute -> S.t)
7083

7184
let _ = sexp_of_attribute
@@ -131,6 +144,14 @@ let check ~local_diagnostics
131144
| `TopFun ->
132145
Tattr_alert { loc_; category; message = message.string_val }
133146
:: acc)
147+
| Apply
148+
( { qual = None; name = "alias" },
149+
Expr (String { string_val = alias_name; _ }) :: [] ) -> (
150+
match context with
151+
| `TopLet | `TopTypeDecl | `Impl | `Trait ->
152+
warn_unused_attribute "alias";
153+
acc
154+
| `TopFun -> Tattr_alias { loc_; alias_name } :: acc)
134155
| _ -> acc)
135156
| _ -> acc)
136157
: t)

src/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
(env
1616
(_
1717
(flags
18-
(:standard -w -9-30))))
18+
(:standard -w -6-8-9-26-27-30-32-33-35-50))))
1919

2020
(executables
2121
(names moon0_main)

src/mcore.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3174,7 +3174,7 @@ module Map = struct
31743174
loc_ = _visitors_r3;
31753175
}
31763176

3177-
method visit_To_result : _ -> handle_kind = fun env -> To_result
3177+
method visit_To_result : _ -> handle_kind = fun _env -> To_result
31783178

31793179
method visit_Joinapply : _ -> var -> handle_kind =
31803180
fun env ->
@@ -3646,7 +3646,7 @@ module Map = struct
36463646
let _visitors_r4 = self#visit_location env _visitors_floc_ in
36473647
(fun cond ->
36483648
fun ifso ->
3649-
fun ifnot -> fun ty -> fun loc -> if_ ~loc cond ~ifso ?ifnot)
3649+
fun ifnot -> fun _ty -> fun loc -> if_ ~loc cond ~ifso ?ifnot)
36503650
_visitors_r0 _visitors_r1 _visitors_r2 _visitors_r3
36513651
_visitors_r4
36523652

@@ -3695,7 +3695,7 @@ module Map = struct
36953695
(fun obj ->
36963696
fun cases ->
36973697
fun default ->
3698-
fun ty -> fun loc -> switch_constr ~loc obj cases ~default)
3698+
fun _ty -> fun loc -> switch_constr ~loc obj cases ~default)
36993699
_visitors_r0 _visitors_r1 _visitors_r2 _visitors_r3
37003700
_visitors_r4
37013701

@@ -3731,7 +3731,7 @@ module Map = struct
37313731
(fun obj ->
37323732
fun cases ->
37333733
fun default ->
3734-
fun ty ->
3734+
fun _ty ->
37353735
fun loc -> switch_constant ~loc obj cases ~default)
37363736
_visitors_r0 _visitors_r1 _visitors_r2 _visitors_r3
37373737
_visitors_r4
@@ -4183,7 +4183,7 @@ module Map = struct
41834183
let _visitors_r0 = self#visit_typ env _visitors_ffunc_ty in
41844184
Normal { func_ty = _visitors_r0 }
41854185

4186-
method visit_Join : _ -> apply_kind = fun env -> Join
4186+
method visit_Join : _ -> apply_kind = fun _env -> Join
41874187

41884188
method visit_apply_kind : _ -> apply_kind -> apply_kind =
41894189
fun env ->

src/riscv_internals.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn unsafe_bytes_blit (dst, dst_offset, src, src_offset, length) {
2121
return %3
2222
}
2323
*)
24-
let unsafe_bytes_blit fn =
24+
let unsafe_bytes_blit _fn =
2525
(* Construct arguments *)
2626
let dst = new_temp T_bytes in
2727
let dst_offset = new_temp T_int in
@@ -66,7 +66,7 @@ fn unsafe_bytes_sub_string (src, offset, length) {
6666
return %3
6767
}
6868
*)
69-
let unsafe_bytes_sub_string fn =
69+
let unsafe_bytes_sub_string _fn =
7070
(* Arguments *)
7171
let src = new_temp T_bytes in
7272
let offset = new_temp T_int in

src/riscv_opt.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ let iter_fn2 f ssa =
152152
let map_fn f ssa =
153153
let map_aux (toplevel: instruction) =
154154
match toplevel with
155-
| FnDecl { fn; body; args; } -> Riscv_ssa.FnDecl { fn; body = f fn; args }
155+
| FnDecl { fn; body = _body; args; } -> Riscv_ssa.FnDecl { fn; body = f fn; args }
156156
| x -> x
157157
in
158158
List.map map_aux ssa
@@ -240,7 +240,7 @@ let liveness_analysis fn =
240240
let last_item = Vec.pop_opt worklist in
241241
match last_item with
242242
| None -> ()
243-
| Some fn ->
243+
| Some _fn ->
244244
List.iter (fun name ->
245245
let block = block_of name in
246246
let old_live_in = Hashtbl.find live_in name in

0 commit comments

Comments
 (0)