Commit Graph

401 Commits

Author SHA1 Message Date
Denis Merigoux
9cecf5587a
Register surface syntax languge in program troughout the compilation chain 2023-09-22 18:05:26 +02:00
zapashcanon
97e5b15531
replace let _ by let () or add type annotation 2023-09-09 22:02:39 +02:00
Louis Gesbert
4910158aea Reformat 2023-09-01 16:24:27 +02:00
Louis Gesbert
8e33355ead Reformat 2023-08-31 18:31:48 +02:00
Louis Gesbert
6bccd89482 Fix OCaml backend for cross-module refs 2023-08-31 18:31:48 +02:00
Louis Gesbert
7db63e5f78 Simplification: store paths in Uids
rather than scattered in structures

The context is still hierarchical for defs though, so one needs to retrieve the
path to lookup in the correct context for info. Exceptions are enums and struct
defs, which are re-exposed at toplevel.
2023-08-31 18:31:48 +02:00
Louis Gesbert
72882f82df Reformat 2023-08-31 17:55:36 +02:00
Louis Gesbert
9bac045d03 Implement module lookups for scopes, structs, and enums 2023-08-31 17:54:39 +02:00
Louis Gesbert
f2fc79f640 Add some helper functions in a wrapper Map module
and use them throughout. No more `List.map fst (Map.bindings m)` !

Also adds some facilities for direct formatting without going through a list.
2023-07-12 11:51:15 +02:00
Louis Gesbert
db34c9a848 Generalise the expression printer
This patch functorises the generic expression printer, in order to be able to
re-use it for end-user printing.

It makes it possible to have an end-user, localised printer that shares the code
for e.g. priority and automatic parens handling.

A generic AST rewriting that disambiguates variables (very simple to write with
bindlib) is also added and used in the OCaml backend for something safer than
just appending `_user` (-- this also handles clashing variables that could be
introduced during compilation which would have generated wrong code before this)

Finally, the `explain` plugin is adapted to use the new printer.

Ah, and `String.format_t` was tweaked to correctly print strings that might
contain unicode without breaking alignment, and should be used instead of
`format_string` or `%s` whenever unicode can be expected.
2023-07-11 17:33:56 +02:00
Louis Gesbert
a3c0c366e6 Some code simplification
We now have all the functions to factorise this code
2023-07-04 18:31:52 +02:00
Louis Gesbert
fcb2d08983 Remove unconditional optimisation on exceptions compilation
This should be handled at a different level
2023-07-04 17:16:09 +02:00
Louis Gesbert
8920564f9e Fix some documentation comments formatting 2023-07-04 10:01:51 +02:00
Louis Gesbert
c799968934 Add a 'modules' plugin with helpers to compile modules
This will be done by Clerk at some point, but the plugin is useful for the time being.
2023-07-03 16:42:54 +02:00
Louis Gesbert
0f9ee2c72e Refacter the main Driver module
- Use separate functions for successive passes in module `Driver.Passes`
- Use other functions for end results printing in module `Driver.Commands`

As a consequence, it is much more flexible to use by plugins or libs and we no
longer need the complex polymorphic variant parameter.

This patch leverages previous changes to use Cmdliner subcommands and
effectively specialises the flags of each Catala subcommand.

Other changes include:

- an attempt to normalise the generic options and reduce the number of global
  references. Some are ok, like `debug` ; some would better be further cleaned up,
  e.g. the ones used by Proof backend were moved to a `Proof.globals` module and
  need discussion. The printer no longer relies on the global languages and prints
  money amounts in an agnostic way.
- the plugin directory is automatically guessed and loaded even in dev setups.
  Plugins are shown by the main `catala` command and listed in `catala --help`
- exception catching at the toplevel has been refactored a bit as well; return
  codes are normalised to follow the manpage and avoid codes >= 128 that are
  generally reserved for shells.

