diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index b178232..5dbff76 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -6,13 +6,13 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Increase Swap - uses: get-bridge/swap-space-action@v1 - with: - swap-size-mb: 16384 - - name: Report Disk - run: | - df -h + # - name: Increase Swap + # uses: get-bridge/swap-space-action@v1 + # with: + # swap-size-mb: 16384 + # - name: Report Disk + # run: | + # df -h - name: Checkout uses: actions/checkout@v4 - name: Install pnpm diff --git a/ic10emu/Cargo.lock b/ic10emu/Cargo.lock index ed36075..68150b7 100644 --- a/ic10emu/Cargo.lock +++ b/ic10emu/Cargo.lock @@ -11,137 +11,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - -[[package]] -name = "anyhow" -version = "1.0.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" - -[[package]] -name = "ascii" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - -[[package]] -name = "bumpalo" -version = "3.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "c2rust-bitfields" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb34f0c0ace43530b2df7f18bc69ee0c4082158aa451ece29602f8c841e73764" -dependencies = [ - "c2rust-bitfields-derive", -] - -[[package]] -name = "c2rust-bitfields-derive" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dd1601a7b828ab874d890e5a895563ca8ad485bdd3d2a359f148c8b72537241" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "cc" -version = "1.0.90" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" - -[[package]] -name = "cesu8" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "chunked_transfer" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4de3bc4ea267985becf712dc6d9eed8b04c953b3fcfb339ebc87acd9804901" - -[[package]] -name = "clap" -version = "2.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "ansi_term", - "atty", - "bitflags 1.3.2", - "strsim", - "textwrap", - "unicode-width", - "vec_map", -] - -[[package]] -name = "combine" -version = "4.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" -dependencies = [ - "bytes", - "memchr", -] - [[package]] name = "const-crc32" version = "1.3.0" @@ -157,286 +26,39 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" - -[[package]] -name = "difference" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" - -[[package]] -name = "dirs" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30baa043103c9d0c2a57cf537cc2f35623889dc0d405e6c3cccfadbc81c71309" -dependencies = [ - "dirs-sys", -] - -[[package]] -name = "dirs-sys" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - [[package]] name = "either" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" - -[[package]] -name = "form_urlencoded" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "getrandom" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - -[[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 = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "home" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "html-escape" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d1ad449764d627e22bfd7cd5e8868264fc9236e07c752972b4080cd351cb476" -dependencies = [ - "utf8-width", -] - -[[package]] -name = "httpdate" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" - [[package]] name = "ic10emu" version = "0.1.0" dependencies = [ "const-crc32", "convert_case", + "itertools", "phf", "phf_codegen", "regex", - "rust-sitter", - "rust-sitter-tool", "strum_macros", -] - -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[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.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" -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 = "jni" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" -dependencies = [ - "cesu8", - "cfg-if", - "combine", - "jni-sys", - "log", "thiserror", - "walkdir", - "windows-sys 0.45.0", ] [[package]] -name = "jni-sys" -version = "0.3.0" +name = "itertools" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" - -[[package]] -name = "js-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.153" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" - -[[package]] -name = "libloading" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" -dependencies = [ - "cfg-if", - "winapi", -] - -[[package]] -name = "libredox" -version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" -dependencies = [ - "bitflags 2.5.0", - "libc", - "redox_syscall", -] - -[[package]] -name = "linux-raw-sys" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" - -[[package]] -name = "log" -version = "0.4.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" - -[[package]] -name = "malloc_buf" -version = "0.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" -dependencies = [ - "libc", + "either", ] [[package]] @@ -445,33 +67,6 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" -[[package]] -name = "ndk-context" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" - -[[package]] -name = "objc" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" -dependencies = [ - "malloc_buf", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - [[package]] name = "phf" version = "0.11.2" @@ -543,32 +138,6 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -[[package]] -name = "raw-window-handle" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" - -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "redox_users" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" -dependencies = [ - "getrandom", - "libredox", - "thiserror", -] - [[package]] name = "regex" version = "1.10.3" @@ -578,7 +147,7 @@ dependencies = [ "aho-corasick", "memchr", "regex-automata", - "regex-syntax 0.8.2", + "regex-syntax", ] [[package]] @@ -589,166 +158,27 @@ checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.2", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - [[package]] name = "regex-syntax" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" -[[package]] -name = "rust-sitter" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9740bfc968b639729ae72acf0bcacacc8dfee136db6ac11a0c27baa7ccfab13" -dependencies = [ - "rust-sitter-macro", - "tree-sitter-c2rust", -] - -[[package]] -name = "rust-sitter-common" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49fd04db2e36bf681c70f293db3162105c02d64d7af66827bc639bb1e26827e2" -dependencies = [ - "quote", - "syn 1.0.109", -] - -[[package]] -name = "rust-sitter-macro" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611081d5efb786ea1864f4f8ca3ebde7a4218a84aedee4b1fbb5be2bb60e6bae" -dependencies = [ - "proc-macro2", - "quote", - "rust-sitter-common", - "syn 1.0.109", -] - -[[package]] -name = "rust-sitter-tool" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37438e08664649ed0967334dec982f8dcc3cec5c39afc73ef669f79f56085336" -dependencies = [ - "cc", - "rust-sitter-common", - "serde", - "serde_json", - "syn 1.0.109", - "syn-inline-mod", - "tempfile", - "tree-sitter", - "tree-sitter-cli", -] - -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "rustix" -version = "0.38.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" -dependencies = [ - "bitflags 2.5.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] - [[package]] name = "rustversion" version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" -[[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.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 = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.53", -] - -[[package]] -name = "serde_json" -version = "1.0.114" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" -dependencies = [ - "indexmap 2.2.5", - "itoa", - "ryu", - "serde", -] - [[package]] name = "siphasher" version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" -[[package]] -name = "smallbitvec" -version = "2.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3fc564a4b53fd1e8589628efafe57602d91bde78be18186b5f61e8faea470" - -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strum_macros" version = "0.26.2" @@ -759,18 +189,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.53", -] - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "syn", ] [[package]] @@ -784,37 +203,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "syn-inline-mod" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b670f535364c67358ecffb60b9f2579f9b45d3c71e8cca6d45d22ee0fadaa7eb" -dependencies = [ - "proc-macro2", - "syn 1.0.109", -] - -[[package]] -name = "tempfile" -version = "3.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" -dependencies = [ - "cfg-if", - "fastrand", - "rustix", - "windows-sys 0.52.0", -] - -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.58" @@ -832,480 +220,17 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn", ] -[[package]] -name = "tiny_http" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "389915df6413a2e74fb181895f933386023c71110878cd0825588928e64cdc82" -dependencies = [ - "ascii", - "chunked_transfer", - "httpdate", - "log", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - -[[package]] -name = "tree-sitter" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e747b1f9b7b931ed39a548c1fae149101497de3c1fc8d9e18c62c1a66c683d3d" -dependencies = [ - "cc", - "regex", -] - -[[package]] -name = "tree-sitter-c2rust" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee40a4d9cf5a30c199935f346887588239daceae4d1418d81b789276fffb8d91" -dependencies = [ - "c2rust-bitfields", - "once_cell", - "regex", -] - -[[package]] -name = "tree-sitter-cli" -version = "0.20.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae7e9d844d4d38e511a7b93fe8ced79f2a364c32fdea10d04546f1c8317d5a0c" -dependencies = [ - "ansi_term", - "anyhow", - "atty", - "clap", - "difference", - "dirs", - "glob", - "html-escape", - "indexmap 1.9.3", - "lazy_static", - "log", - "regex", - "regex-syntax 0.6.29", - "rustc-hash", - "semver", - "serde", - "serde_json", - "smallbitvec", - "tiny_http", - "toml", - "tree-sitter", - "tree-sitter-config", - "tree-sitter-highlight", - "tree-sitter-loader", - "tree-sitter-tags", - "walkdir", - "webbrowser", - "which", -] - -[[package]] -name = "tree-sitter-config" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5fec4cb27f052ead2246631b332dba0cb6af9a54ce012badee59c4b0ded5e03" -dependencies = [ - "anyhow", - "dirs", - "serde", - "serde_json", -] - -[[package]] -name = "tree-sitter-highlight" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "042342584c5a7a0b833d9fc4e2bdab3f9868ddc6c4b339a1e01451c6720868bc" -dependencies = [ - "regex", - "thiserror", - "tree-sitter", -] - -[[package]] -name = "tree-sitter-loader" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0b17eef4833c7c139abed66d562dfa23228e97e647597baf246fd56c21bbfaf" -dependencies = [ - "anyhow", - "cc", - "dirs", - "libloading", - "once_cell", - "regex", - "serde", - "serde_json", - "tree-sitter", - "tree-sitter-highlight", - "tree-sitter-tags", -] - -[[package]] -name = "tree-sitter-tags" -version = "0.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccb3f1376219530a37a809751ecf65aa35fd8b9c1c4ab6d4faf5f6a9eeda2c05" -dependencies = [ - "memchr", - "regex", - "thiserror", - "tree-sitter", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-normalization" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-segmentation" version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" - -[[package]] -name = "unicode-width" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" - -[[package]] -name = "url" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "utf8-width" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3" - -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - -[[package]] -name = "walkdir" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" -dependencies = [ - "same-file", - "winapi-util", -] - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wasm-bindgen" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.53", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.53", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" - -[[package]] -name = "web-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "webbrowser" -version = "0.8.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1b04c569c83a9bb971dd47ec6fd48753315f4bf989b9b04a2e7ca4d7f0dc950" -dependencies = [ - "core-foundation", - "home", - "jni", - "log", - "ndk-context", - "objc", - "raw-window-handle", - "url", - "web-sys", -] - -[[package]] -name = "which" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" -dependencies = [ - "either", - "home", - "once_cell", - "rustix", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.4", -] - -[[package]] -name = "windows-targets" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - -[[package]] -name = "windows-targets" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" -dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" - -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" diff --git a/ic10emu/Cargo.toml b/ic10emu/Cargo.toml index e5bc53a..28dface 100644 --- a/ic10emu/Cargo.toml +++ b/ic10emu/Cargo.toml @@ -11,15 +11,17 @@ crate-type = ["lib"] [dependencies] const-crc32 = "1.3.0" +itertools = "0.12.1" phf = "0.11.2" regex = "1.10.3" -rust-sitter = "0.4.1" +# rust-sitter = "0.4.1" strum_macros = "0.26.2" +thiserror = "1.0.58" [build-dependencies] convert_case = "0.6.0" phf_codegen = "0.11.2" regex = "1.10.3" -rust-sitter-tool = "0.4.1" +# rust-sitter-tool = "0.4.1" diff --git a/ic10emu/build.rs b/ic10emu/build.rs index b565df0..07c4709 100644 --- a/ic10emu/build.rs +++ b/ic10emu/build.rs @@ -26,7 +26,7 @@ fn write_logictypes(logictypes_grammar: &mut HashSet) { logictypes_grammar.insert(name.to_string()); if let Some(v) = val { - logictype_lookup_map_builder.entry(name.to_case(Case::Pascal), &format!("{}u8", v)); + logictype_lookup_map_builder.entry(name, &format!("{}u8", v)); } } @@ -42,7 +42,7 @@ fn write_logictypes(logictypes_grammar: &mut HashSet) { logictypes_grammar.insert(name.to_string()); if let Some(v) = val { - slotlogictype_lookup_map_builder.entry(name.to_case(Case::Pascal), &format!("{}u8", v)); + slotlogictype_lookup_map_builder.entry(name, &format!("{}u8", v)); } } @@ -52,10 +52,8 @@ fn write_logictypes(logictypes_grammar: &mut HashSet) { logictype_lookup_map_builder.build() ) .unwrap(); - println!("cargo:rerun-if-changed=data/logictypes.txt"); - write!( &mut writer, "pub(crate) const SLOT_TYPE_LOOKUP: phf::Map<&'static str, u8> = {};\n", @@ -90,7 +88,7 @@ fn write_enums(enums_grammar: &mut HashSet) { } if let Some(v) = val { - enums_lookup_map_builder.entry(name.to_case(Case::Pascal), &format!("{}u8", v)); + enums_lookup_map_builder.entry(name, &format!("{}u8", v)); } } @@ -123,7 +121,7 @@ fn write_modes(logictypes_grammar: &mut HashSet) { logictypes_grammar.insert(name.to_string()); if let Some(v) = val { - batchmode_lookup_map_builder.entry(name.to_case(Case::Pascal), &format!("{}u8", v)); + batchmode_lookup_map_builder.entry(name, &format!("{}u8", v)); } } @@ -139,7 +137,7 @@ fn write_modes(logictypes_grammar: &mut HashSet) { logictypes_grammar.insert(name.to_string()); if let Some(v) = val { - reagentmode_lookup_map_builder.entry(name.to_case(Case::Pascal), &format!("{}u8", v)); + reagentmode_lookup_map_builder.entry(name, &format!("{}u8", v)); } } @@ -179,7 +177,7 @@ fn write_constants(constants_grammar: &mut HashSet) { let constant = it.next().unwrap(); constants_grammar.insert(name.to_string()); - constants_lookup_map_builder.entry(name.to_case(Case::Pascal), constant); + constants_lookup_map_builder.entry(name, constant); } write!( @@ -191,82 +189,13 @@ fn write_constants(constants_grammar: &mut HashSet) { println!("cargo:rerun-if-changed=data/constants.txt"); } -fn write_logictypes_grammar(logictypes: &HashSet) { - let dest_path = Path::new("src/grammar/ic10").join("logictypes.rs"); +fn write_instructions_enum() { + let out_dir = env::var_os("OUT_DIR").unwrap(); + + let dest_path = Path::new(&out_dir).join("instructions.rs"); let output_file = File::create(dest_path).unwrap(); let mut writer = BufWriter::new(&output_file); - write!( - &mut writer, - "// GENERATED CODE DO NOT MODIFY\n\ - #[derive(PartialEq, Debug, IntoStaticStr, AsRefStr)]\n\ - pub enum LogicType {{\n\ - " - ) - .unwrap(); - for typ in logictypes { - let enum_name = typ.to_case(Case::Pascal); - write!( - &mut writer, - " #[rust_sitter::leaf(text = \"{typ}\" )]{},\n", - &enum_name - ) - .unwrap(); - } - write!(&mut writer, "}}\n").unwrap(); -} - -fn write_enums_grammar(enums: &HashSet) { - let dest_path = Path::new("src/grammar/ic10").join("enums.rs"); - let output_file = File::create(dest_path).unwrap(); - let mut writer = BufWriter::new(&output_file); - write!( - &mut writer, - "// GENERATED CODE DO NOT MODIFY\n\ - #[derive(PartialEq, Debug, IntoStaticStr, AsRefStr)]\n\ - pub enum Enum {{\n\ - " - ) - .unwrap(); - for typ in enums { - let enum_name = typ.replace(".", "").to_case(Case::Pascal); - - write!( - &mut writer, - " #[rust_sitter::leaf(text = \"{typ}\" )]{},\n", - &enum_name - ) - .unwrap(); - } - write!(&mut writer, "}}\n").unwrap(); -} - -fn write_constants_grammar(constants: HashSet) { - let dest_path = Path::new("src/grammar/ic10").join("constants.rs"); - let output_file = File::create(dest_path).unwrap(); - let mut writer = BufWriter::new(&output_file); - write!( - &mut writer, - "// GENERATED CODE DO NOT MODIFY\n\ - #[derive(PartialEq, Debug, IntoStaticStr, AsRefStr)]\n\ - pub enum Constant {{\n\ - " - ) - .unwrap(); - for typ in constants { - let enum_name = typ.replace(".", "").to_case(Case::Pascal); - - write!( - &mut writer, - " #[rust_sitter::leaf(text = \"{typ}\" )]{},\n", - &enum_name - ) - .unwrap(); - } - write!(&mut writer, "}}\n").unwrap(); -} - -fn load_instructions() -> HashSet { let mut instructions = HashSet::new(); let infile = Path::new("data/instructions.txt"); let contents = fs::read_to_string(infile).unwrap(); @@ -276,104 +205,6 @@ fn load_instructions() -> HashSet { let instruction = it.next().unwrap(); instructions.insert(instruction.to_string()); } - instructions -} - -fn write_instructions_grammar(instructions: &HashSet) { - let dest_path = Path::new("src/grammar/ic10").join("instructions.rs"); - let output_file = File::create(dest_path).unwrap(); - let mut writer = BufWriter::new(&output_file); - - write!( - &mut writer, - "// GENERATED CODE DO NOT MODIFY\n\ - #[derive(PartialEq, Debug, IntoStaticStr, AsRefStr)]\n\ - pub enum InstructionOp {{\n\ - " - ) - .unwrap(); - for typ in instructions { - let enum_name = typ.to_case(Case::Pascal); - - write!( - &mut writer, - " #[rust_sitter::leaf(text = \"{typ}\" )]{},\n", - &enum_name - ) - .unwrap(); - } - write!(&mut writer, "}}\n").unwrap(); -} - -fn patch_grammar() { - let out_path = env::var_os("OUT_DIR").unwrap(); - let out_dir = Path::new(&out_path); - let src_dir = Path::new("src"); - fs::copy( - src_dir.join("grammar.rs"), - out_dir.join("grammar_unpatched.rs"), - ) - .unwrap(); - { - let grammar_file = File::open(src_dir.join("grammar.rs")).unwrap(); - let output_file = File::create(out_dir.join("grammar_patched.rs")).unwrap(); - let mut writer = BufWriter::new(output_file); - - let patch_regex = regex::Regex::new(r"^\s+// PATCH ([\w/.]+)\s*$").unwrap(); - - let mut patch_marker: Option = None; - for line in BufReader::new(grammar_file).lines().flatten() { - if let Some(marker) = &patch_marker { - if let Some(_) = marker.captures(&line) { - write!(&mut writer, "{}\n", line).unwrap(); - patch_marker = None; - } else { - continue; - } - } else { - if let Some(captures) = patch_regex.captures(&line) { - write!(&mut writer, "{}\n", line).unwrap(); - let in_path = captures.get(1).unwrap(); - patch_marker = Some( - regex::Regex::new(&format!(r"^\s+// END PATCH {}\s*$", in_path.as_str())) - .unwrap(), - ); - let in_buff = - BufReader::new(File::open(src_dir.join(in_path.as_str())).unwrap()); - write!( - &mut writer, - " {}\n", - in_buff.lines().flatten().collect::>().join("\n ") - ) - .unwrap(); - } else { - write!(&mut writer, "{}\n", line).unwrap(); - } - } - } - } - fs::rename( - out_dir.join("grammar_patched.rs"), - src_dir.join("grammar.rs"), - ) - .unwrap(); -} - -fn build_grammar() { - println!("cargo:rerun-if-changed=src/grammar/"); - println!("cargo:rerun-if-changed=src/grammar.rs"); - // let out_path = env::var_os("OUT_DIR").unwrap(); - // let out_dir = Path::new(&out_path); - rust_sitter_tool::build_parsers(&PathBuf::from("src/lib.rs")); - // rust_sitter_tool::build_parsers(&out_dir.join("grammar_patched.rs")); -} - -fn write_instructions_enum(instructions: &HashSet) { - let out_dir = env::var_os("OUT_DIR").unwrap(); - - let dest_path = Path::new(&out_dir).join("instructions.rs"); - let output_file = File::create(dest_path).unwrap(); - let mut writer = BufWriter::new(&output_file); write!( &mut writer, @@ -385,34 +216,35 @@ fn write_instructions_enum(instructions: &HashSet) { write!(&mut writer, " Nop,\n").unwrap(); - for typ in instructions { + for typ in &instructions { write!(&mut writer, " {},\n", typ.to_case(Case::Pascal)).unwrap(); } write!(&mut writer, "}}\n").unwrap(); write!( &mut writer, - "impl From for InstructionOp {{\n \ - fn from(value: crate::grammar::ic10::InstructionOp) -> Self {{\n \ - match value {{\n" + "impl FromStr for InstructionOp {{\n \ + type Err = ParseError;\n \ + fn from_str(s: &str) -> Result {{\n \ + let end = s.len();\n \ + match s {{\n" ) .unwrap(); - for typ in instructions { + for typ in &instructions { let name = typ.to_case(Case::Pascal); - write!( - &mut writer, - " crate::grammar::ic10::InstructionOp::{name} => Self::{name},\n" - ) - .unwrap(); + write!(&mut writer, " \"{typ}\" => Ok(Self::{name}),\n").unwrap(); } write!( &mut writer, - " }}\n \ + " _ => Err(crate::grammar::ParseError {{ line: 0, start: 0, end, msg: format!(\"Unknown instruction '{{}}'\", s) }})\n \ + }}\n \ }}\n\ }}" ) .unwrap(); + + println!("cargo:rerun-if-changed=data/instructions.txt"); } fn main() { @@ -425,15 +257,5 @@ fn main() { write_constants(&mut constants_grammar); write_enums(&mut enums_grammar); - let instructions = load_instructions(); - write_instructions_enum(&instructions); - - write_logictypes_grammar(&logictype_grammar); - write_enums_grammar(&enums_grammar); - write_constants_grammar(constants_grammar); - write_instructions_grammar(&instructions); - - patch_grammar(); - - build_grammar(); + write_instructions_enum(); } diff --git a/ic10emu/src/compiler.rs b/ic10emu/src/compiler.rs deleted file mode 100644 index 04c6112..0000000 --- a/ic10emu/src/compiler.rs +++ /dev/null @@ -1,115 +0,0 @@ -use std::convert::AsRef; -use crate::grammar; - -// include files built from lang def -include!(concat!(env!("OUT_DIR"), "/logictypes.rs")); -include!(concat!(env!("OUT_DIR"), "/modes.rs")); -include!(concat!(env!("OUT_DIR"), "/constants.rs")); -include!(concat!(env!("OUT_DIR"), "/enums.rs")); -include!(concat!(env!("OUT_DIR"), "/instructions.rs")); - -#[derive(Debug)] -pub enum Device { - Db, - Numbered(u8), - Indirect { indirection: u32, target: u8 }, -} - -impl From for Device { - fn from(value: grammar::rich_types::Device) -> Self { - match value { - grammar::rich_types::Device::Db => Self::Db, - grammar::rich_types::Device::Numbered(n) => Self::Numbered(n), - grammar::rich_types::Device::Indirect(r) => Self::Indirect { - indirection: r.indirection, - target: r.target, - }, - } - } -} - -#[derive(Debug)] -pub enum Operand { - Register { - indirection: u32, - target: u8, - }, - DeviceSpec { - device: Device, - channel: Option, - }, - Number(f64), - Identifier(String), -} - -impl TryFrom for Operand { - type Error = String; - fn try_from(value: grammar::ic10::Operand) -> Result { - match value { - grammar::ic10::Operand::RegisterSpec(r) => Ok(Self::Register { - indirection: r.indirection, - target: r.target, - }), - grammar::ic10::Operand::DeviceSpec(ds) => Ok(Self::DeviceSpec { - device: ds.device.into(), - channel: ds.channel, - }), - grammar::ic10::Operand::LogicType(t) => Ok(Self::Number( - (*LOGIC_TYPE_LOOKUP - .get(t.as_ref()) - .ok_or(format!("Unknown Logic Type {}", t.as_ref()))?) - .into(), - )), - grammar::ic10::Operand::Identifier(id) => Ok(Self::Identifier(id.name)), - grammar::ic10::Operand::Number(n) => match n { - grammar::ic10::Number::Float(f) => Ok(Self::Number(f)), - grammar::ic10::Number::Binary(_, f) => Ok(Self::Number(f)), - grammar::ic10::Number::Hexadecimal(_, f) => Ok(Self::Number(f)), - grammar::ic10::Number::Constant(c) => Ok(Self::Number( - *CONSTANTS_LOOKUP - .get(c.as_ref()) - .ok_or(format!("Unknown constant {}", c.as_ref()))?, - )), - grammar::ic10::Number::Enum(e) => Ok(Self::Number( - (*ENUM_LOOKUP - .get(e.as_ref()) - .ok_or(format!("Unknown enum {}", e.as_ref()))?) - .into(), - )), - grammar::ic10::Number::String(s) => Ok(Self::Number(s.string.hash.into())), - }, - } - } -} - -#[derive(Debug)] -pub struct Instruction { - pub instruction: InstructionOp, - pub operands: Vec, -} - -#[derive(Debug)] -pub struct Program { - pub instructions: Vec, -} - -impl Default for Program { - fn default() -> Self { - Program::new() - } -} - -impl Program { - pub fn new() -> Self { Program { instructions: Vec::new() }} - pub fn try_from_code(input: &str) -> Result { - let mut code = input.to_string(); - if let Some((i, _)) = code.char_indices().rev().nth(0) { - let last_char = &code[i..]; - if last_char != "\r" && last_char != "\n" {code.push('\n');} - } - let parse_tree = grammar::ic10::parse(&code); - - - Ok(Program { instructions: vec![] }) - } -} diff --git a/ic10emu/src/grammar.rs b/ic10emu/src/grammar.rs index b881ffe..9b43552 100644 --- a/ic10emu/src/grammar.rs +++ b/ic10emu/src/grammar.rs @@ -1,1003 +1,663 @@ -pub mod rich_types; +use crate::interpreter; +use crate::tokens::SplitConsecutiveIndicesExt; +use itertools::Itertools; +use std::error::Error; +use std::fmt::Display; +use std::str::FromStr; -#[rust_sitter::grammar("ic10")] -pub mod ic10 { - use super::rich_types::*; - use strum_macros::IntoStaticStr; - use strum_macros::AsRefStr; +#[derive(Debug, Clone)] +pub struct ParseError { + pub line: usize, + pub start: usize, + pub end: usize, + pub msg: String, +} - #[derive(PartialEq, Debug)] - #[rust_sitter::language] - pub struct Language { - pub lines: Vec, +impl Display for ParseError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{} at line {} {}:{}", + self.msg, self.line, self.start, self.end + ) + } +} + +impl Error for ParseError {} + +impl ParseError { + /// Offset the ParseError in it's line, adding the passed values to it's `start` and `end` + pub fn offset(self, offset: usize) -> Self { + ParseError { + line: self.line, + start: self.start + offset, + end: self.end + offset, + msg: self.msg, + } } - #[derive(PartialEq, Debug)] - pub struct Line { - pub code: Option, - pub comment: Option, - pub _newline: NewLine, + /// Offset the ParseError line, adding the passed value to it's `line` + pub fn offset_line(self, offset: usize) -> Self { + ParseError { + line: self.line + offset, + start: self.start, + end: self.end, + msg: self.msg, + } } - // #[derive(Debug)] - // #[rust_sitter::prec_left(1)] - // pub enum LastLine { - // #[rust_sitter::prec_left(3)] - // Both(Code, Comment), - // #[rust_sitter::prec_left(2)] - // Code(Code), - // #[rust_sitter::prec_left(1)] - // Comment(Comment), - // } + /// Mark the parse error as extending 'length' bytes from `start` + pub fn span(self, length: usize) -> Self { + ParseError { + line: self.line, + start: self.start, + end: self.start + length, + msg: self.msg, + } + } +} - #[derive(PartialEq, Debug)] - pub enum Code { - Instruction(Instruction), - Label(Label), - } +include!(concat!(env!("OUT_DIR"), "/instructions.rs")); +include!(concat!(env!("OUT_DIR"), "/logictypes.rs")); +include!(concat!(env!("OUT_DIR"), "/modes.rs")); +include!(concat!(env!("OUT_DIR"), "/constants.rs")); +include!(concat!(env!("OUT_DIR"), "/enums.rs")); - #[derive(PartialEq, Debug)] - pub struct Comment { - #[rust_sitter::leaf(text = r"#")] - pub _header: (), - #[rust_sitter::leaf(pattern = r"[^\n\r]*", transform = |s| s.to_string() )] - pub comment: String, - } +pub fn parse(code: &str) -> Result, ParseError> { + code.lines() + .enumerate() + .map(|(n, l)| l.parse::().map_err(|e| e.offset_line(n))) + .collect() +} - #[derive(PartialEq, Debug)] - pub struct Instruction { - pub instruction: InstructionOp, - pub operands: Vec, - } +#[derive(PartialEq, Debug)] +pub struct Line { + pub code: Option, + pub comment: Option, +} - #[derive(PartialEq, Debug)] - pub enum Operand { - RegisterSpec( - #[rust_sitter::leaf(pattern = r"sp|r(?:a|r*)(?:[0-9]|1[0-7])", transform = |rs| Register::from_str(rs))] - Register, - ), - DeviceSpec( - #[rust_sitter::leaf(pattern = r"d(?:b|[0-5]|r*(?:[0-9]|1[0-7]))(?::[0-9]+)?", transform = |ds| DeviceSpec::from_str(ds))] - DeviceSpec, - ), - Number(Number), - LogicType(LogicType), - Identifier(Identifier), +impl FromStr for Line { + type Err = ParseError; + fn from_str(s: &str) -> Result { + let mut parts = s.splitn(2, "#"); + let code = parts + .next() + .map(|s| { + let s = s.trim_end(); + if s.is_empty() { + None + } else { + Some(s.parse::()) + } + }) + .flatten() + .transpose()?; + let comment = parts.next().map(|s| s.parse()).transpose()?; + Ok(Line { code, comment }) } +} - #[derive(PartialEq, Debug)] - pub struct Label(pub Identifier, #[rust_sitter::leaf(text = r":")] pub ()); +#[derive(PartialEq, Debug)] +pub enum Code { + Instruction(Instruction), + Label(Label), +} - #[derive(PartialEq, Debug)] - pub struct Identifier { - #[rust_sitter::leaf(pattern = r"[a-zA-Z_.][\w\d.]*", transform = |id| id.to_string())] - pub name: String, - } +impl FromStr for Code { + type Err = ParseError; - #[derive(PartialEq, Debug)] - pub struct HashPreProc { - #[rust_sitter::leaf(text = "HASH(\"")] - pub _head: (), - #[rust_sitter::leaf(pattern = "[^\"\\n]*", transform = |s| HashString::from_str(s) )] - pub string: HashString, - #[rust_sitter::leaf(text = "\")")] - pub _foot: (), + /// Parse a non empty Code line from a &str with no comment in it + fn from_str(s: &str) -> Result { + let s = s.trim_end(); + if let Some((index, ':')) = s.chars().enumerate().last() { + Ok(Code::Label( + s.parse::