home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / microcode / sdata.h < prev    next >
Text File  |  1999-01-02  |  15KB  |  425 lines

  1. /* -*-C-*-
  2.  
  3. Copyright (c) 1987, 1988, 1989, 1999 Massachusetts Institute of Technology
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or (at
  8. your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /* $Id: sdata.h,v 9.34 1999/01/02 06:11:34 cph Exp $
  21.  *
  22.  * Description of the user data objects.  This should parallel the
  23.  * file SDATA.SCM in the runtime system.
  24.  *
  25.  */
  26.  
  27. /* Alphabetical order.  Every type of object is described either with a
  28.    comment or with offsets describing locations of various parts. */
  29.  
  30. /* ADDRESS
  31.  * is a FIXNUM.  It represents a 24-bit address.  Not a pointer type.
  32.  */
  33.  
  34. /* BIG_FIXNUM (bignum).
  35.  * See the file BIGNUM.C
  36.  */
  37.  
  38. /* BIG_FLONUM (flonum).
  39.  * Implementation dependent format (uses C data type "double").  Pointer
  40.  * to implemetation defined floating point format.
  41.  */
  42.  
  43. /* BROKEN_HEART.
  44.  * "Forwarding address" used by garbage collector to indicate that an
  45.  * object has been moved to a new location.  These should never be
  46.  * encountered by the interpreter!
  47.  */
  48.  
  49. /* CELL.
  50.  * An object that points to one other object (extra indirection).
  51.  * Used by the compiler to share objects.
  52.  */
  53. #define CELL_CONTENTS         0
  54.  
  55. /* CHARACTER
  56.  * Not currently used.  Intended ultimately to complete the abstraction
  57.  * of strings.  This will probably be removed eventually.
  58.  */
  59.  
  60. /* CHARACTER_STRING
  61.  * Synonym for 8B_VECTOR.  Used to store strings of characters.  Format
  62.  * consists of the normal non-marked vector header (STRING_HEADER)
  63.  * followed by the number of characters in the string (as a FIXNUM),
  64.  * followed by the characters themselves.
  65.  */
  66. #define STRING_HEADER        0
  67. #define STRING_LENGTH_INDEX    1
  68. #define STRING_CHARS        2
  69.  
  70. /* COMPILED_PROCEDURE */
  71. #define COMP_PROCEDURE_ADDRESS    0
  72. #define COMP_PROCEDURE_ENV    1
  73.  
  74. /* CONTINUATION
  75.  * Pushed on the control stack by the interpreter, each has two parts:
  76.  * the return address within the interpreter (represented as a type
  77.  * code RETURN_ADDRESS and address part RC_xxx), and an expression
  78.  * which was being evaluated at that time (sometimes just used as
  79.  * additional data needed at the return point).  The offsets given
  80.  * here are with respect to the stack pointer as it is located
  81.  * immediately after pushing a continuation (or, of course,
  82.  * immediately before popping it back).
  83.  *
  84.  * HISTORY_SIZE is the size of a RESTORE_HISTORY (or
  85.  * RESTORE_DONT_COPY_HISTORY) continuation.
  86.  */
  87.  
  88. #define CONTINUATION_EXPRESSION    1
  89. #define CONTINUATION_RETURN_CODE   0
  90. #define CONTINUATION_SIZE          2
  91. #define HISTORY_SIZE           (CONTINUATION_SIZE + 2)
  92.  
  93. /* CONTROL_POINT
  94.  * Points to a copy of the control stack at the time a control point is
  95.  * created.  This is the saved state of the interpreter, and can be
  96.  * restored later by APPLYing the control point to an argument (i.e. a
  97.  * throw).  Format is that of an ordinary vector.  They are linked
  98.  * together by using the return code RC_JOIN_STACKLETS.
  99.  */
  100.  
  101. /* If USE_STACKLETS is defined, then a stack (i.e. control point) is
  102.    actually made from smaller units allocated from the heap and linked
  103.    together.  The format is:
  104.  
  105.            0 memory address
  106.  
  107.              _______________________________________
  108.              |MAN. VECT.| n                        |
  109.            _ _______________________________________
  110.          /   | #T if it does not need to be copied |
  111.         |    _______________________________________
  112.         |    | NM VECT   | m  at GC or when full   |
  113.         |    _______________________________________
  114.         |    |               ...                   |\
  115.         |    |     not yet in use -- garbage       | > m
  116.      n <     _______________________________________/
  117.         |    | Top of Stack, useful contents       | <---Stack_Pointer
  118.         |    _______________________________________
  119.         \    |               ...                   |
  120.          \   |           useful stuff              |
  121.           \_ ________________________________________
  122.                                                      <---Stack_Top
  123.            infinite memory address
  124.  
  125. */
  126.  
  127. #define STACKLET_HEADER_SIZE        3
  128. #define STACKLET_LENGTH            0
  129. #define STACKLET_REUSE_FLAG        1
  130. #define STACKLET_UNUSED_LENGTH        2
  131.  
  132. /* Aliases */
  133. #define STACKLET_FREE_LIST_LINK        STACKLET_REUSE_FLAG
  134.  
  135. /* DELAYED
  136.  * The object returned by a DELAY operation.  Consists initially of a
  137.  * procedure to be APPLYed and environment.  After the FORCE primitive
  138.  * is applied to the object, the result is stored in the DELAYED object
  139.  * and further FORCEs return this same result.  I.e. FORCE memoizes the
  140.  * value of the DELAYED object.  For historical reasons, such an object
  141.  * is called a 'thunk.'
  142.  */
  143. #define THUNK_SNAPPED        0
  144. #define THUNK_VALUE        1
  145. #define THUNK_ENVIRONMENT    0
  146. #define THUNK_PROCEDURE        1
  147.  
  148. /* ENTITY
  149.    A cons of a procedure and something else.
  150.    When invoked, it invokes (tail recurses) into the procedure passing
  151.    the entity and the arguments to it.
  152.  */
  153.  
  154. #define ENTITY_OPERATOR        0
  155. #define ENTITY_DATA        1
  156.  
  157. /* ENVIRONMENT
  158.  * Associates identifiers with values.
  159.  * The identifiers are either from a lambda-binding (as in a procedure
  160.  * call) or a incremental (run-time) DEFINE (known as an 'auxilliary'
  161.  * binding).
  162.  * When an environment frame is created, it only contains lambda
  163.  * bindings.  If incremental defines are performed in it or its
  164.  * children, it acquires an extension which contains a list of the
  165.  * auxiliary bindings.  Some of these bindings are fictitious in that
  166.  * their only purpose is to make the real bindings (if and when they
  167.  * occur) become automatically dangerous.  Bindings become dangerous
  168.  * when they are shadowed by incremental bindings in children frames.
  169.  * Besides the lambda bindings, an environment frame contains a
  170.  * pointer to the procedure which created it.  It is through this
  171.  * procedure that the parent frame is found.
  172.  *
  173.  * An environment frame has three distinct stages in its formation:
  174.  * - A STACK_COMBINATION is the structure built on the stack to
  175.  * evaluate normal (long) combinations.  It contains a slot for the
  176.  * finger and the combination whose operands are being evaluated.
  177.  * Only some of the argument slots in a stack-combination are
  178.  * meaningful: those which have already been evaluated (those not
  179.  * "hidden" by the finger).  This is the first stage.
  180.  * - A STACK_ENVIRONMENT is the format used at Internal_Apply
  181.  * just as an application is about to occur.
  182.  * - An ENVIRONMENT is a real environment frame, containing
  183.  * associations between names and values.  It is the final stage, and
  184.  * corresponds to the structure described above.
  185.  */
  186.  
  187. #define ENVIRONMENT_HEADER    0
  188. #define ENVIRONMENT_FUNCTION    1
  189. #define ENVIRONMENT_FIRST_ARG    2
  190.  
  191. #define STACK_ENV_EXTRA_SLOTS   1
  192. #define STACK_ENV_HEADER        0
  193. #define STACK_ENV_FUNCTION      1
  194. #define STACK_ENV_FIRST_ARG     2
  195.  
  196. #define STACK_COMB_FINGER       0
  197. #define STACK_COMB_FIRST_ARG    1
  198.  
  199. /* An environment chain always ends in a pointer with type code
  200.    of GLOBAL_ENV.  This will contain an address part which
  201.    either indicates that the lookup should continue on to the
  202.    true global environment, or terminate at this frame.
  203.  
  204.    We arrange for the global environment to be the same as #F, and the
  205.    end chain to be different by toggling the lowest bit:
  206.  */
  207.  
  208. #define GLOBAL_ENV     (OBJECT_TYPE(SHARP_F))
  209. #define GO_TO_GLOBAL   (OBJECT_DATUM(SHARP_F))
  210. #define END_OF_CHAIN   ((GO_TO_GLOBAL) ^ 1)
  211.  
  212. /* Environment extension objects:
  213.  
  214.    These objects replace the procedure in environment frames when an
  215.    aux slot is desired.  The parent frame is copied into the extension
  216.    so that the "compiled" lookup code does not have to check whether
  217.    the frame has been extended or not.
  218.  
  219.    Note that for the code to work, ENV_EXTENSION_PARENT_FRAME must be
  220.    equal to PROCEDURE_ENVIRONMENT.
  221.  
  222.    The following constants are implicitely hard-coded in lookup.c,
  223.    where a new extension object is consed in extend_frame.
  224.  */
  225.  
  226. #define ENV_EXTENSION_HEADER        0
  227. #define ENV_EXTENSION_PARENT_FRAME    1
  228. #define ENV_EXTENSION_PROCEDURE        2
  229. #define ENV_EXTENSION_COUNT        3
  230. #define ENV_EXTENSION_MIN_SIZE        4
  231.  
  232. /* EXTENDED_FIXNUM
  233.  * Not used in the C version.  On the 68000 this is used for 24-bit
  234.  * integers, while FIXNUM is used for 16-bit integers.
  235.  */
  236.  
  237. /* EXTENDED_PROCEDURE
  238.  * Type of procedure created by evaluation of EXTENDED_LAMBDA.
  239.  * It's fields are the same as those for PROCEDURE.
  240.  */
  241.  
  242. /* FALSE
  243.  * Alternate name for NULL.  This is the type code of objects which are
  244.  * considered as false for the value of predicates.
  245.  */
  246.  
  247. /* FIXNUM
  248.  * Small integer.  Fits in the datum portion of a SCHEME_OBJECT.
  249.  */
  250.  
  251. /* HUNK3
  252.  * User object like a CONS, but with 3 slots rather than 2.
  253.  */
  254. #define HUNK3_CXR0        0
  255. #define HUNK3_CXR1        1
  256. #define HUNK3_CXR2        2
  257.  
  258. /* Old code uses these */
  259.  
  260. #define HUNK_CXR0        HUNK3_CXR0
  261. #define HUNK_CXR1        HUNK3_CXR1
  262. #define HUNK_CXR2        HUNK3_CXR2
  263.  
  264. /* INTERNED_SYMBOL
  265.  * A symbol, such as the result of evaluating (QUOTE A).  Some
  266.  * important properties of symbols are that they have a print name,
  267.  * and may be 'interned' so that all instances of a symbol with the
  268.  * same name share a unique object.  The storage pointed to by a
  269.  * symbol includes both the print name (a string) and the value cell
  270.  * associated with a variable of that name in the global environment.
  271.  */
  272. #define SYMBOL_NAME        0
  273. #define SYMBOL_GLOBAL_VALUE    1
  274.  
  275. /* LIST
  276.  * Ordinary CONS cell as supplied to a user.  Perhaps this data type is
  277.  * misnamed ... CONS or PAIR would be better.
  278.  */
  279. #define CONS_CAR        0
  280. #define CONS_CDR        1
  281.  
  282. /* MANIFEST_NM_VECTOR
  283.  * Not a true object, this type code is used to indicate the start of a
  284.  * vector which contains objects other than Scheme pointers.  The
  285.  * address portion indicates the number of cells of non-pointers
  286.  * which follow the header word.  For use primarily in garbage
  287.  * collection to indicate the number of words to copy but not trace.
  288.  */
  289.  
  290. /* MANIFEST_SPECIAL_NM_VECTOR Similar to MANIFEST_NM_VECTOR but the
  291.  * contents are relocated when loaded by the FALOADer.  This header
  292.  * occurs in pure and constant space to indicate the start of a region
  293.  * which contains Pointers to addresses which are known never to move in
  294.  * the operation of the system.
  295.  */
  296.  
  297. /* MANIFEST_VECTOR
  298.  * Synonym for NULL, used as first cell in a vector object to indicate
  299.  * how many cells it occupies.  Usage is similar to MANIFEST_NM_VECTOR
  300.  */
  301.  
  302. /* NON_MARKED_VECTOR
  303.  * User-visible object containing arbitrary bits.  Not currently used.
  304.  * The data portion will always point to a MANIFEST_NM_VECTOR or
  305.  * MANIFEST_SPECIAL_NM_VECTOR specifying the length of the vector.
  306.  */
  307. #define NM_VECTOR_HEADER    0
  308. #define NM_ENTRY_COUNT        1
  309. #define NM_DATA            2
  310. #define NM_HEADER_LENGTH    2
  311.  
  312. /* NULL
  313.  * The type code used by predicates to test for 'false' and by list
  314.  * operations for testing for the end of a list.
  315.  */
  316.  
  317. /* PRIMITIVE
  318.  * The data portion contains a number specifying a particular primitive
  319.  * operation to be performed.  An object of type PRIMITIVE can be
  320.  * APPLYed in the same way an object of type PROCEDURE can be.
  321.  */
  322.  
  323. /* PROCEDURE (formerly CLOSURE)
  324.  * Consists of two parts: a LAMBDA expression and the environment
  325.  * in which the LAMBDA was evaluated to yield the PROCEDURE.
  326.  */
  327. #define PROCEDURE_LAMBDA_EXPR    0
  328. #define PROCEDURE_ENVIRONMENT    1
  329.  
  330. /* QUAD or HUNK4
  331.  * Like a pair but with 4 components.
  332.  */
  333.  
  334. #define HUNK4_CXR0                0
  335. #define HUNK4_CXR1                1
  336. #define HUNK4_CXR2                2
  337. #define HUNK4_CXR3                3
  338.  
  339. /* REFERENCE_TRAP
  340.  * Causes the variable lookup code to trap.
  341.  * Used to implement a variety of features.
  342.  * This type code is really the collection of two, done this way for efficiency.
  343.  * Traps whose datum is less than TRAP_MAX_IMMEDIATE are immediate (not pointers).
  344.  * The rest are pairs.  The garbage collector deals with them specially.
  345.  */
  346.  
  347. #define TRAP_TAG                0
  348. #define TRAP_EXTRA                1
  349.  
  350. /* Traps can be extended for the use of the fast variable reference mechanism in
  351.  * compiled code.  The following is the format of a trap extension object.
  352.  */
  353.  
  354. #define TRAP_EXTENSION_CELL            HUNK4_CXR0
  355. #define TRAP_EXTENSION_NAME            HUNK4_CXR1
  356. #define TRAP_EXTENSION_CLONE            HUNK4_CXR2
  357. #define TRAP_EXTENSION_REFERENCES        HUNK4_CXR3
  358.  
  359. /* Aliases */
  360.  
  361. #define TRAP_EXTENSION_BLOCK            TRAP_EXTENSION_CLONE
  362. #define TRAP_EXTENSION_OFFSET            TRAP_EXTENSION_REFERENCES
  363.  
  364. #define TRAP_REFERENCES_LOOKUP            HUNK3_CXR0
  365. #define TRAP_REFERENCES_ASSIGNMENT        HUNK3_CXR1
  366. #define TRAP_REFERENCES_OPERATOR        HUNK3_CXR2
  367.  
  368. /* RETURN_CODE
  369.  * Represents an address where computation is to continue.  These can be
  370.  * thought of as states in a finite state machine, labels in an assembly
  371.  * language program, or continuations in a formal semantics.  When the
  372.  * interpretation of a single SCode item requires the EVALuation of a
  373.  * subproblem, a RETURN_CODE is left behind indicating where computation
  374.  * continues after the evaluation.
  375.  */
  376.  
  377. /* When in RC_MOVE_TO_ADJACENT_POINT in the interpreter, the following
  378.    information is available on the stack (placed there by
  379.    Translate_To_Point
  380. */
  381. #define TRANSLATE_FROM_POINT        0
  382. #define TRANSLATE_FROM_DISTANCE        1
  383. #define TRANSLATE_TO_POINT        2
  384. #define TRANSLATE_TO_DISTANCE        3
  385.  
  386. /* TRUE
  387.  * The initial binding of the variable T is to an object of this type.
  388.  * This type is the beginnings of a possible move toward a system where
  389.  * predicates check for TRUE / FALSE rather than not-NULL / NULL.
  390.  */
  391.  
  392. /* UNINTERNED_SYMBOL
  393.  * This indicates that the object is in the format of an INTERNED_SYMBOL
  394.  * but is not interned.
  395.  */
  396.  
  397. /* VECTOR
  398.  * A group of contiguous cells with a header (of type MANIFEST_VECTOR)
  399.  * indicating the length of the group.
  400.  */
  401. #define VECTOR_DATA        1
  402.  
  403. /* VECTOR_16B
  404.  * Points to a MANIFEST_NM_VECTOR or MANIFEST_SPECIAL_NM_VECTOR header.
  405.  * The format is described under NON_MARKED_VECTOR.  The contents are to
  406.  * be treated as an array of 16-bit signed or unsigned quantities.  Not
  407.  * currently used.
  408.  */
  409.  
  410. /* VECTOR_1B
  411.  * Similar to VECTOR_16B, but used for a compact representation of an
  412.  * array of booleans.
  413.  */
  414.  
  415. /* VECTOR_8B
  416.  * An alternate name of CHARACTER_STRING.
  417.  */
  418.  
  419. /* COMPLEX
  420.  * System Pair with REAL in CAR and IMAGINARY in CDR
  421.  */
  422.  
  423. #define COMPLEX_REAL        0
  424. #define COMPLEX_IMAG        1
  425.