work towards being able to follow along with the samples in the core paper
This commit is contained in:
parent
8b009cfa71
commit
e8b4ca0a48
|
@ -1,15 +1,20 @@
|
|||
use std::{sync::{atomic::{AtomicU8, Ordering}, Arc}, fs::canonicalize};
|
||||
use guile_goblins_rs::start_scm;
|
||||
use rust_guile::api::GuileApi;
|
||||
use rust_guile::api::subroutines::register_subroutine;
|
||||
use std::fs;
|
||||
fn main() {
|
||||
let counter = Arc::new(AtomicU8::new(1));
|
||||
let counter = Box::leak(Box::new(AtomicU8::new(1)));
|
||||
|
||||
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_script("./guile-goblins.scm");
|
||||
register_subroutine("idk", |a| {
|
||||
println!("i'm a closure subroutine that's been called {} times.", counter.fetch_add(1, Ordering::Relaxed));
|
||||
a
|
||||
});
|
||||
api.load_script("./goblins.scm");
|
||||
api.load_script("./repl-init.scm");
|
||||
};
|
||||
start_scm(vec!["-s", "./hello.scm"], to_run);
|
||||
start_scm(vec![], to_run);
|
||||
// code after here is never reached because guile exits
|
||||
println!("after run counter is {}", counter.load(std::sync::atomic::Ordering::Relaxed));
|
||||
}
|
||||
|
|
14
flake.nix
14
flake.nix
|
@ -36,6 +36,7 @@
|
|||
guile_3_0
|
||||
guile-fibers
|
||||
autoconf
|
||||
automake.out
|
||||
(rust-bin.stable.latest.default.override {
|
||||
extensions = ["rust-src"];
|
||||
targets = [ ];
|
||||
|
@ -43,6 +44,19 @@
|
|||
];
|
||||
|
||||
shellHook = ''
|
||||
find_path_containing_file () {
|
||||
find "$1" -type f -name "$2" -exec dirname "{}" \; -quit
|
||||
}
|
||||
# fibers. path containing fibers.scm
|
||||
export GUILE_LOAD_PATH="$(find_path_containing_file ${pkgs.guile-fibers} fibers.scm):$GUILE_LOAD_PATH"
|
||||
# gcrypt hash. path containing directory containing hash.scm
|
||||
export GUILE_LOAD_PATH="$(dirname $(find_path_containing_file ${pkgs.guile-gcrypt} hash.scm)):$GUILE_LOAD_PATH"
|
||||
|
||||
# goblins itself. assume it's in a subdirectory of pwd named "guile-goblins"
|
||||
# stopgap until i build goblins itself in nix and pull that in.
|
||||
export GUILE_LOAD_PATH="$(pwd)/guile-goblins:$GUILE_LOAD_PATH"
|
||||
export GUILE_LOAD_PATH="$(pwd)/guile-modules:$GUILE_LOAD_PATH"
|
||||
|
||||
alias repl="cargo run --example repl"
|
||||
echo "run 'repl' to start a repl embedded in rust"
|
||||
'';
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
(define-module (taste-of-goblins)
|
||||
#:use-module (goblins)
|
||||
#:use-module (goblins actor-lib methods)
|
||||
#:export (^cell ^greeter ^cgreeter ^borked-cgreeter
|
||||
^car-factory ^borked-car-factory)
|
||||
)
|
||||
|
||||
;; (define a-vat (spawn-vat))
|
||||
;; (define-vat-run a-run a-vat)
|
||||
|
||||
(define
|
||||
(^greeter _bcom our-name)
|
||||
(lambda
|
||||
(your-name) (format #f "Hello ~a, my name is ~a!" . (your-name our-name))
|
||||
)
|
||||
)
|
Loading…
Reference in New Issue