shirok / Gauche

Scheme Scripting Engine
https://practical-scheme.net/gauche
Other
822 stars 82 forks source link

Integrating `gauche-package compile` and `precomp` #993

Closed shirok closed 8 months ago

shirok commented 8 months ago

This stemmed from https://github.com/shirok/Gauche/issues/990

gauche-package compile is provided to make building extensions simpler. It originally aimed at handling *.c files and *.stub files.

precomp is for AOT compilation, but it can also handle embedded stub code in *.scm files. Almost all C-Scheme bridge in Gauche source has been moved from genstub to precomp.

Now that we want to retire *.stub, it's better for gauche-package compile to handle *.scm files seamlessly. However, those two tools covers slightly different areas. For extension packages, the important thing is to compile C-Scheme bridge, and pure Scheme code doesn't need to be compiled. OTOH, precomp aims to compile even pure Scheme code, and it has to deal with the complications to keep the behaivor compatible with pure Scheme source (e.g. whether to allow to load component Scheme files individually.)

Since two tools have different purposes, we won't make them into one. However, a bluk of operations are common, so we want a nice abstraction of it in gauche.cgen.precomp module.

shirok commented 8 months ago

Actually, whether gauche-package compile should generate '*.sci' file or not is debatable. If the extension is small and all inline-stubs are in the module defintiion file, then it's reasonable to precompile it and we need sci file. If there are lots of stubs, however, we might want a separate scm file. In that case, module definition file can be a normal Scheme file (with dynamic-load form) that doesn't need to be precompiled.

shirok commented 8 months ago

It is conceptually simpler that we always keep module definition file as pure Scheme, and let the module has separate scm file to be precompiled. The issue is that how to specify the module in the precompiled scm file. We can't use the main module, since the main module file contains dynamic-load to load the dso file that is to be compiled. We can't just select-module, for the module hasn't been defined. Dummy define-module works, but that's a bit confusing, for the "real" module definition is in the module defintiion file.

An idea is to introduce in-module, which is like select-module but allows the named module to be created if it doesn't exist yet. You also need to use necessary libraries if the precompiled Scheme part requires them. That's ugly, since the information is duplicated from the main module defintiion.

shirok commented 8 months ago

Closing. See examples/spigot and examples/mqueue-cpp for how it turned out.