add top level declarative structure
This commit is contained in:
@@ -24,7 +24,7 @@ pub enum VarStatus {
|
||||
}
|
||||
|
||||
// Perm: 0 initially, a stack register once processed.
|
||||
// Temp: labeled with chunk_num and temp offset (unassigned if 0), arg (0 if unassigned).
|
||||
// Temp: labeled with chunk_num and temp offset (unassigned if 0).
|
||||
pub enum VarData {
|
||||
Perm(usize), Temp(usize, usize, TempVarData)
|
||||
}
|
||||
|
||||
@@ -304,49 +304,53 @@ Each predicate must have the same name and arity.";
|
||||
pub fn print(wam: &mut Machine, result: EvalSession) {
|
||||
match result {
|
||||
EvalSession::InitialQuerySuccess(alloc_locs, mut heap_locs) => {
|
||||
println!("yes");
|
||||
println!("true");
|
||||
|
||||
if heap_locs.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
'outer: loop {
|
||||
loop {
|
||||
let mut result = EvalSession::QueryFailure;
|
||||
let bindings = wam.heap_view(&heap_locs);
|
||||
|
||||
let stdin = stdin();
|
||||
let mut stdout = stdout().into_raw_mode().unwrap();
|
||||
|
||||
write!(stdout, "{}\n\r", bindings).unwrap();
|
||||
write!(stdout, "{}", bindings).unwrap();
|
||||
stdout.flush().unwrap();
|
||||
|
||||
if !wam.or_stack_is_empty() {
|
||||
write!(stdout, "Press ; to continue or . to abort.\n\r").unwrap();
|
||||
stdout.flush().unwrap();
|
||||
|
||||
for c in stdin.keys() {
|
||||
match c.unwrap() {
|
||||
Key::Char(';') => {
|
||||
write!(stdout, " ;\n\r").unwrap();
|
||||
result = wam.continue_query(&alloc_locs, &mut heap_locs);
|
||||
break;
|
||||
},
|
||||
Key::Char('.') =>
|
||||
break 'outer,
|
||||
Key::Char('.') => {
|
||||
write!(stdout, " .\n\r").unwrap();
|
||||
return;
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
if let &EvalSession::QueryFailure = &result {
|
||||
write!(stdout, "no\n\r").unwrap();
|
||||
write!(stdout, "false.\n\r").unwrap();
|
||||
stdout.flush().unwrap();
|
||||
break;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
write!(stdout(), ".\n").unwrap();
|
||||
},
|
||||
EvalSession::QueryFailure => println!("no"),
|
||||
EvalSession::QueryFailure => println!("false."),
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -306,10 +306,6 @@ impl Machine {
|
||||
-> EvalSession
|
||||
{
|
||||
if !self.or_stack_is_empty() {
|
||||
if self.ms.b == 0 {
|
||||
return EvalSession::QueryFailure;
|
||||
}
|
||||
|
||||
let b = self.ms.b - 1;
|
||||
self.ms.p = self.ms.or_stack[b].bp;
|
||||
|
||||
@@ -386,7 +382,7 @@ impl Machine {
|
||||
}
|
||||
|
||||
pub fn or_stack_is_empty(&self) -> bool {
|
||||
self.ms.or_stack.is_empty()
|
||||
self.ms.b == 0
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
|
||||
Reference in New Issue
Block a user