#define __STORE_GLOBVARS__

#include "include/glbtypes.h"
#include "include/glbproto.h"
#include "include/globvars.h"


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


void clear_local_declarations(struct vardecl_list PTR vl,struct type_list PTR tl)
{
struct vardecl_list PTR vl1;
struct type_list PTR tl1;

for(vl1=vl;vl!=NULL;vl1=vl)
	{
	vl=vl->next;
	if(vl1->var!=NULL)
		{
		if(vl1->var->name!=NULL)
			Free(vl1->var->name);
/*		if(vl1->var->type!=NULL)
			Free(vl1->var->type); */
		if(vl1->var->defvalue!=NULL)
			Free(vl1->var->defvalue);
		Free(vl1->var);
		};
	Free(vl1);
	};
for(tl1=tl;tl!=NULL;tl1=tl)
	{
	tl=tl->next;
	if(tl1->type!=NULL)
		{
		if(tl1->type->name!=NULL)
			Free(tl1->type->name);
		switch(tl1->type->typekind)
			{
			case CLASS:
				clear_local_declarations(tl1->type->typebody.class_def->vars,NULL);
				Free(tl1->type->typebody.class_def);
				break;
			case STRUCT:
				clear_local_declarations(tl1->type->typebody.struct_def->fields,NULL);
				Free(tl1->type->typebody.struct_def);
				break;
			case ACTIONCLASS:
/* clear_local_declarations(tl1->type->typebody.actionclass->vars,NULL);*/
				Free(tl1->type->typebody.actionclass);
				break;
			case ISTYPEOF:
				rm_lnd_all(tl1->type->typebody.typeof);
				break;
			};
		Free(tl1->type);
		};
	Free(tl1);
	};
};




