-
Notifications
You must be signed in to change notification settings - Fork 464
/
Copy pathRuntime.ml
51 lines (41 loc) · 1.43 KB
/
Runtime.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
type recordGen = {mutable unboxed: int; mutable boxed: int}
type recordValue = int
type moduleItem = string
type moduleAccessPath = Root of string | Dot of moduleAccessPath * moduleItem
let recordValueToString recordValue = recordValue |> string_of_int
let recordGen () = {unboxed = 0; boxed = 0}
let newRecordValue ~unboxed recordGen =
if unboxed then (
let v = recordGen.unboxed in
recordGen.unboxed <- recordGen.unboxed + 1;
v)
else
let v = recordGen.boxed in
recordGen.boxed <- recordGen.boxed + 1;
v
let newModuleItem ~name = name
let rec emitModuleAccessPath ~config moduleAccessPath =
match moduleAccessPath with
| Root s -> s
| Dot (p, moduleItem) ->
p |> emitModuleAccessPath ~config |> EmitText.fieldAccess ~label:moduleItem
let jsVariantTag ~polymorphic ~tag =
match polymorphic with
| true -> "NAME"
| false -> (
match tag with
| Some tag -> tag
| None -> "TAG")
let jsVariantPayloadTag ~n = "_" ^ string_of_int n
let jsVariantValue ~polymorphic =
match polymorphic with
| true -> "VAL"
| false -> "value"
let isMutableObjectField name =
String.length name >= 2
&& (String.sub name (String.length name - 2) 2 [@doesNotRaise]) = "#="
(** Mutable fields, i.e. fields annotated "[@bs.set]"
are represented as extra fields called "fieldName#="
preceding the normal field. *)
let checkMutableObjectField ~previousName ~name = previousName = name ^ "#="
let default = "$$default"