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

RE: how to make a function inline

>	Date: Mon, 23 Jul 90 19:34:47 PDT
>	From: lakin@csli.Stanford.EDU (Fred Lakin)
>	To: kcl@CLI.COM
>	Subject: how to make a function inline?

>	Example is below. am i doing something wrong? My understanding
>	is that the line 

>		static LnkT0(){ call_or_link(VV[0],&Lnk0);} /* FOO */

>	would not present in the disassembled code if foo were being
>	compiled inline.

>	tnx, f

As I wrote in the KCL Report, INLINE declarations do not work for
user-defined functions.  This is because I did not know any simple way
to expand user-defined functions inline, without modifying the semantics
of the function.  (What happens if the function refers to a global
variable and its body is to be embedded within the scope of a local
variable with the same name?)  Instead, KCL provides a macro
SI:DEFINE-INLINE-FUNCTION.  This macro is similar to DEFUN, but the
compiler always expands a call to the function inline.  The problem of
the INLINE declaration remains, but I believe that, since the user is
aware of the explicit declaration by SI:DEFINE-INLINE-FUNCTION, use of
this macro is safer than INLINE.

Here's an example of the use of SI:DEFINE-INLINE-FUNCTION.  See that
the function FOO is invoked as an ordinary function defined by DEFUN,
but the call to FOO in BAR is replaced by the body of FOO.

Starts dribbling to aaa.lll (1990/7/28, 11:29:22).

>(si:define-inline-function foo (x) (car x))

>(foo '(a b))

>(defun bar (x) (foo x))

>(disassemble 'bar)
init_code(start,size,data)char *start;int size;object data;
{	register object *base=vs_top;register object *sup=base+VM2;vs_top=sup;vs_check;
/*	function definition for BAR	*/

static L1()
{	register object *base=vs_base;
	register object *sup=base+VM3;
	base[2]= CMPcar(base[0]);


-- Taiichi