diff --git a/Cargo.lock b/Cargo.lock index cf927d8..1731557 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "atty" version = "0.2.14" @@ -27,63 +36,24 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "block-buffer" -version = "0.7.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ - "block-padding", - "byte-tools", - "byteorder", "generic-array", ] -[[package]] -name = "block-padding" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" -dependencies = [ - "byte-tools", -] - -[[package]] -name = "bstr" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" -dependencies = [ - "lazy_static", - "memchr", - "regex-automata", - "serde", -] - [[package]] name = "bumpalo" -version = "3.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" - -[[package]] -name = "byte-tools" -version = "0.3.1" +version = "3.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" - -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" [[package]] name = "cast" -version = "0.2.7" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" -dependencies = [ - "rustc_version", -] +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cfg-if" @@ -104,39 +74,57 @@ dependencies = [ [[package]] name = "clap" -version = "3.1.2" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5177fac1ab67102d8989464efd043c6ff44191b1557ec1ddd489b4f7e1447e77" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", "bitflags", "clap_derive", + "clap_lex", "indexmap", - "lazy_static", - "os_str_bytes", + "once_cell", "strsim", "termcolor", - "textwrap 0.14.2", + "textwrap 0.16.1", ] [[package]] name = "clap_derive" -version = "3.1.2" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01d42c94ce7c2252681b5fed4d3627cc807b13dfc033246bd05d5b252399000e" +checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" dependencies = [ "heck", "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", ] [[package]] name = "criterion" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10" +checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f" dependencies = [ "atty", "cast", @@ -160,101 +148,85 @@ dependencies = [ [[package]] name = "criterion-plot" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d00996de9f2f7559f7f4dc286073197f83e92256a59ed395f9aac01fe717da57" +checksum = "2673cc8207403546f45f5fd319a974b1e6983ad1a3ee7e6041650013be041876" dependencies = [ "cast", "itertools", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - [[package]] name = "crossbeam-deque" -version = "0.8.1" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ - "cfg-if", "crossbeam-epoch", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.8" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ - "autocfg", - "cfg-if", "crossbeam-utils", - "lazy_static", - "memoffset", - "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.8" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + +[[package]] +name = "crypto-common" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ - "cfg-if", - "lazy_static", + "generic-array", + "typenum", ] [[package]] name = "csv" -version = "1.1.6" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" +checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe" dependencies = [ - "bstr", "csv-core", - "itoa 0.4.8", + "itoa", "ryu", "serde", ] [[package]] name = "csv-core" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" +checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" dependencies = [ "memchr", ] [[package]] name = "digest" -version = "0.8.1" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "generic-array", + "block-buffer", + "crypto-common", ] [[package]] name = "either" -version = "1.6.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] -name = "fake-simd" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" [[package]] name = "fuchsia-cprng" @@ -264,30 +236,31 @@ checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" [[package]] name = "generic-array" -version = "0.12.4" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", + "version_check", ] [[package]] name = "half" -version = "1.8.2" +version = "1.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" +checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" [[package]] name = "hashbrown" -version = "0.11.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "heck" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" @@ -300,9 +273,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.8.0" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown", @@ -310,30 +283,24 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.3" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ "either", ] [[package]] name = "itoa" -version = "0.4.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" - -[[package]] -name = "itoa" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.57" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] @@ -348,48 +315,31 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" name = "lem" version = "0.0.1" dependencies = [ - "clap 3.1.2", + "clap 3.2.25", "criterion", "pest", "pest_derive", "stopwatch", + "thiserror", ] [[package]] name = "libc" -version = "0.2.119" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "log" -version = "0.4.16" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "maplit" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "memchr" -version = "2.4.1" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" - -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "num" @@ -429,19 +379,18 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.44" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] name = "num-iter" -version = "0.1.42" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" +checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" dependencies = [ "autocfg", "num-integer", @@ -462,22 +411,18 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.14" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", ] [[package]] -name = "num_cpus" -version = "1.13.1" +name = "once_cell" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" -dependencies = [ - "hermit-abi", - "libc", -] +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "oorandom" @@ -485,36 +430,28 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" -[[package]] -name = "opaque-debug" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" - [[package]] name = "os_str_bytes" -version = "6.0.0" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" -dependencies = [ - "memchr", -] +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "pest" -version = "2.5.2" +version = "2.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f6e86fb9e7026527a0d46bc308b841d73170ef8f443e1807f6ef88526a816d4" +checksum = "56f8023d0fb78c8e03784ea1c7f3fa36e68a723138990b8d5a47d916b651e7a8" dependencies = [ + "memchr", "thiserror", "ucd-trie", ] [[package]] name = "pest_derive" -version = "2.1.0" +version = "2.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0" +checksum = "b0d24f72393fd16ab6ac5738bc33cdb6a9aa73f8b902e8fe29cf4e67d7dd1026" dependencies = [ "pest", "pest_generator", @@ -522,33 +459,33 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.1.3" +version = "2.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" +checksum = "fdc17e2a6c7d0a492f0158d7a4bd66cc17280308bbaff78d5bef566dca35ab80" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn", + "syn 2.0.52", ] [[package]] name = "pest_meta" -version = "2.1.3" +version = "2.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" +checksum = "934cd7631c050f4674352a6e835d5f6711ffbfb9345c2fc0107155ac495ae293" dependencies = [ - "maplit", + "once_cell", "pest", - "sha-1", + "sha2", ] [[package]] name = "plotters" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a3fd9ec30b9749ce28cd91f255d569591cdf937fe280c312143e3c4bad6f2a" +checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" dependencies = [ "num-traits", "plotters-backend", @@ -559,15 +496,15 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.2" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d88417318da0eaf0fdcdb51a0ee6c3bed624333bff8f946733049380be67ac1c" +checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" [[package]] name = "plotters-svg" -version = "0.3.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521fa9638fa597e1dc53e9412a4f9cefb01187ee1f7413076f9e6749e2885ba9" +checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" dependencies = [ "plotters-backend", ] @@ -581,7 +518,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "version_check", ] @@ -598,18 +535,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.36" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.15" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -644,27 +581,22 @@ checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" [[package]] name = "rayon" -version = "1.5.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" +checksum = "e4963ed1bc86e4f3ee217022bd855b297cef07fb9eac5dfa1f788b220b49b3bd" dependencies = [ - "autocfg", - "crossbeam-deque", "either", "rayon-core", ] [[package]] name = "rayon-core" -version = "1.9.1" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ - "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "lazy_static", - "num_cpus", ] [[package]] @@ -678,45 +610,44 @@ dependencies = [ [[package]] name = "regex" -version = "1.5.5" +version = "1.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", "regex-syntax", ] [[package]] name = "regex-automata" -version = "0.1.10" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "rustc-serialize" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" - -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver", -] +checksum = "fe834bc780604f4674073badbad26d7219cadfb4a2275802db12cbae17498401" [[package]] name = "ryu" -version = "1.0.9" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "same-file" @@ -727,23 +658,14 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "semver" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d65bd28f48be7196d222d95b9243287f48d27aca604e08497513019ff0502cc4" - [[package]] name = "serde" -version = "1.0.136" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] [[package]] name = "serde_cbor" @@ -757,36 +679,35 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.136" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.52", ] [[package]] name = "serde_json" -version = "1.0.79" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ - "itoa 1.0.1", + "itoa", "ryu", "serde", ] [[package]] -name = "sha-1" -version = "0.8.2" +name = "sha2" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ - "block-buffer", + "cfg-if", + "cpufeatures", "digest", - "fake-simd", - "opaque-debug", ] [[package]] @@ -806,20 +727,31 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.86" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] name = "termcolor" -version = "1.1.2" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] @@ -835,28 +767,28 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.14.2" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" [[package]] name = "thiserror" -version = "1.0.38" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.38" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.52", ] [[package]] @@ -871,27 +803,27 @@ dependencies = [ [[package]] name = "typenum" -version = "1.15.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ucd-trie" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" [[package]] -name = "unicode-width" -version = "0.1.9" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] -name = "unicode-xid" -version = "0.2.2" +name = "unicode-width" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" [[package]] name = "version_check" @@ -901,20 +833,19 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "walkdir" -version = "2.3.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" dependencies = [ "same-file", - "winapi", "winapi-util", ] [[package]] name = "wasm-bindgen" -version = "0.2.80" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -922,24 +853,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.80" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", - "lazy_static", "log", + "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.52", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.80" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -947,28 +878,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.80" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.52", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.80" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "web-sys" -version = "0.3.57" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ "js-sys", "wasm-bindgen", @@ -992,9 +923,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ "winapi", ] diff --git a/Cargo.toml b/Cargo.toml index e10d9bd..a2f2fdb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ clap = { version = "3.1.2", features = ["cargo", "derive"] } pest = "2.5.2" pest_derive = "2.1.0" stopwatch = "0.0.7" +thiserror = "1.0.58" [dev-dependencies] criterion = "0.3" diff --git a/docs/src/README.md b/docs/src/README.md index 961953f..930a613 100644 --- a/docs/src/README.md +++ b/docs/src/README.md @@ -4,7 +4,7 @@ Lem is a minimal, only-what-you-need scripting language, built as an alternative ## Why? -While Bash has proven powerful again and again, its scripts have also proved unmaintainable time and time again. This is in part due to its unclear syntax. Lem strives to have a simplistic, readable syntax that will make maintaining scripts much more enjoyable. +While Bash has proven powerful again and again, its scripts have also proved unmaintainable time and time again. This is in part due to its unclear syntax. Lem aims to have a simplistic, readable syntax that makes maintaining scripts much more enjoyable. Unlike Bash, Lem attempts to provide a single way to perform a single operation. Bash is notably able to do one thing in four or five different ways, which can make it hard for maintainers to remember what does what without comments littered across the script. diff --git a/src/ast.rs b/src/ast.rs index fcbf61c..70d55c4 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1,4 +1,4 @@ -use std::{cell::RefCell, collections::LinkedList, rc::Rc}; +use std::{cell::RefCell, collections::LinkedList, fmt::Error, rc::Rc}; use crate::parser::Rule; use pest::iterators::{Pair, Pairs}; @@ -10,13 +10,28 @@ pub struct File { #[derive(Debug)] pub enum Node { Call { ident: String, args: Args }, + VarDecl { ident: String, value: Value }, + VarReassign { ident: String, value: Value }, + EnterBlock, + ExitBlock, EOI, } -#[derive(Debug)] +#[derive(Debug, Clone, PartialEq)] pub enum Value { String(String), Ident(String), + None +} + +impl std::fmt::Display for Value { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Value::String(string) => write!(f, "{}", string), + Value::Ident(ident) => unimplemented!(), + Value::None => unimplemented!(), + } + } } #[derive(Debug)] @@ -37,9 +52,17 @@ impl Args { Args { inner: vec![value] } } - pub fn has_args(self) -> bool { + pub fn has_args(&self) -> bool { !self.inner.is_empty() } + + pub fn len(&self) -> usize { + self.inner.len() + } + + pub fn get(&self) -> &Vec { + &self.inner + } } impl IntoIterator for Args { @@ -107,9 +130,82 @@ impl<'a> AST<'a> { self.next = next; self.visit_call(); }, - _ => {}, + Rule::var_decl => { + self.next = next; + self.visit_var_decl(); + }, + Rule::var_reassign => { + self.next = next; + self.visit_var_reassign(); + } + Rule::block => { + self.next = next; + self.visit_block(); + } + _ => unimplemented!(), + } + } + } + + fn visit_block(&mut self) { + self.nodes.borrow_mut().push_back(Node::EnterBlock); + for next in self.next.clone().into_inner() { + self.next = next; + self.visit_decl(); + } + self.nodes.borrow_mut().push_back(Node::ExitBlock); + } + + fn visit_var_decl(&mut self) { + let mut ident = String::new(); + let mut value = Value::None; + + for next in self.next.clone().into_inner() { + match next.as_rule() { + Rule::ident => { + self.next = next; + ident = self.visit_ident(); + }, + Rule::value => { + self.next = next; + value = self.visit_value(); + }, + _ => unreachable!(), } } + + self.nodes.borrow_mut().push_back( + Node::VarDecl { + ident: ident, + value: value, + } + ) + } + + fn visit_var_reassign(&mut self) { + let mut ident = String::new(); + let mut value = Value::None; + + for next in self.next.clone().into_inner() { + match next.as_rule() { + Rule::ident => { + self.next = next; + ident = self.visit_ident(); + }, + Rule::value => { + self.next = next; + value = self.visit_value(); + }, + _ => unreachable!(), + } + } + + self.nodes.borrow_mut().push_back( + Node::VarReassign { + ident: ident, + value: value, + } + ) } fn visit_call(&mut self) { @@ -165,6 +261,10 @@ impl<'a> AST<'a> { self.next = next; Value::String(self.visit_string()) }, + Rule::ident => { + self.next = next; + Value::Ident(self.visit_ident()) + } _ => unimplemented!(), } } @@ -177,8 +277,6 @@ impl<'a> AST<'a> { self.next.clone().as_span().as_str().to_string().replace("\"", "") } - - fn visit_eoi(&mut self) { self.nodes.borrow_mut().push_back(Node::EOI); } diff --git a/src/interp/environment.rs b/src/interp/environment.rs new file mode 100644 index 0000000..b91af54 --- /dev/null +++ b/src/interp/environment.rs @@ -0,0 +1,90 @@ +use std::collections::HashMap; +use std::cell::Cell; + +use crate::ast::Value; + +#[derive(Debug, Clone)] +pub struct Environment { + pub id: usize, + pub values: HashMap, // todo: remove pub + pub parent: Option, +} + +thread_local!(static ENVIRONMENT_ID: Cell = Cell::new(0)); + +impl Environment { + // use Interpreter::new_env() + pub fn new(parent: Option) -> Self { + ENVIRONMENT_ID.with(|thread_id| { + let id = thread_id.get(); + // if a program gets big enough, this could overflow. todo: find new id solution that won't run out. uuids? + thread_id.set(id + 1); + Environment { id: id, values: HashMap::new(), parent: parent } + }) + } + + pub fn define(&mut self, ident: String, value: Value) { + println!("define in: {}", self.id); + if !self.values.contains_key(ident.as_str()) { + self.values.insert(ident, value); + } else { + // error + } + println!("{:?}", self.values); + } + + pub fn redefine(&mut self, ident: String, value: Value) { + if self.values.contains_key(ident.as_str()) { + self.values.insert(ident, value); + } else { + // error + } + } + + pub fn var_exists(&self, ident: &str) -> bool { + self.values.contains_key(ident) + } + + pub fn get_var(&self, ident: &str) -> Option<&Value> { + self.values.get(ident) + } +} + +#[cfg(test)] +mod tests { + use std::collections::HashMap; + use super::{Environment, Value}; + + #[test] + fn new() { + let env = Environment::new(None); + + assert_eq!(env.parent, None); + assert!(env.values.is_empty()); + } + + #[test] + fn get_var() { + let mut env = Environment::new(None); + + assert_eq!(env.values, HashMap::new()); + + env.values.insert("test".to_string(), Value::String("test".to_string())); + + let mut map = HashMap::new(); + map.insert(String::from("test"), Value::String(String::from("test"))); + + assert_eq!(env.values, map); + } + + #[test] + fn define_var() { + let mut env = Environment::new(None); + env.define(String::from("test"), Value::String(String::from("test"))); + + let mut map = HashMap::new(); + map.insert(String::from("test"), Value::String(String::from("test"))); + + assert_eq!(env.values, map); + } +} diff --git a/src/interp/mod.rs b/src/interp/mod.rs index 960841b..682de0e 100644 --- a/src/interp/mod.rs +++ b/src/interp/mod.rs @@ -1,35 +1,216 @@ -use std::collections::LinkedList; +use std::collections::HashMap; +use std::cell::Cell; +use thiserror::Error; -use crate::{ast::*, parser::Rule}; -use pest::iterators::Pairs; +use crate::ast::*; +pub use crate::interp::environment::*; + +pub mod environment; + +#[derive(Error, Debug)] +enum InterpreterError { + #[error("")] + DefineError, + #[error("")] + RedefineError, +} + +#[derive(Debug)] +pub enum Command { + Call { ident: String, args: Args }, + VarDecl { ident: String, value: Value }, + VarReassign { ident: String, value: Value }, + EnterBlock, + ExitBlock, + EOI, +} pub struct Interpreter { - // pub instrs: LinkedList, - pub tree: File, + pub environments: HashMap, + pub environment: Environment, + // TODO: environment is out of sync with the same one stored in environments. Perhaps only store the current environment in the environment variable, and not in environments as well? That way you can update any for loops through all environments (or lookups) to first try the current environment and then the environments map + // TODO: write an executor/program that lets you step by step see the execution of the program so you can see exactly how state changes } impl Interpreter { - pub fn new(tree: File) -> Self { - Self { tree: tree } + pub fn new() -> Self { + let mut environments = HashMap::new(); + let environment = Environment::new(None); + environments.insert(environment.id, environment.clone()); + + Interpreter { + environments: environments, + environment: environment, + } + } + + pub fn new_env(&mut self) { + let new_env = Environment::new(Some(self.environment.id)); + self.environments.insert(new_env.id, new_env.clone()); + self.environment = new_env; } - pub fn interpret(&mut self) { - let mut nodes = self.tree.nodes.borrow_mut(); - while !nodes.is_empty() { - let instr = nodes.pop_front().unwrap(); - match instr { - Node::Call { ident: ident, args } => { - println!("- call {:?} with {:?}", ident, args); - if ident == String::from("print") { - println!("{args:#?}"); + pub fn destroy_env(&mut self) { + if self.environment.parent.is_some() { + let parent = self.environments.get(&self.environment.parent.unwrap()).unwrap(); + let old_id = self.environment.id.clone(); + self.environment = parent.clone(); + // self.environments.remove(&old_id); + } else { + // runtime error + // println!("destroy_env: reached parent"); + } + } + + pub fn fetch(&self, ident: &str) -> Option<&Value> { + if self.environment.var_exists(ident) { + return self.environment.get_var(ident); + } else { + let mut current_env = &self.environment; + loop { + if current_env.parent.is_some() { + current_env = self.environments.get(¤t_env.parent.unwrap()).unwrap(); + if current_env.var_exists(ident) { + return current_env.get_var(ident); } - }, - Node::EOI => {}, // terminate - }; + } else { + return None; + } + } + } + } + + pub fn interpret(&mut self, command: Command) { + match command { + Command::Call { ident, args } => { + match ident.as_str() { + "debug" => { + println!("{args:?}"); + }, + // todo: implement seperately & properly + "print" | "println" => { + if args.len() == 1 { + let value = args.get().first().unwrap(); + match value { + Value::Ident(inner_ident) => { + if self.environment.var_exists(inner_ident) { + let inner_string = self.fetch(inner_ident).unwrap(); + println!("{}", inner_string); + } else { + // error + } + }, + Value::String(inner_string) => { + print!("{}", inner_string); + }, + _ => unimplemented!(), + } + } else { + // error + } + }, + _ => unimplemented!(), + } + }, + Command::VarDecl { ident, value } => { + match &value { + // let example2 = example; + // example is ident + // example2 is ref_ident + Value::Ident(ref_ident) => { + if self.environment.var_exists(ref_ident.as_str()) { + // let ref_value = self.environment.values.get(ref_ident.as_str()).unwrap().to_owned(); + let ref_value = self.fetch(ref_ident).unwrap(); + self.environment.define(ident, ref_value.clone()); + // self.environment.values.insert(ident.clone(), ref_value); + } else { + // error + } + }, + _ => { + println!("before: {:?}", self.environment.values); + let mut env = self.environment.clone(); + env.define(ident, value); + self.environments.remove(&self.environment.id); + self.environments.insert(env.id, env); + println!("after: {:?}", self.environment.values); + // println!("{:?}", self.environment.values); + // self.environment.values.insert(ident, value); + } + } + }, + Command::VarReassign { ident, value } => { + match &value { + // let example2 = example; + // example is ident + // example2 is refIdent + Value::Ident(ref_ident) => { + if self.environment.var_exists(ref_ident.as_str()) { + let ref_value = self.fetch(ref_ident).unwrap(); + + self.environment.define(ident.clone(), ref_value.clone()); + } else { + // error + } + }, + _ => { + println!("before: {:?}", self.environment.values); + let mut env = self.environment.clone(); + env.define(ident, value); + self.environments.remove(&self.environment.id); + self.environments.insert(env.id, env); + println!("after: {:?}", self.environment.values); + } + } + }, + Command::EnterBlock => { + println!("{:#?}", self.environments); + self.new_env(); + }, // create new env + Command::ExitBlock => { + self.destroy_env(); + }, // destroy env + Command::EOI => { + // println!("{:#?}", self.environments); + }, } } } + + + + + +// impl Interpreter { +// pub fn new(tree: File) -> Self { +// Self { tree: tree } +// } + +// pub fn interpret(&mut self) { +// let mut nodes = self.tree.nodes.borrow_mut(); +// while !nodes.is_empty() { +// let instr = nodes.pop_front().unwrap(); +// match instr { +// Node::Call { ident, args } => { +// println!("- call {:?} with {:?}", ident, args); +// if ident == String::from("print") { +// println!("{args:#?}"); +// } +// } +// Node::VarDecl { ident, value } => { +// println!("- var decl {:?} as {:?}", ident, value); +// } +// Node::VarReassign { ident, value } => { +// println!("- var reassign {:?} as {:?}", ident, value); +// } + +// Node::EOI => {} // terminate +// }; +// } +// } +// } + // fn execute_builtin(&self, var_store: &HashMap, builtin_ident: String, args: Args) { // match builtin_ident.as_str() { // "println" => { diff --git a/src/lib.rs b/src/lib.rs index b2fcaa5..f0079be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,8 @@ use std::collections::LinkedList; use pest::Parser; use stopwatch::Stopwatch; -use crate::interp::Interpreter; +use crate::ast::{AST, Node}; +use crate::interp::{Command, Interpreter}; use crate::parser::{LemParser, Rule}; pub mod ast; @@ -18,18 +19,52 @@ pub fn execute_script(script: &String) { parse_sw.stop(); // println!("{tree:#?}"); + let ast = AST::new(tree).parse_tree(); + // println!("{ast:#?}"); + + let mut commands = Vec::new(); - Interpreter::new(crate::ast::AST::new(tree).parse_tree()).interpret(); + let mut nodes = ast.nodes.borrow_mut(); + while !nodes.is_empty() { + let instr = nodes.pop_front().unwrap(); + match instr { + Node::Call { ident, args} => { + commands.push(Command::Call { ident: ident, args: args }); + }, + Node::VarDecl { ident, value } => { + commands.push(Command::VarDecl { ident: ident, value: value }); + }, + Node::VarReassign { ident, value } => { + commands.push(Command::VarReassign { ident: ident, value: value }); + }, + Node::EnterBlock => commands.push(Command::EnterBlock), + Node::ExitBlock => commands.push(Command::ExitBlock), + Node::EOI => { + commands.push(Command::EOI); + }, + } + } + + let mut interpreter = Interpreter::new(); + + println!("{commands:#?}"); + for command in commands { + interpreter.interpret(command); + } - // let mut ast_sw = Stopwatch::start_new(); - // let syntax_tree = SyntaxTree::new(tree); - // ast_sw.stop(); - // println!("{syntax_tree:#?}"); + //let mut nodes = self.tree.nodes.borrow_mut(); +// while !nodes.is_empty() { +// let instr = nodes.pop_front().unwrap(); +// match instr { +// Node::Call { ident, args } => { + + // let interpreter = Interpreter::new(); + // let mut ast_sw = Stopwatch::start_new(); + // ast_sw.stop(); + // let mut interp_sw = Stopwatch::start_new(); - // let interpreter = Interpreter; - // interpreter.interpret(syntax_tree); // interp_sw.stop(); println!("\nFinished in {}μs", sw.elapsed().as_micros());