1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 01:52:11 +03:00
juvix/tests/positive/MiniC/ClosureNoEnv/Input.juvix

85 lines
1.5 KiB
Plaintext
Raw Normal View History

module Input;
Support partial application and closure passing in C backend (#190) * Add support for parital application eval/apply * include string.h in libc runtime * Add wasm SimpleFungibleTokenImplicit to tests * Update VP example to new syntax * propagate types from all reachable modules * Change prelude import ordering to workaround minic issue * Pre-declare inductive typedefs in C backend This generates the typedefs corresponding to each inductive type. e.g ``` inductive Bool { .. } ``` is translated to: ``` typedef struct Bool_3_s Bool_3_t; ``` This means that C code can reference these typedefs before they have been fully defined. (all references to inductive types go through these typedefs names). This fixes an issue with the ordering of delcarations when modules are included. * Use common Lib for MiniC tests * libc runtime: flush stdout after writing to it * Adds MiniTicTacToe example using common example lib In MonoJuvixToMiniC we emit the inductive type typedefs before anything else to support includes ordering * Adds tests for mutually recrusive functions * Add golden tests for milestone examples * Example: Remove commented out code * Test error handling behaviour in MiniTicTacToe * Fail clang compilation on warnings * Add test for Nested list types * Add PrettyCode instances for NonEmpty and ConcreteType * Ignore IsImplicit field in Eq and Hashable of TypeApplication This is to workaround a crash in Micro->Mono translation when looking up a concrete type * Fix formatting * hlint fixes * Formatting fixes not reported by local pre-commit * Refactor MonoJuvixToMiniC * Fix shelltest NB: We cannot check the order of the 'Writing' lines because this depends on the order of files returned by the FS which is non-deterministic between systems * Refactor Base to CBuilder * Refactor using applyOnFunStatement Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2022-06-28 11:25:43 +03:00
open import Data.IO;
open import Data.String;
axiom Int : Type;
compile Int {
c ↦ "int";
};
axiom Int_0 : Int;
compile Int_0 {
c ↦ "0";
};
axiom Int_1 : Int;
compile Int_1 {
c ↦ "1";
};
axiom Int_2 : Int;
compile Int_2 {
c ↦ "2";
};
axiom to-str : Int → String;
compile to-str {
c ↦ "intToStr";
};
foreign c {
int cplus(int l, int r) {
return l + r;
\}
};
axiom plus : Int → Int → Int;
compile plus {
c ↦ "cplus";
};
apply : (Int → Int → Int) → Int → Int → Int;
apply f a b := f a b;
type Nat :=
zero : Nat
| suc : Nat → Nat;
plus-nat : Nat → Nat → Nat;
plus-nat zero n := n;
plus-nat (suc m) n := suc (plus-nat m n);
apply-nat : (Nat → Nat) → Nat → Nat;
apply-nat f a := f a;
apply-nat2 : (Nat → Nat → Nat) → Nat → Nat → Nat;
apply-nat2 f a b := f a b;
nat-to-int : Nat → Int;
nat-to-int zero := Int_0;
nat-to-int (suc n) := plus Int_1 (nat-to-int n);
one : Nat;
one := suc zero;
nest-apply : ((Nat → Nat) → Nat → Nat) → (Nat → Nat) → Nat → Nat;
nest-apply f g x := f g x;
two : Nat;
two := suc one;
main : Action;
main := put-str "plus 1 2: "
>> put-str-ln (to-str (apply plus Int_1 Int_2))
>> put-str "suc one: "
>> put-str-ln (to-str (nat-to-int (apply-nat suc one)))
>> put-str "plus-nat 1 2: "
>> put-str-ln (to-str (nat-to-int (apply-nat2 plus-nat one two)))
>> put-str "nest-apply apply-nat suc one: "
>> put-str-ln (to-str (nat-to-int (nest-apply apply-nat suc one)));
end;