[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).
NIL

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

>(foo '(a b))
A

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

>(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;
	Cstart=start;Csize=size;Cdata=data;set_VV(VV,VM1,data);
	mkLKD;
	MF0(VV[0],L1);
	vs_top=vs_base=base;
}
/*	function definition for BAR	*/

static L1()
{	register object *base=vs_base;
	register object *sup=base+VM3;
	vs_check;
	vs_top=sup;
TTL:;
	base[2]= CMPcar(base[0]);
	vs_top=(vs_base=base+2)+1;
	return;
}

>(dribble)


-- Taiichi