Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/runtime/include/ml-base.h
ViewVC logotype

Annotation of /sml/trunk/src/runtime/include/ml-base.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (view) (download) (as text)

1 : monnier 249 /* ml-base.h
2 :     *
3 :     * COPYRIGHT (c) 1992 AT&T Bell Laboratories
4 :     *
5 :     */
6 :    
7 :     #ifndef _ML_BASE_
8 :     #define _ML_BASE_
9 :    
10 :     /* macro concatenation (ANSI CPP) */
11 :     #define CONCAT(a,b) a ## b
12 :     #define CONCAT3(a,b,c) a ## b ## c
13 :    
14 :     #define ONE_K 1024
15 :     #define ONE_MEG (ONE_K*ONE_K)
16 :    
17 :     /* The generated file ml-sizes.h defines various size macros, and
18 :     * the following types:
19 :     *
20 :     * Int16_t -- 16-bit signed integer
21 :     * Int32_t -- 32-bit signed integer
22 :     * Int64_t -- 64-bit signed integer (64-bit machines only)
23 :     * Unsigned16_t -- 16-bit unsigned integer
24 :     * Unsigned32_t -- 32-bit unsigned integer
25 :     * Unsigned64_t -- 64-bit unsigned integer (64-bit machines only)
26 :     * Byte_t -- unsigned 8-bit integer.
27 :     * Word_t -- unsigned integer that is large enough to hold an ML value.
28 :     * Int_t -- signed integer that is large enough to hold an ML value.
29 :     * Addr_t -- an unsigned integer that is large enough to hold an address.
30 :     */
31 :     #ifndef _ML_SIZES_
32 :     #include "ml-sizes.h"
33 :     #endif
34 :    
35 :     /* the size of a pair */
36 :     #define PAIR_SZB (2*WORD_SZB)
37 :     /* the number of Word_t's per double */
38 :     #define REALD_SZW (REALD_SZB / WORD_SZB)
39 :     /* the number of Word_t's per pair object */
40 :     #define PAIR_SZW 2
41 :     /* the number of Word_t's per special object */
42 :     #define SPECIAL_SZW 2
43 :    
44 :     /* convert a number of bytes to an even number of words */
45 :     #define BYTES_TO_WORDS(N) (((N)+(WORD_SZB-1)) >> LOG_BYTES_PER_WORD)
46 :    
47 :     /* convert a number of doubles to an even number of words */
48 :     #define DOUBLES_TO_WORDS(N) ((N) * REALD_SZW)
49 :    
50 :     /* on 32-bit machines it is useful to align doubles on 8-byte boundries */
51 :     #ifndef SIZES_C64_ML64
52 :     # define ALIGN_REALDS
53 :     #endif
54 :    
55 :    
56 :     #ifndef _ASM_
57 :    
58 :     #include <stdlib.h>
59 :    
60 :     #define PVT static
61 :    
62 :     typedef Int32_t bool_t;
63 :     #ifndef TRUE /* Some systems already define TRUE and FALSE */
64 :     # define TRUE 1
65 :     # define FALSE 0
66 :     #endif
67 :    
68 :     typedef Int32_t status_t;
69 :     #define SUCCESS 1
70 :     #define FAILURE 0
71 :    
72 :     /* nil pointers */
73 :     #define NIL(ty) ((ty)0)
74 :    
75 :     /* assertions for debugging */
76 :     #ifdef ASSERT_ON
77 :     extern void AssertFail (const char *a, const char *file, int line);
78 :     /* #define ASSERT(A) ((A) ? ((void)0) : AssertFail(#A, __FILE__, __LINE__)) */
79 :     #define ASSERT(A) { if (!(A)) AssertFail(#A, __FILE__, __LINE__); }
80 :     #else
81 :     #define ASSERT(A) { }
82 :     #endif
83 :    
84 :     /* Convert a bigendian 32-bit quantity into the host machine's representation. */
85 :     #if defined(BYTE_ORDER_BIG)
86 :     # define BIGENDIAN_TO_HOST(x) (x)
87 :     #elif defined(BYTE_ORDER_LITTLE)
88 :     extern Unsigned32_t SwapBytes (Unsigned32_t x);
89 :     # define BIGENDIAN_TO_HOST(x) SwapBytes(x)
90 :     #else
91 :     # error must define endianess
92 :     #endif
93 :    
94 :     /* round i up to the nearest multiple of n, where n is a power of 2 */
95 :     #define ROUNDUP(i, n) (((i)+((n)-1)) & ~((n)-1))
96 :    
97 :    
98 :     /* extract the bitfield of width WID starting at position POS from I */
99 :     #define XBITFIELD(I,POS,WID) (((I) >> (POS)) & ((1<<(WID))-1))
100 :    
101 :     /* aliases for malloc/free, so that we can easily replace them */
102 :     #define MALLOC(sz) malloc(sz)
103 :     #define _FREE free
104 :     #define FREE(p) _FREE(p)
105 :    
106 :     /* Allocate a new C object of type t. */
107 :     #define NEW_OBJ(t) ((t *)MALLOC(sizeof(t)))
108 :     /* Allocate a new C array of type t objects. */
109 :     #define NEW_VEC(t,n) ((t *)MALLOC((n)*sizeof(t)))
110 :    
111 :     /* clear memory */
112 :     #define CLEAR_MEM(m, sz) (memset((m), 0, (sz)))
113 :    
114 :     /* The size of a page in the BIBOP memory map (in bytes) */
115 :     #define BIBOP_PAGE_SZB ((Addr_t)(64*ONE_K))
116 :     #define RND_MEMOBJ_SZB(SZ) ROUNDUP(SZ,BIBOP_PAGE_SZB)
117 :    
118 :     /** C types used in the run-time system **/
119 :     #ifdef SIZES_C64_ML32
120 :     typedef Unsigned32_t ml_val_t;
121 :     #else
122 :     typedef struct { Word_t v[1]; } ml_object_t; /* something for an ml_val_t to point to */
123 :     typedef ml_object_t *ml_val_t;
124 :     #endif
125 :     typedef struct vproc_state vproc_state_t;
126 :     typedef struct ml_state ml_state_t;
127 :     typedef struct heap heap_t;
128 :    
129 :    
130 :     /* In C, system constants are usually integers. We represent these in the ML
131 :     * system as (int * string) pairs, where the integer is the C constant, and the
132 :     * string is a short version of the symbolic name used in C (e.g., the constant
133 :     * EINTR might be represented as (4, "INTR")).
134 :     */
135 :     typedef struct { /* The representation of system constants */
136 :     int id;
137 :     char *name;
138 :     } sys_const_t;
139 :    
140 :     typedef struct { /* a table of system constants. */
141 :     int numConsts;
142 :     sys_const_t *consts;
143 :     } sysconst_tbl_t;
144 :    
145 :    
146 :     /* run-time system messages */
147 :     extern void Say (char *fmt, ...);
148 :     extern void SayDebug (char *fmt, ...);
149 :     extern void Error (char *, ...);
150 :     extern void Exit (int code);
151 :     extern void Die (char *, ...);
152 :    
153 :     /* heap_params is an abstract type, whose representation depends on the
154 :     * particular GC being used.
155 :     */
156 :     typedef struct heap_params heap_params_t;
157 :    
158 :     extern heap_params_t *ParseHeapParams (char **argv);
159 :     extern ml_state_t *AllocMLState (bool_t isBoot, heap_params_t *params);
160 : blume 537 extern void BootML (const char *bootlist, heap_params_t *params);
161 : monnier 249 extern void LoadML (const char *loadImage, heap_params_t *params);
162 :    
163 :     extern bool_t QualifyImageName (char *buf);
164 :     extern void InitMLState (ml_state_t *msp);
165 :     extern void SaveCState (ml_state_t *msp, ...);
166 :     extern void RestoreCState (ml_state_t *msp, ...);
167 :     extern void InitTimers ();
168 :     extern void ResetTimers (vproc_state_t *vsp);
169 :     extern ml_val_t ApplyMLFn (ml_state_t *msp, ml_val_t f, ml_val_t arg, bool_t useCont);
170 :     extern void RunML (ml_state_t *msp);
171 :     extern void RaiseMLExn (ml_state_t *msp, ml_val_t exn);
172 :     extern void InitFaultHandlers ();
173 :    
174 :     #ifdef SOFT_POLL
175 :     extern void ResetPollLimit (ml_state_t *msp);
176 :     #endif
177 :    
178 :    
179 :     /* These are two views of the command line arguments; RawArgs is essentially
180 :     * argv[]. CmdLineArgs is argv[] with runtime system arguments stripped
181 :     * out (e.g., those of the form @SMLxxx[=yyy]).
182 :     */
183 :     extern char **RawArgs;
184 :     extern char **CmdLineArgs; /* does not include the command name (argv[0]) */
185 :     extern char *MLCmdName; /* the command name used to invoke the runtime */
186 :     extern bool_t SilentLoad;
187 :     extern bool_t DumpObjectStrings;
188 :     extern bool_t GCMessages;
189 :     #ifdef HACKED_STANDALONE
190 :     extern bool_t StandAlone;
191 :     #endif
192 :    
193 :     /* The table of virtual processor ML states */
194 :     extern vproc_state_t *VProc[];
195 :     extern int NumVProcs;
196 :    
197 :     #endif /* !_ASM_ */
198 :    
199 :     #endif /* !_ML_BASE_ */
200 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0