Update tests
2023-07-03 16:42:54 +02:00
Denis Merigoux
5f48e5dac1
Merge branch 'master' into closure_conversion 2023-06-20 11:02:13 +02:00
Denis Merigoux
9007eb4204
Apply suggestions by @altgr 2023-06-19 17:29:51 +02:00
Denis Merigoux
420348beda Added a last TODO and put big example under CI 2023-06-18 21:38:00 +02:00
Denis Merigoux
b55d8c823b Closure conversion & hoisting working 2023-06-18 21:30:55 +02:00
Denis Merigoux
2ddbe93126 Bug identified 2023-06-18 18:15:29 +02:00
Denis Merigoux
a20adc0055 Closure hoisting (missing a bug on hardest case) 2023-06-18 18:08:18 +02:00
Denis Merigoux
2c45ca1599 More doc 2023-06-18 16:08:16 +02:00
Denis Merigoux
9cf55b0edd Closure env is unit if no extra variable captured 2023-06-18 15:49:02 +02:00
Louis Gesbert
ec97c386c3 Reformat + regen 2023-06-15 17:57:01 +02:00
Louis Gesbert
e224e87f71 Wip support for modules
(first working dynload test with compilation done by manual calls to ocaml)

A few pieces of the puzzle:

* Loading of interfaces only from Catala files
* Registration of toplevel values in modules compiled to OCaml, to allow access
  using dynlink
* Shady conversion from OCaml runtime values to/from Catala expressions, to
  allow interop (ffi) of compiled modules and the interpreter
2023-06-15 17:56:57 +02:00
Denis Merigoux
6962761774
Merge branch 'master' into closure_conversion 2023-06-15 17:56:41 +02:00
Denis Merigoux
ed2891c761
Closure conversion should work now 2023-06-15 17:32:00 +02:00
Denis Merigoux
57abfbf2c7
Other pattern matching 2023-06-15 16:33:14 +02:00
Denis Merigoux
2c9b56fb70
More agressive re-typing 2023-06-13 20:37:23 +02:00
Aminata-Dev
10d147a8b1 Messages renamed to Message (lighter syntax) 2023-06-13 11:50:56 +02:00
Denis Merigoux
7072369b2d
Starting to work 2023-06-13 11:43:13 +02:00
Denis Merigoux
926c9436e3
Fix some bugs 2023-06-13 11:15:32 +02:00
Denis Merigoux
0e99d1598b
Continue closure conversion 2023-06-13 10:49:46 +02:00
Denis Merigoux
45375dd7b5
Fix a bug in closure conversion 2023-06-12 15:21:06 +02:00
Denis Merigoux
cdae3e43ac
Improve names of temp variable in monadic pass 2023-06-12 15:02:08 +02:00
Louis Gesbert
16c93fbb0c Reformat 2023-06-08 12:14:11 +02:00
Louis Gesbert
deaf40761e Use ocolor instead of ANSITerminal 2023-06-08 12:11:55 +02:00
Denis Merigoux
79801292e9
Fix most doc errors 2023-06-02 17:17:45 +02:00
Denis Merigoux
4e6efe08da All renamings done, on with actual refactor 2023-06-02 10:50:33 +02:00
Denis Merigoux
0faa97b8fc Abstract messages interface 2023-06-02 10:50:29 +02:00
Denis Merigoux
8987d358e7
Implement the rest 2023-05-26 16:54:52 +02:00
Louis Gesbert
209be6b758 Improve integration of marks into the main AST
Two interdependent changes here:
1. Enforce all instances of Shared_ast.gexpr to use the generic type for marks.
   This makes the interfaces a tad simpler to manipulate: you now write
   `('a, 'm) gexpr` rather than `('a, 'm mark) gexpr`.
2. Define a polymorphic `Custom` mark case for use by pass-specific annotations.
   And leverage this in the typing module
2023-05-17 17:37:00 +02:00
Louis Gesbert
fc531777c0 Rework and normalise the Marked interface
The module is renamed to `Mark`, and functions renamed to avoid redundancy:

