/*
 *      Copyright (c) 1987 Paul Campbell
 *      All Rights Reserved
 *      THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Paul Campbell
 *      The copyright notice above does not evidence any
 *      actual or intended publication of such source code.
 */

#ifdef COMPILER
#define	TYPE_UNKNOWN	0
#define	TYPE_BITS		1
#define	TYPE_KNOWN		2
#define	TYPE_BIT		3
#define	TYPE_CHAR		4
#define	TYPE_WORD		5
#define	TYPE_PROC		6
#define	TYPE_PARAM		7
#define	TYPE_CONST		8

#define O_BIT		1
#define O_ASSIGN	2 
#define O_LIST		3 
#define O_OROR		4 
#define O_ANDAND	5	 
#define O_LT		6	 
#define O_LE		7	 
#define O_GT		8	 
#define O_GE		9	 
#define O_NE		10	 
#define O_EQ		11	 
#define O_OR		12	 
#define O_AND		13 
#define O_XOR		14
#define O_LTLT		15
#define O_GTGT		16 
#define O_ADD		17 
#define O_SUB		18 
#define O_MUL		19 
#define O_DIV		20 
#define O_MINUS		21 
#define O_NOT		22 
#define O_TILDE		23 
#define O_INDEX		24 
#define O_CALL		25 
#define O_BITS		26 
#define O_STAR 		27 
#define O_AT		28	 
#define O_CARET		29 
#define O_STRING	30	 
#define O_CONST		31 
#define O_NAME		32 
#define O_KNOWN		33 
#define O_CHAR		34 
#define O_WORD		35 
#define O_ADDR		36 
#define O_STAR2 	37	 
#define O_AT2		38 
#define O_CARET2	39	 
#define O_CALL2		40 

struct OHDR {
	unsigned char	Oop;
	unsigned char	Otp;
	unsigned char	Oloc;
	unsigned short	Osz;
	unsigned short	Oline;
};

struct OP1 {
	struct	OP 	*o1;
};

struct OP2 {
	struct	OP 	*o1;
	struct	OP 	*o2;
};

struct OP3 {
	struct	OP 	*o1;
	struct	OP 	*o2;
	struct	OP 	*o3;
};

struct OP4 {
	struct	OP 	*o1;
	struct	OP 	*o2;
	struct	OP 	*o3;
	struct	OP 	*o4;
};

struct OPN {
	struct dict *d;
};

struct OPC {
	long val;
};

struct OPS {
	char string[0];
};

struct OP {
	struct OHDR		oh;
	union {
		struct OP1 o1;
		struct OP2 o2;
		struct OP3 o3;
		struct OP4 o4;
		struct OPN n;
		struct OPC c;
		struct OPS s;
	}o;
};

#define	op		oh.Oop
#define	tp		oh.Otp
#define	loc		oh.Oloc
#define	sz		oh.Osz
#define	line	oh.Oline
#define	op1		o.o4.o1
#define	op2		o.o4.o2
#define	op3		o.o4.o3
#define	op4		o.o4.o4

extern unsigned char *tree_name[];
extern char tree_size[];
extern int max_op;
#endif

struct dict {
	struct dict 	*lt;
	struct dict		*gt;
	unsigned char	valid;
	unsigned char	bits;
#ifdef COMPILER
	unsigned char	bits_save;
	unsigned char	type;
	unsigned char	type_save;
	struct dict 	*param_next;
	unsigned short	val_save;
#else
	unsigned char	builtin;
#endif
	unsigned short	val;
	char			name[0];
};

void yyerror(char *s, long a, long b, long c, long d, long e, long f);
void yywarnline(int err, char *s, long a, long b, long c, long d, long e, long f);
void yyerrline(int err, char *s, long a, long b, long c, long d, long e, long f);
void yyerrlinex(long err, char *s, long a, long b, long c, long d, long e, long f);
void emit1(unsigned char c1);
void emit2(unsigned char c1, unsigned char c2);
void emit3(unsigned char c1, unsigned char c2, unsigned char c3);
void set_val( struct dict *dp, unsigned short val, unsigned char b);
void new_label(struct dict *dp);
int yylex();
void set_addr();
void dump_done();
void pmap(int flag);
void yyinit();
void yyrewind();
int yyopen(char *file);
int yyparse();
void yyclose();
void set_addr();
#ifdef COMPILER
struct OP * constant(struct OP *p);
struct OP * types(struct OP *p, int type);
void first_state(struct OP *p);
void next_state(struct OP *p);
void start_state(struct OP *p);
void last_state();
void mid_state();
void end_state();
void exit_state();
void event_int(int v);
void event_exp(struct OP *p);
void event_timeout(struct OP *p);
void event_input(struct dict *dp);
void event_idle();
void event_output();
void end_event();
int exp(struct OP *p);
void do_call(struct OP *p);
int get_bits(struct OP *p);
void do_return(struct OP *p);
void do_assign(struct OP *p);
unsigned long new_label();
void use_label(unsigned long l);
void use_labels(char *p1, char *p2);
void do_cond(int type, struct OP *p, unsigned long l);
void do_uncond(unsigned long l);
void do_unconds(char *p, char        *cp);
void enter_proc(int type, struct dict *name, struct OP *params);
void forward_proc(int type, struct dict *name);
void exit_proc();
void declare(int type, struct dict *name, int size, int known, int bits);
void dec_const(struct dict *name, struct OP *p);
struct OP * build0(unsigned short type, struct OP *ln);
struct OP * build1(unsigned short type, struct OP *ln, struct OP *p1);
struct OP * build2(unsigned short type, struct OP *ln, struct OP *p1, struct OP *p2);
struct OP * build3(unsigned short type, struct OP *ln, struct OP *p1, struct OP *p2, struct OP *p3);
struct OP * build4(unsigned short type, struct OP *ln, struct OP *p1, struct OP *p2, struct OP *p3, struct OP *p4);
struct OP * build_name(struct dict *name);
struct OP * make_constant(long l);
struct OP * make_string(char *str);
void err_space();
void tree_free(struct OP *trp);
void tree_print(char *name, struct OP *trp, int ind);
void int_error(char *s, long a, long b, long c, long d, long e);
int alloc_reg();
void free_reg(int i);
int alloc_c();
int save_acc();
int save_r2();
int save_r3();
int save_c();
void free_c(int r);
void bit_to_acc();
void yydone(int x);
extern int yyerrcount, yydebug;
#endif
