reimplement RocList and RocStr

This commit is contained in:
Tom Dohrmann 2022-02-23 14:49:10 +01:00
parent 16e568be76
commit 788c8a6af2
19 changed files with 680 additions and 792 deletions

View file

@ -75,7 +75,7 @@ pub unsafe extern "C" fn roc_memset(dst: *mut c_void, c: i32, n: usize) -> *mut
#[no_mangle]
pub extern "C" fn rust_main() -> i32 {
let arg = env::args().skip(1).next().unwrap();
let arg = RocStr::from_slice(arg.as_bytes());
let arg = RocStr::from(arg.as_str());
let size = unsafe { roc_main_size() } as usize;
let layout = Layout::array::<u8>(size).unwrap();
@ -121,7 +121,7 @@ pub extern "C" fn roc_fx_getLine() -> RocStr {
let stdin = io::stdin();
let line1 = stdin.lock().lines().next().unwrap().unwrap();
RocStr::from_slice(line1.as_bytes())
RocStr::from(line1.as_str())
}
#[no_mangle]
@ -142,16 +142,14 @@ pub extern "C" fn roc_fx_getChar() -> u8 {
#[no_mangle]
pub extern "C" fn roc_fx_putLine(line: ManuallyDrop<RocStr>) {
let bytes = line.as_slice();
let string = unsafe { std::str::from_utf8_unchecked(bytes) };
let string = line.as_str();
println!("{}", string);
std::io::stdout().lock().flush();
}
#[no_mangle]
pub extern "C" fn roc_fx_putRaw(line: ManuallyDrop<RocStr>) {
let bytes = line.as_slice();
let string = unsafe { std::str::from_utf8_unchecked(bytes) };
let string = line.as_str();
print!("{}", string);
std::io::stdout().lock().flush();
}
@ -164,7 +162,7 @@ pub extern "C" fn roc_fx_getFileLine(br_ptr: *mut BufReader<File>) -> RocStr {
br.read_line(&mut line1)
.expect("Failed to read line from file");
RocStr::from_slice(line1.as_bytes())
RocStr::from(line1.as_str())
}
#[no_mangle]