1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-13 19:49:20 +03:00

Documentation: how to compile Juvix programs (#1813)

This commit is contained in:
Łukasz Czajka 2023-02-07 19:12:44 +01:00 committed by GitHub
parent 45aa415b71
commit 58a0f196da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 15 deletions

View File

@ -30,8 +30,6 @@
- [[./reference/language/modules.md][Modules]] - [[./reference/language/modules.md][Modules]]
- [[./reference/language/comments.md][Comments]] - [[./reference/language/comments.md][Comments]]
- [[./reference/language/axioms.md][Axioms]] - [[./reference/language/axioms.md][Axioms]]
- [[./reference/language/compileblocks.md][Compile blocks]]
- [[./reference/language/foreign.md][Foreign blocks]]
- [[./reference/examples.md][Example programs]] - [[./reference/examples.md][Example programs]]
- [[./reference/benchmarks.md][Benchmarks]] - [[./reference/benchmarks.md][Benchmarks]]
- [[./reference/tooling/README.md][Tooling]] - [[./reference/tooling/README.md][Tooling]]

View File

@ -0,0 +1,41 @@
* Compiling simple programs
A Juvix file must declare a module whose name corresponds exactly to the name of the file. For example, a file =Hello.juvix= must declare a module =Hello=:
#+begin_example
-- Hello world example. This is a comment.
module Hello;
-- Import the standard library prelude, including the function 'printStringLn'
open import Stdlib.Prelude;
main : IO;
main := printStringLn "Hello world!";
end;
#+end_example
A file compiled to an executable must define the zero-argument function =main= of type =IO= which is evaluated when running the program.
To compile the file =Hello.juvix= type =juvix compile Hello.juvix=. Typing =juvix compile --help= will list all options to the =compile= command.
* Compilation targets
Since version 0.3 Juvix supports three compilation targets. The targets are specified with the =-t= option: =juvix compile -t target file.juvix=.
1. =native=. This is the default. Produces a native 64bit executable for your machine.
2. =wasm32-wasi=. Produces a WebAssembly binary which uses the WASI runtime.
3. =geb=. Produces a [[https://anoma.github.io/geb/][GEB]] input file.
* Juvix projects
A _Juvix project_ is a collection of Juvix modules inside one main
project directory containing a =juvix.yaml= metadata file. The name of
each module must coincide with the path of the file it is defined in,
relative to the project's root directory. For example, if the file is
=root/Data/List.juvix= then the module must be called =Data.List=,
assuming =root= is the project's directory.
To check that Juvix is correctly detecting your project's root, you
can run the command =juvix dev root File.juvix=.
See also: [[../reference/language/modules.md][Modules Reference]].

View File

@ -6,4 +6,3 @@ The following links are clickable versions of their corresponding Juvix programs
- [[https://docs.juvix.org/examples/html/PascalsTriangle/PascalsTriangle.html][PascalsTriangle.juvix]] - [[https://docs.juvix.org/examples/html/PascalsTriangle/PascalsTriangle.html][PascalsTriangle.juvix]]
- [[https://docs.juvix.org/examples/html/Collatz/Collatz.html][Collatz.juvix]] - [[https://docs.juvix.org/examples/html/Collatz/Collatz.html][Collatz.juvix]]
- [[https://docs.juvix.org/examples/html/TicTacToe/CLI/CLI.TicTacToe.html][TicTacToe.juvix]] - [[https://docs.juvix.org/examples/html/TicTacToe/CLI/CLI.TicTacToe.html][TicTacToe.juvix]]
- [[https://docs.juvix.org/examples/html/ValidityPredicates/SimpleFungibleToken.html][SimpleFungibleToken.juvix]]

View File

@ -3,5 +3,3 @@
- [[./modules.md][Modules]] - [[./modules.md][Modules]]
- [[./comments.md][Comments]] - [[./comments.md][Comments]]
- [[./axioms.md][Axioms]] - [[./axioms.md][Axioms]]
- [[./compileblocks.md][Compile blocks]]
- [[./foreign.md][Foreign blocks]]

View File

@ -2,9 +2,8 @@
** Defining a module ** Defining a module
A module is of the following form. The =module= keyword stars the declaration of The =module= keyword stars the declaration of a module followed by its
a module followed by its name and its body. The module declaration ends after name and body. The module declaration ends with the =end= keyword.
seeing the =end= keyword.
#+begin_example #+begin_example
-- ModuleName.juvix -- ModuleName.juvix
@ -13,15 +12,16 @@ module ModuleName;
end; end;
#+end_example #+end_example
A _Juvix project_ is a collection of Juvix modules inside one main project A _Juvix project_ is a collection of Juvix modules inside one main
folder containing a metadata file named =juvix.yaml=. Each Juvix file has to project folder containing a metadata file named =juvix.yaml=. Each
define a _module_ of the same name. The name of the module must coincide with Juvix file has to define a _module_ of the same name. The name of the
the path of the its file respect to its project. For example, if the file is module must coincide with the path of the its file relative to its
=root/Data/List.juvix= then the module must be called =Data.List=, assuming project's root directory. For example, if the file is
=root= is the project's folder. =root/Data/List.juvix= then the module must be called =Data.List=,
assuming =root= is the project's folder.
To check that Juvix is correctly detecting your project's root, one can run the To check that Juvix is correctly detecting your project's root, one can run the
command =juvix internal root File.juvix=. command =juvix dev root File.juvix=.
# - Inside a module, other (sub) modules can be declared. # - Inside a module, other (sub) modules can be declared.