From 74a0f8b899e1a6172f1e24c16d7384e25f27dbc6 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Fri, 15 Feb 2019 20:44:15 -0700 Subject: [PATCH] correct attribute_goals/2 bug, add freeze/2, update README --- README.md | 11 ++++++----- src/prolog/lib/dif.pl | 3 +-- src/prolog/machine/attributed_variables.rs | 14 +++++++------- src/prolog/machine/mod.rs | 2 ++ 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 356548b8..3e3e0e4a 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ Extend rusty-wam to include the following, among other features: * Clause creation and destruction (`asserta/1`, `assertz/1`, `retract/1`, `abolish/1`) with logical update semantics. * Streams and predicates for stream control. +* An incremental compacting garbage collector satisfying the five + properties of "Precise Garbage Collection in Prolog." * Mode declarations. * Extensions for clp(FD). @@ -77,14 +79,12 @@ Gustafson's book "The End of Error." 3. Add support for shift/reset delimited continuations, see "Delimited Continuations for Prolog." -4. Add an incremental compacting garbage collector for the heap. - -5. Add concurrent tables to manage shared references to atoms and +4. Add concurrent tables to manage shared references to atoms and strings. -6. Add optional SLG resolution for fast memoization of predicates. +5. Add optional SLG resolution for fast memoization of predicates. -7. Add some form of JIT predicate indexing. +6. Add some form of JIT predicate indexing. ## Installing rusty-wam @@ -151,6 +151,7 @@ The following predicates are built-in to rusty-wam. * `expand_term/2` * `false/0` * `float/1` +* `freeze/2` * `functor/3` * `goal_expansion/2` * `ground/1` diff --git a/src/prolog/lib/dif.pl b/src/prolog/lib/dif.pl index c2097fd4..82aa5f1c 100644 --- a/src/prolog/lib/dif.pl +++ b/src/prolog/lib/dif.pl @@ -36,8 +36,7 @@ verify_attributes(Var, Value, Goals) :- % suggestions for improvement. dif(X, Y) :- X \== Y, - ( X \= Y -> true - ; term_variables(X, XVars), term_variables(Y, YVars), + ( term_variables(X, XVars), term_variables(Y, YVars), dif_set_variables(XVars, X, Y), dif_set_variables(YVars, X, Y) ). diff --git a/src/prolog/machine/attributed_variables.rs b/src/prolog/machine/attributed_variables.rs index bd7ec478..b8216e2e 100644 --- a/src/prolog/machine/attributed_variables.rs +++ b/src/prolog/machine/attributed_variables.rs @@ -83,14 +83,14 @@ impl MachineState { self[temp_v!(2)] = value_list_addr; } - fn gather_attr_vars_created_since(&mut self, h: usize) -> IntoIter { + fn gather_attr_vars_created_since(&self, h: usize) -> IntoIter { let mut attr_vars = HashSet::new(); - for i in h .. self.heap.len() { + for i in h .. self.heap.h { let addr = self.heap[i].as_addr(i); - match self.store(self.deref(addr)) { - Addr::AttrVar(h) => { + match addr { + Addr::AttrVar(h) if i == h => { attr_vars.insert(Addr::AttrVar(h)); }, _ => {} @@ -162,13 +162,13 @@ impl MachineState { if attr_goals.is_empty() { return; } - + let mut output = PrinterOutputter::new(); for goal_addr in attr_goals { let mut printer = HCPrinter::from_heap_locs(&self, output, var_dict); printer.see_all_locs(); - + printer.numbervars = false; printer.quoted = true; @@ -179,7 +179,7 @@ impl MachineState { // cut trailing ", " let output_len = output.len(); output.truncate(output_len - 2); - + println!("\r\n{}\r", output.result()); } } diff --git a/src/prolog/machine/mod.rs b/src/prolog/machine/mod.rs index 1b6ac2a5..54f27231 100644 --- a/src/prolog/machine/mod.rs +++ b/src/prolog/machine/mod.rs @@ -320,6 +320,7 @@ static TERMS: &str = include_str!("../lib/terms.pl"); static DCGS: &str = include_str!("../lib/dcgs.pl"); static ATTS: &str = include_str!("../lib/atts.pl"); static DIF: &str = include_str!("../lib/dif.pl"); +static FREEZE: &str = include_str!("../lib/freeze.pl"); impl Machine { fn compile_special_forms(&mut self) { @@ -349,6 +350,7 @@ impl Machine { compile_user_module(self, DCGS.as_bytes()); compile_user_module(self, ATTS.as_bytes()); compile_user_module(self, DIF.as_bytes()); + compile_user_module(self, FREEZE.as_bytes()); } pub fn new() -> Self { -- 2.54.0