]> Repositorios git - scryer-prolog.git/commitdiff
add non-backtrackable and backtrackable global variables
authorMark Thom <[email protected]>
Wed, 13 Mar 2019 06:16:57 +0000 (00:16 -0600)
committerMark Thom <[email protected]>
Wed, 13 Mar 2019 06:16:57 +0000 (00:16 -0600)
Cargo.lock
Cargo.toml
README.md
src/prolog/lib/builtins.pl
src/prolog/machine/mod.rs

index 5dd057556998a73e96162d9c0dbd3412dde9d26f..6e7aa3a5b8d980d6d1e2f01defc900809bab3ed2 100644 (file)
@@ -111,7 +111,7 @@ dependencies = [
 
 [[package]]
 name = "scryer-prolog"
-version = "0.8.2"
+version = "0.8.3"
 dependencies = [
  "downcast 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
index a6196c957965b9ace0c6df054728f2cf42fb9cab..98d36db4c4a7b7796d8dbecb34ac80c97f6f25f7 100644 (file)
@@ -1,6 +1,6 @@
 [package]
 name = "scryer-prolog"
-version = "0.8.2"
+version = "0.8.3"
 authors = ["Mark Thom <[email protected]>"]
 repository = "https://github.com/mthom/scryer-prolog"
 description = "A modern Prolog implementation written mostly in Rust."
index d8a86f2a1923071f09f8124936f8bb5f3844e9b9..45d8ce27365459183679fff4c3e2dbb9365f485e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -46,8 +46,10 @@ Extend Scryer Prolog to include the following, among other features:
   paper "Indexing `dif/2`" (_done_).
 * All-solutions predicates (`findall/{3,4}`, `bagof/3`, `setof/3`) (_done_).
 * Clause creation and destruction (`asserta/1`, `assertz/1`,
-  `retract/1`, `abolish/1`) with logical update semantics (_done_).
-* Backtrackable global variables via `bb_get/2` and `bb_put/2` (_done_).
+  `retract/1`, `abolish/1`) with logical update semantics (_done_).  
+* Backtrackable and non-backtrackable global variables via `bb_get/2`
+  `bb_put/2` (non-backtrackable) and `b_bb_put/2`
+  (backtrackable).  (_done_).
 * Streams and predicates for stream control (_in progress_).
 * An incremental compacting garbage collector satisfying the five
   properties of "Precise Garbage Collection in Prolog."
index 1de2db6ab856a7d7b884491f88a11bbd8676d5f2..91b693da4e4aceacde9ff63832646caa12c1a97c 100644 (file)
@@ -6,13 +6,13 @@
        (>)/2, (<)/2, (=\=)/2, (=:=)/2, (>=)/2, (=<)/2, (,)/2, (->)/2,
        (;)/2, (=..)/2, (==)/2, (\==)/2, (@=<)/2, (@>=)/2, (@<)/2,
        (@>)/2, (=@=)/2, (\=@=)/2, (:)/2, abolish/1, asserta/1,
-       assertz/1, bagof/3, bb_get/2, bb_put/2, call_cleanup/2,
-       call_with_inference_limit/3, catch/3, clause/2,
-       current_predicate/1, current_prolog_flag/2, expand_goal/2,
-       expand_term/2, findall/3, findall/4, once/1, repeat/0,
-       retract/1, set_prolog_flag/2, setof/3, setup_call_cleanup/3,
-       term_variables/2, throw/1, true/0, false/0, write/1,
-       write_canonical/1, writeq/1, write_term/2]).
+       assertz/1, bagof/3, bb_b_put/2, bb_get/2, bb_put/2,
+       call_cleanup/2, call_with_inference_limit/3, catch/3,
+       clause/2, current_predicate/1, current_prolog_flag/2,
+       expand_goal/2, expand_term/2, findall/3, findall/4, once/1,
+       repeat/0, retract/1, set_prolog_flag/2, setof/3,
+       setup_call_cleanup/3, term_variables/2, throw/1, true/0,
+       false/0, write/1, write_canonical/1, writeq/1, write_term/2]).
 
 /* this is an implementation specific declarative operator used to implement call_with_inference_limit/3
    and setup_call_cleanup/3. switches to the default trust_me and retry_me_else. Indexing choice
@@ -738,7 +738,10 @@ current_predicate(Pred) :-
     ;  throw(error(type_error(predicate_indicator, Pred), current_predicate/1))
     ).
 
-bb_put(Key, NewValue) :- 
+bb_put(Key, Value) :- atom(Key), !, '$store_global_var'(Key, Value).
+bb_put(Key, _) :- throw(error(type_error(atom, Key), bb_put/2)).
+
+bb_b_put(Key, NewValue) :-
     (  bb_get(Key, OldValue) ->
        call_cleanup((store_global_var(Key, NewValue) ; false), store_global_var(Key, OldValue))
     ;  call_cleanup((store_global_var(Key, NewValue) ; false), reset_global_var_at_key(Key))
index 40945f6c2733adb93cef95e29b37db658e8472e6..73706f8bf9b644abb926350d7215903c365db8cd 100644 (file)
@@ -113,7 +113,7 @@ impl SubModuleUser for IndexStore {
                 println!("warning: overwriting {}/{}", &name, arity);
             }
 
-            let (p, module_name) = idx.0.borrow().clone();            
+            let (p, module_name) = idx.0.borrow().clone();
             set_code_index!(code_idx, p, module_name);
             return;
         }
@@ -183,7 +183,7 @@ impl Machine {
        compile_user_module(self, TERMS.as_bytes());
         compile_user_module(self, DCGS.as_bytes());
         compile_user_module(self, ATTS.as_bytes());
-        compile_user_module(self, ORDSETS.as_bytes());        
+        compile_user_module(self, ORDSETS.as_bytes());
         compile_user_module(self, DIF.as_bytes());
         compile_user_module(self, FREEZE.as_bytes());
         compile_user_module(self, REIF.as_bytes());