Add pid/1 predicate to the os library
This commit is contained in:
@@ -300,6 +300,7 @@ pub(crate) enum SystemClauseType {
|
|||||||
GetEnv,
|
GetEnv,
|
||||||
SetEnv,
|
SetEnv,
|
||||||
UnsetEnv,
|
UnsetEnv,
|
||||||
|
PID,
|
||||||
CharsBase64,
|
CharsBase64,
|
||||||
DevourWhitespace,
|
DevourWhitespace,
|
||||||
IsSTOEnabled,
|
IsSTOEnabled,
|
||||||
@@ -588,6 +589,7 @@ impl SystemClauseType {
|
|||||||
&SystemClauseType::GetEnv => clause_name!("$getenv"),
|
&SystemClauseType::GetEnv => clause_name!("$getenv"),
|
||||||
&SystemClauseType::SetEnv => clause_name!("$setenv"),
|
&SystemClauseType::SetEnv => clause_name!("$setenv"),
|
||||||
&SystemClauseType::UnsetEnv => clause_name!("$unsetenv"),
|
&SystemClauseType::UnsetEnv => clause_name!("$unsetenv"),
|
||||||
|
&SystemClauseType::PID => clause_name!("$pid"),
|
||||||
&SystemClauseType::CharsBase64 => clause_name!("$chars_base64"),
|
&SystemClauseType::CharsBase64 => clause_name!("$chars_base64"),
|
||||||
&SystemClauseType::LoadLibraryAsStream => clause_name!("$load_library_as_stream"),
|
&SystemClauseType::LoadLibraryAsStream => clause_name!("$load_library_as_stream"),
|
||||||
&SystemClauseType::DevourWhitespace => clause_name!("$devour_whitespace"),
|
&SystemClauseType::DevourWhitespace => clause_name!("$devour_whitespace"),
|
||||||
@@ -806,6 +808,7 @@ impl SystemClauseType {
|
|||||||
("$getenv", 2) => Some(SystemClauseType::GetEnv),
|
("$getenv", 2) => Some(SystemClauseType::GetEnv),
|
||||||
("$setenv", 2) => Some(SystemClauseType::SetEnv),
|
("$setenv", 2) => Some(SystemClauseType::SetEnv),
|
||||||
("$unsetenv", 1) => Some(SystemClauseType::UnsetEnv),
|
("$unsetenv", 1) => Some(SystemClauseType::UnsetEnv),
|
||||||
|
("$pid", 1) => Some(SystemClauseType::PID),
|
||||||
("$chars_base64", 4) => Some(SystemClauseType::CharsBase64),
|
("$chars_base64", 4) => Some(SystemClauseType::CharsBase64),
|
||||||
("$load_library_as_stream", 3) => Some(SystemClauseType::LoadLibraryAsStream),
|
("$load_library_as_stream", 3) => Some(SystemClauseType::LoadLibraryAsStream),
|
||||||
("$push_load_context", 2) => Some(SystemClauseType::REPL(REPLCodePtr::PushLoadContext)),
|
("$push_load_context", 2) => Some(SystemClauseType::REPL(REPLCodePtr::PushLoadContext)),
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
|
|
||||||
:- module(os, [getenv/2,
|
:- module(os, [getenv/2,
|
||||||
setenv/2,
|
setenv/2,
|
||||||
unsetenv/1]).
|
unsetenv/1,
|
||||||
|
pid/1]).
|
||||||
|
|
||||||
:- use_module(library(error)).
|
:- use_module(library(error)).
|
||||||
:- use_module(library(charsio)).
|
:- use_module(library(charsio)).
|
||||||
@@ -33,6 +34,10 @@ unsetenv(Key) :-
|
|||||||
must_be_env_var(Key),
|
must_be_env_var(Key),
|
||||||
'$unsetenv'(Key).
|
'$unsetenv'(Key).
|
||||||
|
|
||||||
|
pid(PID) :-
|
||||||
|
can_be(integer, PID),
|
||||||
|
'$pid'(PID).
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
For now, we only support a restricted subset of variable names.
|
For now, we only support a restricted subset of variable names.
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ use std::net::{TcpListener, TcpStream};
|
|||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
use std::ops::Sub;
|
use std::ops::Sub;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::process;
|
||||||
|
|
||||||
use chrono::{offset::Local, DateTime};
|
use chrono::{offset::Local, DateTime};
|
||||||
use cpu_time::ProcessTime;
|
use cpu_time::ProcessTime;
|
||||||
@@ -5351,6 +5352,12 @@ impl MachineState {
|
|||||||
let key = self.heap_pstr_iter(self[temp_v!(1)]).to_string();
|
let key = self.heap_pstr_iter(self[temp_v!(1)]).to_string();
|
||||||
env::remove_var(key);
|
env::remove_var(key);
|
||||||
}
|
}
|
||||||
|
&SystemClauseType::PID => {
|
||||||
|
let a1 = self[temp_v!(1)];
|
||||||
|
let pid = process::id();
|
||||||
|
let addr = self.heap.put_constant(Constant::Integer(Rc::new(Integer::from(pid))));
|
||||||
|
(self.unify_fn)(self, a1, addr);
|
||||||
|
}
|
||||||
&SystemClauseType::CharsBase64 => {
|
&SystemClauseType::CharsBase64 => {
|
||||||
let padding = self.atom_argument_to_string(3);
|
let padding = self.atom_argument_to_string(3);
|
||||||
let charset = self.atom_argument_to_string(4);
|
let charset = self.atom_argument_to_string(4);
|
||||||
|
|||||||
Reference in New Issue
Block a user