Closed6

Waml をビルドする

ピン留めされたアイテム
tanishikingtanishiking
FROM ocaml/opam:debian-ocaml-4.12

RUN git clone -b waml https://github.com/WebAssembly/gc.git

RUN opam install dune

RUN eval $(opam env) && \
    cd gc/interpreter && \
    make && \
    make install

RUN eval $(opam env) && \
    cd gc/proposals/gc/waml && \
    make

# wasm interpreter and waml
ENV PATH $PATH:$HOME/gc/interpreter
ENV PATH $PATH:$HOME/gc/proposals/gc/waml

https://github.com/tanishiking/waml-docker

tanishikingtanishiking

https://github.com/WebAssembly/gc/tree/waml/proposals/gc/waml

Waml is a typed FP language in the style of ML and friends. It is meant to be representative of the most relevant problems that arise when compiling such languages to Wasm with GC extensions.

最初はこれを Scala で再実装して勉強しようかと思ったけれど、wamlはいろんな機能を備えた言語で実装が大変そうなので、一旦 input と output を眺めて wasm/gc に関する知見を得たい。

tanishikingtanishiking

waml をビルドする

FROM ocaml/opam:debian-ocaml-4.12

RUN git clone -b waml https://github.com/WebAssembly/gc.git

RUN opam install dune

RUN eval $(opam env) && \
    cd gc/proposals/gc/waml && \
    make
$ docker build . --progress=plain -t waml

...
#7 [4/4] RUN eval $(opam env) &&     cd gc/proposals/gc/waml &&     make
#7 0.123 dune build waml.exe
#7 0.173 File "dune", line 6, characters 13-17:
#7 0.173 6 |   (libraries wasm)
#7 0.173                  ^^^^
#7 0.173 Error: Library "wasm" not found.
#7 0.173 -> required by _build/default/waml.exe
#7 0.514 make: *** [Makefile:80: waml] Error 1
#7 ERROR: process "/bin/sh -c eval $(opam env) &&     cd gc/proposals/gc/waml &&     make" did not complete successfully: exit code: 2
------
 > [4/4] RUN eval $(opam env) &&     cd gc/proposals/gc/waml &&     make:
0.123 dune build waml.exe
0.173 File "dune", line 6, characters 13-17:
0.173 6 |   (libraries wasm)
0.173                  ^^^^
0.173 Error: Library "wasm" not found.
0.173 -> required by _build/default/waml.exe
0.514 make: *** [Makefile:80: waml] Error 1
------
Dockerfile:12
--------------------
  11 |
  12 | >>> RUN eval $(opam env) && \
  13 | >>>     cd gc/proposals/gc/waml && \
  14 | >>>     make
  15 |
--------------------
ERROR: failed to solve: process "/bin/sh -c eval $(opam env) &&     cd gc/proposals/gc/waml &&     make" did not complete successfully: exit code: 2

wasm パッケージとやらがたりないとのこと

tanishikingtanishiking

wasm package

これかな? https://opam.ocaml.org/packages/wasm/

diff --git a/Dockerfile b/Dockerfile
index 23c9af6..2a31c38 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,7 +2,7 @@ FROM ocaml/opam:debian-ocaml-4.12

 RUN git clone -b waml https://github.com/WebAssembly/gc.git

-RUN opam install dune
+RUN opam install dune wasm

 RUN eval $(opam env) && \
     cd gc/proposals/gc/waml && \
$ docker build . --progress=plain -t waml

#7 [4/4] RUN eval $(opam env) &&     cd gc/proposals/gc/waml &&     make
#7 0.238 dune build waml.exe
#7 0.615 File "src/scc.ml", line 19, characters 28-38:
#7 0.615 19 | let sccs_of_subtypes (dta : W.sub_type array) : IntSet.t list =
#7 0.615                                  ^^^^^^^^^^
#7 0.615 Error: Unbound type constructor W.sub_type
#7 0.615 Hint: Did you mean num_type?
#7 0.621 File "src/emit.mli", line 7, characters 25-35:
#7 0.621 7 |   include module type of Wasm.Value
#7 0.621                              ^^^^^^^^^^
#7 0.621 Error: Unbound module Wasm.Value
#7 0.621 Hint: Did you mean Values?
#7 0.977 make: *** [Makefile:80: waml] Error 1
#7 ERROR: process "/bin/sh -c eval $(opam env) &&     cd gc/proposals/gc/waml &&     make" did not complete successfully: exit code: 2
------
 > [4/4] RUN eval $(opam env) &&     cd gc/proposals/gc/waml &&     make:
0.615 19 | let sccs_of_subtypes (dta : W.sub_type array) : IntSet.t list =
0.615                                  ^^^^^^^^^^
0.615 Error: Unbound type constructor W.sub_type
0.615 Hint: Did you mean num_type?
0.621 File "src/emit.mli", line 7, characters 25-35:
0.621 7 |   include module type of Wasm.Value
0.621                              ^^^^^^^^^^
0.621 Error: Unbound module Wasm.Value
0.621 Hint: Did you mean Values?
0.977 make: *** [Makefile:80: waml] Error 1

wasm package のバージョン違いそう? と思って publish されてるやつ試してみたけど結果は同じだった。そもそもこれはどこから publish されている? 多分これ

https://github.com/WebAssembly/spec/blob/main/interpreter/dune

あー spec から publish されているということは、gc に関連するやつはここにはないのか。どこかで改造された interpreter が実装されているはず

https://github.com/WebAssembly/gc/tree/waml/interpreter これかな

tanishikingtanishiking
FROM ocaml/opam:debian-ocaml-4.12

RUN git clone -b waml https://github.com/WebAssembly/gc.git

RUN opam install dune

RUN eval $(opam env) && \
    cd gc/interpreter && \
    make install

RUN eval $(opam env) && \
    cd gc/proposals/gc/waml && \
    make

ENTRYPOINT ["gc/proposals/gc/waml/waml"]
$ docker build . -t waml
$ docker run -it waml -x -c
waml 0.2 interpreter
> val f x = x + 7;  f 5;
(module
  (type $0 (sub (struct (field i32))))
  (type $1 (func (param (ref 0) (ref eq)) (result (ref eq))))
  (type $2 (func))
  (rec
    (type $3 (func (param (ref 4) (ref eq)) (result (ref eq))))
    (type $4 (sub 0 (struct (field i32) (field (ref 3)))))
  )
  (type $5 (sub final 4 (struct (field i32) (field (ref 3)))))
  (import "waml-runtime" "func_apply1" (func $0 (type 1)))
  (global $0 (mut (ref null 4)) (ref.null 4))
  (global $1 (mut (ref null i31)) (ref.null i31))
  (func $1
    (type 2)
    (i32.const 1)
    (ref.func 2)
    (struct.new 5)
    (global.set 0)
    (global.get 0)
    (ref.as_non_null)
    (i32.const 5)
    (ref.i31)
    (call 2)
    (ref.cast (ref i31))
    (global.set 1)
  )
  (func $2
    (type 3)
    (local i32)
    (local.get 1)
    (ref.cast (ref i31))
    (i31.get_s)
    (local.set 2)
    (local.get 2)
    (i32.const 7)
    (i32.add)
    (ref.i31)
  )
  (export "return" (global 1))
  (export "f" (global 0))
  (export "func f" (func 2))
  (start 1)
  (elem $0 declare func 2)
)
(i31 12) : Int
val f : Int ->1 Int

このスクラップは5ヶ月前にクローズされました