180 Commits

Author SHA1 Message Date
Gabriel Scherer
95934067f5 deduplication of pattern actions 2020-12-19 10:01:21 +01:00
Gabriel Scherer
dea17c0c16 patterns.ml: use a large right-hand-side in a duplicated action 2020-12-19 10:01:21 +01:00
Gabriel Scherer
9de7a40764 compilation of nested patterns by matrix decomposition 2020-12-19 10:01:21 +01:00
Gabriel Scherer
2e6299f305 parse and ignore module type declarations 2020-12-19 07:20:50 +01:00
Gabriel Scherer
d47ff5c47f substitution-on-the-fly as a generalization of the (let x = y in ...) optimization 2020-12-19 07:17:43 +01:00
Gabriel Scherer
5dc6313d54 opcodes arity compression 2020-12-18 23:48:14 +01:00
Gabriel Scherer
6573717b21 short functions for various (compressible) opcodes 2020-12-18 23:48:14 +01:00
Gabriel Scherer
d5408c2a51 more functions.ml nitpicks 2020-12-17 14:32:13 +01:00
Gabriel Scherer
94387ffc7d test: split functions.ml into sections 2020-12-17 14:29:54 +01:00
Gabriel Scherer
97bbc9e67b surface syntax for local exits as extension points 2020-12-16 11:41:02 +01:00
Gabriel Scherer
ae6d55f8eb backend support for let-exits 2020-12-15 21:24:44 +01:00
Gabriel Scherer
580b73ac39 track exception traps in the compilation environments
Jumping to a local exit will need to pop all traps inserted after the
jump point was placed.
2020-12-15 21:24:44 +01:00
Gabriel Scherer
c820a2d552 function compilation: start from an empty environment 2020-12-15 21:24:44 +01:00
Gabriel Scherer
e8ad32c867 make terminology more consistent 2020-12-14 10:52:04 +01:00
Gabriel Scherer
25b14694d2 use a separate "compilation environment" in compile-* functions 2020-12-14 10:52:04 +01:00
Gabriel Scherer
e341b8b447 stop tracking shapes in the compilation pass 2020-12-14 10:52:04 +01:00
Gabriel Scherer
bed5bba1de free variable computation: use a vset to remember locally-bound variables 2020-12-14 10:52:04 +01:00
Gabriel Scherer
255e342cd4 now that shapes are lowering-only, LLetOpen is not useful anymore 2020-12-14 10:52:04 +01:00
Gabriel Scherer
7658a612eb [minor] move code around 2020-12-14 10:52:04 +01:00
Gabriel Scherer
f591cba43b cleaner handling of low-expression variables
We drop the 'Lident markers from all LVar variables. This is a first
step before changing the environment structure.
2020-12-14 10:52:04 +01:00
Gabriel Scherer
c933e20057 L(Tail)Apply: allow arbitrary function expressions
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.
2020-12-14 10:52:04 +01:00
Gabriel Scherer
42e9805e43 compile-*: remove now-unused "istail" parameter 2020-12-14 10:52:04 +01:00
Gabriel Scherer
ae8328e919 lower more: make lower a self-contained pass
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.
2020-12-14 10:52:04 +01:00
Gabriel Scherer
d4292e5d5e errorp: show a backtrace again
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.
2020-12-12 22:44:52 +01:00
Gabriel Scherer
48c4ad41e9 track the size of the produced bytecode files 2020-12-12 13:21:50 +01:00
Gabriel Scherer
4d4f16572c test/Makefile: do not require that OCAMLRUN be explicitly set anymore
upon usage, this proved annoying
2020-12-12 12:04:37 +01:00
Gabriel Scherer
1460eeea96 compile.scm: exit with an error on parse errors 2020-12-12 12:04:37 +01:00
Gabriel Scherer
19255bce2c split the test file into several testfiles 2020-12-12 12:04:37 +01:00
Gabriel Scherer
6874fb0436 guile compile.scm lib.ml --open Lib main.ml 2020-12-12 11:41:05 +01:00
Gabriel Scherer
1860dc91f8 multifile support: guile compile.scm a.ml b.ml c.ml -o foo.byte
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.)
2020-12-11 21:41:00 +01:00
Gabriel Scherer
c61d94ed0e turn hello.ml into a more convenient test
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.
2020-12-11 18:42:18 +01:00
Gabriel Scherer
8d83210804 [minor] move functions around 2020-12-11 13:21:00 +01:00
Gabriel Scherer
456df1d279 lower function declarations 2020-12-11 13:21:00 +01:00
Gabriel Scherer
f6039c4315
Merge pull request #20 from Ekdohibs/readme
Add READMEs
2020-12-07 22:08:13 +01:00
Gabriel Scherer
ed5d352242
Merge pull request #19 from Ekdohibs/infix-new
General infix and prefix operators
2020-12-07 22:06:22 +01:00
Nathanaël Courant
a5a47ba108 Use pair? for condition on pair 2020-12-07 21:46:01 +01:00
Nathanaël Courant
435d3f8755 Use string-index to make symbol lexing more readable, remove unused errorp parameter 2020-12-07 21:44:29 +01:00
Nathanaël Courant
b84dff4c94 Add READMEs 2020-12-07 18:07:44 +01:00
Nathanaël Courant
cf4506e656 Change bytecode magic number to match the one in the ocaml version we use 2020-12-07 17:16:08 +01:00
Gabriel Scherer
35ffa040ee allow (Cons _) patterns even if Cons has arity >1 2020-12-07 16:24:37 +01:00
Gabriel Scherer
5c3a9b264f first-class status for wildcard patterns 2020-12-07 16:24:37 +01:00
Gabriel Scherer
9a5f6a091c change the grammar of patterns to accept patterns under constructors... but require variable for compilation 2020-12-07 16:24:37 +01:00
Nathanaël Courant
2617b736cc General infix and prefix operators 2020-12-07 16:07:38 +01:00
Nathanaël Courant
5cb0ed73f3 Add tests for argument of functor 2020-12-07 13:29:28 +01:00
Nathanaël Courant
637eb2c355 miniml: add functors 2020-12-07 12:33:33 +01:00
Gabriel Scherer
2fe9599bc1 environments: weird code factorization 2020-12-07 11:36:43 +01:00
Gabriel Scherer
46ca612508 bindings visibility: bindings-exported-only, bindings-make-local 2020-12-07 11:36:43 +01:00
Gabriel Scherer
9dbc6ac08a bindings-filter-map 2020-12-07 11:36:43 +01:00
Gabriel Scherer
2680aa4ff3 bindings in env: introduce bindings-replace to elide explicit 'Export markers 2020-12-07 11:36:43 +01:00
Gabriel Scherer
1bde4c5d88 environments contain "bindings", export bindings-get
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.
2020-12-07 11:36:43 +01:00