Skip to content

Commit 73df1a7

Browse files
Samuel OrtizSamuel Ortiz
authored andcommitted
do-core1: First do-core usage
Signed-off-by: Samuel Ortiz <samuel.e.ortiz@protonmail.com>
1 parent 46e1aa1 commit 73df1a7

1 file changed

Lines changed: 2 additions & 29 deletions

File tree

src/main.rs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use clap::Parser;
2+
use do_core::instruction::OpCode;
3+
use do_core::Error;
24

35
#[derive(Parser)]
46
#[clap(version, author)]
@@ -15,14 +17,6 @@ struct Instruction {
1517
op1: u8,
1618
}
1719

18-
#[derive(Debug)]
19-
enum Error {
20-
InvalidOpCode(u8),
21-
Op0OutOfRange,
22-
Op1OutOfRange,
23-
AdditionOverflow(u32, u32),
24-
}
25-
2620
// do-core1 register indexes range from 0 to 31.
2721
const MAX_REGISTER_INDEX: u8 = 31;
2822

@@ -50,27 +44,6 @@ impl Instruction {
5044
}
5145
}
5246

53-
#[allow(dead_code)]
54-
#[derive(Debug, PartialEq)]
55-
enum OpCode {
56-
LDW = 0x00,
57-
STW = 0x01,
58-
ADD = 0x02,
59-
XOR = 0x03,
60-
}
61-
62-
impl OpCode {
63-
fn from_u8(opcode: u8) -> Result<OpCode, Error> {
64-
match opcode {
65-
0x00 => Ok(OpCode::LDW),
66-
0x01 => Ok(OpCode::STW),
67-
0x02 => Ok(OpCode::ADD),
68-
0x03 => Ok(OpCode::XOR),
69-
_ => Err(Error::InvalidOpCode(opcode)),
70-
}
71-
}
72-
}
73-
7447
fn add(op0: u32, op1: u32) -> Result<u32, Error> {
7548
op0.checked_add(op1)
7649
.ok_or(Error::AdditionOverflow(op0, op1))

0 commit comments

Comments
 (0)