Scala как родная
2022-11-21 13:06![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Оказывается, Скалу теперь можно компилить непосредственно в бинарный код, без всякой Джавы и прочих виртуальных машин. Неплохой язычок получается.
(1) Сначала устанавливаем sbt по инструкции: https://www.scala-sbt.org/1.x/docs/Setup.html
(2) Создаём проект типа "Hello World":
(3) Компилируем и запускаем:
(1) Сначала устанавливаем sbt по инструкции: https://www.scala-sbt.org/1.x/docs/Setup.html
(2) Создаём проект типа "Hello World":
На запрос надо будет ввести желаемое имя проекта. Я выбрал hello.$ sbt new scala-native/scala-native.g8
(3) Компилируем и запускаем:
Смотрим исходник:$ cd hello
$ sbt run
[info] welcome to sbt 1.6.2 (Ubuntu Java 11.0.17)
[info] loading settings for project hello-build from plugins.sbt ...
[info] loading project definition from /.../hello/project
[info] loading settings for project hello from build.sbt ...
[info] set current project to hello (in build file:/.../hello/)
[info] compiling 1 Scala source to /.../hello/target/scala-3.1.3/classes ...
[info] Linking (1343 ms)
[info] Discovered 663 classes and 3689 methods
[info] Optimizing (debug mode) (1047 ms)
[info] Generating intermediate code (829 ms)
[info] Produced 12 files
[info] Compiling to native code (1583 ms)
[info] Linking native code (immix gc, none lto) (122 ms)
[info] Total (4968 ms)
Hello, world!
[success] Total time: 9 s, completed Nov 21, 2022, 1:11:59 PM
Смотрим бинарник:$ cat src/main/scala/Main.scala object Main { def main(args: Array[String]): Unit = println("Hello, world!") }
Подробности здесь: https://scala-native.org/en/stable/user/index.html$ size target/scala-3.1.3/hello-out
text data bss dec hex filename
1625129 223248 4928 1853305 1c4779 target/scala-3.1.3/hello-out
$ ldd target/scala-3.1.3/hello-out
linux-vdso.so.1 (0x00007ffe9492a000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5817600000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5817517000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5817895000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5817200000)
/lib64/ld-linux-x86-64.so.2 (0x00007f5817a93000)
$ ./target/scala-3.1.3/hello-out
Hello, world!
no subject
Date: 2022-11-22 00:10 (UTC)Это ещё по божески. Скажем, у Dart размер кода для Hello выходит в три раза больше.
no subject
Date: 2022-11-22 05:37 (UTC)no subject
Date: 2022-11-22 12:59 (UTC)На c++ написанный.
Но тогда это не вполне native.
Turbo Basic был такой в прошлом веке.
no subject
Date: 2022-11-22 12:14 (UTC)У суслика 1М выходит.
Статический.