`Marked.mark` is now `Mark.add`
`Marked.unmark` is now `Mark.remove`
`Marked.map_under_mark` is now simply `Mark.map`
etc.

`Marked.same_mark_as` is replaced by `Mark.copy`, but with the arguments
swapped (which seemed more convenient throughout)

Since a type `Mark.t` would indicate a mark, and to avoid confusion, the type
`Marked.t` is renamed to `Mark.ed` as a shorthand for `Mark.marked` ; this part
can easily be removed if that's too much quirkiness.
2023-05-17 17:37:00 +02:00
Louis Gesbert
558fcb6fef Build: remove unnecessary ppx on dcalc, lcalc
we only use `visitors` for positions on the surface AST
2023-05-17 14:08:32 +02:00
Louis Gesbert
ba52aae401 Cleanup: definitions.ml is not for values
A module without mli is ok as long as it only contains types

Here we already stretch it a bit with some functor applications, but having
toplevel values defeats the expectation that you can safely `open` this module.
2023-05-17 13:26:47 +02:00
Louis Gesbert
b1955bd9d4 Don't use a debug printing function for OCaml output 2023-05-02 16:48:01 +02:00
Louis Gesbert
5e26c5c83d Yet more printer improvements
- Fix the printer for scopes
- Improve the printer for struct types
- Remove `Print.expr'`. Use `Expr.format` as the function with simplified arguments instead.
2023-05-02 16:33:23 +02:00
Louis Gesbert
83e7a845fe Cleanup expr printer interface
- `Print.expr` no longer needs the context
- This removes the need for `expr ~debug` + `expr_debug` ;
  use `Print.expr` for normal (non-debug) output,
  and `Print.expr' ?debug ()` for possibly debug output.
- This improves consistency of debug expr output in many places
- Prints simplified operators (without type suffix) in non-verbose mode