int get_code_block(
char * instr,
listnode dst,
listnode inl,
defined_op ops,
listnode inl_lab,
listnode labels,
struct vardecl_listoflist PTR vars,
struct type_listoflist PTR types,
listnode fnlist,
int do_list)
{
struct vardecl_listoflist PTR this_vars;
struct type_listoflist PTR this_types;
struct vardecl_list PTR tmpvind;
struct type_list PTR tmptind;

char * str;
int change=0;
int was_inline=0;
listnode l,l1,l2;/* ,labels; */
char local_buf[34];

/* labels=mk_set_lnd(NULL,NULL,LABELDEF); */

str=instr;
while (*str==32) str++;
refresh_buffer(instr,str-instr,64);
instr=str;

if (*str!='{')
	{
/*	(listnode) l->data=mk_set_lnd(NULL,NULL,0); // make it a sublist */

	l1=mk_set_lnd(NULL,NULL,VARIABLE);

	for(l2=inl;l2!=NULL;l2=l2->next)
		if(inline_op_recognize(instr,l1,(inline_op)l2->data,ops,inl,inl_lab,labels,vars,types,fnlist,0,do_list))
			break;
	if(l2==NULL)
		{
		rm_lnd_all(l1); /* remove l */

		if(do_list)
			change=get_expression(str,dst,ops,inl,0,types,vars,fnlist); 
			/* Just an operator */
		else
			{
			l1=mk_set_lnd(NULL,NULL,VARIABLE);
			change=get_expression(str,l1,ops,inl,0,types,vars,fnlist);
			};
		if (!change)
			{
			if(!do_list)
				rm_lnd_all(l1);
			return 0;
			};
		refresh_buffer(instr,change,64);
		if(!do_list)
			{
			l1->next=op_to_function(l1->next);
			mk_asm_output(l1->next,labels,vars,types,fnlist);
			rm_lnd_all(l1);
			};
		}
	else
		{
		if(do_list)
			{
			l=lnd_cdre(dst);
			l->next=l1->next;/* skip junk at the beginning */
			Free(l1);/* clear this junk */
			};
		};
	return 1;
	};
change=1; /*  *str='{' */

if(do_list)
	l=mk_set_lnd(dst,NULL,TWOLISTS);
else
	dst=l=mk_set_lnd(NULL,NULL,TWOLISTS);

refresh_buffer(instr,change,64);

this_types=my_malloc(sizeof(struct type_listoflist));
this_vars=my_malloc(sizeof(struct vardecl_listoflist));
this_types->next=types;
this_vars->next=vars;
this_types->tlist=NULL;
this_vars->vlist=NULL;

while((!!change)||was_inline)
	{
	memset(local_buf,0,34);

	str=instr;

	while(*str==32) str++;
	refresh_buffer(instr,str-instr,64);

	str=get_variable_name(instr);

	strncpy(local_buf,instr,str-instr);
	
	change=get_opdef_def(instr,ops,inl,vars,types,fnlist);

	if(!change)
		{
		if((get_type_by_name(local_buf,NONE,this_types)!=NULL)
		||(get_type_by_name(local_buf,FUNC,this_types)!=NULL) /* actionclass */
		||(!Strcmp(local_buf,"typeof"))
		||(!Strcmp(local_buf,"struct"))
		||(!Strcmp(local_buf,"union"))
		||(!Strcmp(local_buf,"class"))
		||(!Strcmp(local_buf,"aclass"))
		||(!Strcmp(local_buf,"typedef"))
		||(!Strcmp(local_buf,"modif")))

			change=get_var_decl(instr,this_types,this_vars,labels,fnlist,ops,inl,inl_lab,0,NULL);
		};

	l->data=(char PTR)mk_set_lnd(NULL,NULL,PARTOFOP);/* for AIX cc */

	for(l2=inl;!change&(l2!=NULL);l2=l2->next)
		{
		was_inline=inline_op_recognize(instr,(listnode)l->data,(inline_op)l2->data,ops,inl,inl_lab,labels,this_vars,this_types,fnlist,0,do_list);
		if(was_inline)
			break;
		};

	if(!change&!was_inline)
		{
		change=get_expression(instr,(listnode)l->data,ops,inl,0,this_types,this_vars,fnlist);
		if (change)
			{
			l1=op_to_function(((listnode) l->data)->next);

			if(!do_list)
				{
				mk_asm_output(l1,labels,this_vars,this_types,fnlist);
				rm_lnd_all(l1);
				}
			else
				{
				l->next=mk_set_lnd(NULL,NULL,TWOLISTS);
				Free((listnode) l->data);
				l->data=(char PTR)l1;/* dumb AIX cc */
				l=l->next;
				};

			refresh_buffer(instr,change,64);

			}
		else /* if !change ... */
			{
			if(l->data!=NULL)
				Free(l->data);
			l->data=NULL;
			if (*str=='}')
				break;
			else
				{
				str=get_variable_name(instr);
				while(*str==32) str++;
				if (*str==':')
					{
					str++;		/* avoid ':' */
					memset(local_buf,0,32);
					for(change=str-instr;*(instr+change)==32;change--);
					strncpy(local_buf,instr,change++);
					printf("lab%s :  ## Label %s\n",get_local_label((char PTR)local_buf,labels,LABELDEF),local_buf);
					refresh_buffer(instr,str-instr,64);
					str=instr;
					continue; /* after label no comma */
					}
				else
					{
					clear_local_declarations(this_vars->vlist,this_types->tlist);
					Free(this_vars);
					Free(this_types);
					return 0;
					};
				};
			};
		};

	for(str=instr;(!!*str)&(*str!=';')&(*str!='}');str++){};
	if(*str==';') str++;
	refresh_buffer(instr,str-instr,64);
	};

if(!do_list)
	clear_local_declarations(this_vars->vlist,this_types->tlist);
else
	dst->next=mk_head_lnd(mk_head_lnd(dst->next,this_vars->vlist,VARDLIST),this_types->tlist,TYPELIST);

Free(this_vars);
Free(this_types);

if(*instr=='}')
	refresh_buffer(instr,1,64);
else
	return 0;
if(!do_list)
	rm_lnd_all(dst);

return 1;
};


char PTR get_local_label(char PTR name, listnode labels,enum lnd_attr mode)
{
listnode l;
char local_buf[34];
char PTR res=NULL;

if (labels==NULL)
	return NULL;

for(l=labels;l!=NULL;l=l->next)
	{
	if(l->attr==TWOLISTS)
		res=get_local_label(name,(listnode)l->data,PARTOFOP);
/*don't replace*/
	else if(l->data != NULL)
			if(!Strcmp(((listnode)l->data)->data,name))
				if(((listnode)l->data)->next != NULL )
					res=((listnode)l->data)->next->data;
	if(res!=NULL)
		break;   /* known label */
	};

if(l==NULL)  /* new label */
	{
	if(mode==0)
		return NULL; /* No replacing */
	if(labels->attr==TWOLISTS)
		return get_local_label(name,(listnode)labels->data,mode);/* NOW Replace */
	else
		l=mk_set_lnd(labels,NULL,mode);
	l->data=(char PTR)lnd_asapnde(NULL,name,PARTOFOP);/* dumb AIX cc */
	};

if (((listnode)l->data)->next==NULL)
	{
	sprintf(local_buf,"%lX",global_label_count);
	l=lnd_asapnde((listnode)l->data,local_buf,PARTOFOP);
	global_label_count++;
	return l->data;
	};

if((mode==LABELDEF)&(l->attr==LABELREQ))
	l->attr=LABELDEF;   /* The label is known now */

return res;
};






