/*-------------------------------------------------------------------------*
 * GNU Prolog                                                              *
 *                                                                         *
 * Part  : Prolog engine                                                   *
 * File  : wam_archi.def (gives rise to wam_archi.h)                       *
 * Descr.: Wam architecture definition - description file                  *
 * Author: Daniel Diaz                                                     *
 *                                                                         *
 * Copyright (C) 1999-2021 Daniel Diaz                                     *
 *                                                                         *
 * This file is part of GNU Prolog                                         *
 *                                                                         *
 * GNU Prolog is free software: you can redistribute it and/or             *
 * modify it under the terms of either:                                    *
 *                                                                         *
 *   - the GNU Lesser General Public License as published by the Free      *
 *     Software Foundation; either version 3 of the License, or (at your   *
 *     option) any later version.                                          *
 *                                                                         *
 * or                                                                      *
 *                                                                         *
 *   - the GNU General Public License as published by the Free             *
 *     Software Foundation; either version 2 of the License, or (at your   *
 *     option) any later version.                                          *
 *                                                                         *
 * or both in parallel, as here.                                           *
 *                                                                         *
 * GNU Prolog is distributed in the hope that it will be useful,           *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
 * General Public License for more details.                                *
 *                                                                         *
 * You should have received copies of the GNU General Public License and   *
 * the GNU Lesser General Public License along with this program.  If      *
 * not, see http://www.gnu.org/licenses/.                                  *
 *-------------------------------------------------------------------------*/

#include "pl_long.h"

/*---------------------------------*
 * Register Descriptions           *
 *---------------------------------*/

typedef intptr_t WamWord;       /* a WamWord can store a ptr (32/64 bits) */

typedef void (*CodePtr) ();     /* a code pointer is a ptr to fct */

typedef CodePtr WamCont;        /* a continuation is a code pointer */

#ifndef ONLY_TAG_PART

#define X(x)                       (pl_reg_bank[x])
#define A(a)                       (pl_reg_bank[a])

typedef WamWord *WamWordP;


@begin regs

@filler NB_OF_X_REGS

@reg 4 WamCont  CP              /* Continuation pointer */

@reg 4 WamWordP E               /* Last environment pointer */

@reg 2 WamWordP B               /* Last choice point pointer */

@reg 3 WamWordP H               /* Top of the heap */
@reg 3 WamWordP HB1             /* copy of HB(B) */

@reg 1 WamWordP TR              /* Top of the trail */
@reg 5 WamWordP S               /* Unification pointer */

@reg 9 WamWord  STAMP           /* Choice point stamp (for FD) */
@reg 4 WamWordP CS              /* Top of the constraint stack */

@reg 9 WamWord  BCI             /* Byte-code info */

@reg 9 WamWordP LSSA            /* Local stack start address */


@end regs

#endif


/*---------------------------------*
 * Tag Descriptions                *
 *---------------------------------*/


@begin tags

@tag REF address 0              /* Reference */
@tag LST address 1              /* List */
@tag STC address 2              /* Structure */

@tag ATM short_uns 3            /* Atom */

@tag FLT address 4              /* Float */
@tag FDV address 5              /* Finite Domain Variable */

@tag INT long_int 7             /* Integer */

@end tags




/*---------------------------------*
 * Stack Descriptions              *
 *---------------------------------*/

#ifndef ONLY_TAG_PART

#define KBytes_To_Wam_Words(kb)    ((1024 * kb + sizeof(WamWord) - 1) / sizeof(WamWord))

#define Wam_Words_To_KBytes(ww)    (ww * sizeof(WamWord) / 1024)

#define Local_Top                  ((B >= E) ? B : E)

@begin stacks

@stack trail  "Trail Stack (undo)"        16384 TR          /* Trail  stack */
@stack cstr   "Cstr Stack (constraints)"  16384 CS          /* Constraint stack */
@stack global "Global Stack (heap)"       32768 H           /* Global stack */
@stack local  "Local Stack (control)"     16384 Local_Top   /* Local  stack (after global) */

@end stacks

#endif
