PageRenderTime 27ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/reference/codegen.rst

https://github.com/idris-lang/Idris-dev
ReStructuredText | 147 lines | 87 code | 60 blank | 0 comment | 0 complexity | 42dc18a6e459cc479171a0010b77789d MD5 | raw file
  1. .. _code-generation-targets:
  2. ************************
  3. Code Generation Targets
  4. ************************
  5. ``Idris`` has been designed such that the compiler can generate code for
  6. different backends upon request. By default ``Idris`` generates a ``C``
  7. backend when generating an executable. Included within the standard Idris installation are backends for Javascript and Node.js.
  8. However, there are third-party code generators out there. Below we
  9. describe some of these backends and how you can use them when
  10. compiling your ``Idris`` code. If you want to write your own codegen for your language there is a `stub project on GitHub <https://github.com/idris-lang/idris-emptycg>`__ that can help point you in the right direction.
  11. Official Backends
  12. ==================
  13. C Language
  14. ----------
  15. The default target of Idris is C. In order to view the generated C code, compile via:
  16. ::
  17. $ idris hello.idr -S -o hello.c
  18. Javascript
  19. ----------
  20. To generate code that is tailored for running in the browser
  21. issue the following command:
  22. ::
  23. $ idris --codegen javascript hello.idr -o hello.js
  24. Idris can produce big chunks of JavaScript code (hello world weighs in at about
  25. 60 lines). However, the generated code can be minified using the
  26. `closure-compiler <https://developers.google.com/closure/compiler/>`__ from
  27. Google.
  28. ::
  29. java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --js hello.js
  30. Node.js
  31. -------
  32. Generating code for NodeJS is slightly different. Idris outputs a
  33. JavaScript file that can be directly executed via node.
  34. ::
  35. $ idris --codegen node hello.idr -o hello
  36. $ ./hello
  37. Hello world
  38. Third Party
  39. ============
  40. .. note::
  41. These are third-party code generations and may have bit-rotted or
  42. do not work with current versions of Idris. Please speak to the
  43. project's maintainers if there are any problems.
  44. CIL (.NET, Mono, Unity)
  45. -----------------------
  46. ::
  47. idris --codegen cil Main.idr -o HelloWorld.exe \
  48. && mono HelloWorld.exe
  49. The resulting assemblies can also be used with .NET or Unity.
  50. Requires `idris-cil <https://github.com/bamboo/idris-cil>`__.
  51. Erlang
  52. ------
  53. `Available online <https://github.com/lenary/idris-erlang>`__
  54. Java
  55. ----
  56. `Available online <https://github.com/idris-hackers/idris-java>`__
  57. ::
  58. idris hello.idr --codegen java -o hello.jar
  59. Note: The resulting .jar is automatically prefixed by a header including
  60. an .sh script to allow executing it directly.
  61. JVM
  62. ---
  63. `Available online <https://github.com/mmhelloworld/idris-jvm>`__
  64. LLVM
  65. -----
  66. `Available online <https://github.com/idris-hackers/idris-llvm>`__
  67. Malfunction
  68. ------------
  69. `Available online <https://github.com/stedolan/idris-malfunction>`__
  70. Ocaml
  71. -----
  72. `Available online <https://github.com/ziman/idris-ocaml>`__
  73. PHP
  74. ---
  75. `Available online <https://github.com/edwinb/idris-php>`__
  76. Python
  77. ------
  78. `Available online <https://github.com/ziman/idris-py>`__
  79. Ruby
  80. ----
  81. `Available online <https://github.com/mrb/idris-ruby>`__
  82. WS
  83. ---
  84. `Available online <https://github.com/edwinb/WS-idr>`__
  85. WebAssembly
  86. -----------
  87. `Available online <https://github.com/SPY/idris-codegen-wasm>`__