throw permission_error in compile_assert when attempting to assert a built-in (#1872)
This commit is contained in:
@@ -4919,11 +4919,19 @@ impl Machine {
|
|||||||
self.machine_st.p = self.machine_st.cp;
|
self.machine_st.p = self.machine_st.cp;
|
||||||
}
|
}
|
||||||
&Instruction::CallBuiltInProperty => {
|
&Instruction::CallBuiltInProperty => {
|
||||||
self.builtin_property();
|
let key = self
|
||||||
|
.machine_st
|
||||||
|
.read_predicate_key(self.machine_st.registers[1], self.machine_st.registers[2]);
|
||||||
|
|
||||||
|
self.machine_st.fail = !self.indices.builtin_property(key);
|
||||||
step_or_fail!(self, self.machine_st.p += 1);
|
step_or_fail!(self, self.machine_st.p += 1);
|
||||||
}
|
}
|
||||||
&Instruction::ExecuteBuiltInProperty => {
|
&Instruction::ExecuteBuiltInProperty => {
|
||||||
self.builtin_property();
|
let key = self
|
||||||
|
.machine_st
|
||||||
|
.read_predicate_key(self.machine_st.registers[1], self.machine_st.registers[2]);
|
||||||
|
|
||||||
|
self.machine_st.fail = !self.indices.builtin_property(key);
|
||||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||||
}
|
}
|
||||||
&Instruction::CallMetaPredicateProperty => {
|
&Instruction::CallMetaPredicateProperty => {
|
||||||
|
|||||||
@@ -2016,6 +2016,7 @@ impl Machine {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let arity = head.arity();
|
let arity = head.arity();
|
||||||
|
let is_builtin = loader.wam_prelude.indices.builtin_property((name, arity));
|
||||||
|
|
||||||
let is_dynamic_predicate = loader
|
let is_dynamic_predicate = loader
|
||||||
.wam_prelude
|
.wam_prelude
|
||||||
@@ -2026,7 +2027,7 @@ impl Machine {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let no_such_predicate =
|
let no_such_predicate =
|
||||||
if !is_dynamic_predicate && !ClauseType::is_inbuilt(name, arity) {
|
if !is_dynamic_predicate && !is_builtin {
|
||||||
let idx_tag = loader
|
let idx_tag = loader
|
||||||
.wam_prelude
|
.wam_prelude
|
||||||
.indices
|
.indices
|
||||||
@@ -2038,8 +2039,9 @@ impl Machine {
|
|||||||
.map(|code_idx| code_idx.get_tag())
|
.map(|code_idx| code_idx.get_tag())
|
||||||
.unwrap_or(IndexPtrTag::DynamicUndefined);
|
.unwrap_or(IndexPtrTag::DynamicUndefined);
|
||||||
|
|
||||||
idx_tag == IndexPtrTag::DynamicUndefined ||
|
idx_tag == IndexPtrTag::DynamicUndefined || idx_tag == IndexPtrTag::Undefined
|
||||||
idx_tag == IndexPtrTag::Undefined
|
} else if is_builtin {
|
||||||
|
return Err(SessionError::CannotOverwriteBuiltIn((name, arity)));
|
||||||
} else {
|
} else {
|
||||||
is_dynamic_predicate
|
is_dynamic_predicate
|
||||||
};
|
};
|
||||||
@@ -2466,20 +2468,6 @@ impl Machine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn builtin_property(&mut self) {
|
|
||||||
let (name, arity) = self
|
|
||||||
.machine_st
|
|
||||||
.read_predicate_key(self.machine_st.registers[1], self.machine_st.registers[2]);
|
|
||||||
|
|
||||||
if !ClauseType::is_inbuilt(name, arity) { // ClauseType::from(key.0, key.1, &mut self.machine_st.arena) {
|
|
||||||
if let Some(module) = self.indices.modules.get(&(atom!("builtins"))) {
|
|
||||||
self.machine_st.fail = !module.code_dir.contains_key(&(name, arity));
|
|
||||||
} else {
|
|
||||||
self.machine_st.fail = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Loader<'a, LiveLoadAndMachineState<'a>> {
|
impl<'a> Loader<'a, LiveLoadAndMachineState<'a>> {
|
||||||
|
|||||||
@@ -442,7 +442,7 @@ impl MachineState {
|
|||||||
// SessionError::CannotOverwriteImport(pred_atom) => {
|
// SessionError::CannotOverwriteImport(pred_atom) => {
|
||||||
self.permission_error(
|
self.permission_error(
|
||||||
Permission::Modify,
|
Permission::Modify,
|
||||||
atom!("private_procedure"),
|
atom!("static_procedure"),
|
||||||
functor_stub(key.0, key.1).into_iter().collect::<MachineStub>(),
|
functor_stub(key.0, key.1).into_iter().collect::<MachineStub>(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::parser::ast::*;
|
|||||||
use crate::arena::*;
|
use crate::arena::*;
|
||||||
use crate::atom_table::*;
|
use crate::atom_table::*;
|
||||||
use crate::forms::*;
|
use crate::forms::*;
|
||||||
|
use crate::machine::ClauseType;
|
||||||
use crate::machine::loader::*;
|
use crate::machine::loader::*;
|
||||||
use crate::machine::machine_state::*;
|
use crate::machine::machine_state::*;
|
||||||
use crate::machine::streams::Stream;
|
use crate::machine::streams::Stream;
|
||||||
@@ -259,6 +260,20 @@ pub struct IndexStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl IndexStore {
|
impl IndexStore {
|
||||||
|
pub(crate) fn builtin_property(&self, key: PredicateKey) -> bool {
|
||||||
|
let (name, arity) = key;
|
||||||
|
|
||||||
|
if !ClauseType::is_inbuilt(name, arity) {
|
||||||
|
return if let Some(module) = self.modules.get(&(atom!("builtins"))) {
|
||||||
|
module.code_dir.contains_key(&(name, arity))
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn goal_expansion_defined(&self, key: PredicateKey) -> bool {
|
pub(crate) fn goal_expansion_defined(&self, key: PredicateKey) -> bool {
|
||||||
self.goal_expansion_indices.contains(&key)
|
self.goal_expansion_indices.contains(&key)
|
||||||
|
|||||||
Reference in New Issue
Block a user