Permalink
Browse files

Add 4.00 runtime.

Multiple runtime managment.
  • Loading branch information...
bvaugon committed Jan 28, 2013
1 parent d505afb commit fc5faab1a4004ca979f1f8f2be75d00c571a0f6d
Showing with 20,132 additions and 81 deletions.
  1. +3 −1 Makefile
  2. +30 −3 configure
  3. BIN dist/ocamlcc-1.0.tar.bz2
  4. +0 −1 runtime/VERSION
  5. +3 −3 runtime/ocamlcc-apply-gen.c
  6. +3 −3 runtime/ocamlcc-apply-none.c
  7. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/alloc.c
  8. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/alloc.h
  9. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/array.c
  10. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/backtrace.c
  11. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/backtrace.h
  12. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/callback.c
  13. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/callback.h
  14. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/compact.c
  15. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/compact.h
  16. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/compare.c
  17. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/compare.h
  18. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/compatibility.h
  19. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/custom.c
  20. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/custom.h
  21. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/debugger.c
  22. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/debugger.h
  23. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/dynlink.c
  24. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/dynlink.h
  25. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/exec.h
  26. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/extern.c
  27. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/fail.c
  28. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/fail.h
  29. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/finalise.c
  30. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/finalise.h
  31. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/fix_code.c
  32. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/fix_code.h
  33. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/flexdll.c
  34. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/flexdll.h
  35. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/floats.c
  36. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/freelist.c
  37. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/freelist.h
  38. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/gc.h
  39. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/gc_ctrl.c
  40. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/gc_ctrl.h
  41. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/globroots.c
  42. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/globroots.h
  43. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/hash.c
  44. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/instruct.h
  45. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/int64_emul.h
  46. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/int64_format.h
  47. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/int64_native.h
  48. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/intern.c
  49. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/intext.h
  50. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/ints.c
  51. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/io.c
  52. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/io.h
  53. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/jumptbl.h
  54. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/lexing.c
  55. +1 −1 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/main.c
  56. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/major_gc.c
  57. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/major_gc.h
  58. +1 −0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/md5.c
  59. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/md5.h
  60. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/memory.c
  61. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/memory.h
  62. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/minor_gc.c
  63. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/minor_gc.h
  64. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/misc.c
  65. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/misc.h
  66. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/mlvalues.h
  67. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/obj.c
  68. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/opnames.h
  69. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/osdeps.h
  70. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/parsing.c
  71. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/prims.c
  72. +1 −0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/prims.h
  73. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/printexc.c
  74. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/printexc.h
  75. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/reverse.h
  76. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/roots.c
  77. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/roots.h
  78. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/signals.c
  79. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/signals.h
  80. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/signals_byt.c
  81. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/signals_machdep.h
  82. +1 −2 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/stacks.c
  83. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/stacks.h
  84. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/startup.c
  85. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/startup.h
  86. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/str.c
  87. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/sys.c
  88. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/sys.h
  89. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/terminfo.c
  90. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/ui.h
  91. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/unix.c
  92. +1 −0 runtime/ocamlcc-byterun-3.12/version.h
  93. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/weak.c
  94. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/weak.h
  95. 0 runtime/{ocamlcc-byterun → ocamlcc-byterun-3.12}/win32.c
  96. +194 −0 runtime/ocamlcc-byterun-4.00/alloc.c
  97. +58 −0 runtime/ocamlcc-byterun-4.00/alloc.h
  98. +389 −0 runtime/ocamlcc-byterun-4.00/array.c
  99. +310 −0 runtime/ocamlcc-byterun-4.00/backtrace.c
  100. +33 −0 runtime/ocamlcc-byterun-4.00/backtrace.h
  101. +295 −0 runtime/ocamlcc-byterun-4.00/callback.c
  102. +57 −0 runtime/ocamlcc-byterun-4.00/callback.h
  103. +506 −0 runtime/ocamlcc-byterun-4.00/compact.c
  104. +27 −0 runtime/ocamlcc-byterun-4.00/compact.h
  105. +322 −0 runtime/ocamlcc-byterun-4.00/compare.c
  106. +21 −0 runtime/ocamlcc-byterun-4.00/compare.h
  107. +372 −0 runtime/ocamlcc-byterun-4.00/compatibility.h
  108. +103 −0 runtime/ocamlcc-byterun-4.00/custom.c
  109. +73 −0 runtime/ocamlcc-byterun-4.00/custom.h
  110. +446 −0 runtime/ocamlcc-byterun-4.00/debugger.c
  111. +113 −0 runtime/ocamlcc-byterun-4.00/debugger.h
  112. +274 −0 runtime/ocamlcc-byterun-4.00/dynlink.c
  113. +38 −0 runtime/ocamlcc-byterun-4.00/dynlink.h
  114. +62 −0 runtime/ocamlcc-byterun-4.00/exec.h
  115. +827 −0 runtime/ocamlcc-byterun-4.00/extern.c
  116. +176 −0 runtime/ocamlcc-byterun-4.00/fail.c
  117. +86 −0 runtime/ocamlcc-byterun-4.00/fail.h
  118. +251 −0 runtime/ocamlcc-byterun-4.00/finalise.c
  119. +29 −0 runtime/ocamlcc-byterun-4.00/finalise.h
  120. +174 −0 runtime/ocamlcc-byterun-4.00/fix_code.c
  121. +42 −0 runtime/ocamlcc-byterun-4.00/fix_code.h
  122. +431 −0 runtime/ocamlcc-byterun-4.00/flexdll.c
  123. +548 −0 runtime/ocamlcc-byterun-4.00/floats.c
  124. +556 −0 runtime/ocamlcc-byterun-4.00/freelist.c
  125. +36 −0 runtime/ocamlcc-byterun-4.00/freelist.h
  126. +58 −0 runtime/ocamlcc-byterun-4.00/gc.h
  127. +502 −0 runtime/ocamlcc-byterun-4.00/gc_ctrl.c
  128. +42 −0 runtime/ocamlcc-byterun-4.00/gc_ctrl.h
  129. +283 −0 runtime/ocamlcc-byterun-4.00/globroots.c
  130. +27 −0 runtime/ocamlcc-byterun-4.00/globroots.h
  131. +413 −0 runtime/ocamlcc-byterun-4.00/hash.c
  132. +31 −0 runtime/ocamlcc-byterun-4.00/hash.h
  133. +265 −0 runtime/ocamlcc-byterun-4.00/instrtrace.c
  134. +31 −0 runtime/ocamlcc-byterun-4.00/instrtrace.h
  135. +63 −0 runtime/ocamlcc-byterun-4.00/instruct.h
  136. +275 −0 runtime/ocamlcc-byterun-4.00/int64_emul.h
  137. +107 −0 runtime/ocamlcc-byterun-4.00/int64_format.h
  138. +54 −0 runtime/ocamlcc-byterun-4.00/int64_native.h
  139. +895 −0 runtime/ocamlcc-byterun-4.00/intern.c
  140. +170 −0 runtime/ocamlcc-byterun-4.00/intext.h
  141. +788 −0 runtime/ocamlcc-byterun-4.00/ints.c
  142. +810 −0 runtime/ocamlcc-byterun-4.00/io.c
  143. +126 −0 runtime/ocamlcc-byterun-4.00/io.h
  144. +37 −0 runtime/ocamlcc-byterun-4.00/jumptbl.h
  145. +256 −0 runtime/ocamlcc-byterun-4.00/lexing.c
  146. +63 −0 runtime/ocamlcc-byterun-4.00/main.c
  147. +510 −0 runtime/ocamlcc-byterun-4.00/major_gc.c
  148. +62 −0 runtime/ocamlcc-byterun-4.00/major_gc.h
  149. +324 −0 runtime/ocamlcc-byterun-4.00/md5.c
  150. +43 −0 runtime/ocamlcc-byterun-4.00/md5.h
  151. +550 −0 runtime/ocamlcc-byterun-4.00/memory.c
  152. +468 −0 runtime/ocamlcc-byterun-4.00/memory.h
  153. +326 −0 runtime/ocamlcc-byterun-4.00/minor_gc.c
  154. +58 −0 runtime/ocamlcc-byterun-4.00/minor_gc.h
  155. +125 −0 runtime/ocamlcc-byterun-4.00/misc.c
  156. +136 −0 runtime/ocamlcc-byterun-4.00/misc.h
  157. +306 −0 runtime/ocamlcc-byterun-4.00/mlvalues.h
  158. +255 −0 runtime/ocamlcc-byterun-4.00/obj.c
  159. +71 −0 runtime/ocamlcc-byterun-4.00/osdeps.h
  160. +321 −0 runtime/ocamlcc-byterun-4.00/parsing.c
  161. +826 −0 runtime/ocamlcc-byterun-4.00/prims.c
  162. +37 −0 runtime/ocamlcc-byterun-4.00/prims.h
  163. +127 −0 runtime/ocamlcc-byterun-4.00/printexc.c
  164. +35 −0 runtime/ocamlcc-byterun-4.00/printexc.h
  165. +88 −0 runtime/ocamlcc-byterun-4.00/reverse.h
  166. +113 −0 runtime/ocamlcc-byterun-4.00/roots.c
  167. +38 −0 runtime/ocamlcc-byterun-4.00/roots.h
  168. +307 −0 runtime/ocamlcc-byterun-4.00/signals.c
  169. +59 −0 runtime/ocamlcc-byterun-4.00/signals.h
  170. +101 −0 runtime/ocamlcc-byterun-4.00/signals_byt.c
  171. +62 −0 runtime/ocamlcc-byterun-4.00/signals_machdep.h
  172. +116 −0 runtime/ocamlcc-byterun-4.00/stacks.c
  173. +43 −0 runtime/ocamlcc-byterun-4.00/stacks.h
  174. +533 −0 runtime/ocamlcc-byterun-4.00/startup.c
  175. +40 −0 runtime/ocamlcc-byterun-4.00/startup.h
  176. +155 −0 runtime/ocamlcc-byterun-4.00/str.c
  177. +376 −0 runtime/ocamlcc-byterun-4.00/sys.c
  178. +30 −0 runtime/ocamlcc-byterun-4.00/sys.h
  179. +132 −0 runtime/ocamlcc-byterun-4.00/terminfo.c
  180. +28 −0 runtime/ocamlcc-byterun-4.00/ui.h
  181. +325 −0 runtime/ocamlcc-byterun-4.00/unix.c
  182. +1 −0 runtime/ocamlcc-byterun-4.00/version.h
  183. +193 −0 runtime/ocamlcc-byterun-4.00/weak.c
  184. +26 −0 runtime/ocamlcc-byterun-4.00/weak.h
  185. +482 −0 runtime/ocamlcc-byterun-4.00/win32.c
  186. +48 −44 runtime/ocamlcc-byterun.h
  187. +0 −1 runtime/ocamlcc-byterun/version.h
  188. +1 −1 runtime/ocamlcc-exceptions.c
  189. +5 −5 runtime/ocamlcc-main.c
  190. +6 −2 runtime/ocamlcc-unimpl.c
  191. +2 −2 runtime/ocamlcc-windows.c
  192. +1 −1 runtime/ocamlcc.h
  193. +2 −0 src/codegen/codegen.ml
  194. +25 −7 src/ocamlcc.ml
  195. +19 −0 src/tools/options.ml
  196. +6 −4 tests/Makefile
