
#ifndef _GLOBAL_TYPES_H_MODULE_
#define _GLOBAL_TYPES_H_MODULE_

#define TARGET_SYSTEM_LINUX

	#ifndef PTR
	/*  make memory allocation work with both UNIXes and DOSes */
		#ifdef TARGET_SYSTEM_DOS
			#define PTR far *
		#else
			#define PTR *
		#endif
	#endif

/**************************************************************************/

enum lnd_attr
{
PARTOFOP=0,TWOLISTS,BRACKETT,VARIABLE,FUNCTION,
ASSOCVAR,OPDEFPTR,FUNCAVAR,INLCBVAR,INLINSUB,
LABELDEF,LABELREQ,FUNCDEFN,FUNDEFNL,TYPEDEFN,
TYPEVARL,VARTYPEL,TYPELIST,VARDLIST
};

enum opdef_attr
{
OPD_NONE=0,
NOTYPECK,
STOP_XOP=255
};

typedef struct _listnode_ PTR listnode;
struct _listnode_
{
enum lnd_attr attr;
listnode next;
char PTR data;
};

/**************************************************************************/

typedef struct op_definition 
{
  struct op_definition PTR next,PTR prev;
  char * form;
  char * defn;
  struct vardecl_list * vars;
  union
    {
      listnode opdef;
      struct inline_fun_rec PTR inlfun;
    } fdef;
  enum opdef_attr attr;
  int prec;
} PTR defined_op;

/* typedef struct inline_op_defn {
	struct inline_op_defn PTR next,PTR prev;
	char * form;
	char * defn;
	struct vardecl_list * vars;

	int attr;
	int prec;
} PTR inline_op; */
#define inline_op defined_op

typedef defined_op * opdef_arr;

typedef enum {eq,left,right,llong,rlong} cmp_str;

/**************************************************************************/

enum func_attr
{
  IS_EXPR,IS_FEXPR
};

enum typekind
{
  BUILT_IN,STRUCT,UNION,ENUM,CLASS,ACTIONCLASS,TYPEREFR,ISTYPEOF,SYMBREFR,
  ISMODIF,MODIFARG,VAR_TYPE
};

enum typemodf
{
  NONE,POINTER,INDEX,REFERENCE,FUNC,LAZYEVAL,MODIFIED
};

enum var_attr
{
  VAR_NORM,VMODFARG,VAR_FUNC,TYPE_VAR,FN_VAR,VFN_VAR,OPD_TYPE
};

enum tb_built_in {__int___,__char__,__list__,__str__,__long__,__double__,__void__,
__float__,_lpsdata};

union typebody
{
   enum tb_built_in built_in;
   struct actionclass PTR actionclass;
   struct class_def PTR class_def;
   struct struct_def PTR struct_def;
   /*struct modif_def PTR modif_def;*/
   struct enum_def PTR enum_def;
   
   struct tb_index
     {
      struct typerec PTR pointer_to;
      int size;
      int * dims;
     } index;
   
   struct typerec PTR pointer_to;
   struct type_list PTR class_list;
   char PTR symbrefr;
   listnode typeof;
   struct
     {
	struct type_list * topclass;
	struct var_decl PTR var;
     } var_type;
};

struct typerec
{
  int size;
  char * name;
  unsigned long typeid;
  enum typekind typekind;
  enum typemodf typemodf;
  union typebody typebody;
  struct fundef_list PTR typeconv;
  listnode validate;
};

enum fundef_type {is_normal,is_inline,is_virtual, is_prototype, is_actionclass};

struct fundef
{
  char PTR name;
  enum func_attr attr;
  enum fundef_type kind;
  union
  {
    char PTR name_in_code;
    struct inline_fndef PTR inline_fndef;
  } def_to_use;
  struct typerec PTR actionclass; /* combined action class */
  struct typerec PTR res_type;
  /*struct argdef PTR args;*/
  struct vardecl_list PTR args;
};

enum _state_ {ON,OFF};
enum funcall_arg {FC_VAR,FC_FUN};

struct type_list
{
  enum _state_ convert_lock;
  struct typerec PTR type;
  struct type_list PTR next;
};


struct fundef_list
{
  struct fundef PTR fundef;
  struct fundef_list PTR next;
};

/* struct field_def
{
char PTR name;
struct typerec PTR type;
struct field_def PTR next;
}; */

/* struct modif_def
{
struct type_list PTR top_class;
struct type_list PTR types;
struct code_block PTR code;
};
*/
struct struct_def
{
int size;
int s_or_u;
char * tag;
/*struct field_def fields;*/
struct vardecl_list PTR fields;
};

/* struct union_def
{
int size;
char * tag;
struct field_def fields;
}; */

struct enum_def
{
  char * name;
  int * assoc_value;
  struct enum_def PTR next;
};

struct var_decl
{
   enum var_attr attr;
   char PTR name;
   struct typerec PTR type;
   
   union
     {
	void * defvalue;
	struct fundef * fundef;
     } var_data;
};

struct vardecl_list
{
struct var_decl PTR var;
struct vardecl_list PTR next;
};

struct class_def
{
char PTR name;
int size;
struct type_list PTR top_class;
struct fundef_list PTR constructors;
struct fundef_list PTR destructors;
struct fundef_list PTR funcs;
struct vardecl_list PTR vars;
struct type_list PTR types;
listnode variable_constructors;
};

struct funcall_list
{
struct fundef PTR function;
struct vardecl_list PTR args;
struct funcall_list PTR next;
};

struct code_block
{
struct vardecl_list PTR vars;
struct type_list PTR types;
listnode code;
};

struct actionclass
{
struct type_list PTR top_class;
struct fundef_list * local_funcs;
struct vardecl_list PTR args;
struct vardecl_list * ac_args;
struct vardecl_list PTR local_vars;
struct type_list PTR local_types;
struct typerec PTR res_type;
enum func_attr attr;
listnode body;
};

struct inline_fndef
{
struct vardecl_list PTR vars; 
struct type_list PTR types;
listnode body;
};



struct struct_def_list
{
struct struct_def struct_def;
struct struct_def_list PTR next;
};

/* struct union_def_list
{
struct union_def union_def;
struct union_def_list PTR next;
}; */

struct class_def_list
{
struct class_def class_def;
struct class_def_list PTR next;
};

struct actionclass_list
{
  struct actionclass actionclass;
  struct actionclass_list PTR next;
};

struct vardecl_listoflist
{
struct vardecl_list PTR vlist;
struct vardecl_listoflist PTR next;
};

struct type_listoflist
{
struct type_list PTR tlist;
struct type_listoflist PTR next;
};

/**************************************************************************/

struct inline_fun_rec
{
struct vardecl_list PTR args;
listnode body,labels;
inline_op subfunctions;
};
struct inline_varinfo
{
char name[33];
int times_used;
struct inline_varinfo PTR next;
};

/**************************************************************************/
#endif /* Global types */
