1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-12 14:28:08 +03:00
juvix/tests/Rust/Compilation/positive/test064.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

43 lines
786 B
Plaintext

-- Constant folding
module test064;
import Stdlib.Prelude open;
import Stdlib.Debug.Fail as Debug;
{-# inline: false #-}
f (x y : Nat) : Nat := x + y;
{-# inline: false #-}
g (x : Bool) : Bool := if x false true;
{-# inline: false #-}
h (x : Bool) : Bool := if (g x) false true;
{-# inline: false, eval: false #-}
j (x : Nat) : Nat := x + 0;
sum : Nat -> Nat
| zero := 0
| k@(suc n) := k + sum n;
even : Nat -> Bool
| zero := true
| (suc n) := odd n;
odd : Nat -> Bool
| zero := false
| (suc n) := even n;
terminating
loop : Nat := loop;
{-# inline: false #-}
even' : Nat -> Bool := even;
main : Nat :=
sum 3
+ case even' 6 || g true || h true of {
| true := if (g false) (f 1 2 + sum 7 + j 0) 0
| false := f (3 + 4) (f 0 8) + loop
};