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

37 lines
539 B
Plaintext

-- arithmetic
module test014;
import Stdlib.Prelude open;
f (x y : Nat) : Nat := x + y;
g (x y : Nat) : Nat := sub (x + 21) (y * 7);
h (f : Nat → Nat → Nat) (y z : Nat) : Nat := f y y * z;
x : Nat := 5;
y : Nat := 17;
func (x : Nat) : Nat := x + 4;
z : Nat := 0;
vx : Nat := 30;
vy : Nat := 7;
main : Nat :=
func (div y x)
+ -- 17 div 5 + 4 = 7
(y
+ x * z)
+ -- 17
(vx
+ vy * (z + 1))
+ -- 37
f
(h g 2 3)
4;
-- (g 2 2) * 3 + 4 = (2+21-2*7)*3 + 4 = 9*3 + 4 = 27+4 = 31