source: trunk/source/lisp-kernel/macros.h @ 10883

Last change on this file since 10883 was 10883, checked in by gb, 12 years ago

*printf format strings specify the width of their integer arguments (as
signed/unsigned "long", "long long", etc.) Since 64-bit Windows defines
"long" as a 32-bit integer, we have to use "long long" (e.g., "%llx") to
print a lisp object successfully, but printing a 32-bit lisp pointer
as a "long long" may print at least 32 bits of garbage ... Define
a few constants based on word size, and use implicit concatenation of
adjacent C string constants to hide this.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/*
2   Copyright (C) 1994-2001 Digitool, Inc
3   This file is part of OpenMCL. 
4
5   OpenMCL is licensed under the terms of the Lisp Lesser GNU Public
6   License , known as the LLGPL and distributed with OpenMCL as the
7   file "LICENSE".  The LLGPL consists of a preamble and the LGPL,
8   which is distributed with OpenMCL as the file "LGPL".  Where these
9   conflict, the preamble takes precedence. 
10
11   OpenMCL is referenced in the preamble as the "LIBRARY."
12
13   The LLGPL is also available online at
14   http://opensource.franz.com/preamble.html
15*/
16
17/* Totally different content than 'macros.s' */
18
19
20
21#ifndef __macros__
22#define __macros__
23
24#define ptr_to_lispobj(p) ((LispObj)(p))
25#define ptr_from_lispobj(o) ((LispObj*)(o))
26#define lisp_reg_p(reg)  ((reg) >= fn)
27
28#define fulltag_of(o)  ((o) & fulltagmask)
29#define tag_of(o) ((o) & tagmask)
30#define untag(o) ((o) & ~fulltagmask)
31#define node_aligned(o) ((o) & ~tagmask)
32#define indirect_node(o) (*(LispObj *)(node_aligned(o)))
33
34#define deref(o,n) ((((LispObj*) (untag((LispObj)o))))[(n)])
35#define header_of(o) deref(o,0)
36
37#define header_subtag(h) ((h) & subtagmask)
38#define header_element_count(h) ((h) >> num_subtag_bits)
39#define make_header(subtag,element_count) ((subtag)|((element_count)<<num_subtag_bits))
40
41#define unbox_fixnum(x) ((signed_natural)(((signed_natural)(x))>>fixnum_shift))
42#define box_fixnum(x) ((LispObj)((signed_natural)(x)<<fixnum_shift))
43
44#define car(x) (((cons *)ptr_from_lispobj(untag(x)))->car)
45#define cdr(x) (((cons *)ptr_from_lispobj(untag(x)))->cdr)
46
47/* "sym" is an untagged pointer to a symbol */
48#define BOUNDP(sym)  ((((lispsymbol *)(sym))->vcell) != undefined)
49
50/* Likewise. */
51#define FBOUNDP(sym) ((((lispsymbol *)(sym))->fcell) != nrs_UDF.vcell)
52
53#ifdef PPC
54#ifdef PPC64
55#define nodeheader_tag_p(tag) (((tag) & lowtag_mask) == lowtag_nodeheader)
56#define immheader_tag_p(tag) (((tag) & lowtag_mask) == lowtag_immheader)
57#else
58#define nodeheader_tag_p(tag) (tag == fulltag_nodeheader)
59#define immheader_tag_p(tag) (tag == fulltag_immheader)
60#endif
61#endif
62
63#ifdef X86
64#ifdef X8664
65#define NODEHEADER_MASK ((1<<(fulltag_nodeheader_0)) | \
66                         (1<<(fulltag_nodeheader_1)))
67#define nodeheader_tag_p(tag) ((1<<(tag)) &  NODEHEADER_MASK)
68
69#define IMMHEADER_MASK ((1<<fulltag_immheader_0) | \
70                        (1UL<<fulltag_immheader_1) |                    \
71                        (1UL<<fulltag_immheader_2))
72
73#define immheader_tag_p(tag) ((1<<(tag)) & IMMHEADER_MASK)
74#else
75#define nodeheader_tag_p(tag) (tag == fulltag_nodeheader)
76#define immheader_tag_p(tag) (tag == fulltag_immheader)
77#endif
78#endif
79
80#ifdef VC
81#define inline
82#define __attribute__(x)
83#endif
84
85/* lfuns */
86#define lfun_bits(f) (deref(f,header_element_count(header_of(f))))
87#define named_function_p(f) (!(lfun_bits(f)&(1<<(29+fixnum_shift))))
88#define named_function_name(f) (deref(f,-1+header_element_count(header_of(f))))
89
90#define TCR_INTERRUPT_LEVEL(tcr) \
91  (((signed_natural *)((tcr)->tlb_pointer))[INTERRUPT_LEVEL_BINDING_INDEX])
92#endif
93
94#ifdef WINDOWS
95#define LSEEK(fd,offset,how) _lseeki64(fd,offset,how)
96#else
97#define LSEEK(fd,offset,how) lseek(fd,offset,how)
98#endif
99
100/* We can't easily and unconditionally use format strings like "0x%lx"
101   to print lisp objects: the "l" might not match the word size, and
102   neither would (necessarily) something like "0x%llx".  We can at
103   least exploit the fact that on all current platforms, "ll" ("long long")
104   is the size of a 64-bit lisp object and "l" ("long") is the size of
105   a 32-bit lisp object. */
106
107#if (WORD_SIZE == 64)
108#define LISP "%llx"
109#define ZLISP "%016llx"
110#define DECIMAL "%lld"
111#else
112#define LISP "%lx"
113#define ZLISP "%08x"
114#define DECIMAL "%ld"
115#endif
Note: See TracBrowser for help on using the repository browser.