Compare commits

...

3 Commits

Author SHA1 Message Date
aca410fbc2 2026-05-25 23:13:33 -06:00
198a85afe4 2026-05-25 22:18:41 -06:00
1558c38185 2026-05-24 12:53:29 -06:00
8 changed files with 121 additions and 12 deletions

39
runtime/Cargo.lock generated
View File

@@ -2,6 +2,12 @@
# It is not intended for manual editing.
version = 4
[[package]]
name = "allocator-api2"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
[[package]]
name = "bdwgc-alloc"
version = "0.6.13"
@@ -39,21 +45,54 @@ dependencies = [
"typewit",
]
[[package]]
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "find-msvc-tools"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
[[package]]
name = "foldhash"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]]
name = "gyehoek"
version = "0.1.0"
dependencies = [
"bdwgc-alloc",
"const_panic",
"internment",
"libc",
]
[[package]]
name = "hashbrown"
version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [
"allocator-api2",
"equivalent",
"foldhash",
]
[[package]]
name = "internment"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "636d4b0f6a39fd684effe2a73f5310df16a3fa7954c26d36833e98f44d1977a2"
dependencies = [
"hashbrown",
]
[[package]]
name = "libc"
version = "0.2.186"

View File

@@ -13,6 +13,7 @@ bdwgc-alloc = { version = "0.6.13"
, default-features = false
, features = ["cmake"] }
const_panic = "0.2.15"
internment = "0.8.6"
libc = "0.2.186"
[patch.crates-io]

View File

@@ -11,3 +11,12 @@ pub extern "C" fn scm_from_utf8_string (
let bytes = unsafe { slice::from_raw_parts (ptr, len) };
scm::make_string (str::from_utf8 (bytes).unwrap ())
}
#[unsafe(no_mangle)]
pub extern "C" fn scm_hash (ptr : *const u8, len : usize) -> u64 {
let bytes = unsafe { slice::from_raw_parts (ptr, len) };
crate::obarray::hash (str::from_utf8 (bytes).unwrap ())
}
// #[unsafe(no_mangle)]
// pub extern "C" fn scm_lookup (name : scm_)

View File

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

View File

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

@@ -1,7 +1,13 @@
use std::{collections::HashMap, hash::{BuildHasher, Hasher}};
pub struct FNV1a (u64);
pub struct SymbolHash;
pub struct SymbolHash ();
impl Default for FNV1a {
fn default () -> Self {
FNV1a (offset_basis)
}
}
impl Hasher for FNV1a {
fn finish (&self) -> u64 {
@@ -24,5 +30,5 @@ impl BuildHasher for SymbolHash {
}
}
const offset_basis : u64 = 0xcbf29ce484222325;
const prime : u64 = 0x100000001b3;
pub const offset_basis : u64 = 0xcbf29ce484222325;
pub const prime : u64 = 0x100000001b3;

View File

@@ -3,13 +3,15 @@
use std::slice;
use crate::gc;
use internment::Intern;
use crate::{gc, obarray};
pub type scm_bits = u64;
pub const tc2_int : u64 = 2;
pub const tc3_cons : u64 = 0;
pub const tc7_weak_set : u64 = 0x55;
pub const tc7_obarray : u64 = 0x55;
pub const tc7_symbol : u64 = 0x05;
pub const tc7_string : u64 = 0x15;
@@ -21,6 +23,7 @@ pub enum SCM {
SmallInt (i64),
Cons (scm_bits, scm_bits),
String (String),
Symbol (usize),
Nil,
False,
True,
@@ -147,5 +150,17 @@ 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 make_symbol_off_heap (name : scm_bits) -> [scm_bits; 2] {
[ tc7_symbol, name ]
}
pub fn string_to_symbol (str : scm_bits) -> scm_bits {
let r = Intern::new (make_symbol_off_heap (str));
pack_ptr (r.as_ref () as *const 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 ();