This commit is contained in:
@@ -6,3 +6,4 @@ mod scm;
|
||||
mod primitives;
|
||||
mod obarray;
|
||||
mod capi;
|
||||
mod var;
|
||||
|
||||
+17
-19
@@ -1,26 +1,24 @@
|
||||
use std::{collections::HashMap, hash::{BuildHasher, Hasher}};
|
||||
use crate::scm::scm_bits;
|
||||
use crate::scm;
|
||||
use std::{ops::DerefMut, sync::{LazyLock, Mutex, RwLock}};
|
||||
|
||||
mod fnv1a;
|
||||
use fnv1a::{FNV1a, SymbolHash};
|
||||
// mod fnv1a;
|
||||
// use fnv1a::{FNV1a, SymbolHash};
|
||||
use string_interner::{StringInterner, symbol::SymbolU32};
|
||||
|
||||
pub struct Obarray (HashMap <String, scm_bits, SymbolHash>);
|
||||
|
||||
pub const fn new () -> Obarray {
|
||||
Obarray (HashMap::with_hasher (SymbolHash ()))
|
||||
}
|
||||
|
||||
pub fn hash (s : &str) -> u64 {
|
||||
let mut a : FNV1a = Default::default ();
|
||||
a.write (s.as_bytes ());
|
||||
return a.finish ()
|
||||
}
|
||||
pub struct Obarray (
|
||||
LazyLock <RwLock <StringInterner <string_interner::DefaultBackend>>>
|
||||
);
|
||||
|
||||
impl Obarray {
|
||||
pub fn insert (&mut self) {
|
||||
|
||||
pub const fn new () -> Obarray {
|
||||
Obarray (LazyLock::new (|| RwLock::new (StringInterner::new ())))
|
||||
}
|
||||
}
|
||||
|
||||
pub static symbols : Obarray = new ();
|
||||
impl Obarray {
|
||||
pub fn intern (&self, name : &str) -> SymbolU32 {
|
||||
let mut r = symbols.0.write ().unwrap ();
|
||||
r.deref_mut ().get_or_intern (name)
|
||||
}
|
||||
}
|
||||
|
||||
pub static symbols : Obarray = Obarray::new ();
|
||||
|
||||
+11
-2
@@ -3,7 +3,9 @@
|
||||
|
||||
use std::slice;
|
||||
|
||||
use crate::gc;
|
||||
use string_interner::Symbol as _;
|
||||
|
||||
use crate::{gc, obarray};
|
||||
|
||||
pub type scm_bits = u64;
|
||||
|
||||
@@ -21,6 +23,7 @@ pub enum SCM {
|
||||
SmallInt (i64),
|
||||
Cons (scm_bits, scm_bits),
|
||||
String (String),
|
||||
Symbol (usize),
|
||||
Nil,
|
||||
False,
|
||||
True,
|
||||
@@ -147,5 +150,11 @@ pub fn make_string (s : &str) -> scm_bits {
|
||||
|
||||
|
||||
pub fn make_symbol (name : &str) -> scm_bits {
|
||||
todo! ()
|
||||
let r = unsafe { words (tc7_symbol, 2) };
|
||||
let sym = obarray::symbols.intern (name).to_usize ();
|
||||
unsafe { set_word (r, 1, sym.try_into ().unwrap ()) };
|
||||
pack_ptr (r)
|
||||
}
|
||||
|
||||
pub fn string_to_symbol (str : scm_bits) {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
use std::{collections::HashMap, ops::DerefMut as _, sync::{LazyLock, RwLock}};
|
||||
use string_interner::symbol::SymbolU32;
|
||||
use crate::scm::scm_bits;
|
||||
|
||||
struct Vars (
|
||||
LazyLock <RwLock <HashMap <SymbolU32, scm_bits>>>
|
||||
);
|
||||
|
||||
impl Vars {
|
||||
pub const fn new () -> Vars {
|
||||
Vars (LazyLock::new (|| RwLock::new (HashMap::new ())))
|
||||
}
|
||||
|
||||
pub fn lookup (&self, name : SymbolU32) -> Option <scm_bits> {
|
||||
let r = self.0.write ().unwrap ();
|
||||
(*r).get (&name).map (|x| *x)
|
||||
}
|
||||
|
||||
pub fn define (&self, name : SymbolU32, value : scm_bits) {
|
||||
let mut r = self.0.write ().unwrap ();
|
||||
r.deref_mut ().insert (name, value);
|
||||
}
|
||||
}
|
||||
|
||||
static vars : Vars = Vars::new ();
|
||||
Reference in New Issue
Block a user