1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-04 06:23:13 +03:00
Commit Graph

1497 Commits

Author SHA1 Message Date
Łukasz Czajka
5d0aa6ea54
Fix RISC0 compilation on the CI (#3015) 2024-09-10 17:17:00 +02:00
Jan Mas Rovira
d8919087dd
Fix location of scoped modulePathName (#3011)
Closes #2737.

This issues caused the formatter to sometimes insert unwanted line
breaks.
2024-09-09 15:50:29 +02:00
Łukasz Czajka
7167cb319a
Lift non-immediate expressions out of case values for the Nockma backend (#3010)
Implements a transformation `compute-case-anf` which lifts out
non-immediate values matched on in case expressions by introducing
let-bindings for them. In essence, this is a partial ANF transformation
for case expressions only.

For example, transforms
```
case f x of { c y := y + x; d y := y }
```
to
```
let z := f x in case z of { c y := y + x; d y := y }
```
This transformation is needed to avoid duplication of values matched on
in case-expressions in the Nockma backend.
2024-09-09 14:56:36 +02:00
Jan Mas Rovira
f47b9b0034
Do not duplicate nockma stdlib in the nockma backend (#3005) 2024-09-09 14:02:47 +02:00
Jan Mas Rovira
372375ef4d
Only output .debug.nockma file with the --debug flag (#3006) 2024-09-09 13:16:32 +02:00
Łukasz Czajka
ab2d31a313
Compilation of side conditions in pattern matches (#2984)
* Closes #2804 
* Requires #3003
* Front-end syntax for side conditions was implemented in #2852. This PR
implements compilation of side conditions.
* Adds side-conditions to `Match` nodes in Core. Updates Core parsing,
printing and the evaluator.
* Only side-conditions without an `else` branch are allowed in Core. If
there is an `else` branch, the side conditions are translated in
`fromInternal` into nested ifs. Because with `else` the conditions are
exhaustive, there are no implications for pattern exhaustiveness
checking.
* Adjusts the "wildcard row" case in the pattern matching compilation
algorithm to take into account the side conditions.
2024-09-09 12:25:15 +02:00
Jan Mas Rovira
453afffd15
Do not inline the functions library everywhere in the Nockma backend (#3004) 2024-09-08 22:39:55 +02:00
Łukasz Czajka
5675b4f480
Remove legacy naive match-to-case compiler (#3003)
Removes the naive match-to-case transformation.
2024-09-08 11:59:45 +02:00
Jan Mas Rovira
4ae4e4e4d9
Fix a bug that prevented use of name signature defined after the point (#3001)
- Fixes #2999
2024-09-06 14:32:03 +02:00
Jan Mas Rovira
e45503a63e
Fix typechecking of default arguments in signatures with trait arguments (#2998)
- Fixes #2994
2024-09-05 19:43:04 +02:00
Łukasz Czajka
d7c69db126
Fix locations in Internal hole substitution (only for the case of substituting identifiers) (#2995)
Type checking messes up the locations by substituting the holes
(instance holes and ordinary holes) without adjusting the location of
the expression substituted into the hole. Instead, the location of the
expression substituted into the hole is preserved. This messes up
locations in type-checked Internal, because the substituted expressions
can come from anywhere. Later on, the error locations are wrong in Core,
and get wrongly displayed e.g. for pattern matching coverage errors.

This PR implements a partial solution for the (most common) case when
the substituted expression is an identifier. In the future, we should
have a general solution to preserve the hole locations.
2024-09-05 10:57:30 +02:00
Paul Cadman
e4559bbc87
Release 0.6.6 (#2993)
This PR updates:

- [x] Package version
- [x] Smoke test
- [x] Changelog
2024-09-03 18:10:01 +01:00
Łukasz Czajka
b9d864123a
Isabelle/HOL translation: comments (#2974)
* Closes #2962 
* Depends on #2963 
* In Isabelle/HOL comments cannot appear in internal syntax. All
comments inside a Juvix definition are moved outside: to before the
definition or before the earliest function clause.

---------

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2024-09-02 15:56:58 +02:00
Jan Mas Rovira
9d2a2b5638
Add IsInstanceCoercion to Internal (#2981)
We now use a sum type:
```
data IsInstanceCoercion
  = IsInstanceCoercionInstance
  | IsInstanceCoercionCoercion
```
instead of two mutually exclusive Bools.

Moreover, we properly print the keyword in the internal prettyprinter.
2024-09-02 13:46:53 +02:00
Paul Cadman
87c5f0af44
Improve performance of anomaEncode / anomaDecode in the Core evaluator (#2975)
This PR:

* Adds a new implementation of {decode, encode}ByteString functions,
used by anomaEncode and anomaDecode in the Core evaluator
* Adds property tests for roundtripping and benchmarks for the new
functions.

The old implementation used
[bitvec](https://hackage.haskell.org/package/bitvec) to manipulate the
ByteString. This was far too slow. The new implementation uses bit
operations directly on the input integer and ByteArray.

It's now possible to run
[anoma-app-patterns:`Tests/Swap.juvix`](https://github.com/anoma/anoma-app-patterns/blob/feature/tests/Tests/Swap.juvix)
to completion.

For encoding, if the size of the output integer exceeds 64 bits (and
therefore a BigInt must be used) then the new implementation has
quadratic time complexity in the number of input bytes if an
implementation of `ByteString -> Integer` is used as follows:

```
byteStringToIntegerLE :: ByteString -> Integer
byteStringToIntegerLE = BS.foldr (\b acc -> acc `shiftL` 8 .|. fromIntegral b) 0
```

```
byteStringToInteger' :: ByteString -> Integer
byteStringToInteger' = BS.foldl' (\acc b -> acc `shiftL` 8 .|. fromIntegral b) 0

```

I think this is because `shiftL` is expensive for large Integers. To
mitigate this I'm splitting the input ByteString into 1024 byte chunks
and processing each separately. Using this we get 100x speed up at
~0.25Mb input over the non-chunked approach and linear time-complexity
thereafter.

## Benchmarks

The benchmarks for encoding and decoding 250000 bytes:

```
 ByteString Encoding to/from integer
      encode bytes to integer:   OK
        59.1 ms ± 5.3 ms
      decode bytes from integer: OK
        338  ms ±  16 ms
```

The previous implementation would never complete for this input.

Benchmarks for encoding and decoding 2 * 250000 bytes:

```
    ByteString Encoding to/from integer
      encode bytes to integer:   OK
        121  ms ± 8.3 ms
      decode bytes from integer: OK
        651  ms ±  27 ms
```

Benchmarks for encoding and decoding 4 * 250000 bytes:

```
    ByteString Encoding to/from integer
      encode bytes to integer:   OK
        249  ms ±  17 ms
      decode bytes from integer: OK
        1.317 s ±  16 ms
```

---------

Co-authored-by: Lukasz Czajka <lukasz@heliax.dev>
2024-08-30 18:20:18 +01:00
Jan Mas Rovira
7119d3929b
Add PartialDo effect (#2978)
This effect is a different name for [Effectful's
`Fail`](https://hackage.haskell.org/package/effectful-core-2.3.1.0/docs/Effectful-Fail.html).
It gives an instance of
[`MonadFail`](https://hackage.haskell.org/package/base-4.18.1.0/docs/Control-Monad-Fail.html#t:MonadFail)
to `Sem`
2024-08-30 16:27:08 +02:00
Paul Cadman
3d21ab4325
Monad and Applicative traits in juvix stdlib (#2979)
This PR updates the stdlib submodule to juvix-stdlib main branch.

It contains Monad and Applicative traits.
2024-08-30 15:07:29 +02:00
Jan Mas Rovira
eb00fa48ba
Improve compilation progress log (#2969)
- Closes #2797 

Changes:

1. The global flag `--dev-show-thread-ids` is now properly being passed.
Before it was ignored.
3. The progress log has been refactored out of the `ParallelTemplate`
into the `Pipeline.Driver`. With the extra information available, I've
improved how we display the progress log:
1. We show `Compiling`, `Recompiling`, `Loading` to tell if the module
is compiled for the first time (the jvo is missing), or it needs to be
recompiled (with the reason displayed in parentheses), or is loaded from
a jvo file. In the latter case, the message is only showed with
`--log-level verbose|debug`.
2. The modules in other packages are displayed as dependencies with
their own progress counter.
2. When using `-N 1` and compiling a whole project we also get progress
log.

Example screencast:


https://github.com/user-attachments/assets/7cc43cd4-9b23-4ad5-a863-832abacc1b6c
2024-08-30 00:10:13 +02:00
Łukasz Czajka
a4f3704f4e
Isabelle/HOL translation: records and named patterns (#2963)
* Closes #2894 
* Closes #2895
* The translation of pattern matching on records is a bit tricky because
one cannot pattern match on records in Isabelle, except in top patterns
of function clauses. We thus need to translate into nested pattern
matching and record projections. Named patterns can be translated with a
similar technique and are also handled in this PR.

Checklist
---------
- [x] record creation
- [x] record projections
- [x] record update
- [x] top-level record patterns
- [x] nested record patterns
- [x] named patterns
- [x] remove redundant pattern matching clauses
- [x] remove redundant single-branch pattern matches
2024-08-29 16:15:58 +02:00
Jan Mas Rovira
e0bbac2d11
Improve output of juvix dev import-tree print (#2976)
Example:

Old:
```
Import Tree:
============

* Package at /home/jan/.config/juvix/0.6.5/package-base/
Juvix/Builtin/V1.juvix imports Juvix/Builtin/V1/Bool.juvix
Juvix/Builtin/V1.juvix imports Juvix/Builtin/V1/Fixity.juvix
Juvix/Builtin/V1.juvix imports Juvix/Builtin/V1/List.juvix
Juvix/Builtin/V1.juvix imports Juvix/Builtin/V1/Maybe.juvix
Juvix/Builtin/V1.juvix imports Juvix/Builtin/V1/Nat.juvix
Juvix/Builtin/V1.juvix imports Juvix/Builtin/V1/String.juvix
Juvix/Builtin/V1.juvix imports Juvix/Builtin/V1/Trait/Natural.juvix
Juvix/Builtin/V1/List.juvix imports Juvix/Builtin/V1/Fixity.juvix
Juvix/Builtin/V1/Nat.juvix imports Juvix/Builtin/V1/Nat/Base.juvix
Juvix/Builtin/V1/Nat.juvix imports Juvix/Builtin/V1/Trait/FromNatural.juvix
Juvix/Builtin/V1/Nat.juvix imports Juvix/Builtin/V1/Trait/Natural.juvix
Juvix/Builtin/V1/Nat/Base.juvix imports Juvix/Builtin/V1/Fixity.juvix
Juvix/Builtin/V1/String.juvix imports Juvix/Builtin/V1/Fixity.juvix
Juvix/Builtin/V1/Trait/FromNatural.juvix imports Juvix/Builtin/V1/Nat/Base.juvix
Juvix/Builtin/V1/Trait/Natural.juvix imports Juvix/Builtin/V1/Fixity.juvix
Juvix/Builtin/V1/Trait/Natural.juvix imports Juvix/Builtin/V1/Nat/Base.juvix
Juvix/Builtin/V1/Trait/Natural.juvix imports Juvix/Builtin/V1/Trait/FromNatural.juvix
```

New:
```
Import Tree:
============

* Package at /home/jan/.config/juvix/0.6.5/package-base/
Nodes (10)
Juvix/Builtin/V1/Nat.juvix
Juvix/Builtin/V1/Nat/Base.juvix
Juvix/Builtin/V1/Fixity.juvix
Juvix/Builtin/V1/Trait/Natural.juvix
Juvix/Builtin/V1/Bool.juvix
Juvix/Builtin/V1.juvix
Juvix/Builtin/V1/List.juvix
Juvix/Builtin/V1/String.juvix
Juvix/Builtin/V1/Trait/FromNatural.juvix
Juvix/Builtin/V1/Maybe.juvix

Edges (17)
Juvix/Builtin/V1.juvix imports (7):
  • Juvix/Builtin/V1/Bool.juvix
  • Juvix/Builtin/V1/Fixity.juvix
  • Juvix/Builtin/V1/List.juvix
  • Juvix/Builtin/V1/Maybe.juvix
  • Juvix/Builtin/V1/Nat.juvix
  • Juvix/Builtin/V1/String.juvix
  • Juvix/Builtin/V1/Trait/Natural.juvix

Juvix/Builtin/V1/Bool.juvix imports (0):

Juvix/Builtin/V1/Fixity.juvix imports (0):

Juvix/Builtin/V1/List.juvix imports (1):
  • Juvix/Builtin/V1/Fixity.juvix

Juvix/Builtin/V1/Maybe.juvix imports (0):

Juvix/Builtin/V1/Nat.juvix imports (3):
  • Juvix/Builtin/V1/Nat/Base.juvix
  • Juvix/Builtin/V1/Trait/FromNatural.juvix
  • Juvix/Builtin/V1/Trait/Natural.juvix

Juvix/Builtin/V1/Nat/Base.juvix imports (1):
  • Juvix/Builtin/V1/Fixity.juvix

Juvix/Builtin/V1/String.juvix imports (1):
  • Juvix/Builtin/V1/Fixity.juvix

Juvix/Builtin/V1/Trait/FromNatural.juvix imports (1):
  • Juvix/Builtin/V1/Nat/Base.juvix

Juvix/Builtin/V1/Trait/Natural.juvix imports (3):
  • Juvix/Builtin/V1/Fixity.juvix
  • Juvix/Builtin/V1/Nat/Base.juvix
  • Juvix/Builtin/V1/Trait/FromNatural.juvix
```
2024-08-28 12:26:45 +02:00
Łukasz Czajka
7c8ac153e6
Don't fold lets with fail, trace or >-> in the body (#2973)
This is to avoid optimizing e.g.
```
let x := A in
trace "after A" >-> x
```
into 
```
trace "after A" >-> A
```
which is annoying when debugging.
2024-08-27 15:52:08 +02:00
Łukasz Czajka
eb5b2e4595
Fix JuvixTree type unification (#2972)
* Closes #2954 
* The problem was that the type validation algorithm was too strict for
higher-order functions with a dynamic (unknown) target.
2024-08-27 10:31:14 +02:00
Łukasz Czajka
9c980d152a
Translate Judoc comments to Isabelle/HOL (#2958)
* Closes #2891
2024-08-23 20:43:57 +02:00
Jan Mas Rovira
2b4520c855
Fix bug where highlighting is not kept when the file has a type error and imports some other file (#2959)
Example file:
```
module error;

import empty; -- error only happens if we have at least one import

type T := t;

x : T := t t; -- type error
```
If one loads this file into emacs (or vscode) they'll get a type error
as expected, but name colors and go-to information is lost, which is
annoying. This pr fixes this.
I'm not sure why, but this bug only occurs when there is at least one
import.
2024-08-21 13:42:33 +02:00
Jan Mas Rovira
eb0922a244
Add do notation (#2937)
- Closes #2355
- Depends on #2943 

Example:
```
minusOne : Nat -> Maybe Nat
  | zero := nothing
  | (suc n) := just n;


minusThree (n : Nat) : Maybe Nat :=
  do {
    x1 <- minusOne n;
    x2 <- minusOne x1;
    let
      x2' : Nat := x2;
    in
    x3 <- minusOne x2';
    pure x3;
  };
```
2024-08-21 12:01:44 +02:00
Jan Mas Rovira
41450a88ff
Register builtins during scoping and report proper errors instead of crashing (#2943)
This pr has two relevant changes:
## Errors instead of crases
When registering a builtin, we perform some sanity checks. When
unsuccessful, the compiler crashes. This seldom happens because builtins
are defined in libraries that we write ourselves. However, any compiler
crash is a bug, so this pr refactors these crashes into proper errors.

## Registering builtins during scoping
Before this pr, builtins are registered and sanity checked during the
translation from Concrete to Internal. This imposes that the order in
which we translate stuff is relevant, as we must register a builtin
before we use it. For the most part this is fine when the dependency is
explicit in the code, but sometimes there are explicit dependencies.
E.g. do notation and the builtin `monad-bind`. In order to avoid adding
special rules, it is easier to just register builtins during scoping, so
I've refactored the code to do this.

I've also removed the `Builtins` effect and moved its methods to the
`InfoTableBuilder` since the builtins table is now part of the Scoped
InfoTable. Consequently, I've removed the the field `_artifactBuiltins`.

## Future work
- Fix #2952. I didn't find a good way to fix this problem in this pr, so
it is left for a separate pr.

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
2024-08-20 13:23:28 +01:00
Łukasz Czajka
7df1e00235
Isabelle/HOL translation: add 'O' and 'OO' to reversed names (#2961)
As requested by Jonathan, adds 'O' and 'OO' to the list reserved
Isabelle/HOL names.
2024-08-19 18:39:08 +02:00
Łukasz Czajka
4fa5d3ca1b
Isabelle/HOL translation: the isabelle-ignore pragma (#2955)
* Closes #2940
2024-08-19 12:22:10 +02:00
Paul Cadman
8d03ac2b6c
Add anoma-bytearray-{to, from}-anoma-contents builtins (#2960)
The `anoma-bytearray-{to, from}-anoma-contents` are intended to be used
to convert to/from atoms representing `ByteArrays`. These builtins are
required temporarily until Anoma Node makes ByteArray representation
uniform across all of its APIs.

We represent ByteArrays in nock as a cell:

```
[size contents]
```

Where `size` is the size of the ByteArray and `contents` is an Atom
representing the bytes in LSB ordering.

The `size` is required in general because the encoding of ByteArrays to
Atoms is ambiguous. For example the ByteArrays [0x01; 0x00] and [0x01]
are represented by `1`.

Some Anoma ByteArrays like keys and signatures are represented using on
the `contents` atom because the size is constant.

Users of Anoma APIs have to strip / add size information from ByteArrays
depending on where the data is used. The new builtins provide this
facility.

These builtins are temporary because it's been agreed with Anoma
engineering team to change the Anoma APIs to make the ByteArray
representation uniform, i.e always represent ByteArrays using `[size
content]`. When this is implemented in Anoma Node we can remove these
builtins.

```
builtin anoma-bytearray-to-anoma-contents
axiom toAnomaContents : ByteArray -> Nat;

builtin anoma-bytearray-from-anoma-contents
axiom fromAnomaContents :
  -- | The size of the ByteArray
  Nat
  -- | The contents of the ByteArray
  -> Nat
  -- | The resulting ByteArray
  -> ByteArray;
```
2024-08-19 11:19:26 +02:00
Paul Cadman
4fe60ea85d
Release 0.6.5 (#2956)
This PR updates:

- [x] Package version
- [x] Smoke test
- [x] Changelog

We can't merge this until the stdlib submodule pointer is fixed-up to
point to stdlib main.
2024-08-14 17:48:36 +01:00
Paul Cadman
7258e66818
Update stdlib submodule to point to stdlib main (#2957)
This PR updates the stdlib submodule to point to juvix stdlib main.
2024-08-14 16:58:08 +01:00
Jan Mas Rovira
b78279c3e0
Fix inference of let and letrec in core (#2953)
* Closes #2949

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
2024-08-14 15:15:49 +01:00
Łukasz Czajka
d60bcccffb
Isabelle/HOL name quoting (#2951)
* Closes #2941 
* Depends on #2950
2024-08-14 15:24:42 +02:00
Łukasz Czajka
fcd52a443f
Improve specialization optimization (#2944)
* Specialization has become less effective after recent changes to the
codebase. This PR fixes issues with specialization.
* Closes #2939 
* Closes #2945 

Checklist
---------
- [X] Preserve pragmas for letrec and lambda in Stored Core
- [x] Remove the assumption that all type variables are at the front
(closes #2945)
- [x] Allow specialization when the argument is a constructor
application
- [x] Make renaming adjust pragmas
- [x] Allow pragmas for fields in record definitions (closes #2939)
- [x] Update standard library pragmas
- [x] Fix JuvixTree printing
2024-08-14 10:04:30 +02:00
Łukasz Czajka
52e4e78dc8
Remove unicode from Isabelle/HOL output (#2950)
* Closes #2942
2024-08-13 18:50:25 +02:00
Paul Cadman
d759d27da7
Use ByteArray for Anoma cryptographic builtins (#2947)
This PR adds support for ByteArray in the Anoma cryptographic functions.

```
builtin anoma-sign
axiom anomaSign : {A : Type} -> A -> ByteArray -> ByteArray;

builtin anoma-verify-with-message
axiom anomaVerifyWithMessage : {A : Type} -> ByteArray -> ByteArray -> Maybe A;

builtin anoma-sign-detached
axiom anomaSignDetached : {A : Type} -> A -> ByteArray -> ByteArray;

builtin anoma-verify-detached
axiom anomaVerifyDetached : {A : Type} -> ByteArray -> A -> ByteArray -> Bool;
```

The Anoma / Hoon Stdlib function `length` needs to be exposed as a
StdlibFunction because a ByteArray stores its length and the value
returned by `anomaSign` is not a fixed length.
2024-08-13 13:17:57 +01:00
Paul Cadman
ce5c2c5c55
Add builtin ByteArray type (#2933)
This PR adds support for a builtin `ByteArray` type and associated
functions for constructing a `ByteArray` from a list of bytes and a
function to query the size of the `ByteArray`. It is only available in
the Anoma backend.

In Core / Tree, ByteArray constant is stored using a Haskell ByteString.

In Anoma the ByteArray is stored as a cell where the head is the length
of the ByteArray and the tail is an integer is an integer formed by
concatenating the bytes in the array using little-endian byte ordering.

The Nock for constructing a `ByteArray` uses the `length`, `add`,
`folder` and `lsh` functions from the Anoma hoon stdlib. See the [code
comment](fa068a30e7/src/Juvix/Compiler/Nockma/StdlibFunction.hs (L37))
for more details.

Example:

```
module test082;

import Stdlib.Prelude open;
import Stdlib.Debug.Trace open;

builtin bytearray
axiom ByteArray : Type;

builtin bytearray-from-list-byte
axiom mkByteArray : List Byte -> ByteArray;

builtin bytearray-size
axiom size : ByteArray -> Nat;

bs0 : ByteArray := mkByteArray [];

bs1 : ByteArray := mkByteArray [0x0; 0x0; 0x0];

bs2 : ByteArray := mkByteArray [0x1; 0x0; 0x0; 0x0];

bs3 : ByteArray := mkByteArray [0x2; 0x1];

bs4 : ByteArray := mkByteArray [0x100];

main : ByteArray :=
  trace (size bs0)
   >-> trace bs0
   >-> trace (size bs1)
    >-> trace bs1
    >-> trace (size bs2)
    >-> trace bs2
    >-> trace (size bs3)
    >-> trace bs3
    >-> trace (size bs4)
    >-> bs4;
```

Output using `tests/Anoma/Compilation/positive/test082.juvix`

```
$ juvix compile anoma -g test082.juvix
$ juvix dev nockma run test082.pretty.nockma
0
[0 0]
3
[3 0]
4
[4 1]
2
[2 258]
1
[1 0]
```
2024-08-13 11:13:27 +01:00
Jan Mas Rovira
2b5ece7b28
Add --statements flag to juvix dev latex export (#2946)
This pr adds the `--statements` flag to `juvix dev latex export`. It can
be used like this:
```
juvix dev latex export --statements "List; elem; find" List.juvix
```
All statements are selectable by their 'label'. The label of a statement
is defined as:
1. The function/type/operator/alias/axiom/local_module/fixity/iterator
name being defined.
2. The module name being imported.

## Limitations:
1. Only top statements are allowed. I.e. statements inside local modules
cannot be selected.
1. Open statements are not selectable. Giving `--statements "My.Module"`
will refer to the import statement `import My.Module`.
4. Single constructors are not selectable. Only the whole type
definition.
5. No comments will be printed.
2024-08-12 14:16:39 +02:00
Łukasz Czajka
206bed5ed3
Add more comments in the source code (#2938)
* Adds more comments describing some Core transformations 
* Fixes minor Core printing issues
2024-08-07 16:13:11 +02:00
Paul Cadman
527599f1c1
Update stdlib submodule reference to juvix-stdlib main (#2936) 2024-08-05 16:56:24 +01:00
Jan Mas Rovira
bad61a797f
Export Juvix source code to latex (#2917)
This pr adds two new commands related to latex.
1. `juvix dev latex getJuvixSty`. This command prints the contents of
the `juvix.sty` latex package to stdout. It has no options and the
expected usage is `juvix dev latex getJuvixSty > juvix.sty`.
2. `juvix dev latex export`. Expects a .juvix file as an argument and
outputs to stdout the highlighted module in latex format. Optional flags
`--from LINE`, `--to LINE` to output only the specified line range.
There is a `--mode` flag to choose how you want the output.
   ```
   • standalone: Output a ready to compile LaTeX file
   • wrap: Wrap the code in a Verbatim environment
   • raw: Output only the code (default: standalone)
   ```
4. As shown in the standalone output, one is allowed to choose the theme
when importing the juvix package like this: `\usepackage[theme =
latte]{juvix}`. Available themes are `latte`, `frappe`, `macchiato`,
`mocha`.

Examples:
To generate the following output I ran these commands:
```
cd examples/milestones/HelloWorld
mkdir latex
juvix dev latex getJuvixSty > latex/juvix.sty
juvix dev latex export HelloWorld.juvix > latex/main.tex
cd latex
xelatex main.tex
open main.pdf
```
1. with `\usepackage[theme = latte]{juvix}`:

![image](https://github.com/user-attachments/assets/200c212f-cc18-4dac-95fe-b3828346e7fa)
1. with `\usepackage[theme = frappe]{juvix}`:

![image](https://github.com/user-attachments/assets/a71d07aa-8adc-485c-a41d-3ea62dc2c5a3)
1. with `\usepackage[theme = macchiato]{juvix}`:

![image](https://github.com/user-attachments/assets/e7e878cf-3c2b-4497-a06c-0e8a445b5116)
1. with `\usepackage[theme = mocha]{juvix}`:

![image](https://github.com/user-attachments/assets/79a4c82c-c90e-4844-baf4-f107d8b8ae20)
2024-08-05 11:28:19 +02:00
Jan Mas Rovira
bd3b7f1401
Improve css of html documentation and allow different themes (#2931)
1. Refactors css theme to only use variables as source for colors to
make it easier to define themes. In order to define a theme, the
following variables need to be defined (these variables have been taken
mostly from the catppuchin theme):
```
  /* Code */
  --ju-inductive: var(--ctp-green);
  --ju-constructor: var(--ctp-mauve);
  --ju-function: var(--ctp-yellow);
  --ju-module: var(--ctp-lavender);
  --ju-axiom: var(--ctp-red);
  --ju-string: var(--ctp-flamingo);
  --ju-keyword: var(--ctp-sky);
  --ju-delimiter: var(--ctp-overlay2);
  --ju-var: var(--ctp-text);
  --ju-fixity: var(--ctp-sapphire);
  --ju-comment: var(--ctp-rosewater);
  --ju-judoc: var(--ctp-teal);
  --ju-number: var(--ctp-peach);

  /* Text */
  --ju-text: var(--ctp-text);
  --ju-subtext1: var(--ctp-subtext1);
  --ju-subtext0: var(--ctp-subtext0);

  /* Overlay */
  --ju-overlay0: var(--ctp-overlay0);
  --ju-overlay1: var(--ctp-overlay1);
  --ju-overlay2: var(--ctp-overlay2);

  /* Surface */
  --ju-surface0: var(--ctp-surface0);
  --ju-surface1: var(--ctp-surface1);
  --ju-surface2: var(--ctp-surface2);

  /* Panes */
  --ju-base: var(--ctp-base);
  --ju-mantle: var(--ctp-mantle);
  --ju-crust: var(--ctp-mantle);

  /* Theme */
  --ju-main: var(--ctp-maroon);
  --ju-main-link: var(--ctp-maroon);
  --ju-main-link-visited: var(--ctp-flamingo);
  --ju-warning: var(--ctp-red);
```
2. When changing theme, the judoc documentation will also use that
theme, as opposed to only the source code.
3. Added highlighting for module names.
4. When hovering a juvix code element (axiom, constructor, inductive,
etc.), the underline will be of the correct color for the kind. Before
it was always a fixed color.
2024-08-02 16:16:33 +02:00
Jan Mas Rovira
69b5916270
Do not try flatparse scanner for .md files (#2934)
- In https://github.com/anoma/juvix/pull/2925, the flatparse scanner
always fails for .md files and silently falls back to megaparsec.
- In https://github.com/anoma/juvix/pull/2929, a warning is introduced
that informs the user when the fallback parser is being used. This is
causing a warning every time we scan a markdown file.
- This pr fixes the problem by changing the default strategy to directly
use megaparsec when a .md file is given.
2024-08-02 12:31:47 +02:00
Paul Cadman
e2fe830d28
Add support for unsigned 8-bit integer type Byte (#2918)
This PR adds `Byte` as a builtin with builtin functions for equality,
`byte-from-nat` and `byte-to-nat`. The standard library is updated to
include this definition with instances for `FromNatural`, `Show` and
`Eq` traits.

The `FromNatural` trait means that you can assign `Byte` values using
non-negative numeric literals.


You can use byte literals in jvc files by adding the u8 suffix to a
numeric value. For example, 1u8 represents a byte literal.

Arithmetic is not supported as the intention is for this type to be used
to construct ByteArrays of data where isn't not appropriate to modify
using arithmetic operations. We may add a separate `UInt8` type in the
future which supports arithmetic.

The Byte is supported in the native, rust and Anoma backend. Byte is not
supported in the Cairo backend because `byte-from-nat` cannot be
defined.

The primitive builtin ops for `Byte` are called `OpUInt8ToInt` and
`OpUInt8FromInt`, named because these ops work on integers and in future
we may reuse these for a separate unsigned 8-bit integer type that
supports arithmetic.

Part of:

* https://github.com/anoma/juvix/issues/2865
2024-08-02 07:43:24 +01:00
Jan Mas Rovira
d3f57a6187
Put Last modified message inside footer tag (#2922)
This is needed so that the color of the text is set according to the
theme.

Before

![image](https://github.com/user-attachments/assets/d8a67cd1-8fef-4530-a3f8-75b755c6481b)

After

![image](https://github.com/user-attachments/assets/ae8e1ac7-9d88-4e0c-aabc-31d7c2ffb1a5)
2024-08-01 19:35:02 +02:00
Jan Mas Rovira
fe07c053d2
Improve css themes (#2921)
This pr:
- Removes the light `ayu` theme.
- Adds the light `latte` theme (this now becomes the default theme).
- Adds the dark `frappe` theme.
- Adds the dark `moccha` theme.
- Refactor all source themes to use css variables instead of inlined
color definitions. This makes it much easier to maintain.
2024-08-01 18:32:03 +02:00
Paul Cadman
d859a033c0
Add FromNatural trait in package-base (#2926)
This PR adds `FromNatural` to package-base. The change is backwards
compatible for existing Juvix code so we don't need to make a new
version of package-base. The new trait is unused, it will be integrated
in subsequent PRs.

### `FromNatural` trait

The `FromNatural` trait has the following definition.

```
trait
type FromNatural A :=
  mkFromNatural {
    builtin from-nat
    fromNat : Nat -> A
};
```

### `Natural` trait changes

The `Natural` trait is changed to remove its `fromNat` field and add a
new instance field for `FromNatural A`.

### juvix-stdlib changes

`FromNatural` instances are added for `Int` and `Field` in the standard
library.

## Rationale

The `FromNatural` trait will be used for the Bytes type.

We want the following properties for Byte:

1. Values of the Bytes type should be assignable from a non-negative
numeric literal.
2. We don't want to implement + and * for Bytes.

Currently, in order for a type to have property 1. it must have an
instance of `Natural` so property 2. can't be satisfied.

To solve this we split the `from-nat` builtin from the `Natural` trait
into a new trait `FromNatural`.
2024-08-01 08:26:52 +01:00
Jan Mas Rovira
0e27e9a49e
Fix html rendering of fixities (#2930)
Before:

![image](https://github.com/user-attachments/assets/656b3458-e994-4357-9ed2-cd3152cdb3be)

After:

![image](https://github.com/user-attachments/assets/5f65e81d-815a-45a1-8ea1-8f5f5fd82366)
2024-07-31 19:08:47 +02:00
Paul Cadman
0edbcfdaa0
Update juvix-stdlib to include Foldable and Functor traits (#2932)
This updates the juvix-stdlib to contain:

* https://github.com/anoma/juvix-stdlib/pull/111
* https://github.com/anoma/juvix-stdlib/pull/114

Much work needs to be done in the test suite to integrate these changes.
2024-07-31 15:13:27 +02:00
Jan Mas Rovira
3a9eb20f4a
Fix scanning of names with import prefix (#2929)
1. When the flatparse scanner fails and we fallback to megaparsec, a
warning is issued.
2. The flatparse scanner has been fixed so it is not confused when a
name starts with `import`.
2024-07-31 10:02:38 +02:00