Add warnings
This commit is contained in:
@@ -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