on master help sign in
Idris-dev/docs/reference/codegen.rst
147 lines 3.1 kB history raw
1.. _code-generation-targets:
3************************
4Code Generation Targets
5************************
7``Idris`` has been designed such that the compiler can generate code for
8different backends upon request. By default ``Idris`` generates a ``C``
9backend when generating an executable. Included within the standard Idris installation are backends for Javascript and Node.js.
11However, there are third-party code generators out there. Below we
12describe some of these backends and how you can use them when
13compiling 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.
15Official Backends
16==================
18C Language
19----------
21The default target of Idris is C. In order to view the generated C code, compile via:
23::
25 $ idris hello.idr -S -o hello.c
28Javascript
29----------
31To generate code that is tailored for running in the browser
32issue the following command:
34::
36 $ idris --codegen javascript hello.idr -o hello.js
39Idris can produce big chunks of JavaScript code (hello world weighs in at about
4060 lines). However, the generated code can be minified using the
41`closure-compiler <https://developers.google.com/closure/compiler/>`__ from
42Google.
44::
46 java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --js hello.js
49Node.js
50-------
52Generating code for NodeJS is slightly different. Idris outputs a
53JavaScript file that can be directly executed via node.
55::
57 $ idris --codegen node hello.idr -o hello
58 $ ./hello
59 Hello world
63Third Party
64============
66.. note::
68 These are third-party code generations and may have bit-rotted or
69 do not work with current versions of Idris. Please speak to the
70 project's maintainors if there are any problems.
73CIL (.NET, Mono, Unity)
74-----------------------
76::
78 idris --codegen cil Main.idr -o HelloWorld.exe \
79 && mono HelloWorld.exe
81The resulting assemblies can also be used with .NET or Unity.
83Requires `idris-cil <https://github.com/bamboo/idris-cil>`__.
85Erlang
86------
88`Available online <https://github.com/lenary/idris-erlang>`__
90Java
91----
93`Available online <https://github.com/idris-hackers/idris-java>`__
96::
98 idris hello.idr --codegen java -o hello.jar
101Note: The resulting .jar is automatically prefixed by a header including
102an .sh script to allow executing it directly.
104JVM
105---
107`Available online <https://github.com/mmhelloworld/idris-jvm>`__
109LLVM
110-----
112`Available online <https://github.com/idris-hackers/idris-llvm>`__
114Malfunction
115------------
117`Available online <https://github.com/stedolan/idris-malfunction>`__
119Ocaml
120-----
122`Available online <https://github.com/ziman/idris-ocaml>`__
124PHP
125---
127`Available online <https://github.com/edwinb/idris-php>`__
129Python
130------
132`Available online <https://github.com/ziman/idris-py>`__
134Ruby
135----
137`Available online <https://github.com/mrb/idris-ruby>`__
139WS
140---
142`Available online <https://github.com/edwinb/WS-idr>`__
144WebAssembly
145-----------
147`Available online <https://github.com/SPY/idris-codegen-wasm>`__