Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port process stuff #325

Merged
merged 6 commits into from Sep 28, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -734,6 +734,71 @@ pub struct Lisp_Char_Table {
pub extras: [Lisp_Object; 1],
}

#[repr(C)]
pub struct Lisp_Process {
/// Name of subprocess terminal.
pub tty_name: Lisp_Object,

/// Name of this process.
pub name: Lisp_Object,

/// List of command arguments that this process was run with.
/// Is set to t for a stopped network process; nil otherwise.
pub command: Lisp_Object,

/// (funcall FILTER PROC STRING) (if FILTER is non-nil)
/// to dispose of a bunch of chars from the process all at once.
pub filter: Lisp_Object,

/// (funcall SENTINEL PROCESS) when process state changes.
pub sentinel: Lisp_Object,

/// (funcall LOG SERVER CLIENT MESSAGE) when a server process
/// accepts a connection from a client.
pub log: Lisp_Object,

/// Buffer that output is going to.
pub buffer: Lisp_Object,

/// t if this is a real child process. For a network or serial
/// connection, it is a plist based on the arguments to
/// make-network-process or make-serial-process.
pub childp: Lisp_Object,

/// Plist for programs to keep per-process state information, parameters, etc.
pub plist: Lisp_Object,

/// Marker set to end of last buffer-inserted output from this process.
pub mark: Lisp_Object,

/// Symbol indicating status of process.
/// This may be a symbol: run, open, closed, listen, or failed.
/// Or it may be a pair (connect . ADDRINFOS) where ADDRINFOS is
/// a list of remaining (PROTOCOL . ADDRINFO) pairs to try.
/// Or it may be (failed ERR) where ERR is an integer, string or symbol.
/// Or it may be a list, whose car is stop, exit or signal
/// and whose cdr is a pair (EXIT_CODE . COREDUMP_FLAG)
/// or (SIGNAL_NUMBER . COREDUMP_FLAG).
pub status: Lisp_Object,

/// Coding-system for decoding the input from this process.
pub decode_coding_system: Lisp_Object,

/// Working buffer for decoding.
pub decoding_buf: Lisp_Object,

/// Coding-system for encoding the output to this process.
pub encode_coding_system: Lisp_Object,

/// Working buffer for encoding.
pub encoding_buf: Lisp_Object,

/// Queue for storing waiting writes.
pub write_queue: Lisp_Object,

// TODO: this struct is incomplete.
}

#[repr(C)]
pub struct hash_table_test {
pub name: Lisp_Object,
@@ -788,6 +853,8 @@ extern "C" {
pub static Qbufferp: Lisp_Object;
pub static Qwindowp: Lisp_Object;
pub static Qwindow_live_p: Lisp_Object;
pub static Qprocessp: Lisp_Object;
pub static Qthreadp: Lisp_Object;
pub static Qoverlayp: Lisp_Object;
pub static Qminus: Lisp_Object;
pub static Qmark_inactive: Lisp_Object;
@@ -385,6 +385,7 @@ pub extern "C" fn rust_init_syms() {
defsubr(&*editfns::Spoint_max);
defsubr(&*minibuf::Sminibufferp);
defsubr(&*minibuf::Sactive_minibuffer_window);
defsubr(&*cmds::Sforward_point)
defsubr(&*threads::Sthread_name);
defsubr(&*cmds::Sforward_point);
}
}
@@ -16,11 +16,13 @@ use symbols::LispSymbolRef;
use vectors::LispVectorlikeRef;
use buffers::{LispBufferRef, LispOverlayRef};
use windows::LispWindowRef;
use process::LispProcessRef;
use marker::LispMarkerRef;
use hashtable::LispHashTableRef;
use fonts::LispFontRef;
use chartable::LispCharTableRef;
use obarray::LispObarrayRef;
use threads::ThreadStateRef;

use remacs_sys::{EmacsInt, EmacsUint, EmacsDouble, VALMASK, VALBITS, INTTYPEBITS, INTMASK,
USE_LSB_TAG, MOST_POSITIVE_FIXNUM, MOST_NEGATIVE_FIXNUM, Lisp_Type,
@@ -29,7 +31,7 @@ use remacs_sys::{EmacsInt, EmacsUint, EmacsDouble, VALMASK, VALBITS, INTTYPEBITS
Qnumberp, Qfloatp, Qstringp, Qsymbolp, Qnumber_or_marker_p, Qinteger_or_marker_p,
Qwholenump, Qvectorp, Qcharacterp, Qlistp, Qplistp, Qintegerp, Qhash_table_p,
Qchar_table_p, Qconsp, Qbufferp, Qmarkerp, Qoverlayp, Qwindowp, Qwindow_live_p,
SYMBOL_NAME, PseudovecType, EqualKind};
Qprocessp, Qthreadp, SYMBOL_NAME, PseudovecType, EqualKind};

#[cfg(test)]
use functions::ExternCMocks;
@@ -416,6 +418,16 @@ impl LispObject {
})
}

