diff --git a/rust/Cargo.lock b/rust/Cargo.lock index c9e2afc3..446d0e2e 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.11" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" +checksum = "96b09b5178381e0874812a9b157f7fe84982617e48f71f4e3235482775e5b540" dependencies = [ "anstyle", "anstyle-parse", @@ -61,9 +61,15 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.79" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1" + +[[package]] +name = "arc-swap" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" [[package]] name = "autocfg" @@ -72,20 +78,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] -name = "block" -version = "0.1.6" +name = "bitflags" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] -name = "cc" -version = "1.0.83" +name = "bstr" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "c48f0051a4b4c5e0b6d365cd04af53aeaa209e3cc15ec2cdb69e73cc87fbd0dc" dependencies = [ - "libc", + "memchr", + "serde", ] +[[package]] +name = "cc" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9fa1897e4325be0d68d48df6aa1a71ac2ed4d27723887e7754192705350730" + [[package]] name = "cfg-if" version = "1.0.0" @@ -94,9 +107,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.5.0" +version = "4.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80c21025abd42669a92efc996ef13cfb2c5c627858421ea58d5c3b331a6c134f" +checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" dependencies = [ "clap_builder", "clap_derive", @@ -104,9 +117,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.0" +version = "4.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "458bf1f341769dfcf849846f65dffdf9146daa56bcd2a47cb4e1de9915567c99" +checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" dependencies = [ "anstream", "anstyle", @@ -148,6 +161,31 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + [[package]] name = "derive" version = "0.1.0" @@ -163,6 +201,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "getrandom" version = "0.2.12" @@ -175,31 +219,95 @@ dependencies = [ ] [[package]] -name = "gettext-rs" -version = "0.7.0" +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "globset" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e49ea8a8fad198aaa1f9655a2524b64b70eb06b2f3ff37da407566c93054f364" +checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" dependencies = [ - "gettext-sys", - "locale_config", + "aho-corasick", + "bstr", + "log", + "regex-automata", + "regex-syntax", ] [[package]] -name = "gettext-sys" -version = "0.21.3" +name = "globwalk" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ce2e00f56a206778276704bbe38564c8695249fdc8f354b4ef71c57c3839d" +checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" dependencies = [ - "cc", - "temp-dir", + "bitflags", + "ignore", + "walkdir", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + [[package]] name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "ignore" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1" +dependencies = [ + "crossbeam-deque", + "globset", + "log", + "memchr", + "regex-automata", + "same-file", + "walkdir", + "winapi-util", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177" +dependencies = [ + "equivalent", + "hashbrown 0.14.3", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + [[package]] name = "lazy_static" version = "1.4.0" @@ -222,6 +330,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "llvm-sys" version = "170.0.1" @@ -237,26 +351,10 @@ dependencies = [ ] [[package]] -name = "locale_config" -version = "0.3.0" +name = "log" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d2c35b16f4483f6c26f0e4e9550717a2f6575bcd6f12a53ff0c490a94a6934" -dependencies = [ - "lazy_static", - "objc", - "objc-foundation", - "regex", - "winapi", -] - -[[package]] -name = "malloc_buf" -version = "0.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" -dependencies = [ - "libc", -] +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "memchr" @@ -264,6 +362,15 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +[[package]] +name = "normpath" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "num-bigint" version = "0.4.4" @@ -294,33 +401,10 @@ dependencies = [ ] [[package]] -name = "objc" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" -dependencies = [ - "malloc_buf", -] - -[[package]] -name = "objc-foundation" -version = "0.1.1" +name = "once_cell" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" -dependencies = [ - "block", - "objc", - "objc_id", -] - -[[package]] -name = "objc_id" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" -dependencies = [ - "objc", -] +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "ppv-lite86" @@ -411,11 +495,141 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +[[package]] +name = "rust-i18n" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dcd94370631e5658a0a23635f7f47e43d06a00ad948e0bb5de79b00d85b880c" +dependencies = [ + "globwalk", + "once_cell", + "regex", + "rust-i18n-macro", + "rust-i18n-support", + "smallvec", +] + +[[package]] +name = "rust-i18n-macro" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "355763801dcf287e777e42def7c578410783477b804b1107852119e0b2518396" +dependencies = [ + "glob", + "once_cell", + "proc-macro2", + "quote", + "rust-i18n-support", + "serde", + "serde_json", + "serde_yaml", + "syn", +] + +[[package]] +name = "rust-i18n-support" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "399801f4d955abf1c3ce3ce2215dc76bd40beb4ae39e3a84936b21a79ce2caa5" +dependencies = [ + "arc-swap", + "globwalk", + "lazy_static", + "normpath", + "once_cell", + "proc-macro2", + "regex", + "serde", + "serde_json", + "serde_yaml", + "toml", + "triomphe", +] + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "semver" -version = "1.0.21" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_yaml" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578a7433b776b56a35785ed5ce9a7e777ac0598aac5a6dd1b4b18a307c7fc71b" +dependencies = [ + "indexmap 1.9.3", + "ryu", + "serde", + "yaml-rust", +] + +[[package]] +name = "smallvec" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "stdlib" @@ -429,9 +643,9 @@ checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb" dependencies = [ "proc-macro2", "quote", @@ -439,10 +653,47 @@ dependencies = [ ] [[package]] -name = "temp-dir" -version = "0.1.12" +name = "sys-locale" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd16aa9ffe15fe021c6ee3766772132c6e98dfa395a167e16864f61a9cfb71d6" +checksum = "e801cf239ecd6ccd71f03d270d67dd53d13e90aab208bf4b8fe4ad957ea949b0" +dependencies = [ + "libc", +] + +[[package]] +name = "toml" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap 2.2.3", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] [[package]] name = "trc" @@ -452,12 +703,24 @@ dependencies = [ "colored", "derive", "downcast-rs", - "gettext-rs", "libloading", "llvm-sys", "num-bigint", "rand", + "rust-i18n", "stdlib", + "sys-locale", +] + +[[package]] +name = "triomphe" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3" +dependencies = [ + "arc-swap", + "serde", + "stable_deref_trait", ] [[package]] @@ -472,6 +735,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "walkdir" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -494,6 +767,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -515,7 +797,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.3", ] [[package]] @@ -535,17 +817,17 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "d380ba1dc7187569a8a9e91ed34b8ccfc33123bbacb8c0aed2d1ad7f3ef2dc5f" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm 0.52.3", + "windows_aarch64_msvc 0.52.3", + "windows_i686_gnu 0.52.3", + "windows_i686_msvc 0.52.3", + "windows_x86_64_gnu 0.52.3", + "windows_x86_64_gnullvm 0.52.3", + "windows_x86_64_msvc 0.52.3", ] [[package]] @@ -556,9 +838,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "68e5dcfb9413f53afd9c8f86e56a7b4d86d9a2fa26090ea2dc9e40fba56c6ec6" [[package]] name = "windows_aarch64_msvc" @@ -568,9 +850,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "8dab469ebbc45798319e69eebf92308e541ce46760b49b18c6b3fe5e8965b30f" [[package]] name = "windows_i686_gnu" @@ -580,9 +862,9 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "2a4e9b6a7cac734a8b4138a4e1044eac3404d8326b6c0f939276560687a033fb" [[package]] name = "windows_i686_msvc" @@ -592,9 +874,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "28b0ec9c422ca95ff34a78755cfa6ad4a51371da2a5ace67500cf7ca5f232c58" [[package]] name = "windows_x86_64_gnu" @@ -604,9 +886,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "704131571ba93e89d7cd43482277d6632589b18ecf4468f591fbae0a8b101614" [[package]] name = "windows_x86_64_gnullvm" @@ -616,9 +898,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "42079295511643151e98d61c38c0acc444e52dd42ab456f7ccfd5152e8ecf21c" [[package]] name = "windows_x86_64_msvc" @@ -628,6 +910,24 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0770833d60a970638e989b3fa9fd2bb1aaadcf88963d1659fd7d9990196ed2d6" + +[[package]] +name = "winnow" +version = "0.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] diff --git a/rust/Cargo.toml b/rust/Cargo.toml index b082f1a9..646ca84e 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -11,8 +11,7 @@ repository = "https://github.com/limuy2022/trc" [dependencies] rand = "0.8.5" -clap = { version = "4.5.0", features = ["derive"] } -gettext-rs = "0.7.0" +clap = { version = "4.5.1", features = ["derive"] } colored = "2.1.0" downcast-rs = "1.2.0" num-bigint = "0.4.4" @@ -20,6 +19,8 @@ llvm-sys = "170.0.1" derive = { path = "./derive" } libloading = "0.8.1" stdlib = { path = "./stdlib" } +rust-i18n = "3.0.1" +sys-locale = "0.3.1" [profile.release] panic = "abort" @@ -29,3 +30,15 @@ strip = true [workspace] members = ["derive", ".", "stdlib"] + +[package.metadata.i18n] +# The available locales for your application, default: ["en"]. +available-locales = ["en", "zh-CN"] + +# The default locale, default: "en". +default-locale = "en" + +# Path for your translations YAML file, default: "locales". +# This config for let `cargo i18n` command line tool know where to find your translations. +# You must keep this path same as the one you pass to method `rust_i18n::i18n!`. +load-path = "locales" diff --git a/rust/examples/print.trc b/rust/examples/print.trc new file mode 100644 index 00000000..fa3fa0be --- /dev/null +++ b/rust/examples/print.trc @@ -0,0 +1 @@ +print("{},{}!", "hello", "world") diff --git a/rust/locales/en.toml b/rust/locales/en.toml new file mode 100644 index 00000000..c71349bf --- /dev/null +++ b/rust/locales/en.toml @@ -0,0 +1,51 @@ +[tshell] +welcome = "Welcome to tshell.Type help() to get more infomation" + +[compiler] +ZeroDivisionError = "ZeroDivisionError" +NumberOverFlowError = "NumberOverFlowError" +ArgumentError = "ArgumentError" +FormatStringError = "FormatStringError" +SymbolError = "SymbolError" +TypeError = "TypeError" +OperatorError = "OperatorError" +VmError = "VmError" +SyntaxError = "SyntaxError" + +[compiler.syntaxerror] +str_error = "this string should be ended with \"" +unmatched = "%{0} is unmatched" +prefix_float = "Prefix %{0} can be used for float" +unexpected_token = "token %{0} is not expected" +unclosed_comment = "unclosed comment" +char_error = "char should be the format like 'x'." + +[compiler.symbolerror] +not_found_sym = "Symbol %{0} not found" +redefined_sym = "Symbol %{0} redefined" + +[compiler.argumenterror] +argu_num = "expect %{0}.But given %{1}" +type_unmatched = "Expect type %{0}.But given type %{1}" +void_argu = "argument cannot be 'void'" + +[compiler.formatstringerror] +unclosed_format = "unmatched {" + +[compiler.typerror] +operator_unsupport = "operator %{0} is not supported for type %{1}" +type_not_same = "Type %{0} and %{1} are not the same" + +[compiler.report] +in_module = "In module %{name}" +error_in_line = "Error in line %{line}" + +[compiler.numberoverflowerror] +float_over_flow = "Float %{0} is too large to store" + +[vm.vmerror] +data_num_error = "The number of data of vm stack is not correct, should have %{0} data" +stack_frame_empty = "frame stack is empty.But running a pop frame opcode" + +[vm.zerodivisionerror] +zerodiv = "%{0} is divided by zero" diff --git a/rust/locales/zh-CN.toml b/rust/locales/zh-CN.toml new file mode 100644 index 00000000..651c6b11 --- /dev/null +++ b/rust/locales/zh-CN.toml @@ -0,0 +1,51 @@ +[tshell] +welcome = "欢迎使用tshell。输入help()获取更多信息" + +[compiler] +NumberOverFlowError = "数值溢出错误" +FormatStringError = "格式化字符串错误" +SymbolError = "符号错误" +TypeError = "类型错误" +ZeroDivisionError = "除零错误" +VmError = "虚拟机错误" +ArgumentError = "参数错误" +SyntaxError = "语法错误" +OperatorError = "操作符错误" + +[compiler.syntaxerror] +unmatched = "%{0}未匹配" +char_error = "字符应当以类似'x'的格式书写." +str_error = "这个字符串应当以\"结束" +unclosed_comment = "未闭合的注释" +prefix_float = "前缀%{0}不能对浮点数使用" +unexpected_token = "token %{0}不是被期望的" + +[compiler.symbolerror] +not_found_sym = "未找到符号%{0}" +redefined_sym = "符号%{0}重定义" + +[compiler.argumenterror] +void_argu = "参数不能为void" +type_unmatched = "期望类型%{0}.但是传入类型是%{1}" +argu_num = "期望%{0}个参数.但是输入%{1}个参数" + +[compiler.formatstringerror] +unclosed_format = "{未匹配" + +[compiler.typerror] +operator_unsupport = "操作符%{0}不支持类型%{1}" +type_not_same = "类型%{0}和%{1}不同" + +[compiler.report] +error_in_line = "错误在第%{line}行" +in_module = "在模块%{name}中" + +[compiler.numberoverflowerror] +float_over_flow = "浮点数%{0}超过了储存范围" + +[vm.vmerror] +data_num_error = "虚拟机栈中数据数量不正确,期望有%{0}个数据" +stack_frame_empty = "帧栈为空,但运行了pop frame指令" + +[vm.zerodivisionerror] +zerodiv = "%{0}被零除" diff --git a/rust/locales/zh_CN/LC_MESSAGES/trans.mo b/rust/locales/zh_CN/LC_MESSAGES/trans.mo deleted file mode 100644 index 48156718..00000000 Binary files a/rust/locales/zh_CN/LC_MESSAGES/trans.mo and /dev/null differ diff --git a/rust/locales/zh_CN/LC_MESSAGES/trans.po b/rust/locales/zh_CN/LC_MESSAGES/trans.po deleted file mode 100644 index 4eff2fd6..00000000 --- a/rust/locales/zh_CN/LC_MESSAGES/trans.po +++ /dev/null @@ -1,94 +0,0 @@ -msgid "" -msgstr "" -"Content-Type: text/plain; charset=UTF-8\n" - -msgid "Welcome to tshell.Type help() to get more infomation" -msgstr "欢迎使用tshell。输入help()获取更多信息" - -msgid "SyntaxError" -msgstr "语法错误" - -msgid "OperatorError" -msgstr "操作符错误" - -msgid "VmError" -msgstr "虚拟机错误" - -msgid "this string should be ended with {}" -msgstr "这个字符串应当以{}结束" - -msgid "operator {} is not supported for type {}" -msgstr "操作符{}不支持类型{}" - -msgid "The number of data of vm stack is not correct, should have {} data" -msgstr "虚拟机栈中数据数量不正确,期望有{}个数据" - -msgid "{} is unmatched" -msgstr "{}未匹配" - -msgid "ZeroDivisionError" -msgstr "除零错误" - -msgid "{} is divided by zero" -msgstr "{}被零除" - -msgid "frame stack is empty.But running a pop frame opcode" -msgstr "帧栈为空,但运行了pop frame指令" - -msgid "Prefix {} can be used for float" -msgstr "前缀{}不能对浮点数使用" - -msgid "NumberOverFlowError" -msgstr "数值溢出错误" - -msgid "Float {} is too large to store" -msgstr "浮点数{}超过了储存范围" - -msgid "token {} is not expected" -msgstr "token {}不是被期望的" - -msgid "In module {}" -msgstr "在模块{}中" - -msgid "Error in line {}" -msgstr "错误在第{}行" - -msgid "SymbolError" -msgstr "符号错误" - -msgid "Symbol {} not found" -msgstr "未找到符号{}" - -msgid "Symbol {} redefined" -msgstr "符号{}重定义" - -msgid "Only support Linux.Users on other platforms should update program by hand" -msgstr "仅支持在linux上直接更新文件.其他操作系统用户请自行更新程序" - -msgid "TypeError" -msgstr "类型错误" - -msgid "Type {} and {} are not the same" -msgstr "类型{}和{}不同" - -msgid "ArgumentError" -msgstr "参数错误" - -msgid "expect {}.But given {}" -msgstr "期望{}.但是输入{}" - -msgid "Expect type {}.But given type {}" -msgstr "期望类型{}.但是传入类型是{}" - -msgid "unclosed comment" -msgstr "未闭合的注释" - -msgid "FormatStringError" -msgstr "格式化字符串错误" - -msgid "{ is not matched." -msgstr "{未匹配" - -msgid "char should be the format like 'x'." -msgstr "字符应当以类似'x'的格式书写." - diff --git a/rust/script/gen_locales.py b/rust/script/gen_locales.py deleted file mode 100644 index 193f5b7c..00000000 --- a/rust/script/gen_locales.py +++ /dev/null @@ -1,21 +0,0 @@ -""" -A easy script for auto generate the locales files -""" - -import os -import sys - -os.chdir("../locales") -tt = os.listdir(".") -for i in tt: - os.chdir(i) - os.chdir("LC_MESSAGES") - subdirs = os.listdir() - for j in subdirs: - tmp = os.path.splitext(j) - if tmp[1] != ".po": - continue - if os.system(f"msgfmt -o {tmp[0]}.mo {j}"): - print("Cannot generate your locales files.Stop.") - sys.exit(1) - os.chdir("../..") diff --git a/rust/src/base/codegen.rs b/rust/src/base/codegen.rs index 14b369d4..7db9ca5c 100644 --- a/rust/src/base/codegen.rs +++ b/rust/src/base/codegen.rs @@ -146,10 +146,12 @@ pub enum VmStackType { Object, } +pub type InstSet = Vec; + #[derive(Default)] pub struct StaticData { pub constpool: ConstPool, - pub inst: Vec, + pub inst: InstSet, pub funcs: Vec, pub sym_table_sz: usize, pub line_table: Vec, diff --git a/rust/src/base/error.rs b/rust/src/base/error.rs index 87711070..af05ed43 100644 --- a/rust/src/base/error.rs +++ b/rust/src/base/error.rs @@ -1,38 +1,38 @@ use colored::Colorize; -use gettextrs::gettext; +use rust_i18n::t; use std::error::Error; use std::fmt::{Debug, Display}; -pub const SYNTAX_ERROR: &str = "SyntaxError"; -pub const OPERATOR_ERROR: &str = "OperatorError"; -pub const VM_ERROR: &str = "VmError"; -pub const ZERO_DIVSION_ERROR: &str = "ZeroDivisionError"; -pub const NUMBER_OVER_FLOW: &str = "NumberOverFlowError"; -pub const SYMBOL_ERROR: &str = "SymbolError"; -pub const TYPE_ERROR: &str = "TypeError"; -pub const ARGUMENT_ERROR: &str = "ArgumentError"; -pub const FORMAT_STR_ERROR: &str = "FormatStringError"; - -pub const STRING_WITHOUT_END: &str = "this string should be ended with {}"; -pub const CHAR_FORMAT: &str = "char should be the format like 'x'."; -pub const UNMATCHED_BRACE: &str = "{} is unmatched"; -pub const OPERATOR_IS_NOT_SUPPORT: &str = "operator {} is not supported for type {}"; -pub const VM_DATA_NUMBER: &str = - "The number of data of vm stack is not correct, should have {} data"; -pub const VM_FRAME_EMPTY: &str = "frame stack is empty.But running a pop frame opcode"; -pub const ZERO_DIV: &str = "{} is divided by zero"; -pub const PREFIX_FOR_FLOAT: &str = "Prefix {} can be used for float"; -pub const FLOAT_OVER_FLOW: &str = "Float {} is too large to store"; -pub const UNEXPECTED_TOKEN: &str = "token {} is not expected"; -pub const ERROR_IN_LINE: &str = "Error in line {}"; -pub const IN_MODULE: &str = "In module {}"; -pub const SYMBOL_NOT_FOUND: &str = "Symbol {} not found"; -pub const SYMBOL_REDEFINED: &str = "Symbol {} redefined"; -pub const TYPE_NOT_THE_SAME: &str = "Type {} and {} are not the same"; -pub const ARGU_NUMBER: &str = "expect {}.But given {}"; -pub const EXPECT_TYPE: &str = "Expect type {}.But given type {}"; -pub const UNCLODED_COMMENT: &str = "unclosed comment"; -pub const UNCLOSED_FORMAT: &str = "{ is not matched."; +pub const SYNTAX_ERROR: &str = "compiler.SyntaxError"; +pub const OPERATOR_ERROR: &str = "compiler.OperatorError"; +pub const VM_ERROR: &str = "compiler.VmError"; +pub const ZERO_DIVSION_ERROR: &str = "compiler.ZeroDivisionError"; +pub const NUMBER_OVER_FLOW: &str = "compiler.NumberOverFlowError"; +pub const SYMBOL_ERROR: &str = "compiler.SymbolError"; +pub const TYPE_ERROR: &str = "compiler.TypeError"; +pub const ARGUMENT_ERROR: &str = "compiler.ArgumentError"; +pub const FORMAT_STR_ERROR: &str = "compiler.FormatStringError"; + +pub const STRING_WITHOUT_END: &str = "compiler.syntaxerror.str_error"; +pub const CHAR_FORMAT: &str = "compiler.syntaxerror.char_error"; +pub const UNMATCHED_BRACE: &str = "compiler.syntaxerror.unmatched"; +pub const OPERATOR_IS_NOT_SUPPORT: &str = "compiler.typerror.operator_unsupport"; +pub const VM_DATA_NUMBER: &str = "vm.vmerror.data_num_error"; +pub const VM_FRAME_EMPTY: &str = "vm.vmerror.stack_frame_empty"; +pub const ZERO_DIV: &str = "vm.zerodivisionerror.zerodiv"; +pub const PREFIX_FOR_FLOAT: &str = "compiler.syntaxerror.prefix_float"; +pub const FLOAT_OVER_FLOW: &str = "compiler.numberoverflowerror.float_over_flow"; +pub const UNEXPECTED_TOKEN: &str = "compiler.syntaxerror.unexpected_token"; +pub const ERROR_IN_LINE: &str = "compiler.report.error_in_line"; +pub const IN_MODULE: &str = "compiler.report.in_module"; +pub const SYMBOL_NOT_FOUND: &str = "compiler.symbolerror.not_found_sym"; +pub const SYMBOL_REDEFINED: &str = "compiler.symbolerror.redefined_sym"; +pub const TYPE_NOT_THE_SAME: &str = "compiler.typerror.type_not_same"; +pub const ARGU_NUMBER: &str = "compiler.argumenterror.argu_num"; +pub const EXPECT_TYPE: &str = "compiler.argumenterror.type_unmatched"; +pub const UNCLODED_COMMENT: &str = "compiler.syntaxerror.unclosed_comment"; +pub const UNCLOSED_FORMAT: &str = "compiler.formatstringerror.unclosed_format"; +pub const ARGUMENT_CANNOT_BE_VOID: &str = "compiler.argumenterror.void_argu"; #[derive(Debug)] pub struct ErrorInfo { @@ -72,9 +72,9 @@ impl Display for RuntimeError { r#"{} {} {}:{}"#, - gettext!(ERROR_IN_LINE, self.content.get_line()), - gettext!(IN_MODULE, self.content.get_module_name()), - gettext(self.info.error_type.clone()).red(), + t!(ERROR_IN_LINE, line = self.content.get_line()), + t!(IN_MODULE, name = self.content.get_module_name()), + self.info.error_type.clone().red(), self.info.message.red() ); write!(f, "{}", s) diff --git a/rust/src/base/stdlib.rs b/rust/src/base/stdlib.rs index efba0e24..064018bd 100644 --- a/rust/src/base/stdlib.rs +++ b/rust/src/base/stdlib.rs @@ -8,6 +8,7 @@ use crate::{ tvm::DynaData, }; use downcast_rs::{impl_downcast, Downcast}; +use rust_i18n::t; use std::sync::OnceLock; use std::{ collections::HashMap, @@ -45,8 +46,8 @@ impl IOType { pub fn check_argvs(&self, argvs: Vec) -> Result<(), ErrorInfo> { if argvs.len() != self.argvs_type.len() { return Err(ErrorInfo::new( - gettextrs::gettext!(ARGU_NUMBER, self.argvs_type.len(), argvs.len()), - gettextrs::gettext(ARGUMENT_ERROR), + t!(ARGU_NUMBER, "0" = self.argvs_type.len(), "1" = argvs.len()), + t!(ARGUMENT_ERROR), )); } for i in argvs.iter().enumerate().take(self.argvs_type.len()) { @@ -55,8 +56,8 @@ impl IOType { } if self.argvs_type[i.0] != *i.1 { return Err(ErrorInfo::new( - gettextrs::gettext!(EXPECT_TYPE, self.argvs_type[i.0], i.1), - gettextrs::gettext(ARGUMENT_ERROR), + t!(EXPECT_TYPE, "0" = self.argvs_type[i.0], "1" = i.1), + t!(ARGUMENT_ERROR), )); } } diff --git a/rust/src/compiler.rs b/rust/src/compiler.rs index bdb5bb10..92505895 100644 --- a/rust/src/compiler.rs +++ b/rust/src/compiler.rs @@ -6,9 +6,11 @@ pub mod llvm_convent; pub mod scope; pub mod token; +use rust_i18n::t; + use self::token::TokenLex; use crate::base::codegen::{ConstPool, StaticData}; -use crate::base::error::{self, RunResult}; +use crate::base::error::*; use crate::cfg; use std::collections::HashMap; use std::fmt::Display; @@ -32,7 +34,7 @@ pub struct Content { line: usize, } -impl error::ErrorContent for Content { +impl ErrorContent for Content { fn get_module_name(&self) -> &str { &self.module_name } @@ -363,6 +365,11 @@ impl Compiler { ast_builder.generate_code()?; Ok(ast_builder.return_static_data()) } + + #[inline] + pub fn report_compiler_error(&self, info: ErrorInfo) -> RunResult { + Err(RuntimeError::new(Box::new(self.content.clone()), info)) + } } mod tests { diff --git a/rust/src/compiler/ast.rs b/rust/src/compiler/ast.rs index ff47013c..48c49a3f 100644 --- a/rust/src/compiler/ast.rs +++ b/rust/src/compiler/ast.rs @@ -1,23 +1,25 @@ use super::token::TokenType; use super::{scope, TokenLex}; use super::{scope::*, InputSource}; -use crate::base::codegen::{Inst, Opcode, VmStackType, NO_ARG}; -use crate::base::func::Func; -use crate::base::stdlib::{get_stdlib, FunctionInterface, RustFunction}; -use crate::base::{codegen::StaticData, error::*}; -use gettextrs::gettext; -use std::borrow::Borrow; -use std::cell::RefCell; -use std::rc::Rc; +use crate::base::{ + codegen::{Inst, Opcode, StaticData, VmStackType, NO_ARG}, + error::*, + stdlib::{get_stdlib, RustFunction}, +}; +use rust_i18n::t; +use std::{cell::RefCell, rc::Rc}; /// 过程间分析用的结构 +#[derive(Default)] struct LexProcess { stack_type: Vec, } impl LexProcess { pub fn new() -> Self { - Self { stack_type: vec![] } + Self { + ..Default::default() + } } pub fn new_type(&mut self, ty: VmStackType) { @@ -46,17 +48,6 @@ pub struct AstBuilder<'a> { type AstError = RunResult; -macro_rules! try_err { - ($istry: expr, $($argvs:expr),*) => { - {if $istry { - Err(LightFakeError::new().into()) - } else { - Err(RuntimeError::new($($argvs),*)) - } - } - }; -} - macro_rules! tmp_expe_function_gen { ($tmpfuncname:ident, $next_item_func:ident, $($accepted_token:path),*) => { fn $tmpfuncname(&mut self, istry: bool, extend: usize) -> AstError { @@ -68,19 +59,17 @@ macro_rules! tmp_expe_function_gen { let func_obj = self.self_scope.as_ref().borrow().get_class(extend).unwrap(); let io_check = func_obj.get_override_func($accepted_token); match io_check { - None => return try_err!(istry, - Box::new(self.token_lexer.compiler_data.content.clone()), + None => self.try_err(istry, ErrorInfo::new( - gettext!(OPERATOR_IS_NOT_SUPPORT, $accepted_token, func_obj.get_name()), - gettext(OPERATOR_ERROR), + t!(OPERATOR_IS_NOT_SUPPORT, "0"=$accepted_token, "1"=func_obj.get_name()), + t!(OPERATOR_ERROR), ) - ), + )?, Some(v) => { if let Ok(_) = v.io.check_argvs(vec![tya]) {} else { - return try_err!(istry, - Box::new(self.token_lexer.compiler_data.content.clone()), - ErrorInfo::new(gettext!(OPERATOR_IS_NOT_SUPPORT, $accepted_token, func_obj.get_name()), gettextrs::gettext(OPERATOR_ERROR))) + self.try_err(istry, + ErrorInfo::new(t!(OPERATOR_IS_NOT_SUPPORT, "0"=$accepted_token, "1"=func_obj.get_name()), t!(OPERATOR_ERROR)))? } } } @@ -126,6 +115,15 @@ macro_rules! expr_gen { } impl<'a> AstBuilder<'a> { + #[inline] + pub fn try_err(&self, istry: bool, info: ErrorInfo) -> AstError { + if istry { + Err(LightFakeError::new().into()) + } else { + self.token_lexer.compiler_data.report_compiler_error(info) + } + } + pub fn new(token_lexer: TokenLex<'a>) -> Self { let prelude = get_stdlib().sub_modules.get("prelude").unwrap(); for i in &prelude.functions { @@ -205,58 +203,64 @@ impl<'a> AstBuilder<'a> { fn check_next_token(&mut self, tp: TokenType) -> AstError<()> { let next_sym = self.token_lexer.next_token()?; if next_sym.tp != tp { - return Err(RuntimeError::new( - Box::new(self.token_lexer.compiler_data.content.clone()), - ErrorInfo::new( - gettext!(UNEXPECTED_TOKEN, next_sym.tp), - gettextrs::gettext(SYNTAX_ERROR), - ), - )); + self.token_lexer + .compiler_data + .report_compiler_error(ErrorInfo::new( + t!(UNEXPECTED_TOKEN, "0" = next_sym.tp), + t!(SYNTAX_ERROR), + ))?; } Ok(()) } + fn add_var_params_bycode(&mut self, var_params_num: usize) { + let tmp = self + .token_lexer + .compiler_data + .const_pool + .add_int(var_params_num as i64); + self.add_bycode(Opcode::LoadInt, tmp); + } + /// 解析出函数参数 fn opt_args(&mut self, lex_func_obj: &scope::Func) -> AstError> { let mut ret = vec![]; let mut var_params_num = 0; let io_tmp = lex_func_obj.get_io(); loop { - let t = self.expr(true); + let t = self.expr(true)?; match t { - Err(_) => { + TypeAllowNull::No => { + self.token_lexer + .compiler_data + .report_compiler_error(ErrorInfo::new( + t!(ARGUMENT_CANNOT_BE_VOID), + t!(ARGUMENT_ERROR), + ))?; + } + TypeAllowNull::Yes(t) => { + // 如果是可变参数是需要将其转入obj_stack的 + if io_tmp.var_params && io_tmp.argvs_type.len() <= ret.len() { + // the values that have been stored is more than exact requirement of function + self.move_val_into_obj_stack(); + var_params_num += 1; + } + ret.push(t) + } + } + let nextt = self.token_lexer.next_token()?; + match nextt.tp { + TokenType::RightSmallBrace => { if io_tmp.var_params { - let tmp = self - .token_lexer - .compiler_data - .const_pool - .add_int(var_params_num); - self.add_bycode(Opcode::LoadInt, tmp); + self.add_var_params_bycode(var_params_num); } + self.token_lexer.next_back(nextt); return Ok(ret); } - Ok(ty) => match ty { - TypeAllowNull::No => { - if io_tmp.var_params { - let tmp = self - .token_lexer - .compiler_data - .const_pool - .add_int(var_params_num); - self.add_bycode(Opcode::LoadInt, tmp); - } - return Ok(ret); - } - TypeAllowNull::Yes(t) => { - // 如果是可变参数是需要将其转入obj_stack的 - if io_tmp.var_params && io_tmp.argvs_type.len() <= ret.len() { - // the values that have been stored is more than exact requirement of function - self.move_val_into_obj_stack(); - var_params_num += 1; - } - ret.push(t) - } - }, + TokenType::Comma => {} + _ => { + self.token_lexer.next_back(nextt); + } } } } @@ -308,17 +312,16 @@ impl<'a> AstBuilder<'a> { let token_data = t.data.unwrap(); let idx = self.self_scope.as_ref().borrow().get_sym_idx(token_data); if idx.is_none() { - return try_err!( + self.try_err( istry, - Box::new(self.token_lexer.compiler_data.content.clone()), ErrorInfo::new( - gettext!( + t!( SYMBOL_NOT_FOUND, - self.token_lexer.compiler_data.const_pool.id_name[token_data] + "0" = self.token_lexer.compiler_data.const_pool.id_name[token_data] ), - gettextrs::gettext(SYMBOL_ERROR), - ) - ); + t!(SYMBOL_ERROR), + ), + )? } let idx = idx.unwrap(); let nxt = self.token_lexer.next_token()?; @@ -339,11 +342,7 @@ impl<'a> AstBuilder<'a> { // 这是为了加速 // 可变参数的话,因为类型不确定,我们会将其生成指令移入obj栈中 if let Err(e) = func_obj.get_io().check_argvs(argv_list) { - return try_err!( - istry, - Box::new(self.token_lexer.compiler_data.content.clone()), - e - ); + self.try_err(istry, e)? } if let Some(obj) = func_obj.downcast_ref::() { self.add_bycode(Opcode::CallNative, obj.buildin_id); @@ -358,14 +357,10 @@ impl<'a> AstBuilder<'a> { } } else { self.token_lexer.next_back(t.clone()); - try_err!( + self.try_err( istry, - Box::new(self.token_lexer.compiler_data.content.clone()), - ErrorInfo::new( - gettext!(UNEXPECTED_TOKEN, t.tp), - gettextrs::gettext(SYNTAX_ERROR), - ) - ) + ErrorInfo::new(t!(UNEXPECTED_TOKEN, "0" = t.tp), t!(SYNTAX_ERROR)), + )? } } @@ -402,14 +397,10 @@ impl<'a> AstBuilder<'a> { } _ => { self.token_lexer.next_back(t.clone()); - try_err!( + self.try_err( istry, - Box::new(self.token_lexer.compiler_data.content.clone()), - ErrorInfo::new( - gettext!(UNEXPECTED_TOKEN, t.tp), - gettextrs::gettext(SYNTAX_ERROR), - ) - ) + ErrorInfo::new(t!(UNEXPECTED_TOKEN, "0" = t.tp), t!(SYNTAX_ERROR)), + )? } } } @@ -435,25 +426,20 @@ impl<'a> AstBuilder<'a> { self.add_bycode(v.opcode.clone(), NO_ARG); Ok(v.io.return_type.clone()) } - Err(e) => { - try_err!( - istry, - Box::new(self.token_lexer.compiler_data.content.clone()), - e - ) - } + Err(e) => self.try_err(istry, e)?, } } - None => { - try_err!( - istry, - Box::new(self.token_lexer.compiler_data.content.clone()), - ErrorInfo::new( - gettext!(OPERATOR_IS_NOT_SUPPORT, optoken, class_obj.get_name()), - gettext(OPERATOR_ERROR), - ) - ) - } + None => self.try_err( + istry, + ErrorInfo::new( + t!( + OPERATOR_IS_NOT_SUPPORT, + "0" = optoken, + "1" = class_obj.get_name() + ), + t!(OPERATOR_ERROR), + ), + )?, } } @@ -500,14 +486,10 @@ impl<'a> AstBuilder<'a> { fn import_module(&mut self, istry: bool) -> AstError<()> { let path = self.token_lexer.next_token()?; if path.tp != TokenType::StringValue { - return try_err!( + self.try_err( istry, - Box::new(self.token_lexer.compiler_data.content.clone()), - ErrorInfo::new( - gettext!(UNEXPECTED_TOKEN, path.tp), - gettextrs::gettext(SYNTAX_ERROR), - ) - ); + ErrorInfo::new(t!(UNEXPECTED_TOKEN, "0" = path.tp), t!(SYNTAX_ERROR)), + )? } let path = std::path::PathBuf::from( self.token_lexer.compiler_data.const_pool.id_str[path.data.unwrap()] @@ -553,11 +535,12 @@ impl<'a> AstBuilder<'a> { return Err(RuntimeError::new( Box::new(self.token_lexer.compiler_data.content.clone()), ErrorInfo::new( - gettext!( + t!( SYMBOL_NOT_FOUND, - self.token_lexer.compiler_data.const_pool.id_name[name] + "0" = + self.token_lexer.compiler_data.const_pool.id_name[name] ), - gettext(SYMBOL_ERROR), + t!(SYMBOL_ERROR), ), )); } @@ -570,11 +553,12 @@ impl<'a> AstBuilder<'a> { return Err(RuntimeError::new( Box::new(self.token_lexer.compiler_data.content.clone()), ErrorInfo::new( - gettext!( + t!( SYMBOL_REDEFINED, - self.token_lexer.compiler_data.const_pool.id_name[name] + "0" = + self.token_lexer.compiler_data.const_pool.id_name[name] ), - gettext(SYMBOL_ERROR), + t!(SYMBOL_ERROR), ), )); } @@ -623,7 +607,7 @@ impl<'a> AstBuilder<'a> { #[cfg(test)] mod tests { use super::*; - use crate::compiler::{Compiler, INT_VAL_POOL_ONE}; + use crate::compiler::{Compiler, INT_VAL_POOL_ONE, INT_VAL_POOL_ZERO}; macro_rules! gen_test_env { ($test_code:expr, $env_name:ident) => { @@ -759,6 +743,7 @@ mod tests { t.staticdata.inst, vec![ Inst::new(Opcode::LoadString, 0), + Inst::new(Opcode::LoadInt, INT_VAL_POOL_ZERO), Inst::new( Opcode::CallNative, get_stdlib() @@ -833,4 +818,31 @@ if 8 == 7 { ] ) } + + #[test] + fn test_var_params() { + gen_test_env!(r#"print("{}{}{}", 1, 2, 3)"#, t); + t.generate_code().unwrap(); + assert_eq!( + t.staticdata.inst, + vec![ + Inst::new(Opcode::LoadString, 0), + Inst::new(Opcode::LoadInt, INT_VAL_POOL_ONE), + Inst::new(Opcode::LoadInt, 2), + Inst::new(Opcode::LoadInt, 3), + Inst::new(Opcode::LoadInt, 3), + Inst::new( + Opcode::CallNative, + get_stdlib() + .sub_modules + .get("prelude") + .unwrap() + .functions + .get("print") + .unwrap() + .buildin_id + ), + ] + ) + } } diff --git a/rust/src/compiler/scope.rs b/rust/src/compiler/scope.rs index 1f5e9acb..042886c5 100644 --- a/rust/src/compiler/scope.rs +++ b/rust/src/compiler/scope.rs @@ -1,13 +1,14 @@ -use super::ValuePool; +use super::{token::ConstPoolIndexTy, ValuePool}; use crate::base::stdlib::{ get_stdclass_end, get_stdlib, ClassInterface, FunctionInterface, IOType, OverrideWrapper, Stdlib, STD_CLASS_TABLE, }; use std::{cell::RefCell, collections::HashMap, fmt::Display, rc::Rc}; +pub type ScopeAllocIdTy = usize; #[derive(Clone, Debug)] pub enum TypeAllowNull { - Yes(usize), + Yes(ScopeAllocIdTy), No, } @@ -75,7 +76,7 @@ pub type Type = Box; pub type Func = Box; /// Manager of type -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct CommonType { attr: Vec, funcs: Vec, @@ -92,10 +93,9 @@ impl Display for CommonType { impl CommonType { pub fn new(name: usize, origin_name: impl Into) -> Self { Self { - attr: vec![], - funcs: vec![], name, origin_name: origin_name.into(), + ..Default::default() } } @@ -140,30 +140,31 @@ impl ClassInterface for CommonType { } } +pub type ScopeAllocClassId = usize; + +#[derive(Default)] pub struct SymScope { + //父作用域 prev_scope: Option>>, - sym_map: HashMap, - scope_sym_id: usize, - types: HashMap, - funcs: HashMap>, - vars: HashMap, - modules: HashMap, - types_id: usize, - types_custom_store: HashMap, + // 管理符号之间的映射,由token在name pool中的id映射到符号表中的id + sym_map: HashMap, + // 当前作用域要分配的下一个ID,也就是当前作用域的最大id+1 + scope_sym_id: ScopeAllocIdTy, + types: HashMap, + funcs: HashMap>, + // token id + vars: HashMap, + // 由token id到模块的映射 + modules: HashMap, + types_id: ScopeAllocClassId, + types_custom_store: HashMap, } impl SymScope { pub fn new(prev_scope: Option>>) -> Self { let mut ret = Self { prev_scope: prev_scope.clone(), - sym_map: HashMap::new(), - scope_sym_id: 0, - types: HashMap::new(), - funcs: HashMap::new(), - vars: HashMap::new(), - modules: HashMap::new(), - types_custom_store: HashMap::new(), - types_id: 0, + ..Default::default() }; match prev_scope { Some(prev_scope) => { @@ -176,7 +177,7 @@ impl SymScope { } /// import the module defined in rust - pub fn import_native_module(&mut self, id: usize, stdlib: &'static Stdlib) { + pub fn import_native_module(&mut self, id: ScopeAllocIdTy, stdlib: &'static Stdlib) { self.modules.insert(id, stdlib); } @@ -199,7 +200,7 @@ impl SymScope { match self.funcs.get(&id) { Some(f) => Some(f.clone()), None => match self.prev_scope { - Some(ref prev) => return prev.as_ref().borrow().get_function(id), + Some(ref prev) => prev.as_ref().borrow().get_function(id), None => None, }, } @@ -209,10 +210,10 @@ impl SymScope { if self.sym_map.contains_key(&id) { return true; } - return match self.prev_scope { + match self.prev_scope { Some(ref prev_scope) => prev_scope.as_ref().borrow().has_sym(id), None => false, - }; + } } pub fn new_id(&mut self) -> usize { @@ -231,13 +232,13 @@ impl SymScope { pub fn get_sym_idx(&self, id: usize) -> Option { let t = self.sym_map.get(&id); - return match t { + match t { None => match self.prev_scope { Some(ref prev_scope) => prev_scope.as_ref().borrow().get_sym_idx(id), None => None, }, Some(t) => Some(*t), - }; + } } pub fn add_func(&mut self, id: usize, f: Box) { @@ -253,7 +254,7 @@ impl SymScope { } pub fn get_type(&self, id: usize) -> usize { - return *self.types.get(&id).unwrap(); + *self.types.get(&id).unwrap() } pub fn get_scope_last_idx(&self) -> usize { @@ -272,13 +273,13 @@ impl SymScope { return None; } let t = self.types.get(&classid); - return match t { + match t { Some(t) => Some(Box::new(self.types_custom_store.get(t).unwrap().clone())), None => match self.prev_scope { Some(ref prev_scope) => prev_scope.as_ref().borrow().get_class(classid), None => None, }, - }; + } } } diff --git a/rust/src/compiler/token.rs b/rust/src/compiler/token.rs index 8e3f3a13..00695303 100644 --- a/rust/src/compiler/token.rs +++ b/rust/src/compiler/token.rs @@ -7,7 +7,7 @@ use crate::{ cfg::FLOAT_OVER_FLOW_LIMIT, hash_map, }; -use gettextrs::gettext; +use rust_i18n::t; use std::{collections::HashMap, fmt::Display, process::exit, sync::OnceLock}; #[derive(PartialEq, Debug, Clone, Hash, Eq)] @@ -131,6 +131,8 @@ pub enum TokenType { EndOfFile, } +pub type ConstPoolIndexTy = usize; + impl Display for TokenType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let res = match self { @@ -244,8 +246,8 @@ macro_rules! check_braces_match { return Err(error::RuntimeError::new( Box::new(Content::new_line(&$sself.compiler_data.content.module_name, $brace_record.line)), ErrorInfo::new( - gettext!(error::UNMATCHED_BRACE, $brace_record.c), - gettext(error::SYNTAX_ERROR), + t!(error::UNMATCHED_BRACE, "0"=$brace_record.c), + t!(error::SYNTAX_ERROR), ), )); } @@ -305,7 +307,7 @@ impl TokenLex<'_> { match top { None => Err(RuntimeError::new( Box::new(self.compiler_data.content.clone()), - ErrorInfo::new(gettext!(error::UNMATCHED_BRACE, c), gettext(SYNTAX_ERROR)), + ErrorInfo::new(t!(error::UNMATCHED_BRACE, "0" = c), t!(SYNTAX_ERROR)), )), Some(cc) => { check_braces_match!(self, c, cc, @@ -458,7 +460,7 @@ impl TokenLex<'_> { } else if c == '\0' { return Err(RuntimeError::new( Box::new(self.compiler_data.content.clone()), - ErrorInfo::new(gettext(UNCLODED_COMMENT), gettext(SYNTAX_ERROR)), + ErrorInfo::new(t!(UNCLODED_COMMENT), t!(SYNTAX_ERROR)), )); } else if c == '\n' { self.compiler_data.content.add_line(); @@ -564,8 +566,11 @@ impl TokenLex<'_> { return Err(RuntimeError::new( Box::new(self.compiler_data.content.clone()), ErrorInfo::new( - gettext!(PREFIX_FOR_FLOAT, get_redix_to_prefix()[&(radix as usize)]), - gettext(SYNTAX_ERROR), + t!( + PREFIX_FOR_FLOAT, + "0" = get_redix_to_prefix()[&(radix as usize)] + ), + t!(SYNTAX_ERROR), ), )); } @@ -577,8 +582,8 @@ impl TokenLex<'_> { return Err(RuntimeError::new( Box::new(self.compiler_data.content.clone()), ErrorInfo::new( - gettext!(FLOAT_OVER_FLOW, format!("{intpart}.{float_part}")), - gettext(NUMBER_OVER_FLOW), + t!(FLOAT_OVER_FLOW, "0" = format!("{intpart}.{float_part}")), + t!(NUMBER_OVER_FLOW), ), )); } @@ -737,10 +742,7 @@ impl TokenLex<'_> { if c == '\0' { RuntimeError::new( Box::new(self.compiler_data.content.clone()), - ErrorInfo::new( - gettext!(error::STRING_WITHOUT_END, '"'), - gettext(SYNTAX_ERROR), - ), + ErrorInfo::new(t!(error::STRING_WITHOUT_END), t!(SYNTAX_ERROR)), ); } } @@ -756,7 +758,7 @@ impl TokenLex<'_> { if end != '\'' { return Err(RuntimeError::new( Box::new(self.compiler_data.content.clone()), - ErrorInfo::new(gettext(CHAR_FORMAT), gettext(SYNTAX_ERROR)), + ErrorInfo::new(t!(CHAR_FORMAT), t!(SYNTAX_ERROR)), )); } Ok(Token::new(TokenType::CharValue, Some(c as usize))) @@ -822,8 +824,8 @@ impl TokenLex<'_> { unmatch_char.line, )), ErrorInfo::new( - gettext!(error::UNMATCHED_BRACE, unmatch_char.c), - gettext(SYNTAX_ERROR), + t!(error::UNMATCHED_BRACE, "0" = unmatch_char.c), + t!(SYNTAX_ERROR), ), )); } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 482f6fe6..31359a57 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -7,6 +7,7 @@ pub mod tvm; use clap::{self, Parser, Subcommand}; use std::error::Error; +rust_i18n::i18n!("locales"); #[derive(Debug, Parser)] #[command( author = "limuy", diff --git a/rust/src/main.rs b/rust/src/main.rs index 6a964a7c..3079b9b7 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -1,9 +1,8 @@ +use rust_i18n::t; use trc::run; fn main() -> Result<(), Box> { - gettextrs::setlocale(gettextrs::LocaleCategory::LcAll, ""); - gettextrs::bindtextdomain("trans", "locales")?; - gettextrs::textdomain("trans")?; + rust_i18n::set_locale(&sys_locale::get_locale().unwrap()); run().unwrap(); Ok(()) } diff --git a/rust/src/tools/tshell.rs b/rust/src/tools/tshell.rs index 61bdbcab..60978fc2 100644 --- a/rust/src/tools/tshell.rs +++ b/rust/src/tools/tshell.rs @@ -1,16 +1,13 @@ //! the read execute print loop for trc use colored::*; -use gettextrs::gettext; +use rust_i18n::t; use std::io::{self, Write}; fn get_block() {} pub fn tshell() { - println!( - "{}\n\n", - gettext("Welcome to tshell.Type help() to get more infomation").bold() - ); + println!("{}\n\n", t!("tshell.welcome").bold()); loop { print!("tshell>"); io::stdout().flush().unwrap(); diff --git a/rust/src/tools/update.rs b/rust/src/tools/update.rs index 89001706..4059cee9 100644 --- a/rust/src/tools/update.rs +++ b/rust/src/tools/update.rs @@ -1,4 +1,3 @@ -use gettextrs::gettext; use std::{error::Error, fmt::Display}; static GITHUB_API_URL: &str = "http://185.106.176.199/trc_version"; @@ -17,7 +16,7 @@ impl Display for UpdateError { write!( f, "{}", - gettext("Only support Linux.Users on other platforms should update program by hand") + ("Only support Linux.Users on other platforms should update program by hand") ) } } diff --git a/rust/src/tvm.rs b/rust/src/tvm.rs index ca70451b..744ba066 100644 --- a/rust/src/tvm.rs +++ b/rust/src/tvm.rs @@ -12,8 +12,8 @@ use self::types::{TrcBool, TrcChar, TrcObj}; use crate::base::codegen::{self, Opcode, StaticData}; use crate::base::stdlib::STD_FUNC_TABLE; use crate::{base::error::*, cfg}; -use gettextrs::gettext; use libloading::Library; +use rust_i18n::t; #[derive(Default)] pub struct DynaData<'a> { @@ -36,8 +36,8 @@ impl<'a> DynaData<'a> { pub fn check_stack(obj: &[T], require: usize) -> RuntimeResult<()> { if obj.len() < require { return Err(ErrorInfo::new( - gettext!(VM_DATA_NUMBER, require), - gettext(VM_ERROR), + t!(VM_DATA_NUMBER, "0" = require), + t!(VM_ERROR), )); } Ok(()) @@ -223,7 +223,7 @@ impl<'a> Vm<'a> { if ret.is_none() { return Err(RuntimeError::new( Box::new(self.run_contnet.clone()), - ErrorInfo::new(gettext(VM_FRAME_EMPTY), gettext(VM_ERROR)), + ErrorInfo::new(t!(VM_FRAME_EMPTY), t!(VM_ERROR)), )); } } diff --git a/rust/src/tvm/stdlib/prelude.rs b/rust/src/tvm/stdlib/prelude.rs index 03a7b2f5..080ab2f2 100644 --- a/rust/src/tvm/stdlib/prelude.rs +++ b/rust/src/tvm/stdlib/prelude.rs @@ -1,10 +1,9 @@ -use std::io::{self, Write}; - use super::super::types::*; use crate::base::stdlib::*; use crate::{base::error::*, tvm::DynaData}; use derive::{def_module, trc_function}; -use gettextrs::gettext; +use rust_i18n::t; +use std::io::{self, Write}; #[trc_function(var_params = true)] pub fn print(fmt_string: str) -> void { @@ -17,10 +16,7 @@ pub fn print(fmt_string: str) -> void { .unwrap(); if let Some(j) = output_iter.next() { if j != '}' { - return Err(ErrorInfo::new( - gettext(UNCLOSED_FORMAT), - gettext(FORMAT_STR_ERROR), - )); + return Err(ErrorInfo::new(t!(UNCLOSED_FORMAT), t!(FORMAT_STR_ERROR))); } } } else { @@ -40,10 +36,7 @@ pub fn println(fmt_string: str) -> void { .unwrap(); if let Some(j) = output_iter.next() { if j != '}' { - return Err(ErrorInfo::new( - gettext(UNCLOSED_FORMAT), - gettext(FORMAT_STR_ERROR), - )); + return Err(ErrorInfo::new(t!(UNCLOSED_FORMAT), t!(FORMAT_STR_ERROR))); } } } else { diff --git a/rust/src/tvm/types.rs b/rust/src/tvm/types.rs index 6f226986..ac59f4ca 100644 --- a/rust/src/tvm/types.rs +++ b/rust/src/tvm/types.rs @@ -1,9 +1,8 @@ -use std::fmt::Debug; - use crate::base::error::*; use crate::tvm::DynaData; use downcast_rs::{impl_downcast, Downcast}; -use gettextrs::gettext; +use rust_i18n::t; +use std::fmt::Debug; pub mod data_structure; pub mod trcbigint; @@ -25,12 +24,12 @@ macro_rules! batch_unsupported_operators { $( fn $traie_name(&self, _:Box) -> RuntimeResult> { return Err(ErrorInfo::new( - gettext!( + t!( OPERATOR_IS_NOT_SUPPORT, - $oper_name, - self.get_type_name() + "0"=$oper_name, + "1"=self.get_type_name() ), - gettext(SYNTAX_ERROR), + t!(SYNTAX_ERROR), )); })* }; @@ -46,7 +45,7 @@ macro_rules! impl_oper { return Ok(Box::new($newtype::new($oper(self._value.clone(), v._value.clone())$whether_throw_error))); }, None => { - return Err(ErrorInfo::new(gettext!(OPERATOR_IS_NOT_SUPPORT, $error_oper_name, other.get_type_name()), gettext(OPERATOR_ERROR))) + return Err(ErrorInfo::new(t!(OPERATOR_IS_NOT_SUPPORT, "0"=$error_oper_name, "1"=other.get_type_name()), t!(OPERATOR_ERROR))) } } } @@ -59,7 +58,7 @@ macro_rules! impl_oper { return Ok(Box::new($newtype::new(self._value $oper v._value))); }, None => { - return Err(ErrorInfo::new(gettext!(OPERATOR_IS_NOT_SUPPORT, $error_oper_name, other.get_type_name()), gettext(OPERATOR_ERROR))) + return Err(ErrorInfo::new(t!(OPERATOR_IS_NOT_SUPPORT, "0"=$error_oper_name, "1"=other.get_type_name()), t!(OPERATOR_ERROR))) } } } @@ -130,22 +129,34 @@ pub trait TrcObj: Downcast + std::fmt::Display + Debug { fn not(&self) -> RuntimeResult> { Err(ErrorInfo::new( - gettext!(OPERATOR_IS_NOT_SUPPORT, "!", self.get_type_name()), - gettext(OPERATOR_ERROR), + t!( + OPERATOR_IS_NOT_SUPPORT, + "0" = "!", + "1" = self.get_type_name() + ), + t!(OPERATOR_ERROR), )) } fn bit_not(&self) -> RuntimeResult> { Err(ErrorInfo::new( - gettext!(OPERATOR_IS_NOT_SUPPORT, "~", self.get_type_name()), - gettext(OPERATOR_ERROR), + t!( + OPERATOR_IS_NOT_SUPPORT, + "0" = "~", + "1" = self.get_type_name() + ), + t!(OPERATOR_ERROR), )) } fn self_negative(&self) -> RuntimeResult> { Err(ErrorInfo::new( - gettext!(OPERATOR_IS_NOT_SUPPORT, "-", self.get_type_name()), - gettext(OPERATOR_ERROR), + t!( + OPERATOR_IS_NOT_SUPPORT, + "0" = "-", + "1" = self.get_type_name() + ), + t!(OPERATOR_ERROR), )) } diff --git a/rust/src/tvm/types/trcbool.rs b/rust/src/tvm/types/trcbool.rs index c7ee77f7..38675440 100644 --- a/rust/src/tvm/types/trcbool.rs +++ b/rust/src/tvm/types/trcbool.rs @@ -6,7 +6,7 @@ use crate::compiler::scope::TypeAllowNull; use crate::compiler::token::TokenType; use crate::{batch_impl_opers, hash_map, impl_oper, impl_single_oper}; use derive::{trc_class, trc_method}; -use gettextrs::gettext; +use rust_i18n::t; use std::collections::hash_map::HashMap; use std::fmt::Display; diff --git a/rust/src/tvm/types/trcfloat.rs b/rust/src/tvm/types/trcfloat.rs index 23bb27c5..29d498ef 100644 --- a/rust/src/tvm/types/trcfloat.rs +++ b/rust/src/tvm/types/trcfloat.rs @@ -11,7 +11,7 @@ use crate::impl_single_oper; use crate::{batch_impl_opers, impl_oper}; use derive::trc_class; use derive::trc_method; -use gettextrs::gettext; +use rust_i18n::t; use std::collections::hash_map::HashMap; use std::fmt::Display; @@ -47,8 +47,8 @@ impl TrcFloat { pub fn div_float(a: f64, b: f64) -> Result { if b == 0.0 { return Err(ErrorInfo::new( - gettext!(ZERO_DIV, a), - gettext(ZERO_DIVSION_ERROR), + t!(ZERO_DIV, "0" = a), + t!(ZERO_DIVSION_ERROR), )); } Ok(a / b) @@ -57,8 +57,8 @@ pub fn div_float(a: f64, b: f64) -> Result { pub fn exact_div_float(a: f64, b: f64) -> Result { if b == 0.0 { return Err(ErrorInfo::new( - gettext!(ZERO_DIV, a), - gettext(ZERO_DIVSION_ERROR), + t!(ZERO_DIV, "0" = a), + t!(ZERO_DIVSION_ERROR), )); } Ok((a / b).floor() as i64) diff --git a/rust/src/tvm/types/trcint.rs b/rust/src/tvm/types/trcint.rs index 479b7edc..79c6aeb2 100644 --- a/rust/src/tvm/types/trcint.rs +++ b/rust/src/tvm/types/trcint.rs @@ -10,7 +10,7 @@ use crate::impl_single_oper; use crate::{base::error::*, batch_impl_opers, impl_oper}; use derive::trc_class; use derive::trc_method; -use gettextrs::gettext; +use rust_i18n::t; use std::collections::hash_map::HashMap; use std::fmt::Display; @@ -53,8 +53,8 @@ impl TrcInt { pub fn exact_div_int(a: i64, b: i64) -> Result { if b == 0 { return Err(ErrorInfo::new( - gettext!(ZERO_DIV, a), - gettext(ZERO_DIVSION_ERROR), + t!(ZERO_DIV, "0" = a), + t!(ZERO_DIVSION_ERROR), )); } Ok(a / b) @@ -63,8 +63,8 @@ pub fn exact_div_int(a: i64, b: i64) -> Result { pub fn div_int(a: i64, b: i64) -> Result { if b == 0 { return Err(ErrorInfo::new( - gettext!(ZERO_DIV, a), - gettext(ZERO_DIVSION_ERROR), + t!(ZERO_DIV, "0" = a), + t!(ZERO_DIVSION_ERROR), )); } Ok(a as f64 / b as f64) @@ -73,8 +73,8 @@ pub fn div_int(a: i64, b: i64) -> Result { pub fn mod_int(a: i64, b: i64) -> Result { if b == 0 { return Err(ErrorInfo::new( - gettext!(ZERO_DIV, a), - gettext(ZERO_DIVSION_ERROR), + t!(ZERO_DIV, "0" = a), + t!(ZERO_DIVSION_ERROR), )); } Ok(a % b) diff --git a/rust/src/tvm/types/trcstr.rs b/rust/src/tvm/types/trcstr.rs index 55acea83..d0497e79 100644 --- a/rust/src/tvm/types/trcstr.rs +++ b/rust/src/tvm/types/trcstr.rs @@ -5,7 +5,7 @@ use crate::compiler::token::TokenType; use crate::hash_map; use crate::{base::error::*, batch_impl_opers, impl_oper}; use derive::{trc_class, trc_method}; -use gettextrs::gettext; +use rust_i18n::t; use std::collections::hash_map::HashMap; use std::fmt::Display;