cl-structures::Interned: Change to_ref() from assoc. function to member function
(it's so much nicer)
This commit is contained in:
parent
dcdb100a8a
commit
584207fc8c
@ -938,7 +938,7 @@ mod path {
|
||||
/// Checks whether this path refers to the sinkhole identifier, `_`
|
||||
pub fn is_sinkhole(&self) -> bool {
|
||||
if let [PathPart::Ident(id)] = self.parts.as_slice() {
|
||||
if let "_" = Sym::to_ref(id) {
|
||||
if let "_" = id.to_ref(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ impl ConValue {
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn TupleStruct(name: Sym, values: Box<[ConValue]>) -> Self {
|
||||
Self::TupleStruct(Box::new((Sym::to_ref(&name), values)))
|
||||
Self::TupleStruct(Box::new((name.to_ref(), values)))
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
pub fn Struct(name: Sym, values: HashMap<Sym, ConValue>) -> Self {
|
||||
|
@ -59,7 +59,7 @@ impl Callable for Function {
|
||||
return Err(Error::ArgNumber { want: bind.len(), got: args.len() });
|
||||
}
|
||||
if self.is_constructor {
|
||||
return Ok(ConValue::TupleStruct(Box::new((Sym::to_ref(name), args.into()))));
|
||||
return Ok(ConValue::TupleStruct(Box::new((name.to_ref(), args.into()))));
|
||||
}
|
||||
let Some(body) = body else {
|
||||
return Err(Error::NotDefined(*name));
|
||||
|
@ -89,7 +89,7 @@ impl Interpret for Module {
|
||||
// TODO: Keep modules around somehow, rather than putting them on the stack
|
||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
let Self { name, kind } = self;
|
||||
env.push_frame(Interned::to_ref(name), Default::default());
|
||||
env.push_frame(name.to_ref(), Default::default());
|
||||
let out = match kind {
|
||||
Some(file) => file.interpret(env),
|
||||
None => {
|
||||
@ -154,7 +154,7 @@ impl Interpret for Enum {
|
||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
let Self { name, variants: kind } = self;
|
||||
if let Some(variants) = kind {
|
||||
env.push_frame(Sym::to_ref(name), Default::default());
|
||||
env.push_frame(name.to_ref(), Default::default());
|
||||
for (idx, Variant { name, kind }) in variants.iter().enumerate() {
|
||||
match kind {
|
||||
VariantKind::Plain => env.insert(*name, Some(ConValue::Int(idx as _))),
|
||||
@ -223,7 +223,7 @@ impl Interpret for UseTree {
|
||||
let Ok(ConValue::Module(m)) = env.get(*name) else {
|
||||
Err(Error::TypeError)?
|
||||
};
|
||||
env.push_frame(Interned::to_ref(name), *m);
|
||||
env.push_frame(name.to_ref(), *m);
|
||||
let out = get_bindings(tree, env, bindings);
|
||||
env.pop_frame();
|
||||
return out;
|
||||
|
@ -37,8 +37,8 @@ pub mod interned {
|
||||
}
|
||||
|
||||
/// Gets the internal value as a reference with the interner's lifetime
|
||||
pub fn to_ref(interned: &Self) -> &'a T {
|
||||
interned.value
|
||||
pub fn to_ref(&self) -> &'a T {
|
||||
self.value
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -320,9 +320,9 @@ fn banner() {
|
||||
|
||||
/// Interns a [File](cl_ast::File), returning a static reference to it.
|
||||
fn interned(file: cl_ast::File) -> &'static cl_ast::File {
|
||||
use cl_structures::intern::{interned::Interned, typed_interner::TypedInterner};
|
||||
use cl_structures::intern::typed_interner::TypedInterner;
|
||||
static INTERNER: LazyLock<TypedInterner<'static, cl_ast::File>> =
|
||||
LazyLock::new(Default::default);
|
||||
|
||||
Interned::to_ref(&INTERNER.get_or_insert(file))
|
||||
INTERNER.get_or_insert(file).to_ref()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user