Guest User

Untitled

a guest
Feb 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. diff --git a/Changes b/Changes
  2. index 9639cc3..151cf97 100644
  3. --- a/Changes
  4. +++ b/Changes
  5. @@ -32,6 +32,8 @@ Runtime system:
  6. - PR#6517: use ISO C99 types {,u}int{32,64}_t in preference to our homegrown
  7. types {,u}int{32,64}.
  8. (Xavier Leroy)
  9. +- PR#6760: closures can now be marshalled in toplevel.
  10. + (Peter Zotov)
  11.  
  12. Standard library:
  13. * PR#6494: Add equal function in modules
  14. diff --git a/byterun/caml/misc.h b/byterun/caml/misc.h
  15. index df75298..b2d4425 100644
  16. --- a/byterun/caml/misc.h
  17. +++ b/byterun/caml/misc.h
  18. @@ -91,6 +91,7 @@ struct ext_table {
  19.  
  20. extern void caml_ext_table_init(struct ext_table * tbl, int init_capa);
  21. extern int caml_ext_table_add(struct ext_table * tbl, void * data);
  22. +extern void caml_ext_table_remove(struct ext_table * tbl, void * data);
  23. extern void caml_ext_table_free(struct ext_table * tbl, int free_entries);
  24.  
  25. /* GC flags and messages */
  26. diff --git a/byterun/meta.c b/byterun/meta.c
  27. index edec407..fde0b83 100644
  28. --- a/byterun/meta.c
  29. +++ b/byterun/meta.c
  30. @@ -47,6 +47,12 @@ CAMLprim value caml_get_section_table(value unit)
  31.  
  32. CAMLprim value caml_reify_bytecode(value prog, value len)
  33. {
  34. + struct code_fragment * cf = caml_stat_alloc(sizeof(struct code_fragment));
  35. + cf->code_start = (char *) prog;
  36. + cf->code_end = (char *) prog + Long_val(len);
  37. + cf->digest_computed = 0;
  38. + caml_ext_table_add(&caml_code_fragments_table, cf);
  39. +
  40. value clos;
  41. #ifdef ARCH_BIG_ENDIAN
  42. caml_fixup_endianness((code_t) prog, (asize_t) Long_val(len));
  43. @@ -60,6 +66,34 @@ CAMLprim value caml_reify_bytecode(value prog, value len)
  44. return clos;
  45. }
  46.  
  47. +/* signal to the interpreter machinery that a bytecode is no more
  48. + needed (before freeing it) - this might be useful for a JIT
  49. + implementation */
  50. +
  51. +CAMLprim value caml_static_release_bytecode(value prog, value len)
  52. +{
  53. + struct code_fragment * cf = NULL, * cfi;
  54. + int i;
  55. + for (i = 0; i < caml_code_fragments_table.size; i++) {
  56. + cfi = (struct code_fragment *) caml_code_fragments_table.contents[i];
  57. + if (cfi->code_start == (char *) prog &&
  58. + cfi->code_end == (char *) prog + Long_val(len)) {
  59. + cf = cfi;
  60. + break;
  61. + }
  62. + }
  63. + /* Not matched with a caml_reify_bytecode call; impossible. */
  64. + if (!cf) abort();
  65. + caml_ext_table_remove(&caml_code_fragments_table, cf);
  66. +
  67. +#ifndef NATIVE_CODE
  68. + caml_release_bytecode((code_t) prog, (asize_t) Long_val(len));
  69. +#else
  70. + caml_failwith("Meta.static_release_bytecode impossible with native code");
  71. +#endif
  72. + return Val_unit;
  73. +}
  74. +
  75. CAMLprim value caml_register_code_fragment(value prog, value len, value digest)
  76. {
  77. struct code_fragment * cf = caml_stat_alloc(sizeof(struct code_fragment));
  78. diff --git a/byterun/misc.c b/byterun/misc.c
  79. index 784bdf4..03e5f57 100644
  80. --- a/byterun/misc.c
  81. +++ b/byterun/misc.c
  82. @@ -116,6 +116,19 @@ int caml_ext_table_add(struct ext_table * tbl, void * data)
  83. return res;
  84. }
  85.  
  86. +void caml_ext_table_remove(struct ext_table * tbl, void * data)
  87. +{
  88. + int i;
  89. + for (i = 0; i < tbl->size; i++) {
  90. + if (tbl->contents[i] == data) {
  91. + caml_stat_free(tbl->contents[i]);
  92. + memmove(&tbl->contents[i], &tbl->contents[i + 1],
  93. + (tbl->size - i - 1) * sizeof(void *));
  94. + tbl->size--;
  95. + }
  96. + }
  97. +}
  98. +
  99. void caml_ext_table_free(struct ext_table * tbl, int free_entries)
  100. {
  101. int i;
  102. diff --git a/byterun/obj.c b/byterun/obj.c
  103. index 3a43832..27b50d9 100644
  104. --- a/byterun/obj.c
  105. +++ b/byterun/obj.c
  106. @@ -37,21 +37,6 @@ CAMLprim value caml_static_free(value blk)
  107. return Val_unit;
  108. }
  109.  
  110. -/* signal to the interpreter machinery that a bytecode is no more
  111. - needed (before freeing it) - this might be useful for a JIT
  112. - implementation */
  113. -
  114. -CAMLprim value caml_static_release_bytecode(value blk, value size)
  115. -{
  116. -#ifndef NATIVE_CODE
  117. - caml_release_bytecode((code_t) blk, (asize_t) Long_val(size));
  118. -#else
  119. - caml_failwith("Meta.static_release_bytecode impossible with native code");
  120. -#endif
  121. - return Val_unit;
  122. -}
  123. -
  124. -
  125. CAMLprim value caml_static_resize(value blk, value new_size)
  126. {
  127. return (value) caml_stat_resize((char *) blk, (asize_t) Long_val(new_size));
Add Comment
Please, Sign In to add comment