Compare commits
9 Commits
0af4079832
...
fix-workfl
Author | SHA1 | Date | |
---|---|---|---|
|
9681a86ac1 | ||
|
5161a4162d | ||
|
7c08a57143 | ||
|
cf16c3a34d | ||
75c0a8f234 | |||
fa1eaf6f7c | |||
8eaebbb25c | |||
0be7c25034 | |||
f11d861eef |
27
.github/workflows/rust.yml
vendored
27
.github/workflows/rust.yml
vendored
@@ -220,19 +220,22 @@ jobs:
|
||||
|
||||
all-required-checks-complete:
|
||||
{
|
||||
"needs":
|
||||
[
|
||||
'nix-build',
|
||||
'nix-run',
|
||||
'build',
|
||||
'build-release',
|
||||
'alejandra',
|
||||
'clippy',
|
||||
'rust-fmt',
|
||||
'linkcheck',
|
||||
],
|
||||
"needs": [
|
||||
'nix-build',
|
||||
'nix-run',
|
||||
'build',
|
||||
'build-release',
|
||||
'alejandra',
|
||||
'clippy',
|
||||
'rust-fmt',
|
||||
'linkcheck',
|
||||
],
|
||||
"runs-on": "ubuntu-latest",
|
||||
"if": "${{ always() }}",
|
||||
"steps": [
|
||||
{ "run": "echo \"All required checks complete.\"" }
|
||||
{
|
||||
"uses": "Smaug123/all-required-checks-complete-action@05b40a8c47ef0b175ea326e9abb09802cb67b44e",
|
||||
"with": { "needs-context": "${{ toJson(needs) }}" }
|
||||
}
|
||||
]
|
||||
}
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -7,3 +7,6 @@ target/
|
||||
|
||||
data_*_flex.json
|
||||
data_*_haveranswer.f64
|
||||
.direnv/
|
||||
|
||||
result
|
||||
|
10
.woodpecker/.all-checks-complete.yml
Normal file
10
.woodpecker/.all-checks-complete.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
steps:
|
||||
echo:
|
||||
image: alpine
|
||||
commands:
|
||||
- echo "All required checks complete"
|
||||
|
||||
depends_on:
|
||||
- build
|
||||
|
||||
skip_clone: true
|
25
.woodpecker/.build.yml
Normal file
25
.woodpecker/.build.yml
Normal file
@@ -0,0 +1,25 @@
|
||||
steps:
|
||||
build:
|
||||
image: nixos/nix
|
||||
commands:
|
||||
- echo 'experimental-features = flakes nix-command' >> /etc/nix/nix.conf
|
||||
# Lint
|
||||
- nix develop .#ci --command cargo -- fmt --all -- --check
|
||||
- nix develop --command cargo -- clippy -- -D warnings -W clippy::must_use_candidate
|
||||
- nix develop .#ci --command alejandra -- --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 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"
|
72
flake.lock
generated
72
flake.lock
generated
@@ -3,11 +3,11 @@
|
||||
"crate2nix": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1678820090,
|
||||
"narHash": "sha256-4FFeonajXNqiSP0PqUlC1wmTyPC8SX6SthEvgRjMupw=",
|
||||
"lastModified": 1719760654,
|
||||
"narHash": "sha256-L3VIJ9182wsYJqP27xO5qiWwfK+a00x0JHiy8ns3NQE=",
|
||||
"owner": "kolloch",
|
||||
"repo": "crate2nix",
|
||||
"rev": "4fd826e37bec90dfe26ca16cb6e632c617cc7c0d",
|
||||
"rev": "a6ca1e58132bab26fc08572f22a34bbb86f4d91d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -19,11 +19,11 @@
|
||||
"flake-compat": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1673956053,
|
||||
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
|
||||
"lastModified": 1696426674,
|
||||
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
|
||||
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -32,28 +32,13 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1659877975,
|
||||
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1679705136,
|
||||
"narHash": "sha256-MDlZUR7wJ3PlPtqwwoGQr3euNOe0vdSSteVVOef7tBY=",
|
||||
"lastModified": 1720768451,
|
||||
"narHash": "sha256-EYekUHJE2gxeo2pM/zM9Wlqw1Uw2XTJXOSAO79ksc4Y=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "8f40f2f90b9c9032d1b824442cfbbe0dbabd0dbd",
|
||||
"rev": "7e7c39ea35c5cdd002cd4588b03a3fb9ece6fad9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -65,11 +50,11 @@
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1679734080,
|
||||
"narHash": "sha256-z846xfGLlon6t9lqUzlNtBOmsgQLQIZvR6Lt2dImk1M=",
|
||||
"lastModified": 1718428119,
|
||||
"narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "dbf5322e93bcc6cfc52268367a8ad21c09d76fea",
|
||||
"rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -90,15 +75,14 @@
|
||||
},
|
||||
"rust-overlay": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1679106165,
|
||||
"narHash": "sha256-03Opt2yu4E/AIFjvlgib0/nhMn6B4B/t/nvwS2bzOGw=",
|
||||
"lastModified": 1720923816,
|
||||
"narHash": "sha256-GrDL1nFYZrB/+Ah1hNoaNFfduB1agpfqL9QyEl12UOU=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "7313c06ac334d6262ddfe30a38b3abc3da6bd565",
|
||||
"rev": "fb8c8be0313f0e6385b3d70151a04ea1d71e4b68",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -107,13 +91,31 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"utils": {
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1678901627,
|
||||
"narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=",
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
14
flake.nix
14
flake.nix
@@ -16,7 +16,6 @@
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
utils,
|
||||
rust-overlay,
|
||||
@@ -33,13 +32,6 @@
|
||||
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;
|
||||
})
|
||||
];
|
||||
};
|
||||
inherit
|
||||
@@ -71,8 +63,8 @@
|
||||
};
|
||||
|
||||
# Configuration for the non-Rust dependencies
|
||||
buildInputs = with pkgs; [openssl.dev];
|
||||
nativeBuildInputs = with pkgs; [rustc cargo pkgconfig];
|
||||
buildInputs = [pkgs.openssl.dev];
|
||||
nativeBuildInputs = with pkgs; [rustc cargo pkg-config];
|
||||
buildEnvVars = {
|
||||
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
|
||||
};
|
||||
@@ -94,7 +86,7 @@
|
||||
ci =
|
||||
pkgs.mkShell {
|
||||
inherit nativeBuildInputs;
|
||||
buildInputs = [pkgs.nodePackages.markdown-link-check pkgs.alejandra] ++ buildInputs;
|
||||
buildInputs = [pkgs.cargo-fmt pkgs.nodePackages.markdown-link-check pkgs.alejandra] ++ buildInputs;
|
||||
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||
}
|
||||
// buildEnvVars;
|
||||
|
@@ -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;
|
||||
|
@@ -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,
|
||||
|
@@ -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,
|
||||
|
@@ -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 {
|
||||
|
@@ -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 [
|
||||
|
@@ -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())
|
||||
|
@@ -60,6 +60,7 @@ where
|
||||
}
|
||||
|
||||
impl<'a> Instruction<&'a 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(),
|
||||
|
@@ -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
|
||||
|
@@ -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()),
|
||||
|
@@ -472,6 +472,7 @@ impl MoveInstruction {
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn clock_count(&self) -> (u32, String) {
|
||||
match self {
|
||||
MoveInstruction::RegRegMove(_) => (2, "".to_owned()),
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user