use ExitCode when halting so Drop is called, close terminal stream in rustyline Drop
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
fn main() {
|
fn main() -> std::process::ExitCode {
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use scryer_prolog::*;
|
use scryer_prolog::*;
|
||||||
|
|
||||||
@@ -7,5 +7,5 @@ fn main() {
|
|||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
let mut wam = machine::Machine::new();
|
let mut wam = machine::Machine::new();
|
||||||
wam.run_top_level();
|
wam.run_top_level()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -558,7 +558,7 @@ impl Machine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(super) fn dispatch_loop(&mut self) {
|
pub(super) fn dispatch_loop(&mut self) -> std::process::ExitCode {
|
||||||
'outer: loop {
|
'outer: loop {
|
||||||
for _ in 0 .. INSTRUCTIONS_PER_INTERRUPT_POLL {
|
for _ in 0 .. INSTRUCTIONS_PER_INTERRUPT_POLL {
|
||||||
match &self.code[self.machine_st.p] {
|
match &self.code[self.machine_st.p] {
|
||||||
@@ -3809,13 +3809,8 @@ impl Machine {
|
|||||||
self.is_partial_string();
|
self.is_partial_string();
|
||||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||||
}
|
}
|
||||||
&Instruction::CallHalt => {
|
&Instruction::CallHalt | &Instruction::ExecuteHalt => {
|
||||||
self.halt();
|
return self.halt();
|
||||||
self.machine_st.p += 1;
|
|
||||||
}
|
|
||||||
&Instruction::ExecuteHalt => {
|
|
||||||
self.halt();
|
|
||||||
self.machine_st.p = self.machine_st.cp;
|
|
||||||
}
|
}
|
||||||
&Instruction::CallGetLiftedHeapFromOffset => {
|
&Instruction::CallGetLiftedHeapFromOffset => {
|
||||||
self.get_lifted_heap_from_offset();
|
self.get_lifted_heap_from_offset();
|
||||||
@@ -5356,5 +5351,7 @@ impl Machine {
|
|||||||
Err(_) => unreachable!(),
|
Err(_) => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::process::ExitCode::SUCCESS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ impl Machine {
|
|||||||
self.machine_st.throw_exception(err);
|
self.machine_st.throw_exception(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_module_predicate(&mut self, module_name: Atom, key: PredicateKey) {
|
fn run_module_predicate(&mut self, module_name: Atom, key: PredicateKey) -> std::process::ExitCode {
|
||||||
if let Some(module) = self.indices.modules.get(&module_name) {
|
if let Some(module) = self.indices.modules.get(&module_name) {
|
||||||
if let Some(ref code_index) = module.code_dir.get(&key) {
|
if let Some(ref code_index) = module.code_dir.get(&key) {
|
||||||
let p = code_index.local().unwrap();
|
let p = code_index.local().unwrap();
|
||||||
@@ -283,7 +283,7 @@ impl Machine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_top_level(&mut self) {
|
pub fn run_top_level(&mut self) -> std::process::ExitCode {
|
||||||
let mut arg_pstrs = vec![];
|
let mut arg_pstrs = vec![];
|
||||||
|
|
||||||
for arg in env::args() {
|
for arg in env::args() {
|
||||||
@@ -298,7 +298,7 @@ impl Machine {
|
|||||||
iter_to_heap_list(&mut self.machine_st.heap, arg_pstrs.into_iter())
|
iter_to_heap_list(&mut self.machine_st.heap, arg_pstrs.into_iter())
|
||||||
);
|
);
|
||||||
|
|
||||||
self.run_module_predicate(atom!("$toplevel"), (atom!("$repl"), 1));
|
self.run_module_predicate(atom!("$toplevel"), (atom!("$repl"), 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn configure_modules(&mut self) {
|
pub(crate) fn configure_modules(&mut self) {
|
||||||
|
|||||||
@@ -5229,24 +5229,24 @@ impl Machine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn halt(&mut self) {
|
pub(crate) fn halt(&mut self) -> std::process::ExitCode {
|
||||||
let code = self.deref_register(1);
|
let code = self.deref_register(1);
|
||||||
|
|
||||||
let code = match Number::try_from(code) {
|
let code = match Number::try_from(code) {
|
||||||
Ok(Number::Fixnum(n)) => i32::try_from(n.get_num()).unwrap(),
|
Ok(Number::Fixnum(n)) => u8::try_from(n.get_num()).unwrap(),
|
||||||
Ok(Number::Integer(n)) => n.to_i32().unwrap(),
|
Ok(Number::Integer(n)) => n.to_u8().unwrap(),
|
||||||
Ok(Number::Rational(r)) => {
|
Ok(Number::Rational(r)) => {
|
||||||
// n has already been confirmed as an integer, and
|
// n has already been confirmed as an integer, and
|
||||||
// internally, Rational is assumed reduced, so its
|
// internally, Rational is assumed reduced, so its
|
||||||
// denominator must be 1.
|
// denominator must be 1.
|
||||||
r.numer().to_i32().unwrap()
|
r.numer().to_u8().unwrap()
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::process::exit(code);
|
std::process::ExitCode::from(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|||||||
Reference in New Issue
Block a user