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

379 Commits

Author SHA1 Message Date
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
janmasrovira
bcb6335c1d
Fix: Identifiers with a keyword prefix cannot be parsed (#171) 2022-06-16 10:13:13 +02:00
janmasrovira
117020215c
Improve filepath equality (#170)
* improve filepath equality

* replace makeAbsolute by canonicalizePath
2022-06-15 12:38:24 +02:00
janmasrovira
b09d4602e7
Add negative test for AppLeftImplicit error (#154) 2022-06-14 08:56:48 +02:00
janmasrovira
ba912b0057
Add positive test designed for implicit arguments (#153) 2022-06-13 18:16:32 +02:00
janmasrovira
2cf3f85439
Support implicit arguments (#144)
* work in progress towards implicit arguments

* Wip towards implicit types

* improve arity checker

* Add version of SimpleFungibleToken with implicit arguments

* guess arity of body before checking the lhs of a clause

* add ArityUnknown and fix some tests

* wip: proper errors in arity checker

* fix bugs, improve errors and add tests

* format

* set hlint version to 3.4 in the ci

* update pre-commit version to 3.0.0

* minor changes

* added more revisions

* minor

Co-authored-by: Jonathan Cubides <jonathan.cubides@uib.no>
2022-06-13 14:25:22 +02:00
Paul Cadman
3396c52fa2
Support function closures with no environment in minic (#137)
* Updates runtime with function calls

* wip function calls

* Remove juvix_function_call macro

* Remove "new_" prefix for constructors and add _field suffix

* Rename test file

* Add example of using constructor as closure

* Test mjuvix function as function closure

* Keep track of emitted closures to avoid duplication

* Use concatMapM from MiniJuvix.Prelude

* Refactoring to split out the closure gen

* Separate passes for function sigs and closures

* Renaming functions generating functionDefs

* Rename juvix_function to minijuvix_function

* Rename DeclJuvixClosure

* Remove typeDefType'

* Remove unnecessary do

* Use Mono.getName

* Extract isNullary

* Use let-in instead of where
2022-06-13 14:04:38 +02:00
janmasrovira
bfcaf6bde4
140 Support holes in type signatures (#141) 2022-06-02 13:02:07 +02:00
janmasrovira
bd110723df
Add holes for expressions in function clauses and inference support (#136)
* Add holes to abstract and micro

* Support trivial implicit arguments

* Support refinement of meta type variables
2022-06-01 17:54:53 +02:00
Jonathan Cubides
29c526833d
Revision for package.yaml and minor deletions (#135) 2022-06-01 11:53:06 +02:00
Jonathan Cubides
f16570e546
Add the termination checker to the pipeline (#111)
* [WIP] EntryPoint now has options. --no-termination is a new global opt.

* Add TerminationChecking to the pipeline

* Add TerminationChecking to the pipeline

* Keep GlobalOptions in App

* Fix reviewer's comments

* delete unnecessary parens

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2022-05-30 13:40:52 +02:00
Jonathan Cubides
a4eb2124b2
Generic Errors and refactoring (#123)
* w.i.p adoption of generic error type

* harmonize

* Remove the use of Error effect for internal bugs

* add location information to expression atom list

* Add GenericError instance for PatternAtoms

* Remove Maybe GenericError occurrences

* [ci] fix draft job's condition

* minor changes

* [stack] macos support ghc-opts

* Fix reviewer's comments

* remove accidentally commited file

* refactor to avoid duplication

* fix

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2022-05-26 17:52:08 +02:00
Paul Cadman
cfc11fecc5
Add minic-runtime for linking without libc (#113)
* [minic] Add minic-runtime for linking without libc

The C generated by minic now depends on `minic-runtime.h`. There are two
versions of this, one that depends on libc and one that doesn't (i.e standalone).

The standalone runtime implements the minimal set of functions required for
the tests to compile and run.

The standalone runtime also contains a copy of
https://github.com/wingo/walloc, a small memory allocator that's
indended for use with WASM.

The benefit of using the standalone runtime is that the resulting
binaries are much smaller. For example the Nat example compiles to about
24k WASM binary with libc, the standalone version is 2.8k.

This commit adds a dependency on
https://hackage.haskell.org/package/file-embed for finding the path to
the minic-runtime directory in tests. It does not add any additional
transitive dependencies to the project.
2022-05-19 09:48:23 +02:00
janmasrovira
50ea7373ee
Improve error generation and handling (#108)
* add face and handling of not in scope symbol error

* small fix

* generic errors wip

* add App effect

* format

* add flycheck-minijuvix

* use absolute paths and refactor

* fix dir0

* add generic error instances and improve some errors

* format

* qualify strings

* use AnsiText

* add ToGenericError instances for the type checker errors

* improve error message

* improve handling of parsing errors
2022-05-18 17:10:10 +02:00
Paul Cadman
5b38727d39
Support uncurried higher order functions (#110)
* [minic] Translate TypeFunction to a C function pointer

* [minic] Add define macros for nullary functions

For example in the translation of:

inductive Nat {
  zero : Nat;
  suc : Nat → Nat;
};

The zero constructor is translated to a nullary C function:

static inline Nat_13_t * new_Zero_14_nullary()

and a macro:

\#define new_Zero_14 (new_Zero_14_nullary())

so that it can be referenced subsequently by the unapplied name
'new_Zero_14'.

A similar translation is applied to nullary top-level functions.

This means that uncurried higher-order functions now work.

* [chore] ormolu and hlint fixes

* [minic] Implement PR review suggestions

* [chore] Fix formatting
2022-05-17 15:12:36 +01:00
Paul Cadman
5ed3ef34c0
[cbackend] run minic tests with clang+wasi-sdk (#105)
* [cbackend] run minic tests with clang+wasi-sdk

* [docs] Add docs for setting up clang+wasi-sdk

* [doc] Updates README usage with clang

* [docs] Fix LLVM URL in README

* [docs] Fix README

* [doc] Update clang setup docs with wasm-ld
2022-05-16 16:17:28 +01:00
janmasrovira
6bf0b1a839
Fix highlight command for modules with import statements (#102)
* fix highlight

* Add minijuvix.yaml to test directories

Co-authored-by: Jonathan Cubides <jonathan.cubides@uib.no>
2022-05-13 16:17:26 +02:00
janmasrovira
bd4ea3e54b
Support multiple modules in compilation (#100)
* translate MiniJuvix import statements to MicroJuvix include statements
2022-05-13 11:44:06 +02:00
Jonathan Cubides
f9d9b10fc9
New target syntax and modular VP examples (#92)
* New target syntax and modular VP examples

* [ .gitignore ] updated

* Fix spaces new lines

* Remove outdated lab folder
2022-05-06 12:45:09 +02:00
janmasrovira
a24e0379d3
87 refactor warning related stuff (#91)
* remove all field selectors

* add local type signatures

* delete Wno-monomorphism-restriction and fix warnings

* [tests] inline two error messages

* remove Wno-missing-exported-signatures

* remove Wno-all-missed-specialisations

* remove Wno-missed-specialisations
2022-05-06 11:48:07 +02:00
Paul Cadman
60236e7b58
Add C code generation backend (#68)
* [cbackend] Adds an AST for C

This should cover enough C to implement the microjuvix backend.

* [cbackend] Add C serializer using language-c library

We may decide to write our own serializer for the C AST but this
demonstrates that the C AST is sufficient at least.

* [cbackend] Declarations will always be typed

* [cbackend] Add CPP support to AST

* [cbackend] Rename some names for clarity

* [cbackend] Add translation of InductiveDef to C

* [cbackend] Add CLI for C backend

* [cbackend] Add stdbool.h to file header

* [cbackend] Allow Cpp and Verbatim code inline

* [cbackend] Add a newline after printing C

* [cbackend] Support foreign blocks

* [cbackend] Add support for axioms

* [cbackend] Remove code examples

* [cbackend] wip FunctionDef including Expressions

* [parser] Support esacping '}' inside a foreign block

* [cbackend] Add support for patterns in functions

* [cbackend] Add foreign C support to HelloWorld.mjuvix

* hlint fixes

* More hlint fixes not picked up by pre-commit

* [cbackend] Remove CompileStatement from MonoJuvix

* [cbackend] Add support for compile blocks

* [cbackend] Move compileInfo extraction to MonoJuvixResult

* [minihaskell] Fix compile block support

* [chore] Remove ununsed isBackendSupported function

* [chore] Remove unused imports

* [cbackend] Use a Reader for pattern bindings

* [cbackend] Fix compiler warnings

* [cbackend] Add support for nested patterns

* [cbackend] Use functions to instantiate argument names

* [cbackend] Add non-exhaustive pattern error message

* [cbackend] Adds test for c to WASM compile and execution

* [cbackend] Add links to test dependencies in quickstart

* [cbackend] Add test with inductive types and patterns

* [cbackend] Fix indentation

* [cbackend] Remove ExpressionTyped case

https://github.com/heliaxdev/minijuvix/issues/79

* [lexer] Fix lexing of \ inside a foreign block

* [cbackend] PR review fixes

* [chore] Remove unused import

* [cbackend] Rename CJuvix to MiniC

* [cbackend] Rename MonoJuvixToC to MonoJuvixToMiniC

* [cbackend] Add test for polymorphic function

* [cbackend] Add module for string literals
2022-05-05 14:12:17 +01:00
janmasrovira
3acade4072
Monomorphization (#70)
* add TypeCallsBuilder and others

* implement propagation of type calls

* improve type propagation

* polymorphize fungible token

* sort type calls map pretty output

* use HashSet in TypeCallsMap

* renaming

* rename module

* improve indexing in type propagation

* draft monomorphization generation algorithm

* fix draft

* wip mono code generation

* wip code generation

* finish first candidate for code generation

* add monojuvix command

* fix MonoJuvix pretty printer to properly display name ids

* [monojuvix] improve clause pretty printing

* add support for function types in expressions

* properly translate function expressions

* ormolu

* add a basic positive test for monomorphization

* cleanup effect constraints

* collect type applications in axiom types

* apply some style improvements

* fix PolySimpleFungibleToken and add it to the test suite

* ignore polymorphic inductive definitions that are never used
2022-05-04 10:50:03 +02:00
janmasrovira
7392e8cc20
check if stderr supports ANSI and print accordingly (#67) 2022-04-29 12:18:09 +02:00
Paul Cadman
dc6fce8820
Add support for compile (by Jonathan) (#66)
* Add support for compile (by Jonathan)

* Remove error related to unsopported backend

Co-authored-by: Jonathan Prieto-Cubides <jonathan.cubides@uib.no>
2022-04-28 17:42:15 +02:00
janmasrovira
fb2999eaf1
add NameIdGen effect to the pipeline (#64)
* add NameIdGen effect to the pipeline

* run ormolu
2022-04-25 12:33:04 +02:00
janmasrovira
ba47f11189
Implement type checker with polymorphism (#62) 2022-04-22 10:06:34 +02:00
Paul Cadman
90f607e6ce [typecheck] Shortcircuit clause pattern check errors
In the following case:

```
module WrongConstructorArity;
  inductive T {
    A : T;
  };

  f : T → T;
  f (A i) ≔ i;
end;
```

The typechecker fails when checking the clause `f (A i) := i` because of
the extra constructor argument. However if typechecking continues then
the variable `i` on the rhs does not have a type so we must short-circuit.
2022-04-08 13:32:11 +02:00
Jonathan Prieto-Cubides
e6ea03a6eb Fix test suite 2022-04-08 12:46:37 +02:00
Jonathan Prieto-Cubides
beb2556111 w.i.p Fixing test suite 2022-04-07 18:10:53 +02:00
Jonathan Prieto-Cubides
4c58b82588 Make Ormolu happy and Hlint 2022-04-07 12:53:05 +02:00
Jonathan Prieto-Cubides
86162090ce merging conflicts 2022-04-07 12:13:03 +02:00
Paul Cadman
3af9cb95ac
Restore correct handling of TypeAny and add positive typecheck tests (#34)
* [ format ] AbstractToMicroJuvix

* [ CI ] fixes

* [ CI ] fixes

* [ CI ] Using GHC 9.0 for Hlint

* [ CI ] Use static-checks for Dev as well

* [test] Add positive test for typechecker

* [test] Improve positive typechecker error output

* [typecheck] Restore correct handling of TypeAny

I mistakenly removed the matchTypes function in
https://github.com/heliaxdev/minijuvix/pull/22. This caused the handling
of TypeAny to break.

Literals have type TypeAny and so should be valid when matching against
any other type. The tests have been updated to reflect this.

* [test] Add positive MicroJuvix typecheck tests

* [ ormolu ] fixes

Co-authored-by: Jonathan Prieto-Cubides <jonathan.cubides@uib.no>
2022-04-05 22:02:03 +02:00
Jonathan Prieto-Cubides
4d918cd1fd [ CI ] New jobs: ormolu and hlint 2022-04-05 19:57:21 +02:00
Jan Mas Rovira
5f9887e69c define ParserResult and refactor 2022-04-05 16:12:13 +02:00
Jonathan Cubides
3fe3cc4305
Merge branch 'main' into dev 2022-04-04 19:11:26 +02:00
Paul Cadman
5bbe6cbfb2 [test] Add test for multiple type errors
Add test for literals
2022-04-04 14:59:56 +01:00
Paul Cadman
658bdf076c [typecheck] Return all errors encountered during typechecking
Any expression that fails typechecking is assigned TypeAny so
typechecking can proceed.
2022-04-04 14:59:56 +01:00
Jonathan Cubides
fd3622a274
Adds many new features (w.i.p v0.1.2) (#28)
* add references to the syntax and cleanup code

* [make] add .PHONY to Makefile targets

* [parser] add parser / pretty for axiom backends

* Pairing progress

* [scoper] Add support for Axiom backends

* [parser] Fix foreign block parsing

* [ app ] adds --no-colors flag for the scope command

* [ghc] upgrade to ghc 9.2.2

* use GHC2021

* [doc] Remove out-of-date comment

* [test] Add ambiguity tests

* [scoper] Improve resolution of local symbols

* [error] WIP improving ambiguity error messages

* [ clean-up ] new lab folder for experimentation

* [ app ] ixes the lint warning

* [ Termination ] removes Alga dependency

* [error] Add message for ambiguous symbol error

* [error] Add ambiguous module message

* [scoper] Remove ErrGeneric

* [test] Add test to suite

* [test] show diff when ast's are different

* [ lab ] folder organization

* [ Makefile ] add targets with --watch option (stack cmds) and remove unused things

* [ app ] add --version flag and fixed warnings and formatting

* [test] remove fromRightIO to fix ambiguity error

* [test] Add test of shadowing public open

* [scoper] Add visibility annotation for Name

* prepare buildIntoTable

* [ Concrete ] add instance of hashable for refs.

* add InfoTableBuilder effect

* [ scoper ] add InfoTableBuilder effect

* [ CHANGELOG ] updated v0.1.1

* [ README ] org version now

* fix package.yaml

* fix readme

* [microjuvix] implement basic typechecker

* add simple test for MicroJuvix type checker

* fix checking for constructors apps in patterns

* [scope] Move InfoTable to a new module

* [abstract] Make Iden use references instead of Name

* [abstract] Add InfoTable for abstract syntax

* [scoper] Add function clauses to scoped InfoTable

* [abstract] Add InfoTableBuilder for scoped to abstract

* [main] Fix callsites of translateModule

* [doc] Remove empty docs

* [scoper] Update emptyInfoTable with missing field

* rename some functions

* [minihaskell] add compilation to MiniHaskell

* [microjuvix] improve wrong type message

* Add a validity predicate example written in MiniJuvix

* [typecheck] Add error infrastructure for type errors

Add a pretty error for mismatched constructor type in a pattern match

* [test] Adds negative typecheck test for constructor

* [app] Adds microjuvix subcommands for printing / typechecking

* [typecheck] Add error message for ctor match args mistmatch

* [typecheck] Add descriptive messages for remainng errors

* [typecheck] Updates to error message copy

* [typecheck] fix merge conflicts:

* [highlight] add basic support for highlighting symbols

* [minijuvix-mode] add minijuvix-mode and basic description in the readme

* [readme] improve formatting

* automatically detect the root of the project and add --show-root flag

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
Co-authored-by: Paul Cadman <git@paulcadman.dev>
Co-authored-by: Paul Cadman <pcadman@gmail.com>
2022-04-01 13:00:15 +02:00
Paul Cadman
a030b97e8f [typecheck] Add descriptive messages for remainng errors 2022-03-31 09:30:54 +01:00
Paul Cadman
b41b4c4e84 [typecheck] Add error message for ctor match args mistmatch 2022-03-31 09:29:27 +01:00
Paul Cadman
615f7d11c0 [test] Adds negative typecheck test for constructor 2022-03-31 09:28:20 +01:00
Jonathan Cubides
de6fabf625
v0.1.1 (#15)
* add references to the syntax and cleanup code

* [make] add .PHONY to Makefile targets

* [parser] add parser / pretty for axiom backends

* Pairing progress

* [scoper] Add support for Axiom backends

* [parser] Fix foreign block parsing

* [ app ] adds --no-colors flag for the scope command

* [ghc] upgrade to ghc 9.2.2

* use GHC2021

* [doc] Remove out-of-date comment

* [test] Add ambiguity tests

* [scoper] Improve resolution of local symbols

* [error] WIP improving ambiguity error messages

* [ clean-up ] new lab folder for experimentation

* [ app ] ixes the lint warning

* [ Termination ] removes Alga dependency

* [error] Add message for ambiguous symbol error

* [error] Add ambiguous module message

* [scoper] Remove ErrGeneric

* [test] Add test to suite

* [test] show diff when ast's are different

* [ lab ] folder organization

* [ Makefile ] add targets with --watch option (stack cmds) and remove unused things

* [ app ] add --version flag and fixed warnings and formatting

* [test] remove fromRightIO to fix ambiguity error

* [test] Add test of shadowing public open

* [scoper] Add visibility annotation for Name

* prepare buildIntoTable

* [ Concrete ] add instance of hashable for refs.

* add InfoTableBuilder effect

* [ scoper ] add InfoTableBuilder effect

* [ CHANGELOG ] updated v0.1.1

* [ README ] org version now

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2022-03-25 18:16:34 +01:00
Jonathan Prieto-Cubides
ce30de2dc3 [ scoper ] add InfoTableBuilder effect 2022-03-25 17:44:32 +01:00
Paul Cadman
2ec85d39a4 [test] Add test of shadowing public open 2022-03-25 09:30:05 +00:00
Jan Mas Rovira
e241cc7b5b [test] remove fromRightIO to fix ambiguity error 2022-03-25 09:26:40 +01:00
Jan Mas Rovira
eedf468261 [test] show diff when ast's are different 2022-03-24 17:04:22 +01:00
Paul Cadman
6ce6489617 [test] Add test to suite 2022-03-24 14:59:39 +00:00
Paul Cadman
e60d307595 [error] Add ambiguous module message 2022-03-24 14:45:49 +00:00
Paul Cadman
86110e063a [test] Add ambiguity tests 2022-03-24 10:22:03 +00:00
Paul Cadman
f527143e67 [parser] Fix foreign block parsing 2022-03-23 15:34:08 +00:00
Paul Cadman
20dfb7b736 [scoper] Add support for Axiom backends 2022-03-23 15:05:52 +00:00
Paul Cadman
37bafc7b55 [parser] add parser / pretty for axiom backends 2022-03-23 12:24:53 +00:00
Jan Mas Rovira
1a23adc762 add references to the syntax and cleanup code 2022-03-23 11:40:03 +01:00
Jan Mas Rovira
c0ac8ddc9d [tests] add check for pretty printing parsed code 2022-03-17 12:10:45 +01:00
Jan Mas Rovira
b7347efde1 [tests] remove unused pragma 2022-03-16 13:59:10 +01:00
Jan Mas Rovira
df5f6d2df0 [scoper] check that top modules are defined in the correct path 2022-03-16 13:58:07 +01:00
Jan Mas Rovira
271464df04 add integer and string literals 2022-03-15 12:37:33 +01:00
Jan Mas Rovira
028c6ac5c0 [tests] add test and error for missing function clause 2022-02-24 00:29:59 +01:00
Jan Mas Rovira
a8d7f183b8 [tests] add test for parenthesized operators: (+) 2022-02-23 10:59:56 +01:00
Jan Mas Rovira
13279f7b47 [tests] fix some comments 2022-02-21 16:38:39 +01:00
Jan Mas Rovira
3124052807 [tests] add more positive tests from the stdlib 2022-02-18 22:02:57 +01:00
Jan Mas Rovira
3ead694533 [tests] add test for a fragment of stdlib Data.List 2022-02-18 17:57:04 +01:00
Jan Mas Rovira
bdd155d712 [tests] add support for mocked file system in scope checker. Useful for multi
file tests
2022-02-18 17:48:21 +01:00
Jan Mas Rovira
09bf131990 [tests] setup step-wise positive tests 2022-02-18 13:01:42 +01:00
Jan Mas Rovira
85601c6332 [scoper] properly handle qualified constructors in patterns 2022-02-18 00:58:41 +01:00
Jan Mas Rovira
393f907a51 [scoper] add error for unused operator syntax definitions 2022-02-17 22:00:58 +01:00
Jan Mas Rovira
e55680bfec [scoper] add module not in scope error 2022-02-17 13:40:19 +01:00
Jan Mas Rovira
4ffc7f368d [wip] incorporate singletons-th 2022-02-16 20:15:14 +01:00
Jan Mas Rovira
add1b6e689 [tests] add more errors and their tests 2022-02-16 15:18:08 +01:00
Jan Mas Rovira
96930352aa [tests] setup basic testing 2022-02-15 14:12:53 +01:00
Jan Mas Rovira
6da7dd8b30 add unified minijuvix errors 2022-02-12 12:29:25 +01:00
Jan Mas Rovira
0d14e62a4f [test] remove qualified-by-type constructors 2022-01-21 09:20:27 +01:00
Jan Mas Rovira
f822a1a157 [parser, scoper] rethink concrete/scoped AST. Use TypeFamilies again 2022-01-13 11:51:19 +01:00
Jan Mas Rovira
70c4e6184f [parser] add pattern matching for lambda abstractions 2022-01-11 19:29:02 +01:00
Jan Mas Rovira
3536d33cf2 [parser] remove Stage from concrete syntax AST 2022-01-11 12:15:09 +01:00
Jan Mas Rovira
27fc96b4f3 [structure] restructure some files and delete obsolete ones 2022-01-11 11:50:18 +01:00
Jan Mas Rovira
82e23bb78c [example, test] fix syntax of example and add it to the test suite 2022-01-11 10:14:42 +01:00
Jan Mas Rovira
d74871d185 [test] fix tests paths and add stance to package.yaml 2022-01-11 10:09:08 +01:00
Jonathan Prieto-Cubides
655f2a3d96 Put test folder outside src 2022-01-10 12:34:46 -05:00