Guest User

Untitled

a guest
Feb 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. diff -rw -C 2 ocaml-3.12.0/asmcomp/closure.ml ocaml-3.12.0+partial/asmcomp/closure.ml
  2. *** ocaml-3.12.0/asmcomp/closure.ml 2008-08-01 14:52:14.000000000 +0200
  3. --- ocaml-3.12.0+partial/asmcomp/closure.ml 2011-06-09 19:42:20.282517002 +0200
  4. ***************
  5. *** 493,496 ****
  6. --- 493,499 ----
  7. | Lfunction(kind, params, body) as funct ->
  8. close_one_function fenv cenv (Ident.create "fun") funct
  9. +
  10. + (* we want to convert [f a] in [let a' = a in fun b c -> f a b c] when
  11. + fun_arity > nargs *)
  12. | Lapply(funct, args, loc) ->
  13. let nargs = List.length args in
  14. ***************
  15. *** 505,508 ****
  16. --- 508,536 ----
  17. let app = direct_apply fundesc funct ufunct uargs in
  18. (app, strengthen_approx app approx_res)
  19. +
  20. + | ((ufunct, Value_closure(fundesc, approx_res)), uargs)
  21. + when nargs < fundesc.fun_arity ->
  22. + let first_args = List.map (fun arg ->
  23. + (Ident.create "arg", arg) ) uargs in
  24. + let final_args = Array.to_list (Array.init (fundesc.fun_arity - nargs) (fun _ ->
  25. + Ident.create "arg")) in
  26. + let rec iter args body =
  27. + match args with
  28. + [] -> body
  29. + | (arg1, arg2) :: args ->
  30. + iter args
  31. + (Ulet ( arg1, arg2, body))
  32. + in
  33. + let internal_args =
  34. + (List.map (fun (arg1, arg2) -> Lvar arg1) first_args)
  35. + @ (List.map (fun arg -> Lvar arg ) final_args)
  36. + in
  37. + let (new_fun, approx) = close fenv cenv
  38. + (Lfunction(
  39. + Curried, final_args, Lapply(funct, internal_args, loc)))
  40. + in
  41. + let new_fun = iter first_args new_fun in
  42. + (new_fun, approx)
  43. +
  44. | ((ufunct, Value_closure(fundesc, approx_res)), uargs)
  45. when fundesc.fun_arity > 0 && nargs > fundesc.fun_arity ->
  46. Only in ocaml-3.12.0+partial/asmcomp: closure.ml.orig
  47. diff -rw -C 2 ocaml-3.12.0/asmcomp/cmmgen.ml ocaml-3.12.0+partial/asmcomp/cmmgen.ml
  48. *** ocaml-3.12.0/asmcomp/cmmgen.ml 2010-05-19 13:29:38.000000000 +0200
  49. --- ocaml-3.12.0+partial/asmcomp/cmmgen.ml 2011-06-09 19:41:52.222516999 +0200
  50. ***************
  51. *** 1911,1919 ****
  52. get_field (Cvar clos) 2 ::
  53. args @ [Cvar last_arg; Cvar clos])
  54. ! else begin
  55. let newclos = Ident.create "clos" in
  56. Clet(newclos,
  57. get_field (Cvar clos) 3,
  58. curry_fun (get_field (Cvar clos) 2 :: args) newclos (n-1))
  59. end in
  60. Cfunction
  61. --- 1911,1927 ----
  62. get_field (Cvar clos) 2 ::
  63. args @ [Cvar last_arg; Cvar clos])
  64. ! else
  65. ! if n = arity - 1 then
  66. ! begin
  67. let newclos = Ident.create "clos" in
  68. Clet(newclos,
  69. get_field (Cvar clos) 3,
  70. curry_fun (get_field (Cvar clos) 2 :: args) newclos (n-1))
  71. + end else
  72. + begin
  73. + let newclos = Ident.create "clos" in
  74. + Clet(newclos,
  75. + get_field (Cvar clos) 4,
  76. + curry_fun (get_field (Cvar clos) 3 :: args) newclos (n-1))
  77. end in
  78. Cfunction
  79. ***************
  80. *** 1934,1943 ****
  81. {fun_name = name2;
  82. fun_args = [arg, typ_addr; clos, typ_addr];
  83. ! fun_body = Cop(Calloc,
  84. [alloc_closure_header 4;
  85. Cconst_symbol(name1 ^ "_" ^ string_of_int (num+1));
  86. int_const 1; Cvar arg; Cvar clos]);
  87. fun_fast = true}
  88. ! :: intermediate_curry_functions arity (num+1)
  89. end
  90.  
  91. --- 1942,1989 ----
  92. {fun_name = name2;
  93. fun_args = [arg, typ_addr; clos, typ_addr];
  94. ! fun_body =
  95. ! if arity - num > 2 then
  96. ! Cop(Calloc,
  97. ! [alloc_closure_header 5;
  98. ! Cconst_symbol(name1 ^ "_" ^ string_of_int (num+1));
  99. ! int_const (arity - num - 1);
  100. ! Cconst_symbol(name1 ^ "_" ^ string_of_int (num+1) ^ "_app");
  101. ! Cvar arg; Cvar clos])
  102. ! else
  103. ! Cop(Calloc,
  104. [alloc_closure_header 4;
  105. Cconst_symbol(name1 ^ "_" ^ string_of_int (num+1));
  106. int_const 1; Cvar arg; Cvar clos]);
  107. fun_fast = true}
  108. ! ::
  109. ! (if arity - num > 2 then
  110. ! let rec iter i =
  111. ! if i <= arity then
  112. ! let arg = Ident.create (Printf.sprintf "arg%d" i) in
  113. ! (arg, typ_addr) :: iter (i+1)
  114. ! else []
  115. ! in
  116. ! let direct_args = iter (num+2) in
  117. ! let rec iter i args clos =
  118. ! if i = 0 then
  119. ! Cop(Capply(typ_addr, Debuginfo.none),
  120. ! (get_field (Cvar clos) 2) :: args @ [Cvar clos])
  121. ! else
  122. ! let newclos = Ident.create "clos" in
  123. ! Clet(newclos,
  124. ! get_field (Cvar clos) 4,
  125. ! iter (i-1) (get_field (Cvar clos) 3 :: args) newclos)
  126. ! in
  127. ! let cf =
  128. ! Cfunction
  129. ! {fun_name = name1 ^ "_" ^ string_of_int (num+1) ^ "_app";
  130. ! fun_args = direct_args @ [clos, typ_addr];
  131. ! fun_body = iter (num+1)
  132. ! (List.map (fun (arg,_) -> Cvar arg) direct_args) clos;
  133. ! fun_fast = true}
  134. ! in
  135. ! cf :: intermediate_curry_functions arity (num+1)
  136. ! else
  137. ! intermediate_curry_functions arity (num+1))
  138. end
Add Comment
Please, Sign In to add comment