From 6ae7ae0210f24d55fd49636298b7b7d1ec6ec75e Mon Sep 17 00:00:00 2001 From: notoria Date: Fri, 1 May 2020 16:46:31 +0200 Subject: [PATCH] Enhanced version --- src/main.rs | 5 ----- src/prolog/clause_types.rs | 3 +++ src/prolog/machine/system_calls.rs | 9 +++++++++ src/prolog/toplevel.pl | 3 ++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index c8866b38..fc85a959 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(); } diff --git a/src/prolog/clause_types.rs b/src/prolog/clause_types.rs index 9b550c35..83e144eb 100644 --- a/src/prolog/clause_types.rs +++ b/src/prolog/clause_types.rs @@ -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, } } diff --git a/src/prolog/machine/system_calls.rs b/src/prolog/machine/system_calls.rs index a0e5762a..144bcd8b 100644 --- a/src/prolog/machine/system_calls.rs +++ b/src/prolog/machine/system_calls.rs @@ -3515,6 +3515,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) diff --git a/src/prolog/toplevel.pl b/src/prolog/toplevel.pl index 05cb6b6e..d691c66e 100644 --- a/src/prolog/toplevel.pl +++ b/src/prolog/toplevel.pl @@ -54,7 +54,8 @@ print_help(Args) :- halt. print_version(Args) :- - write('v0.8.120'), nl, % TODO: Something better is required here. + '$scryer_prolog_version'(Version), + write(Version), nl, halt. gather_goal(Type, Args0, Goals) :- -- 2.54.0