]> Repositorios git - scryer-prolog.git/commitdiff
Added $scryer_prolog_version/1
authornotoria <[email protected]>
Fri, 1 May 2020 23:52:53 +0000 (01:52 +0200)
committernotoria <[email protected]>
Sat, 2 May 2020 00:19:22 +0000 (02:19 +0200)
src/main.rs
src/prolog/clause_types.rs
src/prolog/machine/system_calls.rs
src/prolog/toplevel.pl

index c8866b38e6bcb55c2a4c65be2aba2b65e2c9a1c5..ff24d88c6ca3a43a31ff99f9753db52d42d2e31f 100644 (file)
@@ -28,7 +28,7 @@ use std::sync::atomic::Ordering;
 extern fn handle_sigint(signal: libc::c_int) {
     let signal = signal::Signal::from_c_int(signal).unwrap();
     if signal == signal::Signal::SIGINT {
-       INTERRUPT.store(true, Ordering::Relaxed);
+        INTERRUPT.store(true, Ordering::Relaxed);
     }
 }
 
@@ -36,11 +36,6 @@ fn main() {
     let handler = signal::SigHandler::Handler(handle_sigint);
     unsafe { signal::signal(signal::Signal::SIGINT, handler) }.unwrap();
 
-    if env::args().skip(1).any(|a| a == "-v" || a == "--version") {
-        println!("{:}", git_version!(cargo_prefix = "cargo:", fallback = "unknown"));
-        return;
-    }
-
     let mut wam = Machine::new(readline::input_stream(), Stream::stdout());
     wam.run_top_level();
 }
index 9b550c35b859e5aed1d0415545ab6980fc2ea83b..83e144ebda0309dbe8ad855e3aa6924d498d0bce 100644 (file)
@@ -264,6 +264,7 @@ pub enum SystemClauseType {
     WAMInstructions,
     WriteTerm,
     WriteTermToChars,
+    ScryerPrologVersion,
 }
 
 impl SystemClauseType {
@@ -418,6 +419,7 @@ impl SystemClauseType {
             &SystemClauseType::WAMInstructions => clause_name!("$wam_instructions"),
             &SystemClauseType::WriteTerm => clause_name!("$write_term"),
             &SystemClauseType::WriteTermToChars => clause_name!("$write_term_to_chars"),
+            &SystemClauseType::ScryerPrologVersion => clause_name!("$scryer_prolog_version"),
         }
     }
 
@@ -552,6 +554,7 @@ impl SystemClauseType {
             ("$wam_instructions", 3) => Some(SystemClauseType::WAMInstructions),
             ("$write_term", 6) => Some(SystemClauseType::WriteTerm),
             ("$write_term_to_chars", 7) => Some(SystemClauseType::WriteTermToChars),
+            ("$scryer_prolog_version", 1) => Some(SystemClauseType::ScryerPrologVersion),
             _ => None,
         }
     }
index d393262695cea7d1ea48334a00ffbebd4f585849..a976423ffeb7edfdbee70e5d976f8605682c295b 100644 (file)
@@ -3543,6 +3543,15 @@ impl MachineState {
                     unreachable!()
                 }
             }
+            &SystemClauseType::ScryerPrologVersion => {
+                use crate::git_version::git_version;
+                let version = self[temp_v!(1)];
+                let buffer =
+                    git_version!(cargo_prefix = "cargo:", fallback = "unknown");
+                let chars = buffer.chars().map(|c| Addr::Char(c));
+                let result = Addr::HeapCell(self.heap.to_list(chars));
+                self.unify(version, result);
+            }
         };
 
         return_from_clause!(self.last_call, self)
index 8f5349172b4ce065198d8c5a2afed87cf9ad5dcc..ad095c199a704cacdab5a0001c3166448e73c689 100644 (file)
@@ -30,15 +30,15 @@ delegate_task([], Goals0) :-
     run_goals(Goals),
     repl.
 delegate_task([Arg0|Args], Goals0) :-
-    (   member(Arg0, ["-h", "--help"]) -> print_help(Args)
-    ;   member(Arg0, ["-v", "--version"]) -> print_version(Args)
+    (   member(Arg0, ["-h", "--help"]) -> print_help
+    ;   member(Arg0, ["-v", "--version"]) -> print_version
     ;   member(Arg0, ["-g", "--goal"]) -> gather_goal(g, Args, Goals0)
     ;   atom_chars(Mod, Arg0),
         catch(use_module(Mod), E, print_exception(E))
     ),
     delegate_task(Args, Goals0).
 
-print_help(_) :-
+print_help :-
     write('Usage: scryer-prolog [OPTIONS] [FILES] [-- ARGUMENTS]'),
     nl, nl,
     write('Options:'), nl,
@@ -51,22 +51,18 @@ print_help(_) :-
     % write('                        '),
     halt.
 
-print_version(_) :-
+print_version :-
     '$scryer_prolog_version'(Version),
     write(Version), nl,
     halt.
 
 gather_goal(Type, Args0, Goals) :-
     length(Args0, N),
-    (   N < 1 -> print_help(_), halt
+    (   N < 1 -> print_help, halt
     ;   true
     ),
     [Gs1|Args] = Args0,
-    (   Type = g -> Gs =.. [Type, Gs1]
-    ;   write('caught: '),
-        write(error(domain_error(arg_type, Type), gather_goal/3)), nl,
-        halt
-    ),
+    Gs =.. [Type, Gs1],
     delegate_task(Args, [Gs|Goals]).
 
 arg_type(g).