home *** CD-ROM | disk | FTP | other *** search
- /*
- element.h
- */
- /* Copyright (c) 1994 Christian F. Tschudin. All rights reserved.
-
- Distributed under the terms of the GNU General Public License
- version 2 of june 1991 as published by the Free Software
- Foundation, Inc.
-
- This file is part of M0.
-
- M0 is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY. No author or distributor accepts responsibility to anyone for
- the consequences of using it or for whether it serves any particular
- purpose or works at all, unless he says so in writing. Refer to the GNU
- General Public License for full details.
-
- Everyone is granted permission to copy, modify and redistribute M0, but
- only under the conditions described in the GNU General Public License.
- A copy of this license is supposed to have been given to you along with
- M0 so you can know your rights and responsibilities. It should be in a
- file named LICENSE. Among other things, the copyright notice and this
- notice must be preserved on all copies. */
-
- #ifndef ELEMENT_H
- #define ELEMENT_H
-
- #include "std.h"
-
- #define MAXLOCALS 256
- #define MAXGLOBALS 8192 /* must fit into a short */
-
- typedef struct mproc_s *mproc;
-
- #ifdef __MSDOS__
- typedef struct element_s huge *eptr;
- #else
- typedef struct element_s *eptr;
- #endif
- typedef short eindex; /* index in element table */
- typedef void (*submitfct)(mproc p, void *data, eindex m);
- typedef void (*receivefct)(int fd, eindex *msgr, eindex *orig);
-
- /* adjust type_names (in l_elemnt.c) if you change this sequence: */
- enum {
- T_EMPTY=0, T_NULL, T_INT, T_TIME, T_NAME, T_KEY, T_ARRAY,
- T_STRING, T_DICT, T_PROC, T_MARK, T_QUEUE, T_CHANNEL, LAST_TYPE
- };
-
-
- /* attributes: */
- #define A_READ 0x01
- #define A_WRITE 0x02
- #define A_EXEC 0x04
- #define A_EXECUTABLE 0x08
- #define A_SUB 0x10 /* sub for name/key/array/dict/string */
- #define A_FRAG 0x20 /* for strings only */
- /*
- #define A_COPYONWRITE 0x40
- */
- #define A_VISITED 0x80
-
- #define A_ALL (A_READ|A_WRITE|A_EXEC)
-
- /* --------------------------------------------------------------------- */
-
- /* type specific data structures, no more than 8 bytes */
-
- struct array_s {
- uint alen; /* number of allocated entries */
- eindex *a;
- };
-
-
- struct chan_s {
- void *data;
- submitfct submit;
- };
-
- struct dict_s {
- uint alen; /* number of allocated entries */
- eindex *d; /* array of 2*alen eindex entries */
- };
-
- struct frag_s {
- eindex f[2]; /* the two fragments */
- };
-
- struct name_s {
- eindex next; /* used for external hashing */
- union {
- byteptr s;
- #define SHORTNAMELEN 6 /* (2*sizeof(byteptr)-2) */
- byte n[SHORTNAMELEN]; /* short names with length <= 6 */
- } u;
- };
- /* note: keys are stored as 8-byte names i.e., under V.nam.u.s */
-
- struct proc_s {
- ushort pop, push; /* number of elements cons. and prod. */
- int (*fct)();
- };
-
- struct queue_s {
- mproc head;
- mproc tail;
- };
-
- struct string_s {
- uint alen; /* length of allocated buffer */
- byteptr s;
- };
-
- struct sub_s {
- uint offset;
- eindex e;
- };
-
- struct time_s {
- uint sec; /* seconds since 1970-01-01 */
- uint usec; /* micro seconds */
- };
-
-
- /* --------------------------------------------------------------------- */
-
- struct element_s { /* 16 bytes: */
- byte T; /* 1 byte type */
- byte A; /* 1 byte attribute */
- ushort R; /* 2 bytes reference count */
- uint L; /* 4 bytes length */
- union { /* 8 bytes value: */
- long i; /* integer */
- struct array_s arr;
- struct chan_s cha;
- struct dict_s dic;
- struct frag_s fra;
- struct name_s nam;
- struct proc_s pro;
- struct queue_s que;
- struct string_s str;
- struct sub_s sub;
- struct time_s tim;
- } V;
- };
-
- /* --------------------------------------------------------------------- */
-
- #define eptype(ep) ((ep)->T)
- #define eplen(ep) ((ep)->L)
- #define epattr(ep) ((ep)->A)
- #define eprefcnt(ep) ((ep)->R)
-
- #define epis_str(ep) (eptype(ep)==T_STRING \
- || eptype(ep)==T_SUBSTR \
- || eptype(ep)==T_FRAGSTR)
-
- #define gaddr(ei) (global-(ei)-1)
- #define eaddr(p,ei) ((ei)<0 ? gaddr(ei) : p->local+(ei)-1)
-
- #define etype(p,ei) eptype(eaddr(p,ei))
- #define elen(p,ei) eplen(eaddr(p,ei))
- #define eattr(p,ei) epattr(eaddr(p,ei))
- #define erefcnt(p,ei) eprefcnt(eaddr(p,ei))
-
- #define is_string(p,ei) epis_string(eaddr(p,ei))
-
- #define incref(p,ei) erefcnt(p,ei)++
- #define increfp(ep) eprefcnt(ep)++
-
- #define decrefp(p,ei,ep) if (ei && eptype(ep)!=T_EMPTY) { \
- eprefcnt(ep)--; \
- if (eprefcnt(ep) == 0) \
- free_element(p,ei); \
- }
-
- /* ---------------------------------------------------------------------- */
-
- #endif
-