Skip to content

Ajout du mot-clé "evenement" #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
cf541fe
Ajout du mot-clé "evenement"
david-michel1 Dec 10, 2024
8d2cee7
Déclaration des événements
david-michel1 Dec 12, 2024
9812acd
Événements pour l'interpréteur
david-michel1 Dec 12, 2024
d9d85eb
Événements pour le backend C
david-michel1 Dec 17, 2024
ad51e69
Itérateurs numérique (instable).
david-michel1 Jan 13, 2025
1a8fea0
Taille des piles d'exécution (instable)
david-michel1 Jan 14, 2025
655b2f7
Dimensionnement des piles d'exécution des variables.
david-michel1 Jan 15, 2025
6aea338
Itérateur sur les valeurs.
david-michel1 Jan 16, 2025
2ed57c8
Fonction nb_evenements pour l'interpréteur
david-michel1 Jan 20, 2025
297bfed
Accesseurs pour les événements.
david-michel1 Jan 21, 2025
2621cc0
Assignation dynamique des champs des événements.
david-michel1 Jan 21, 2025
c85d473
Amélioration de la gestion des événements.
david-michel1 Jan 22, 2025
e26fd33
Arrangement des événements (en cours).
david-michel1 Jan 23, 2025
6cbc4ba
Intruction d'arrangement des exceptions (en cours).
david-michel1 Jan 23, 2025
ad82995
Arrangement des événements, suite.
david-michel1 Jan 24, 2025
14cbd60
Arrange événements
david-michel1 Jan 28, 2025
443b0b9
Arrange événements (correction)
david-michel1 Jan 28, 2025
4521c45
Restauration des événements (listes).
david-michel1 Jan 28, 2025
286150f
Restauration des événements (prédicats).
david-michel1 Jan 30, 2025
1e016c2
Amélioration de la lisibilité du code C
david-michel1 Jan 30, 2025
3bbc9bf
Ajout d'événements (instable)
david-michel1 Jan 30, 2025
7fdd458
Ajouter des événements.
david-michel1 Jan 30, 2025
8ebd944
Mise à jour des références de variables dans les événements.
david-michel1 Jan 31, 2025
8fbab01
Extension des variables avec des références (partiel)
david-michel1 Feb 3, 2025
044f798
Accès aux références de variables dans les champs des événements (par…
david-michel1 Feb 4, 2025
eeb5e27
Gestion des événements
david-michel1 Feb 6, 2025
8eb7e7f
Lecture des fichers de test correctifs
david-michel1 Feb 11, 2025
21b45ca
Pseudo-rebase à la main
david-michel1 Feb 13, 2025
8c0680f
Suppression de "#define BATCH"
david-michel1 Feb 17, 2025
ba41a1d
Merge commit '4797c03c0c37322c1f01dee98b0783afb1b7905d' into extensio…
david-michel1 Feb 18, 2025
ba61112
Merge remote-tracking branch 'origin/master' into extension_correctif
david-michel1 Feb 18, 2025
fad33d3
Correction de l'accès aux tableaux en C.
david-michel1 Feb 18, 2025
770b746
Corrections syntaxiques.
david-michel1 Feb 18, 2025
389fae4
Adaptations pour 2024.
david-michel1 Feb 18, 2025
60cd65f
Racourcissement des noms des fichiers "varinfo_*.c"
david-michel1 Feb 19, 2025
437b959
Concaténation dynamique des noms de variables (partiel)
david-michel1 Feb 27, 2025
8b7513d
Concaténation des variables indexées
david-michel1 Mar 4, 2025
1b562d4
Factorisation du type target
david-michel1 Mar 6, 2025
0452c64
Factorisation du type target
david-michel1 Mar 10, 2025
ce8cc51
Factorisation des tableaux (instable)
david-michel1 Mar 11, 2025
84fea16
Factorisation des tableaux (suite)
david-michel1 Mar 12, 2025
51cf449
Factorisation des tableaux (suite).
david-michel1 Mar 13, 2025
d225aa3
Factorisation des tableaux (partiel)
david-michel1 Mar 18, 2025
1fdf610
Factorisation fes tableaux (partiel)
david-michel1 Mar 19, 2025
ffad76b
Factorisation des tableaux (suite)
david-michel1 Mar 25, 2025
48dc71b
Factorisationdes tableaux (suite)
david-michel1 Mar 26, 2025
5f7ebb0
Factorisation des tableaux (instable)
david-michel1 Mar 27, 2025
1cadd6e
Factorisation des tableaux (partiel)
david-michel1 Apr 8, 2025
608a786
Factorisation des tableaux (partiel)
david-michel1 Apr 9, 2025
ea74ddc
Factorisationd es tableaux (partiel)
david-michel1 Apr 10, 2025
bf9a859
Factorisation des tableaux (partielle)
david-michel1 Apr 11, 2025
9bb36e9
Appels de sous-procédures (instable)
david-michel1 Apr 15, 2025
50cc151
Réparation des accès aux variables.
david-michel1 Apr 16, 2025
717c3bb
Réparation des accès mémoire (partiel)
david-michel1 Apr 17, 2025
11403bb
Nettoyage des positions
david-michel1 Apr 18, 2025
f7e8dcc
Factorisation de l'accès aux tableaux
david-michel1 Apr 24, 2025
cf6731b
Factorisation des tableaux (corrections).
david-michel1 Apr 29, 2025
27268bc
Fonction Strings.ends_with
david-michel1 Apr 29, 2025
edf67e0
Correcton interpréteur
david-michel1 May 7, 2025
f56ad1d
Fonction est_variable
david-michel1 May 20, 2025
690a002
Renommage cible.m -> cibles.m
david-michel1 May 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/dgfip_c/ml_primitif/ml_driver/common.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
module StrSet = Set.Make(String)
module StrMap = Map.Make(String)

type rappel =
float
* float
* string
* float
* float
* float option
* float option
* float
* float option

15 changes: 15 additions & 0 deletions examples/dgfip_c/ml_primitif/ml_driver/m.ml
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,19 @@ external get_err_list : TGV.t -> string list = "ml_get_err_list"
external annee_calc : unit -> int = "ml_annee_calc"
external export_errs : TGV.t -> unit = "ml_export_errs"
external enchainement_primitif : TGV.t -> unit = "ml_enchainement_primitif"
external set_evt_list :
TGV.t
-> (
float
* float
* string
* float
* float
* float option
* float option
* float
* float option
) list
-> unit
= "ml_set_evt_list"

187 changes: 94 additions & 93 deletions examples/dgfip_c/ml_primitif/ml_driver/main.ml
Original file line number Diff line number Diff line change
@@ -1,31 +1,72 @@
open Common

type instance = {
nom : string;
label : string;
vars : float StrMap.t;
events : rappel list;
expectedVars : float StrMap.t;
expectedAnos : StrSet.t;
}

let new_instance nom = {
nom;
label = "";
vars = StrMap.empty;
events = [];
expectedVars = StrMap.empty;
expectedAnos = StrSet.empty;
}

let read_test filename =
let test = Read_test.read_test filename in
let tgv = M.TGV.alloc_tgv () in
let res_prim, ctl_prim =
let fold_prim (res_prim, ctl_prim) s =
match s with
| `EntreesPrimitif pl ->
List.iter (fun (code, montant) -> M.TGV.set tgv code montant) pl;
res_prim, ctl_prim
| `ResultatsPrimitif pl ->
let res_prim =
let fold res (code, montant) = StrMap.add code montant res in
List.fold_left fold res_prim pl
in
res_prim, ctl_prim
| `ControlesPrimitif el ->
let ctl_prim =
let fold err e = StrSet.add e err in
List.fold_left fold ctl_prim el
in
res_prim, ctl_prim
| _ -> res_prim, ctl_prim
in
List.fold_left fold_prim (StrMap.empty, StrSet.empty) test
let fold_prim (nom, inst, insts) s =
match s with
| `Nom noms ->
let nom = String.concat " " noms in
let inst = {inst with nom} in
let insts = List.map (fun i -> {i with nom}) insts in
(nom, inst, insts)
| `EntreesPrimitif pl ->
let vars =
let fold res (code, montant) = StrMap.add code montant res in
List.fold_left fold StrMap.empty pl
in
(nom, {inst with vars}, insts)
| `ControlesPrimitif el ->
let expectedAnos =
let fold err e = StrSet.add e err in
List.fold_left fold StrSet.empty el
in
(nom, {inst with expectedAnos}, insts)
| `ResultatsPrimitif pl ->
let expectedVars =
let fold res (code, montant) = StrMap.add code montant res in
List.fold_left fold StrMap.empty pl
in
let inst = {inst with label = "primitif"; expectedVars} in
(nom, new_instance nom, inst :: insts)
| `EntreesCorrectif _
| `ControlesCorrectif _
| `ResultatsCorrectif _ -> (nom, inst, insts)
| `EntreesRappels events -> (nom, {inst with events}, insts)
| `ControlesRappels el ->
let expectedAnos =
let fold err e = StrSet.add e err in
List.fold_left fold StrSet.empty el
in
(nom, {inst with expectedAnos}, insts)
| `ResultatsRappels pl ->
let expectedVars =
let fold res (code, montant) = StrMap.add code montant res in
List.fold_left fold StrMap.empty pl
in
let inst = {inst with label = "correctif"; expectedVars} in
(nom, new_instance nom, inst :: insts)
| `Skip -> (nom, inst, insts)
in
tgv, res_prim, ctl_prim
let _, _, insts = List.fold_left fold_prim ("", new_instance "", []) test in
insts

let check_result tgv err expected_tgv expected_err =
let result = ref true in
Expand Down Expand Up @@ -75,79 +116,39 @@ let var_addr () =
in
Lazy.force vars

let compare_dump out outexp =
let out = open_in_bin out in
let outexp = open_in_bin outexp in
let read64 ic =
let buf = Bytes.create 8 in
really_input ic buf 0 8;
buf
in
let rec read_val_diffs vars diffs =
match vars with
| [] -> diffs
| (addr, var)::vars ->
assert (pos_in out = addr);
let res_val = read64 out in
let expe_val = read64 outexp in
if Bytes.equal res_val expe_val then
read_val_diffs vars diffs
else
read_val_diffs vars ((var, res_val, expe_val)::diffs)
in
let rec read_strings ic strs =
try
let str = read64 ic in
let strs = StrSet.add (Bytes.to_string str) strs in
read_strings ic strs
with
| End_of_file -> strs
in
let diffs = read_val_diffs (var_addr ()) [] in
let raised_disco = read_strings out StrSet.empty in
let expected_disco = read_strings outexp StrSet.empty in
StrSet.iter (fun ano ->
Printf.eprintf "Raised unexpected discordance %s\n" ano
) (StrSet.diff raised_disco expected_disco);
StrSet.iter (fun ano ->
Printf.eprintf "Expected discordance %s not raised\n" ano
) (StrSet.diff expected_disco raised_disco);
let undef = Int64.of_string "0xefbeaddeefbeadde" in
let hex2floatstr bytes =
let i64 = Bytes.get_int64_le bytes 0 in
if Int64.equal i64 undef then "undef"
else string_of_float(Int64.float_of_bits i64)
in
List.iter (fun (var, res, exp) ->
Printf.eprintf "%s: %s found, expected %s\n"
var (hex2floatstr res) (hex2floatstr exp)
)
diffs;
flush stderr;
close_in out;
close_in outexp

let run_test test_file annee_exec =
Printf.printf "Testing %s...\n%!" test_file;
let annee_calc = M.annee_calc () in
let tgv, res_prim, ctl_prim = read_test test_file in
let annee_revenu = M.TGV.get_int_def tgv "ANREV" annee_calc in
if annee_revenu <> annee_calc then (
Printf.eprintf
"Attention, année calculette (%d) <> année revenu (%d)\n%!"
annee_calc
annee_revenu
);
M.TGV.set_int tgv "IND_TRAIT" 4 (* = primitif *);
M.TGV.set_int tgv "ANCSDED" annee_exec;
M.init_errs tgv;
let _err = M.enchainement_primitif tgv in
M.export_errs tgv;
let err_set =
let add res e = StrSet.add e res in
List.fold_left add StrSet.empty (M.get_err_list tgv)
let insts = read_test test_file in
let rec run_insts res = function
| [] -> res
| inst :: insts ->
Printf.printf " Running %s:%s...\n%!" inst.nom inst.label;
let tgv = M.TGV.alloc_tgv () in
StrMap.iter (M.TGV.set tgv) inst.vars;
M.set_evt_list tgv inst.events;
let annee_revenu = M.TGV.get_int_def tgv "ANREV" annee_calc in
if annee_revenu <> annee_calc then (
Printf.eprintf
"Attention, année calculette (%d) <> année revenu (%d)\n%!"
annee_calc
annee_revenu
);
(match inst.label with
| "primitif" -> M.TGV.set_int tgv "IND_TRAIT" 4
| "correctif" -> M.TGV.set_int tgv "IND_TRAIT" 5
| _ -> M.TGV.set_int tgv "IND_TRAIT" 0);
M.TGV.set_int tgv "ANCSDED" annee_exec;
M.init_errs tgv;
let _err = M.enchainement_primitif tgv in
M.export_errs tgv;
let err_set =
let add res e = StrSet.add e res in
List.fold_left add StrSet.empty (M.get_err_list tgv)
in
res && check_result tgv err_set inst.expectedVars inst.expectedAnos
in
check_result tgv err_set res_prim ctl_prim
run_insts true insts

let main () =
if Array.length Sys.argv < 2 then (
Expand Down Expand Up @@ -175,7 +176,7 @@ let main () =
let rec loop = function
| [] -> true
| test_file :: files ->
run_test test_file annee_exec && ((* Gc.minor ();*) loop files)
run_test test_file annee_exec && (Gc.minor (); loop files)
in
match loop test_files with
| true -> exit 0
Expand Down
36 changes: 29 additions & 7 deletions examples/dgfip_c/ml_primitif/ml_driver/read_test.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Common

type file = {
c: in_channel;
mutable lines: string list;
Expand All @@ -21,14 +23,17 @@ let convert_int s = try int_of_string s with _ -> 0

let convert_float s =
try Float.of_string s
(* with _ -> 0.0 *)
with _ -> (* to cope with badly formatted tests *)
try Float.of_string
(String.sub s 0
(String.index_from s
((String.index s '.') + 1) '.'))
with _ -> 0.0

let convert_float_opt s =
let rec isSpc i = i < 0 || (s.[i] = ' ' && isSpc (i - 1)) in
if isSpc (String.length s - 1) then None else Some (convert_float s)

let parse_generic s =
let sl = String.split_on_char '/' s in
match sl with
Expand All @@ -55,16 +60,33 @@ let parse_entree_corr s =
| _ -> failwith (Printf.sprintf "Ligne entree correctif invalide: '%s'" s)

let parse_entree_rap s =
let err () = failwith (Printf.sprintf "Ligne entree rappel invalide: '%s'" s) in
let sl = String.split_on_char '/' s in
match sl with
| [ num_evt; num_rappel; code; montant; sens;
penalite; base_tl; date_evt; ind20 ] ->
let date_evt = convert_int date_evt in
(convert_int num_evt, convert_int num_rappel,
code, convert_float montant, sens.[0],
convert_int penalite, convert_float base_tl,
(date_evt mod 10000, date_evt / 10000), String.equal ind20 "1") (* TODO: improve *)
| _ -> failwith (Printf.sprintf "Ligne entree rappel invalide: '%s'" s)
if String.length code = 0 then err ();
let sens_float =
if String.length sens = 0 then err ();
match sens.[0] with
| 'R' -> 0.0
| 'C' -> 1.0
| 'M' -> 2.0
| 'P' -> 3.0
| _ -> err ()
in
(
convert_float num_evt,
convert_float num_rappel,
code,
convert_float montant,
sens_float,
convert_float_opt penalite,
convert_float_opt base_tl,
convert_float date_evt,
convert_float_opt ind20
) (* TODO: improve *)
| _ -> err ()

let read_section_contents f parsefun =
let rec aux contents =
Expand Down
Loading