1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../LICENSE. */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* Primitives for the toplevel */
|
|
|
|
|
|
|
|
#include "alloc.h"
|
1996-05-28 05:41:37 -07:00
|
|
|
#include "config.h"
|
1997-11-17 02:39:01 -08:00
|
|
|
#include "fail.h"
|
1995-05-09 02:34:59 -07:00
|
|
|
#include "fix_code.h"
|
1995-05-04 03:15:53 -07:00
|
|
|
#include "interp.h"
|
2004-02-22 07:07:51 -08:00
|
|
|
#include "intext.h"
|
1995-05-04 03:15:53 -07:00
|
|
|
#include "major_gc.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "minor_gc.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "mlvalues.h"
|
|
|
|
#include "prims.h"
|
1995-09-14 04:52:50 -07:00
|
|
|
#include "stacks.h"
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1997-11-17 02:39:01 -08:00
|
|
|
#ifndef NATIVE_CODE
|
|
|
|
|
2003-12-31 06:20:40 -08:00
|
|
|
CAMLprim value caml_get_global_data(value unit)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
2003-12-31 06:20:40 -08:00
|
|
|
return caml_global_data;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
2004-02-22 07:07:51 -08:00
|
|
|
char * caml_section_table = NULL;
|
|
|
|
asize_t caml_section_table_size;
|
|
|
|
|
|
|
|
CAMLprim value caml_get_section_table(value unit)
|
|
|
|
{
|
|
|
|
if (caml_section_table == NULL) caml_raise_not_found();
|
|
|
|
return caml_input_value_from_block(caml_section_table,
|
|
|
|
caml_section_table_size);
|
|
|
|
}
|
|
|
|
|
2003-12-31 06:20:40 -08:00
|
|
|
CAMLprim value caml_reify_bytecode(value prog, value len)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1996-05-28 05:41:37 -07:00
|
|
|
value clos;
|
1996-07-01 05:43:28 -07:00
|
|
|
#ifdef ARCH_BIG_ENDIAN
|
2004-01-02 11:23:29 -08:00
|
|
|
caml_fixup_endianness((code_t) prog, (asize_t) Long_val(len));
|
1995-05-04 03:15:53 -07:00
|
|
|
#endif
|
1996-05-28 05:41:37 -07:00
|
|
|
#ifdef THREADED_CODE
|
2004-01-02 11:23:29 -08:00
|
|
|
caml_thread_code((code_t) prog, (asize_t) Long_val(len));
|
1996-05-28 05:41:37 -07:00
|
|
|
#endif
|
2004-04-26 07:09:01 -07:00
|
|
|
caml_prepare_bytecode((code_t) prog, (asize_t) Long_val(len));
|
2003-12-29 14:15:02 -08:00
|
|
|
clos = caml_alloc_small (1, Closure_tag);
|
1996-05-28 05:41:37 -07:00
|
|
|
Code_val(clos) = (code_t) prog;
|
|
|
|
return clos;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
2003-12-31 06:20:40 -08:00
|
|
|
CAMLprim value caml_realloc_global(value size)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
mlsize_t requested_size, actual_size, i;
|
|
|
|
value new_global_data;
|
|
|
|
|
|
|
|
requested_size = Long_val(size);
|
2003-12-31 06:20:40 -08:00
|
|
|
actual_size = Wosize_val(caml_global_data);
|
1995-05-04 03:15:53 -07:00
|
|
|
if (requested_size >= actual_size) {
|
|
|
|
requested_size = (requested_size + 0x100) & 0xFFFFFF00;
|
2003-12-29 14:15:02 -08:00
|
|
|
caml_gc_message (0x08, "Growing global data to %lu entries\n",
|
|
|
|
requested_size);
|
2003-12-31 06:20:40 -08:00
|
|
|
new_global_data = caml_alloc_shr(requested_size, 0);
|
1995-05-04 03:15:53 -07:00
|
|
|
for (i = 0; i < actual_size; i++)
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_initialize(&Field(new_global_data, i), Field(caml_global_data, i));
|
1995-05-04 03:15:53 -07:00
|
|
|
for (i = actual_size; i < requested_size; i++){
|
|
|
|
Field (new_global_data, i) = Val_long (0);
|
|
|
|
}
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_global_data = new_global_data;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
1995-06-18 07:44:56 -07:00
|
|
|
return Val_unit;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
2003-12-31 06:20:40 -08:00
|
|
|
CAMLprim value caml_get_current_environment(value unit)
|
1995-09-14 04:52:50 -07:00
|
|
|
{
|
2003-12-31 06:20:40 -08:00
|
|
|
return *caml_extern_sp;
|
1995-09-14 04:52:50 -07:00
|
|
|
}
|
1997-11-17 02:39:01 -08:00
|
|
|
|
2003-12-31 06:20:40 -08:00
|
|
|
CAMLprim value caml_invoke_traced_function(value codeptr, value env, value arg)
|
1998-09-07 00:56:06 -07:00
|
|
|
{
|
|
|
|
/* Stack layout on entry:
|
|
|
|
return frame into instrument_closure function
|
|
|
|
arg3 to call_original_code (arg)
|
|
|
|
arg2 to call_original_code (env)
|
|
|
|
arg1 to call_original_code (codeptr)
|
|
|
|
arg3 to call_original_code (arg)
|
|
|
|
arg2 to call_original_code (env)
|
|
|
|
saved env */
|
|
|
|
|
|
|
|
/* Stack layout on exit:
|
|
|
|
return frame into instrument_closure function
|
|
|
|
actual arg to code (arg)
|
|
|
|
pseudo return frame into codeptr:
|
|
|
|
extra_args = 0
|
|
|
|
environment = env
|
|
|
|
PC = codeptr
|
|
|
|
arg3 to call_original_code (arg) same 6 bottom words as
|
|
|
|
arg2 to call_original_code (env) on entrance, but
|
|
|
|
arg1 to call_original_code (codeptr) shifted down 4 words
|
|
|
|
arg3 to call_original_code (arg)
|
|
|
|
arg2 to call_original_code (env)
|
|
|
|
saved env */
|
|
|
|
|
|
|
|
value * osp, * nsp;
|
|
|
|
int i;
|
|
|
|
|
2003-12-31 06:20:40 -08:00
|
|
|
osp = caml_extern_sp;
|
|
|
|
caml_extern_sp -= 4;
|
|
|
|
nsp = caml_extern_sp;
|
1998-09-07 00:56:06 -07:00
|
|
|
for (i = 0; i < 6; i++) nsp[i] = osp[i];
|
|
|
|
nsp[6] = codeptr;
|
|
|
|
nsp[7] = env;
|
|
|
|
nsp[8] = Val_int(0);
|
|
|
|
nsp[9] = arg;
|
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
1997-11-17 02:39:01 -08:00
|
|
|
#else
|
|
|
|
|
|
|
|
/* Dummy definitions to support compilation of ocamlc.opt */
|
|
|
|
|
2003-12-31 06:20:40 -08:00
|
|
|
value caml_get_global_data(value unit)
|
1997-11-17 02:39:01 -08:00
|
|
|
{
|
2004-01-01 08:42:43 -08:00
|
|
|
caml_invalid_argument("Meta.get_global_data");
|
2000-02-22 09:02:54 -08:00
|
|
|
return Val_unit; /* not reached */
|
1997-11-17 02:39:01 -08:00
|
|
|
}
|
|
|
|
|
2004-02-22 07:07:51 -08:00
|
|
|
value caml_get_section_table(value unit)
|
|
|
|
{
|
|
|
|
caml_invalid_argument("Meta.get_section_table");
|
|
|
|
return Val_unit; /* not reached */
|
|
|
|
}
|
|
|
|
|
2003-12-31 06:20:40 -08:00
|
|
|
value caml_realloc_global(value size)
|
1997-11-17 02:39:01 -08:00
|
|
|
{
|
2004-01-01 08:42:43 -08:00
|
|
|
caml_invalid_argument("Meta.realloc_global");
|
2000-02-22 09:02:54 -08:00
|
|
|
return Val_unit; /* not reached */
|
1997-11-17 02:39:01 -08:00
|
|
|
}
|
|
|
|
|
2003-12-31 06:20:40 -08:00
|
|
|
value caml_invoke_traced_function(value codeptr, value env, value arg)
|
1998-09-07 00:56:06 -07:00
|
|
|
{
|
2004-01-01 08:42:43 -08:00
|
|
|
caml_invalid_argument("Meta.invoke_traced_function");
|
2000-02-22 09:02:54 -08:00
|
|
|
return Val_unit; /* not reached */
|
1998-09-07 00:56:06 -07:00
|
|
|
}
|
|
|
|
|
2003-12-31 06:20:40 -08:00
|
|
|
value * caml_stack_low;
|
|
|
|
value * caml_stack_high;
|
|
|
|
value * caml_stack_threshold;
|
|
|
|
value * caml_extern_sp;
|
|
|
|
value * caml_trapsp;
|
|
|
|
int caml_callback_depth;
|
2004-01-01 08:42:43 -08:00
|
|
|
int volatile caml_something_to_do;
|
|
|
|
void (* volatile caml_async_action_hook)(void);
|
|
|
|
struct longjmp_buffer * caml_external_raise;
|
2002-02-21 05:54:44 -08:00
|
|
|
|
1997-11-17 02:39:01 -08:00
|
|
|
#endif
|