use an enum for OpDesc spec

This commit is contained in:
Bennet Bleßmann
2024-07-31 23:48:27 +02:00
parent 2814d79b56
commit 409f56ea37
9 changed files with 216 additions and 148 deletions

View File

@@ -24,8 +24,6 @@ use std::fmt;
use std::ops::{AddAssign, Deref, DerefMut};
use std::path::PathBuf;
use crate::{is_infix, is_postfix};
pub type PredicateKey = (Atom, usize); // name, arity.
/*
@@ -403,16 +401,6 @@ pub struct OpDecl {
pub(crate) name: Atom,
}
#[inline(always)]
pub(crate) fn fixity(spec: u32) -> Fixity {
match spec {
XFY | XFX | YFX => Fixity::In,
XF | YF => Fixity::Post,
FX | FY => Fixity::Pre,
_ => unreachable!(),
}
}
impl OpDecl {
#[inline]
pub(crate) fn new(op_desc: OpDesc, name: Atom) -> Self {
@@ -429,7 +417,7 @@ impl OpDecl {
}
pub(crate) fn insert_into_op_dir(&self, op_dir: &mut OpDir) -> Option<OpDesc> {
let key = (self.name, fixity(self.op_desc.get_spec() as u32));
let key = (self.name, self.op_desc.get_spec().fixity());
if let Some(cell) = op_dir.get_mut(&key) {
let (old_prec, old_spec) = cell.get();
@@ -447,7 +435,7 @@ impl OpDecl {
) -> Result<(), SessionError> {
let (spec, name) = (self.op_desc.get_spec(), self.name);
if is_infix!(spec as u32) {
if spec.is_infix() {
if let Some(desc) = existing_desc {
if desc.post > 0 {
return Err(SessionError::OpIsInfixAndPostFix(name));
@@ -455,7 +443,7 @@ impl OpDecl {
}
}
if is_postfix!(spec as u32) {
if spec.is_postfix() {
if let Some(desc) = existing_desc {
if desc.inf > 0 {
return Err(SessionError::OpIsInfixAndPostFix(name));