Skip to content

Commit

Permalink
Make juvix compile default to native target (#1502)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcadman authored Aug 31, 2022
1 parent ff39db3 commit 105188b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
19 changes: 14 additions & 5 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ brew install --build-from-source --HEAD juvix --verbose

** The Hello World Example

In the following example a Juvix file is compiled to Wasm. Please check out the documentation
[[https://anoma.github.io/juvix/getting-started/dependencies.html][Installing
dependencies]] for instructions on how to setup your environment for compiling Juvix. You can also run =juvix doctor= to check your system setup.
This is the Juvix source code of the traditional Hello World program.

#+begin_src shell
-- HelloWorld.juvix
Expand All @@ -132,15 +130,26 @@ main ≔ putStrLn "hello world!";
end;
#+end_src

Then, run the following commands at the location folder of the file =HelloWorld.juvix=:
To compile and run a binary generated by Juvix, save the source code to a file
called =HelloWorld.juvix= and run the following command from the directory
containing it:

#+begin_src shell
juvix compile HelloWorld.juvix
wasmer HelloWorld.wasm
./HelloWorld
#+end_src

You should see the output: =hello world!=

The source code can also be compiled to a WebAssembly binary. This requires some
additional setup. See [[https://anoma.github.io/juvix/getting-started/dependencies.html][Installing dependencies]] in the documentation for more
information. You can also run =juvix doctor= to check your setup.

#+begin_src shell
juvix compile --target wasm HelloWorld.juvix
wasmer HelloWorld.wasm
#+end_src

** The Juvix programming language

Juvix allows us to write programs with a high degree of assurance. The Juvix
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ parseCompile = do
( long "target"
<> short 't'
<> metavar "TARGET"
<> value TargetWasm
<> value TargetNative
<> showDefaultWith targetShow
<> help "select a target: wasm, c, native"
)
Expand Down
4 changes: 2 additions & 2 deletions docs/org/tutorials/nodejs-interop.org
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ end;
The Juvix module can be compiled using the following command:

#+begin_src
juvix compile -r standalone NodeJsInterop.juvix
juvix compile -t wasm -r standalone NodeJsInterop.juvix
#+end_src

This will create a file containing a Wasm module called =NodeJsInterop.wasm=.
Expand All @@ -55,7 +55,7 @@ The functions =ptrToCstr= and =cstrlen= are necessary to convert the =char=
pointer passed from Juvix to a JS =String=.

#+begin_src
-- NodeJSInterop.js
// NodeJSInterop.js
const fs = require('fs');
let wasmModule = null;

Expand Down

0 comments on commit 105188b

Please sign in to comment.