Designing a calling convention for a Lisp->C compiler

Manuel <msimoni@gmail.com>
Thu, 3 Jun 2010 06:05:12 -0700 (PDT)

          From comp.compilers

Related articles
Designing a calling convention for a Lisp->C compiler msimoni@gmail.com (Manuel) (2010-06-03)
Re: Designing a calling convention for a Lisp->C compiler marc@lithia.nl (Marc van Lieshout) (2010-06-03)
Re: Designing a calling convention for a Lisp->C compiler kym@sdf.lonestar.org (russell kym horsell) (2010-06-04)
Re: Designing a calling convention for a Lisp->C compiler kym@sdf.lonestar.org (russell kym horsell) (2010-06-06)
Re: Designing a calling convention for a Lisp->C compiler cr88192@hotmail.com (BGB / cr88192) (2010-06-06)
Re: Designing a calling convention for a Lisp->C compiler comp.compilers@inglorion.net (Robbert Haarman) (2010-06-07)
Re: Designing a calling convention for a Lisp->C compiler gene.ressler@gmail.com (Gene) (2010-06-06)
| List of all articles for this month |

From: Manuel <msimoni@gmail.com>
Newsgroups: comp.compilers
Date: Thu, 3 Jun 2010 06:05:12 -0700 (PDT)
Organization: Compilers Central
Keywords: Lisp, C, question
Posted-Date: 03 Jun 2010 15:09:22 EDT

Hello group!


I am building a Lisp to C compiler. I don't know very much about the
lowlevel details of things like stdarg, so I it is rather unclear for
me how to go about making this as efficient as possible.


The requirements are similar to Common Lisp parameter passing:


There are two groups of parameters, _positional_ and _named_
parameters, and these are strictly separated (in contrast to Python,
where the call site may determine what arguments to pass as positional
and named arguments.)


There may be zero or more _required_ positional arguments, zero or
more _optional_ positional arguments, and any additional positional
arguments may be collected by the called function into a "rest"
parameter, a list.


The named parameters are always optional. Additionally, the called
function may collect _all_ named arguments into an "all-keys"
parameter, a dictionary.


One possible calling convention would be to pass the numbers of
positional and named parameters as the first two arguments, followed
by the positional arguments, followed by pairs of name/argument for
the named parameters.


lisp_obj *
lisp_function(uint16 npos, uint16 nnamed, ...);


A call like (some-function a b :name-1 c :name-2 d) is a call to a
function called some-function with two positional arguments with the
values a and b, and the named parameters name-1 and name-2 with the
values c and d, respectively.


The compiler would translate this call to something like this:
some_function(2, 2, a, b, "name-1", c, "name-2", d);


The function would then use stdarg to take the passed arguments apart,
and assign them to local variables inside the function.


What do you think?


Thanks in advance for any help!


Manuel J. Simoni


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.