void print_asm_output(listnode lst, listnode labels,struct vardecl_listoflist PTR vars, struct type_listoflist PTR types,listnode fnlist)
{
char local_buf[34];
listnode l;
unsigned long loc_tmp_count=0;

if(lst==NULL)
	return;

if(lst->attr==VARIABLE)
	{
	if(*lst->data==4)
		printf("push word ptr %s\n",(lst->data+1));
	else if(isnum(*lst->data))
		printf("mov ax, %s\npush ax\n",lst->data);
	else
		printf("push word ptr v%s\n",lst->data);
	return;
	};


if (lst->attr!=FUNCTION)
	return;

loc_tmp_count=global_tmp_var;
global_tmp_var++;

if(!Strcmp(lst->data,"\4run_inline"))
	{
	exec_inline_func((struct fundef PTR)lst->next->data,lst->next->next,labels,vars,types,fnlist);
	return;
	};
if(!Strcmp(lst->data,"\4lambda"))
	{
	printf("###LAMBDA HERE###\n");
	return;
	};
if(!Strcmp(lst->data,"\4label"))
	{
	printf("lab%s :\n",get_local_label(lst->next->data,labels,LABELDEF));
	return;
	};

if(!Strcmp(lst->data,"\4goto"))
	{
	printf("jmp lab%s\n",get_local_label(lst->next->data,labels,LABELREQ));
	return;
	};

if(!Strcmp(lst->data,"\4ifjmp"))
	{
	printf("jz lab%s\n",get_local_label(lst->next->data,labels,LABELREQ));
	return;
	};

if(!Strcmp(lst->data,"\4check"))
	{
	if(lst->next->attr==FUNCTION)
		{
		if(validate_function(lst->next,fnlist,vars,types,labels,0)==NULL)
			{
			fprintf(stderr,"One of current inline's components (%s) have type mismatch !\n",lst->next->data);
			return;
			};
		print_asm_output(lst->next,labels,vars,types,fnlist);
		printf("cmp word prt [bp+__FIRST_ARG_IN_HEADER], 0\n");
		}
	else
		printf("cmp word ptr %s,0\n",lst->next->data);
	return;
	};

if(!Strcmp(lst->data,"\4runcode"))
	{
	printf("call %s\n",get_local_label(lst->next->data,labels,LABELREQ));
	return;
	};

if(!Strcmp(lst->data,"\4vartypeif"))
	{
	if(lst->next->attr!=TYPEVARL)
		printf("# print_asm_output():strange:\4vartypeif's 2nd arg have attr %d different from TYPEVARL\n",lst->next->attr);
	if(lst->next->data==NULL)
		printf("# print_asm_output():strange:\4vartypeif's 2nd arg  == NULL\n");

	global_tmp_var++;
	sprintf(local_buf,"\4tmplab%lx",global_tmp_var);
	for(l=(listnode)lst->next->data;l!=NULL;l=l->next)
		{
		if(l->attr!=VARTYPEL)
			printf("# print_asm_output():strange:\4vartypeif's 2nd arg's list member have attr %d different from VARTYPEL\n",lst->next->attr);

		if(((listnode)l->data)->attr==VARTYPEL)
			printf("push [xt%s]\n",((struct typerec PTR)((listnode)l->data)->data)->typebody.var_type->name);
		else
			printf("push %d #static type id\n",((struct typerec PTR)((listnode)l->data)->data)->typeid);

		if(((listnode)l->data)->next->attr==VARTYPEL)
			printf("push [xt%s]\n",((struct typerec PTR)((listnode)l->data)->next->data)->typebody.var_type->name);
		else
			printf("push %d #static type id\n",((struct typerec PTR)((listnode)l->data)->next->data)->typeid);

		printf("call x_dyn_type_conv\njnz %s\n",get_local_label(local_buf,labels,LABELREQ));
		};
	printf("lab%s:\n",get_local_label(local_buf,labels,LABELDEF));
	print_asm_output((listnode)lst->next->next,labels,vars,types,fnlist);
	return;
	};
if(!Strncmp(lst->data,"\4vartype",8))
	{
	if(lst->next->next->next->attr==FUNCTION)	
		print_asm_output(lst->next->next->next,labels,vars,types,fnlist);
	else if(lst->next->next->next->attr==TWOLISTS)
		print_asm_output((listnode)lst->next->next->next->data,labels,vars,types,fnlist);
	else
		printf("push word ptr [v%s]\n",lst->next->next->next->data);

	if(lst->data[8]=='v')
		printf("push [xt%s]\n",((struct typerec PTR)lst->next->data)->typebody.var_type->name);
	else
		printf("push %d #static type id\n",((struct typerec PTR)lst->next->data)->typeid);

	if(lst->data[9]=='v')
		printf("push [xt%s]\n",((struct typerec PTR)lst->next->next->data)->typebody.var_type->name);
	else
		printf("push %d #static type id\n",((struct typerec PTR)lst->next->next->data)->typeid);

	printf("call x_dyn_type_conv\njz x_gen_except_wrong_type\n");
	return;
	};

if(!Strcmp(lst->data,"\4objpart"))
	{
	if(lst->next->attr==TWOLISTS)
		{
		print_asm_output((listnode)lst->next->data,labels,vars,types,fnlist);
		printf("mov bx, word ptr [bp+__FIRS_ARG_IN_HEADER]\n");
		}
	else
		printf("mov bx, o%s\n",lst->next->data);

	if(lst->next->next->attr!=TWOLISTS)
		printf("push [bx+O%s]\n",lst->next->next->data);
	else
		{
		printf("push [bx] ; object itself as a first arg\n");
		if(*((listnode)lst->next->next->data)->data==4)
			{
			print_asm_output((listnode)lst->next->next->data,labels,vars,types,fnlist);
			return;
			};
		for(l=((listnode)lst->next->next->data)->next;l!=NULL;l=l->next)
			if(l->attr==TWOLISTS)
				{
				sprintf(local_buf,"\4tmpvar%lX",loc_tmp_count);
				printf("%s EQU [bp+%ld]\npush word ptr __asm_NULL\n",local_buf,loc_tmp_count);
				print_asm_output((listnode)l->data,labels,vars,types,fnlist);
				rm_lnd_all((listnode)l->data);
				l->attr=ASSOCVAR;
				Strcpy(l->data,local_buf);
				}
			else
				{
				if(*l->data==4)
					printf("push word ptr %s\n",(l->data+1));
				else if(isnum(*l->data))
					printf("mov ax, %s\npush ax\n",l->data);
				else
					printf("push word ptr v%s\n",l->data);
				};

		if(*((listnode)lst->next->next->data)->data!=4)
			printf("call [bx+O%s]\n",((listnode)lst->next->next->data)->data);
		else
			printf("call [bx+%s]\n",((listnode)lst->next->next->data)->data+2);
		};
	return;
	};


for(l=lst->next;l!=NULL;l=l->next)
	if(l->attr==TWOLISTS)
		{
		if(((listnode)l->data)->attr==FUNCTION)
			{
			sprintf(local_buf,"\4tmpvar%lX",loc_tmp_count);
			printf("%s EQU [bp+%ld]\npush word ptr __asm_NULL\n",local_buf,loc_tmp_count);
			};
		print_asm_output((listnode)l->data,labels,vars,types,fnlist);
		rm_lnd_all((listnode)l->data);
		l->attr=ASSOCVAR;
		l->data=Strdup(local_buf);
		}
	else
		if(*l->data==4)
			printf("push word ptr [%s]\n",(l->data+1));
		else if(isnum(*l->data))
			printf("mov ax, %s\npush ax\n",l->data);
		else
			printf("push word ptr [v%s]\n",l->data);

/* printf("push bp\nmov bp, sp\n"); */
if(!Strncmp("\4_",lst->data,2))
	printf("call %s\n",lst->data+2);
else
	printf("call _%s\n",lst->data);
/* printf("mov sp, bp\npop bp\n"); */
};


