Skip to content

Commit 44c7706

Browse files
committed
Merge remote-tracking branch 'origin/son_string'
2 parents 4e48d26 + 82cae1d commit 44c7706

6 files changed

Lines changed: 53 additions & 31 deletions

File tree

kremlib/c/c.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
intptr_t nullptr = (intptr_t) NULL;
1010

11+
char char_of_uint8(uint8_t c) {
12+
return c;
13+
}
14+
1115
bool __eq__C_char(char c1, char c2) {
1216
return c1 == c2;
1317
}

src/Ast.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,3 +629,5 @@ let flags_of_decl = function
629629
| DType (_, flags, _, _)
630630
| DExternal (_, flags, _, _, _) ->
631631
flags
632+
633+
let tuple_lid = [ "K" ], ""

src/Inlining.ml

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,6 @@ let inline files =
463463

464464

465465
let inline_type_abbrevs files =
466-
let gc_map = Helpers.build_map files (fun map -> function
467-
| DType (lid, flags, _, _) when List.mem GcType flags -> Hashtbl.add map lid ()
468-
| _ -> ()
469-
) in
470-
471466
let map = Helpers.build_map files (fun map -> function
472467
| DType (lid, _, _, Abbrev t) -> Hashtbl.add map lid (White, t)
473468
| _ -> ()
@@ -493,31 +488,21 @@ let inline_type_abbrevs files =
493488
* type pair a b = Tuple (1, 0)
494489
* breaks this invariant. *)
495490
filter_decls (function
496-
| DType (lid, flags, n, Abbrev def) ->
497-
begin match def with
498-
| TApp (hd, args)
499-
when List.assoc_opt (hd, args) !NamingHints.hints = None &&
500-
not (Hashtbl.mem gc_map hd) ->
501-
(* Don't use a type abbreviation towards a to-be-GC'd type as a
502-
* hint, because there will be a mismatch later on with a * being
503-
* added. This is mosly for backwards-compat with miTLS having
504-
* hand-written code in mitlsffi.c. *)
505-
NamingHints.(hints := ((hd, args), lid) :: !hints);
506-
(* Never leave the abbreviation in the program otherwise there will
507-
* be two types with the same name, the abbreviation and the
508-
* monomorphized one. *)
509-
None
510-
| TTuple args when List.assoc_opt (Monomorphization.tuple_lid, args) !NamingHints.hints = None ->
511-
NamingHints.(hints := ((Monomorphization.tuple_lid, args), lid) :: !hints);
512-
None
513-
| _ ->
514-
if n = 0 then
515-
Some (DType (lid, flags, n, Abbrev def))
516-
else
517-
(* A type definition with parameters is not something we'll be able to
518-
* generate code for (at the moment). So, drop it. *)
519-
None
520-
end
491+
| DType (_, _, n, Abbrev def) as d ->
492+
let in_hints = match def with
493+
| TApp (hd, args) ->
494+
List.assoc_opt (hd, args) !NamingHints.hints <> None
495+
| TTuple args ->
496+
List.assoc_opt (tuple_lid, args) !NamingHints.hints <> None
497+
| _ ->
498+
false
499+
in
500+
if in_hints then
501+
None
502+
else if n > 0 then
503+
None
504+
else
505+
Some d
521506

522507
| d ->
523508
Some d

src/Kremlin.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ Supported options:|}
498498
* A_f" comes before "static void B_g" (since they're static, there's no
499499
* forward declaration in the header. *)
500500
let files = Builtin.make_libraries files in
501+
NamingHints.record files;
501502
let files = Bundles.topological_sort files in
502503

503504
(* 1. We create bundles, and monomorphize functions first. This creates more

src/Monomorphization.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ let build_def_map files =
5858
*)
5959
type node = lident * typ list
6060
type color = Gray | Black
61-
let tuple_lid = [ "K" ], ""
6261

6362
let monomorphize_data_types map = object(self)
6463

src/NamingHints.ml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,37 @@ open PrintAst.Ops
1616
elimination / unit field elimination. *)
1717
let hints: ((lident * typ list) * lident) list ref = ref []
1818

19+
20+
let record files =
21+
let gc_map = Helpers.build_map files (fun map -> function
22+
| DType (lid, flags, _, _) when List.mem Common.GcType flags -> Hashtbl.add map lid ()
23+
| _ -> ()
24+
) in
25+
26+
(object
27+
inherit [_] iter
28+
29+
method visit_DType _ lid _ n def =
30+
match def with
31+
| Abbrev (TApp (hd, args))
32+
when List.assoc_opt (hd, args) !hints = None &&
33+
not (Hashtbl.mem gc_map hd) &&
34+
n = 0 ->
35+
(* Don't use a type abbreviation towards a to-be-GC'd type as a
36+
* hint, because there will be a mismatch later on with a * being
37+
* added. This is mosly for backwards-compat with miTLS having
38+
* hand-written code in mitlsffi.c. *)
39+
hints := ((hd, args), lid) :: !hints
40+
41+
| Abbrev (TTuple args)
42+
when List.assoc_opt (tuple_lid, args) !hints = None &&
43+
n = 0 ->
44+
hints := ((tuple_lid, args), lid) :: !hints
45+
46+
| _ ->
47+
()
48+
end)#visit_files () files
49+
1950
let debug () =
2051
KPrint.bprintf "==== state of naming hints ====\n";
2152
List.iter (fun ((hd, args), lid) ->

0 commit comments

Comments
 (0)