add expand_term/2

This commit is contained in:
Mark Thom
2018-10-15 20:07:22 -06:00
parent 24a7206021
commit eabb851d8c
4 changed files with 10 additions and 1 deletions

View File

@@ -141,6 +141,7 @@ The following predicates are built-in to rusty-wam.
* `compound/1` * `compound/1`
* `copy_term/2` * `copy_term/2`
* `cyclic_term/1` * `cyclic_term/1`
* `expand_term/2`
* `false/0` * `false/0`
* `float/1` * `float/1`
* `functor/3` * `functor/3`

View File

@@ -217,6 +217,7 @@ pub struct Module {
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
pub enum SystemClauseType { pub enum SystemClauseType {
CheckCutPoint, CheckCutPoint,
ExpandTerm,
GetBValue, GetBValue,
GetSCCCleaner, GetSCCCleaner,
InstallSCCCleaner, InstallSCCCleaner,
@@ -252,6 +253,7 @@ impl SystemClauseType {
pub fn name(&self) -> ClauseName { pub fn name(&self) -> ClauseName {
match self { match self {
&SystemClauseType::CheckCutPoint => clause_name!("$check_cp"), &SystemClauseType::CheckCutPoint => clause_name!("$check_cp"),
&SystemClauseType::ExpandTerm => clause_name!("$expand_term"),
&SystemClauseType::GetBValue => clause_name!("$get_b_value"), &SystemClauseType::GetBValue => clause_name!("$get_b_value"),
&SystemClauseType::GetDoubleQuotes => clause_name!("$get_double_quotes"), &SystemClauseType::GetDoubleQuotes => clause_name!("$get_double_quotes"),
&SystemClauseType::GetSCCCleaner => clause_name!("$get_scc_cleaner"), &SystemClauseType::GetSCCCleaner => clause_name!("$get_scc_cleaner"),
@@ -286,6 +288,7 @@ impl SystemClauseType {
pub fn from(name: &str, arity: usize) -> Option<SystemClauseType> { pub fn from(name: &str, arity: usize) -> Option<SystemClauseType> {
match (name, arity) { match (name, arity) {
("$check_cp", 1) => Some(SystemClauseType::CheckCutPoint), ("$check_cp", 1) => Some(SystemClauseType::CheckCutPoint),
("$expand_term", 2) => Some(SystemClauseType::ExpandTerm),
("$get_b_value", 1) => Some(SystemClauseType::GetBValue), ("$get_b_value", 1) => Some(SystemClauseType::GetBValue),
("$get_double_quotes", 1) => Some(SystemClauseType::GetDoubleQuotes), ("$get_double_quotes", 1) => Some(SystemClauseType::GetDoubleQuotes),
("$get_scc_cleaner", 1) => Some(SystemClauseType::GetSCCCleaner), ("$get_scc_cleaner", 1) => Some(SystemClauseType::GetSCCCleaner),

View File

@@ -43,6 +43,7 @@ term_expansion(Term0, (ModHead :- ModBody)) :-
expand_body(Term0, (ModTerm, ModTerms), N0, N) :- expand_body(Term0, (ModTerm, ModTerms), N0, N) :-
nonvar(Term0), Term0 = (Term, Terms), !, nonvar(Term0), Term0 = (Term, Terms), !,
nonvar(Term),
expand_body_term(Term, ModTerm, N0, N1), expand_body_term(Term, ModTerm, N0, N1),
expand_body(Terms, ModTerms, N1, N). expand_body(Terms, ModTerms, N1, N).
expand_body(Term0, ModTerm, N0, N) :- expand_body(Term0, ModTerm, N0, N) :-

View File

@@ -190,7 +190,7 @@ impl MachineState {
pub(super) fn system_call(&mut self, ct: &SystemClauseType, pub(super) fn system_call(&mut self, ct: &SystemClauseType,
indices: &IndexStore, indices: &IndexStore,
call_policy: &mut Box<CallPolicy>, call_policy: &mut Box<CallPolicy>,
cut_policy: &mut Box<CutPolicy>,) cut_policy: &mut Box<CutPolicy>)
-> CallResult -> CallResult
{ {
match ct { match ct {
@@ -202,6 +202,10 @@ impl MachineState {
_ => self.fail = true _ => self.fail = true
}; };
}, },
&SystemClauseType::ExpandTerm => {
self.p = CodePtr::Local(LocalCodePtr::UserTermExpansion(0));
return Ok(());
},
&SystemClauseType::GetDoubleQuotes => { &SystemClauseType::GetDoubleQuotes => {
let a1 = self[temp_v!(1)].clone(); let a1 = self[temp_v!(1)].clone();