[Top][All Lists]

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

[Chicken-hackers] [PATCH] [5] Aggressively reject definitions in express

From: Peter Bex
Subject: [Chicken-hackers] [PATCH] [5] Aggressively reject definitions in expression contexts (#1309)
Date: Sun, 11 Dec 2016 18:00:09 +0100
User-agent: Mutt/1.5.23 (2014-03-12)

Hi all,

Attached is a patch for #1309, which is due to an underlying problem
that has plagued us for a long time, and has been reported in a few
other bugs too (for example in #445 and #1297, and probably #512 too).

The attached patch fixes this by letting the core compiler (and also
the closure compiler for "eval") keep track of whether or not the
expression it's "walk"ing is at toplevel.  This is then communicated
to "expand" and parameterized.  The exposed API is a procedure called
"at-toplevel?", which can then be used by macros.

I think once we apply this, we might try and see if we can simplify
##sys#canonicalize-body.  It looks like it is more convoluted than
necessary to avoid falling back to the global "define" in places
where defines don't belong.  And it doesn't work properly either,
because even with this patch, something like (let () 1 (define x 2) x)
still evaluates to 2, even though this is forbidden by the spec
(see #1294).  And I think #1132 is also a related bug.

But this patch is a prequisite to cleaning things up, I think.

We could also add a call to ##sys#check-toplevel-definition to the
define-record-printer macro, but I think a proper fix for #1294 is
to rework ##sys#canonicalize-body (I'll work on a follow-up patch
for that once this is accepted).

This patch should probably be applied to CHICKEN 5 only, because it
messes with core macro expansion and changes the API to "expand" as
well.  I think it's acceptable to keep the bogus behaviour in CHICKEN 4,
because it's only triggered by code that's incorrect in the first place.

On a final note, I found it very surprising that in the tests, we use
module declarations as expressions.  In order not to change too much,
I decided to simply reset the "at-toplevel" state to #t when compiling
a module definition.  We might want to revisit that, I think it's
counter-intuitive that module or functor definitions are expressions
that can even yield a value.


Attachment: 0001-Let-macros-know-if-they-run-at-toplevel.patch
Description: Text Data

Attachment: signature.asc
Description: Digital signature

reply via email to

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