View
@@ -34,7 +34,9 @@ install: all
cp bin/ocamlcc "$(BINDIR)/ocamlcc"
gzip -c man/ocamlcc.1 > "$(MAN1DIR)/ocamlcc.1.gz"
cp -R runtime/* "$(INCLUDEDIR)/"
- cp etc/config.h "$(INCLUDEDIR)/ocamlcc-byterun/config.h"
+ for d in runtime/ocamlcc-byterun-?.??; do \
+ cp etc/config.h "$(INCLUDEDIR)/$${d:8:20}/config.h"; \
+ done
@if [ $(INSTALL_OCAMLCLEAN) = true ]; then \
cd $(OCAMLCLEAN_DIRECTORY)/; \
make --no-print-directory install; \
View
@@ -41,6 +41,7 @@ function remove_trailing_slash () {
###
+cd $(dirname "$0")
mkdir -p bin etc dist
###
@@ -58,12 +59,34 @@ check_command "gcc"
###
+OCAML_VERSION=$(ocamlc -version | cut -c1-4)
+DEFAULT_RUNTIME_VERSION=''
+RUNTIME_VERSIONS=''
+for d in runtime/ocamlcc-byterun-?.??; do
+ V="${d:24:4}"
+ RUNTIME_VERSIONS="$RUNTIME_VERSIONS $V"
+ if [ "$OCAML_VERSION" = "$V" ]; then
+ DEFAULT_RUNTIME_VERSION="$OCAML_VERSION"
+ fi
+done
+if [ "$OCAML_VERSION" != "$DEFAULT_RUNTIME_VERSION" ]; then
+ echo "Error: Incompatible OCaml version: $OCAML_VERSION" 1>&2
+ echo " Supported versions: $RUNTIME_VERSIONS" 1>&2
+ exit 1
+fi
+RUNTIME_VERSION_LIST='['
+for v in $RUNTIME_VERSIONS; do
+ RUNTIME_VERSION_LIST="$RUNTIME_VERSION_LIST \"$v\";"
+done
+RUNTIME_VERSION_LIST="$RUNTIME_VERSION_LIST ]"
+
+###
+
OCAMLBUILD=$(which ocamlbuild)
OCAMLLIB=$(ocamlc -where)
GCC=$(which gcc)
ARCH=$(test -x /bin/uname && /bin/uname -m || echo none)
VERSION=$(cat VERSION)
-RUNTIME_VERSION=$(cat runtime/VERSION)
SAVED_PWD=$(pwd)
###
@@ -147,13 +170,16 @@ fi
###
echo "\
+SHELL = bash
+
INSTALL_OCAMLCLEAN = $INSTALL_OCAMLCLEAN
OCAMLCLEAN = $OCAMLCLEAN
OCAMLCLEAN_VERSION = $OCAMLCLEAN_VERSION
OCAMLCLEAN_DIRECTORY = $OCAMLCLEAN_DIRECTORY
OCAMLCLEAN_ARCHIVE = $OCAMLCLEAN_ARCHIVE
VERSION = $VERSION
-RUNTIME_VERSION = $RUNTIME_VERSION
+RUNTIME_VERSIONS = $RUNTIME_VERSIONS
+DEFAULT_RUNTIME_VERSION = $DEFAULT_RUNTIME_VERSION
OCAMLBUILD = $OCAMLBUILD -cflags -w,Ae,-warn-error,A -lflags -w,Ae,-warn-error,A -no-links -classic-display
@@ -167,7 +193,8 @@ MAN1DIR = $MANDIR/man1
echo "\
(* Generated by configure *)
let version = \"$VERSION\";;
-let runtime_version = \"$RUNTIME_VERSION\";;
+let runtime_versions = $RUNTIME_VERSION_LIST;;
+let default_runtime_version = \"$DEFAULT_RUNTIME_VERSION\";;
let include_dir = \"$INCLUDEDIR/ocamlcc\";;
let default_arch = \"gen\";;
let ccomp = \"$CCOMP\";;
View
Binary file not shown.
View
@@ -1 +0,0 @@
-OCaml 3.12
@@ -14,9 +14,9 @@
#include <stdio.h>
#include <stdlib.h>
-#include "ocamlcc-byterun/mlvalues.h"
-#include "ocamlcc-byterun/memory.h"
-#include "ocamlcc-byterun/stacks.h"
+#include <mlvalues.h>
+#include <memory.h>
+#include <stacks.h>
/***/
@@ -14,9 +14,9 @@
#include <stdio.h>
#include <stdlib.h>
-#include "ocamlcc-byterun/mlvalues.h"
-#include "ocamlcc-byterun/memory.h"
-#include "ocamlcc-byterun/stacks.h"
+#include <mlvalues.h>
+#include <memory.h>
+#include <stacks.h>
/***/
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -31,7 +31,7 @@ int main(int argc, char **argv)
{
#ifdef DEBUG
{
-#if 0
+#if 0 /* OCamlCC: clean */
char *ocp;
char *cp;
int i;
@@ -173,6 +173,7 @@ CAMLexport void caml_MD5Final(unsigned char *digest, struct MD5Context *ctx)
{
unsigned count;
unsigned char *p;
+ /* OCamlCC: see below */
uint32 *tmp;
/* Compute number of bytes mod 64 */
File renamed without changes.
File renamed without changes.
@@ -21,6 +21,7 @@
typedef value (*c_primitive)();
extern c_primitive caml_builtin_cprim[];
+/* OCamlCC: add const modifier */
extern const char * caml_names_of_builtin_cprim[];
extern struct ext_table caml_prim_table;
@@ -22,12 +22,11 @@
#include "mlvalues.h"
#include "stacks.h"
-
CAMLexport value * caml_stack_low;
CAMLexport value * caml_stack_high;
+CAMLexport value * caml_stack_threshold;
/* OCamlCC: move caml_extern_sp definition to ocamlcc-sp.c */
/*CAMLexport value * caml_extern_sp;*/
-CAMLexport value * caml_stack_threshold;
CAMLexport value * caml_trapsp;
CAMLexport value * caml_trap_barrier;
value caml_global_data;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1 @@
+#define OCAML_VERSION "3.12"
@@ -0,0 +1,194 @@
+/***********************************************************************/
+/* */
+/* OCaml */
+/* */
+/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */
+/* */
+/* Copyright 1996 Institut National de Recherche en Informatique et */
+/* en Automatique. All rights reserved. This file is distributed */
+/* under the terms of the GNU Library General Public License, with */
+/* the special exception on linking described in file ../LICENSE. */
+/* */
+/***********************************************************************/
+
+/* $Id: alloc.c 11156 2011-07-27 14:17:02Z doligez $ */
+
+/* 1. Allocation functions doing the same work as the macros in the
+ case where [Setup_for_gc] and [Restore_after_gc] are no-ops.
+ 2. Convenience functions related to allocation.
+*/
+
+#include <string.h>
+#include "alloc.h"
+#include "custom.h"
+#include "major_gc.h"
+#include "memory.h"
+#include "mlvalues.h"
+#include "stacks.h"
+
+#define Setup_for_gc
+#define Restore_after_gc
+
+CAMLexport value caml_alloc (mlsize_t wosize, tag_t tag)
+{
+ value result;
+ mlsize_t i;
+
+ Assert (tag < 256);
+ Assert (tag != Infix_tag);
+ if (wosize == 0){
+ result = Atom (tag);
+ }else if (wosize <= Max_young_wosize){
+ Alloc_small (result, wosize, tag);
+ if (tag < No_scan_tag){
+ for (i = 0; i < wosize; i++) Field (result, i) = 0;
+ }
+ }else{
+ result = caml_alloc_shr (wosize, tag);
+ if (tag < No_scan_tag) memset (Bp_val (result), 0, Bsize_wsize (wosize));
+ result = caml_check_urgent_gc (result);
+ }
+ return result;
+}
+
+CAMLexport value caml_alloc_small (mlsize_t wosize, tag_t tag)
+{
+ value result;
+
+ Assert (wosize > 0);
+ Assert (wosize <= Max_young_wosize);
+ Assert (tag < 256);
+ Alloc_small (result, wosize, tag);
+ return result;
+}
+
+CAMLexport value caml_alloc_tuple(mlsize_t n)
+{
+ return caml_alloc(n, 0);
+}
+
+CAMLexport value caml_alloc_string (mlsize_t len)
+{
+ value result;
+ mlsize_t offset_index;
+ mlsize_t wosize = (len + sizeof (value)) / sizeof (value);
+
+ if (wosize <= Max_young_wosize) {
+ Alloc_small (result, wosize, String_tag);
+ }else{
+ result = caml_alloc_shr (wosize, String_tag);
+ result = caml_check_urgent_gc (result);
+ }
+ Field (result, wosize - 1) = 0;
+ offset_index = Bsize_wsize (wosize) - 1;
+ Byte (result, offset_index) = offset_index - len;
+ return result;
+}
+
+CAMLexport value caml_alloc_final (mlsize_t len, final_fun fun,
+ mlsize_t mem, mlsize_t max)
+{
+ return caml_alloc_custom(caml_final_custom_operations(fun),
+ len * sizeof(value), mem, max);
+}
+
+CAMLexport value caml_copy_string(char const *s)
+{
+ int len;
+ value res;
+
+ len = strlen(s);
+ res = caml_alloc_string(len);
+ memmove(String_val(res), s, len);
+ return res;
+}
+
+CAMLexport value caml_alloc_array(value (*funct)(char const *),
+ char const ** arr)
+{
+ CAMLparam0 ();
+ mlsize_t nbr, n;
+ CAMLlocal2 (v, result);
+
+ nbr = 0;
+ while (arr[nbr] != 0) nbr++;
+ if (nbr == 0) {
+ CAMLreturn (Atom(0));
+ } else {
+ result = caml_alloc (nbr, 0);
+ for (n = 0; n < nbr; n++) {
+ /* The two statements below must be separate because of evaluation
+ order (don't take the address &Field(result, n) before
+ calling funct, which may cause a GC and move result). */
+ v = funct(arr[n]);
+ caml_modify(&Field(result, n), v);
+ }
+ CAMLreturn (result);
+ }
+}
+
+CAMLexport value caml_copy_string_array(char const ** arr)
+{
+ return caml_alloc_array(caml_copy_string, arr);
+}
+
+CAMLexport int caml_convert_flag_list(value list, int *flags)
+{
+ int res;
+ res = 0;
+ while (list != Val_int(0)) {
+ res |= flags[Int_val(Field(list, 0))];
+ list = Field(list, 1);
+ }
+ return res;
+}
+
+/* For compiling let rec over values */
+
+CAMLprim value caml_alloc_dummy(value size)
+{
+ mlsize_t wosize = Int_val(size);
+
+ if (wosize == 0) return Atom(0);
+ /* OCamlCC: allocate size + 1, because closures' arity */
+ return caml_alloc (wosize + 1, 0);
+}
+
+CAMLprim value caml_alloc_dummy_float (value size)
+{
+ mlsize_t wosize = Int_val(size) * Double_wosize;
+
+ if (wosize == 0) return Atom(0);
+ return caml_alloc (wosize, 0);
+}
+
+CAMLprim value caml_update_dummy(value dummy, value newval)
+{
+ mlsize_t size, i;
+ tag_t tag;
+ size = Wosize_val(newval);
+ tag = Tag_val (newval);
+ /* OCamlCC: size of dummy and newval may differ. Adjust them. */
+ Assert (Is_block (newval));
+ Assert (size <= Wosize_val(dummy));
+ Assert (tag < No_scan_tag || tag == Double_array_tag);
+ if (size < Wosize_val(dummy))
+ caml_obj_truncate(dummy, Val_long(size));
+ Tag_val(dummy) = tag;
+ if (tag == Double_array_tag){
+ size = Wosize_val (newval) / Double_wosize;
+ for (i = 0; i < size; i++){
+ Store_double_field (dummy, i, Double_field (newval, i));
+ }
+ }else{
+ for (i = 0; i < size; i++){
+ caml_modify (&Field(dummy, i), Field(newval, i));
+ }
+ }
+ return Val_unit;
+}
+
+/* OCamlCC: undef Setup_for_gc, Restore_after_gc (conflicts with interp.c) */
+
+#undef Setup_for_gc
+#undef Restore_after_gc
Oops, something went wrong.

0 comments on commit fc5faab

Please sign in to comment.