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"
|
|
|
|
#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
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value get_global_data(value unit)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
return global_data;
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value 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
|
1995-05-04 03:15:53 -07:00
|
|
|
fixup_endianness((code_t) prog, (asize_t) Long_val(len));
|
|
|
|
#endif
|
1996-05-28 05:41:37 -07:00
|
|
|
#ifdef THREADED_CODE
|
|
|
|
thread_code((code_t) prog, (asize_t) Long_val(len));
|
|
|
|
#endif
|
1998-10-26 11:19:32 -08:00
|
|
|
clos = 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
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value 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);
|
|
|
|
actual_size = Wosize_val(global_data);
|
|
|
|
if (requested_size >= actual_size) {
|
|
|
|
requested_size = (requested_size + 0x100) & 0xFFFFFF00;
|
1998-08-07 11:43:39 -07:00
|
|
|
gc_message (0x08, "Growing global data to %lu entries\n", requested_size);
|
1995-05-04 03:15:53 -07:00
|
|
|
new_global_data = alloc_shr(requested_size, 0);
|
|
|
|
for (i = 0; i < actual_size; i++)
|
|
|
|
initialize(&Field(new_global_data, i), Field(global_data, i));
|
|
|
|
for (i = actual_size; i < requested_size; i++){
|
|
|
|
Field (new_global_data, i) = Val_long (0);
|
|
|
|
}
|
|
|
|
global_data = new_global_data;
|
|
|
|
}
|
1995-06-18 07:44:56 -07:00
|
|
|
return Val_unit;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value get_current_environment(value unit)
|
1995-09-14 04:52:50 -07:00
|
|
|
{
|
|
|
|
return *extern_sp;
|
|
|
|
}
|
1997-11-17 02:39:01 -08:00
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value 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;
|
|
|
|
|
|
|
|
osp = extern_sp;
|
|
|
|
extern_sp -= 4;
|
|
|
|
nsp = extern_sp;
|
|
|
|
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 */
|
|
|
|
|
|
|
|
value get_global_data(value unit)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
value realloc_global(value size)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
value available_primitives(value unit)
|
|
|
|
{
|
|
|
|
invalid_argument("Meta.available_primitives");
|
2000-02-22 09:02:54 -08:00
|
|
|
return Val_unit; /* not reached */
|
1997-11-17 02:39:01 -08:00
|
|
|
}
|
|
|
|
|
1998-09-07 00:56:06 -07:00
|
|
|
value invoke_traced_function(value codeptr, value env, value arg)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1997-11-17 02:39:01 -08:00
|
|
|
#endif
|