Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/src/types/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use crate::symbols::{Symbol, SymbolTable};
use crate::types::{Struct, TypeValue};
use crate::wasm::WasmExport;

thread_local! {
static BUILTIN_METHODS: OnceCell<Rc<SymbolTable>> = const { OnceCell::new() };
}

#[derive(Serialize, Deserialize)]
pub(crate) enum Array {
Integers(Vec<i64>),
Expand All @@ -18,20 +22,17 @@ pub(crate) enum Array {
}

impl Array {
#[allow(clippy::declare_interior_mutable_const)]
const BUILTIN_METHODS: OnceCell<Rc<SymbolTable>> = OnceCell::new();

pub fn builtin_methods() -> Rc<SymbolTable> {
#[allow(clippy::borrow_interior_mutable_const)]
Self::BUILTIN_METHODS
.get_or_init(|| {
BUILTIN_METHODS.with(|cell| {
cell.get_or_init(|| {
let mut s = SymbolTable::new();
for (name, func) in WasmExport::get_methods("Array") {
s.insert(name, Symbol::Func(Rc::new(func)));
}
Rc::new(s)
})
.clone()
})
}

pub fn deputy(&self) -> TypeValue {
Expand Down
13 changes: 7 additions & 6 deletions lib/src/types/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use crate::symbols::{Symbol, SymbolTable};
use crate::types::TypeValue;
use crate::wasm::WasmExport;

thread_local! {
static BUILTIN_METHODS: OnceCell<Rc<SymbolTable>> = const { OnceCell::new() };
}

#[derive(Serialize, Deserialize)]
pub(crate) enum Map {
/// A map that has integer keys.
Expand All @@ -31,20 +35,17 @@ pub(crate) enum Map {
}

impl Map {
#[allow(clippy::declare_interior_mutable_const)]
const BUILTIN_METHODS: OnceCell<Rc<SymbolTable>> = OnceCell::new();

pub fn builtin_methods() -> Rc<SymbolTable> {
#[allow(clippy::borrow_interior_mutable_const)]
Self::BUILTIN_METHODS
.get_or_init(|| {
BUILTIN_METHODS.with(|cell| {
cell.get_or_init(|| {
let mut s = SymbolTable::new();
for (name, func) in WasmExport::get_methods("Map") {
s.insert(name, Symbol::Func(Rc::new(func)));
}
Rc::new(s)
})
.clone()
})
}

pub fn deputy(&self) -> TypeValue {
Expand Down
13 changes: 7 additions & 6 deletions lib/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ pub(crate) use func::*;
pub(crate) use map::*;
pub(crate) use structure::*;

thread_local! {
static STRING_BUILTIN_METHODS: OnceCell<Rc<SymbolTable>> = const { OnceCell::new() };
}

mod array;
mod func;
mod map;
Expand Down Expand Up @@ -310,20 +314,17 @@ impl TypeValue {
}
}

#[allow(clippy::declare_interior_mutable_const)]
const STRING_BUILTIN_METHODS: OnceCell<Rc<SymbolTable>> = OnceCell::new();

fn string_builtin_methods() -> Rc<SymbolTable> {
#[allow(clippy::borrow_interior_mutable_const)]
Self::STRING_BUILTIN_METHODS
.get_or_init(|| {
STRING_BUILTIN_METHODS.with(|cell| {
cell.get_or_init(|| {
let mut s = SymbolTable::new();
for (name, func) in WasmExport::get_methods("RuntimeString") {
s.insert(name, Symbol::Func(Rc::new(func)));
}
Rc::new(s)
})
.clone()
})
}

/// Returns the symbol table associated to this [`TypeValue`].
Expand Down
Loading