Compare commits

...

7 Commits

Author SHA1 Message Date
Smaug123
0af4079832 Kick pipeline
Some checks failed
ci/woodpecker/push/all-checks-complete Pipeline is pending
ci/woodpecker/pr/build Pipeline is pending
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/pr/all-checks-complete unknown status
2023-07-30 15:02:16 +01:00
Smaug123
f4ab3acfd6 Fix
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
ci/woodpecker/pr/all-checks-complete Pipeline was successful
2023-07-24 23:40:12 +01:00
Smaug123
8686bd5154 Fix
Some checks failed
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/pr/all-checks-complete unknown status
ci/woodpecker/push/build Pipeline failed
ci/woodpecker/push/all-checks-complete unknown status
2023-07-24 20:01:02 +01:00
Smaug123
a1f0557fa0 Add warnings
Some checks failed
ci/woodpecker/push/build Pipeline failed
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/push/all-checks-complete unknown status
ci/woodpecker/pr/all-checks-complete unknown status
2023-07-24 19:35:07 +01:00
Smaug123
136b2d733d Kick pipeline
Some checks failed
ci/woodpecker/push/build Pipeline failed
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/push/all-checks-complete unknown status
ci/woodpecker/pr/all-checks-complete unknown status
2023-07-24 19:18:06 +01:00
Smaug123
cf36dd20fd Add pipeline 2023-07-24 18:46:30 +01:00
Smaug123
9c1b30cad7 A change 2023-07-24 18:42:42 +01:00
14 changed files with 67 additions and 0 deletions

View File

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

23
.woodpecker/.build.yml Normal file
View File

@@ -0,0 +1,23 @@
pipeline:
build:
image: nixos/nix
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 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:
evaluate: '(CI_BUILD_EVENT == "push" && CI_COMMIT_BRANCH == CI_REPO_DEFAULT_BRANCH) || (CI_BUILD_EVENT == "pull_request")'

View File

@@ -9,3 +9,4 @@ It does, however, conform to all Casey's provided test cases except the "complet
The code in this repo is MIT-licensed. The code in this repo is MIT-licensed.
However, note that the included submodule is licensed *very* restrictively, and you might not even be permitted to clone it. However, note that the included submodule is licensed *very* restrictively, and you might not even be permitted to clone it.
askldfjl

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

@@ -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,

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

@@ -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

@@ -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

@@ -60,6 +60,7 @@ where
} }
impl<'a> Instruction<&'a str> { impl<'a> Instruction<&'a 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

@@ -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,