Flesh out basic file I/O examples

This commit is contained in:
Richard Feldman 2022-09-11 16:55:36 -04:00
parent 224475a87d
commit 079311d080
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
5 changed files with 2765 additions and 40 deletions

View file

@ -1,5 +1,6 @@
#![allow(non_snake_case)]
mod file_glue;
mod glue;
use core::alloc::Layout;
@ -14,6 +15,9 @@ use std::os::raw::c_char;
use std::path::Path;
use std::time::Duration;
use file_glue::ReadErr;
use file_glue::WriteErr;
extern "C" {
#[link_name = "roc__mainForHost_1_exposed_generic"]
fn roc_main(output: *mut u8);
@ -136,24 +140,35 @@ pub extern "C" fn roc_fx_stderrLine(line: &RocStr) {
eprintln!("{}", string);
}
// #[no_mangle]
// pub extern "C" fn roc_fx_fileWriteUtf8(
// roc_path: &RocList<u8>,
// roc_string: &RocStr,
// // ) -> RocResult<(), WriteErr> {
// ) -> (u8, u8) {
// let _ = write_slice(roc_path, roc_string.as_str().as_bytes());
// (255, 255)
// }
type Fail = Foo;
#[repr(C)]
pub enum ReadErr {
NotFound,
Other,
}
#[repr(u8)]
pub enum WriteErr {
Other,
PermissionDenied,
pub struct Foo {
data: u8,
tag: u8,
}
// #[no_mangle]
// pub extern "C" fn roc_fx_fileWriteUtf8(roc_path: &RocList<u8>, roc_string: &RocStr) -> Fail {
// write_slice2(roc_path, roc_string.as_str().as_bytes())
// }
#[no_mangle]
pub extern "C" fn roc_fx_fileWriteUtf8(
roc_path: &RocList<u8>,
roc_string: &RocStr,
roc_str: &RocStr,
) -> RocResult<(), WriteErr> {
write_slice(roc_path, roc_string.as_str().as_bytes())
write_slice(roc_path, roc_str.as_str().as_bytes())
}
#[no_mangle]