term_expansion beginnings

This commit is contained in:
Mark Thom
2018-09-22 16:25:32 -06:00
parent 908972eff1
commit 4d57989c2b
11 changed files with 86 additions and 37 deletions

View File

@@ -1,9 +1,11 @@
use prolog_parser::ast::*;
use prolog_parser::tabled_rc::*;
use prolog::instructions::*;
use prolog::codegen::*;
use prolog::compile::*;
use prolog::debray_allocator::*;
use prolog::heap_print::*;
use prolog::instructions::*;
mod machine_errors;
pub(super) mod machine_state;
@@ -249,6 +251,21 @@ impl Machine {
}
}
#[inline]
pub(super)
fn add_term_expansion_clause(&mut self, clause: PredicateClause) -> Result<(), ParserError>
{
let key = (clause_name!("term_expansion"), 2);
let preds = self.term_dir.entry(key).or_insert(Predicate(vec![]));
preds.0.push(clause);
let mut cg = CodeGenerator::<DebrayAllocator>::new(false, self.ms.flags);
let code = cg.compile_predicate(&preds.0)?;
Ok(self.term_expanders = code)
}
fn lookup_instr(&self, p: CodePtr) -> Option<Line> {
match p {
CodePtr::Local(LocalCodePtr::UserTermExpansion(p)) =>

View File

@@ -203,7 +203,7 @@ impl MachineState {
},
&SystemClauseType::GetDoubleQuotes => {
let a1 = self[temp_v!(1)].clone();
match self.flags.double_quotes {
DoubleQuotes::Chars =>
self.unify(a1, Addr::Con(atom!("chars"))),
@@ -435,14 +435,7 @@ impl MachineState {
return Err(err);
},
&SystemClauseType::Succeed => {},
&SystemClauseType::UnwindStack => self.unwind_stack(),
&SystemClauseType::CompileAndRunQuery => {}
/* let addr = self[temp_v!(1)].clone();
match term_write(&self, addr) {
Err(e) => machine_error
Ok(term) =>
}*/
&SystemClauseType::UnwindStack => self.unwind_stack()
};
self.set_p();

View File

@@ -24,6 +24,11 @@ impl<R: Read> TermStream<R> {
}
}
#[inline]
pub fn add_to_top(&mut self, buf: &str) {
self.parser.add_to_top(buf);
}
#[inline]
pub fn eof(&mut self) -> Result<bool, ParserError> {
Ok(self.stack.is_empty() && self.parser.eof()?)