]> Repositorios git - scryer-prolog.git/commitdiff
throw permission_error in compile_assert when attempting to assert a built-in (#1872)
authorMark <[email protected]>
Thu, 13 Jul 2023 21:03:26 +0000 (15:03 -0600)
committerMark <[email protected]>
Thu, 13 Jul 2023 21:03:26 +0000 (15:03 -0600)
src/machine/dispatch.rs
src/machine/loader.rs
src/machine/machine_errors.rs
src/machine/machine_indices.rs

index 3b30e75b208f2f3250450f8586a79e029cd95e40..afe67fb9e0785ea10291dfc69919d8aa9b84dc44 100644 (file)
@@ -4919,11 +4919,19 @@ impl Machine {
                     self.machine_st.p = self.machine_st.cp;
                 }
                 &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);
                 }
                 &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);
                 }
                 &Instruction::CallMetaPredicateProperty => {
index 5a309197bca6e3dd463d96b1fad4f1823f02e654..9da054c7566b590e88453972ed2f748e7758c8cf 100644 (file)
@@ -2016,6 +2016,7 @@ impl Machine {
             };
 
             let arity = head.arity();
+            let is_builtin = loader.wam_prelude.indices.builtin_property((name, arity));
 
             let is_dynamic_predicate = loader
                   .wam_prelude
@@ -2026,7 +2027,7 @@ impl Machine {
                   );
 
             let no_such_predicate =
-                if !is_dynamic_predicate && !ClauseType::is_inbuilt(name, arity) {
+                if !is_dynamic_predicate && !is_builtin {
                     let idx_tag = loader
                         .wam_prelude
                         .indices
@@ -2038,8 +2039,9 @@ impl Machine {
                         .map(|code_idx| code_idx.get_tag())
                         .unwrap_or(IndexPtrTag::DynamicUndefined);
 
-                    idx_tag == IndexPtrTag::DynamicUndefined ||
-                    idx_tag == IndexPtrTag::Undefined
+                    idx_tag == IndexPtrTag::DynamicUndefined || idx_tag == IndexPtrTag::Undefined
+                } else if is_builtin {
+                    return Err(SessionError::CannotOverwriteBuiltIn((name, arity)));
                 } else {
                     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>> {
index 62b06ca25a67d95e42fc7cebff22a2291b7e59d8..936200f059b5db5435564799b4b76d965ea391d5 100644 (file)
@@ -442,7 +442,7 @@ impl MachineState {
             // SessionError::CannotOverwriteImport(pred_atom) => {
                 self.permission_error(
                     Permission::Modify,
-                    atom!("private_procedure"),
+                    atom!("static_procedure"),
                     functor_stub(key.0, key.1).into_iter().collect::<MachineStub>(),
                 )
             }
index df880447f5d438ea08a7c241f6c7e6b098a07857..b19ac3bf44ec60b09356695ac3e13596bf5c029e 100644 (file)
@@ -3,6 +3,7 @@ use crate::parser::ast::*;
 use crate::arena::*;
 use crate::atom_table::*;
 use crate::forms::*;
+use crate::machine::ClauseType;
 use crate::machine::loader::*;
 use crate::machine::machine_state::*;
 use crate::machine::streams::Stream;
@@ -259,6 +260,20 @@ pub struct 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)]
     pub(crate) fn goal_expansion_defined(&self, key: PredicateKey) -> bool {
         self.goal_expansion_indices.contains(&key)