wip cleanup

This commit is contained in:
Viv Lim 2022-12-11 00:39:48 -08:00
parent ebcf8bfdfb
commit a6ca0b7508
4 changed files with 66 additions and 19 deletions

56
Cargo.lock generated
View File

@ -15,9 +15,65 @@ version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
[[package]]
name = "proc-macro2"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rust-guile"
version = "0.1.6"
dependencies = [
"pkg-config",
"thiserror",
]
[[package]]
name = "syn"
version = "1.0.105"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thiserror"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"

View File

@ -1,13 +1,13 @@
use std::{sync::{atomic::{AtomicU8, Ordering}, Arc}, fs::canonicalize};
use guile_goblins_rs::start_scm;
use rust_guile::api::SchemeApi;
use rust_guile::api::GuileApi;
use std::fs;
fn main() {
let counter = Arc::new(AtomicU8::new(1));
let to_run = |api: SchemeApi| {
let to_run = |api: GuileApi| {
counter.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
println!("I'm running inside the fn {}", counter.load(Ordering::Relaxed));
api.load_file("/Users/vivlim/git/guile-goblins-rs/hello.scm");
api.load_script("./hello.scm");
};
start_scm(vec!["-s", "./hello.scm"], to_run);
// code after here is never reached because guile exits

View File

@ -1,11 +1,11 @@
use std::{sync::{atomic::{AtomicU8, Ordering}, Arc}};
use guile_goblins_rs::start_scm;
use rust_guile::api::SchemeApi;
use rust_guile::api::GuileApi;
fn main() {
// We want to run the contents of repl-init.scm before starting the repl, mostly to activate readline.
let to_run = |api: SchemeApi| {
api.load_file("./repl-init.scm");
let to_run = |api: GuileApi| {
api.load_script("./repl-init.scm");
};
start_scm(vec![], to_run); // start guile with no args = repl
// note execution stops here, because guile exits the process.

View File

@ -1,4 +1,4 @@
use rust_guile::{*, bindings::*, api::SchemeApi};
use rust_guile::{*, bindings::*, api::{GuileApi, exec_with_guile}};
use std::ffi::CString;
extern "C" fn hello_from_rust() -> SCM {
@ -12,21 +12,12 @@ extern "C" fn hello_from_rust() -> SCM {
pub fn start_scm<F>(args: Vec<&str>, with_api: F)
where F: FnMut(SchemeApi) {
where F: FnMut(GuileApi) {
init_scm();
register_void_function!(b"hello-from-rust\0", hello_from_rust);
init_and_use_api_scm(with_api);
let args: Vec<String> = args.into_iter().map(|arg| arg.to_string()).collect();
let mut args: Vec<Vec<i8>> = args.into_iter().map(|arg| {
let cstr = CString::new(arg.into_bytes()).expect("args should be valid to represent as cstring");
cstr.into_bytes_with_nul().into_iter().map(|b| b as i8).collect()
}).collect();
let argc: i32 = args.len() as i32;
let mut arg_ptrs: Vec<*mut i8> = args.iter_mut().map(|arg| arg.as_mut_ptr()).collect();
let argv = arg_ptrs.as_mut_ptr();
exec_with_guile(with_api);
/* this was actually unnecessary because guile does inherit env variables. i was just doing (getenv TERM) instead of (getenv "TERM")
// set all the env variables that apply to the rust process
@ -45,7 +36,7 @@ where F: FnMut(SchemeApi) {
// set something so i don't feel like i wasted time :)
setenv_scm("UPDOG", "yes").unwrap();
run_scm(argc, argv);
run_scm_with_args(args);
}