store child process in machine state

This commit is contained in:
Bennet Bleßmann
2025-07-20 21:08:44 +02:00
committed by Bennet Bleßmann
parent 43dd1587fb
commit 1ee4f7a55f
3 changed files with 9 additions and 0 deletions

View File

@@ -20,9 +20,11 @@ use crate::parser::dashu::Integer;
use indexmap::IndexMap; use indexmap::IndexMap;
use std::collections::BTreeMap;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::fmt; use std::fmt;
use std::ops::{Index, IndexMut, Range}; use std::ops::{Index, IndexMut, Range};
use std::process::Child;
use std::sync::Arc; use std::sync::Arc;
pub(crate) type Registers = [HeapCellValue; MAX_ARITY + 1]; pub(crate) type Registers = [HeapCellValue; MAX_ARITY + 1];
@@ -97,6 +99,7 @@ pub struct MachineState {
pub(crate) unify_fn: fn(&mut MachineState), pub(crate) unify_fn: fn(&mut MachineState),
pub(crate) bind_fn: fn(&mut MachineState, Ref, HeapCellValue), pub(crate) bind_fn: fn(&mut MachineState, Ref, HeapCellValue),
pub(crate) run_cleaners_fn: fn(&mut Machine) -> bool, pub(crate) run_cleaners_fn: fn(&mut Machine) -> bool,
pub(crate) child_processes: BTreeMap<u32, Child>,
} }
impl fmt::Debug for MachineState { impl fmt::Debug for MachineState {

View File

@@ -19,6 +19,7 @@ use crate::types::*;
use indexmap::IndexSet; use indexmap::IndexSet;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::collections::BTreeMap;
use std::convert::TryFrom; use std::convert::TryFrom;
impl MachineState { impl MachineState {
@@ -67,6 +68,7 @@ impl MachineState {
unify_fn: MachineState::unify, unify_fn: MachineState::unify,
bind_fn: MachineState::bind, bind_fn: MachineState::bind,
run_cleaners_fn: |_| false, run_cleaners_fn: |_| false,
child_processes: BTreeMap::new(),
} }
} }

View File

@@ -8497,12 +8497,16 @@ impl Machine {
match command.spawn() { match command.spawn() {
Ok(child) => { Ok(child) => {
let pid = child.id(); let pid = child.id();
self.machine_st.child_processes.insert(pid, child);
self.machine_st.bind( self.machine_st.bind(
pid_r pid_r
.as_var() .as_var()
.expect("invalid values should have been rejected on the prolog side"), .expect("invalid values should have been rejected on the prolog side"),
fixnum_as_cell!(Fixnum::build_with(pid)), fixnum_as_cell!(Fixnum::build_with(pid)),
); );
Ok(()) Ok(())
} }
Err(_) => { Err(_) => {