]> Repositorios git - scryer-prolog.git/commitdiff
minor fixes
authorMark Thom <[email protected]>
Thu, 18 Apr 2019 03:31:00 +0000 (21:31 -0600)
committerMark Thom <[email protected]>
Thu, 18 Apr 2019 03:31:00 +0000 (21:31 -0600)
Cargo.toml
src/prolog/lib/builtins.pl
src/prolog/macros.rs

index 754d19cc9c652bd39d32f02d738c23940de4a8f3..454fb1c4e32dcfc8265b4fa9eb7a18552a14b542 100644 (file)
@@ -1,6 +1,6 @@
 [package]
 name = "scryer-prolog"
-version = "0.8.54"
+version = "0.8.55"
 authors = ["Mark Thom <[email protected]>"]
 repository = "https://github.com/mthom/scryer-prolog"
 description = "A modern Prolog implementation written mostly in Rust."
index b678b3679fa494062b83c7dfb48a38a95493eb64..6127bc362c46cf108ffe9f374a2f53de0d482a4d 100644 (file)
@@ -220,32 +220,28 @@ is_write_option(Functor) :-
     Functor =.. [Name, Arg],
     ( Arg == true -> true
     ; Arg == false -> true
-    ; throw(error(domain_error(write_option, Functor), write_term/2)) ), % 8.14.2.3 e)
+    ; var(Arg) -> throw(error(instantiation_error, write_term/2))
+    ; throw(error(domain_error(write_option, Functor), write_term/2))
+    ), % 8.14.2.3 e)
     ( Name == ignore_ops -> true
     ; Name == quoted -> true
     ; Name == numbervars -> true
-    ; throw(error(domain_error(write_option, Functor), write_term/2)) ). % 8.14.2.3 e)
+    ; throw(error(domain_error(write_option, Functor), write_term/2))
+    ). % 8.14.2.3 e)
 
 inst_member_or([X|Xs], Y, _) :-
-    ( nonvar(X), is_write_option(X) -> ( Y = X, ! ; inst_member_or(Xs, Y, _) )
-    ; throw(instantiation_error) ). % 8.14.2.3 b)
+    (  var(X) -> throw(error(instantiation_error, write_term/2))
+    ;  is_write_option(X) -> ( Y = X, ! ; inst_member_or(Xs, Y, _) )
+    ;  throw(error(domain_error(write_option, X), write_term/2))
+    ).
 inst_member_or([], Y, Y).
 
-%% TODO: complete the predicate! Most read options are missing.
-read_term(Term, Options) :-
+write_term(_, Options) :-
+    var(Options), throw(error(instantiation_error, write_term/2)).
+write_term(Term, Options) :-        
     '$skip_max_list'(_, -1, Options, Options0),
-    (  Options0 == [] -> true
-    ;  var(Options0)  -> throw(error(instantiation_error, read_term/2)) % 8.14.1.3 b)
-    ;  throw(error(type_error(list, Options), read_term/2)) % 8.14.1.3 d)
-    ),
-    (  Options = [variable_names(VarList)] -> '$read_term'(Term, VarList)
-    ;  Options = [] -> read(Term)
-    ;  false
-    ).
-    
-write_term(Term, Options) :-
-    '$skip_max_list'(_, -1, Options, Options0),
-    (  Options0 == [] -> true
+    (  var(Options0)  -> throw(error(instantiation_error, write_term/2))
+    ;  Options0 == [] -> true
     ;  throw(error(type_error(list, Options), write_term/2))
     ), % 8.14.2.3 c)
     inst_member_or(Options, ignore_ops(IgnoreOps), ignore_ops(false)),
@@ -259,6 +255,18 @@ write_canonical(Term) :- write_term(Term, [ignore_ops(true), quoted(true)]).
 
 writeq(Term) :- write_term(Term, [quoted(true), numbervars(true)]).
 
+%% TODO: complete the predicate! Most read options are missing.
+read_term(Term, Options) :-
+    '$skip_max_list'(_, -1, Options, Options0),
+    (  Options0 == [] -> true
+    ;  var(Options0)  -> throw(error(instantiation_error, read_term/2)) % 8.14.1.3 b)
+    ;  throw(error(type_error(list, Options), read_term/2)) % 8.14.1.3 d)
+    ),
+    (  Options = [variable_names(VarList)] -> '$read_term'(Term, VarList)
+    ;  Options = [] -> read(Term)
+    ;  false
+    ).
+
 % expand_goal.
 
 expand_goal(Term0, Term) :- '$expand_goal'(Term0, Term).
@@ -269,9 +277,9 @@ expand_term(Term0, Term) :- '$expand_term'(Term0, Term).
 
 % term_variables.
 
-% ensures List is either a variable or a proper list.
+% ensures List is either a variable or a list.
 can_be_list(List, _)  :- var(List), !.
-can_be_list(List, _)  :- '$skip_max_list'(_, -1, List, Tail), Tail == [], !.
+can_be_list(List, _)  :- '$skip_max_list'(_, -1, List, Tail), ( var(Tail) -> true ; Tail == []), !.
 can_be_list(List, PI) :- throw(error(type_error(list, List), PI)).
 
 term_variables(Term, Vars) :-
index 9620fa8a7f11ec0f232398de99add9b3d81350a6..63e01aa24843556a0e47bf10c7e0d519955ae9fe 100644 (file)
@@ -183,7 +183,7 @@ macro_rules! return_from_clause {
         }
         
         if $lco {
-            $machine_st.p = CodePtr::Local($machine_st.cp.clone());
+            $machine_st.p = CodePtr::Local($machine_st.cp);
         } else {
             $machine_st.p += 1;
         }