1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-12 14:28:08 +03:00
juvix/tests/Rust/Compilation/positive/test071.juvix
Łukasz Czajka 55598e0f95
Rust backend (#2787)
* Implements code generation through Rust.
* CLI: adds two `dev` compilation targets: 
  1. `rust` for generating Rust code
  2. `native-rust` for generating a native executable via Rust
* Adds end-to-end tests for compilation from Juvix to native executable
via Rust.
* A target for RISC0 needs to be added in a separate PR building on this
one.
2024-05-29 13:34:04 +02:00

44 lines
1.1 KiB
Plaintext

-- Named application
module test071;
import Stdlib.Data.Nat open hiding {Ord; mkOrd};
import Stdlib.Data.Nat.Ord as Ord;
import Stdlib.Data.Product as Ord;
import Stdlib.Data.Bool.Base open;
import Stdlib.Trait.Ord open using {Ordering; LT; EQ; GT; isLT; isGT};
trait
type Ord A :=
mkOrd {
cmp : A -> A -> Ordering;
lt : A -> A -> Bool;
ge : A -> A -> Bool
};
mkOrdHelper
{A}
(cmp : A -> A -> Ordering)
{lt : A -> A -> Bool := λ {a b := isLT (cmp a b)}}
{gt : A -> A -> Bool := λ {a b := isGT (cmp a b)}}
: Ord A :=
mkOrd cmp lt gt;
instance
ordNat : Ord Nat := mkOrdHelper@{
cmp (x y : Nat) : Ordering := Ord.compare x y
};
fun {a : Nat := 1} {b : Nat := a + 1} {c : Nat := b + a + 1}
: Nat := a * b + c;
f {a : Nat := 2} {b : Nat := a + 1} {c : Nat} : Nat := a * b * c;
g {a : Nat := 2} {b : Nat := a + 1} (c : Nat) : Nat := a * b * c;
h {a : Nat := 2} (b c : Nat) {d : Nat := 3} : Nat := a * b + c * d;
main : Nat :=
fun@{a := fun; b := fun@{b := 3} * fun@{b := fun {2}}} +
f@{c := 5} + g@?{b := 4} 3 + if (Ord.lt 1 0) 1 0 +
h@?{b := 4} 1;