From 081d35995898d2cd9383734e23776ad62ee0362a Mon Sep 17 00:00:00 2001 From: Nicolas Abril Date: Thu, 24 Nov 2022 15:25:45 +0100 Subject: [PATCH] Add initial to-kdl compile function --- Cargo.lock | 507 +++++++++++++++++++++++++- crates/kind-target-kdl/Cargo.toml | 4 +- crates/kind-target-kdl/src/lib.rs | 242 +++++++++++- crates/kind-tree/src/desugared/mod.rs | 6 +- 4 files changed, 746 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 428a69ad..5c6acbf4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + [[package]] name = "atty" version = "0.2.14" @@ -13,12 +19,27 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "autocfg" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" +dependencies = [ + "autocfg 1.1.0", +] + [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + [[package]] name = "bitflags" version = "1.3.2" @@ -34,18 +55,58 @@ dependencies = [ "typenum", ] +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "block-padding", + "generic-array", +] + +[[package]] +name = "block-padding" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" + [[package]] name = "bumpalo" version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + [[package]] name = "byteorder" version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "cc" +version = "1.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" + [[package]] name = "cfg-if" version = "1.0.0" @@ -128,12 +189,30 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + [[package]] name = "core-foundation-sys" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +[[package]] +name = "cpufeatures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +dependencies = [ + "libc", +] + [[package]] name = "crossbeam" version = "0.8.2" @@ -175,7 +254,7 @@ version = "0.9.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96bf8df95e795db1a4aca2957ad884a2df35413b24bbeb3114422f3cc21498e8" dependencies = [ - "autocfg", + "autocfg 1.1.0", "cfg-if", "crossbeam-utils", "memoffset", @@ -201,6 +280,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "ctor" version = "0.1.26" @@ -230,12 +315,45 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + [[package]] name = "either" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[package]] +name = "fixed-hash" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" +dependencies = [ + "byteorder", + "rand 0.8.5", + "rustc-hex", + "static_assertions", +] + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "fxhash" version = "0.2.1" @@ -245,6 +363,27 @@ dependencies = [ "byteorder", ] +[[package]] +name = "generic-array" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -266,6 +405,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "highlight_error" version = "0.1.1" @@ -293,20 +438,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0acd33ff0285af998aaf9b57342af478078f53492322fafc47450e09397e0e9" dependencies = [ "bitmaps", - "rand_core", + "rand_core 0.6.4", "rand_xoshiro", "sized-chunks", "typenum", "version_check", ] +[[package]] +name = "impl-codec" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "indexmap" version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ - "autocfg", + "autocfg 1.1.0", "hashbrown", ] @@ -340,6 +505,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "keccak" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" +dependencies = [ + "cpufeatures", +] + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -472,11 +646,13 @@ dependencies = [ name = "kind-target-kdl" version = "0.1.0" dependencies = [ - "hvm", + "fxhash", "kind-derive", "kind-report", "kind-span", "kind-tree", + "kindelia_lang", + "linked-hash-map", ] [[package]] @@ -489,6 +665,30 @@ dependencies = [ "linked-hash-map", ] +[[package]] +name = "kindelia_common" +version = "0.1.5" +source = "git+https://github.com/developedby/Kindelia/?branch=kdl-lang-crate#5a59c6b0798c561bb1ec42a6e786a93af9151276" +dependencies = [ + "bit-vec", + "hex", + "primitive-types", + "secp256k1", + "serde", + "sha3", + "tiny-keccak", +] + +[[package]] +name = "kindelia_lang" +version = "0.1.0" +source = "git+https://github.com/developedby/Kindelia/?branch=kdl-lang-crate#5a59c6b0798c561bb1ec42a6e786a93af9151276" +dependencies = [ + "hex", + "kindelia_common", + "serde", +] + [[package]] name = "libc" version = "0.2.137" @@ -507,7 +707,7 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ - "autocfg", + "autocfg 1.1.0", "scopeguard", ] @@ -526,7 +726,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" dependencies = [ - "autocfg", + "autocfg 1.1.0", ] [[package]] @@ -601,6 +801,12 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "os_str_bytes" version = "6.3.1" @@ -616,6 +822,32 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "parity-scale-codec" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "366e44391a8af4cfd6002ef6ba072bae071a96aafca98d7d448a34c5dca38b6a" +dependencies = [ + "arrayvec", + "bitvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9299338969a3d2f491d65f140b00ddec470858402f888af98e8642fb5e8965cd" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "parking_lot_core" version = "0.9.4" @@ -635,6 +867,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "pretty_assertions" version = "1.3.0" @@ -647,6 +885,17 @@ dependencies = [ "yansi", ] +[[package]] +name = "primitive-types" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28720988bff275df1f51b171e1b2a18c30d194c4d2b61defdacecd625a5d94a" +dependencies = [ + "fixed-hash", + "impl-codec", + "uint", +] + [[package]] name = "proc-macro-crate" version = "1.2.1" @@ -700,11 +949,147 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +dependencies = [ + "autocfg 0.1.8", + "libc", + "rand_chacha 0.1.1", + "rand_core 0.4.2", + "rand_hc", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg", + "rand_xorshift", + "winapi 0.3.9", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +dependencies = [ + "autocfg 0.1.8", + "rand_core 0.3.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + [[package]] name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +dependencies = [ + "libc", + "rand_core 0.4.2", + "winapi 0.3.9", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.2", + "rdrand", + "winapi 0.3.9", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +dependencies = [ + "autocfg 0.1.8", + "rand_core 0.4.2", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +dependencies = [ + "rand_core 0.3.1", +] [[package]] name = "rand_xoshiro" @@ -712,7 +1097,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" dependencies = [ - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -738,6 +1123,15 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -756,6 +1150,12 @@ dependencies = [ "redox_syscall", ] +[[package]] +name = "rustc-hex" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" + [[package]] name = "same-file" version = "1.0.6" @@ -771,11 +1171,56 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "secp256k1" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26947345339603ae8395f68e2f3d85a6b0a8ddfe6315818e80b8504415099db0" +dependencies = [ + "rand 0.6.5", + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "152e20a0fd0519390fc43ab404663af8a0b794273d2a91d60ad4a39f13ffe110" +dependencies = [ + "cc", +] + [[package]] name = "serde" version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sha3" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +dependencies = [ + "block-buffer", + "digest", + "keccak", + "opaque-debug", +] [[package]] name = "sized-chunks" @@ -793,6 +1238,12 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strsim" version = "0.10.0" @@ -825,6 +1276,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "termcolor" version = "1.1.3" @@ -885,6 +1342,15 @@ dependencies = [ "syn", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "toml" version = "0.5.9" @@ -900,6 +1366,18 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +[[package]] +name = "uint" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a45526d29728d135c2900b0d30573fe3ee79fceb12ef534c7bb30e810a91b601" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + [[package]] name = "unicode-ident" version = "1.0.5" @@ -929,6 +1407,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "wasm-bindgen" version = "0.2.83" @@ -1093,6 +1577,15 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "yansi" version = "0.5.1" diff --git a/crates/kind-target-kdl/Cargo.toml b/crates/kind-target-kdl/Cargo.toml index 41240470..f7e09289 100644 --- a/crates/kind-target-kdl/Cargo.toml +++ b/crates/kind-target-kdl/Cargo.toml @@ -11,4 +11,6 @@ kind-tree = { path = "../kind-tree" } kind-report = { path = "../kind-report" } kind-derive = { path = "../kind-derive" } -hvm = { git = "https://github.com/Kindelia/HVM.git" } \ No newline at end of file +kindelia_lang = { git = "https://github.com/developedby/Kindelia/", branch = "kdl-lang-crate" } +linked-hash-map = "0.5.6" +fxhash = "0.2.1" \ No newline at end of file diff --git a/crates/kind-target-kdl/src/lib.rs b/crates/kind-target-kdl/src/lib.rs index b5c8acf8..f9b4020a 100644 --- a/crates/kind-target-kdl/src/lib.rs +++ b/crates/kind-target-kdl/src/lib.rs @@ -1 +1,241 @@ -mod term; +use fxhash::FxHashMap; +use kind_tree::desugared as kind; +pub use kindelia_lang::ast as kdl; +use linked_hash_map::LinkedHashMap; + +pub struct File { + funs: LinkedHashMap, + runs: Vec, +} + +pub struct CompileCtx<'a> { + file: File, + kdl_names: FxHashMap, + kdl_states: Vec, + book: &'a kind::Book, +} + +pub fn compile_book(book: &kind::Book) -> File { + let mut ctx = CompileCtx { + file: File { + funs: Default::default(), + runs: Default::default(), + }, + kdl_names: Default::default(), + kdl_states: Default::default(), + book, + }; + for (_name, entry) in &book.entrs { + compile_entry(&mut ctx, entry); + } + ctx.file +} + +pub fn compile_entry(ctx: &mut CompileCtx, entry: &kind::Entry) { + let is_erased = entry + .attrs + .iter() + .find(|x| matches!(x, kind::Attribute::KdlErase)) + .is_some(); + if is_erased { + // Don't compile + return; + } + let is_run = entry + .attrs + .iter() + .find(|x| matches!(x, kind::Attribute::KdlRun)) + .is_some(); + if is_run { + // Compile as Run + if entry.args.len() != 0 { + todo!(); // run has args + } else if entry.rules.len() != 1 { + todo!(); // run doesn't have exactly 1 rule + } else { + let expr = compile_expr(ctx, &entry.rules[0].body); + let statement = kdl::Statement::Run { expr, sign: None }; + ctx.file.runs.push(statement); + } + } else { + // Shared between Ctr and Fun + let name = ctx.kdl_names.get(&entry.name.to_string()).unwrap().clone(); + let mut args = Vec::new(); + for arg in &entry.args { + let name = arg.name.to_str(); + if let Ok(name) = kdl::Name::from_str(name) { + args.push(name); + } else { + todo!(); // arg name not valid kdl name + } + } + if entry.rules.len() == 0 { + // Compile as Ctr + let stmt = kdl::Statement::Ctr { + name, + args, + sign: None, + }; + ctx.file.funs.insert(entry.name.to_string(), stmt); + } else { + // Compile as Fun + let mut rules = Vec::new(); + for rule in &entry.rules { + rules.push(compile_rule(ctx, rule)); + } + let func = kdl::Func { rules }; + let attr = entry + .attrs + .iter() + .find(|x| matches!(x, kind::Attribute::KdlState(_))); + let init = if let Some(kind::Attribute::KdlState(init_name)) = attr { + let init_entry = ctx.book.entrs.get(init_name.to_str()); + if let Some(init_entry) = init_entry { + // Has some initial state + if init_entry.args.len() != 0 { + todo!(); // state has args + } else if init_entry.rules.len() != 1 { + todo!(); // state doesn't have exactly 1 rule + } else { + ctx.kdl_states.push(init_name.to_string()); + let init = compile_expr(ctx, &init_entry.rules[0].body); + Some(init) + } + } else { + todo!(); // Init state not defined + } + } else { + todo!(); // Has no initial state + }; + let stmt = kdl::Statement::Fun { + name, + args, + func, + init, + sign: None, + }; + ctx.file.funs.insert(entry.name.to_string(), stmt); + } + } +} + +pub fn compile_rule(ctx: &mut CompileCtx, rule: &kind::Rule) -> kdl::Rule { + let name = ctx.kdl_names.get(rule.name.to_str()).unwrap().clone(); + let mut args = Vec::new(); + for pat in &rule.pats { + let arg = compile_expr(ctx, pat); + args.push(arg); + } + let lhs = kdl::Term::fun(name, args); + let rhs = compile_expr(ctx, &rule.body); + let rule = kdl::Rule { lhs, rhs }; + rule +} + +pub fn compile_expr(ctx: &mut CompileCtx, expr: &kind::Expr) -> kdl::Term { + use kdl::Term as T; + use kind::ExprKind as E; + match &expr.data { + E::App(head, spine) => { + let mut expr = compile_expr(ctx, head); + for binding in spine { + let body = compile_expr(ctx, &binding.data); + expr = T::App { + func: Box::new(expr), + argm: Box::new(body), + }; + } + expr + } + E::Binary(op, x0, x1) => { + // TODO: Special compilation for U60 ops + let oper = compile_oper(op); + let val0 = Box::new(compile_expr(ctx, x0)); + let val1 = Box::new(compile_expr(ctx, x1)); + T::Op2 { oper, val0, val1 } + } + E::Ctr(name, spine) => { + let name = ctx.kdl_names.get(name.to_str()).unwrap().clone(); + let mut args = Vec::new(); + for arg in spine { + args.push(compile_expr(ctx, &arg)); + } + T::Ctr { name, args } + } + E::Fun(name, spine) => { + // TODO: Special compilation for U60 and U120 ops + let name = ctx.kdl_names.get(name.to_str()).unwrap().clone(); + let mut args = Vec::new(); + for arg in spine { + args.push(compile_expr(ctx, &arg)); + } + T::Fun { name, args } + } + E::Lambda(name, body, _) => { + let name = kdl::Name::from_str(name.to_str()); + if let Ok(name) = name { + let body = Box::new(compile_expr(ctx, &body)); + T::Lam { name, body } + } else { + todo!(); // var name not valid + } + } + E::Let(name, expr, body) => { + let name = kdl::Name::from_str(name.to_str()); + if let Ok(name) = name { + let expr = Box::new(compile_expr(ctx, &expr)); + let func = Box::new(T::Lam { name, body: expr }); + let argm = Box::new(compile_expr(ctx, body)); + T::App { func, argm } + } else { + todo!(); // var name not valid + } + } + E::Num(kind::Number::U60(numb)) => T::Num { + numb: kdl::U120(*numb as u128), + }, + E::Num(kind::Number::U120(numb)) => T::Num { + numb: kdl::U120(*numb), + }, + E::Var(name) => { + let name = kdl::Name::from_str(name.to_str()); + if let Ok(name) = name { + T::Var { name } + } else { + todo!(); // var name not valid + } + } + E::All(..) => unreachable!(), + E::Ann(..) => unreachable!(), + E::Hlp(..) => unreachable!(), + E::Hole(..) => unreachable!(), + E::NumType(..) => unreachable!(), + E::Str(..) => unreachable!(), + E::Sub(..) => unreachable!(), + E::Typ => unreachable!(), + E::Err => unreachable!(), + } +} + +fn compile_oper(oper: &kind::Operator) -> kdl::Oper { + use kdl::Oper as T; + use kind::Operator as F; + match oper { + F::Add => T::Add, + F::Sub => T::Sub, + F::Mul => T::Mul, + F::Div => T::Div, + F::Mod => T::Mod, + F::Shl => T::Shl, + F::Shr => T::Shr, + F::Eql => T::Eql, + F::Neq => T::Neq, + F::Ltn => T::Ltn, + F::Lte => T::Lte, + F::Gte => T::Gte, + F::Gtn => T::Gtn, + F::And => T::And, + F::Xor => T::Xor, + F::Or => T::Or, + } +} diff --git a/crates/kind-tree/src/desugared/mod.rs b/crates/kind-tree/src/desugared/mod.rs index c3fe94fc..d28d5b99 100644 --- a/crates/kind-tree/src/desugared/mod.rs +++ b/crates/kind-tree/src/desugared/mod.rs @@ -7,10 +7,8 @@ use fxhash::FxHashMap; use kind_span::{Range, Span}; use linked_hash_map::LinkedHashMap; -use crate::{ - symbol::{Ident, QualifiedIdent}, - Operator, -}; +use crate::symbol::{Ident, QualifiedIdent}; +pub use crate::{NumType, Number, Operator}; /// Just a vector of expressions. It is called spine because /// it is usually in a form like (a b c d e) that can be interpret