Commit Graph

4260 Commits

Author SHA1 Message Date
Louis Gesbert
183882c3a3 Interpreter: avoid double-loading of shared modules 2024-10-01 15:03:31 +02:00
Louis Gesbert
c99ae6e59c Fix: support tuples in interpreter comparison and embedding 2024-10-01 15:03:31 +02:00
Louis Gesbert
543dd243c9 Add support for automatic instrumentation with assertions
This adds a `--autotest` flag. Quoting the (new) manpage section:

> Insert automatic test assertions in the compiled program. This
> detects all scopes that have no input or context variables, runs
> the interpreter to pre-compute their values, then adds runtime
> assertions to the program that ensure that the actual output of the
> scopes match their pre-computed values. If used on a testing
> program with a given backend, this guarantees consistency between
> the backend and the interpreter.
2024-10-01 15:03:31 +02:00
Louis Gesbert
22b0d02d06 Deps: fix commit for dates_calc (temporary, until its release) 2024-10-01 13:28:23 +02:00
Louis Gesbert
29ce1649bc
Small interface improvements (#704) 2024-09-26 15:35:00 +02:00
Denis Merigoux
47314a6ba2 Refactoring : put sub-scope's I/O information where it should be 2024-09-26 13:44:06 +02:00
Louis Gesbert
3f0c9d9947 Plugins: allow registration of multiple subcommands 2024-09-26 13:39:29 +02:00
Louis Gesbert
04233527c9
Fix handling of the lexer context (#703) 2024-09-26 13:37:44 +02:00
Louis Gesbert
d5b5fe71c4 Fix handling of the lexer context
The lexing context uses a global reference. This patch ensures it is handled
carefully for the lifetime of lexing a given file.

Before that, very weird bugs could happen, for example when a file ended with an
unclosed verbatim block, the parsing of module interfaces done later on would
start in verbatim context and fail to parse e.g. module use definitions.

The patch additionally adds checks and warns about unclosed blocks at EOF, which
before that would be silently accepted (with the above pitfall).
2024-09-26 10:25:52 +02:00
Louis Gesbert
0f409dd9af
Progress on the C backend (#671) 2024-09-26 10:00:04 +02:00
Louis Gesbert
156afa761a Add tiny C runtime unit test 2024-09-25 19:47:05 +02:00
Louis Gesbert
aa8bc3573f Finalisation of the C backend PR 2024-09-25 19:32:38 +02:00
Louis Gesbert
270d33f8a6 Python backend: fix handling of renamed modules 2024-09-25 15:25:19 +02:00
vbot
12c98ecde1
Fix inconsistent marks (#694) 2024-09-25 14:40:42 +02:00
vbot
4a5bb63e25
Fix overwrote positions 2024-09-24 17:39:58 +02:00
vbot
a79f272fc5
Add map_info to UIds 2024-09-24 17:37:59 +02:00
Louis Gesbert
a20bdc80b0 Cleanup: pass visibility info down to scalc 2024-09-23 16:40:38 +02:00
Louis Gesbert
ea0ab3ccf9 Clerk: consistent capitalisation of module filenames
now all artefacts related to the module Foo are capitalised, like the module
name.
2024-09-23 16:29:36 +02:00
Louis Gesbert
7f929a3bb6 Clerk: compilation to C 2024-09-23 16:28:45 +02:00
Louis Gesbert
f50f3872dd C backend: generate .h files and use them for imported modules
Also includes some fixes to the propagation of visibility info of types.
2024-09-23 16:27:11 +02:00
Louis Gesbert
dd6ef8bcce C backend: first module handling proto using raw #include 2024-09-17 14:47:27 +02:00
Louis Gesbert
59afc7f4dd Cleanup: add function for more direct stringification of uids 2024-09-17 11:59:52 +02:00
Louis Gesbert
5ca37029a8 C backend: qualify definitions with module name 2024-09-17 11:51:45 +02:00
vbot
7ccedafa13
Fix OCaml backend bug regarding exception source positions (#689) 2024-09-17 11:18:16 +02:00
Louis Gesbert
2e63a21b34 Fix OCaml backend bug regarding exception source positions 2024-09-16 17:25:26 +02:00
Louis Gesbert
2e68915b9c C backend: fix handling of struct inits that may be const or not
This happens when there are two branches that are bound to an existing struct,
and to a literal one that needs a malloc+non-const;

the fix refines the handling of `no_struct_literals` in scalc, to ensure that
`SLocalInit` is used on a local temporary variable for the constructs needing
malloc.
2024-09-16 15:47:18 +02:00
Louis Gesbert
ee569657e1 C backend: WIP handling mixed const/non-const inits
we want our pointers to "const" (in the C sense, i.e. read-only) values in
general; but structures need to be initialised field by field. We handle the
absence of `const` in this case (the pointer target will be made `const` upon
function return).

When we compile with `-O`, though, intermediate variables are removed, and we
have branchings with one side getting an already allocated (`const`) structure,
while the other one will need to init through allocation of individual fields.

In the current state of this patch, we define the structure as non-const and
malloc it when this happens, like in the basic definition case. It works, but in
the branch of the already allocated structure, the malloc is discarded (wasted),
and there is a legitimate warning because we strip the `const` flag from the
source pointer.

I see only two solutions:
- remove all consts (beh, they are very good for understanding what's going on,
  and I'm sure that without them we'll fall into more traps later)
- in the branch(es) needing malloc, allocate and initialise to a temporary
  non-const structure, then affect it to the return pointer ("sealing" it as
  const after initialisation). This basically what happens without `-O` because
  we have more intermediate variables... But we want to target that specifically
  at cases that need malloc.

A variant of the 2nd option could be to define initialiser functions for all
structs, but we loose in readability since the arguments would be unlabelled.
The cleaner way to do it would probably be at the scalc level, depending on the
`--no-struct-literals` flag.
2024-09-13 18:38:50 +02:00
Louis Gesbert
2e312c3814 C backend: fix a few priority and closure-env cast issues 2024-09-13 18:20:12 +02:00
Louis Gesbert
c27f1c4007 C backend: all tests pass but modules
(of course, their output values aren't tested yet for all modules that don't
have asserts; but the testing framework is the next step)
2024-09-13 15:37:31 +02:00
Louis Gesbert
313eff47a3 scalc translation: simplify local bindings implem
it now follows a pattern that was generalised
2024-09-13 12:19:45 +02:00
Louis Gesbert
22a16c2b8a C backend: better ensure consistent declarations and mallocs 2024-09-13 10:12:34 +02:00
Louis Gesbert
ff18ee0267 Marvelous hack to handle lazy constant initialisation in C 2024-09-11 17:54:48 +02:00
Louis Gesbert
e1b5e2cac6 Scalc printer: be explicit about inits 2024-09-11 16:27:26 +02:00
vbot
42a6c43f20
Add the possibility to override inputs of included files (#688) 2024-09-11 15:37:24 +02:00
vbot
601dc80e3d
Add the possibility to override inputs of included files 2024-09-11 14:46:32 +02:00
Louis Gesbert
d0bc112912 Properly link and use dates_calc into the C runtime, and use header files
The c runtime is now compiled into a `.a` static library.

it's now picked up by the Python backend as well, but the corresponding runtime
hasn't been updated to use it.
2024-09-11 13:51:38 +02:00
Louis Gesbert
20c37495b5 Fix the date - duration operator to handle date rounding mode
it was only applied to the addition!
2024-09-10 18:26:34 +02:00
Denis Merigoux
26077d60e1
#683 follow-up (#684) 2024-09-10 14:59:24 +02:00
vbot
f1a134143d
Syntax cheat-typo follow-up: add spacing 2024-09-10 14:23:19 +02:00
vbot
87d38d23d0
Syntax cheat typo (#683) 2024-09-10 14:19:24 +02:00
Denis Merigoux
6970b38c5f
Fixes #680 2024-09-10 10:55:03 +02:00
Louis Gesbert
d3f4b58f2f Some more scalc/c/renaming tweaks
Bindlib flag `skip_constant_binders` should be disabled for C, and is better
left disabled for debugging as well.
2024-09-06 18:08:42 +02:00
Louis Gesbert
77607ace25 Renaming: forbid use of x within <e> in let x = <e> in ...
It's fine with OCaml (as long as we don't use `rec`), but could break
scalc-based backends; and this probably improves readability anyways.
2024-09-06 17:10:50 +02:00
Louis Gesbert
62d9270c95 We can keep scope idents capitalised in Python 2024-09-06 17:10:50 +02:00
Louis Gesbert
06937a0a78 One more fix for variable names in scalc 2024-09-06 17:10:50 +02:00
Louis Gesbert
2ef266681b Fix the application of naming rules on the scalc translation 2024-09-06 17:10:50 +02:00
Louis Gesbert
9c10e7f427 Scalc backends: inline arguments of enums
this avoids yet another addition of intermediate variables and makes the
resulting code much more readable
2024-09-06 17:10:50 +02:00
Louis Gesbert
6dad83e8bc Scalc translation: rework to avoid unneeded intermediate vars 2024-09-06 17:06:56 +02:00
Louis Gesbert
e91bf3bab8 Renaming: use __N suffixes rather than just N
This avoids incrementing existing numbers at the end of user-defined variable
names, which doesn't feel right.
2024-09-05 16:58:47 +02:00
Louis Gesbert
0e220ba47c C runtime fixes 2024-09-05 14:27:28 +02:00