pub fn as_thread(self) -> Option<ThreadStateRef> {
self.as_vectorlike().map_or(None, |v| v.as_thread())
}

pub fn as_thread_or_error(self) -> ThreadStateRef {
self.as_thread().unwrap_or_else(
|| wrong_type!(Qthreadp, self),
)
}

pub fn is_mutex(self) -> bool {
self.as_vectorlike().map_or(false, |v| {
v.is_pseudovector(PseudovecType::PVEC_MUTEX)
@@ -501,6 +513,16 @@ impl LispObject {
})
}

pub fn as_process(self) -> Option<LispProcessRef> {
self.as_vectorlike().map_or(None, |v| v.as_process())
}

pub fn as_process_or_error(self) -> LispProcessRef {
self.as_process().unwrap_or_else(
|| wrong_type!(Qprocessp, self),
)
}

pub fn is_window(self) -> bool {
self.as_vectorlike().map_or(false, |v| {
v.is_pseudovector(PseudovecType::PVEC_WINDOW)
@@ -1,10 +1,12 @@
//! Functions operating on process.

use remacs_macros::lisp_fn;
use remacs_sys::Vprocess_alist;
use lisp::LispObject;
use remacs_sys::{Lisp_Process, Vprocess_alist};
use lisp::{LispObject, ExternalPtr};
use lists::{assoc, cdr};

pub type LispProcessRef = ExternalPtr<Lisp_Process>;

/// Return t if OBJECT is a process.
#[lisp_fn]
pub fn processp(object: LispObject) -> LispObject {
@@ -1,11 +1,31 @@
//! Threading code.

use std::mem;
use remacs_sys::current_thread;
use remacs_sys::{thread_state, current_thread};
use remacs_macros::lisp_fn;
use lisp::{ExternalPtr, LispObject};
use buffers::LispBufferRef;

pub type ThreadStateRef = ExternalPtr<thread_state>;

pub struct ThreadState {}

impl ThreadState {
pub fn current_buffer() -> LispBufferRef {
unsafe { mem::transmute((*current_thread).m_current_buffer) }
}
}

impl ThreadStateRef {
#[inline]
pub fn name(&self) -> LispObject {
LispObject::from_raw(self.name)
}
}

/// Return the name of the THREAD.
/// The name is the same object that was passed to `make-thread'.
#[lisp_fn]
pub fn thread_name(thread: LispObject) -> LispObject {
thread.as_thread_or_error().name()
}
@@ -12,7 +12,9 @@ use multibyte::MAX_CHAR;
use lists::{sort_list, inorder, nthcdr, car};
use buffers::LispBufferRef;
use windows::LispWindowRef;
use process::LispProcessRef;
use chartable::LispCharTableRef;
use threads::ThreadStateRef;
use remacs_sys::{Qsequencep, EmacsInt, PSEUDOVECTOR_FLAG, PVEC_TYPE_MASK, PSEUDOVECTOR_AREA_BITS,
PSEUDOVECTOR_SIZE_MASK, PseudovecType, Lisp_Vectorlike, Lisp_Vector,
Lisp_Bool_Vector, MOST_POSITIVE_FIXNUM, Faref};
@@ -75,6 +77,24 @@ impl LispVectorlikeRef {
}
}

#[inline]
pub fn as_process(&self) -> Option<LispProcessRef> {
if self.is_pseudovector(PseudovecType::PVEC_PROCESS) {
Some(unsafe { mem::transmute(*self) })
} else {
None
}
}

#[inline]
pub fn as_thread(&self) -> Option<ThreadStateRef> {
if self.is_pseudovector(PseudovecType::PVEC_THREAD) {
Some(unsafe { mem::transmute(*self) })
} else {
None
}
}

#[inline]
pub fn as_char_table(&self) -> Option<LispCharTableRef> {
if self.is_pseudovector(PseudovecType::PVEC_CHAR_TABLE) {
@@ -817,19 +817,6 @@ DEFUN ("current-thread", Fcurrent_thread, Scurrent_thread, 0, 0, 0,
return result;
}

DEFUN ("thread-name", Fthread_name, Sthread_name, 1, 1, 0,
doc: /* Return the name of the THREAD.
The name is the same object that was passed to `make-thread'. */)
(Lisp_Object thread)
{
struct thread_state *tstate;

CHECK_THREAD (thread);
tstate = XTHREAD (thread);

return tstate->name;
}

static void
thread_signal_callback (void *arg)
{
@@ -1032,7 +1019,6 @@ syms_of_threads (void)
defsubr (&Sthread_yield);
defsubr (&Smake_thread);
defsubr (&Scurrent_thread);
defsubr (&Sthread_name);
defsubr (&Sthread_signal);
defsubr (&Sthread_alive_p);
defsubr (&Sthread_join);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.