File tree Expand file tree Collapse file tree 5 files changed +48
-34
lines changed
src/compiler/ocaml_to_erlang
tests/compiler/expressions.t Expand file tree Collapse file tree 5 files changed +48
-34
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,15 @@ let ppf = Format.err_formatter
11
11
let file_a_bug =
12
12
{| If you think this is a bug, please file an issue here : https :// github.com/ AbstractMachinesLab / caramel/ issues/ new |}
13
13
14
+ let unsupported_let_rec_inside_of_function_body () =
15
+ Format. fprintf ppf
16
+ {| We have found a let rec binding within a function .
17
+
18
+ This is currently not supported .
19
+ \n
20
+ |};
21
+ exit 1
22
+
14
23
let unsupported_let_shadowing name =
15
24
Format. fprintf ppf
16
25
{| We have found that the variable name % s is being shadowed.
Original file line number Diff line number Diff line change @@ -327,7 +327,9 @@ and mk_expression exp ~var_names ~modules ~functions ~module_name =
327
327
in
328
328
let branches = if_true :: if_false in
329
329
Erlang.Ast. Expr_case (expr, branches)
330
- | Texp_let (_ , vbs , expr ) ->
330
+ | Texp_let (Recursive, _ , _ ) ->
331
+ Error. unsupported_let_rec_inside_of_function_body ()
332
+ | Texp_let (Nonrecursive, vbs , expr ) ->
331
333
(* NOTE: consider flattening let-ins ?
332
334
let rec flatten e acc =
333
335
match e with
Original file line number Diff line number Diff line change @@ -26,28 +26,3 @@ let let_nested f g h =
26
26
in
27
27
f a
28
28
29
- (* FIXME: Erlang does not support let rec bindings, and we're forced to use a
30
- combinator instead.
31
-
32
- Right now it believes that the name is supposed to be a module level
33
- function, which compiles fine but crashes at runtime.
34
-
35
- So this:
36
- let rec f x = f (x + 1) in
37
- f 0
38
-
39
- could look like:
40
-
41
- let_rec() ->
42
- RecF = fun(G) -> fun (X) -> (G(G))(X+1) end end,
43
- F = RecF(RecF),
44
- F(0).
45
-
46
- alternatively we coudl wrap this in a support library too
47
-
48
- F = caramel:letrec1(fun (F, X) -> F(X + 1) end)
49
-
50
- *)
51
- let let_rec () =
52
- let rec f x = f (x + 1 ) in
53
- f 0
Original file line number Diff line number Diff line change
1
+ (* FIXME: Erlang does not support let rec bindings, and we're forced to use a
2
+ combinator instead.
3
+
4
+ Right now it believes that the name is supposed to be a module level
5
+ function, which compiles fine but crashes at runtime.
6
+
7
+ So this:
8
+ let rec f x = f (x + 1) in
9
+ f 0
10
+
11
+ could look like:
12
+
13
+ let_rec() ->
14
+ RecF = fun(G) -> fun (X) -> (G(G))(X+1) end end,
15
+ F = RecF(RecF),
16
+ F(0).
17
+
18
+ alternatively we coudl wrap this in a support library too
19
+
20
+ F = caramel:letrec1(fun (F, X) -> F(X + 1) end)
21
+
22
+ *)
23
+ let let_rec () =
24
+ let rec f x = f (x + 1 ) in
25
+ f 0
Original file line number Diff line number Diff line change 3
3
binding_on_match.ml
4
4
funref.ml
5
5
let_bindings.ml
6
+ let_rec.ml
6
7
let_shadowing.ml
7
8
list.ml
8
9
literals.ml
175
176
- export ([let_many/ 0 ]).
176
177
- export ([let_nested/ 3 ]).
177
178
- export ([let_one/ 0 ]).
178
- - export ([let_rec/ 0 ]).
179
179
180
180
- spec let_one () -> integer ().
181
181
let_one () ->
210
210
end (),
211
211
F (A).
212
212
213
- - spec let_rec () -> any ().
214
- let_rec () ->
215
- F = fun
216
- (X) -> f (erlang:'+' (X, 1 ))
217
- end ,
218
- F (0 ).
219
-
220
213
221
214
$ caramelc compile list.ml
222
215
File "list.ml" , line 7 , characters 9 - 21 :
568
561
$ cat let_shadowing.erl
569
562
cat: let_shadowing.erl: No such file or directory
570
563
[1 ]
564
+
571
565
$ caramelc compile names_primes.ml
572
566
Compiling names_primes.erl OK
573
567
$ cat names_primes.erl
584
578
X_prime_prime.
585
579
586
580
581
+ $ caramelc compile let_rec.ml
582
+ We have found a let rec binding within a function.
583
+
584
+ This is currently not supported.
585
+ \n
586
+ [1 ]
587
+ $ cat let_rec.erl
588
+ cat: let_rec.erl: No such file or directory
589
+ [1 ]
You can’t perform that action at this time.
0 commit comments