misc: revert "purged .unwrap()"
Harry is an idiot @zxq5 is also an idiot
This reverts commit d4e538a2b3.
This commit is contained in:
+32
-69
@@ -22,17 +22,13 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
match opcode {
|
match opcode {
|
||||||
Opcode::Nop => Ok(Instruction::Nop),
|
Opcode::Nop => Ok(Instruction::Nop),
|
||||||
Opcode::Mov => {
|
Opcode::Mov => {
|
||||||
let src =
|
let src = expect_token!(args.first().unwrap(), Register)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
let dest = expect_token!(args.get(1).unwrap(), Register)?;
|
||||||
let dest =
|
|
||||||
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
|
||||||
Ok(Instruction::Mov(args!(R, sr1: src, dr: dest)))
|
Ok(Instruction::Mov(args!(R, sr1: src, dr: dest)))
|
||||||
}
|
}
|
||||||
Opcode::Movs => {
|
Opcode::Movs => {
|
||||||
let src =
|
let src = expect_token!(args.first().unwrap(), Register)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
let dest = expect_token!(args.get(1).unwrap(), Register)?;
|
||||||
let dest =
|
|
||||||
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
|
||||||
Ok(Instruction::MovSigned(args!(R, sr1: src, dr: dest)))
|
Ok(Instruction::MovSigned(args!(R, sr1: src, dr: dest)))
|
||||||
}
|
}
|
||||||
Opcode::Ldb
|
Opcode::Ldb
|
||||||
@@ -43,12 +39,9 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
| Opcode::Stb
|
| Opcode::Stb
|
||||||
| Opcode::Stw
|
| Opcode::Stw
|
||||||
| Opcode::Sth => {
|
| Opcode::Sth => {
|
||||||
let base =
|
let base = expect_token!(args.first().unwrap(), Register)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
let dest = expect_token!(args.get(1).unwrap(), Register)?;
|
||||||
let dest =
|
let offset = expect_token!(args.get(2).unwrap(), Immediate)?;
|
||||||
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
|
||||||
let offset =
|
|
||||||
expect_token!(args.get(2).expect("The spanish Inquisition"), Immediate)?;
|
|
||||||
let args = args!(I, immediate: offset as u16, r1: base, r2: dest);
|
let args = args!(I, immediate: offset as u16, r1: base, r2: dest);
|
||||||
|
|
||||||
match opcode {
|
match opcode {
|
||||||
@@ -64,20 +57,15 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Opcode::Lli => {
|
Opcode::Lli => {
|
||||||
let value =
|
let value = expect_token!(args.first().unwrap(), Immediate)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Immediate)?;
|
let dest = expect_token!(args.get(1).unwrap(), Register)?;
|
||||||
let dest =
|
|
||||||
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
|
||||||
let args = args!(I, immediate: value as u16, r1: dest);
|
let args = args!(I, immediate: value as u16, r1: dest);
|
||||||
|
|
||||||
Ok(Instruction::LoadLowerImmediate(args))
|
Ok(Instruction::LoadLowerImmediate(args))
|
||||||
}
|
}
|
||||||
Opcode::Lui => {
|
Opcode::Lui => {
|
||||||
let value =
|
let value = expect_token!(args.first().unwrap(), Immediate)? >> 16;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Immediate)?
|
let dest = expect_token!(args.get(1).unwrap(), Register)?;
|
||||||
>> 16;
|
|
||||||
let dest =
|
|
||||||
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
|
||||||
let args = args!(I, immediate: value as u16, r1: dest);
|
let args = args!(I, immediate: value as u16, r1: dest);
|
||||||
|
|
||||||
Ok(Instruction::LoadUpperImmediate(args))
|
Ok(Instruction::LoadUpperImmediate(args))
|
||||||
@@ -89,10 +77,8 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
| Opcode::Jge
|
| Opcode::Jge
|
||||||
| Opcode::Jlt
|
| Opcode::Jlt
|
||||||
| Opcode::Jle => {
|
| Opcode::Jle => {
|
||||||
let address =
|
let address = expect_token!(args.first().unwrap(), Immediate)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Immediate)?;
|
let offset = expect_token!(args.get(1).unwrap(), Register)?;
|
||||||
let offset =
|
|
||||||
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
|
||||||
let args = args!(I, immediate: address as u16, r1: offset);
|
let args = args!(I, immediate: address as u16, r1: offset);
|
||||||
|
|
||||||
match opcode {
|
match opcode {
|
||||||
@@ -107,36 +93,26 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Opcode::Cmp => {
|
Opcode::Cmp => {
|
||||||
let left =
|
let left = expect_token!(args.first().unwrap(), Register)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
let right = expect_token!(args.get(1).unwrap(), Register)?;
|
||||||
let right =
|
|
||||||
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
|
||||||
Ok(Instruction::Compare(args!(R, sr1: left, sr2: right)))
|
Ok(Instruction::Compare(args!(R, sr1: left, sr2: right)))
|
||||||
}
|
}
|
||||||
Opcode::Inc => {
|
Opcode::Inc => {
|
||||||
let reg =
|
let reg = expect_token!(args.first().unwrap(), Register)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
|
||||||
Ok(Instruction::Increment(args!(R, sr1: reg)))
|
Ok(Instruction::Increment(args!(R, sr1: reg)))
|
||||||
}
|
}
|
||||||
Opcode::Dec => {
|
Opcode::Dec => {
|
||||||
let reg =
|
let reg = expect_token!(args.first().unwrap(), Register)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
|
||||||
Ok(Instruction::Decrement(args!(R, sr1: reg)))
|
Ok(Instruction::Decrement(args!(R, sr1: reg)))
|
||||||
}
|
}
|
||||||
Opcode::Shl => {
|
Opcode::Shl => {
|
||||||
let reg =
|
let reg = expect_token!(args.first().unwrap(), Register)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
let amount = expect_token!(args.get(1).unwrap(), Immediate)? as u8;
|
||||||
let amount =
|
|
||||||
expect_token!(args.get(1).expect("The spanish Inquisition"), Immediate)?
|
|
||||||
as u8;
|
|
||||||
Ok(Instruction::ShiftLeft(args!(R, sr1: reg, shamt: amount)))
|
Ok(Instruction::ShiftLeft(args!(R, sr1: reg, shamt: amount)))
|
||||||
}
|
}
|
||||||
Opcode::Shr => {
|
Opcode::Shr => {
|
||||||
let reg =
|
let reg = expect_token!(args.first().unwrap(), Register)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
let amount = expect_token!(args.get(1).unwrap(), Immediate)? as u8;
|
||||||
let amount =
|
|
||||||
expect_token!(args.get(1).expect("The spanish Inquisition"), Immediate)?
|
|
||||||
as u8;
|
|
||||||
Ok(Instruction::ShiftRight(args!(R, sr1: reg, shamt: amount)))
|
Ok(Instruction::ShiftRight(args!(R, sr1: reg, shamt: amount)))
|
||||||
}
|
}
|
||||||
Opcode::Add
|
Opcode::Add
|
||||||
@@ -147,12 +123,9 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
| Opcode::Nand
|
| Opcode::Nand
|
||||||
| Opcode::Nor
|
| Opcode::Nor
|
||||||
| Opcode::Xnor => {
|
| Opcode::Xnor => {
|
||||||
let left =
|
let left = expect_token!(args.first().unwrap(), Register)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
let right = expect_token!(args.get(1).unwrap(), Register)?;
|
||||||
let right =
|
let dest = expect_token!(args.get(2).unwrap(), Register)?;
|
||||||
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
|
||||||
let dest =
|
|
||||||
expect_token!(args.get(2).expect("The spanish Inquisition"), Register)?;
|
|
||||||
let args = args!(R, sr1: left, sr2: right, dr: dest);
|
let args = args!(R, sr1: left, sr2: right, dr: dest);
|
||||||
|
|
||||||
match opcode {
|
match opcode {
|
||||||
@@ -168,13 +141,9 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Opcode::Iadd | Opcode::Isub => {
|
Opcode::Iadd | Opcode::Isub => {
|
||||||
let reg =
|
let reg = expect_token!(args.first().unwrap(), Register)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
let immediate = expect_token!(args.get(1).unwrap(), Immediate)? as u16;
|
||||||
let immediate =
|
let dest = expect_token!(args.get(2).unwrap(), Register)?;
|
||||||
expect_token!(args.get(1).expect("The spanish Inquisition"), Immediate)?
|
|
||||||
as u16;
|
|
||||||
let dest =
|
|
||||||
expect_token!(args.get(2).expect("The spanish Inquisition"), Register)?;
|
|
||||||
let args = args!(I, immediate: immediate, r1: reg, r2: dest);
|
let args = args!(I, immediate: immediate, r1: reg, r2: dest);
|
||||||
|
|
||||||
match opcode {
|
match opcode {
|
||||||
@@ -184,28 +153,22 @@ fn build_instruction(node: Node) -> Result<Instruction, AssembleError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Opcode::Not => {
|
Opcode::Not => {
|
||||||
let reg =
|
let reg = expect_token!(args.first().unwrap(), Register)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Register)?;
|
let dest = expect_token!(args.get(1).unwrap(), Register)?;
|
||||||
let dest =
|
|
||||||
expect_token!(args.get(1).expect("The spanish Inquisition"), Register)?;
|
|
||||||
Ok(Instruction::Not(args!(R, sr1: reg, dr: dest)))
|
Ok(Instruction::Not(args!(R, sr1: reg, dr: dest)))
|
||||||
}
|
}
|
||||||
Opcode::Int => {
|
Opcode::Int => {
|
||||||
let code =
|
let code = expect_token!(args.first().unwrap(), Immediate)? as u8;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Immediate)?
|
|
||||||
as u8;
|
|
||||||
Ok(Instruction::Interrupt(Interrupt::Software(code)))
|
Ok(Instruction::Interrupt(Interrupt::Software(code)))
|
||||||
}
|
}
|
||||||
Opcode::Irt => Ok(Instruction::IntReturn),
|
Opcode::Irt => Ok(Instruction::IntReturn),
|
||||||
Opcode::Hlt => Ok(Instruction::Halt),
|
Opcode::Hlt => Ok(Instruction::Halt),
|
||||||
Opcode::Data => {
|
Opcode::Data => {
|
||||||
let immediate =
|
let immediate = expect_token!(args.first().unwrap(), Immediate)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Immediate)?;
|
|
||||||
Ok(Instruction::Data(immediate))
|
Ok(Instruction::Data(immediate))
|
||||||
}
|
}
|
||||||
Opcode::Segment => {
|
Opcode::Segment => {
|
||||||
let immediate =
|
let immediate = expect_token!(args.first().unwrap(), Immediate)?;
|
||||||
expect_token!(args.first().expect("The spanish Inquisition"), Immediate)?;
|
|
||||||
Ok(Instruction::Segment(immediate))
|
Ok(Instruction::Segment(immediate))
|
||||||
}
|
}
|
||||||
Opcode::Db
|
Opcode::Db
|
||||||
|
|||||||
+13
-22
@@ -44,7 +44,7 @@ fn try_expand(
|
|||||||
|
|
||||||
fn expand_push(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
fn expand_push(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||||
let label = current.label();
|
let label = current.label();
|
||||||
let reg = expect_type!(current.arg(0).expect("The spanish Inquisition"), Register)?;
|
let reg = expect_type!(current.arg(0).unwrap(), Register)?;
|
||||||
|
|
||||||
nodes.extend(vec![
|
nodes.extend(vec![
|
||||||
node!(
|
node!(
|
||||||
@@ -68,7 +68,7 @@ fn expand_push(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError
|
|||||||
|
|
||||||
fn expand_pop(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
fn expand_pop(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||||
let label = current.label();
|
let label = current.label();
|
||||||
let reg = expect_type!(current.arg(0).expect("The spanish Inquisition"), Register)?;
|
let reg = expect_type!(current.arg(0).unwrap(), Register)?;
|
||||||
|
|
||||||
nodes.extend(vec![
|
nodes.extend(vec![
|
||||||
node!(
|
node!(
|
||||||
@@ -92,10 +92,9 @@ fn expand_pop(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError>
|
|||||||
|
|
||||||
fn expand_ldx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
fn expand_ldx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||||
let opcode = current.opcode();
|
let opcode = current.opcode();
|
||||||
let name = expect_type!(current.arg(0).expect("The spanish Inquisition"), Symbol)?;
|
let name = expect_type!(current.arg(0).unwrap(), Symbol)?;
|
||||||
let reg = expect_type!(current.arg(1).expect("The spanish Inquisition"), Register)?;
|
let reg = expect_type!(current.arg(1).unwrap(), Register)?;
|
||||||
let offset =
|
let offset = expect_type!(current.arg(2).unwrap(), Immediate)?;
|
||||||
expect_type!(current.arg(2).expect("The spanish Inquisition"), Immediate)?;
|
|
||||||
|
|
||||||
nodes.extend(vec![
|
nodes.extend(vec![
|
||||||
node!(current.label(), Opcode::Lli, name.clone(), reg.clone()),
|
node!(current.label(), Opcode::Lli, name.clone(), reg.clone()),
|
||||||
@@ -108,10 +107,9 @@ fn expand_ldx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError>
|
|||||||
|
|
||||||
fn expand_stx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
fn expand_stx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||||
let opcode = current.opcode();
|
let opcode = current.opcode();
|
||||||
let base = expect_type!(current.arg(0).expect("The spanish Inquisition"), Register)?;
|
let base = expect_type!(current.arg(0).unwrap(), Register)?;
|
||||||
let dest = expect_type!(current.arg(1).expect("The spanish Inquisition"), Symbol)?;
|
let dest = expect_type!(current.arg(1).unwrap(), Symbol)?;
|
||||||
let offset =
|
let offset = expect_type!(current.arg(2).unwrap(), Immediate)?;
|
||||||
expect_type!(current.arg(2).expect("The spanish Inquisition"), Immediate)?;
|
|
||||||
nodes.extend(vec![
|
nodes.extend(vec![
|
||||||
node!(
|
node!(
|
||||||
current.label(),
|
current.label(),
|
||||||
@@ -132,12 +130,8 @@ fn expand_stx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError>
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn expand_lwi(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
fn expand_lwi(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||||
let val = expect_type!(
|
let val = expect_type!(current.arg(0).unwrap(), Symbol, Immediate)?;
|
||||||
current.arg(0).expect("The spanish Inquisition"),
|
let reg = expect_type!(current.arg(1).unwrap(), Register)?;
|
||||||
Symbol,
|
|
||||||
Immediate
|
|
||||||
)?;
|
|
||||||
let reg = expect_type!(current.arg(1).expect("The spanish Inquisition"), Register)?;
|
|
||||||
|
|
||||||
nodes.extend(vec![
|
nodes.extend(vec![
|
||||||
node!(current.label(), Opcode::Lli, val.clone(), reg.clone()),
|
node!(current.label(), Opcode::Lli, val.clone(), reg.clone()),
|
||||||
@@ -148,10 +142,8 @@ fn expand_lwi(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError>
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn expand_resx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
fn expand_resx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||||
let region_label =
|
let region_label = expect_token!(current.arg(0).unwrap(), Symbol)?;
|
||||||
expect_token!(current.arg(0).expect("The spanish Inquisition"), Symbol)?;
|
let size = expect_token!(current.arg(1).unwrap(), Immediate)?;
|
||||||
let size =
|
|
||||||
expect_token!(current.arg(1).expect("The spanish Inquisition"), Immediate)?;
|
|
||||||
|
|
||||||
let units_per = match current.opcode() {
|
let units_per = match current.opcode() {
|
||||||
Opcode::Resb => 4,
|
Opcode::Resb => 4,
|
||||||
@@ -173,8 +165,7 @@ fn expand_resx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn expand_dx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
fn expand_dx(current: Node, nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||||
let region_label =
|
let region_label = expect_token!(current.arg(0).unwrap(), Symbol)?;
|
||||||
expect_token!(current.arg(0).expect("The spanish Inquisition"), Symbol)?;
|
|
||||||
let size = match current.opcode() {
|
let size = match current.opcode() {
|
||||||
Opcode::Db => 4,
|
Opcode::Db => 4,
|
||||||
Opcode::Dh => 2,
|
Opcode::Dh => 2,
|
||||||
|
|||||||
+12
-27
@@ -59,10 +59,7 @@ impl Parser {
|
|||||||
let mut dependencies = Vec::new();
|
let mut dependencies = Vec::new();
|
||||||
for node in nodes {
|
for node in nodes {
|
||||||
if let Opcode::Include = node.opcode() {
|
if let Opcode::Include = node.opcode() {
|
||||||
let path = expect_token!(
|
let path = expect_token!(node.args().get(1).unwrap(), StringLit)?;
|
||||||
node.args().get(1).expect("The spanish Inquisition"),
|
|
||||||
StringLit
|
|
||||||
)?;
|
|
||||||
dependencies.push(PathBuf::from(path));
|
dependencies.push(PathBuf::from(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -245,16 +242,12 @@ impl Parser {
|
|||||||
Opcode::Db => {
|
Opcode::Db => {
|
||||||
// db can take string literals or u8 immediates
|
// db can take string literals or u8 immediates
|
||||||
while !self.tokens.is_empty() {
|
while !self.tokens.is_empty() {
|
||||||
match self.tokens.last().expect("The spanish Inquisition") {
|
match self.tokens.last().unwrap() {
|
||||||
Token::StringLit(_) => {
|
Token::StringLit(_) => {
|
||||||
values.push(
|
values.push(self.tokens.pop().unwrap());
|
||||||
self.tokens.pop().expect("The spanish Inquisition"),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Token::Immediate(val) if *val <= u8::MAX as u32 => {
|
Token::Immediate(val) if *val <= u8::MAX as u32 => {
|
||||||
values.push(
|
values.push(self.tokens.pop().unwrap());
|
||||||
self.tokens.pop().expect("The spanish Inquisition"),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
_ => break,
|
_ => break,
|
||||||
}
|
}
|
||||||
@@ -264,16 +257,12 @@ impl Parser {
|
|||||||
Opcode::Dh => {
|
Opcode::Dh => {
|
||||||
// dh can take u16 immediates
|
// dh can take u16 immediates
|
||||||
while !self.tokens.is_empty() {
|
while !self.tokens.is_empty() {
|
||||||
match self.tokens.last().expect("The spanish Inquisition") {
|
match self.tokens.last().unwrap() {
|
||||||
Token::StringLit(_) => {
|
Token::StringLit(_) => {
|
||||||
values.push(
|
values.push(self.tokens.pop().unwrap());
|
||||||
self.tokens.pop().expect("The spanish Inquisition"),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Token::Immediate(val) if *val <= u16::MAX as u32 => {
|
Token::Immediate(val) if *val <= u16::MAX as u32 => {
|
||||||
values.push(
|
values.push(self.tokens.pop().unwrap());
|
||||||
self.tokens.pop().expect("The spanish Inquisition"),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
_ => break,
|
_ => break,
|
||||||
}
|
}
|
||||||
@@ -283,16 +272,12 @@ impl Parser {
|
|||||||
Opcode::Dw => {
|
Opcode::Dw => {
|
||||||
// dw can take u32 immediates
|
// dw can take u32 immediates
|
||||||
while !self.tokens.is_empty() {
|
while !self.tokens.is_empty() {
|
||||||
match self.tokens.last().expect("The spanish Inquisition") {
|
match self.tokens.last().unwrap() {
|
||||||
Token::StringLit(_) => {
|
Token::StringLit(_) => {
|
||||||
values.push(
|
values.push(self.tokens.pop().unwrap());
|
||||||
self.tokens.pop().expect("The spanish Inquisition"),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Token::Immediate(_) => {
|
Token::Immediate(_) => {
|
||||||
values.push(
|
values.push(self.tokens.pop().unwrap());
|
||||||
self.tokens.pop().expect("The spanish Inquisition"),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
_ => break,
|
_ => break,
|
||||||
}
|
}
|
||||||
@@ -309,7 +294,7 @@ impl Parser {
|
|||||||
if self.tokens.is_empty() {
|
if self.tokens.is_empty() {
|
||||||
Err(AssembleError::UnexpectedEof)
|
Err(AssembleError::UnexpectedEof)
|
||||||
} else {
|
} else {
|
||||||
Ok(self.tokens.pop().expect("The spanish Inquisition"))
|
Ok(self.tokens.pop().unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,7 +302,7 @@ impl Parser {
|
|||||||
if self.tokens.is_empty() {
|
if self.tokens.is_empty() {
|
||||||
Err(AssembleError::UnexpectedEof)
|
Err(AssembleError::UnexpectedEof)
|
||||||
} else {
|
} else {
|
||||||
Ok(self.tokens.last().expect("The spanish Inquisition").clone())
|
Ok(self.tokens.last().unwrap().clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ pub fn resolve_symbols(nodes: &mut [Node]) -> Result<(), AssembleError> {
|
|||||||
for node in nodes.iter_mut() {
|
for node in nodes.iter_mut() {
|
||||||
match node.opcode() {
|
match node.opcode() {
|
||||||
Opcode::Lli => {
|
Opcode::Lli => {
|
||||||
if let Token::Symbol(symbol) =
|
if let Token::Symbol(symbol) = node.arg(0).unwrap() {
|
||||||
node.arg(0).expect("The spanish Inquisition")
|
|
||||||
{
|
|
||||||
if let Some(address) = symbol_table.get(&symbol) {
|
if let Some(address) = symbol_table.get(&symbol) {
|
||||||
node.tokens[0] = Token::Immediate(*address);
|
node.tokens[0] = Token::Immediate(*address);
|
||||||
} else {
|
} else {
|
||||||
@@ -25,9 +23,7 @@ pub fn resolve_symbols(nodes: &mut [Node]) -> Result<(), AssembleError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Opcode::Lui => {
|
Opcode::Lui => {
|
||||||
if let Token::Symbol(symbol) =
|
if let Token::Symbol(symbol) = node.arg(0).unwrap() {
|
||||||
node.arg(0).expect("The spanish Inquisition")
|
|
||||||
{
|
|
||||||
if let Some(address) = symbol_table.get(&symbol) {
|
if let Some(address) = symbol_table.get(&symbol) {
|
||||||
node.tokens[0] = Token::Immediate(*address);
|
node.tokens[0] = Token::Immediate(*address);
|
||||||
} else {
|
} else {
|
||||||
@@ -42,9 +38,7 @@ pub fn resolve_symbols(nodes: &mut [Node]) -> Result<(), AssembleError> {
|
|||||||
| Opcode::Jge
|
| Opcode::Jge
|
||||||
| Opcode::Jlt
|
| Opcode::Jlt
|
||||||
| Opcode::Jle => {
|
| Opcode::Jle => {
|
||||||
if let Token::Symbol(symbol) =
|
if let Token::Symbol(symbol) = node.arg(0).unwrap() {
|
||||||
node.arg(0).expect("The spanish Inquisition")
|
|
||||||
{
|
|
||||||
if let Some(address) = symbol_table.get(&symbol) {
|
if let Some(address) = symbol_table.get(&symbol) {
|
||||||
node.tokens[0] = Token::Immediate(*address);
|
node.tokens[0] = Token::Immediate(*address);
|
||||||
} else {
|
} else {
|
||||||
@@ -77,16 +71,12 @@ pub fn resolve_dependencies(mut nodes: Vec<Node>) -> Result<Vec<Node>, AssembleE
|
|||||||
for node in &nodes {
|
for node in &nodes {
|
||||||
if let Opcode::Include = node.opcode() {
|
if let Opcode::Include = node.opcode() {
|
||||||
// we want the path, and the name
|
// we want the path, and the name
|
||||||
let name = if let Token::Symbol(name) =
|
let name = if let Token::Symbol(name) = node.arg(0).unwrap() {
|
||||||
node.arg(0).expect("The spanish Inquisition")
|
|
||||||
{
|
|
||||||
name.name.clone()
|
name.name.clone()
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}; //node.2.get(0).expect("The spanish Inquisition")
|
}; //node.2.get(0).unwrap()
|
||||||
let path = if let Token::StringLit(path) =
|
let path = if let Token::StringLit(path) = node.arg(1).unwrap() {
|
||||||
node.arg(1).expect("The spanish Inquisition")
|
|
||||||
{
|
|
||||||
path
|
path
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ impl Executable for Instruction {
|
|||||||
// To populate the lower 16 bits, see LLI.
|
// To populate the lower 16 bits, see LLI.
|
||||||
Self::LoadUpperImmediate(a) => {
|
Self::LoadUpperImmediate(a) => {
|
||||||
*cpu.reg(a.r1) =
|
*cpu.reg(a.r1) =
|
||||||
(cpu.get(a.r1) & 0x0000_FFFF) | (u32::from(a.immediate) << 16);
|
(cpu.get(a.r1) & 0x0000_FFFF) | u32::from(a.immediate) << 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unconditionally jumps to the calculated address or direct address
|
// Unconditionally jumps to the calculated address or direct address
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ impl Component for MemoryInspector {
|
|||||||
// combine all 4 bytes in the chunk into a u32
|
// combine all 4 bytes in the chunk into a u32
|
||||||
let combined = chunk
|
let combined = chunk
|
||||||
.iter()
|
.iter()
|
||||||
.fold(0u32, |acc, &byte| (acc << 8) | u32::from(byte));
|
.fold(0u32, |acc, &byte| acc << 8 | u32::from(byte));
|
||||||
|
|
||||||
ui.monospace(format!("{combined}"));
|
ui.monospace(format!("{combined}"));
|
||||||
ui.monospace(format!("{}", Instruction::decode(combined).unwrap_or(Instruction::Nop)));
|
ui.monospace(format!("{}", Instruction::decode(combined).unwrap_or(Instruction::Nop)));
|
||||||
|
|||||||
Reference in New Issue
Block a user