119370Spst/* This is a minimally edited version of Guile's tags.h. */
219370Spst/* classes: h_files */
319370Spst
419370Spst#ifndef TAGSH
519370Spst#define TAGSH
698944Sobrien/*      Copyright 1995, 1999 Free Software Foundation, Inc.
798944Sobrien
819370Spst * This program is free software; you can redistribute it and/or modify
919370Spst * it under the terms of the GNU General Public License as published by
1019370Spst * the Free Software Foundation; either version 2, or (at your option)
1119370Spst * any later version.
1219370Spst *
1319370Spst * This program is distributed in the hope that it will be useful,
1419370Spst * but WITHOUT ANY WARRANTY; without even the implied warranty of
1519370Spst * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1619370Spst * GNU General Public License for more details.
1719370Spst *
1819370Spst * You should have received a copy of the GNU General Public License
1946283Sdfr * along with this program; if not, write to the Free Software
2046283Sdfr * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2119370Spst *
2219370Spst * As a special exception, the Free Software Foundation gives permission
2319370Spst * for additional uses of the text contained in its release of GUILE.
2419370Spst *
2519370Spst * The exception is that, if you link the GUILE library with other files
2619370Spst * to produce an executable, this does not by itself cause the
2719370Spst * resulting executable to be covered by the GNU General Public License.
2819370Spst * Your use of that executable is in no way restricted on account of
2919370Spst * linking the GUILE library code into it.
3019370Spst *
3119370Spst * This exception does not however invalidate any other reasons why
3219370Spst * the executable file might be covered by the GNU General Public License.
3319370Spst *
3419370Spst * This exception applies only to the code released by the
3519370Spst * Free Software Foundation under the name GUILE.  If you copy
3619370Spst * code from other Free Software Foundation releases into a copy of
3719370Spst * GUILE, as the General Public License permits, the exception does
3819370Spst * not apply to the code that you add in this way.  To avoid misleading
3919370Spst * anyone as to the status of such modified files, you must delete
4019370Spst * this exception notice from them.
4119370Spst *
4219370Spst * If you write modifications of your own for GUILE, it is your choice
4319370Spst * whether to permit this exception to apply to your modifications.
4419370Spst * If you do not wish that, delete this exception notice.
4519370Spst */
4619370Spst
4719370Spst
4819370Spst/** This file defines the format of SCM values and cons pairs.
4919370Spst ** It is here that tag bits are assigned for various purposes.
5019370Spst **/
5198944Sobrien
5219370Spst
5319370Spst/* Three Bit Tags
5498944Sobrien
5519370Spst * 000 -- a non-immediate value.  Points into the pair heap.
5619370Spst *
5719370Spst * 001 -- a gloc (i.e., a resolved global variable in a CAR in a code graph)
5898944Sobrien *        or the CAR of an object handle (i.e., the tagged pointer to the
5998944Sobrien *        vtable part of a user-defined object).
6019370Spst *
6119370Spst *        If X has this tag, the value at CDAR(X - 1) distinguishes
6298944Sobrien *        glocs from object handles.  The distinction only needs
6398944Sobrien *        to be made in a few places.  Only a few parts of the code know
6498944Sobrien *        about glocs.  In most cases, when a value in the CAR of a pair
6598944Sobrien *        has the tag 001, it means that the pair is an object handle.
6619370Spst *
6719370Spst * 010 -- the tag for immediate, exact integers.
6819370Spst *
6919370Spst * 011 -- in the CAR of a pair, this tag indicates that the pair is a closure.
7098944Sobrien *        The remaining bits of the CAR are a pointer into the pair heap
7198944Sobrien *        to the code graph for the closure.
7219370Spst *
7319370Spst * 1xy -- an extension tag which means that there is a five or six bit
7498944Sobrien *        tag to the left of the low three bits.  See the nice diagrams
7598944Sobrien *        in ../doc/code.doc if you want to know what the bits mean.
7619370Spst */
7719370Spst
7819370Spst
7919370Spst
8019370Spst
8198944Sobrien
8219370Spst#define scm_tc3_cons		0
8319370Spst#define scm_tc3_cons_gloc	1
8419370Spst#define scm_tc3_closure		3
8519370Spst
8619370Spst#define scm_tc7_ssymbol		5
8719370Spst#define scm_tc7_msymbol		7
8819370Spst#define scm_tc7_string		13
8919370Spst#define scm_tc7_bvect		15
9019370Spst#define scm_tc7_vector		21
9119370Spst#define scm_tc7_lvector		23
9219370Spst#define scm_tc7_ivect		29
9319370Spst#define scm_tc7_uvect		31
9419370Spst/* spare 37 39 */
9519370Spst#define scm_tc7_fvect		45
9619370Spst#define scm_tc7_dvect		47
9719370Spst#define scm_tc7_cvect		53
9819370Spst#define scm_tc7_port		55
9919370Spst#define scm_tc7_contin		61
10019370Spst#define scm_tc7_cclo		63
10119370Spst/* spare 69 71 77 79 */
10219370Spst#define scm_tc7_subr_0		85
10319370Spst#define scm_tc7_subr_1		87
10419370Spst#define scm_tc7_cxr		93
10519370Spst#define scm_tc7_subr_3		95
10619370Spst#define scm_tc7_subr_2		101
10719370Spst#define scm_tc7_asubr		103
10819370Spst#define scm_tc7_subr_1o		109
10919370Spst#define scm_tc7_subr_2o		111
11019370Spst#define scm_tc7_lsubr_2		117
11119370Spst#define scm_tc7_lsubr		119
11219370Spst#define scm_tc7_rpsubr		125
11319370Spst
11419370Spst#define scm_tc7_smob		127
11519370Spst#define scm_tc_free_cell	127
11619370Spst
11719370Spst#define scm_tc16_flo		0x017f
11819370Spst#define scm_tc_flo		0x017fL
11919370Spst
12019370Spst#define SCM_REAL_PART		(1L<<16)
12119370Spst#define SCM_IMAG_PART		(2L<<16)
12219370Spst#define scm_tc_dblr		(scm_tc16_flo|REAL_PART)
12319370Spst#define scm_tc_dblc		(scm_tc16_flo|REAL_PART|IMAG_PART)
12419370Spst
12519370Spst#define scm_tc16_bigpos		0x027f
12619370Spst#define scm_tc16_bigneg		0x037f
12719370Spst
12819370Spst#define scm_tc16_fport 		(scm_tc7_port + 0*256L)
12919370Spst#define scm_tc16_pipe 		(scm_tc7_port + 1*256L)
13019370Spst#define scm_tc16_strport	(scm_tc7_port + 2*256L)
13119370Spst#define scm_tc16_sfport 	(scm_tc7_port + 3*256L)
13219370Spst
13319370Spst
13419370Spst
13519370Spst/* For cons pairs with immediate values in the CAR */
13619370Spst#define scm_tcs_cons_imcar 2:case 4:case 6:case 10:\
13719370Spst case 12:case 14:case 18:case 20:\
13819370Spst case 22:case 26:case 28:case 30:\
13919370Spst case 34:case 36:case 38:case 42:\
14019370Spst case 44:case 46:case 50:case 52:\
14119370Spst case 54:case 58:case 60:case 62:\
14219370Spst case 66:case 68:case 70:case 74:\
14319370Spst case 76:case 78:case 82:case 84:\
14419370Spst case 86:case 90:case 92:case 94:\
14519370Spst case 98:case 100:case 102:case 106:\
14619370Spst case 108:case 110:case 114:case 116:\
14719370Spst case 118:case 122:case 124:case 126
14819370Spst
14919370Spst/* For cons pairs with non-immediate values in the CAR */
15019370Spst#define scm_tcs_cons_nimcar 0:case 8:case 16:case 24:\
15119370Spst case 32:case 40:case 48:case 56:\
15219370Spst case 64:case 72:case 80:case 88:\
15319370Spst case 96:case 104:case 112:case 120
15419370Spst
15519370Spst/* A CONS_GLOC occurs in code.  It's CAR is a pointer to the
15619370Spst * CDR of a variable.  The low order bits of the CAR are 001.
15719370Spst * The CDR of the gloc is the code continuation.
15819370Spst */
15919370Spst#define scm_tcs_cons_gloc 1:case 9:case 17:case 25:\
16019370Spst case 33:case 41:case 49:case 57:\
16119370Spst case 65:case 73:case 81:case 89:\
16219370Spst case 97:case 105:case 113:case 121
16319370Spst
16419370Spst#define scm_tcs_closures   3:case 11:case 19:case 27:\
16519370Spst case 35:case 43:case 51:case 59:\
16619370Spst case 67:case 75:case 83:case 91:\
16719370Spst case 99:case 107:case 115:case 123
16819370Spst
16919370Spst#define scm_tcs_subrs scm_tc7_asubr:case scm_tc7_subr_0:case scm_tc7_subr_1:case scm_tc7_cxr:\
17019370Spst case scm_tc7_subr_3:case scm_tc7_subr_2:case scm_tc7_rpsubr:case scm_tc7_subr_1o:\
17119370Spst case scm_tc7_subr_2o:case scm_tc7_lsubr_2:case scm_tc7_lsubr
17219370Spst
17319370Spst#define scm_tcs_symbols scm_tc7_ssymbol:case scm_tc7_msymbol
17419370Spst
17519370Spst#define scm_tcs_bignums tc16_bigpos:case tc16_bigneg
17619370Spst
17719370Spst
17898944Sobrien
17919370Spst/* References to objects are of type SCM.  Values may be non-immediate
18019370Spst * (pointers) or immediate (encoded, immutable, scalar values that fit
18119370Spst * in an SCM variable).
18219370Spst */
18319370Spst
18419370Spsttypedef long SCM;
18519370Spst
18619370Spst/* Cray machines have pointers that are incremented once for each word,
18719370Spst * rather than each byte, the 3 most significant bits encode the byte
18819370Spst * within the word.  The following macros deal with this by storing the
18919370Spst * native Cray pointers like the ones that looks like scm expects.  This
19019370Spst * is done for any pointers that might appear in the car of a scm_cell, pointers
19119370Spst * to scm_vector elts, functions, &c are not munged.
19219370Spst */
19319370Spst#ifdef _UNICOS
19498944Sobrien#define SCM2PTR(x) ((int)(x) >> 3)
19598944Sobrien#define PTR2SCM(x) (((SCM)(x)) << 3)
19698944Sobrien#define SCM_POINTERS_MUNGED
19719370Spst#else
19898944Sobrien#define SCM2PTR(x) (x)
19998944Sobrien#define PTR2SCM(x) ((SCM)(x))
20019370Spst#endif /* def _UNICOS */
20119370Spst
20219370Spst
20398944Sobrien
20419370Spst/* Immediate? Predicates
20519370Spst */
20619370Spst#define SCM_IMP(x) 	(6 & (int)(x))
20719370Spst#define SCM_NIMP(x) 	(!SCM_IMP(x))
20819370Spst
20919370Spst
21098944Sobrien
21119370Spstenum scm_tags
21298944Sobrien  {
21398944Sobrien    scm_tc8_char = 0xf4
21498944Sobrien  };
21519370Spst
21619370Spst#define SCM_ITAG8(X)		((int)(X) & 0xff)
21719370Spst#define SCM_MAKE_ITAG8(X, TAG)	(((X)<<8) + TAG)
21819370Spst#define SCM_ITAG8_DATA(X)	((X)>>8)
21998944Sobrien
22019370Spst
22119370Spst
22219370Spst/* Local Environment Structure
22319370Spst */
22419370Spst#define SCM_ILOCP(n)		((0xff & (int)(n))==0xfc)
22519370Spst#define SCM_ILOC00		(0x000000fcL)
22619370Spst#define SCM_IDINC		(0x00100000L)
22719370Spst#define SCM_ICDR		(0x00080000L)
22819370Spst#define SCM_IFRINC		(0x00000100L)
22919370Spst#define SCM_IDSTMSK		(-SCM_IDINC)
23019370Spst#define SCM_IFRAME(n) 		((int)((SCM_ICDR-SCM_IFRINC)>>8) & ((int)(n)>>8))
23119370Spst#define SCM_IDIST(n) 		(((unsigned long)(n))>>20)
23219370Spst#define SCM_ICDRP(n) 		(SCM_ICDR & (n))
23398944Sobrien
23419370Spst
23519370Spst/* Immediate Symbols, Special Symbols, Flags (various constants).
23619370Spst */
23719370Spst
23819370Spst/* ISYMP tests for ISPCSYM and ISYM */
23919370Spst#define SCM_ISYMP(n) 		((0x187 & (int)(n))==4)
24019370Spst
24119370Spst/* IFLAGP tests for ISPCSYM, ISYM and IFLAG */
24219370Spst#define SCM_IFLAGP(n) 		((0x87 & (int)(n))==4)
24319370Spst#define SCM_ISYMNUM(n) 		((int)((n)>>9))
24419370Spst#define SCM_ISYMCHARS(n) 	(scm_isymnames[SCM_ISYMNUM(n)])
24519370Spst#define SCM_MAKSPCSYM(n) 	(((n)<<9)+((n)<<3)+4L)
24619370Spst#define SCM_MAKISYM(n) 		(((n)<<9)+0x74L)
24719370Spst#define SCM_MAKIFLAG(n) 	(((n)<<9)+0x174L)
24819370Spst
24919370Spst/* This table must agree with the declarations
25019370Spst * in repl.c: {Names of immediate symbols}.
25119370Spst *
25219370Spst * These are used only in eval but their values
25319370Spst * have to be allocated here.
25419370Spst *
25519370Spst */
25619370Spst
25719370Spst#define SCM_IM_AND		SCM_MAKSPCSYM(0)
25819370Spst#define SCM_IM_BEGIN		SCM_MAKSPCSYM(1)
25919370Spst#define SCM_IM_CASE		SCM_MAKSPCSYM(2)
26019370Spst#define SCM_IM_COND		SCM_MAKSPCSYM(3)
26119370Spst#define SCM_IM_DO		SCM_MAKSPCSYM(4)
26219370Spst#define SCM_IM_IF		SCM_MAKSPCSYM(5)
26319370Spst#define SCM_IM_LAMBDA		SCM_MAKSPCSYM(6)
26419370Spst#define SCM_IM_LET		SCM_MAKSPCSYM(7)
26519370Spst#define SCM_IM_LETSTAR		SCM_MAKSPCSYM(8)
26619370Spst#define SCM_IM_LETREC		SCM_MAKSPCSYM(9)
26719370Spst#define SCM_IM_OR		SCM_MAKSPCSYM(10)
26819370Spst#define SCM_IM_QUOTE		SCM_MAKSPCSYM(11)
26919370Spst#define SCM_IM_SET		SCM_MAKSPCSYM(12)
27019370Spst#define SCM_IM_DEFINE		SCM_MAKSPCSYM(13)
27119370Spst#define SCM_IM_APPLY		SCM_MAKISYM(14)
27219370Spst#define SCM_IM_CONT		SCM_MAKISYM(15)
27319370Spst#define SCM_NUM_ISYMS 16
27419370Spst
27519370Spst/* Important immediates
27619370Spst */
27719370Spst
27819370Spst#define SCM_BOOL_F		SCM_MAKIFLAG(SCM_NUM_ISYMS+0)
27919370Spst#define SCM_BOOL_T 		SCM_MAKIFLAG(SCM_NUM_ISYMS+1)
28019370Spst#define SCM_UNDEFINED	 	SCM_MAKIFLAG(SCM_NUM_ISYMS+2)
28119370Spst#define SCM_EOF_VAL 		SCM_MAKIFLAG(SCM_NUM_ISYMS+3)
28219370Spst
28319370Spst#ifdef SICP
28419370Spst#define SCM_EOL 		SCM_BOOL_F
28519370Spst#else
28619370Spst#define SCM_EOL			SCM_MAKIFLAG(SCM_NUM_ISYMS+4)
28719370Spst#endif
28819370Spst
28919370Spst#define SCM_UNSPECIFIED		SCM_MAKIFLAG(SCM_NUM_ISYMS+5)
29019370Spst
29119370Spst
29298944Sobrien
29319370Spst/* Heap Pairs and the Empty List Predicates
29419370Spst */
29519370Spst#define SCM_NULLP(x) 	(SCM_EOL == (x))
29619370Spst#define SCM_NNULLP(x) 	(SCM_EOL != (x))
29719370Spst#define SCM_CELLP(x) 	(!SCM_NCELLP(x))
29819370Spst#define SCM_NCELLP(x) 	((sizeof(scm_cell)-1) & (int)(x))
29998944Sobrien
30019370Spst
30119370Spst
30219370Spst#define SCM_UNBNDP(x) 	(SCM_UNDEFINED==(x))
30319370Spst
30419370Spst
30598944Sobrien
30619370Spst/* Testing and Changing GC Marks in Various Standard Positions
30719370Spst */
30819370Spst#define SCM_GCMARKP(x) 		(1 & (int)SCM_CDR(x))
30919370Spst#define SCM_GC8MARKP(x) 	(0x80 & (int)SCM_CAR(x))
31019370Spst#define SCM_SETGCMARK(x) 	(SCM_CDR(x) |= 1)
31119370Spst#define SCM_CLRGCMARK(x) 	(SCM_CDR(x) &= ~1L)
31219370Spst#define SCM_SETGC8MARK(x) 	(SCM_CAR(x) |= 0x80)
31319370Spst#define SCM_CLRGC8MARK(x) 	(SCM_CAR(x) &= ~0x80L)
31498944Sobrien
31519370Spst
31619370Spst/* Extracting Tag Bits, With or Without GC Safety and Optional Bits
31719370Spst */
31819370Spst#define SCM_TYP3(x) 		(7 & (int)SCM_CAR(x))
31919370Spst#define SCM_TYP7(x) 		(0x7f & (int)SCM_CAR(x))
32019370Spst#define SCM_TYP7S(x) 		(0x7d & (int)SCM_CAR(x))
32119370Spst#define SCM_TYP16(x) 		(0xffff & (int)SCM_CAR(x))
32219370Spst#define SCM_TYP16S(x) 		(0xfeff & (int)SCM_CAR(x))
32319370Spst#define SCM_GCTYP16(x) 		(0xff7f & (int)SCM_CAR(x))
32498944Sobrien
32519370Spst
32619370Spst/* Two slightly extensible types: smobs and ptobs.
32798944Sobrien
32819370Spst */
32919370Spst#define SCM_SMOBNUM(x) (0x0ff & (CAR(x)>>8));
33019370Spst#define SCM_PTOBNUM(x) (0x0ff & (CAR(x)>>8));
33198944Sobrien
33219370Spst
33319370Spst
33419370Spst
33519370Spst#define SCM_DIRP(x) (SCM_NIMP(x) && (TYP16(x)==(scm_tc16_dir)))
33619370Spst#define SCM_OPDIRP(x) (SCM_NIMP(x) && (CAR(x)==(scm_tc16_dir | OPN)))
33719370Spst
33819370Spst
33998944Sobrien
34019370Spst/* Lvectors
34119370Spst */
34219370Spst#define SCM_LVECTORP(x) (TYP7(x)==tc7_lvector)
34398944Sobrien
34419370Spst
34519370Spst#if 0
34619370Spst
34719370Spst/* Sockets
34819370Spst */
34919370Spst#define tc_socket (tc7_port | OPN)
35019370Spst#define SCM_SOCKP(x) (((0x7f | OPN | RDNG | WRTNG) & CAR(x))==(tc_socket))
35119370Spst#define SCM_SOCKTYP(x) (CAR(x)>>24)
35219370Spst
35319370Spst
35498944Sobrien
35519370Spstextern int scm_tc16_key_vector;
35619370Spst#define SCM_KEYVECP(X)   (scm_tc16_key_vector == TYP16 (X))
35719370Spst#define SCM_KEYVECLEN(OBJ) (((unsigned long)CAR (obj)) >> 16)
35898944Sobrien
35919370Spst
36019370Spst#define SCM_MALLOCDATA(obj) ((char *)CDR(obj))
36119370Spst#define SCM_MALLOCLEN(obj) (((unsigned long)CAR (obj)) >> 16)
36219370Spst#define SCM_WORDDATA(obj)  (CDR (obj))
36319370Spst
36419370Spst
36519370Spst#define SCM_BYTECODEP(X) ((TYP7 (X) == tc7_cclo) && (CCLO_SUBR (X) == rb_proc))
36619370Spst#define SCM_BYTECODE_CONSTANTS(X) (VELTS(X)[1])
36719370Spst#define SCM_BYTECODE_CODE(X) (VELTS(X)[2])
36819370Spst#define SCM_BYTECODE_NAME(X) (VELTS(X)[3])
36919370Spst#define SCM_BYTECODE_BCODE(X) (VELTS(X)[4])
37019370Spst#define SCM_BYTECODE_ELTS 5
37198944Sobrien
37219370Spst
37319370Spst#define SCM_FREEP(x) (CAR(x)==tc_free_cell)
37419370Spst#define SCM_NFREEP(x) (!FREEP(x))
37519370Spst
37698944Sobrien#endif /* 0 */
37719370Spst
37819370Spst
37998944Sobrien#endif /* TAGSH */
380