void mk_asm_output(listnode lst, listnode labels,struct vardecl_listoflist PTR vars, struct type_listoflist PTR types,listnode fnlist)
{

if(validate_function(lst,fnlist,vars,types,labels,0)==NULL)
	{
	fprintf(stderr,"Types doesnt match, aborting !\n");
	return;
	};

print_asm_output(lst,labels,vars,types,fnlist);

};








/*void var_name_cross_ref(listnode lst,listnode vars)
{
listnode l1;

if (lst==NULL) return ;

while((lst!=NULL))
	{
	if (lst->attr==ASSOCVAR)
		{
		for(l1=vars;l1->next!=NULL;l1=l1->next)
			if(!Strcmp(l1->data,lst->data))
				break; // already in the list 
		if ((l1->next==NULL)&(!!Strcmp(l1->data,lst->data)))
			{
			l1->next=mk_listnode(NULL);
			Memset(l1->next->data,0,34);
			Strcpy(l1->next->data,lst->data);
			l1->next->attr=VARIABLE;
			};
		};
	if ((lst->attr==TWOLISTS)||(lst->attr==FUNCAVAR))
		var_name_cross_ref((listnode) lst->data, vars);
	lst=lst->next;
	};
};*/
/*opdef_arr oda;*/

struct op_definition zzz;
struct op_definition inlinetest1;
struct op_definition inlinetest2;
struct op_definition jnk1;
struct op_definition jnk2;

defined_op d_op;
inline_op i_op;

listnode opclist;
int xx;

char inputstr[200];
char * istr;
listnode l1,l2,l3,l4;
struct typerec PTR intptr,PTR charptr,PTR xstrptr,PTR xclsptr,PTR dtypeptr;

