1
0
mirror of https://github.com/exaloop/codon.git synced 2025-06-03 15:03:52 +08:00
codon/docs/sphinx/intro.rst

78 lines
1.9 KiB
ReStructuredText
Raw Normal View History

2021-09-27 14:02:44 -04:00
Getting Started
===============
Install
-------
Pre-built binaries
^^^^^^^^^^^^^^^^^^
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
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
-----
The ``codon`` program can either directly ``run`` Codon source in JIT mode:
2021-09-27 14:02:44 -04:00
.. code-block:: bash
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
codon run -release myprogram.codon
2021-09-27 14:02:44 -04: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
codon build -exe myprogram.codon
2021-09-27 14:02:44 -04:00
# generate 'foo' executable
codon build -o foo myprogram.codon
2021-09-27 14:02:44 -04:00
``codon`` can produce object files:
2021-09-27 14:02:44 -04:00
.. code-block:: bash
# generate 'myprogram.o' object file
codon build -obj myprogram.codon
2021-09-27 14:02:44 -04:00
# generate 'foo.o' object file
codon build -o foo.o myprogram.codon
2021-09-27 14:02:44 -04:00
``codon`` can produce LLVM IR:
2021-09-27 14:02:44 -04:00
.. code-block:: bash
# generate 'myprogram.ll' object file
codon build -llvm myprogram.codon
2021-09-27 14:02:44 -04:00
# generate 'foo.ll' object file
codon build -o foo.ll myprogram.codon
2021-09-27 14:02:44 -04:00
Compile-time definitions
------------------------
``codon`` allows for compile-time definitions via the ``-D`` flag. For example, in the following code:
2021-09-27 14:02:44 -04:00
.. code-block:: python
2021-09-27 14:02:44 -04:00
print(Int[BIT_WIDTH]())
2021-09-27 14:02:44 -04:00
``BIT_WIDTH`` can be specified on the command line as such: ``codon run -DBIT_WIDTH=10 myprogram.codon``.