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 */
|
|
|
|
/* under the terms of the GNU Library General Public License. */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* Structured input/output */
|
|
|
|
|
|
|
|
#ifndef __intext__
|
|
|
|
#define __intext__
|
|
|
|
|
|
|
|
#include "misc.h"
|
|
|
|
#include "mlvalues.h"
|
|
|
|
#include "io.h"
|
|
|
|
|
|
|
|
/* Magic number */
|
|
|
|
|
1996-04-01 07:24:38 -08:00
|
|
|
#define Intext_magic_number 0x8495A6BE
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
/* Codes for the compact format */
|
|
|
|
|
|
|
|
#define PREFIX_SMALL_BLOCK 0x80
|
|
|
|
#define PREFIX_SMALL_INT 0x40
|
|
|
|
#define PREFIX_SMALL_STRING 0x20
|
|
|
|
#define CODE_INT8 0x0
|
|
|
|
#define CODE_INT16 0x1
|
|
|
|
#define CODE_INT32 0x2
|
|
|
|
#define CODE_INT64 0x3
|
|
|
|
#define CODE_SHARED8 0x4
|
|
|
|
#define CODE_SHARED16 0x5
|
|
|
|
#define CODE_SHARED32 0x6
|
|
|
|
#define CODE_BLOCK32 0x8
|
|
|
|
#define CODE_STRING8 0x9
|
|
|
|
#define CODE_STRING32 0xA
|
|
|
|
#define CODE_DOUBLE_BIG 0xB
|
|
|
|
#define CODE_DOUBLE_LITTLE 0xC
|
1995-07-28 05:23:27 -07:00
|
|
|
#define CODE_DOUBLE_ARRAY8_BIG 0xD
|
|
|
|
#define CODE_DOUBLE_ARRAY8_LITTLE 0xE
|
|
|
|
#define CODE_DOUBLE_ARRAY32_BIG 0xF
|
|
|
|
#define CODE_DOUBLE_ARRAY32_LITTLE 0x7
|
1997-07-02 11:16:15 -07:00
|
|
|
#define CODE_CODEPOINTER 0x10
|
|
|
|
#define CODE_INFIXPOINTER 0x11
|
2000-02-10 06:04:59 -08:00
|
|
|
#define CODE_CUSTOM 0x12
|
1995-07-28 05:23:27 -07:00
|
|
|
|
1996-07-01 05:43:28 -07:00
|
|
|
#ifdef ARCH_BIG_ENDIAN
|
1995-05-04 03:15:53 -07:00
|
|
|
#define CODE_DOUBLE_NATIVE CODE_DOUBLE_BIG
|
1995-07-28 05:23:27 -07:00
|
|
|
#define CODE_DOUBLE_ARRAY8_NATIVE CODE_DOUBLE_ARRAY8_BIG
|
|
|
|
#define CODE_DOUBLE_ARRAY32_NATIVE CODE_DOUBLE_ARRAY32_BIG
|
1995-05-04 03:15:53 -07:00
|
|
|
#else
|
|
|
|
#define CODE_DOUBLE_NATIVE CODE_DOUBLE_LITTLE
|
1995-07-28 05:23:27 -07:00
|
|
|
#define CODE_DOUBLE_ARRAY8_NATIVE CODE_DOUBLE_ARRAY8_LITTLE
|
|
|
|
#define CODE_DOUBLE_ARRAY32_NATIVE CODE_DOUBLE_ARRAY32_LITTLE
|
1995-07-27 10:41:09 -07:00
|
|
|
#endif
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
/* Initial sizes of data structures for extern */
|
|
|
|
|
1996-04-01 07:24:38 -08:00
|
|
|
#ifndef INITIAL_EXTERN_BLOCK_SIZE
|
|
|
|
#define INITIAL_EXTERN_BLOCK_SIZE 8192
|
|
|
|
#endif
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
#ifndef INITIAL_EXTERN_TABLE_SIZE
|
|
|
|
#define INITIAL_EXTERN_TABLE_SIZE 2039
|
|
|
|
#endif
|
|
|
|
|
1997-04-11 06:57:04 -07:00
|
|
|
/* Maximal value of initial_ofs above which we should start again with
|
|
|
|
initial_ofs = 1. Should be low enough to prevent rollover of initial_ofs
|
|
|
|
next time we extern a structure. Since a structure contains at most
|
|
|
|
2^N / (2 * sizeof(value)) heap objects (N = 32 or 64 depending on target),
|
|
|
|
any value below 2^N - (2^N / (2 * sizeof(value))) suffices.
|
|
|
|
We just take 2^(N-1) for simplicity. */
|
|
|
|
|
1997-11-17 05:52:31 -08:00
|
|
|
#define INITIAL_OFFSET_MAX ((unsigned long)1 << (8 * sizeof(value) - 1))
|
1997-04-11 06:57:04 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* The entry points */
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void output_val (struct channel * chan, value v, value flags);
|
|
|
|
value input_val (struct channel * chan);
|
|
|
|
value input_val_from_string (value str, long ofs);
|
1997-07-02 11:16:15 -07:00
|
|
|
|
2000-02-10 06:04:59 -08:00
|
|
|
/* Functions for writing user-defined marshallers */
|
|
|
|
|
|
|
|
extern void serialize_int_1(int i);
|
|
|
|
extern void serialize_int_2(int i);
|
|
|
|
extern void serialize_int_4(int32 i);
|
|
|
|
extern void serialize_int_8(int64 i);
|
|
|
|
extern void serialize_float_4(float f);
|
|
|
|
extern void serialize_float_8(double f);
|
|
|
|
extern void serialize_block_1(void * data, long len);
|
|
|
|
extern void serialize_block_2(void * data, long len);
|
|
|
|
extern void serialize_block_4(void * data, long len);
|
|
|
|
extern void serialize_block_8(void * data, long len);
|
|
|
|
|
|
|
|
extern int deserialize_uint_1(void);
|
|
|
|
extern int deserialize_sint_1(void);
|
|
|
|
extern int deserialize_uint_2(void);
|
|
|
|
extern int deserialize_sint_2(void);
|
|
|
|
extern uint32 deserialize_uint_4(void);
|
|
|
|
extern int32 deserialize_sint_4(void);
|
|
|
|
extern uint64 deserialize_uint_8(void);
|
|
|
|
extern int64 deserialize_sint_8(void);
|
|
|
|
extern float deserialize_float_4(void);
|
|
|
|
extern double deserialize_float_8(void);
|
|
|
|
extern void deserialize_block_1(void * data, long len);
|
|
|
|
extern void deserialize_block_2(void * data, long len);
|
|
|
|
extern void deserialize_block_4(void * data, long len);
|
|
|
|
extern void deserialize_block_8(void * data, long len);
|
2000-02-11 07:09:27 -08:00
|
|
|
extern void deserialize_error(char * msg);
|
2000-02-10 06:04:59 -08:00
|
|
|
|
1997-07-02 11:16:15 -07:00
|
|
|
/* Auxiliary stuff for sending code pointers */
|
1997-09-02 05:55:01 -07:00
|
|
|
unsigned char * code_checksum (void);
|
1997-07-02 11:16:15 -07:00
|
|
|
|
|
|
|
#ifndef NATIVE_CODE
|
|
|
|
#include "fix_code.h"
|
|
|
|
#define code_area_start ((char *) start_code)
|
|
|
|
#define code_area_end ((char *) start_code + code_size)
|
|
|
|
#else
|
|
|
|
extern char * code_area_start, * code_area_end;
|
|
|
|
#endif
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
#endif
|
|
|
|
|