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

98
flake.lock generated
View File

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

191
flake.nix
View File

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

View File

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

View File

@@ -1,7 +1,7 @@
[package] [package]
name = "haversine-app" name = "haversine-app"
version = "0.1.0" 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 # 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) { fn read_answer(binary_filename: &str) -> (Vec<f64>, f64) {
let mut file = File::open(binary_filename).unwrap(); let mut file = File::open(binary_filename).unwrap();
let file_size = file.metadata().unwrap().len(); let file_size = file.metadata().unwrap().len();
if file_size % 8 != 0 { if !file_size.is_multiple_of(8) {
panic!( panic!(
"Malformed input file of size {} is not a multiple of 8", "Malformed input file of size {} is not a multiple of 8",
file_size file_size
@@ -82,7 +82,10 @@ fn haversine_sum(v: &[CoordinatePair], reference: &[f64]) -> f64 {
for (count, pair) in v.iter().enumerate() { for (count, pair) in v.iter().enumerate() {
let computed = distance::naive(pair, earth::RADIUS); let computed = distance::naive(pair, earth::RADIUS);
if computed != reference[count] { 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 = answer =
((1.0 - (1.0 / (count as f64 + 1.0))) * answer) + (computed / (count as f64 + 1.0)); ((1.0 - (1.0 / (count as f64 + 1.0))) * answer) + (computed / (count as f64 + 1.0));

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
[package] [package]
name = "sim-wrapper" name = "sim-wrapper"
version = "0.1.0" 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 # 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(_))); .filter(|i| !matches!(i, Instruction::Trivia(_)));
for i1 in without_trivia_1 { for i1 in without_trivia_1 {
if let Some(i2) = without_trivia_2.next() { if let Some(i2) = without_trivia_2.next()
if i1 != i2 { && i1 != i2
return false; {
} return false;
} }
} }
@@ -90,12 +90,18 @@ fn verify_consistency(pre_compiled: &Vec<u8>, asm: &str) {
let disassembled = Program::of_bytes(pre_compiled.iter().cloned()); let disassembled = Program::of_bytes(pre_compiled.iter().cloned());
if disassembled != compiled { 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) std::process::exit(3)
} }
if !program_equal_ignoring_labels(&disassembled, &compiled) { 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) std::process::exit(4)
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -19,15 +19,18 @@ impl Display for IncInstruction {
} }
impl IncInstruction { impl IncInstruction {
#[must_use]
pub fn to_bytes(&self) -> Vec<u8> { pub fn to_bytes(&self) -> Vec<u8> {
let (id, _is_wide) = self.target.to_id(); let (id, _is_wide) = self.target.to_id();
vec![0b01000000 + id + if self.is_inc { 0 } else { 8 }] vec![0b01000000 + id + if self.is_inc { 0 } else { 8 }]
} }
#[must_use]
pub fn length(&self) -> u8 { pub fn length(&self) -> u8 {
1 1
} }
#[must_use]
pub fn clock_count(&self) -> (u32, String) { pub fn clock_count(&self) -> (u32, String) {
if self.target.is_wide() { if self.target.is_wide() {
(2, "".to_owned()) (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> { pub fn to_bytes(&self) -> Vec<u8> {
match self { match self {
Instruction::Move(mov) => mov.to_bytes(), Instruction::Move(mov) => mov.to_bytes(),
@@ -104,6 +105,7 @@ impl<'a> Instruction<&'a str> {
} }
impl Instruction<i8> { impl Instruction<i8> {
#[must_use]
pub fn to_bytes(&self) -> Vec<u8> { pub fn to_bytes(&self) -> Vec<u8> {
match self { match self {
Instruction::Move(mov) => mov.to_bytes(), Instruction::Move(mov) => mov.to_bytes(),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -94,17 +94,17 @@ mod test_program {
{ {
let disassembled = Program::of_bytes(input_bytecode.as_ref().iter().cloned()); 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(), ""); assert_eq!(remaining.trim(), "");
let disassembled = disassembled.instructions.iter().filter(|i| match i { let disassembled = disassembled
Instruction::Trivia(_) => false, .instructions
_ => true, .iter()
}); .filter(|i| !matches!(i, Instruction::Trivia(_)));
let mut compiled = pre_compiled.instructions.iter().filter(|i| match i { let mut compiled = pre_compiled
Instruction::Trivia(_) => false, .instructions
_ => true, .iter()
}); .filter(|i| !matches!(i, Instruction::Trivia(_)));
let mut is_different = false; let mut is_different = false;
@@ -119,8 +119,7 @@ mod test_program {
{ {
println!( println!(
"Different instruction. From disassembly: {dis} ({:?}). From our compilation: {compiled} ({:?}).", "Different instruction. From disassembly: {dis} ({:?}). From our compilation: {compiled} ({:?}).",
dis_bytes, dis_bytes, compiled_bytes
compiled_bytes
); );
is_different = true; is_different = true;
} }
@@ -134,7 +133,7 @@ mod test_program {
} }
} }
while let Some(compiled) = compiled.next() { for compiled in compiled {
println!( println!(
"Extra instruction from compilation: {compiled} ({:?})", "Extra instruction from compilation: {compiled} ({:?})",
compiled.to_bytes() compiled.to_bytes()
@@ -143,7 +142,9 @@ mod test_program {
} }
if is_different { 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."
)
} }
} }