emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs rewrite in a maintainable language


From: Tom Tromey
Subject: Re: Emacs rewrite in a maintainable language
Date: Sun, 18 Oct 2015 10:58:58 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

John> If they are amenable, would you be willing to prototype it? If we
John> could see a language description for the subset/alternate, and a
John> sample compilation into C for some of the functions we have in
John> Emacs core (that is, reimplementing them as a proof of concept),
John> that would help sell it.

You don't really need to do any subsetting.  With a decent compiler you
can just write elisp.

This is pretty much what I am trying to do here:

https://github.com/tromey/el-compilador

My test case is a chunk of fns.c rewritten into ordinary Emacs Lisp.
See appended.  The C output is gross, but of course it doesn't matter.
(And the C output is incorrect, which does matter.  But it's a WIP.)

I chose chunks of fns.c to translate because these are close to "pure
lisp" - no difficult native code to handle.

One of the next steps is wiring it up to FFI so that native calls can be
implemented in the compiler.  See

https://github.com/tromey/emacs-ffi

This is even rougher; but the basic idea is to reuse FFI function
declarations in the C back end of the compiler to emit direct native
calls.

Tom


Input:

(defun nthcdr (num list)
  (cl-check-type num integer)
  (let ((i 0))
    (while (and (< i num) list)
      (setq list (cdr list))
      (setq i (1+ i)))
    list))

Output:

#include <config.h>
#include <lisp.h>

int plugin_is_GPL_compatible;

static Lisp_Object Qinteger;
static Lisp_Object Qnum;
static Lisp_Object Qwrong_type_argument;

static Lisp_Object Knthcdr;

DEFUN ("nthcdr", Fnthcdr, Snthcdr, 2, 2,
    0,
    doc: /* nothing?? */)
  (Lisp_Object num, Lisp_Object list)
{
  Lisp_Object G1_5;
  Lisp_Object i_13;
  Lisp_Object G4_18;
  Lisp_Object i_17;
  Lisp_Object num_14;
  Lisp_Object list_15;
  Lisp_Object list_36;
  Lisp_Object i_37;
  Lisp_Object G3_12;

BB_0:
  G1_5 = Fintegerp (num);
  if (!NILP (G1_5)) goto BB_1; else goto BB_2;
BB_1:
  i_13 = make_number (0);
  goto BB_5;
BB_5:
  G4_18 = F< (i_17, num_14);
  if (!NILP (G4_18)) goto BB_8; else goto BB_6;
BB_8:
  if (!NILP (list_15)) goto BB_10; else goto BB_6;
BB_10:
  list_36 = Fcdr (list_15);
  i_37 = F1+ (i_17);
  goto BB_5;
BB_6:
  return list_15;
BB_2:
  G3_12 = Flist (Qinteger, num, Qnum);
  Ffuncall (3, ((Lisp_Object[]) { signal, Qwrong_type_argument, G3_12 }));
}


void
init (void)
{
  Qinteger = intern_c_string ("integer");
  staticpro (&Qinteger);
  Qnum = intern_c_string ("num");
  staticpro (&Qnum);
  Qwrong_type_argument = intern_c_string ("wrong-type-argument");
  staticpro (&Qwrong_type_argument);

  defsubr (&Snthcdr);
  XSETSUBR (Knthcdr, &Snthcdr);
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]