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 #ifndef SCM_TRAP_H
28 #define SCM_TRAP_H 1
29 
30 /* Kinds of traps:
31 
32    For efficiency, some traps are immediate, while some are
33    pointer objects.  The type code is multiplexed, and the
34    garbage collector handles it specially.
35 
36    The odd-numbered traps used to be "dangerous" versions of the
37    even-numbered ones, but all that complexity has been flushed.  */
38 
39 typedef unsigned long trap_kind_t;
40 
41 /* The following are immediate traps: */
42 #define TRAP_UNASSIGNED				0
43 #define TRAP_UNBOUND				2
44 #define TRAP_EXPENSIVE				6
45 /* TRAP_MAX_IMMEDIATE is defined in object.h */
46 
47 /* The following are non-immediate traps: */
48 #define TRAP_COMPILER_CACHED			14
49 #define TRAP_MACRO				15
50 
51 /* Usages of the above traps:
52    TRAP_UNASSIGNED can appear in a value cell or a cache.
53    TRAP_UNBOUND can appear in the following locations:
54      * The value cell of a global variable.  All symbols initially
55        have their value cell set to UNBOUND_OBJECT.
56      * A cache that is in the value cell of a global variable.  This
57        is like the previous case except that some compiled code has
58        referenced the unbound variable.
59      * The value cell of a procedure's argument frame.  This is caused
60        by calling unbind_variable on a procedure's argument.
61      * A cache that is not stored in an environment.  This is caused
62        by referring to an unbound variable in an environment that does
63        not inherit from the global environment.
64    TRAP_EXPENSIVE can only appear in a "clone" cache.  This causes
65      assignments to this cache to trap out to the microcode, where the
66      updating of the variable's associated UUO links can be performed.
67    TRAP_COMPILER_CACHED can only appear in a value cell.  It is used
68      to associate a cache with the variable.
69    TRAP_MACRO can appear in a value cell or a cache.  It is used for
70    storage of macro transformers in the environment structure.
71 */
72 
73 /* The following never appear in value cells.  */
74 /* NON_TRAP_KIND is returned by get_trap_kind when its argument is not
75    a reference trap object.  */
76 #define NON_TRAP_KIND				32
77 
78 /* The garbage collector knows that pointers of type CACHE_TYPE point
79    to three words of storage, because these pointers are embedded in
80    compiled-code linkage sections (TC_LINKAGE_SECTION) without types.
81    */
82 #define CACHE_TYPE				TC_HUNK3
83 #define CACHE_REFERENCES_TYPE			TC_HUNK3
84 
85 #if (SIZEOF_UNSIGNED_LONG == 4)	/* 32 bit objects */
86 #  if (TYPE_CODE_LENGTH == 8)
87 #    define UNASSIGNED_OBJECT	0x32000000
88 #    define UNBOUND_OBJECT	0x32000002
89 #    define EXPENSIVE_OBJECT	0x32000006
90 #  endif
91 #  if (TYPE_CODE_LENGTH == 6)
92 #    define UNASSIGNED_OBJECT	0xc8000000
93 #    define UNBOUND_OBJECT	0xc8000002
94 #    define EXPENSIVE_OBJECT	0xc8000006
95 #  endif
96 #  if (TC_REFERENCE_TRAP != 0x32)
97 #    include "error: trap.h and types.h are inconsistent"
98 #  endif
99 #endif
100 
101 #ifndef UNASSIGNED_OBJECT	/* Safe version */
102 #  define UNASSIGNED_OBJECT (MAKE_OBJECT (TC_REFERENCE_TRAP, TRAP_UNASSIGNED))
103 #  define UNBOUND_OBJECT    (MAKE_OBJECT (TC_REFERENCE_TRAP, TRAP_UNBOUND))
104 #  define EXPENSIVE_OBJECT  (MAKE_OBJECT (TC_REFERENCE_TRAP, TRAP_EXPENSIVE))
105 #endif
106 
107 #endif /* not SCM_TRAP_H */
108