3 (* Compile a list of variant tags into CPP defines *)
5 (* hash_variant, from ctype.ml *)
9 for i = 0 to String.length s - 1 do
10 accu := 223 * !accu + Char.code s.[i]
12 (* reduce to 31 bits *)
13 accu := !accu land (1 lsl 31 - 1);
14 (* make it signed for 64 bits architectures *)
15 if !accu > 0x3FFFFFFF then !accu - (1 lsl 31) else !accu
19 let lexer = make_lexer ["`"; "["; "]"; "|"]
22 let s = lexer (Stream.of_channel stdin) in
23 let tags = Hashtbl.create 57 in
24 while match s with parser
25 [< ' Kwd "`"; ' Ident tag >] ->
26 let hash = hash_variant tag in
28 let tag' = Hashtbl.find tags hash in
30 failwith (String.concat ~sep:" " ["Doublon tag:";tag;"and";tag'])
32 Hashtbl.add ~key:hash ~data:tag tags;
33 print_string "#define MLTAG_";
35 print_string "\tVal_int(";
44 let _ = Printexc.print main ()