Compare commits

6 Commits

Author SHA1 Message Date
e5b423aab2 Modernise CI (#8)
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
Co-authored-by: Smaug123 <3138005+Smaug123@users.noreply.github.com>
Reviewed-on: #8
2025-09-09 08:18:31 +00:00
75c0a8f234 Direnv (#6)
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk>
Reviewed-on: #6
2024-01-29 00:37:41 +00:00
fa1eaf6f7c Work around for conditional execution in Woodpecker (#5)
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk>
Reviewed-on: #5
2023-08-26 12:58:54 +00:00
8eaebbb25c Fix syntax error in pipeline (#4)
Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk>
Reviewed-on: #4
2023-08-03 20:06:27 +00:00
0be7c25034 Upgrade to Woodpecker v1 (#3)
Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk>
Reviewed-on: #3
2023-08-01 19:45:17 +00:00
f11d861eef Migrate pipelines to Woodpecker (#1)
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk>
Reviewed-on: #1
2023-07-25 07:17:09 +00:00
32 changed files with 395 additions and 371 deletions

1
.envrc Normal file
View File

@@ -0,0 +1 @@
use flake

2
.gitignore vendored
View File

@@ -7,3 +7,5 @@ target/
data_*_flex.json
data_*_haveranswer.f64
.direnv/
result

View File

@@ -0,0 +1,10 @@
steps:
echo:
image: alpine
commands:
- echo "All required checks complete"
depends_on:
- build
skip_clone: true

26
.woodpecker/build.yaml Normal file
View File

@@ -0,0 +1,26 @@
steps:
build:
image: nixos/nix:2.28.5
commands:
- echo 'experimental-features = flakes nix-command' >> /etc/nix/nix.conf
# Lint
- nix develop --command cargo -- fmt --all -- --check
- nix develop --command cargo -- clippy -- -D warnings -W clippy::must_use_candidate
- nix develop .#ci --command nixpkgs-fmt --check .
- nix develop .#ci --command markdown-link-check README.md
# Test
- nix develop --command cargo test --verbose --release
- nix develop --command cargo test --verbose
# Run through Nix
- nix flake check
- nix build
- nix run . -- computer_enhance/perfaware/part1/listing_0038_many_register_mov computer_enhance/perfaware/part1/listing_0038_many_register_mov.asm
- nix run . -- computer_enhance/perfaware/part1/listing_0055_challenge_rectangle computer_enhance/perfaware/part1/listing_0055_challenge_rectangle.asm
# Test round-tripping
- nix develop . --command cargo run --release --bin generator --package generator -- 12345 100
- nix develop . --command cargo run --release --bin haversine-app --package haversine-app -- data_100_flex.json data_100_haveranswer.f64
when:
- event: "push"
evaluate: 'CI_COMMIT_BRANCH == CI_REPO_DEFAULT_BRANCH'
- event: "pull_request"

280
Cargo.lock generated
View File

@@ -1,61 +1,62 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "anstream"
version = "0.3.2"
version = "0.6.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163"
checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is-terminal",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.0"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d"
checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd"
[[package]]
name = "anstyle-parse"
version = "0.2.0"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee"
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.0"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "1.0.1"
version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188"
checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys",
]
[[package]]
name = "arbitrary"
version = "1.3.0"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2d098ff73c1ca148721f37baad5ea6a465a13f9573aba8641fbbbae8164a54e"
checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1"
dependencies = [
"derive_arbitrary",
]
@@ -69,59 +70,45 @@ dependencies = [
"arbitrary",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "byteorder"
version = "1.4.3"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "cc"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "cfg-if"
version = "1.0.0"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
[[package]]
name = "clap"
version = "4.3.1"
version = "4.5.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ed2379f8603fa2b7509891660e802b88c70a79a6427a70abb5968054de2c28"
checksum = "7eac00902d9d136acd712710d71823fb8ac8004ca445a89e73a41d45aa712931"
dependencies = [
"clap_builder",
"clap_derive",
"once_cell",
]
[[package]]
name = "clap_builder"
version = "4.3.1"
version = "4.5.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72394f3339a76daf211e57d4bcb374410f3965dcc606dd0e03738c7888766980"
checksum = "2ad9bbf750e73b5884fb8a211a9424a1906c1e156724260fdae972f31d70e1d6"
dependencies = [
"anstream",
"anstyle",
"bitflags",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.3.1"
version = "4.5.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59e9ef9a08ee1c0e1f2e162121665ac45ac3783b0f897db7244ae75ad9a8f65b"
checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c"
dependencies = [
"heck",
"proc-macro2",
@@ -131,57 +118,36 @@ dependencies = [
[[package]]
name = "clap_lex"
version = "0.5.0"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675"
[[package]]
name = "colorchoice"
version = "1.0.0"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]]
name = "const_panic"
version = "0.2.8"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6051f239ecec86fde3410901ab7860d458d160371533842974fc61f96d15879b"
checksum = "bb8a602185c3c95b52f86dc78e55a6df9a287a7a93ddbcf012509930880cf879"
dependencies = [
"typewit",
]
[[package]]
name = "derive_arbitrary"
version = "1.3.1"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53e0efad4403bfc52dc201159c4b842a246a14b98c64b55dfd0f2d89729dfeb8"
checksum = "1e567bd82dcff979e4b03460c307b3cdc9e96fde3d73bed1496d2bc75d9dd62a"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "errno"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a"
dependencies = [
"errno-dragonfly",
"libc",
"windows-sys",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "generator"
version = "0.1.0"
@@ -195,9 +161,9 @@ dependencies = [
[[package]]
name = "getrandom"
version = "0.2.9"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4"
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
dependencies = [
"cfg-if",
"libc",
@@ -221,38 +187,15 @@ dependencies = [
[[package]]
name = "heck"
version = "0.4.1"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "hermit-abi"
version = "0.3.1"
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
[[package]]
name = "io-lifetimes"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
dependencies = [
"hermit-abi",
"libc",
"windows-sys",
]
[[package]]
name = "is-terminal"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f"
dependencies = [
"hermit-abi",
"io-lifetimes",
"rustix",
"windows-sys",
]
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "json"
@@ -260,21 +203,15 @@ version = "0.1.0"
[[package]]
name = "libc"
version = "0.2.144"
version = "0.2.175"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1"
[[package]]
name = "linux-raw-sys"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543"
[[package]]
name = "memchr"
version = "2.5.0"
version = "2.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
[[package]]
name = "minimal-lexical"
@@ -293,31 +230,34 @@ dependencies = [
]
[[package]]
name = "once_cell"
version = "1.17.2"
name = "once_cell_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b"
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro2"
version = "1.0.59"
version = "1.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b"
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.28"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
@@ -352,20 +292,6 @@ dependencies = [
"getrandom",
]
[[package]]
name = "rustix"
version = "0.37.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]]
name = "sim-wrapper"
version = "0.1.0"
@@ -386,15 +312,15 @@ dependencies = [
[[package]]
name = "strsim"
version = "0.10.0"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "2.0.18"
version = "2.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e"
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
dependencies = [
"proc-macro2",
"quote",
@@ -403,15 +329,15 @@ dependencies = [
[[package]]
name = "typewit"
version = "1.3.0"
version = "1.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c52b4cb7830f995903b2fcff3f523d21efc1c11f6c1596dd544b7925a64ff56"
checksum = "4c98488b93df24b7c794d6a58c4198d7a2abde676324beaca84f7fb5b39c0811"
[[package]]
name = "unicode-ident"
version = "1.0.9"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "utf8-read"
@@ -421,34 +347,42 @@ checksum = "fb566ac06e11c3f13872ebcb0e72ea5f97f0f65a16f45048d0adea21edc28018"
[[package]]
name = "utf8parse"
version = "0.2.1"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "windows-link"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
[[package]]
name = "windows-sys"
version = "0.48.0"
version = "0.60.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.48.0"
version = "0.53.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
dependencies = [
"windows-link",
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
@@ -457,42 +391,68 @@ dependencies = [
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.0"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.0"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
[[package]]
name = "windows_i686_gnu"
version = "0.48.0"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
[[package]]
name = "windows_i686_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
[[package]]
name = "windows_i686_msvc"
version = "0.48.0"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.0"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.0"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.0"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
[[package]]
name = "zerocopy"
version = "0.8.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831"
dependencies = [
"proc-macro2",
"quote",
"syn",
]

View File

@@ -7,6 +7,14 @@ members = [
"json",
"haversine-app"
]
resolver = "3"
[workspace.package]
edition = "2024"
[workspace.metadata.crane]
name = "performance_aware_programming"
version = "0.1.0"
[profile.release]
lto = true

98
flake.lock generated
View File

@@ -1,44 +1,30 @@
{
"nodes": {
"crate2nix": {
"flake": false,
"crane": {
"locked": {
"lastModified": 1678820090,
"narHash": "sha256-4FFeonajXNqiSP0PqUlC1wmTyPC8SX6SthEvgRjMupw=",
"owner": "kolloch",
"repo": "crate2nix",
"rev": "4fd826e37bec90dfe26ca16cb6e632c617cc7c0d",
"lastModified": 1757183466,
"narHash": "sha256-kTdCCMuRE+/HNHES5JYsbRHmgtr+l9mOtf5dpcMppVc=",
"owner": "ipetkov",
"repo": "crane",
"rev": "d599ae4847e7f87603e7082d73ca673aa93c916d",
"type": "github"
},
"original": {
"owner": "kolloch",
"repo": "crate2nix",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
@@ -49,11 +35,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1679705136,
"narHash": "sha256-MDlZUR7wJ3PlPtqwwoGQr3euNOe0vdSSteVVOef7tBY=",
"lastModified": 1757068644,
"narHash": "sha256-NOrUtIhTkIIumj1E/Rsv1J37Yi3xGStISEo8tZm3KW4=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "8f40f2f90b9c9032d1b824442cfbbe0dbabd0dbd",
"rev": "8eb28adfa3dc4de28e792e3bf49fcf9007ca8ac9",
"type": "github"
},
"original": {
@@ -63,42 +49,26 @@
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1679734080,
"narHash": "sha256-z846xfGLlon6t9lqUzlNtBOmsgQLQIZvR6Lt2dImk1M=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "dbf5322e93bcc6cfc52268367a8ad21c09d76fea",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"crate2nix": "crate2nix",
"flake-compat": "flake-compat",
"crane": "crane",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay",
"utils": "utils"
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_2"
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1679106165,
"narHash": "sha256-03Opt2yu4E/AIFjvlgib0/nhMn6B4B/t/nvwS2bzOGw=",
"lastModified": 1757298987,
"narHash": "sha256-yuFSw6fpfjPtVMmym51ozHYpJQ7SzVOTkk7tUv2JA0U=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "7313c06ac334d6262ddfe30a38b3abc3da6bd565",
"rev": "cfd63776bde44438ff2936f0c9194c79dd407a5f",
"type": "github"
},
"original": {
@@ -107,18 +77,18 @@
"type": "github"
}
},
"utils": {
"systems": {
"locked": {
"lastModified": 1678901627,
"narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6",
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}

191
flake.nix
View File

@@ -2,110 +2,121 @@
description = "Coursework for Performance-Aware Programming";
inputs = {
self.submodules = true;
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
crate2nix = {
url = "github:kolloch/crate2nix";
flake = false;
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
};
outputs = {
self,
nixpkgs,
utils,
rust-overlay,
crate2nix,
...
}: let
name = "sim-wrapper";
in
utils.lib.eachDefaultSystem
(
system: let
# Imports
outputs = { self, nixpkgs, flake-utils, rust-overlay, crane }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
rust-overlay.overlays.default
(self: super: {
# Because rust-overlay bundles multiple rust packages into one
# derivation, specify that mega-bundle here, so that crate2nix
# will use them automatically.
rustc = self.rust-bin.nightly.latest.default;
cargo = self.rust-bin.nightly.latest.default;
})
overlays = [ (import rust-overlay) ];
};
rustToolchain = pkgs.rust-bin.nightly.latest.default;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
# Common build inputs for all derivations
commonArgs = {
version = "0.1.0"; # Set explicitly to avoid warnings
src = pkgs.lib.cleanSourceWith {
src = ./.;
name = "source";
filter = path: type: (builtins.match ".*json$" path != null || pkgs.lib.hasInfix "/computer_enhance" path || craneLib.filterCargoSources path type);
};
strictDeps = true;
buildInputs = [
pkgs.openssl
];
nativeBuildInputs = [
pkgs.pkg-config
];
};
inherit
(import "${crate2nix}/tools.nix" {inherit pkgs;})
generatedCargoNix
;
# Create the cargo2nix project
project =
pkgs.callPackage
(generatedCargoNix {
inherit name;
src = ./.;
})
{
# Individual crate overrides go here
# Example: https://github.com/balsoft/simple-osd-daemons/blob/6f85144934c0c1382c7a4d3a2bbb80106776e270/flake.nix#L28-L50
defaultCrateOverrides =
pkgs.defaultCrateOverrides
// {
# The app crate itself is overriden here. Typically we
# configure non-Rust dependencies (see below) here.
${name} = oldAttrs:
{
inherit buildInputs nativeBuildInputs;
}
// buildEnvVars;
};
# Build just the cargo dependencies
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual package
sim-wrapper = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
});
in
{
packages = {
default = sim-wrapper;
sim-wrapper = sim-wrapper;
};
apps = {
default = {
type = "app";
program = "${sim-wrapper}/bin/sim-wrapper";
meta = sim-wrapper.meta;
};
sim-wrapper = {
type = "app";
program = "${sim-wrapper}/bin/sim-wrapper";
meta = sim-wrapper.meta;
};
};
devShells = {
default = craneLib.devShell {
# Inherit the build inputs from commonArgs
buildInputs = commonArgs.buildInputs;
nativeBuildInputs = commonArgs.nativeBuildInputs;
# Additional dev tools
packages = [
rustToolchain
pkgs.rust-analyzer
];
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
};
# Configuration for the non-Rust dependencies
buildInputs = with pkgs; [openssl.dev];
nativeBuildInputs = with pkgs; [rustc cargo pkgconfig];
buildEnvVars = {
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
};
in rec {
packages.${name} = project.workspaceMembers.${name}.build;
ci = pkgs.mkShell {
buildInputs = commonArgs.buildInputs ++ [
pkgs.nodePackages.markdown-link-check
pkgs.nixpkgs-fmt
rustToolchain
];
# `nix build`
defaultPackage = packages.${name};
nativeBuildInputs = commonArgs.nativeBuildInputs;
# `nix run`
apps.${name} = utils.lib.mkApp {
inherit name;
drv = packages.${name};
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
};
};
defaultApp = apps.${name};
# `nix develop`
devShells = {
ci =
pkgs.mkShell {
inherit nativeBuildInputs;
buildInputs = [pkgs.nodePackages.markdown-link-check pkgs.alejandra] ++ buildInputs;
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
}
// buildEnvVars;
default =
pkgs.mkShell
{
inherit buildInputs nativeBuildInputs;
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
}
// buildEnvVars;
# Optional: add checks for CI
checks = {
inherit sim-wrapper;
# Run cargo fmt check
fmt = craneLib.cargoFmt {
inherit (commonArgs) src;
};
# Run clippy
clippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
# Run tests
tests = craneLib.cargoTest (commonArgs // {
inherit cargoArtifacts;
});
};
}
);
});
}

View File

@@ -1,7 +1,7 @@
[package]
name = "generator"
version = "0.1.0"
edition = "2021"
edition.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@@ -1,5 +1,5 @@
use byteorder::{BigEndian, ByteOrder};
use clap::{builder::PossibleValue, Parser, ValueEnum};
use clap::{Parser, ValueEnum, builder::PossibleValue};
use haversine::haversine::{CoordinatePair, HaversineData};
use haversine::{distance, earth};
use json::json_object::JsonValue;
@@ -69,9 +69,9 @@ fn write_json(data: &HaversineData, json_filename: &str) {
let mut is_first = true;
for point in data.pairs.iter() {
if !is_first {
writer.write_all(&[b',']).unwrap();
writer.write_all(b",").unwrap();
}
writer.write_all(&[b'{']).unwrap();
writer.write_all(b"{").unwrap();
writer
.write_all(
format!(
@@ -81,7 +81,7 @@ fn write_json(data: &HaversineData, json_filename: &str) {
.as_bytes(),
)
.unwrap();
writer.write_all(&[b'}']).unwrap();
writer.write_all(b"}").unwrap();
is_first = false;
}
@@ -149,11 +149,7 @@ where
let x1 = range.sample(rng);
let x2 = range.sample(rng);
if x1 < x2 {
(x1, x2)
} else {
(x2, x1)
}
if x1 < x2 { (x1, x2) } else { (x2, x1) }
}
fn sample_point<R, D1, D2>(rng: &mut R, x_range: D1, y_range: D2) -> CoordinatePair

View File

@@ -1,7 +1,7 @@
[package]
name = "haversine-app"
version = "0.1.0"
edition = "2021"
edition.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@@ -18,7 +18,7 @@ struct Args {
fn read_answer(binary_filename: &str) -> (Vec<f64>, f64) {
let mut file = File::open(binary_filename).unwrap();
let file_size = file.metadata().unwrap().len();
if file_size % 8 != 0 {
if !file_size.is_multiple_of(8) {
panic!(
"Malformed input file of size {} is not a multiple of 8",
file_size
@@ -82,7 +82,10 @@ fn haversine_sum(v: &[CoordinatePair], reference: &[f64]) -> f64 {
for (count, pair) in v.iter().enumerate() {
let computed = distance::naive(pair, earth::RADIUS);
if computed != reference[count] {
println!("Different! At index {}, received pair: {:?}, computed distance {computed}, expected {}", count, pair, reference[count])
println!(
"Different! At index {}, received pair: {:?}, computed distance {computed}, expected {}",
count, pair, reference[count]
)
}
answer =
((1.0 - (1.0 / (count as f64 + 1.0))) * answer) + (computed / (count as f64 + 1.0));

View File

@@ -1,7 +1,7 @@
[package]
name = "haversine"
version = "0.1.0"
edition = "2021"
edition.workspace = true
[lib]

View File

@@ -4,6 +4,7 @@ fn square(x: f64) -> f64 {
x * x
}
#[must_use]
pub fn naive(point: &CoordinatePair, earth_radius: f64) -> f64 {
let lat1 = point.y0;
let lat2 = point.y1;

View File

@@ -1,7 +1,7 @@
[package]
name = "json"
version = "0.1.0"
edition = "2021"
edition.workspace = true
[lib]

View File

@@ -350,6 +350,7 @@ where
}
impl JsonValue {
#[must_use]
pub fn as_number(&self) -> f64 {
match self {
JsonValue::Number(f) => *f,
@@ -357,6 +358,7 @@ impl JsonValue {
}
}
#[must_use]
pub fn as_object(&self) -> &HashMap<String, JsonValue> {
match self {
JsonValue::Object(o) => &o.values,
@@ -364,6 +366,7 @@ impl JsonValue {
}
}
#[must_use]
pub fn as_array(&self) -> &Vec<JsonValue> {
match self {
JsonValue::Array(a) => a,
@@ -600,7 +603,7 @@ mod test {
panic!("oh no")
}
if let JsonValue::Boolean(is_student) = obj.values.get("isStudent").unwrap() {
assert_eq!(*is_student, false)
assert!(!(*is_student))
} else {
panic!("oh no")
}
@@ -818,7 +821,7 @@ mod test {
// Rust chose the float immediately above 1.23e-6; my computation
// chose the float immediately below.
let delta = expected - *actual;
assert_eq!(delta, 2.1175823681357508E-22);
assert_eq!(delta, 2.117_582_368_135_751E-22);
}
e => {
panic!("bad value: {:?}", e)
@@ -897,7 +900,7 @@ mod test {
fn borderline_example() {
let (parsed, remaining) = JsonValue::parse(&mut "-28.5175025263690110".chars()).unwrap();
assert_eq!(remaining, None);
let expected = -28.5175025263690110;
let expected = -28.517_502_526_369_01;
let actual = parsed.as_number();
assert_eq!(actual, expected);
}
@@ -917,7 +920,7 @@ mod test {
#[test]
fn haversine_example() {
let s = include_str!("example.json");
let parsed = parse_object(&s);
let parsed = parse_object(s);
let o = parsed.values.get("pairs").unwrap().as_array();
assert_eq!(o.len(), 20);
}

View File

@@ -1,7 +1,7 @@
[package]
name = "sim-wrapper"
version = "0.1.0"
edition = "2021"
edition.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@@ -43,10 +43,10 @@ where
.filter(|i| !matches!(i, Instruction::Trivia(_)));
for i1 in without_trivia_1 {
if let Some(i2) = without_trivia_2.next() {
if i1 != i2 {
return false;
}
if let Some(i2) = without_trivia_2.next()
&& i1 != i2
{
return false;
}
}
@@ -90,12 +90,18 @@ fn verify_consistency(pre_compiled: &Vec<u8>, asm: &str) {
let disassembled = Program::of_bytes(pre_compiled.iter().cloned());
if disassembled != compiled {
println!("Disassembled and compiled versions do not produce the same bytes. From disassembly:\n{}\nFrom assembling the input asm:\n{}", disassembled, compiled);
println!(
"Disassembled and compiled versions do not produce the same bytes. From disassembly:\n{}\nFrom assembling the input asm:\n{}",
disassembled, compiled
);
std::process::exit(3)
}
if !program_equal_ignoring_labels(&disassembled, &compiled) {
println!("Program failed to disassemble back to the compiled version. Compiled:\n{}\nDisassembled again:\n{}", compiled, disassembled);
println!(
"Program failed to disassemble back to the compiled version. Compiled:\n{}\nDisassembled again:\n{}",
compiled, disassembled
);
std::process::exit(4)
}

View File

@@ -1,7 +1,7 @@
[package]
name = "sim_8086"
version = "0.1.0"
edition = "2021"
edition.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@@ -90,6 +90,7 @@ impl ArithmeticInstruction {
(s as u8) * 8 + d * 2 + if is_wide { 1 } else { 0 }
}
#[must_use]
pub fn to_bytes(&self) -> Vec<u8> {
let mut result = Vec::<u8>::with_capacity(2);
match &self.instruction {
@@ -187,6 +188,7 @@ impl ArithmeticInstruction {
}
}
#[must_use]
pub fn clock_count(&self) -> (u32, String) {
match self.op {
ArithmeticOperation::Sub
@@ -299,6 +301,7 @@ impl Display for ArithmeticOperation {
}
impl ArithmeticOperation {
#[must_use]
pub const fn of_byte(x: u8) -> ArithmeticOperation {
match x {
0 => ArithmeticOperation::Add,

View File

@@ -1,4 +1,5 @@
use nom::{
IResult,
branch::alt,
bytes::complete::{is_not, tag},
character::complete::{
@@ -8,7 +9,6 @@ use nom::{
error::FromExternalError,
multi::{many0, many1},
sequence::{delimited, preceded, separated_pair, terminated, tuple},
IResult,
};
use crate::boolean_instruction::{
@@ -62,12 +62,11 @@ enum OffsetTag {
None,
}
fn bracketed<'a, F, O, E: nom::error::ParseError<&'a str>>(
inner: F,
) -> impl FnMut(&'a str) -> IResult<&'a str, (OffsetTag, O), E>
fn bracketed<'a, F, O, E>(inner: F) -> impl FnMut(&'a str) -> IResult<&'a str, (OffsetTag, O), E>
where
F: FnMut(&'a str) -> IResult<&'a str, O, E>,
E: FromExternalError<&'a str, ()>,
E: nom::error::ParseError<&'a str>,
{
map_res(
tuple((
@@ -203,10 +202,9 @@ fn literal_absolute_u8(input: &str) -> IResult<&str, u8> {
Err(())
}
})
.fold(Ok(0u8), |acc, new| match (acc, new) {
(Ok(acc), Ok(new)) => Ok(acc * 16 + new),
.try_fold(0u8, |acc, new| match (acc, new) {
(_, Err(())) => Err(()),
(Err(()), _) => Err(()),
(acc, Ok(new)) => Ok(acc * 16 + new),
})
}),
map_res(digit1, str::parse::<u8>),
@@ -227,10 +225,9 @@ fn literal_absolute_u16(input: &str) -> IResult<&str, u16> {
Err(())
}
})
.fold(Ok(0u16), |acc, new| match (acc, new) {
(Ok(acc), Ok(new)) => Ok(acc * 16 + new),
.try_fold(0u16, |acc, new| match (acc, new) {
(_, Err(())) => Err(()),
(Err(()), _) => Err(()),
(acc, Ok(new)) => Ok(acc * 16 + new),
})
}),
map_res(digit1, str::parse::<u16>),

View File

@@ -73,6 +73,7 @@ impl Display for BooleanInstruction {
}
impl BooleanInstruction {
#[must_use]
pub fn to_bytes(&self) -> Vec<u8> {
match &self.dest {
/*
@@ -154,6 +155,7 @@ impl BooleanInstruction {
}
}
#[must_use]
pub fn length(&self) -> u8 {
match &self.dest {
BooleanInstructionDestination::ImmediateToAcc(data) => match data {
@@ -164,6 +166,7 @@ impl BooleanInstruction {
}
}
#[must_use]
pub fn clock_count(&self) -> (u32, String) {
match self.selection {
BooleanInstructionType::Test => match self.dest {

View File

@@ -52,6 +52,7 @@ pub struct Registers {
}
impl Registers {
#[must_use]
pub fn diff(&self, old: &Registers) -> String {
let mut result = Vec::new();
@@ -264,6 +265,7 @@ struct ResultFlags {
impl Computer {
#[allow(clippy::new_without_default)]
#[must_use]
pub fn new() -> Computer {
Computer {
memory: [0; 65536],
@@ -291,6 +293,7 @@ impl Computer {
self.flags.set(f, v)
}
#[must_use]
pub fn dump_flag_state(&self) -> String {
format!("{}", self.flags)
}
@@ -1307,6 +1310,7 @@ impl Computer {
)
}
#[must_use]
pub fn get_program_counter(&self) -> u16 {
self.program_counter
}
@@ -1432,6 +1436,7 @@ impl Computer {
}
}
#[must_use]
pub fn dump_register_state(&self) -> String {
let mut result = "".to_owned();
for r in [

View File

@@ -111,12 +111,12 @@ impl EffectiveAddress {
if mode == 3 {
panic!("we don't handle this case, you need to do it manually to get a register")
}
let source_dest = if rm % 2 == 0 {
let source_dest = if rm.is_multiple_of(2) {
SourceDest::Source
} else {
SourceDest::Dest
};
let base = if (rm / 2) % 2 == 0 {
let base = if (rm / 2).is_multiple_of(2) {
Base::Bx
} else {
Base::Bp

View File

@@ -19,15 +19,18 @@ impl Display for IncInstruction {
}
impl IncInstruction {
#[must_use]
pub fn to_bytes(&self) -> Vec<u8> {
let (id, _is_wide) = self.target.to_id();
vec![0b01000000 + id + if self.is_inc { 0 } else { 8 }]
}
#[must_use]
pub fn length(&self) -> u8 {
1
}
#[must_use]
pub fn clock_count(&self) -> (u32, String) {
if self.target.is_wide() {
(2, "".to_owned())

View File

@@ -59,7 +59,8 @@ where
}
}
impl<'a> Instruction<&'a str> {
impl Instruction<&str> {
#[must_use]
pub fn to_bytes(&self) -> Vec<u8> {
match self {
Instruction::Move(mov) => mov.to_bytes(),
@@ -104,6 +105,7 @@ impl<'a> Instruction<&'a str> {
}
impl Instruction<i8> {
#[must_use]
pub fn to_bytes(&self) -> Vec<u8> {
match self {
Instruction::Move(mov) => mov.to_bytes(),

View File

@@ -54,6 +54,7 @@ impl Display for Jump {
}
impl Jump {
#[must_use]
pub fn clock_count(&self, is_success: bool) -> u32 {
match self {
Jump::Jle

View File

@@ -65,6 +65,7 @@ impl Display for LogicInstruction {
}
impl LogicInstruction {
#[must_use]
pub fn length(&self) -> u8 {
match &self.target {
LogicTarget::Register(_) => 2,
@@ -72,6 +73,7 @@ impl LogicInstruction {
}
}
#[must_use]
pub fn to_bytes(&self) -> Vec<u8> {
let mut result = Vec::new();
let byte = match self.op {
@@ -103,6 +105,7 @@ impl LogicInstruction {
result
}
#[must_use]
pub fn clock_count(&self) -> (u32, String) {
match (&self.op, &self.target) {
(LogicInstructionType::Not, LogicTarget::Register(_)) => (3, "".to_owned()),

View File

@@ -472,6 +472,7 @@ impl MoveInstruction {
}
}
#[must_use]
pub fn clock_count(&self) -> (u32, String) {
match self {
MoveInstruction::RegRegMove(_) => (2, "".to_owned()),

View File

@@ -37,10 +37,10 @@ where
}
let mut labels = HashMap::new();
for (counter, instruction) in self.instructions.as_ref().iter().enumerate() {
if let Instruction::Trivia(TriviaInstruction::Label(s)) = instruction {
if let Some(s) = labels.insert(s.trim(), counter) {
panic!("same label twice: {}", s)
}
if let Instruction::Trivia(TriviaInstruction::Label(s)) = instruction
&& let Some(s) = labels.insert(s.trim(), counter)
{
panic!("same label twice: {}", s)
}
}

View File

@@ -11,6 +11,7 @@ pub enum GeneralRegister {
}
impl GeneralRegister {
#[must_use]
pub const fn to_id(&self) -> u8 {
match self {
GeneralRegister::A => 0b00,
@@ -20,6 +21,7 @@ impl GeneralRegister {
}
}
#[must_use]
pub const fn of_id(id: u8) -> GeneralRegister {
match id {
0 => GeneralRegister::A,
@@ -51,6 +53,7 @@ pub enum SpecialRegister {
}
impl SpecialRegister {
#[must_use]
pub const fn to_id(&self) -> u8 {
// These are all wide.
4 + match self {
@@ -61,6 +64,7 @@ impl SpecialRegister {
}
}
#[must_use]
pub const fn of_id(id: u8) -> SpecialRegister {
match id {
4 => SpecialRegister::StackPointer,
@@ -125,6 +129,7 @@ impl Display for SegmentRegister {
}
impl SegmentRegister {
#[must_use]
pub const fn of_byte(b: u8) -> SegmentRegister {
match b {
0 => SegmentRegister::Extra,
@@ -152,6 +157,7 @@ impl Display for Register {
}
impl Register {
#[must_use]
pub const fn of_id(id: u8, is_wide: bool) -> Register {
if is_wide {
if id >= 4 {
@@ -173,6 +179,7 @@ impl Register {
}
// Returns true if the result is wide.
#[must_use]
pub const fn to_id(self: &Register) -> (u8, bool) {
match self {
Register::Special(s) => (s.to_id(), true),
@@ -184,6 +191,7 @@ impl Register {
}
}
#[must_use]
pub const fn is_wide(self: &Register) -> bool {
match self {
Register::Special(_) => true,

View File

@@ -94,17 +94,17 @@ mod test_program {
{
let disassembled = Program::of_bytes(input_bytecode.as_ref().iter().cloned());
let (remaining, pre_compiled) = assembly::program(&input_asm).unwrap();
let (remaining, pre_compiled) = assembly::program(input_asm).unwrap();
assert_eq!(remaining.trim(), "");
let disassembled = disassembled.instructions.iter().filter(|i| match i {
Instruction::Trivia(_) => false,
_ => true,
});
let mut compiled = pre_compiled.instructions.iter().filter(|i| match i {
Instruction::Trivia(_) => false,
_ => true,
});
let disassembled = disassembled
.instructions
.iter()
.filter(|i| !matches!(i, Instruction::Trivia(_)));
let mut compiled = pre_compiled
.instructions
.iter()
.filter(|i| !matches!(i, Instruction::Trivia(_)));
let mut is_different = false;
@@ -119,8 +119,7 @@ mod test_program {
{
println!(
"Different instruction. From disassembly: {dis} ({:?}). From our compilation: {compiled} ({:?}).",
dis_bytes,
compiled_bytes
dis_bytes, compiled_bytes
);
is_different = true;
}
@@ -134,7 +133,7 @@ mod test_program {
}
}
while let Some(compiled) = compiled.next() {
for compiled in compiled {
println!(
"Extra instruction from compilation: {compiled} ({:?})",
compiled.to_bytes()
@@ -143,7 +142,9 @@ mod test_program {
}
if is_different {
panic!("Disassembling input bytecode produced a different program from compiling the input asm.")
panic!(
"Disassembling input bytecode produced a different program from compiling the input asm."
)
}
}