1/* BEGIN LICENSE BLOCK
2 * Version: CMPL 1.1
3 *
4 * The contents of this file are subject to the Cisco-style Mozilla Public
5 * License Version 1.1 (the "License"); you may not use this file except
6 * in compliance with the License.  You may obtain a copy of the License
7 * at www.eclipse-clp.org/license.
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11 * the License for the specific language governing rights and limitations
12 * under the License.
13 *
14 * The Original Code is  The ECLiPSe Constraint Logic Programming System.
15 * The Initial Developer of the Original Code is  Cisco Systems, Inc.
16 * Portions created by the Initial Developer are
17 * Copyright (C) 1989-2006 Cisco Systems, Inc.  All Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 * END LICENSE BLOCK */
22
23/*
24 * VERSION	$Id: database.h,v 1.2 2009/02/27 21:01:04 kish_shen Exp $
25 */
26
27/*
28 * IDENTIFICATION		database.h
29 *
30 * DESCRIPTION
31 *
32 *
33 * CONTENTS:
34 *
35 *
36 */
37
38/* Header of the code blocks */
39
40/* size of the prefix in (vmcode) units */
41#define PROC_PREFIX_SIZE		7
42#define ProcHeader(codeptr)		((vmcode *) codeptr - PROC_PREFIX_SIZE)
43#define ProcBrkTableOffset(codeptr)	(*((word *) (codeptr) - 6))
44#define ProcCodeSize(codeptr)		(*((word *) (codeptr) - 5))
45#define ProcStruct(codeptr)		((pword *)((vmcode *) (codeptr) - 4))
46#define ProcLink(codeptr)		(*ProcHeader(codeptr))
47#define ProcBid(codeptr)		(*(vmcode *)ProcStruct(codeptr))
48#define ProcFid(codeptr)		(*((dident *) (codeptr) - 3))
49#define ProcLid(codeptr)		(*((vmcode *) (codeptr) - 2))
50#define ProcCid(codeptr)		(*((vmcode *) (codeptr) - 1) & 0xffffff)
51#define CodeStart(headerptr)		((vmcode *) (headerptr) + PROC_PREFIX_SIZE)
52/* BlockType should be int for use in switch labels */
53#define BlockType(headerptr)		(int)ProcLid(CodeStart(headerptr))
54
55#define CodeArity(codeptr)		(*((vmcode *) (codeptr) - 1) >> 24)
56#define Incr_Code_Arity(codeptr)	*((vmcode *) (codeptr) - 1) += 1 << 24;
57#define Cid(cid, did)			((vmcode) ((cid) & 0xffffff | DidArity(did) << 24))
58
59extern vmcode	*allocate_code_block();
60#define AllocateCodeBlock(size, link, bid, fid, type, cid)	\
61	allocate_code_block(size, 0, link, bid, fid, type, cid)
62/* allocate with breaktable */
63#define AllocateCodeBlockBTable(size, btable, link, bid, fid, type, cid)	\
64	allocate_code_block(size, btable, link, bid, fid, type, cid)
65
66#define Make_Prefix(link, btable, size, bid, fid, lid, cid)		\
67	Store_d(link); Store_d(btable);  Store_d(size); Store_d(bid); Store_d(fid); Store_d(lid);Store_d(cid);
68#define Make_Procedure_Prefix(link, size, bid, fid, lid, cid, did)		\
69	Make_Prefix(link, 0, size, bid, fid, lid, Cid(cid, did))
70/* default for system procedures */
71#define Make_Default_Prefix(did)	\
72	Make_Procedure_Prefix(0, 0, (uword)-1, D_UNKNOWN, DEFAULT_LINE, (uword)-1, did)
73
74/* The Lid field stores the type for other blocks */
75#define DEFAULT_LINE			 0
76#define GROUND_TERM			-1
77#define HASH_TABLE		        -2
78#define UNDEFINED_PROC			-3
79#define DYNAMIC_PROC		        -4
80#define PARALLEL_TABLE			-5
81
82/* In the usual code, only this one should occur, when the code for a new
83 * procedure is being allocated. The code pointer must be 'code'
84 * since the name 'code' is obligatory for the macro usage
85 */
86#define Allocate_Procedure(size, bid, fid, lid, cid, did)		\
87	    code = AllocateCodeBlock(size, 0, bid, fid, lid, Cid(cid, did));
88#define Allocate_Default_Procedure(size, did)				\
89	    Allocate_Procedure(size,  (uword)-1 , D_UNKNOWN, 0, (uword)-1, did)
90#define Allocate_Default_ProcedureBTable(size, did, btable)				\
91	    code = AllocateCodeBlockBTable(size, btable, 0, (uword)-1, D_UNKNOWN, 0, Cid((uword)-1, did))
92
93
94
95/*
96 *	by dynamic declaration or after retract_all/retract the last clause
97*/
98#define IsInitialized(c)	(SameCode(*c,Failure) && SameCode(*(c+1),Undefined))
99
100/*
101 *	by compilation, a declaration (local/export/global) or after abolish
102*/
103#define IsUndefined(c)		SameCode(*c,Undefined)
104
105#define DYNAMIC_INSTR_SIZE	6
106#define CALL_CLOCK_LIST_SIZE	100
107#define FACT_SOURCE_SIZE	10
108
109
110