/*
 * Various interpreter data tables.
 */

#include "..\h\config.h"
#include "..\h\rt.h"
#include "rproto.h"

struct b_proc Bnoproc;

/*
 * External declarations for function blocks.
 */

char *fncnames[] = {

#define FncDef(p,n) Lit(p),
#define FncDefV(p) Lit(p),
#include "..\h\fdefs.h"
#undef FncDef
#undef FncDefV
   0
   };

int fnsize = (sizeof(fncnames) / sizeof(char*)) - 1;

#define FncDef(p,n) extern struct b_proc Cat(B,p);
#define FncDefV(p) extern struct b_proc Cat(B,p);
#include "..\h\fdefs.h"
#undef FncDef
#undef FncDefV

#define OpDef(p,n,s) extern struct b_proc Cat(B,p);
#include "..\h\odefs.h"
#undef OpDef

extern struct b_proc Bbscan;
extern struct b_proc Bcreate;
extern struct b_proc Bescan;
extern struct b_proc Bfield;
extern struct b_proc Blimit;
extern struct b_proc Bllist;

/*
 * Array of addresses of function blocks.
 */
struct b_proc *functab[] = {
#define FncDef(p,n) Cat(&B,p),
#define FncDefV(p) Cat(&B,p),
#include "..\h\fdefs.h"
#undef FncDef
#undef FncDefV
   0
   };

int ftsize = (sizeof(functab) / sizeof(struct b_proc *)) - 1;

 

#ifdef TraceBack

struct b_proc *opblks[] = {
	NULL,
#define OpDef(p,n,s) Cat(&B,p),
#include "..\h\odefs.h"
#undef OpDef
   &Bbscan,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   &Bcreate,
   NULL,
   NULL,
   NULL,
   NULL,
   &Bescan,
   NULL,
   &Bfield,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   &Blimit,
   &Bllist,
   NULL,
   NULL,
   NULL
   };
#endif					/* TraceBack */

#ifdef StrInvoke
/*
 * Array of names and corresponding functions.
 */

struct pstrnm pntab[] = {

#ifndef BoundFunctions
#define FncDef(p,n) Lit(p), Cat(&B,p),
#define FncDefV(p) Lit(p), Cat(&B,p),
#include "..\h\fdefs.h"
#undef FncDef
#undef FncDefV
#endif					/* BoundFunctions */

#define OpDef(p,n,s) s, Cat(&B,p),
#include "..\h\odefs.h"
#undef OpDef
	0,		 0
	};
#endif					/* StrInvoke */

/*
 * Structures for built-in values.  Parts of some of these structures are
 *  initialized later. Since some C compilers cannot handle any partial
 *  initializations, all parts are initialized later if any have to be.
 */

/*
 * Built-in csets
 */

/*
 * &ascii; 128 bits on, second 128 bits off.
 */
struct b_cset  k_ascii = {

#if EBCDIC == 1 /* Conflict: "a" is in &ascii, but ord("a") >= 128 */
   T_Cset,
   128,
   cset_display(0xf8af, 0xf34f, 0xe0e0, 0xb084,
                0xf801, 0xfc01, 0xf803, 0xfe00,
                0x03fe, 0x03fe, 0x23fe, 0x2000,
                0x03ff, 0x03ff, 0x03fd, 0x03ff)
   };
#else					/* EBCDIC == 1 */
   T_Cset,
   128,
   cset_display(~0, ~0, ~0, ~0, ~0, ~0, ~0, ~0,
                 0,  0,  0,  0,  0,  0,  0,  0)
   };
#endif					/* EBCDIC == 1 */

/*
 * &cset; all 256 bits on.
 */
struct b_cset  k_cset = {
   T_Cset,
   256,
   cset_display(~0, ~0, ~0, ~0, ~0, ~0, ~0, ~0,
		~0, ~0, ~0, ~0, ~0, ~0, ~0, ~0)
   };

/*
 * &digits; bits corrosponding to 0-9 are on.
 */
struct b_cset  k_digits = {
   T_Cset,
   10,

#if EBCDIC != 1
   cset_display(0,  0,	0,  0x3ff, 0,  0, 0,  0,
		0,  0,	0,  0,	 0,  0,	 0,  0)
#else					/* EBCDIC != 1*/
   cset_display(0,  0,	0,  0,	0,  0,	0,  0,
		0,  0,	0,  0,  0,  0,  0,  0x3ff)
#endif					/* EBCDIC != 1 */

   };

/*
 * Cset for &lcase; bits corresponding to lowercase letters are on.
 */
struct b_cset  k_lcase = {
   T_Cset,
   26,

#if EBCDIC != 1
   cset_display(0,  0,	0,  0,	0,  0,	~01,  03777,
		0,  0,	0,  0,	0,  0,	0,  0)
#else					/* EBCDIC != 1 */
   cset_display(0,  0,	0,  0,	0,  0,	0,  0,
		0x3fe,	0x3fe,	0x3fc,	0,  0,	0,  0,	0)
#endif					/* EBCDIC != 1 */

   };

/*
 * &ucase; bits corresponding to uppercase characters are on.
 */