(this patch also fixes some cases of `Expr.skip_wrappers` and leverages the
binder equality provided by Bindlib)
2023-05-02 13:32:16 +02:00
adelaett
ba6fb5d405
fix documentation 2023-04-24 14:00:12 +02:00
Denis Merigoux
32ee2a0c72
Various small fixes to resolve conversations 2023-04-21 14:54:07 +02:00
Denis Merigoux
22b24a8634
Fusion of all optimizations done correctly 2023-04-21 12:32:09 +02:00
Denis Merigoux
067c7b9155
Merge branch 'master' into adelaett-withoutexceptionsfix 2023-04-21 10:55:36 +02:00
Denis Merigoux
107ff95dc4
Remove dependency on ppx_expect and use alcotest instead 2023-04-21 10:37:31 +02:00
Denis Merigoux
f9a6644da3
Cleanliness and aesthetics 2023-04-18 15:45:30 +02:00
Denis Merigoux
0b0451862e
Correct temp variable names 2023-04-18 14:29:22 +02:00
Denis Merigoux
732e058712
Fix typos 2023-04-18 11:42:33 +02:00
adelaett
b642bdbc54
update optimizations 2023-04-14 17:16:01 +02:00
adelaett
cffcdd7cf9
move monad_* to lcalc/Ast.ml 2023-04-14 14:36:28 +02:00
adelaett
02eeb4ad11
Include Bindlib_ext to Expr.Box 2023-04-14 14:18:28 +02:00
adelaett
ddeaa67ff7
Expr.eid -> Expr.fun_id 2023-04-14 14:07:51 +02:00
adelaett
920bd29835
documentation and deadcode elim 2023-04-14 13:59:06 +02:00
adelaett
f21cb1ff69
adding comment 2023-04-14 12:18:28 +02:00
adelaett
6b6272b0f2
adding an nicer error message 2023-04-14 12:16:09 +02:00
adelaett
123ae9e4c1
rename functions to make the code more readable 2023-04-14 12:15:16 +02:00
adelaett
0c357d2972
adding typing information for monad_* functions 2023-04-14 12:13:33 +02:00
adelaett
167ec9189f
adding a todo related to handle_default and handle_default_opt for
the closure conversion.
2023-04-14 12:02:03 +02:00
adelaett
5833608179
deadcode elim 2023-04-14 10:56:15 +02:00
adelaett
a53bc27d23
documentation 2023-04-14 10:48:31 +02:00
adelaett
cc66023e51
Thunking justifications and conclusion in avoid_translation pass 2023-04-12 10:58:21 +02:00
adelaett
49e9846386
fix a bug in the translation 2023-04-11 16:14:25 +02:00
adelaett
0cfc446455
implementing the behavior of handle_exceptions_opt for the lcalc interpretor 2023-04-11 14:09:57 +02:00
adelaett
3e35d4b826
Merge branch 'master' into adelaett-withoutexceptionsfix 2023-04-11 11:49:22 +02:00
adelaett
0e8eed7ee1 program equality function 2023-04-07 12:10:08 +02:00
adelaett
6c7ac061d4 fix identation and use new formatting functions as default 2023-04-07 11:57:14 +02:00
adelaett
12d85570e8 fix printing boxes & merge issues 2023-04-07 10:51:21 +02:00
adelaett
9b63743c2f documentation 2023-04-07 10:49:48 +02:00
alain
ec40de83fc
Merge branch 'master' into adelaett-withoutexceptionsfix 2023-04-06 13:57:22 +02:00
adelaett
7ebfb2e66a typo 2023-04-06 13:42:40 +02:00
Louis Gesbert
0098f00512 Yet some more small improvements to the AST encoding 2023-04-05 10:32:58 +02:00
adelaett
82992e9858 documentation 2023-04-04 17:02:26 +02:00
adelaett
60f8c229d5 fix to_ocaml new handledefault and handledefault opt operator 2023-04-04 15:57:33 +02:00
adelaett
06f2e56c74 fix closure conversion non-existent variable 2023-04-04 15:57:11 +02:00
adelaett
8ef3db005f clean deadcode 2023-04-04 15:56:49 +02:00
adelaett
b6cf552913 lcalc optimization documentation 2023-04-04 15:17:59 +02:00
adelaett
685785eaa3 adding assert_closed function 2023-04-03 11:20:19 +02:00
adelaett
e9ead93f3f fix typing errors 2023-03-31 16:01:05 +02:00
adelaett
573df8416f Merge branch 'master' into adelaett-withoutexceptionsfix 2023-03-31 15:52:06 +02:00
adelaett
272dc9e8b3 optimization reorg 2023-03-31 15:37:18 +02:00
adelaett
beeecce091 correcting filter definition 2023-03-31 15:31:43 +02:00
adelaett
69ac8ca929 implementation of fold, reduce, map & filter in without exceptions
Work in progress: not working for filter & map
2023-03-31 11:24:43 +02:00
Louis Gesbert
038861a52c Generic mapping function across different ASTs
Used in lcalc/compile_with_exceptions only at the moment
2023-03-30 18:57:51 +02:00
Louis Gesbert
1208744c6b EmptyError is no longer a literal
it's much simpler to handle it as an AST node, as that makes the literal
identical across all AST passes.
2023-03-30 18:54:50 +02:00
Louis Gesbert
4973c74410 Remove date rounding mode from Operator.translate 2023-03-30 15:33:00 +02:00
adelaett
61830bc348 fixing runtime merge errors 2023-03-30 11:02:35 +02:00
adelaett
6dee3874cc Merge branch 'master' into adelaett-withoutexceptionsfix 2023-03-30 10:50:32 +02:00
adelaett
7174480153 start of the translation of fold 2023-03-30 10:39:23 +02:00
adelaett
3e8aae99fe typo in the traslation of lets 2023-03-30 10:39:07 +02:00
adelaett
729d634744 fixing translation of arrays 2023-03-30 10:38:54 +02:00
adelaett
df740eed05 fixing with-exceptions 2023-03-28 10:07:01 +02:00
adelaett
f3abc23c32 fixings tests (90% atm) 2023-03-28 09:54:44 +02:00