on d552eef help sign in
Idris-dev/docs/reference/codegen.rst
133 lines 2.9 kB history raw
1************************
2Code Generation Targets
3************************
5``Idris`` has been designed such that the compiler can generate code for
6different backends upon request. By default ``Idris`` generates a ``C``
7backend when generating an executable. Included within the standard Idris installation are backends for Javascript and Node.js.
9However, there are third-party code generators out there. Below we
10describe some of these backends and how you can use them when
11compiling 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.
13Official Backends
14==================
16C Language
17----------
19Javascript
20----------
22To generate code that is tailored for running in the browser
23issue the following command:
25::
27 $ idris --codegen javascript hello.idr -o hello.js
30Generating code for NodeJS is slightly different. Idris outputs a
31JavaScript file that can be directly executed via node.
33::
35 $ idris --codegen node hello.idr -o hello
36 $ ./hello
37 Hello world
40Idris can produce very big chunks of JavaScript code (hello world
41weighs in at 1500 lines). However, the generated code can be minified
42using the `closure-compiler
43<https://developers.google.com/closure/compiler/>`__ from Google.
45::
47 java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --js hello.js
50Node.js
51-------
54Third Party
55============
57.. note::
59 These are third-party code generations and may have bit-rotted or
60 do not work with current versions of Idris. Please speak to the
61 project's maintainors if there are any problems.
64CIL (.NET, Mono, Unity)
65-----------------------
67::
69 idris --codegen cil Main.idr -o HelloWorld.exe \
70 && mono HelloWorld.exe
72The resulting assemblies can also be used with .NET or Unity.
74Requires `idris-cil <https://github.com/bamboo/idris-cil>`__.
76Erlang
77------
79`Available online <https://github.com/lenary/idris-erlang>`__
81Java
82----
84`Available online <https://github.com/idris-hackers/idris-java>`__
87::
89 idris hello.idr --codegen java -o hello.jar
92Note: The resulting .jar is automatically prefixed by a header including
93an .sh script to allow executing it directly.
95JVM
96---
98`Available online <https://github.com/mmhelloworld/idris-jvm>`__
100LLVM
101-----
103`Available online <https://github.com/idris-hackers/idris-llvm>`__
105Malfunction
106------------
108`Available online <https://github.com/stedolan/idris-malfunction>`__
110Ocaml
111-----
113`Available online <https://github.com/ziman/idris-ocaml>`__
115PHP
116---
118`Available online <https://github.com/edwinb/idris-php>`__
120Python
121------
123`Available online <https://github.com/ziman/idris-py>`__
125Ruby
126----
128`Available online <https://github.com/mrb/idris-ruby>`__
130WS
131---
133`Available online <https://github.com/edwinb/WS-idr>`__