In the high-level language, function calls must use variables to
facilitate shape computation. There is no such requirement after
lowering. Furthermore, a function argument may now be either a LVar or
a LGlobal; allowing arbitrary (low) expressions is the easiest way to
represent this properly.
The goal of having lowering be a pass of its own is to simplify the
compilation by separating the forms of environments that are required
during lowering (shapes, istail, globals for module fields) and those
that are required during compilation (stack size, locations
for identifiers).
This commit, however, does not perform this separation, it merely
duplicates the environment structures on both sides, in the interest
of simplicity / getting a solution that can be tested relatively
quickly. As a result, the code is arguably worse than before --
sometimes you have to go down a bit before you can go up again.
The simplifications should come in followup commits.
The recent change to have errorp raise an exit code makes compile.scm
more usable from a Makefile, but a side-effect is that backtraces are
not shown on failure anymore.
This commit explicitly fixes this.
The declarations of each file are placed into a module whose name is
derived from the filename in the standard OCaml way.
In particular, this changes slightly the semantics of single-file
invocations: now foo.ml is interpreted as if its declarations were
wrapped into a Foo module. The observable behavior of program does not
change, of course, as we only observe the side-effects of the
evaluation.
(This should not change the compilation either, as structure items,
even nested, are compiled into globals. I checked that the generated
bytecode programs for hello.ml keeps the same size.)
Now you can run
make compiler-test
from the root of the repository to run hello.ml, and compare its
output to a version-controlled reference output.
If the output changes for good reasons, you can update the reference
file with
make compiler-test-promote
Note: it may sound unpleasant to version-control program-generated
outputs, but in fact (as long as those outputs are kept
human-readable) this is an excellent idea for testing: it means that
any change to the testing output will be part of the commits/diffs,
making it easier for reviewers to understand the impact of a change.
This is a new abstraction/concept in the codebase: the vhashes that
contain visibility information and a definition are called
"environment bindings".
For now there is only an accessor, bindings-get.