]> Repositorios git - scryer-prolog.git/commitdiff
add expand_term/2
authorMark Thom <[email protected]>
Tue, 16 Oct 2018 02:07:22 +0000 (20:07 -0600)
committerMark Thom <[email protected]>
Tue, 16 Oct 2018 02:07:22 +0000 (20:07 -0600)
README.md
src/prolog/instructions.rs
src/prolog/lib/dcgs.pl
src/prolog/machine/system_calls.rs

index 16e6341cfcbfe20b82eef225d2a040620933a539..c62fbf7fffdd724e0fd1b1d0daccdae44c121729 100644 (file)
--- a/README.md
+++ b/README.md
@@ -141,6 +141,7 @@ The following predicates are built-in to rusty-wam.
 * `compound/1`
 * `copy_term/2`
 * `cyclic_term/1`
+* `expand_term/2`
 * `false/0`
 * `float/1`
 * `functor/3`
index b7be416e2824db08df58a3021731523888359d26..0a7723e46b055971f253780db0af1d3a618d0094 100644 (file)
@@ -217,6 +217,7 @@ pub struct Module {
 #[derive(Copy, Clone, PartialEq)]
 pub enum SystemClauseType {
     CheckCutPoint,
+    ExpandTerm,
     GetBValue,
     GetSCCCleaner,
     InstallSCCCleaner,
@@ -252,6 +253,7 @@ impl SystemClauseType {
     pub fn name(&self) -> ClauseName {
         match self {
             &SystemClauseType::CheckCutPoint => clause_name!("$check_cp"),
+            &SystemClauseType::ExpandTerm => clause_name!("$expand_term"),
             &SystemClauseType::GetBValue => clause_name!("$get_b_value"),
             &SystemClauseType::GetDoubleQuotes => clause_name!("$get_double_quotes"),
             &SystemClauseType::GetSCCCleaner => clause_name!("$get_scc_cleaner"),
@@ -286,6 +288,7 @@ impl SystemClauseType {
     pub fn from(name: &str, arity: usize) -> Option<SystemClauseType> {
         match (name, arity) {
             ("$check_cp", 1) => Some(SystemClauseType::CheckCutPoint),
+            ("$expand_term", 2) => Some(SystemClauseType::ExpandTerm),
             ("$get_b_value", 1) => Some(SystemClauseType::GetBValue),
             ("$get_double_quotes", 1) => Some(SystemClauseType::GetDoubleQuotes),
             ("$get_scc_cleaner", 1) => Some(SystemClauseType::GetSCCCleaner),
index bbb9f5d280d038df361eb7f752ab57b42e65fc1a..0d8eb0765426810157759f5613ca858195b982d4 100644 (file)
@@ -43,6 +43,7 @@ term_expansion(Term0, (ModHead :- ModBody)) :-
 
 expand_body(Term0, (ModTerm, ModTerms), N0, N) :-
     nonvar(Term0), Term0 = (Term, Terms), !,
+    nonvar(Term),
     expand_body_term(Term, ModTerm, N0, N1),
     expand_body(Terms, ModTerms, N1, N).
 expand_body(Term0, ModTerm, N0, N) :-
index f193e034d3ad6dbc8df3c07938291a834e43ccd3..a86835b65bfc88896e80b19ee7d0000c180a09bc 100644 (file)
@@ -190,7 +190,7 @@ impl MachineState {
     pub(super) fn system_call(&mut self, ct: &SystemClauseType,
                               indices: &IndexStore,
                               call_policy: &mut Box<CallPolicy>,
-                              cut_policy:  &mut Box<CutPolicy>,)
+                              cut_policy:  &mut Box<CutPolicy>)
                               -> CallResult
     {
         match ct {
@@ -202,6 +202,10 @@ impl MachineState {
                     _ => self.fail = true
                 };
             },
+            &SystemClauseType::ExpandTerm => {
+                self.p = CodePtr::Local(LocalCodePtr::UserTermExpansion(0));
+                return Ok(());
+            },
             &SystemClauseType::GetDoubleQuotes => {
                 let a1 = self[temp_v!(1)].clone();