chicken-users
[Top][All Lists]
Advanced

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

Re: Using block compilation with compilation units


From: felix . winkelmann
Subject: Re: Using block compilation with compilation units
Date: Mon, 27 Dec 2021 13:20:07 +0100

> Hello Robert,
>
> you are right, you can not directly call procedures from modules/units
> compiled with -block.
>
> A trick I used to "export" procedures was to have two compilation units
> (I used modules for both).  One, the "hook", defining and exporting top
> level bindings, which is not compiled in block mode and a second
> "implementer", which imports from hook and used `set!` to assign the
> bindings.  Other modules only import hook.  (Gotcha: Be sure to force
> initialization of the implementer before any other use of those
> bindings.)
>

(That's a clever trick, Joerg.)

As Joerg writes, block mode is specifically intended to ignore possibly
external bindings. The idea is to have a single compilation unit only
to give the optimizer maximum opportunities to inline calls and remove
dead code. If you want to split up your code into several source files,
use "include" to include the files into a single compilation unit, the
files can include module definitions, if needed.

So if compile-times are not an issue for you, I'd suggest "include",
otherwise the trick suggested seems to me like the only alternative.


felix




reply via email to

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