[gambit-list] Code elimination in (not safe) context

Dimitris Vyzovitis vyzo at hackzen.org
Wed Nov 27 09:10:51 EST 2019


Just a follow up:

It is possible to do it with a cond-expand, as the gerbil compiler can
detect when it is compiling with (not safe).
The contract check in the generated code would be at the function entry
point and look like:
(cond-expand
 (gerbil-runtime-checks
  ...) ;; do checks and raise exception if the contract is violated
 (else))

When the compiler detects that it is in a safe context (absence of a local
or prelude (not safe) declaration), then it
can emit a (define-cond-expand-feature|gerbil-runtime-checks|) for gsc, and
compile in the contract checks.

This is a reasonably good solution, so there is no pressing need to add a
construct to gambit that conditionally compiles based on declarations.

-- vyzo


On Tue, Nov 26, 2019 at 8:39 PM Dimitris Vyzovitis <vyzo at hackzen.org> wrote:

> Is there a mechanism by which we can declare code to be eliminated when
> compiling with (declare (not safe))?
> I haven't been able to find anything, and it would be very nice to have
> something like (when-declare (safe) stuff ...),
> which would be eliminated in unsafe compilation.
> The context is that I want to add a contract system to Gerbil, but I don't
> want the runtime checks to persist when
> compiling with (not safe).
>
> -- vyzo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20191127/c769639e/attachment.htm>


More information about the Gambit-list mailing list