words definition

This commit is contained in:
2026-01-23 11:15:15 +01:00
parent a88904ed0f
commit 74f178f271
10 changed files with 237 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
use rand::rngs::StdRng;
use rand::SeedableRng;
use cagire::model::forth::{Forth, Rng, StepContext, Value, Variables};
use cagire::model::forth::{Dictionary, Forth, Rng, StepContext, Value, Variables};
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
@@ -29,16 +29,20 @@ pub fn new_vars() -> Variables {
Arc::new(Mutex::new(HashMap::new()))
}
pub fn new_dict() -> Dictionary {
Arc::new(Mutex::new(HashMap::new()))
}
pub fn seeded_rng(seed: u64) -> Rng {
Arc::new(Mutex::new(StdRng::seed_from_u64(seed)))
}
pub fn forth() -> Forth {
Forth::new(new_vars(), seeded_rng(42))
Forth::new(new_vars(), new_dict(), seeded_rng(42))
}
pub fn forth_seeded(seed: u64) -> Forth {
Forth::new(new_vars(), seeded_rng(seed))
Forth::new(new_vars(), new_dict(), seeded_rng(seed))
}
pub fn run(script: &str) -> Forth {