Upgrade to Pro — share decks privately, control downloads, hide ads and more …

scala-native 試してみた

scala-native 試してみた

社内 Scala Meetup 2016-05-26

AGAWA Koji

May 27, 2016
Tweet

More Decks by AGAWA Koji

Other Decks in Programming

Transcript

  1. scala-native ͱ͸? 4 ωΠςΟϒόΠφϦΛు͘ Scala ίϯύΠϥ 4 LLVM ϕʔε 4

    LLVM ͷ Scala ϑϩϯτΤϯυ 4 ϝϞϦ؅ཧ͸ Bohem GC
  2. ϥϯλΠϜϥΠϒϥϦ 4 scala-native/javalib 4 scala-js ͔Β͖࣋ͬͯͨ Java API ࣮૷ 4

    io, lang, math, util ͙Β͍ 4 scala-native/nativelib 4 scala-native ϥϯλΠϜ 4 Annotation ఆٛ΍ϙΠϯλܕͳͲ 4 scala-native/scalalib 4 Scala ϥϯλΠϜϥΠϒϥϦ 4 scala-native/clib 4 C ͷඪ४ϥΠϒϥϦ (stdlib.h, stdio.h ͱ͔)
  3. ϥϯλΠϜϥΠϒϥϦ 4 ࠓͷͱ͜Ζ .a ΍ .so ͸࡞Εͳ͍Α͏Ͱɺશ෦ιʔε͔ΒϏϧυ͠ ͯϦϯΫͯ͠Δ 4 Java

    API ͕جૅతͳ΋ͷ͔͠ͳ͍ → طଘͷ Java ࢿ࢈͸࢖͑ͳ͍ 4 JVM Ͱ͸ͳ͍ͷͰ .class ͸࢖͑ͳ͍ → .jar ΋࢖͑ͳ͍ 4 Pure Scala ͷϥΠϒϥϦ͸࢖͑Δ 4 C ͷϥΠϒϥϦ΋࢖͑ΔͷͰؤுΔ 4 ঢ়گతʹ͸ scala-js ͱಉ͡?
  4. ߏ଄ମએݴ @struct class Vec( val x: Double, val y: Double,

    val z: Double ) 4 C ͷ struct ͱͷ૬ޓӡ༻ͷͨΊ ? 4 ελοΫʹ഑ஔͰ͖Δ class Λએݴ͢ΔͨΊ ? 4 C# ͷ class(ࢀরܕ)/struct(஋ܕ) ͷΑ͏ͳৼ෣͍?
  5. ελοΫͱϙΠϯλ @struct class Rect(val w: Double, val h: Double) {

    def area: Double = w * h } def main(args: Array[String]): Unit = { val p: Ptr[Rect] = stackalloc[Rect] // ελοΫׂΓ౰ͯ΁ͷϙΠϯλ !p = new Rect(2, 3) // ϙΠϯλ͕ࢦ͢ϝϞϦ΁ͷ஋֨ೲ fprintf(stdout, c"%f\n", (!p).area) // ϙΠϯλͷࢀর֎͠ } 4 Scala ͰϙΠϯλૢ࡞!!!
  6. C ؔ਺ͷݺͼग़͠ @extern object stdio { def printf(format: CString, args:

    Vararg*): CInt = extern } def main(args: Array[String]): Unit = { stdio.printf(c"hello, world!") } 4 CString = Ptr[Byte] ͳͲͷΑ͏ʹ C ͷܕͱޓ׵ੑͷ͋Δ Scala ܕ͕͋Δ
  7. Ϗϧυ $ git clone [email protected]:scala-native/scala-native.git $ cd scala-native/docker $ ./manage.sh

    build $ ./manage.sh run 4 scala ϥΠϒϥϦͷ git clone ʹࣦഊͨ͠Γͨ͠ͷͰ build.sbt ͷ಺༰ΛखಈͰ࣮ߦͨ͠Γ…
  8. ࣮ߦ࣌ؒ native | 12.2008 clang | 10.9654 jvm | 10.7632

    gcc | 7.3218 4 time ίϚϯυͰ 5 ճܭଌͨ͠ͱ͖ͷฏۉ஋ 4 ࣮ߦ଎౓͸ॳظஈ֊ͷׂʹ͸݈ಆ͍ͯ͠Δ 4 LLVM ͍͢͝!
  9. ىಈ࣌ؒ jvm | 0.2758 native | 0.004 4 ىಈ࣌ؒ͸଎͍! 4

    ͚Ͳ JVM ͷ 0.3 ඵऑ΋ผʹ஗͍ͱ͍͏΄ͲͰ͸ͳ͍…
  10. ࢖͍Ͳ͜Ζ 4 PC (Desktop / Server) ʹ͸ඞཁͳͦ͞͏͔ͳ… 4 ARM ʹϏϧυͰ͖ΔΑ͏ʹͳΕ͹…

    4 JVM Λಈ͔͢΄ͲϦιʔεͷͳ͍Ϛγϯ(IoT)޲͚ͷϓ ϩάϥϜΛ Scala Ͱॻ͚Δͱ͔ 4 iOS ͷωΠςΟϒΞϓϦΛ Scala Ͱॻ͚ΔՄೳੑ?