1 /* -*-C-*- 2 3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 5 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Massachusetts 6 Institute of Technology 7 8 This file is part of MIT/GNU Scheme. 9 10 MIT/GNU Scheme is free software; you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation; either version 2 of the License, or (at 13 your option) any later version. 14 15 MIT/GNU Scheme is distributed in the hope that it will be useful, but 16 WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with MIT/GNU Scheme; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 23 USA. 24 25 */ 26 27 /* Description of the user data objects. This should parallel the 28 file SDATA.SCM in the runtime system. */ 29 30 #ifndef SCM_SDATA_H 31 #define SCM_SDATA_H 32 33 /* Alphabetical order. Every type of object is described either with a 34 comment or with offsets describing locations of various parts. */ 35 36 /* ADDRESS 37 * is a FIXNUM. It represents a 24-bit address. Not a pointer type. 38 */ 39 40 /* BIG_FIXNUM (bignum). 41 * See the file BIGNUM.C 42 */ 43 44 /* BIG_FLONUM (flonum). 45 * Implementation dependent format (uses C data type "double"). Pointer 46 * to implemetation defined floating point format. 47 */ 48 49 /* BROKEN_HEART. 50 * "Forwarding address" used by garbage collector to indicate that an 51 * object has been moved to a new location. These should never be 52 * encountered by the interpreter! 53 */ 54 55 /* CELL. 56 * An object that points to one other object (extra indirection). 57 * Used by the compiler to share objects. 58 */ 59 #define CELL_CONTENTS 0 60 61 /* CHARACTER 62 * Not currently used. Intended ultimately to complete the abstraction 63 * of strings. This will probably be removed eventually. 64 */ 65 66 /* CHARACTER_STRING 67 * Synonym for 8B_VECTOR. Used to store strings of characters. Format 68 * consists of the normal non-marked vector header (STRING_HEADER) 69 * followed by the number of characters in the string (as a FIXNUM), 70 * followed by the characters themselves. 71 */ 72 #define STRING_HEADER 0 73 #define STRING_LENGTH_INDEX 1 74 #define STRING_CHARS 2 75 76 /* COMPILED_PROCEDURE */ 77 #define COMP_PROCEDURE_ADDRESS 0 78 #define COMP_PROCEDURE_ENV 1 79 80 /* CONTINUATION 81 * Pushed on the control stack by the interpreter, each has two parts: 82 * the return address within the interpreter (represented as a type 83 * code RETURN_ADDRESS and address part RC_xxx), and an expression 84 * which was being evaluated at that time (sometimes just used as 85 * additional data needed at the return point). The offsets given 86 * here are with respect to the stack pointer as it is located 87 * immediately after pushing a continuation (or, of course, 88 * immediately before popping it back). 89 * 90 * HISTORY_SIZE is the size of a RESTORE_HISTORY (or 91 * RESTORE_DONT_COPY_HISTORY) continuation. 92 */ 93 94 #define CONTINUATION_EXPRESSION 1 95 #define CONTINUATION_RETURN_CODE 0 96 #define CONTINUATION_SIZE 2 97 #define HISTORY_SIZE (CONTINUATION_SIZE + 2) 98 99 /* DELAYED 100 * The object returned by a DELAY operation. Consists initially of a 101 * procedure to be APPLYed and environment. After the FORCE primitive 102 * is applied to the object, the result is stored in the DELAYED object 103 * and further FORCEs return this same result. I.e. FORCE memoizes the 104 * value of the DELAYED object. For historical reasons, such an object 105 * is called a 'thunk.' 106 */ 107 #define THUNK_SNAPPED 0 108 #define THUNK_VALUE 1 109 #define THUNK_ENVIRONMENT 0 110 #define THUNK_PROCEDURE 1 111 112 /* ENTITY 113 A cons of a procedure and something else. 114 When invoked, it invokes (tail recurses) into the procedure passing 115 the entity and the arguments to it. 116 */ 117 118 #define ENTITY_OPERATOR 0 119 #define ENTITY_DATA 1 120 121 /* ENVIRONMENT 122 * Associates identifiers with values. 123 * The identifiers are either from a lambda-binding (as in a procedure 124 * call) or a incremental (run-time) DEFINE (known as an 'auxilliary' 125 * binding). 126 * When an environment frame is created, it only contains lambda 127 * bindings. If incremental defines are performed in it or its 128 * children, it acquires an extension which contains a list of the 129 * auxiliary bindings. Some of these bindings are fictitious in that 130 * their only purpose is to make the real bindings (if and when they 131 * occur) become automatically dangerous. Bindings become dangerous 132 * when they are shadowed by incremental bindings in children frames. 133 * Besides the lambda bindings, an environment frame contains a 134 * pointer to the procedure which created it. It is through this 135 * procedure that the parent frame is found. 136 * 137 * An environment frame has three distinct stages in its formation: 138 * - A STACK_COMBINATION is the structure built on the stack to 139 * evaluate normal (long) combinations. It contains a slot for the 140 * finger and the combination whose operands are being evaluated. 141 * Only some of the argument slots in a stack-combination are 142 * meaningful: those which have already been evaluated (those not 143 * "hidden" by the finger). This is the first stage. 144 * - A STACK_ENVIRONMENT is the format used at Internal_Apply 145 * just as an application is about to occur. 146 * - An ENVIRONMENT is a real environment frame, containing 147 * associations between names and values. It is the final stage, and 148 * corresponds to the structure described above. 149 */ 150 151 #define ENVIRONMENT_HEADER 0 152 #define ENVIRONMENT_FUNCTION 1 153 #define ENVIRONMENT_FIRST_ARG 2 154 155 #define STACK_ENV_EXTRA_SLOTS 1 156 #define STACK_ENV_HEADER 0 157 #define STACK_ENV_FUNCTION 1 158 #define STACK_ENV_FIRST_ARG 2 159 160 #define STACK_COMB_FINGER 0 161 #define STACK_COMB_FIRST_ARG 1 162 163 /* An environment chain always ends in a pointer with type code 164 of GLOBAL_ENV. This will contain an address part which 165 either indicates that the lookup should continue on to the 166 true global environment, or terminate at this frame. 167 168 We arrange for the global environment to be the same as #F, and the 169 end chain to be different by toggling the lowest bit: */ 170 171 #define GLOBAL_ENV (OBJECT_TYPE (SHARP_F)) 172 #define THE_GLOBAL_ENV (MAKE_OBJECT (GLOBAL_ENV, (OBJECT_DATUM (SHARP_F)))) 173 #define THE_NULL_ENV (MAKE_OBJECT (GLOBAL_ENV, ((OBJECT_DATUM (SHARP_F)) ^ 1))) 174 175 #define GLOBAL_FRAME_P(frame) ((frame) == THE_GLOBAL_ENV) 176 #define NULL_FRAME_P(frame) ((frame) == THE_NULL_ENV) 177 #define PROCEDURE_FRAME_P(frame) ((OBJECT_TYPE (frame)) == TC_ENVIRONMENT) 178 179 #define GET_FRAME_PARENT(frame) \ 180 (GET_PROCEDURE_ENVIRONMENT (GET_FRAME_PROCEDURE (frame))) 181 182 #define GET_FRAME_PROCEDURE(frame) \ 183 (MEMORY_REF ((frame), ENVIRONMENT_FUNCTION)) 184 185 #define SET_FRAME_EXTENSION(frame, extension) \ 186 MEMORY_SET ((frame), ENVIRONMENT_FUNCTION, (extension)) 187 188 #define GET_FRAME_ARG_CELL(frame, index) \ 189 (MEMORY_LOC ((frame), (ENVIRONMENT_FIRST_ARG + (index)))) 190 191 /* Environment extension objects: 192 193 These objects replace the procedure in environment frames when an 194 aux slot is desired. The parent frame is copied into the extension 195 so that the "compiled" lookup code does not have to check whether 196 the frame has been extended or not. 197 198 Note that for the code to work, ENV_EXTENSION_PARENT_FRAME must be 199 equal to PROCEDURE_ENVIRONMENT. 200 201 The following constants are implicitely hard-coded in lookup.c, 202 where a new extension object is consed in extend_frame. 203 */ 204 205 #define ENV_EXTENSION_HEADER 0 206 #define ENV_EXTENSION_PARENT_FRAME 1 207 #define ENV_EXTENSION_PROCEDURE 2 208 #define ENV_EXTENSION_COUNT 3 209 #define ENV_EXTENSION_MIN_SIZE 4 210 211 #define EXTENDED_FRAME_P(frame) \ 212 (FRAME_EXTENSION_P (GET_FRAME_PROCEDURE (frame))) 213 214 #define FRAME_EXTENSION_P VECTOR_P 215 216 #define GET_EXTENDED_FRAME_BINDINGS(frame) \ 217 (GET_FRAME_EXTENSION_BINDINGS (GET_FRAME_PROCEDURE (frame))) 218 219 #define GET_FRAME_EXTENSION_BINDINGS(extension) \ 220 ((OBJECT_ADDRESS (extension)) + ENV_EXTENSION_MIN_SIZE) 221 222 #define GET_EXTENDED_FRAME_LENGTH(frame) \ 223 (GET_FRAME_EXTENSION_LENGTH (GET_FRAME_PROCEDURE (frame))) 224 225 #define GET_FRAME_EXTENSION_LENGTH(extension) \ 226 (UNSIGNED_FIXNUM_TO_LONG \ 227 ((OBJECT_ADDRESS (extension)) [ENV_EXTENSION_COUNT])) 228 229 #define SET_EXTENDED_FRAME_LENGTH(frame, length) \ 230 (SET_FRAME_EXTENSION_LENGTH ((GET_FRAME_PROCEDURE (frame)), (length))) 231 232 #define SET_FRAME_EXTENSION_LENGTH(extension, length) \ 233 (((OBJECT_ADDRESS (extension)) [ENV_EXTENSION_COUNT]) \ 234 = (LONG_TO_UNSIGNED_FIXNUM (length))) 235 236 #define GET_MAX_EXTENDED_FRAME_LENGTH(frame) \ 237 (GET_MAX_FRAME_EXTENSION_LENGTH (GET_FRAME_PROCEDURE (frame))) 238 239 #define GET_MAX_FRAME_EXTENSION_LENGTH(extension) \ 240 ((VECTOR_LENGTH (extension)) - (ENV_EXTENSION_MIN_SIZE - 1)) 241 242 #define GET_EXTENDED_FRAME_PROCEDURE(frame) \ 243 (GET_FRAME_EXTENSION_PROCEDURE (GET_FRAME_PROCEDURE (frame))) 244 245 #define GET_FRAME_EXTENSION_PROCEDURE(extension) \ 246 (MEMORY_REF ((extension), ENV_EXTENSION_PROCEDURE)) 247 248 #define SET_FRAME_EXTENSION_PROCEDURE(extension, procedure) \ 249 MEMORY_SET ((extension), ENV_EXTENSION_PROCEDURE, (procedure)) 250 251 #define SET_FRAME_EXTENSION_PARENT_FRAME(extension, frame) \ 252 MEMORY_SET ((extension), ENV_EXTENSION_PARENT_FRAME, (frame)) 253 254 /* EXTENDED_FIXNUM 255 * Not used in the C version. On the 68000 this is used for 24-bit 256 * integers, while FIXNUM is used for 16-bit integers. 257 */ 258 259 /* EXTENDED_PROCEDURE 260 * Type of procedure created by evaluation of EXTENDED_LAMBDA. 261 * It's fields are the same as those for PROCEDURE. 262 */ 263 264 /* FALSE 265 * Alternate name for NULL. This is the type code of objects which are 266 * considered as false for the value of predicates. 267 */ 268 269 /* FIXNUM 270 * Small integer. Fits in the datum portion of a SCHEME_OBJECT. 271 */ 272 273 /* HUNK3 274 * User object like a CONS, but with 3 slots rather than 2. 275 */ 276 #define HUNK3_CXR0 0 277 #define HUNK3_CXR1 1 278 #define HUNK3_CXR2 2 279 280 /* Old code uses these */ 281 282 #define HUNK_CXR0 HUNK3_CXR0 283 #define HUNK_CXR1 HUNK3_CXR1 284 #define HUNK_CXR2 HUNK3_CXR2 285 286 /* INTERNED_SYMBOL 287 * A symbol, such as the result of evaluating (QUOTE A). Some 288 * important properties of symbols are that they have a print name, 289 * and may be 'interned' so that all instances of a symbol with the 290 * same name share a unique object. The storage pointed to by a 291 * symbol includes both the print name (a string) and the value cell 292 * associated with a variable of that name in the global environment. 293 */ 294 #define SYMBOL_NAME 0 295 #define SYMBOL_GLOBAL_VALUE 1 296 297 #define SYMBOL_GLOBAL_VALUE_CELL(symbol) \ 298 (MEMORY_LOC ((symbol), SYMBOL_GLOBAL_VALUE)) 299 300 #define GET_SYMBOL_GLOBAL_VALUE(symbol) \ 301 (* (SYMBOL_GLOBAL_VALUE_CELL (symbol))) 302 303 #define SET_SYMBOL_GLOBAL_VALUE(symbol, value) \ 304 ((* (SYMBOL_GLOBAL_VALUE_CELL (symbol))) = (value)) 305 306 #define GET_SYMBOL_NAME(symbol) (MEMORY_REF ((symbol), SYMBOL_NAME)) 307 308 #define SET_SYMBOL_NAME(symbol, name) \ 309 MEMORY_SET ((symbol), SYMBOL_NAME, (name)) 310 311 /* LIST 312 * Ordinary CONS cell as supplied to a user. Perhaps this data type is 313 * misnamed ... CONS or PAIR would be better. 314 */ 315 #define CONS_CAR 0 316 #define CONS_CDR 1 317 318 /* MANIFEST_NM_VECTOR 319 * Not a true object, this type code is used to indicate the start of a 320 * vector which contains objects other than Scheme pointers. The 321 * address portion indicates the number of cells of non-pointers 322 * which follow the header word. For use primarily in garbage 323 * collection to indicate the number of words to copy but not trace. 324 */ 325 326 /* MANIFEST_SPECIAL_NM_VECTOR Similar to MANIFEST_NM_VECTOR but the 327 * contents are relocated when loaded by the FALOADer. This header 328 * occurs in pure and constant space to indicate the start of a region 329 * which contains Pointers to addresses which are known never to move in 330 * the operation of the system. 331 */ 332 333 /* MANIFEST_VECTOR 334 * Synonym for NULL, used as first cell in a vector object to indicate 335 * how many cells it occupies. Usage is similar to MANIFEST_NM_VECTOR 336 */ 337 338 /* NON_MARKED_VECTOR 339 * User-visible object containing arbitrary bits. Not currently used. 340 * The data portion will always point to a MANIFEST_NM_VECTOR or 341 * MANIFEST_SPECIAL_NM_VECTOR specifying the length of the vector. 342 */ 343 #define NM_VECTOR_HEADER 0 344 #define NM_ENTRY_COUNT 1 345 #define NM_DATA 2 346 #define NM_HEADER_LENGTH 2 347 348 /* NULL 349 * The type code used by predicates to test for 'false' and by list 350 * operations for testing for the end of a list. 351 */ 352 353 /* PRIMITIVE 354 * The data portion contains a number specifying a particular primitive 355 * operation to be performed. An object of type PRIMITIVE can be 356 * APPLYed in the same way an object of type PROCEDURE can be. 357 */ 358 359 /* PROCEDURE (formerly CLOSURE) 360 * Consists of two parts: a LAMBDA expression and the environment 361 * in which the LAMBDA was evaluated to yield the PROCEDURE. 362 */ 363 #define PROCEDURE_LAMBDA_EXPR 0 364 #define PROCEDURE_ENVIRONMENT 1 365 366 #define GET_PROCEDURE_LAMBDA(procedure) \ 367 (MEMORY_REF ((procedure), PROCEDURE_LAMBDA_EXPR)) 368 369 #define GET_PROCEDURE_ENVIRONMENT(procedure) \ 370 (MEMORY_REF ((procedure), PROCEDURE_ENVIRONMENT)) 371 372 /* QUAD or HUNK4 373 * Like a pair but with 4 components. 374 */ 375 376 #define HUNK4_CXR0 0 377 #define HUNK4_CXR1 1 378 #define HUNK4_CXR2 2 379 #define HUNK4_CXR3 3 380 381 /* REFERENCE_TRAP 382 * Causes the variable lookup code to trap. 383 * Used to implement a variety of features. 384 * This type code is really the collection of two, done this way for 385 * efficiency. Traps whose datum is less than TRAP_MAX_IMMEDIATE are 386 * immediate (not pointers). The rest are pairs. The garbage 387 * collector deals with them specially. */ 388 389 #define TRAP_TAG 0 390 #define TRAP_EXTRA 1 391 392 #define GET_TRAP_TAG(object) \ 393 (MEMORY_REF ((object), TRAP_TAG)) 394 395 #define GET_TRAP_EXTRA(object) \ 396 (MEMORY_REF ((object), TRAP_EXTRA)) 397 398 #define SET_TRAP_EXTRA(object, extra) \ 399 MEMORY_SET ((object), TRAP_EXTRA, (extra)) 400 401 #define GET_TRAP_CACHE GET_TRAP_EXTRA 402 #define SET_TRAP_CACHE SET_TRAP_EXTRA 403 404 #define CACHE_CELL HUNK3_CXR0 405 #define CACHE_CLONE HUNK3_CXR1 406 #define CACHE_REFERENCES HUNK3_CXR2 407 408 #define CACHE_REFERENCES_LOOKUP HUNK3_CXR0 409 #define CACHE_REFERENCES_ASSIGNMENT HUNK3_CXR1 410 #define CACHE_REFERENCES_OPERATOR HUNK3_CXR2 411 412 413 #define GET_CACHE_VALUE(cache) \ 414 (MEMORY_REF ((cache), CACHE_CELL)) 415 416 #define SET_CACHE_VALUE(cache, value) \ 417 MEMORY_SET ((cache), CACHE_CELL, (value)) 418 419 #define GET_CACHE_CLONE(cache) \ 420 (MEMORY_REF ((cache), CACHE_CLONE)) 421 422 #define SET_CACHE_CLONE(cache, clone) \ 423 MEMORY_SET ((cache), CACHE_CLONE, (clone)) 424 425 #define GET_CACHE_REFERENCES_OBJECT(cache) \ 426 (MEMORY_REF ((cache), CACHE_REFERENCES)) 427 428 429 #define GET_CACHE_REFERENCES(cache, kind) \ 430 (MEMORY_LOC ((GET_CACHE_REFERENCES_OBJECT (cache)), (kind))) 431 432 #define GET_CACHE_LOOKUP_REFERENCES(cache) \ 433 (GET_CACHE_REFERENCES ((cache), CACHE_REFERENCES_LOOKUP)) 434 435 #define GET_CACHE_ASSIGNMENT_REFERENCES(cache) \ 436 (GET_CACHE_REFERENCES ((cache), CACHE_REFERENCES_ASSIGNMENT)) 437 438 #define GET_CACHE_OPERATOR_REFERENCES(cache) \ 439 (GET_CACHE_REFERENCES ((cache), CACHE_REFERENCES_OPERATOR)) 440 441 442 #define GET_CACHE_REFERENCE_BLOCK(reference) \ 443 (PAIR_CAR (reference)) 444 445 #define SET_CACHE_REFERENCE_BLOCK(reference, block) \ 446 SET_PAIR_CAR (reference, block) 447 448 #define GET_CACHE_REFERENCE_OFFSET(reference) \ 449 (OBJECT_DATUM (PAIR_CDR (reference))) 450 451 #define SET_CACHE_REFERENCE_OFFSET(reference, offset) \ 452 (SET_PAIR_CDR ((reference), (LONG_TO_UNSIGNED_FIXNUM (offset)))) 453 454 /* RETURN_CODE 455 * Represents an address where computation is to continue. These can be 456 * thought of as states in a finite state machine, labels in an assembly 457 * language program, or continuations in a formal semantics. When the 458 * interpretation of a single SCode item requires the EVALuation of a 459 * subproblem, a RETURN_CODE is left behind indicating where computation 460 * continues after the evaluation. 461 */ 462 463 /* TRUE 464 * The initial binding of the variable T is to an object of this type. 465 * This type is the beginnings of a possible move toward a system where 466 * predicates check for TRUE / FALSE rather than not-NULL / NULL. 467 */ 468 469 /* UNINTERNED_SYMBOL 470 * This indicates that the object is in the format of an INTERNED_SYMBOL 471 * but is not interned. 472 */ 473 474 /* VECTOR 475 * A group of contiguous cells with a header (of type MANIFEST_VECTOR) 476 * indicating the length of the group. 477 */ 478 #define VECTOR_DATA 1 479 480 /* VECTOR_16B 481 * Points to a MANIFEST_NM_VECTOR or MANIFEST_SPECIAL_NM_VECTOR header. 482 * The format is described under NON_MARKED_VECTOR. The contents are to 483 * be treated as an array of 16-bit signed or unsigned quantities. Not 484 * currently used. 485 */ 486 487 /* VECTOR_1B 488 * Similar to VECTOR_16B, but used for a compact representation of an 489 * array of booleans. 490 */ 491 492 /* VECTOR_8B 493 * An alternate name of CHARACTER_STRING. 494 */ 495 496 /* COMPLEX 497 * System Pair with REAL in CAR and IMAGINARY in CDR 498 */ 499 500 #define COMPLEX_REAL 0 501 #define COMPLEX_IMAG 1 502 503 /* EPHEMERON 504 * Similar to a weak pair, but the datum is weakly referenced too. The 505 * key and datum are simultaneously dropped iff the only references to 506 * the key go through the datum. Every ephemeron has extra slots for 507 * data structures that the garbage collector needs to implement this, 508 * so that the garbage collector need not allocate auxiliary storage. 509 */ 510 511 #define EPHEMERON_MANIFEST 0 512 #define EPHEMERON_KEY 1 513 #define EPHEMERON_DATUM 2 514 #define EPHEMERON_LIST 3 515 #define EPHEMERON_NEXT 4 516 517 #define EPHEMERON_SIZE 5 518 519 #define MARKED_EPHEMERON_MANIFEST \ 520 (MAKE_OBJECT (TC_MANIFEST_VECTOR, (EPHEMERON_SIZE - 1))) 521 522 #define UNMARKED_EPHEMERON_MANIFEST \ 523 (MAKE_OBJECT (TC_MANIFEST_NM_VECTOR, (EPHEMERON_SIZE - 1))) 524 525 #endif /* not SCM_SDATA_H */ 526