1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-11 08:25:46 +03:00
Commit Graph

133 Commits

Author SHA1 Message Date
Jonathan Cubides
ff30fe9d05 Bump to version v0.2.4 2022-08-19 23:00:34 +02:00
janmasrovira
bcaf319b90
Add --stdin flag (#1459) 2022-08-19 16:57:07 +02:00
Paul Cadman
ea6191b5a4
Add a native compile target for demos (#1457) 2022-08-19 12:16:02 +02:00
Jonathan Cubides
ef4ddaf4dc Bump version to 0.2.3 2022-08-15 11:08:36 +02:00
janmasrovira
8e1a4dc8b6
Give a proper type to literal natural numbers (#1453) 2022-08-12 17:31:15 +02:00
Paul Cadman
7bf337217d
Allow _ in Wasm exported names to support Anoma signature (#1449)
Allow _ in Wasm exported names

The Anoma validity predicate Wasm signature is:

"_validate_tx": [I64, I64, I64, I64, I64, I64, I64, I64] -> [I64]

So we need to allow exported names containing '_'.

This PR adds a Juvix module that exports a function with this signature
and a test that the resulting Wasm function can be called.
2022-08-12 09:06:14 +01:00
Paul Cadman
1ba72b4d9b
Add Towers of Hanoi and Pascal triangle examples (#1446)
* Add new examples of Juvix programs

* Build documentation for Hanoi and Pascal examples
2022-08-10 12:02:14 +01:00
Paul Cadman
4b7fad9304
Add doctor subcommand (#1436) 2022-08-06 20:13:06 +02:00
Paul Cadman
98776997db
Add a Web version of TicTacToe (#1427)
* Add a Web version of TicTacToe

The web version demonstrates injecting host functions into the WASM
import table and call exported Juvix functions from JS.

The web version and the CLI version of the TicTacToe game use the same
game logic backend Juvix module.

* Build and publish web apps in documentation

* Add a link to the TicTacToe web app in example documentation

* Update Makefile to match the new format
2022-08-03 16:14:38 +02:00
Jonathan Cubides
01a44e436d
Refactor (#1420)
* Big refactor in process

* remove unnecessary functions from the prelude

* remove comments
2022-08-03 13:20:40 +02:00
Paul Cadman
657de73b98
WASM import all non-compile axioms with alphanum names in entrypoint (#1426)
* import all non-compile axioms with alphanum names in entrypoint

This commit adds `__attribute__((input_name(<name>)))` to the type
signature of all axioms that do not have a compile block. This indicates
to the compiler that this function should be added to the input table of
the WASM binary.

Adds a test that an imported function can be called from Juvix.

* test: Run node command in same directory as WASM output

* Don't generate importName for non-alphnum axioms

* Add a tutorial on Juvix module to JS interop via Wasm
2022-08-02 18:58:45 +02:00
Paul Cadman
433e882189
Export all functions with alpha numeric names from entrypoint module (#1425)
* Export all functions with alphanum names in entrypoint

Set the export_name attribute on every function signature that has a
fully alpha numeric name.

* Adds a non-WASI target to compile command

WASM libraries we want to run in the browser and in Anoma VM do not have
access to the WASI runtime. For this usecase we need a target runtime
that does not use the WASI runtime.

A `wasi-` prefix is added to existing compile targets and introduce a new
standalone target. This target does not have IO functions like
`putStrLn` and `exit` calls `__builtin_trap` which corresponds to the
`unreachable` WASM instruction.

In the non-exhaustive case error a debug message is emitted to tell the
user which function had the error. This is now abstracted to a `debug`
function in the runtime which calls `putStrLn` in the case of WASI and
is no-op in the case of non-WASI.

Tests are added which check that exported names can be called with the
correct name and result.

* Moves walloc to a common directory
2022-08-01 12:53:19 +02:00
janmasrovira
2532b34041
Implement an html documentation generator similar to haddock (#1413) (#1416) 2022-07-28 17:19:07 +02:00
Paul Cadman
c6307173dc
Permit axiom without a compile block (#1418)
An axiom without a compile block generates a C function signature
without a corresponding body. This allows implementations to be injected
at link time (JS, Anoma).
2022-07-27 10:36:53 +02:00
Paul Cadman
6a45484e24
Remove Int from stdlib and update SimpleFungibleToken example (#1414)
* Update SimpleFungibleToken to use stdlib

We do not want to put an Int type into the standard library before we
have builtin support for arbitrary precision integers. So we include the
Int type locally in the project for now.

* Update reference to stdlib

* Fix shell-tests for SimpleFungibleToken
2022-07-27 10:24:25 +02:00
Paul Cadman
4a7009acfb
Fix version shell test for 0.2.2 (#1415) 2022-07-26 13:52:17 +02:00
Łukasz Czajka
4c5fee3e95
Compute name dependency graph and filter unreachable definitions (#1408)
* Compute name dependency graph and filter unreachable declarations

* bugfix: recurse into type signatures

* positive tests

* make ormolu happy

* get starting nodes from ExportInfo

* make ormolu happy

* cosmetic refactoring of DependencyInfo

* fix tests & style
2022-07-25 18:38:44 +02:00
janmasrovira
39a300eaa2
Support type aliases (#1404)
* add a simple positive test

* add lambda expressions to microjuvix language

* add basic normalization of type aliases

* fix test name

* normalize only functions on types

* normalize when matching

* fix type of inductive names

* improve detection of normalizing functions

* remove obsolete comment

* match constructor return type

* add test for issue 1333

* fix existing tests

* use lambda case

* add strong normalization

* Add test cases for type aliases and another fix

Co-authored-by: Jonathan Cubides <jonathan.cubides@uib.no>
2022-07-25 12:30:18 +02:00
Jonathan Cubides
423ccec70a
Add positivity check for inductive types (#1393)
* w.i.p

* Added strict positivity condition for datatypes w.i.p

* Add negative test for str.postivity check

* Add some revisions

* the branch is back to feet

* w.i.p add lots of traces to check alg.

* Add more test and revisions

* Add negative and positive test to the new flag and the keyword

* Fix shell tests.

* Make pre-commit happy

* Fix rebase conflicts

* Make pre-commit happy

* Add shell test, rename keyword, fix error msg

* Revert change

* Necessary changes

* Remove wrong unless

* Move the positivity checker to its own folder

* Add missing juvix.yaml

* Add a negative test thanks to jan

* make some style changes

* Make ormolu happy

* Remove unnecessary instance of Show

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2022-07-23 09:27:12 +02:00
janmasrovira
e939f8fe9f
Keep qualified names (#1392)
* keep qualified names

* add comment

* add pretty field to Abstract Name

* add test

* Add shell test

* Add another test

* fix shell test

Co-authored-by: Jonathan Cubides <jonathan.cubides@uib.no>
2022-07-21 15:54:08 +02:00
Łukasz Czajka
e19fbf489f
Implement some error messages (#1396) (#1400)
* Implement error message for double braces
* Implement error message for implicit pattern on the left of an application
* Implement error message for constructor expected on the left of an application 

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2022-07-20 16:24:03 +02:00
janmasrovira
a8f4acaca2
Curly braces are allowed nested in patterns (#1380) 2022-07-20 10:33:52 +02:00
Łukasz Czajka
65a44e0bb5
Direct translation from MicroJuvix to MiniC (#1386) 2022-07-19 15:04:10 +02:00
mariari
d7ad6915d2
Widens the accepted symbol list (#1385)
* Changed the valid symbols from inclusvie to exclusive

* Add test using the new valid symbols
2022-07-18 13:32:43 +02:00
janmasrovira
2ea049cea9
Refine hole in type signature to function type (#1379)
* infer hole in type from pattern

* Refine hole in signature when patterns are found

* fix
2022-07-15 18:39:11 +02:00
janmasrovira
32059965a9
Type checking fails when the type of a pattern is not given by the signature (#1378)
* infer hole in type from pattern

* refactor

* fix error message

* format

* fix matching of identifiers

* improve error message
2022-07-15 17:57:04 +02:00
Paul Cadman
894dea4c6b
Adds Collatz sequence generator example (#1384) 2022-07-15 11:17:22 +01:00
Jonathan Cubides
d11605ab1e
Check all the type parameter names are different when declaring an inductive type (#1377)
* Fix #1334

* Rename error type
2022-07-15 10:58:49 +02:00
Paul Cadman
cff01943f4
Add fibonacci sequence example program (#1375) 2022-07-14 17:03:44 +01:00
Jonathan Cubides
eb6819f0c7
Add typecheck and internal command (#270)
* Closes #269

* Add internal command

* w.i.p

* Fix shell tests.

* Rename check command and add shell-tests
2022-07-12 19:08:03 +02:00
Jonathan Cubides
3b3ea45da9
Rename MiniJuvix to Juvix (#259)
* Renaming MiniJuvix to Juvix

* Make Ormolu happy

* Make Hlint happy

* Remove redundant imports

* Fix shell tests and add target ci to our Makefile

* Make pre-commit happy
2022-07-08 13:59:45 +02:00
Paul Cadman
84732b281f
Updates tests to use the updated standard library (#253)
* Updates tests to use the updated stdlib

* Update to minijuvix-stdlib main
2022-07-07 15:35:56 +02:00
Łukasz Czajka
5a9dfe23bb
Remove the 'match' keyword (#238)
Remove the 'match' keyword (#215)

Since lambda-expressions will support pattern matching, explicit 'match' is redundant.
2022-07-05 16:09:13 +02:00
Paul Cadman
89ccef3da4
Throw error when reading a file that conflicts with embedded stdlib (#243)
* Throw error when reading a file that conflicts with stdlib

The Files effect first tries to read a file from the embedded stdlib. If
this succeeds and the file also exists in the project then an error is
thrown.

This error can be thrown either at the parsing stage, if the entrypoint
file conflicts with the standard library, or at the scoping stage if an
imported file conflicts.

* Fix module name in test file
2022-07-05 15:54:01 +02:00
janmasrovira
57edf1077b
Unify MicroJuvix ASTs representation of types and expressions (#188)
* improve and add Universe to MicroJuvix expressions

* continue with the refactor

* refactor typechecker and aritychecker

* refactor Abstract to Micro

* format

* refactor type calls builder and monojuvix translation

* complete abstract translation

* traversals have betrayed me

* fix monomorphisation and traversals

* update tests

* format

* rename Function2

* remove obsolete comments

* fix comment
2022-07-04 18:15:35 +02:00
Łukasz Czajka
3ad678049b
Merge branch 'main' into main 2022-07-04 17:29:30 +02:00
janmasrovira
82d1f3ecf7
Filter symbol entries properly in the scoper (#234) 2022-07-04 16:40:10 +02:00
Lukasz Czajka
5cf65704c1 Removed tests/positive/HelloWorld.mjuvix and specified clang version in the documentation 2022-07-04 14:27:24 +02:00
Paul Cadman
109f3cf472
Use the ModulesCache for open statements in ScopedToAbstract pass (#224)
* Use the ModulesCache for `open` statements

* Refactor using suggestion from Jan
2022-07-03 16:16:46 +01:00
Paul Cadman
1c74c02c83
Perform ScopedToAbstract exactly once for each module (#223)
This commit introduces a cache of Abstract.TopModule that is queried for
each ImportStatement.

Before this change, `registerBuiltin` could be called multiple times for
a module, if it was imported multiple times.
2022-07-01 15:59:52 +01:00
Paul Cadman
ed78f2636b
Embed standard library in the minijuvix binary (#210)
* Embed stdlib in minijuvix library

We add a new step at the beginning of the pipeline called Setup that
registers the modules in the standard library with the Files effect. The
standard library is then used when the Scoper queries the Files effect
for modules as it resolves import statements.

Use of the standard library can be disabled using the global
`--no-stdlib` command-line option.

* CI: Checkout submodules recursively for stdlib

* Add a new `--no-stdlib` option to shell check

* Poke CI

* CI: Checkout submodules in the test job
2022-06-30 11:31:08 +02:00
Jonathan Cubides
72b4c267a3
v0.2.0 (#198)
* Update package.yaml v0.2

* Update Changelog

* Update CLI version shellcheck to 0.2.0

Co-authored-by: Paul Cadman <git@paulcadman.dev>
2022-06-28 16:31:02 +02:00
janmasrovira
6eb16c74c1
Add support for built in types (#192)
* match inductive definitions

* progress towards builtins

* more progress towards builtin types

* add more builtins

* add some errors

* add reverse table to builtins

* Squashed commit of the following:

commit 93333de502d8dd546eb8edf697ca7eef972ea105
Author: Paul Cadman <git@paulcadman.dev>
Date:   Mon Jun 27 18:21:30 2022 +0100

    Use builtin names for match and project functions

    Add an implementation of nat for the standalone backend

commit 868d2098ee57b7acbca84512b6e096650eeeb22d
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Mon Jun 27 18:15:29 2022 +0200

    add builtin information to ClosureInfo

commit 32c78aceb19ee4010d66090a3c4e6025621b5c1f
Author: Paul Cadman <git@paulcadman.dev>
Date:   Mon Jun 27 12:52:10 2022 +0100

    Refactor BuiltinEnum to sum type of each Builtin

commit 55bb72ab12a8fb7d10070c2dee5875482453b7c6
Author: Paul Cadman <git@paulcadman.dev>
Date:   Fri Jun 24 14:44:28 2022 +0100

    Add Builtin information to Mono InfoTable

commit a72368f2e3af20baaf44c5e21fa7e6a469cf1ac5
Author: Paul Cadman <git@paulcadman.dev>
Date:   Fri Jun 24 14:41:51 2022 +0100

    Add Bitraversable to Prelude

commit afa3153d82a9509b0882e7ca99830040fad9ef65
Author: Paul Cadman <git@paulcadman.dev>
Date:   Fri Jun 24 14:41:39 2022 +0100

    Remove unused import

commit ea0b7848fb80970e03a0561be3fb4448486a89a9
Author: Paul Cadman <git@paulcadman.dev>
Date:   Thu Jun 23 13:54:58 2022 +0100

    Use projection functions instead of direct member access

* Avoid shadowing C runtime names in foreign block

* Fix formatting

* Update C names for builtin functions

* Add prim_ prefix to builtin C names

Implement builtins for standalone and libc backends

* Update ormolu action

* ci: run all tests for draft PRs

Co-authored-by: Paul Cadman <git@paulcadman.dev>
2022-06-28 13:31:31 +02:00
Paul Cadman
40287efabb
Support partial application and closure passing in C backend (#190)
* Add support for parital application eval/apply

* include string.h in libc runtime

* Add wasm SimpleFungibleTokenImplicit to tests

* Update VP example to new syntax

* propagate types from all reachable modules

* Change prelude import ordering to workaround minic issue

* Pre-declare inductive typedefs in C backend

This generates the typedefs corresponding to each inductive type.

e.g

```
inductive Bool { .. }
```

is translated to:

```
typedef struct Bool_3_s Bool_3_t;
```

This means that C code can reference these typedefs before they have
been fully defined. (all references to inductive types go through these typedefs
names).

This fixes an issue with the ordering of delcarations when modules are included.

* Use common Lib for MiniC tests

* libc runtime: flush stdout after writing to it

* Adds MiniTicTacToe example using common example lib

In MonoJuvixToMiniC we emit the inductive type typedefs before anything
else to support includes ordering

* Adds tests for mutually recrusive functions

* Add golden tests for milestone examples

* Example: Remove commented out code

* Test error handling behaviour in MiniTicTacToe

* Fail clang compilation on warnings

* Add test for Nested list types

* Add PrettyCode instances for NonEmpty and ConcreteType

* Ignore IsImplicit field in Eq and Hashable of TypeApplication

This is to workaround a crash in Micro->Mono translation when looking up
a concrete type

* Fix formatting

* hlint fixes

* Formatting fixes not reported by local pre-commit

* Refactor MonoJuvixToMiniC

* Fix shelltest

NB: We cannot check the order of the 'Writing' lines because this
depends on the order of files returned by the FS which is
non-deterministic between systems

* Refactor Base to CBuilder

* Refactor using applyOnFunStatement

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2022-06-28 10:25:43 +02:00
Jonathan Cubides
a78847843b
Fix: proper error handling for typechecker errors (#189)
* Fix: proper error handling for typechecker errors

* Improve error messages
2022-06-22 11:42:59 +02:00
Jonathan Cubides
9e817a62fa
Fix: Add check for constructor return types (#182)
* Checking indtype declar (return type)

* Add missing semicolon

* Fix typo
2022-06-21 17:53:35 +02:00
Jonathan Cubides
cc4566f4a6
Add an option to specify the path where to put the HTML output (#179)
* Add --output-dir option for html generation

* minor

* Add html test for output-dir flag with (no) recursive gen
2022-06-20 18:12:45 +02:00
janmasrovira
94ea0da4a8
Remove ExpressionTyped from MicroJuvix language (#143) 2022-06-16 16:38:07 +02:00
janmasrovira
d8cc6bec04
Allow open import statements (#175) 2022-06-16 12:50:11 +02:00
janmasrovira
bcb6335c1d
Fix: Identifiers with a keyword prefix cannot be parsed (#171) 2022-06-16 10:13:13 +02:00