2021-09-27 14:02:44 -04:00
Getting Started
===============
Install
-------
Pre-built binaries
^^^^^^^^^^^^^^^^^^
2021-10-05 10:12:56 -05:00
Pre-built binaries for Linux and macOS on x86_64 are available alongside `each release <https://github.com/exaloop/codon/releases> `_ . We also have a script for downloading and installing pre-built versions:
2021-09-27 14:02:44 -04:00
.. code-block :: bash
2021-10-05 14:44:32 -04:00
/bin/bash -c "$(curl -fsSL https://codon.dev/install.sh)"
2021-09-27 14:02:44 -04:00
2021-10-05 10:12:56 -05:00
This will install Codon in a new `` .codon `` directory within your home directory.
2021-09-27 14:02:44 -04:00
Building from source
^^^^^^^^^^^^^^^^^^^^
See `Building from Source <build.html> `_ .
Usage
-----
2021-10-05 10:12:56 -05:00
The `` codon `` program can either directly `` run `` Codon source in JIT mode:
2021-09-27 14:02:44 -04:00
.. code-block :: bash
2021-10-05 10:12:56 -05:00
codon run myprogram.codon
2021-09-27 14:02:44 -04:00
The default compilation and run mode is *debug* (`` -debug `` ). Compile and run with optimizations with the `` -release `` option:
.. code-block :: bash
2021-10-05 10:12:56 -05:00
codon run -release myprogram.codon
2021-09-27 14:02:44 -04:00
2021-10-05 10:12:56 -05:00
`` codon `` can also `` build `` executables (ensure you have `` clang `` installed, as it is used for linking):
2021-09-27 14:02:44 -04:00
.. code-block :: bash
# generate 'myprogram' executable
2021-10-05 10:12:56 -05:00
codon build -exe myprogram.codon
2021-09-27 14:02:44 -04:00
# generate 'foo' executable
2021-10-05 10:12:56 -05:00
codon build -o foo myprogram.codon
2021-09-27 14:02:44 -04:00
2021-10-05 10:12:56 -05:00
`` codon `` can produce object files:
2021-09-27 14:02:44 -04:00
.. code-block :: bash
# generate 'myprogram.o' object file
2021-10-05 10:12:56 -05:00
codon build -obj myprogram.codon
2021-09-27 14:02:44 -04:00
# generate 'foo.o' object file
2021-10-05 10:12:56 -05:00
codon build -o foo.o myprogram.codon
2021-09-27 14:02:44 -04:00
2021-10-05 10:12:56 -05:00
`` codon `` can produce LLVM IR:
2021-09-27 14:02:44 -04:00
.. code-block :: bash
# generate 'myprogram.ll' object file
2021-10-05 10:12:56 -05:00
codon build -llvm myprogram.codon
2021-09-27 14:02:44 -04:00
# generate 'foo.ll' object file
2021-10-05 10:12:56 -05:00
codon build -o foo.ll myprogram.codon
2021-09-27 14:02:44 -04:00
Compile-time definitions
------------------------
2021-10-05 10:12:56 -05:00
`` codon `` allows for compile-time definitions via the `` -D `` flag. For example, in the following code:
2021-09-27 14:02:44 -04:00
2021-10-05 10:12:56 -05:00
.. code-block :: python
2021-09-27 14:02:44 -04:00
2021-10-05 10:12:56 -05:00
print(Int[BIT_WIDTH]())
2021-09-27 14:02:44 -04:00
2021-10-05 10:12:56 -05:00
`` BIT_WIDTH `` can be specified on the command line as such: `` codon run -DBIT_WIDTH=10 myprogram.codon `` .