Skip to content

Commit

Permalink
Add HelloWorld example and minor other fixes README
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaprieto committed Aug 8, 2022
1 parent 4b7fad9 commit 9543b06
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 31 deletions.
24 changes: 14 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ PREFIX="$(PWD)/.stack-work/prefix"
UNAME := $(shell uname)
HLINTQUIET :=

ASSETS = seating-mascot.051c86a.svg \
Seating_Tara_smiling.svg \
teaching-mascot.f828959.svg
ASSETS = seating-mascot.051c86a.svg \
Seating_Tara_smiling.svg \
teaching-mascot.f828959.svg

ORGFILES = $(shell find docs/org -type f -name '*.org')
MDFILES:=$(patsubst docs/org/%,docs/md/%,$(ORGFILES:.org=.md))

EXAMPLEMILESTONE=examples/milestone
EXAMPLEHTMLOUTPUT=_docs/examples/html
EXAMPLES=ValidityPredicates/SimpleFungibleToken.juvix \
TicTacToe/CLI/TicTacToe.juvix \
EXAMPLES= HelloWorld/HelloWorld.juvix \
Collatz/Collatz.juvix \
Fibonacci/Fibonacci.juvix \
Collatz/Collatz.juvix
TicTacToe/CLI/TicTacToe.juvix \
ValidityPredicates/SimpleFungibleToken.juvix

EXAMPLE_WEBAPP_OUTPUT=_docs/examples/webapp
WEBAPP_EXAMPLES=TicTacToe/Web/TicTacToe.juvix
Expand Down Expand Up @@ -66,11 +67,11 @@ $(WEBAPP_EXAMPLES):

# -- MDBook

docs/md/README.md :
docs/md/README.md : README.org
@mkdir -p docs/md
@${ORGTOMDPRG} README.org ${ORGOPTS}

docs/md/changelog.md :
docs/md/changelog.md : changelog.org
@mkdir -p docs/md
@${ORGTOMDPRG} changelog.org ${ORGOPTS}

Expand All @@ -79,15 +80,18 @@ docs/md/%.md : docs/org/%.org
@mkdir -p $(dir $@)
${ORGTOMDPRG} $? ${ORGOPTS}

.PHONY: markdown-files
markdown-files: docs/md/README.md docs/md/changelog.md $(MDFILES)

.PHONY: markdown-docs
markdown-docs: docs/md/README.md docs/md/changelog.md $(MDFILES)
markdown-docs: markdown-files
@echo "copying assets ..."
@mkdir -p docs/md/assets
@cp -v $(addprefix assets/,$(ASSETS)) docs/md/assets
@mdbook build

.PHONY: serve-docs
serve-docs: $(MDFILES)
serve-docs: markdown-files
@mdbook serve --open

# -- Codebase Documentation
Expand Down
38 changes: 22 additions & 16 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The Juvix language and related tools are documented in [[https://anoma.github.io

The following links are clickable versions of their corresponding Juvix programs. The HTML output is generated by running =juvix html --recursive FileName.juvix=.

- [[https://docs.juvix.org/examples/html/HelloWorld/HelloWorld.html][HelloWorld.juvix]]
- [[https://docs.juvix.org/examples/html/Fibonacci/Fibonacci.html][Fibonacci.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]]
Expand Down Expand Up @@ -105,21 +106,29 @@ the =main= branch on Github.
brew install --build-from-source --HEAD juvix --verbose
#+end_src

** Usage Example
** The Hello World Example

In the following example a Juvix file is compiled using the C backend. The
result is compiled to WASM using [[https://llvm.org][Clang]] and then executed
using [[https://wasmer.io][wasmer]].

NB: Set the =WASI_SYSROOT_PATH= environment variable to the root of the WASI
sysroot. See
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 install the sysroot.
dependencies]] for instructions on how to setup your environment for compiling Juvix. You can also run =juvix doctor= to check your system setup.

#+begin_src shell
-- HelloWorld.juvix
module HelloWorld;

open import Stdlib.Prelude;

main : IO;
main ≔ putStrLn "hello world!";

end;
#+end_src

Then, run the following commands at the location folder of the file =HelloWorld.juvix=:

#+begin_src shell
cd tests/positive/MiniC/HelloWorld
juvix compile Input.juvix
wasmer Input.wasm
juvix compile HelloWorld.juvix
wasmer HelloWorld.wasm
#+end_src

You should see the output: =hello world!=
Expand Down Expand Up @@ -170,11 +179,8 @@ For the emacs mode:
For the compiler:

- Init command
- New documentation tool. Currently available as an internal command:

#+begin_src shell
juvix internal doc MyFile.juvix
#+end_src
- New documentation tool: =juvix internal doc MyFile.juvix=
#+end_src

** Community

Expand Down
2 changes: 1 addition & 1 deletion docs/org/SUMMARY.org
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

- [[./tooling/README.md][Tooling]]
- [[./tooling/CLI.md][Command line interface]]
- [[./tooling/doctor.md][Doctor]]
- [[./tooling/emacs-mode.md][Emacs mode]]
- [[./tooling/testing.md][Haskell test suite]]
- [[./tooling/doctor.md][Doctor]]

- [[./notes/README.md][Notes]]
- [[./examples/validity-predicates/README.md][Validity predicates]]
Expand Down
11 changes: 7 additions & 4 deletions docs/org/examples/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

The following links are clickable versions of their corresponding Juvix programs. The HTML output can be generated by running =juvix html --recursive FileName.juvix=.

- [[https://anoma.github.io/juvix-stdlib/][The Juvix standard library]]
- [[https://docs.juvix.org/examples/html/ValidityPredicates/SimpleFungibleToken.html][SimpleFungibleToken.juvix]]
- [[https://docs.juvix.org/examples/html/Collatz/Collatz.html][Collatz.juvix]]
- [[https://docs.juvix.org/examples/html/HelloWorld/HelloWorld.html][HelloWorld.juvix]]
- [[https://docs.juvix.org/examples/html/Fibonacci/Fibonacci.html][Fibonacci.juvix]]
- [[https://docs.juvix.org/examples/html/TicTacToe/CLI/TicTacToe.html][TicTacToe.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/ValidityPredicates/SimpleFungibleToken.html][SimpleFungibleToken.juvix]]

The [[https://anoma.github.io/juvix-stdlib/][Juvix standard library]] contains
common functions that can be used in Juvix programs.

** Example Juvix Web apps

Expand Down
Empty file.
Empty file.
9 changes: 9 additions & 0 deletions examples/milestone/HelloWorld/HelloWorld.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- HelloWorld.juvix
module HelloWorld;

open import Stdlib.Prelude;

main : IO;
main ≔ putStrLn "hello world!";

end;
Empty file.

0 comments on commit 9543b06

Please sign in to comment.