This commit is contained in:
2026-05-25 22:18:41 -06:00
parent 1558c38185
commit 198a85afe4
6 changed files with 185 additions and 21 deletions

129
runtime/Cargo.lock generated
View File

@@ -2,6 +2,12 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 4
[[package]]
name = "allocator-api2"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
[[package]] [[package]]
name = "bdwgc-alloc" name = "bdwgc-alloc"
version = "0.6.13" version = "0.6.13"
@@ -39,19 +45,68 @@ dependencies = [
"typewit", "typewit",
] ]
[[package]]
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]] [[package]]
name = "find-msvc-tools" name = "find-msvc-tools"
version = "0.1.9" version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
[[package]]
name = "foldhash"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]]
name = "foldhash"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
[[package]] [[package]]
name = "gyehoek" name = "gyehoek"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bdwgc-alloc", "bdwgc-alloc",
"const_panic", "const_panic",
"internment",
"libc", "libc",
"string-interner",
]
[[package]]
name = "hashbrown"
version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [
"allocator-api2",
"equivalent",
"foldhash 0.1.5",
]
[[package]]
name = "hashbrown"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
dependencies = [
"foldhash 0.2.0",
]
[[package]]
name = "internment"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "636d4b0f6a39fd684effe2a73f5310df16a3fa7954c26d36833e98f44d1977a2"
dependencies = [
"hashbrown 0.15.5",
] ]
[[package]] [[package]]
@@ -60,14 +115,88 @@ version = "0.2.186"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
[[package]]
name = "proc-macro2"
version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
dependencies = [
"proc-macro2",
]
[[package]]
name = "serde"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
dependencies = [
"serde_core",
]
[[package]]
name = "serde_core"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "shlex" name = "shlex"
version = "1.3.0" version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "string-interner"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad3df9b59e2eded8d825c7c4363ad339a20fb6bc0b9a4778560f518f59910b15"
dependencies = [
"hashbrown 0.16.1",
"serde",
]
[[package]]
name = "syn"
version = "2.0.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]] [[package]]
name = "typewit" name = "typewit"
version = "1.15.2" version = "1.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "214ca0b2191785cbc06209b9ca1861e048e39b5ba33574b3cedd58363d5bb5f6" checksum = "214ca0b2191785cbc06209b9ca1861e048e39b5ba33574b3cedd58363d5bb5f6"
[[package]]
name = "unicode-ident"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"

View File

@@ -13,7 +13,9 @@ bdwgc-alloc = { version = "0.6.13"
, default-features = false , default-features = false
, features = ["cmake"] } , features = ["cmake"] }
const_panic = "0.2.15" const_panic = "0.2.15"
internment = "0.8.6"
libc = "0.2.186" libc = "0.2.186"
string-interner = "0.20.0"
[patch.crates-io] [patch.crates-io]
bdwgc-alloc = { git = 'https://git.deertopia.net/msyds/bdwgc-rust.git' } bdwgc-alloc = { git = 'https://git.deertopia.net/msyds/bdwgc-rust.git' }

View File

@@ -6,3 +6,4 @@ mod scm;
mod primitives; mod primitives;
mod obarray; mod obarray;
mod capi; mod capi;
mod var;

View File

@@ -1,26 +1,24 @@
use std::{collections::HashMap, hash::{BuildHasher, Hasher}}; use std::{ops::DerefMut, sync::{LazyLock, Mutex, RwLock}};
use crate::scm::scm_bits;
use crate::scm;
mod fnv1a; // mod fnv1a;
use fnv1a::{FNV1a, SymbolHash}; // use fnv1a::{FNV1a, SymbolHash};
use string_interner::{StringInterner, symbol::SymbolU32};
pub struct Obarray (HashMap <String, scm_bits, SymbolHash>); pub struct Obarray (
LazyLock <RwLock <StringInterner <string_interner::DefaultBackend>>>
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 ()
}
impl Obarray { 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 ();

View File

@@ -3,7 +3,9 @@
use std::slice; use std::slice;
use crate::gc; use string_interner::Symbol as _;
use crate::{gc, obarray};
pub type scm_bits = u64; pub type scm_bits = u64;
@@ -21,6 +23,7 @@ pub enum SCM {
SmallInt (i64), SmallInt (i64),
Cons (scm_bits, scm_bits), Cons (scm_bits, scm_bits),
String (String), String (String),
Symbol (usize),
Nil, Nil,
False, False,
True, True,
@@ -147,5 +150,11 @@ pub fn make_string (s : &str) -> scm_bits {
pub fn make_symbol (name : &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) {
} }

25
runtime/src/var.rs Normal file
View File

@@ -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 ();