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 some symbol functions #308

Merged
merged 3 commits into from Sep 19, 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

@@ -1346,6 +1346,7 @@ extern "C" {
pub static Qwrite_region: Lisp_Object;
pub static Qbuffer_file_coding_system: Lisp_Object;
pub static Qfont_extra_type: Lisp_Object;
pub static Qsetting_constant: Lisp_Object;

pub static Qmd5: Lisp_Object;
pub static Qsha1: Lisp_Object;
@@ -258,6 +258,8 @@ pub extern "C" fn rust_init_syms() {
defsubr(&*symbols::Sfboundp);
defsubr(&*symbols::Ssymbol_function);
defsubr(&*symbols::Ssymbol_plist);
defsubr(&*symbols::Ssetplist);
defsubr(&*symbols::Sfmakunbound);
defsubr(&*lists::Sconsp);
defsubr(&*lists::Ssetcar);
defsubr(&*lists::Ssetcdr);
@@ -318,6 +320,7 @@ pub extern "C" fn rust_init_syms() {
defsubr(&*vectors::Svectorp);
defsubr(&*vectors::Slength);
defsubr(&*vectors::Selt);
defsubr(&*vectors::Srecordp);
defsubr(&*hashtable::Scopy_hash_table);
defsubr(&*fonts::Sfontp);
defsubr(&*crypto::Smd5);
@@ -554,6 +554,12 @@ impl LispObject {
None
})
}

pub fn is_record(self) -> bool {
self.as_vectorlike().map_or(false, |v| {
v.is_pseudovector(PseudovecType::PVEC_RECORD)
})
}
}

impl LispObject {
@@ -1,6 +1,6 @@
use remacs_macros::lisp_fn;
use lisp::{LispObject, ExternalPtr};
use remacs_sys::Lisp_Symbol;
use remacs_sys::{Lisp_Symbol, Qsetting_constant};

pub type LispSymbolRef = ExternalPtr<Lisp_Symbol>;

@@ -20,6 +20,10 @@ impl LispSymbolRef {
pub fn set_plist(&mut self, plist: LispObject) {
self.plist = plist.to_raw();
}

pub fn set_function(&mut self, function: LispObject) {
self.function = function.to_raw();
}
}

/// Return t if OBJECT is a symbol.
@@ -42,19 +46,38 @@ pub fn symbol_name(symbol: LispObject) -> LispObject {

/// Return t if SYMBOL's function definition is not void.
#[lisp_fn]
pub fn fboundp(object: LispObject) -> LispObject {
let symbol = object.as_symbol_or_error();
pub fn fboundp(symbol: LispObject) -> LispObject {
let symbol = symbol.as_symbol_or_error();
LispObject::from_bool(symbol.get_function().is_not_nil())
}

/// Return SYMBOL's function definition, or nil if that is void.
#[lisp_fn]
fn symbol_function(object: LispObject) -> LispObject {
object.as_symbol_or_error().get_function()
fn symbol_function(symbol: LispObject) -> LispObject {
symbol.as_symbol_or_error().get_function()
}

/// Return SYMBOL's property list.
#[lisp_fn]
fn symbol_plist(object: LispObject) -> LispObject {
object.as_symbol_or_error().get_plist()
fn symbol_plist(symbol: LispObject) -> LispObject {
symbol.as_symbol_or_error().get_plist()
}

/// Set SYMBOL's property list to NEWPLIST, and return NEWPLIST.
#[lisp_fn]
fn setplist(symbol: LispObject, newplist: LispObject) -> LispObject {
symbol.as_symbol_or_error().set_plist(newplist);
newplist
}

/// Make SYMBOL's function definition be nil.
/// Return SYMBOL.
#[lisp_fn]
fn fmakunbound(symbol: LispObject) -> LispObject {
let mut sym = symbol.as_symbol_or_error();
if symbol.is_nil() || symbol.is_t() {
xsignal!(Qsetting_constant, symbol);
}
sym.set_function(LispObject::constant_nil());
symbol
}
@@ -280,6 +280,12 @@ pub fn condition_variable_p(object: LispObject) -> LispObject {
LispObject::from_bool(object.is_condition_variable())
}

/// Return t if OBJECT is a record.
#[lisp_fn]
pub fn recordp(object: LispObject) -> LispObject {
LispObject::from_bool(object.is_record())
}

macro_rules! offset_of {
($ty:ty, $field:ident) => {
&(*(0 as *const $ty)).$field as *const _ as usize
@@ -288,15 +288,6 @@ interned in the initial obarray. */)
return Qnil;
}

DEFUN ("recordp", Frecordp, Srecordp, 1, 1, 0,
doc: /* Return t if OBJECT is a record. */)
(Lisp_Object object)
{
if (RECORDP (object))
return Qt;
return Qnil;
}

#ifdef HAVE_MODULES
DEFUN ("user-ptrp", Fuser_ptrp, Suser_ptrp, 1, 1, 0,
doc: /* Return t if OBJECT is a module user pointer. */)
@@ -371,18 +362,6 @@ Return SYMBOL. */)
return symbol;
}

DEFUN ("fmakunbound", Ffmakunbound, Sfmakunbound, 1, 1, 0,
doc: /* Make SYMBOL's function definition be nil.
Return SYMBOL. */)
(register Lisp_Object symbol)
{
CHECK_SYMBOL (symbol);
if (NILP (symbol) || EQ (symbol, Qt))
xsignal1 (Qsetting_constant, symbol);
set_symbol_function (symbol, Qnil);
return symbol;
}

DEFUN ("fset", Ffset, Sfset, 2, 2, 0,
doc: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION. */)
(register Lisp_Object symbol, Lisp_Object definition)
@@ -459,15 +438,6 @@ The return value is undefined. */)
return symbol;
}

DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0,
doc: /* Set SYMBOL's property list to NEWPLIST, and return NEWPLIST. */)
(register Lisp_Object symbol, Lisp_Object newplist)
{
CHECK_SYMBOL (symbol);
set_symbol_plist (symbol, newplist);
return newplist;
}

DEFUN ("subr-arity", Fsubr_arity, Ssubr_arity, 1, 1, 0,
doc: /* Return minimum and maximum number of args allowed for SUBR.
SUBR must be a built-in function.
@@ -2876,15 +2846,12 @@ syms_of_data (void)
defsubr (&Sinteractive_form);
defsubr (&Stype_of);
defsubr (&Skeywordp);
defsubr (&Srecordp);
defsubr (&Smodule_function_p);
defsubr (&Sindirect_function);
defsubr (&Smakunbound);
defsubr (&Sfmakunbound);
defsubr (&Sboundp);
defsubr (&Sfset);
defsubr (&Sdefalias);
defsubr (&Ssetplist);
defsubr (&Ssymbol_value);
defsubr (&Sset);
defsubr (&Sdefault_boundp);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.