Fix skill issues
This commit is contained in:
		
							parent
							
								
									fb1207bae5
								
							
						
					
					
						commit
						f69354ec31
					
				@ -159,7 +159,7 @@ pub fn execute(stack: &mut Stack, mut origin_stack: Option<&mut Stack>, mod_name
 | 
				
			|||||||
            },
 | 
					            },
 | 
				
			||||||
            "native" => {
 | 
					            "native" => {
 | 
				
			||||||
                let arg = instruction.arg.clone();
 | 
					                let arg = instruction.arg.clone();
 | 
				
			||||||
                instructions::native::native(stack, arg)
 | 
					                unsafe {instructions::native::native(stack, arg)}
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Self-modifying
 | 
					            // Self-modifying
 | 
				
			||||||
 | 
				
			|||||||
@ -35,26 +35,12 @@ pub fn exec(mut stack: &mut Stack, arg: String, mod_name: String) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn call(mut stack: &mut Stack, mod_name: String) {
 | 
					pub fn call(stack: &mut Stack, mod_name: String) {
 | 
				
			||||||
    let len: u16 = stack.memory.pop();
 | 
					    let len: u16 = stack.memory.pop();
 | 
				
			||||||
    let mut rev: String = String::new();
 | 
					    let mut rev: String = String::new();
 | 
				
			||||||
    for _i in 0..len {
 | 
					    for _i in 0..len {
 | 
				
			||||||
        rev.push(stack.memory.pop() as u8 as char);
 | 
					        rev.push(stack.memory.pop() as u8 as char);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    let tocall: String = rev.chars().rev().collect::<String>();
 | 
					    let tocall: String = rev.chars().rev().collect::<String>();
 | 
				
			||||||
 | 
					    exec(stack, tocall, mod_name);
 | 
				
			||||||
    if mod_name == tocall {
 | 
					 | 
				
			||||||
        eprintln!("{}", RunError::ExecuteItself(tocall.to_string()));
 | 
					 | 
				
			||||||
        std::process::exit(2);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let lines = fs::read_to_string(&tocall).expect(&format!("{}", RunError::FailToReadFile));
 | 
					 | 
				
			||||||
    let mut temp_stack = Stack::new(stack.memory.size());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    parse(&mut temp_stack, &lines);
 | 
					 | 
				
			||||||
    execute(&mut temp_stack, Some(&mut stack), tocall.clone());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for item in temp_stack.memory.iter() {
 | 
					 | 
				
			||||||
        stack.memory.push(*item);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -4,46 +4,34 @@ use libloading::{Library, Symbol};
 | 
				
			|||||||
static mut STACKPTR: *mut Stack = 0 as *mut Stack;
 | 
					static mut STACKPTR: *mut Stack = 0 as *mut Stack;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[no_mangle]
 | 
					#[no_mangle]
 | 
				
			||||||
extern fn stack_pop_callback() -> u16  { 
 | 
					unsafe extern fn stack_pop_callback() -> u16  { 
 | 
				
			||||||
    return unsafe {
 | 
					 | 
				
			||||||
    (*STACKPTR).memory.pop()
 | 
					    (*STACKPTR).memory.pop()
 | 
				
			||||||
    }; 
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[no_mangle]
 | 
					#[no_mangle]
 | 
				
			||||||
extern fn stack_push_callback(data: u16){ 
 | 
					unsafe extern fn stack_push_callback(data: u16) { 
 | 
				
			||||||
    unsafe { 
 | 
					 | 
				
			||||||
    (*STACKPTR).memory.push(data) 
 | 
					    (*STACKPTR).memory.push(data) 
 | 
				
			||||||
    }; 
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[no_mangle]
 | 
					#[no_mangle]
 | 
				
			||||||
extern fn stack_len_callback() -> usize { 
 | 
					unsafe extern fn stack_len_callback() -> usize { 
 | 
				
			||||||
    return unsafe{
 | 
					 | 
				
			||||||
    (*STACKPTR).memory.len()
 | 
					    (*STACKPTR).memory.len()
 | 
				
			||||||
    }; 
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn native(stack: &mut Stack, arg: String) {
 | 
					pub unsafe fn native(stack: &mut Stack, arg: String) {
 | 
				
			||||||
    unsafe {
 | 
					 | 
				
			||||||
    STACKPTR = stack as *mut Stack;
 | 
					    STACKPTR = stack as *mut Stack;
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    #[cfg(not(target_family = "windows"))]
 | 
					    #[cfg(not(target_family = "windows"))]
 | 
				
			||||||
    let libsuf: String = ".so".to_owned();
 | 
					    let libsuf: String = ".so".to_owned();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[cfg(target_family = "windows")]
 | 
					    #[cfg(target_family = "windows")]
 | 
				
			||||||
    let libsuf: String = ".dll".to_owned();
 | 
					    let libsuf: String = ".dll".to_owned();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let libpref: String = "./".to_owned();
 | 
					    let module = Library::new(format!("./{}{}", arg, libsuf)).unwrap();
 | 
				
			||||||
 | 
					 | 
				
			||||||
    unsafe {
 | 
					 | 
				
			||||||
        let module = Library::new([libpref, arg, libsuf].join("")).unwrap();
 | 
					 | 
				
			||||||
    // C libraries should use 
 | 
					    // C libraries should use 
 | 
				
			||||||
    // void (*labashka)(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size);
 | 
					    // void (*labashka)(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size);
 | 
				
			||||||
        let func: Symbol<unsafe extern "C" fn(extern fn() -> u16, extern fn(u16), extern fn() -> usize, usize)> = module.get(b"labashka").unwrap();
 | 
					    let func: Symbol<unsafe extern "C" fn(unsafe extern fn() -> u16, unsafe extern fn(u16), unsafe extern fn() -> usize, usize)> = module.get(b"labashka").unwrap();
 | 
				
			||||||
    func(stack_pop_callback,stack_push_callback,stack_len_callback, stack.memory.size());
 | 
					    func(stack_pop_callback,stack_push_callback,stack_len_callback, stack.memory.size());
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -47,7 +47,7 @@ pub fn parse(stack: &mut Stack, file_content: &str) {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if name != "" {
 | 
					        if name.is_empty() {
 | 
				
			||||||
            let inst = Instruction { name, arg, data, ispiped: false, isdrained: false };
 | 
					            let inst = Instruction { name, arg, data, ispiped: false, isdrained: false };
 | 
				
			||||||
            stack.program.push(inst);
 | 
					            stack.program.push(inst);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user