diff --git a/crates/kind-pass/src/desugar/attributes.rs b/crates/kind-pass/src/desugar/attributes.rs index 33ae4a1f..787de77e 100644 --- a/crates/kind-pass/src/desugar/attributes.rs +++ b/crates/kind-pass/src/desugar/attributes.rs @@ -44,6 +44,11 @@ impl<'a> DesugarState<'a> { self.attr_without_value(attr); attributes.inlined = true; } + "keep" => { + self.args_should_be_empty(attr); + self.attr_without_value(attr); + attributes.keep = true; + } "kdl_run" => { self.args_should_be_empty(attr); self.attr_without_value(attr); diff --git a/crates/kind-pass/src/erasure/mod.rs b/crates/kind-pass/src/erasure/mod.rs index e01a304c..9499db8d 100644 --- a/crates/kind-pass/src/erasure/mod.rs +++ b/crates/kind-pass/src/erasure/mod.rs @@ -123,7 +123,7 @@ impl<'a> ErasureState<'a> { } } - if entr.attrs.kdl_run { + if entr.attrs.kdl_run || entr.attrs.keep { let id = self.get_edge_or_create(&entr.name); self.set_relevance(id, Relevance::Relevant, entr.name.range); entrypoints.push(id); diff --git a/crates/kind-target-kdl/src/lib.rs b/crates/kind-target-kdl/src/lib.rs index d504c4d6..7575c760 100644 --- a/crates/kind-target-kdl/src/lib.rs +++ b/crates/kind-target-kdl/src/lib.rs @@ -22,6 +22,9 @@ pub fn compile_book( let flattened = flatten(book); let file = compile::compile_book(&flattened, sender, namespace)?; + + println!("{}", file); + let file = linearize::linearize_file(file); Some(file) } diff --git a/crates/kind-tests/tests/mod.rs b/crates/kind-tests/tests/mod.rs index f638fe72..6811499d 100644 --- a/crates/kind-tests/tests/mod.rs +++ b/crates/kind-tests/tests/mod.rs @@ -102,3 +102,38 @@ fn test_eval() -> Result<(), Error> { })?; Ok(()) } + + +#[test] +#[timeout(15000)] +fn test_kdl() -> Result<(), Error> { + test_kind2(Path::new("./tests/suite/kdl"), |path| { + let (rx, tx) = std::sync::mpsc::channel(); + let root = PathBuf::from("./tests/suite/lib").canonicalize().unwrap(); + let mut session = Session::new(root, rx); + + let entrypoints = vec!["Main".to_string()]; + let check = driver::compile_book_to_kdl(&PathBuf::from(path), &mut session, "", entrypoints); + + let diagnostics = tx.try_iter().collect::>(); + let render = RenderConfig::ascii(2); + + kind_report::check_if_colors_are_supported(true); + + match check { + Some(file) if diagnostics.is_empty() => { + file.to_string() + } + _ => { + let mut res_string = String::new(); + + for diag in diagnostics { + diag.render(&mut session, &render, &mut res_string).unwrap(); + } + + res_string + } + } + })?; + Ok(()) +} diff --git a/crates/kind-tests/tests/suite/eval/Getters.golden b/crates/kind-tests/tests/suite/eval/Getters.golden new file mode 100644 index 00000000..f1efb205 --- /dev/null +++ b/crates/kind-tests/tests/suite/eval/Getters.golden @@ -0,0 +1 @@ +300 \ No newline at end of file diff --git a/crates/kind-tests/tests/suite/eval/Getters.kind2 b/crates/kind-tests/tests/suite/eval/Getters.kind2 new file mode 100644 index 00000000..00615476 --- /dev/null +++ b/crates/kind-tests/tests/suite/eval/Getters.kind2 @@ -0,0 +1,10 @@ +#derive[getters] +record Pair (a: Type) (b: Type) { + fst : a + snd : b +} + +Main : U60 +Main = + let a = (Pair.new 100 200 :: Pair U60 U60) + (+ (Pair.fst.get a) (Pair.snd.get a)) \ No newline at end of file diff --git a/crates/kind-tests/tests/suite/eval/Setters.golden b/crates/kind-tests/tests/suite/eval/Setters.golden new file mode 100644 index 00000000..cdb660b8 --- /dev/null +++ b/crates/kind-tests/tests/suite/eval/Setters.golden @@ -0,0 +1 @@ +700 \ No newline at end of file diff --git a/crates/kind-tests/tests/suite/eval/Setters.kind2 b/crates/kind-tests/tests/suite/eval/Setters.kind2 new file mode 100644 index 00000000..1411a6bd --- /dev/null +++ b/crates/kind-tests/tests/suite/eval/Setters.kind2 @@ -0,0 +1,12 @@ +#derive[getters, setters] +record Pair (a: Type) (b: Type) { + fst : a + snd : b +} + +Main : U60 +Main = + let a = (Pair.new 100 200 :: Pair U60 U60) + let b = Pair.fst.set a 500 + let c = Pair.snd.set a (+ (Pair.fst.get b) (Pair.snd.get b)) + Pair.snd.get c \ No newline at end of file diff --git a/crates/kind-tests/tests/suite/kdl/ChangeName.golden b/crates/kind-tests/tests/suite/kdl/ChangeName.golden new file mode 100644 index 00000000..e69de29b diff --git a/crates/kind-tests/tests/suite/kdl/ChangeName.kind2 b/crates/kind-tests/tests/suite/kdl/ChangeName.kind2 new file mode 100644 index 00000000..85f73756 --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/ChangeName.kind2 @@ -0,0 +1,3 @@ +#kdl_name = JOJO +Jonathan.Joestar : U60 +Jonathan.Joestar = 42 \ No newline at end of file diff --git a/crates/kind-tests/tests/suite/kdl/Lambda.golden b/crates/kind-tests/tests/suite/kdl/Lambda.golden new file mode 100644 index 00000000..e69de29b diff --git a/crates/kind-tests/tests/suite/kdl/Lambda.kind2 b/crates/kind-tests/tests/suite/kdl/Lambda.kind2 new file mode 100644 index 00000000..d63a0fee --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/Lambda.kind2 @@ -0,0 +1,8 @@ +CoolFn : U60 -> U60 { + (x: U60) => (* 2 x) +} + +CoolFnApp (n: U60) : U60 { + let lam = (x: U60) => ((CoolFn) x) + (lam n) +} \ No newline at end of file diff --git a/crates/kind-tests/tests/suite/kdl/NonInlineState.golden b/crates/kind-tests/tests/suite/kdl/NonInlineState.golden new file mode 100644 index 00000000..38cdeec3 --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/NonInlineState.golden @@ -0,0 +1 @@ +ctr {MyFn.state} diff --git a/crates/kind-tests/tests/suite/kdl/NonInlineState.kind2 b/crates/kind-tests/tests/suite/kdl/NonInlineState.kind2 new file mode 100644 index 00000000..d94e77b5 --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/NonInlineState.kind2 @@ -0,0 +1,6 @@ +#kdl_state = MyFn.state +MyFn : U60 { + 1 +} + +MyFn.state : U60 \ No newline at end of file diff --git a/crates/kind-tests/tests/suite/kdl/Operators.golden b/crates/kind-tests/tests/suite/kdl/Operators.golden new file mode 100644 index 00000000..7d702560 --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/Operators.golden @@ -0,0 +1,3 @@ +run { + (& (+ #2 (& (- #3 (& (* #4 (/ #5 (% #6 (& (+ #2 (| #8 (^ #9 (<< #10 (% (>> #23 (% (< #2 (>= #4 (<= (== #4 #4) (> #3 (!= #5 #3))))) #60)) #60))))) #1152921504606846975)))) #1152921504606846975)) #1152921504606846975)) #1152921504606846975) +} diff --git a/crates/kind-tests/tests/suite/kdl/Operators.kind2 b/crates/kind-tests/tests/suite/kdl/Operators.kind2 new file mode 100644 index 00000000..6dafa9f6 --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/Operators.kind2 @@ -0,0 +1,18 @@ +#kdl_run +Main : U60 +Main = + (+ 2 + (- 3 + (* 4 + (/ 5 + (% 6 + (& 2 + (| 8 + (^ 9 + (<< 10 + (>> 23 + (< 2 + (>= 4 + (<= (== 4 4) + (> 3 + (!= 5 3))))))))))))))) \ No newline at end of file diff --git a/crates/kind-tests/tests/suite/kdl/RemoveNames.golden b/crates/kind-tests/tests/suite/kdl/RemoveNames.golden new file mode 100644 index 00000000..e69de29b diff --git a/crates/kind-tests/tests/suite/kdl/RemoveNames.kind2 b/crates/kind-tests/tests/suite/kdl/RemoveNames.kind2 new file mode 100644 index 00000000..eac8ce41 --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/RemoveNames.kind2 @@ -0,0 +1,14 @@ +List : Type + List.nil : List + List.cons (head: a) (tail: List a) : List + +/* +#keep +Ora.Ora.ora (h: List U60) : List U60 +Ora.Ora.ora (List.cons x xs) = + let aaa = 2 + let bbb = 3 + let ccc = 4 + let ddd = (+ ccc bbb) + List.cons aaa xs +*/ \ No newline at end of file diff --git a/crates/kind-tests/tests/suite/kdl/Run.golden b/crates/kind-tests/tests/suite/kdl/Run.golden new file mode 100644 index 00000000..0e702f11 --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/Run.golden @@ -0,0 +1,10 @@ +fun (A ) { + {A} = #2 +} + +run { + (A) +} +run { + #4 +} diff --git a/crates/kind-tests/tests/suite/kdl/Run.kind2 b/crates/kind-tests/tests/suite/kdl/Run.kind2 new file mode 100644 index 00000000..b4e34f9d --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/Run.kind2 @@ -0,0 +1,13 @@ +#kdl_name = A +Ata : U60 +Ata = 2 + +#kdl_name = B +#kdl_run +Be : U60 +Be = Ata + +#kdl_name = C +#kdl_run +Ce : U60 +Ce = 4 \ No newline at end of file diff --git a/crates/kind-tests/tests/suite/kdl/Shortener.golden b/crates/kind-tests/tests/suite/kdl/Shortener.golden new file mode 100644 index 00000000..e69de29b diff --git a/crates/kind-tests/tests/suite/kdl/Shortener.kind2 b/crates/kind-tests/tests/suite/kdl/Shortener.kind2 new file mode 100644 index 00000000..7f0c6436 --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/Shortener.kind2 @@ -0,0 +1,3 @@ +FunctionWithAVeryLongName : U60 { + 0 +} \ No newline at end of file diff --git a/crates/kind-tests/tests/suite/kdl/StillCalable.golden b/crates/kind-tests/tests/suite/kdl/StillCalable.golden new file mode 100644 index 00000000..a61d2616 --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/StillCalable.golden @@ -0,0 +1,4 @@ +fun (A ) { + {A} = (& (+ (B) #1) #1152921504606846975) +} + diff --git a/crates/kind-tests/tests/suite/kdl/StillCalable.kind2 b/crates/kind-tests/tests/suite/kdl/StillCalable.kind2 new file mode 100644 index 00000000..53cee51f --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/StillCalable.kind2 @@ -0,0 +1,11 @@ +#kdl_name = A +#keep +FnA { + (+ FnB 1) +} + +#kdl_name = B +#kdl_erase +FnB { + 2 +} \ No newline at end of file diff --git a/crates/kind-tests/tests/suite/kdl/U60.golden b/crates/kind-tests/tests/suite/kdl/U60.golden new file mode 100644 index 00000000..99928f86 --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/U60.golden @@ -0,0 +1,3 @@ +run { + #2 +} diff --git a/crates/kind-tests/tests/suite/kdl/U60.kind2 b/crates/kind-tests/tests/suite/kdl/U60.kind2 new file mode 100644 index 00000000..1f6fa84c --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/U60.kind2 @@ -0,0 +1,4 @@ +#kdl_run +#keep +Main: U60 +Main = 2 \ No newline at end of file diff --git a/crates/kind-tests/tests/suite/kdl/WithAttr.golden b/crates/kind-tests/tests/suite/kdl/WithAttr.golden new file mode 100644 index 00000000..e7df6d7c --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/WithAttr.golden @@ -0,0 +1,3 @@ +run { + #0 +} diff --git a/crates/kind-tests/tests/suite/kdl/WithAttr.kind2 b/crates/kind-tests/tests/suite/kdl/WithAttr.kind2 new file mode 100644 index 00000000..e307640e --- /dev/null +++ b/crates/kind-tests/tests/suite/kdl/WithAttr.kind2 @@ -0,0 +1,9 @@ +#kdl_state = MyFn.state +MyFn : U60 { + 1 +} + +#kdl_run +MyFn.state : U60 { + 0 +} \ No newline at end of file diff --git a/crates/kind-tests/tests/suite/lib/String.kind2 b/crates/kind-tests/tests/suite/lib/String.kind2 new file mode 100644 index 00000000..dea62404 --- /dev/null +++ b/crates/kind-tests/tests/suite/lib/String.kind2 @@ -0,0 +1,4 @@ +type String { + cons (x: U60) (xs: String) + nil +} \ No newline at end of file diff --git a/crates/kind-tree/src/lib.rs b/crates/kind-tree/src/lib.rs index ef259190..86bc7509 100644 --- a/crates/kind-tree/src/lib.rs +++ b/crates/kind-tree/src/lib.rs @@ -32,6 +32,7 @@ pub struct Attributes { pub kdl_name: Option, pub kdl_state: Option, pub trace: Option, // Some is enabled and some(true) is enabled with arguments + pub keep: bool } /// Enum of binary operators.