main()
{


struct vardecl_listoflist vars;
struct type_listoflist types;
/****************************************************************************/
struct fundef_list x,y;
struct type_list main_type_list;
struct type_list PTR tlptr;
x.fundef=my_malloc(sizeof(struct fundef));
/*y.fundef=my_malloc(sizeof(struct fundef));*/
x.fundef->name="int";
x.fundef->def_to_use.name_in_code="B_char_to_int";
x.fundef->args=my_malloc(sizeof(struct vardecl_list));/*argdef));*/
x.fundef->args->var=my_malloc(sizeof(struct var_decl));
x.fundef->args->var->name="x";
x.fundef->args->next=NULL;
x.next=NULL;
/*x.other=NULL;
  y.fundef->name="somekindofdata";
  y.fundef->args=my_malloc(sizeof(struct argdef));
  y.fundef->args->next=NULL;
  y.next=NULL;
  y.other=NULL; */
main_type_list.next=NULL;
main_type_list.convert_lock=OFF;
main_type_list.type=my_malloc(sizeof(struct typerec));
main_type_list.type->typekind=BUILT_IN;
main_type_list.type->typemodf=NONE;
main_type_list.type->typebody.built_in=_lpsdata;
main_type_list.type->name="somekindofdata";
main_type_list.type->typeconv=&y;
main_type_list.type->size=10;
/****************************************************************************/


/*x.fundef->args->type=main_type_list.type;*/

tlptr=install_type((struct type_list PTR)&main_type_list,1,(char PTR)"char",BUILT_IN,NONE,__char__,NULL);

charptr=tlptr->type;

x.fundef->args->var->type=tlptr->type;

dtypeptr=install_type((struct type_list PTR)&main_type_list,1,"dtype",VAR_TYPE,NONE,__char__,NULL)->type;

install_type((struct type_list PTR)&main_type_list,1,"type",VAR_TYPE,NONE,__char__,NULL);

intptr=install_type((struct type_list PTR)&main_type_list,2,(char PTR)"int",BUILT_IN,NONE,__int___,(struct fundef_list PTR)&x)->type;

install_type((struct type_list PTR)&main_type_list,1,(char PTR)"void",BUILT_IN,POINTER,__void__,NULL);

tlptr=install_type((struct type_list PTR)&main_type_list,1,(char PTR)"xstr",STRUCT,NONE,__void__,NULL);
tlptr->type->typebody.struct_def=my_malloc(sizeof(struct struct_def));
tlptr->type->typebody.struct_def->tag="xstrtag";
tlptr->type->typebody.struct_def->fields=my_malloc(sizeof(struct vardecl_list));
tlptr->type->typebody.struct_def->fields->var=my_malloc(sizeof(struct var_decl));
tlptr->type->typebody.struct_def->fields->var->name="xstrmem";
tlptr->type->typebody.struct_def->fields->next=NULL;
tlptr->type->typebody.struct_def->fields->var->type=intptr;

xstrptr=tlptr->type;

/*----------------*/

tlptr=install_type((struct type_list PTR)&main_type_list,1,"xcls",CLASS,NONE,__void__,NULL);
tlptr->type->typebody.class_def=my_malloc(sizeof(struct class_def));
tlptr->type->typebody.class_def->name="xcls";
tlptr->type->typebody.class_def->constructors=NULL;
tlptr->type->typebody.class_def->destructors=NULL;
/*tlptr->type->typebody.class_def->modif_lst=NULL;*/
tlptr->type->typebody.class_def->funcs=my_malloc(sizeof(struct fundef_list));
tlptr->type->typebody.class_def->funcs->next=NULL;
tlptr->type->typebody.class_def->vars=my_malloc(sizeof(struct vardecl_list));
tlptr->type->typebody.class_def->vars->var=my_malloc(sizeof(struct var_decl));
tlptr->type->typebody.class_def->vars->next=NULL;
tlptr->type->typebody.class_def->vars->var->name="cmem";
tlptr->type->typebody.class_def->vars->var->type=intptr;

tlptr->type->typebody.class_def->top_class=my_malloc(sizeof(struct type_list));
tlptr->type->typebody.class_def->top_class->next=NULL;
tlptr->type->typebody.class_def->top_class->type=intptr;/*get_type_by_name("int",NONE,&main_type_list);*/

xclsptr=tlptr->type;


for(tlptr=(struct type_list PTR)&main_type_list;tlptr!=NULL;tlptr=tlptr->next)
	printf("Installed type %s : %d, convert lock is %s\n",(char PTR)tlptr->type->name,tlptr->type->typemodf,(tlptr->convert_lock==OFF)?"OFF":"ON");
/*	while(kbhit()) getch();
	while(!kbhit());
	while(kbhit()) getch(); */


	d_op=&zzz;
	zzz.form="fx";
	zzz.defn="! xx";
	zzz.prec=550;
	zzz.attr=OPD_NONE;
	zzz.vars=NULL;
	zzz.prev=NULL;
	l1=mk_set_lnd(NULL,NULL,VARIABLE);
	get_function("not(xx)",l1,NULL,NULL,0,NULL,NULL,NULL);
	zzz.fdef.opdef=l1->next;
	Free(l1);

	zzz.next=my_malloc(sizeof(defined_op)); /* buffer - junk */
	zzz.next->next=NULL;
	zzz.next->form=NULL;
	zzz.next->defn=NULL;
	zzz.next->vars=NULL;
	zzz.next->prec=0;
	zzz.next->attr=STOP_XOP; /* Never match */
	zzz.next->prev=&zzz;
	zzz.next->fdef.opdef=NULL;


	i_op=&inlinetest1;
	inlinetest1.form="fxfc";
	inlinetest1.defn="while xx do cc";
	inlinetest1.prec=500;
	inlinetest1.attr=OPD_NONE;
	inlinetest1.prev=NULL;
	inlinetest1.fdef.inlfun=my_malloc(sizeof(struct inline_fun_rec));
	inlinetest1.fdef.inlfun->labels=mk_set_lnd(NULL,mk_set_lnd(NULL,"_start_",PARTOFOP),LABELREQ);
	mk_set_lnd(inlinetest1.fdef.inlfun->labels,mk_set_lnd(NULL,"_end_while_",PARTOFOP),LABELREQ);

/*tmp	inlinetest1.fdef->args=my_malloc(sizeof(struct inline_varinfo));
//tmp	inlinetest1.fdef->args->next=my_malloc(sizeof(struct inline_varinfo));
//tmp	inlinetest1.fdef->args->next->next=NULL;
//tmp	inlinetest1.fdef->args->times_used=1;
//tmp	inlinetest1.fdef->args->next->times_used=1;
//tmp	Strcpy(inlinetest1.fdef->args->name,"xx");
//tmp	Strcpy(inlinetest1.fdef->args->next->name,"cc");*/

	inlinetest1.fdef.inlfun->args=insert_var_decl(NULL,"xx",intptr,NULL,0);
	insert_var_decl(inlinetest1.fdef.inlfun->args,"cc",NULL,NULL,0);
	inlinetest1.fdef.inlfun->subfunctions= &inlinetest2; /*NULL;*/
	inlinetest1.vars=inlinetest1.fdef.inlfun->args;

	inlinetest2.form="f";
	inlinetest2.defn="break";
	inlinetest2.prec=500;
	inlinetest2.attr=OPD_NONE;
	inlinetest2.prev=NULL;
	inlinetest2.fdef.inlfun=my_malloc(sizeof(struct inline_fun_rec));
	inlinetest2.fdef.inlfun->labels=NULL;
	inlinetest2.fdef.inlfun->args=NULL;	/*tmp*/
	inlinetest2.vars=NULL; 		/*tmp*/
	inlinetest2.fdef.inlfun->subfunctions=NULL;

/*	inlinetest2.next=my_malloc(sizeof(inline_op)); // buffer - junk */
	inlinetest2.next=&jnk2;
	inlinetest2.next->next=NULL;
	inlinetest2.next->form=NULL;
	inlinetest2.next->defn=NULL;
	inlinetest2.next->prec=0;
	inlinetest2.next->attr=STOP_XOP; /* Never match */
	inlinetest2.next->prev=&inlinetest2;
	inlinetest2.next->fdef.inlfun=NULL;

/*	inlinetest1.next=my_malloc(sizeof(inline_op)); // buffer - junk */
	inlinetest1.next=&jnk1;
	inlinetest1.next->next=NULL;
	inlinetest1.next->form=NULL;
	inlinetest1.next->defn=NULL;
	inlinetest1.next->prec=0;
	inlinetest1.next->attr=STOP_XOP; /* Never match */
	inlinetest1.next->prev=i_op;
	inlinetest1.next->fdef.inlfun=NULL;




/*	oda=(opdef_arr) &y;

	*oda=d_op; */

	finstall_opd(d_op,"xf","xx ++","inc1(xx)",OPD_NONE,550);
	finstall_opd(d_op,"xf","xx --","dec1(xx)",OPD_NONE,550);
/*temp	finstall_opd(d_op,"fx","-- xx","sub1(xx)",OPD_NONE,550);
//temp	finstall_opd(d_op,"fx","++ xx","add1(xx)",OPD_NONE,550);
	install_opd(d_op,"fx","! xx",0,550); */
	finstall_opd(d_op,"xfx","xx + yy","add(xx,yy)",0,350);
	finstall_opd(d_op,"xfx","xx - yy","sub(xx,yy)",0,350);
	finstall_opd(d_op,"xfx","xx * yy","mul(xx,yy)",0,450);
	finstall_opd(d_op,"fx","* yy","derefr(yy)",0,450);
	finstall_opd(d_op,"xfx","xx / yy","div(xx,yy)",0,450);
/*temp	finstall_opd(d_op,"xfx","xx & yy","and(xx,yy)",0,550);
//temp	finstall_opd(d_op,"xfx","xx || yy","or(xx,yy)",0,550);
//temp	finstall_opd(d_op,"xfx","xx ^ yy","pow(xx,yy)",0,550);
//	install_opd(d_op,"fxf","sizeof( xx )",0,550);
//temp	finstall_opd(d_op,"flfxf","[ ll | xx ]","listpart(xx,ll)",0,550);
//temp	finstall_opd(d_op,"flf","[ ll ]","makelist(ll)",0,550);
//temp	finstall_opd(d_op,"xfx","dst = src","setv(dst,src)",0,50); */
	finstall_opd(d_op,"xfx","xx == yy","iseq(xx,yy)",0,150);
	finstall_opd(d_op,"xfx","dst = src","assign1(dst,src)",0,150);
	finstall_opd(d_op,"xfx","xx != yy","isnoteq(xx,yy)",0,150);
	finstall_opd(d_op,"fx","goto lab","\4goto(lab)",NOTYPECK,750);
	finstall_opd(d_op,"xfx","obj -> part","\4objpart(obj,part)",NOTYPECK,6001);
/*temp	finstall_opd(d_op,"xfx","xx += yy","sadd(xx,yy)",0,340);
//temp	finstall_opd(d_op,"xfx","xx -= yy","ssub(xx,yy)",0,340);
//	finstall_opd(d_op,"xfx","xx *= yy","smul(xx,yy)",0,350);
//	finstall_opd(d_op,"xfx","xx /= yy","sdiv(xx,yy)",0,350);

//	install_opd((defined_op) i_op,"fc","zzcode cc",0,550); */


	print_opd(d_op);

	printf("%d definitions\n",opdef_count(d_op));

/*	printf("Variable cc used %d times in inline\n",get_inl_varinfo("cc",inlinetest1.fdef->args)); */
	vars.next=NULL;
	/*
	vars.vlist=my_malloc(sizeof(struct vardecl_list));
	vars.vlist->next=NULL;
	vars.vlist->var=my_malloc(sizeof(struct var_decl));
	vars.vlist->var->name="some_var";
	vars.vlist->var->type=intptr;//get_type_by_name("int",NONE,&main_type_list);
	*/
	vars.vlist=NULL;
	types.next=NULL;
	types.tlist=&main_type_list;

	vars.vlist=insert_var_decl(NULL,"dtidvar",NULL,NULL,0);

	dtypeptr->typebody.var_type=vars.vlist->var;	

	intptr->typeconv=(struct fundef_list PTR)&x;

	strcpy(global_buf,"{\4goto(_end_while_)}");

	memmove(inputstr,global_buf,64);
	global_bufptr+=64;
	l1=mk_set_lnd(NULL,NULL,VARIABLE);

	l2=mk_set_lnd(NULL,mk_set_lnd(NULL,NULL,LABELDEF),TWOLISTS);
	l3=mk_set_lnd(NULL,mk_set_lnd(NULL,NULL,LABELDEF),TWOLISTS);
	get_code_block(inputstr,l1,mk_set_lnd(NULL,NULL,INLINSUB),d_op,l2,l3,NULL,NULL,NULL,1);
	rm_lnd_all(l2);
	rm_last_node(l1);
	inlinetest2.fdef.inlfun->body=l1->next;

	global_bufptr=global_buf;
	strcpy(global_buf,"{\4label(_start_);\4check(xx);\4ifjmp(_end_while_);\4runcode(cc);\4goto(_start_);\4label(_end_while_)}");

	memmove(inputstr,global_buf,64);
	global_bufptr+=64;
	l1->next=NULL;

	l2=mk_set_lnd(NULL,mk_set_lnd(NULL,NULL,LABELDEF),TWOLISTS);
	rm_lnd_all(l3);
	l3=mk_set_lnd(NULL,mk_set_lnd(NULL,NULL,LABELDEF),TWOLISTS);
	get_code_block(inputstr,l1,mk_set_lnd(NULL,NULL,INLINSUB),d_op,l2,l3,NULL,NULL,NULL,1);
	rm_lnd_all(l2);
	rm_last_node(l1);
	inlinetest1.fdef.inlfun->body=l1->next;

	printf("\nString to match <=:");

	global_bufptr=global_buf;
	while((*(global_bufptr++)=getchar())!=27);
	*global_bufptr=0;
	for(global_bufptr=global_buf;*global_bufptr;global_bufptr++)
		*global_bufptr=((*global_bufptr=='\n')? ' ' : *global_bufptr);
	global_bufptr=global_buf;
/*	global_bufptr+=64;*/ /* inputstr size shift */

/*	memmove(inputstr,global_buf,64);*/
	istr=create_new_buffer(NULL,64);

	l4=mk_set_lnd(NULL,my_malloc(sizeof(struct fundef_list)),FUNCDEFN);
	((struct fundef_list PTR)l4->data)->next=my_malloc(sizeof(struct fundef_list));
	((struct fundef_list PTR)l4->data)->fundef=my_malloc(sizeof(struct fundef));
	((struct fundef_list PTR)l4->data)->fundef->attr=IS_EXPR;
	((struct fundef_list PTR)l4->data)->fundef->def_to_use.name_in_code=Strdup("do_add_one");
	((struct fundef_list PTR)l4->data)->fundef->name=Strdup("inc1");/*"inc1";*/
	((struct fundef_list PTR)l4->data)->fundef->res_type=intptr;
	((struct fundef_list PTR)l4->data)->fundef->args=my_malloc(sizeof(struct vardecl_list));
	((struct fundef_list PTR)l4->data)->fundef->args->var=my_malloc(sizeof(struct var_decl));
	((struct fundef_list PTR)l4->data)->fundef->args->var->name="x";
	((struct fundef_list PTR)l4->data)->fundef->args->var->type=intptr;
	((struct fundef_list PTR)l4->data)->fundef->args->next=NULL;

	((struct fundef_list PTR)l4->data)->next->next=NULL;
	((struct fundef_list PTR)l4->data)->next->fundef=my_malloc(sizeof(struct fundef));
	((struct fundef_list PTR)l4->data)->next->fundef->attr=IS_EXPR;
	((struct fundef_list PTR)l4->data)->next->fundef->def_to_use.name_in_code=Strdup("do_assign1");
	((struct fundef_list PTR)l4->data)->next->fundef->name="assign1";
	((struct fundef_list PTR)l4->data)->next->fundef->res_type=intptr;
	((struct fundef_list PTR)l4->data)->next->fundef->args=my_malloc(sizeof(struct vardecl_list));
	((struct fundef_list PTR)l4->data)->next->fundef->args->var=my_malloc(sizeof(struct var_decl));
	((struct fundef_list PTR)l4->data)->next->fundef->args->var->name="dst";
	((struct fundef_list PTR)l4->data)->next->fundef->args->var->type=intptr;
	((struct fundef_list PTR)l4->data)->next->fundef->args->next=NULL;

	xclsptr->typebody.class_def->funcs->fundef=my_malloc(sizeof(struct fundef));
	xclsptr->typebody.class_def->funcs->fundef->name="xcls";
	xclsptr->typebody.class_def->funcs->fundef->attr=IS_FEXPR;
	xclsptr->typebody.class_def->funcs->fundef->def_to_use.name_in_code=Strdup("code_xclsfunc1");
	xclsptr->typebody.class_def->funcs->fundef->res_type=charptr;
	xclsptr->typebody.class_def->funcs->fundef->args=my_malloc(sizeof(struct vardecl_list));
	xclsptr->typebody.class_def->funcs->fundef->args->var=my_malloc(sizeof(struct var_decl));
	xclsptr->typebody.class_def->funcs->fundef->args->var->name="xc";
	xclsptr->typebody.class_def->funcs->fundef->args->var->type=intptr;
	xclsptr->typebody.class_def->funcs->fundef->args->next=NULL;

	l1->next=NULL;
	l2=mk_set_lnd(NULL,mk_set_lnd(NULL,NULL,LABELDEF),TWOLISTS);
	if (!(xx=get_code_block(istr,l1,mk_set_lnd(NULL,i_op,INLINSUB),d_op,l2,l3,(struct vardecl_listoflist PTR) &vars, (struct type_listoflist PTR) &types,l4,0)))
		printf("No compare\n");

	printf("\n%s was used as a string, %s left.\n%d definitions in base.\nThis is what function returned into the list :\n",inputstr,xx-strlen(inputstr)?(inputstr+xx):"nothing",opdef_count(d_op));

/*	while(kbhit()) getch();
//	while(!kbhit());
//	while(kbhit()) getch();*/

	l1=l1->next;
	printlist2(l1,0,1);
	printf("Total %d listnodes.\n",lnd_count(l1));

/*	while(kbhit()) getch();
//	while(!kbhit());
//	while(kbhit()) getch(); */

	printf("Labels left/resolved :\n->Inline:\n");
	printlist2(l2,0,1);
	printf("->Block:\n");
	printlist2(l3,0,1);
	rm_lnd_all(l3);
	rm_lnd_all(l2);

/*	while(kbhit()) getch();
//	while(!kbhit());
//	while(kbhit()) getch(); */

return 0;
};

