fn compile_loop_body(&mut self, code: &[u8], begin_ip: usize) -> (usize, usize) {
        let mut ip = begin_ip;
        let mut chars_processed = 0;
        while chars_processed < code.len() {
            let ch = code[chars_processed] as char;
            match ch {
                '<' | '>' | '+' | '-' => {
                    self.code_mem.write_at(&mut ip, INSTR_TO_BIN_CODE[&ch]);
                }
                '.' => {
                    self.code_mem.write_at(&mut ip, INSTR_TO_BIN_CODE[&ch]);
                    let putchar_addr_offset = if cfg!(unix) {
                        12
                    } else if cfg!(windows) {
                        10
                    } else {
                        panic!("Unsupported platform");
                    };
                    self.code_mem.patch_addr_u64(ip - putchar_addr_offset, putchar_unlocked as u64);
                }
                ',' => {
                    self.code_mem.write_at(&mut ip, INSTR_TO_BIN_CODE[&ch]);
                    let getchar_addr_offset = if cfg!(unix) {
                        14
                    } else if cfg!(windows) {
                        12
                    } else {
                        panic!("Unsupported platform");
                    };
                    self.code_mem.patch_addr_u64(ip - getchar_addr_offset, getchar as u64);
                }
                '[' => {
                    self.code_mem.write_at(&mut ip, INSTR_TO_BIN_CODE[&ch]);
                    let addr_to_patch = ip - 4;
                    let (new_ip, new_cp) = self.compile_loop_body(&code[chars_processed + 1..], ip);
                    let offset = new_ip - ip;
                    assert!(offset > 0 && offset < (1 << 31));
                    self.code_mem.patch_addr_i32(addr_to_patch, offset as i32);
                    ip = new_ip;
                    chars_processed += new_cp;
                }
                ']' => {
                    self.code_mem.write_at(&mut ip, INSTR_TO_BIN_CODE[&ch]);
                    let addr_to_patch = ip - 4;
                    let offset = ip - begin_ip;
                    assert!(offset > 0 && offset < (1 << 31));
                    self.code_mem.patch_addr_i32(addr_to_patch, -(offset as i32));
                }
                _ => {}
            }

            chars_processed += 1;
            if ch == ']' {
                break;
            }
        }

        (ip, chars_processed)
    }
// returns (new ip, code chars processed)
returns (new ip, code chars processed)
returns ( new ip code chars processed )
fn compile_loop_body(&mut self, code: &[u8], begin_ip: usize) -> (usize, usize) {
        let mut ip = begin_ip;
        let mut chars_processed = 0;
        while chars_processed < code.len() {
            let ch = code[chars_processed] as char;
            match ch {
                '<' | '>' | '+' | '-' => {
                    self.code_mem.write_at(&mut ip, INSTR_TO_BIN_CODE[&ch]);
                }
                '.' => {
                    self.code_mem.write_at(&mut ip, INSTR_TO_BIN_CODE[&ch]);
                    let putchar_addr_offset = if cfg!(unix) {
                        12
                    } else if cfg!(windows) {
                        10
                    } else {
                        panic!("Unsupported platform");
                    };
                    self.code_mem.patch_addr_u64(ip - putchar_addr_offset, putchar_unlocked as u64);
                }
                ',' => {
                    self.code_mem.write_at(&mut ip, INSTR_TO_BIN_CODE[&ch]);
                    let getchar_addr_offset = if cfg!(unix) {
                        14
                    } else if cfg!(windows) {
                        12
                    } else {
                        panic!("Unsupported platform");
                    };
                    self.code_mem.patch_addr_u64(ip - getchar_addr_offset, getchar as u64);
                }
                '[' => {
                    self.code_mem.write_at(&mut ip, INSTR_TO_BIN_CODE[&ch]);
                    let addr_to_patch = ip - 4;
                    let (new_ip, new_cp) = self.compile_loop_body(&code[chars_processed + 1..], ip);
                    let offset = new_ip - ip;
                    assert!(offset > 0 && offset < (1 << 31));
                    self.code_mem.patch_addr_i32(addr_to_patch, offset as i32);
                    ip = new_ip;
                    chars_processed += new_cp;
                }
                ']' => {
                    self.code_mem.write_at(&mut ip, INSTR_TO_BIN_CODE[&ch]);
                    let addr_to_patch = ip - 4;
                    let offset = ip - begin_ip;
                    assert!(offset > 0 && offset < (1 << 31));
                    self.code_mem.patch_addr_i32(addr_to_patch, -(offset as i32));
                }
                _ => {}
            }
            chars_processed += 1;
            if ch == ']' {
                break;
            }
        }
        (ip, chars_processed)
    }
fn compile_loop_body ( & mut self , code : & [ u8 ] , begin_ip : usize ) -> ( usize , usize ) { let mut ip = begin_ip ; let mut chars_processed = 0 ; while chars_processed < code . len ( ) { let ch = code [ chars_processed ] as char ; match ch { '<' | '>' | '+' | '-' => { self . code_mem . write_at ( & mut ip , INSTR_TO_BIN_CODE [ & ch ] ) ; } '.' => { self . code_mem . write_at ( & mut ip , INSTR_TO_BIN_CODE [ & ch ] ) ; let putchar_addr_offset = if cfg ! ( unix ) { 12 } else if cfg ! ( windows ) { 10 } else { panic ! ( " " ) ; } ; self . code_mem . patch_addr_u64 ( ip - putchar_addr_offset , putchar_unlocked as u64 ) ; } ',' => { self . code_mem . write_at ( & mut ip , INSTR_TO_BIN_CODE [ & ch ] ) ; let getchar_addr_offset = if cfg ! ( unix ) { 14 } else if cfg ! ( windows ) { 12 } else { panic ! ( " " ) ; } ; self . code_mem . patch_addr_u64 ( ip - getchar_addr_offset , getchar as u64 ) ; } '[' => { self . code_mem . write_at ( & mut ip , INSTR_TO_BIN_CODE [ & ch ] ) ; let addr_to_patch = ip - 4 ; let ( new_ip , new_cp ) = self . compile_loop_body ( & code [ chars_processed + 1 .. ] , ip ) ; let offset = new_ip - ip ; assert ! ( offset 0 offset ( 1 31 ) ) ; self . code_mem . patch_addr_i32 ( addr_to_patch , offset as i32 ) ; ip = new_ip ; chars_processed += new_cp ; } ']' => { self . code_mem . write_at ( & mut ip , INSTR_TO_BIN_CODE [ & ch ] ) ; let addr_to_patch = ip - 4 ; let offset = ip - begin_ip ; assert ! ( offset 0 offset ( 1 31 ) ) ; self . code_mem . patch_addr_i32 ( addr_to_patch , - ( offset as i32 ) ) ; } _ => { } } chars_processed += 1 ; if ch == ']' { break ; } } ( ip , chars_processed ) }
returns (new ip, code chars processed)
returns ( new ip code chars processed )
&mut self
code
&[u8]
begin_ip
usize
&mut self
code
&[u8]
begin_ip
usize