struct b_cset  k_ucase = {
   T_Cset,
   26,

#if EBCDIC != 1
   cset_display(0,  0,	0,  0,	~01,  03777, 0, 0,
		0,  0,	0,  0,	0,  0,	0,  0)
#else					/* EBCDIC != 1 */
   cset_display(0,  0,	0,  0,	0,  0,	0,  0,
		0,  0,	0,  0,	0x3fe,	0x3fe,	0x3fc,	0)
#endif					/* EBCDIC != 1 */

   };

/*
 * &letters; bits corresponding to letters are on.
 */
struct b_cset  k_letters = {
   T_Cset,
   52,

#if EBCDIC != 1
   cset_display(0,  0,	0,  0,	~01,  03777, ~01, 03777,
		0,  0,	0,  0,	0,  0,	0,  0)
#else					/* EBCDIC != 1 */
   cset_display(0,  0,	0,  0,	0,  0,	0,  0,
		0x3fe,  0x3fe,	0x3fc,  0, 0x3fe, 0x3fe, 0x3fc,	0)
#endif					/* EBCDIC != 1 */

   };

/*
 * Built-in files.
 */

struct b_file  k_errout = {T_File, NULL, Fs_Write};	/* &errout */
struct b_file  k_input = {T_File, NULL, Fs_Read};	/* &input */
struct b_file  k_output = {T_File, NULL, Fs_Write};	/* &outout */

/*
 * Keyword trapped variables.
 */


struct b_tvkywd tvky_err = {T_Tvkywd, putint, {D_Integer}};	/* &error */
struct b_tvkywd tvky_pos = {T_Tvkywd, putpos, {D_Integer}};	/* &pos */
struct b_tvkywd tvky_ran = {T_Tvkywd, putint, {D_Integer}};	/* &random */
struct b_tvkywd tvky_sub = {T_Tvkywd, putsub}; 			/* &subject */
struct b_tvkywd tvky_trc = {T_Tvkywd, putint, {D_Integer}};	/* &trace */

/*
 * Various constant descriptors.
 */

struct descrip blank; 			/* one-character blank string */
struct descrip emptystr; 		/* zero-length empty string */
struct descrip errout = {D_File};	/* &errout */
struct descrip input = {D_File};	/* &input */
struct descrip lcase;			/* string of lowercase letters */
struct descrip letr;			/* "r" */
struct descrip nulldesc = {D_Null};	/* null value */
struct descrip onedesc = {D_Integer};	/* integer 1 */
struct descrip ucase;			/* string of uppercase letters */
struct descrip zerodesc = {D_Integer};	/* integer 0 */

/*
 * The tended descriptors.
 */

struct descrip tended[6];

/*
 * Run-time error numbers and text.
 */
struct errtab errtab[] = {
   101, "integer expected",
   102, "numeric expected",
   103, "string expected",
   104, "cset expected",
   105, "file expected",
   106, "procedure or integer expected",
   107, "record expected",
   108, "list expected",
   109, "string or file expected",
   110, "string or list expected",
   111, "variable expected",
   112, "invalid type to size operation",
   113, "invalid type to random operation",
   114, "invalid type to subscript operation",
   115, "list, set, or table expected",
   116, "invalid type to element generator",
   117, "missing main procedure",
   118, "co-expression expected",
   119, "set expected",
   120, "cset or set expected",
   121, "function not supported",
   122, "set or table expected",
   123, "invalid type",
   124, "table expected",

   201, "division by zero",
   202, "remaindering by zero",
   203, "integer overflow",
   204, "real overflow, underflow, or division by zero",
   205, "value out of range",
   206, "negative first argument to real exponentiation",
   207, "invalid field name",
   208, "second and third arguments to map of unequal length",
   209, "invalid second argument to open",
   210, "non-ascending arguments to detab/entab",
   211, "by value equal to zero",
   212, "attempt to read file not open for reading",
   213, "attempt to write file not open for writing",
   214, "input/output error",
   215, "attempt to refresh &main",
   216, "external function not found",


   301, "evaluation stack overflow",
   302, "system stack overflow",
   303, "inadequate space for evaluation stack",

#ifdef FixedRegions
   304, "inadequate space in qualifier list",
#endif					/* FixedRegions */

   305, "inadequate space for static allocation",
   306, "inadequate space in string region",
   307, "inadequate space in block region",
   308, "system stack overflow in co-expression",

#if VMS
   351, "insufficient MAXMEM limit",
#endif					/* VMS */

#ifndef Coexpr
   401, "co-expressions not implemented",
#endif					/* Coexpr */

   500, "program malfunction",		/* for use by runerr() */

/*
 * End of operating-system specific code.
 */

   0,	""
   };

/*
 * Note:  the following material is here to avoid a bug in the Cray C compiler.
 */

/*
 * When an opcode n has a subroutine call associated with it, the
 *  nth word here is the routine to call.
 */

int (*optab[])() = {
	err,
#define OpDef(p,n,s) Cat(O,p),
#include "..\h\odefs.h"
#undef OpDef
   Obscan,
   err,
   err,
   err,
   err,
   err,
   Ocreate,
   err,
   err,
   err,
   err,
   Oescan,
   err,
   Ofield
   };
