forked from Orchid/orchid
Converted Interner to work with Rc-s
- Interner no longer contains unsafe code - Tokens now hold a reference to the value they represent directly This will enable many future improvements
This commit is contained in:
@@ -108,7 +108,7 @@ pub fn apply(
|
||||
if let Some(sym) = ctx.symbols.get(name) {
|
||||
Ok((Clause::Apply { f: sym.clone(), x }, (ctx.gas, false)))
|
||||
} else {
|
||||
Err(RuntimeError::MissingSymbol(*name, loc.clone()))
|
||||
Err(RuntimeError::MissingSymbol(name.clone(), loc.clone()))
|
||||
},
|
||||
Clause::P(Primitive::Atom(atom)) => {
|
||||
// take a step in expanding atom
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::fmt::Display;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::foreign::ExternError;
|
||||
use crate::interner::InternedDisplay;
|
||||
use crate::representations::interpreted::ExprInst;
|
||||
use crate::{Location, Sym};
|
||||
|
||||
@@ -22,12 +22,8 @@ impl From<Rc<dyn ExternError>> for RuntimeError {
|
||||
}
|
||||
}
|
||||
|
||||
impl InternedDisplay for RuntimeError {
|
||||
fn fmt_i(
|
||||
&self,
|
||||
f: &mut std::fmt::Formatter<'_>,
|
||||
i: &crate::Interner,
|
||||
) -> std::fmt::Result {
|
||||
impl Display for RuntimeError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Extern(e) => write!(f, "Error in external function: {e}"),
|
||||
Self::NonFunctionApplication(expr) => {
|
||||
@@ -37,7 +33,7 @@ impl InternedDisplay for RuntimeError {
|
||||
write!(
|
||||
f,
|
||||
"{}, called at {loc} is not loaded",
|
||||
i.extern_vec(*sym).join("::")
|
||||
sym.extern_vec().join("::")
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -30,8 +30,9 @@ pub fn run(expr: ExprInst, mut ctx: Context) -> Result<Return, RuntimeError> {
|
||||
i = clause.clone();
|
||||
},
|
||||
Clause::Constant(c) => {
|
||||
let symval = (ctx.symbols.get(c))
|
||||
.ok_or_else(|| RuntimeError::MissingSymbol(*c, loc.clone()))?;
|
||||
let symval = (ctx.symbols.get(c)).ok_or_else(|| {
|
||||
RuntimeError::MissingSymbol(c.clone(), loc.clone())
|
||||
})?;
|
||||
ctx.gas = ctx.gas.map(|g| g - 1); // cost of lookup
|
||||
i = symval.expr().clause.clone();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user