async fn handle_opcode<S: Stream<Item = String> + Unpin>(
    pc: usize,
    memory: &mut [i64],
    input: &mut S,
) -> Option<usize> {
    let mut opcode = memory[pc];

    if opcode == 99 {
        return None;
    }

    let op = Op::new(opcode);
    opcode /= 100;

    let mut args = [Argument::Imm(0); 3];
    for (i, arg) in (0..op.args()).zip(args.iter_mut()) {
        let v = memory[pc + i + 1];

        *arg = if opcode % 10 == 0 {
            Argument::Pos(v as usize)
        } else {
            Argument::Imm(v)
        };

        opcode /= 10;
    }

    Some(
        op.perform(&args, memory, input)
            .await
            .unwrap_or_else(|| pc + op.args() + 1),
    )
}
// Returns offset to next instruction or None
// for stop execution
Returns offset to next instruction or None
for stop execution
Returns offset to next instruction or None for stop execution
async fn handle_opcode<S: Stream<Item = String> + Unpin>(
    pc: usize,
    memory: &mut [i64],
    input: &mut S,
) -> Option<usize> {
    let mut opcode = memory[pc];
    if opcode == 99 {
        return None;
    }
    let op = Op::new(opcode);
    opcode /= 100;
    let mut args = [Argument::Imm(0); 3];
    for (i, arg) in (0..op.args()).zip(args.iter_mut()) {
        let v = memory[pc + i + 1];
        *arg = if opcode % 10 == 0 {
            Argument::Pos(v as usize)
        } else {
            Argument::Imm(v)
        };
        opcode /= 10;
    }
    Some(
        op.perform(&args, memory, input)
            .await
            .unwrap_or_else(|| pc + op.args() + 1),
    )
}
async fn handle_opcode < S : Stream < Item = String > + Unpin > ( pc : usize , memory : & mut [ i64 ] , input : & mut S , ) -> Option < usize > { let mut opcode = memory [ pc ] ; if opcode == 99 { return None ; } let op = Op :: new ( opcode ) ; opcode /= 100 ; let mut args = [ Argument :: Imm ( 0 ) ; 3 ] ; for ( i , arg ) in ( 0 .. op . args ( ) ) . zip ( args . iter_mut ( ) ) { let v = memory [ pc + i + 1 ] ; * arg = if opcode % 10 == 0 { Argument :: Pos ( v as usize ) } else { Argument :: Imm ( v ) } ; opcode /= 10 ; } Some ( op . perform ( & args , memory , input ) . await . unwrap_or_else ( | | pc + op . args ( ) + 1 ) , ) }
Returns offset to next instruction or None
for stop execution
Returns offset to next instruction or None for stop execution
pc
usize
memory
&mut [i64]
input
&mut S