CL implementation questions

Per Bothner per@bothner.com
Sun Apr 1 04:10:00 GMT 2012


On 03/31/2012 01:25 PM, Charles Turner wrote:
> Thanks Jamison&  Per for the comments.
>
> On 28 March 2012 07:47, Per Bothner<per@bothner.com>  wrote:
>> There may be other problems implementing Common Lisp primitives using
>> Common Lisp, but declare a good thing to tackle first.
>
> Some questions whilst thinking about how to start:
>
> - Environments, to which parts of a variables extent the DECLARE form affects.

Depends on what you mean by "Environment".  If you mean 
gnu.mapping.Environment,
then that is wrong.  Note declare is a compile-time thing.  I figure we 
should
treat them similar to Scheme type specifiers, which attach to Declaration
objects.  Of course type specifiers have runtime effects (such as
casts), but the primary goal should be to be able to express using
Common Lisp syntax what is already supported for Scheme.  Presumably
there may be some incompatibilities between how Scheme type specifies
work and how declare works, but we can fine-tune the semantics later.

> - Its special semantics, i.e. it appears computationally invisible,
> only making a difference in certain forms.
>
> I would modify the reader to check for declarations at the start of
> each body.

Modifying the reader seems wrong.  What you need to modify is the
"rewriter".  For example, for lambda you need to modify or override
kawa.lang.Lambda.rewriteBody.  That calls Translator.rewrite_body,
which seems like a good place to hook in declaration-processing.

My first suggestion would be to override rewrite_body method in
Lisp2Compilation such that it just processes the declare forms,
and then calls super.rewrite_body.  This might not work, if it
doesn't you'll know better why not.

> - Macro forms cannot expand into DECLARE exprs.

Why not?

> - Code generation
>
> I suppose there's existing examples of similar generation. I imagine
> it would just about to emitting the byte code equivalent of if (var
> instanceof type) .. when assigning values to variables and such like.

To start with, just use the existing code generation support as used
to implement Scheme type specifiers and coercions.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/



More information about the Kawa mailing list