Commit Graph

38 Commits

Author SHA1 Message Date
Louis Gesbert
cee8e57d02 More precise positions for operators throughout 2024-04-30 16:35:08 +02:00
Louis Gesbert
def10e7f98 Message: further simplification 2024-04-10 19:26:23 +02:00
Louis Gesbert
98fc97a241 Rewriting message calls to use the new intf 2024-04-10 19:26:23 +02:00
Louis Gesbert
371f9554b8 Support for list recombinations
The primary use-case for this was to be able to run computations on a list of
structures, then return an updated list with some fields in the structures
modified : that is what we need for distribution of tax amounts among household
members, for example.

This patch has a few components:

- Addition of a test as an example for tax distributions

- Added a transformation, performed during desugaring, that -- where lists are
  syntactically expected, i.e. after the `among` keyword -- turns a (syntactic)
  tuple of lists into a list of tuples ("zipping" the lists)

- Arg-extremum transformation was also fixed to use an intermediate list instead
  of computing the predicate twice

- For convenience, allow to bind multiple variables in most* list
  operations (previously only `let in` and functions allowed it)

- Fixed the printer for tuples to differentiate them from lists

*Note: tuples are not yet allowed on the left-hand side of filters and
arg-extremums for annoying syntax conflict reasons.
2024-01-26 11:29:33 +01:00
Louis Gesbert
bc90a7b890 Add (internally) a map2 operator 2024-01-26 11:22:12 +01:00
Denis Merigoux
b616e60c79
Fixes #558 2024-01-16 11:29:45 +01:00
Louis Gesbert
8194abaf93 Operator mismatch fix
wow this remained unspotted for some time...
2023-10-03 18:44:12 +02:00
Denis Merigoux
6962761774
Merge branch 'master' into closure_conversion 2023-06-15 17:56:41 +02:00
Denis Merigoux
d850ac688a
Added operators for closure environment handling 2023-06-15 16:52:36 +02:00
Aminata-Dev
10d147a8b1 Messages renamed to Message (lighter syntax) 2023-06-13 11:50:56 +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
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
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
Denis Merigoux
32ee2a0c72
Various small fixes to resolve conversations 2023-04-21 14:54:07 +02:00
Denis Merigoux
067c7b9155
Merge branch 'master' into adelaett-withoutexceptionsfix 2023-04-21 10:55:36 +02:00
Louis Gesbert
55d343d81c Version that uses object types instead of polymorphic variants
in order to get the row polymorphism controlling the GADT that encodes our AST
2023-04-20 13:51:20 +02:00
adelaett
3e35d4b826
Merge branch 'master' into adelaett-withoutexceptionsfix 2023-04-11 11:49:22 +02:00
adelaett
0906ba025b reviewed operator.ml 2023-04-06 13:50:34 +02:00
Louis Gesbert
0c1cd481e1 Interpreter on dcalc + lcalc (the simple way)
I made some changes in the meantime, and had to factorise e.g. the handling of
the `EEmptyError` case, but this is the simple approach type-wise of making the
function type for `∀ 'a. 'a —> 'a` (with `assert false` match cases), then
restricting its type do `dcalc` or `lcalc` in the `.mli`.
2023-04-05 10:32:58 +02:00
Louis Gesbert
79ff776d2e Multi-pass interperter: typing (but useless) version 2023-04-05 10:32:58 +02:00
adelaett
573df8416f Merge branch 'master' into adelaett-withoutexceptionsfix 2023-03-31 15:52:06 +02:00
Louis Gesbert
4973c74410 Remove date rounding mode from Operator.translate 2023-03-30 15:33:00 +02:00
Louis Gesbert
a415355a39 Rework the AST Gadt to allow merging of different ASTs
The phantom polymorphic variant qualifying AST nodes is reversed:
- previously, we were explicitely restricting each AST node to the passes where it belonged using a closed type (e.g. `[< dcalc | lcalc]`)
- now, each node instead declares the "feature" it provides using an open type (e.g. `[> 'Exceptions ]`)
- then the AST for a specific pass limits the features it allows with a closed type

The result is that you can mix and match all features if you wish,
even if the result is not a valid AST for any given pass. More
interestingly, it's now easier to write a function that works on
different ASTs at once (it's the inferred default if you don't write a
type restriction).

The opportunity was also taken to simplify the encoding of the
operators, which don't need a second type parameter anymore.
2023-03-30 15:30:08 +02:00
adelaett
6dee3874cc Merge branch 'master' into adelaett-withoutexceptionsfix 2023-03-30 10:50:32 +02:00
adelaett
8c66fabe6a fix mission operators in translate 2023-03-17 17:20:46 +01:00
Raphaël Monat
64fa32392f Update generated files 2023-03-16 17:20:09 +01:00
Raphaël Monat
5fc1e8e5d5 Fix operator printing 2023-03-16 16:55:55 +01:00
Raphaël Monat
7021c41f93 Add date rounding option within scopes 2023-03-16 16:55:55 +01:00
adelaett
366a0d952b introducing new operators for handleing defaults 2023-03-14 18:30:58 +01:00
Louis Gesbert
42b8adb968 Add a duration / duration overload
Interstingly enough, it was already implemented in the Python backend.

Required to implement *pro rata temporis*, which the US tax section 121 does
make use of.

Only allowed for durations expressed in days (as returned by `<date> - <date>`),
of course.
2023-03-08 15:17:58 +01:00
adelaett
51b5ccb08e change operator definition style to something more readable 2023-02-22 11:40:22 +01:00
adelaett
f2bebe613b - [x] shared_ast 2023-02-20 15:57:42 +01:00
Louis Gesbert
19f6d3d352 Add a notice on overload rules
Overloads are powerful, but let's clearly draw the line right now between
convenience and type safety, for when someone else will want to add new
operators.
2022-12-19 13:03:16 +01:00
Louis Gesbert
f236e2cfb2 Replace the type conversion and rounding operators with overloads
Ref. #366

Also updates `CONTRIBUTING.md`.

This was pretty straight-forward :)
2022-12-13 15:32:49 +01:00
Louis Gesbert
c94509e0bb Remove integer division from the language
it's unlikely to be used in any law, and likely to be cause for confusion.

best of all, the new operator has a different return type, which
ensures no inconsistency with the change can get overlooked.
2022-12-13 12:35:02 +01:00
Louis Gesbert
9b939d07a4 New syntax for collection operations 2022-12-13 12:30:40 +01:00
Louis Gesbert
fea01cfe4c Add overloaded operators for the common operations
This uses the same disambiguation mechanism put in place for
structures, calling the typer on individual rules on the desugared AST
to propagate types, in order to resolve ambiguous operators like `+`
to their strongly typed counterparts (`+!`, `+.`, `+$`, `+@`, `+$`) in
the translation to scopelang.

The patch includes some normalisation of the definition of all the
operators, and classifies them based on their typing policy instead of
their arity. It also adds a little more flexibility:
- a couple new operators, like `-` on date and duration
- optional type annotation on some aggregation constructions

The `Shared_ast` lib is also lightly restructured, with the `Expr`
module split into `Type`, `Operator` and `Expr`.
2022-12-13 11:55:24 +01:00