fn assemble_instr(&self, linum: usize, instr: Instruction, addr: &Option<String>) -> Result<u16> {
        // Match instruction and use or reject the address as necessary
        // This is pretty ugly
        let new_instr = match instr {
            Instruction::Halt | Instruction::Io(_) | Instruction::Not | Instruction::Nop => {
                refuse_arg(instr, addr, linum)?;
                instr
            }
            Instruction::Shift(_, _) => instr,
            Instruction::Load(_) => Instruction::Load(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Store(_) => Instruction::Store(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Add(_) => Instruction::Add(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Sub(_) => Instruction::Sub(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::And(_) => Instruction::And(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Or(_) => Instruction::Or(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Xor(_) => Instruction::Xor(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Jmp(_) => Instruction::Jmp(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Jmpe(_) => Instruction::Jmpe(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Jmpl(_) => Instruction::Jmpl(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Brl(_) => Instruction::Brl(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
        };

        Ok(new_instr.to_u16())
    }
/// Assemble instruction from the base instruction and an optional address.
Assemble instruction from the base instruction and an optional address.
Assemble instruction from the base instruction and an optional address .
fn assemble_instr(&self, linum: usize, instr: Instruction, addr: &Option<String>) -> Result<u16> {
        // Match instruction and use or reject the address as necessary
        // This is pretty ugly
        let new_instr = match instr {
            Instruction::Halt | Instruction::Io(_) | Instruction::Not | Instruction::Nop => {
                refuse_arg(instr, addr, linum)?;
                instr
            }
            Instruction::Shift(_, _) => instr,
            Instruction::Load(_) => Instruction::Load(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Store(_) => Instruction::Store(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Add(_) => Instruction::Add(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Sub(_) => Instruction::Sub(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::And(_) => Instruction::And(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Or(_) => Instruction::Or(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Xor(_) => Instruction::Xor(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Jmp(_) => Instruction::Jmp(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Jmpe(_) => Instruction::Jmpe(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Jmpl(_) => Instruction::Jmpl(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
            Instruction::Brl(_) => Instruction::Brl(self.resolve_label(require_arg(instr, addr, linum)?, linum)?),
        };
        Ok(new_instr.to_u16())
    }
fn assemble_instr ( & self , linum : usize , instr : Instruction , addr : & Option < String > ) -> Result < u16 > { // Match instruction and use or reject the address as necessary // This is pretty ugly let new_instr = match instr { Instruction :: Halt | Instruction :: Io ( _ ) | Instruction :: Not | Instruction :: Nop => { refuse_arg ( instr , addr , linum ) ? ; instr } Instruction :: Shift ( _ , _ ) => instr , Instruction :: Load ( _ ) => Instruction :: Load ( self . resolve_label ( require_arg ( instr , addr , linum ) ? , linum ) ? ) , Instruction :: Store ( _ ) => Instruction :: Store ( self . resolve_label ( require_arg ( instr , addr , linum ) ? , linum ) ? ) , Instruction :: Add ( _ ) => Instruction :: Add ( self . resolve_label ( require_arg ( instr , addr , linum ) ? , linum ) ? ) , Instruction :: Sub ( _ ) => Instruction :: Sub ( self . resolve_label ( require_arg ( instr , addr , linum ) ? , linum ) ? ) , Instruction :: And ( _ ) => Instruction :: And ( self . resolve_label ( require_arg ( instr , addr , linum ) ? , linum ) ? ) , Instruction :: Or ( _ ) => Instruction :: Or ( self . resolve_label ( require_arg ( instr , addr , linum ) ? , linum ) ? ) , Instruction :: Xor ( _ ) => Instruction :: Xor ( self . resolve_label ( require_arg ( instr , addr , linum ) ? , linum ) ? ) , Instruction :: Jmp ( _ ) => Instruction :: Jmp ( self . resolve_label ( require_arg ( instr , addr , linum ) ? , linum ) ? ) , Instruction :: Jmpe ( _ ) => Instruction :: Jmpe ( self . resolve_label ( require_arg ( instr , addr , linum ) ? , linum ) ? ) , Instruction :: Jmpl ( _ ) => Instruction :: Jmpl ( self . resolve_label ( require_arg ( instr , addr , linum ) ? , linum ) ? ) , Instruction :: Brl ( _ ) => Instruction :: Brl ( self . resolve_label ( require_arg ( instr , addr , linum ) ? , linum ) ? ) , } ; Ok ( new_instr . to_u16 ( ) ) }
Assemble instruction from the base instruction and an optional address.
Assemble instruction from the base instruction and an optional address .
&self
linum
usize
instr
Instruction
addr
&Option<String>
&self
linum
usize
instr
Instruction
addr
&Option<String>