properly demarcate ops in dbrefs

This commit is contained in:
Mark Thom
2019-03-30 13:38:03 -06:00
parent 352ebd1706
commit f55968b1b8
4 changed files with 25 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "scryer-prolog"
version = "0.8.25"
version = "0.8.26"
authors = ["Mark Thom <markjordanthom@gmail.com>"]
repository = "https://github.com/mthom/scryer-prolog"
description = "A modern Prolog implementation written mostly in Rust."
@@ -14,7 +14,7 @@ cfg-if = "0.1.7"
downcast = "0.10.0"
num = "0.2"
ordered-float = "0.5.0"
prolog_parser = "0.8.5"
prolog_parser = "0.8.6"
readline_rs_compat = { version = "0.1.7", optional = true }
ref_thread_local = "0.0.0"

View File

@@ -14,8 +14,8 @@ use std::rc::Rc;
#[derive(Clone, PartialEq, Eq, Hash)]
pub enum DBRef {
BuiltInPred(ClauseName, usize),
NamedPred(ClauseName, usize)
BuiltInPred(ClauseName, usize, Option<(usize, Specifier)>),
NamedPred(ClauseName, usize, Option<(usize, Specifier)>)
}
#[derive(Clone, PartialEq, Eq, Hash)]
@@ -409,7 +409,7 @@ pub struct IndexStore {
pub(super) op_dir: OpDir,
}
impl IndexStore {
impl IndexStore {
pub fn predicate_exists(&self, name: ClauseName, module: ClauseName, arity: usize,
op_spec: Option<(usize, Specifier)>)
-> bool

View File

@@ -1,4 +1,5 @@
use prolog_parser::ast::*;
use prolog_parser::parser::get_clause_spec;
use prolog::clause_types::*;
use prolog::heap_iter::*;
@@ -215,9 +216,9 @@ impl MachineState {
}
}
fn get_next_db_ref(&mut self, db_ref: &DBRef, code_dir: &CodeDir) {
fn get_next_db_ref(&mut self, indices: &IndexStore, db_ref: &DBRef) {
match db_ref {
&DBRef::BuiltInPred(ref name, arity) => {
&DBRef::BuiltInPred(ref name, arity, _) => {
let key = (name.as_str(), arity);
match CLAUSE_TYPE_FORMS.borrow().range(&key ..).skip(1).next() {
@@ -225,18 +226,20 @@ impl MachineState {
let a2 = self[temp_v!(2)].clone();
if let Some(r) = a2.as_var() {
self.bind(r, Addr::DBRef(DBRef::BuiltInPred(ct.name(), *arity)));
self.bind(r, Addr::DBRef(DBRef::BuiltInPred(ct.name(), *arity, ct.spec())));
} else {
self.fail = true;
}
},
None =>
match code_dir.iter().next() {
None =>
match indices.code_dir.iter().next() {
Some(((ref name, arity), _)) => {
let a2 = self[temp_v!(2)].clone();
if let Some(r) = a2.as_var() {
self.bind(r, Addr::DBRef(DBRef::NamedPred(name.clone(), *arity)));
let spec = get_clause_spec(name.clone(), *arity,
composite_op!(&indices.op_dir));
self.bind(r, Addr::DBRef(DBRef::NamedPred(name.clone(), *arity, spec)));
} else {
self.fail = true;
}
@@ -247,15 +250,17 @@ impl MachineState {
}
}
},
&DBRef::NamedPred(ref name, arity) => {
&DBRef::NamedPred(ref name, arity, _) => {
let key = (name.clone(), arity);
match code_dir.range(key ..).skip(1).next() {
match indices.code_dir.range(key ..).skip(1).next() {
Some(((name, arity), _)) => {
let a2 = self[temp_v!(2)].clone();
if let Some(r) = a2.as_var() {
self.bind(r, Addr::DBRef(DBRef::NamedPred(name.clone(), *arity)));
let spec = get_clause_spec(name.clone(), *arity,
composite_op!(&indices.op_dir));
self.bind(r, Addr::DBRef(DBRef::NamedPred(name.clone(), *arity, spec)));
} else {
self.fail = true;
}
@@ -524,7 +529,7 @@ impl MachineState {
| addr @ Addr::AttrVar(_) =>
match CLAUSE_TYPE_FORMS.borrow().iter().next() {
Some(((_, arity), ct)) => {
let db_ref = DBRef::BuiltInPred(ct.name(), *arity);
let db_ref = DBRef::BuiltInPred(ct.name(), *arity, ct.spec());
let r = addr.as_var().unwrap();
self.bind(r, Addr::DBRef(db_ref));
@@ -535,7 +540,7 @@ impl MachineState {
}
},
Addr::DBRef(ref db_ref) =>
self.get_next_db_ref(db_ref, &indices.code_dir),
self.get_next_db_ref(&indices, db_ref),
_ => {
self.fail = true;
}
@@ -547,13 +552,13 @@ impl MachineState {
match self.store(self.deref(a1)) {
Addr::DBRef(db_ref) =>
match db_ref {
DBRef::BuiltInPred(name, arity) | DBRef::NamedPred(name, arity) => {
DBRef::BuiltInPred(name, arity, spec) | DBRef::NamedPred(name, arity, spec) => {
let a2 = self[temp_v!(2)].clone();
let a3 = self[temp_v!(3)].clone();
let arity = Number::Integer(Rc::new(BigInt::from_usize(arity).unwrap()));
self.unify(a2, Addr::Con(Constant::Atom(name, None)));
self.unify(a2, Addr::Con(Constant::Atom(name, spec)));
if !self.fail {
self.unify(a3, Addr::Con(Constant::Number(arity)));

View File

@@ -162,8 +162,8 @@ impl fmt::Display for HeapCellValue {
impl fmt::Display for DBRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&DBRef::BuiltInPred(ref name, arity) => write!(f, "db_ref:builtin:{}/{}", name, arity),
&DBRef::NamedPred(ref name, arity) => write!(f, "db_ref:named:{}/{}", name, arity)
&DBRef::BuiltInPred(ref name, arity, _) => write!(f, "db_ref:builtin:{}/{}", name, arity),
&DBRef::NamedPred(ref name, arity, _) => write!(f, "db_ref:named:{}/{}", name, arity)
}
}
}