Merge pull request #563 from triska/master

ADDED: halt/1, halting with specified exit code
This commit is contained in:
Mark Thom
2020-05-23 16:02:05 -03:00
committed by GitHub
3 changed files with 19 additions and 4 deletions

View File

@@ -580,7 +580,7 @@ impl SystemClauseType {
("$get_lh_from_offset_diff", 3) => Some(SystemClauseType::GetLiftedHeapFromOffsetDiff),
("$get_double_quotes", 1) => Some(SystemClauseType::GetDoubleQuotes),
("$get_scc_cleaner", 1) => Some(SystemClauseType::GetSCCCleaner),
("$halt", 0) => Some(SystemClauseType::Halt),
("$halt", 1) => Some(SystemClauseType::Halt),
("$head_is_dynamic", 1) => Some(SystemClauseType::HeadIsDynamic),
("$install_scc_cleaner", 2) => Some(SystemClauseType::InstallSCCCleaner),
("$install_inference_counter", 3) => Some(SystemClauseType::InstallInferenceCounter),

View File

@@ -52,7 +52,7 @@ user:term_expansion((:- op(Pred, Spec, [Op | OtherOps])), OpResults) :-
findall/3, findall/4, flush_output/0,
flush_output/1, get_byte/1, get_byte/2,
get_char/1, get_char/2, get_code/1, get_code/2,
halt/0, max_arity/1, number_chars/2,
halt/0, halt/1, max_arity/1, number_chars/2,
number_codes/2, once/1, op/3, open/3, open/4,
peek_byte/1, peek_byte/2, peek_char/1,
peek_char/2, peek_code/1, peek_code/2,
@@ -912,7 +912,14 @@ op(Priority, OpSpec, Op) :-
; throw(error(type_error(list, Op), op/3)) % 8.14.3.3 f)
).
halt :- '$halt'.
halt :- halt(0).
halt(N) :-
( -2^31 =< N, N =< 2^31 - 1 ->
'$halt'(N)
; throw(error(domain_error(exit_code, N), halt/1))
).
atom_length(Atom, Length) :-
( var(Atom) -> throw(error(instantiation_error, atom_length/2)) % 8.16.1.3 a)

View File

@@ -3647,7 +3647,15 @@ impl MachineState {
self.fail = true;
}
&SystemClauseType::Halt => {
std::process::exit(0);
let code = self.store(self.deref(self[temp_v!(1)]));
let code = match Number::try_from((code, &self.heap)) {
Ok(Number::Fixnum(n)) => n as i32,
Ok(Number::Integer(n)) => n.to_i32().unwrap(),
_ => { unreachable!() }
};
std::process::exit(code);
}
&SystemClauseType::InstallSCCCleaner => {
let addr = self[temp_v!(1)];