Ejemplo n.º 1
0
/*	===== tls_access_first =========================================================
	PRIVATE. Get access to the first entry/exit structure.
	================================================================================	*/
_tls_entry_exit_t* tls_access_first (bool bEntry)
	{
	_tls_entry_exit_t* p ;

	tls_entry_exit_mutex_p () ;
		{
		//	Get new reference on the first.
		if (bEntry)	// bEntry == PROC_ENTRY
			p = new_reference (gm_entry_proc_list) ;
		else 		// bEntry == PROC_EXIT
			p = new_reference (gm_exit_proc_list) ;
		}
	tls_entry_exit_mutex_v () ;

	return p ;
	}
Ejemplo n.º 2
0
/*	===== tls_create_entry_exit ====================================================
	PRIVATE. Allocate a new entry/exit structure, and insert it.
	================================================================================	*/
status_t tls_create_entry_exit (bool bEntry, tls_proc_t proc, int param)
	{
	_tls_entry_exit_t* p ;

	//	Check parameters.
	if (proc == NULL) return B_BAD_VALUE ;

	//	Allocate structure, and initialize it.
	p = (_tls_entry_exit_t*) malloc (sizeof (_tls_entry_exit_t)) ;
	if (p == NULL) return B_NO_MEMORY ;
	p->useCount 	= 0 ;
	p->proc 		= proc ;
	p->param 		= param ;
	p->next 		= NULL ;

	//	Insert structure in the right list.
	//	Note: list are processed IN the mutex zone, so we dont care of
	//		managing useCount values.
	tls_entry_exit_mutex_p () ;
		{
		if (bEntry)	// bEntry == PROC_ENTRY
			{
			//	Structures are inserted at the end of the list.
			//	Use the well known algorithm which use list pointer links
			//	address in place of value, to reach the last link address and
			//	be able to update it.
			_tls_entry_exit_t** ppNext = &gm_entry_proc_list ;
			while (*ppNext != NULL)
				ppNext = &((*ppNext)->next) ;
			*ppNext = new_reference (p) ;
			}
		else		// bEntry == PROC_EXIT
			{
			//	Structures are inserted at the begining of the list.
			p->next = gm_exit_proc_list ;
			gm_exit_proc_list = new_reference (p) ;
			}
		}
	tls_entry_exit_mutex_v () ;

	//	Finish.
	return B_NO_ERROR ;
	}
Ejemplo n.º 3
0
/*	===== tls_access_next ==========================================================
	PRIVATE. Get access to the next entry/exit structure.
		Loose access to the current entry/exit structure.
	================================================================================	*/
_tls_entry_exit_t* tls_access_next (_tls_entry_exit_t* pCurrent)
	{
	_tls_entry_exit_t* p ;

	if (!pCurrent) return NULL ;

	tls_entry_exit_mutex_p () ;
		{
		//	Get new reference on next.
		p = new_reference (pCurrent->next) ;
		//	Release reference on current.
		release_reference (pCurrent) ;
		}
	tls_entry_exit_mutex_v () ;

	return p ;
	}
Ejemplo n.º 4
0
intercodes translate_array(struct Node *node,operand place,union varp *list,enum varType *listtype) {
	struct Node *child = node->child;
	assert(child != NULL);
	intercodes code1 = NULL;
	intercodes code2,code3,code4;
	int size = 0;
	operand t1;
	//ID[Exp]
	if (strcmp(child->sibling->type,"ID") == 0) {
		int id = getVarID(child->child);
		int flag = getFlag(child->child->text);
		if (flag == 1)
			t1 = new_var(id);
		else 
			t1 = new_reference(id);
		enum varType type;
		union varp vp = getVar(child->child,&type);
		if (vp.ap->basetype == varStruct) 
			size = get_structure_size(vp.ap->base,vp.ap->basetype);
		if (vp.ap->basetype == varInt || vp.ap->basetype == varFloat) 
			size = 4;
		if (list != NULL) {
			*list = vp.ap->base;
			*listtype = vp.ap->basetype;
		}
	}
	//Exp[Exp][Exp]
//	if (child->child->sibling != NULL && strcmp(child->child->sibling->type,"LB") == 0) {
//	}
	//handle Exp2
	operand t2 = new_tmp();
	code2 = translate_Exp(child->sibling->sibling,t2);
	code1 = link(code1,code2);
	//calculate offset
	operand c1 = new_constant(size);
	operand t3 = new_tmp();
	code3 = gen_binop(MUL_K,t3,t2,c1);
	//Add array address
	operand t4 = new_tmp_id(place->u.tmp_no);
	code4 = gen_binop(ADD_K,t4,t1,t3);
	code1 = link(code1,code4);
	place->kind = ADDRESS;
	return code1;
}
Ejemplo n.º 5
0
void do_global (void)
{	char name[16];
	int r;
	header *hd;
	while (1)
	{	scan_space(); scan_name(name); r=xor(name);
		hd=(header *)udfend;
		if (hd==(header *)startlocal) break;
		while ((char *)hd<startlocal)
		{	if (r==hd->xor && !strcmp(hd->name,name)) break;
			hd=nextof(hd);
		}
		if ((char *)hd>=startlocal)
		{	output1("Variable %s not found!\n",name);
			error=160; return;
		}
		newram=endlocal;
		hd=new_reference(hd,name);
		newram=endlocal=(char *)nextof(hd);
		scan_space();
		if (*next!=',') break;
		else next++;
	}
}
Ejemplo n.º 6
0
void do_for (void)
/***** do_for
	do a for command in a UDF.
	for i=value to value step value; .... ; end
*****/
{	int h,signum;
	char name[16],*jump;
	header *hd,*init,*end,*step;
	double vend,vstep;
	struct { header hd; double value; } rv;
	if (!udfon)
	{	output("For only allowed in functions!\n"); error=57; return;
	}
	rv.hd.type=s_real; *rv.hd.name=0;
	rv.hd.size=sizeof(header)+sizeof(double); rv.value=0.0;
	scan_space(); scan_name(name); if (error) return;
	kill_local(name);
	newram=endlocal;
	hd=new_reference(&rv.hd,name); if (error) return;
	endlocal=newram=(char *)hd+hd->size;
	scan_space(); if (*next!='=')
	{	output("Syntax error in for.\n"); error=71; goto end;
	}
	next++; init=scan(); if (error) goto end;
	init=getvalue(init); if (error) goto end;
	if (init->type!=s_real)
	{	output("Startvalue must be real!\n"); error=72; goto end;
	}
	rv.value=*realof(init);
	scan_space(); if (strncmp(next,"to",2))
	{	output("Endvalue missing in for!\n"); error=73; goto end;
	}
	next+=2;
	end=scan(); if (error) goto end;
	end=getvalue(end); if (error) goto end;
	if (end->type!=s_real)
	{	output("Endvalue must be real!\n"); error=73; goto end;
	}
	vend=*realof(end);
	scan_space();
	if (!strncmp(next,"step",4))
	{	next+=4;
		step=scan(); if (error) goto end;
		step=getvalue(step); if (error) goto end;
		if (step->type!=s_real)
		{	output("Stepvalue must be real!\n"); error=73; goto end;
		}
		vstep=*realof(step);
	}
	else vstep=1.0;
	signum=(vstep>=0)?1:-1;
	vend=vend+signum*epsilon;
	if (signum>0 && rv.value>vend) { scan_end(); goto end; }
	else if (signum<0 && rv.value<vend) { scan_end(); goto end; }
	newram=endlocal;
	scan_space(); if (*next==';' || *next==',') next++;
	jump=next;
	while (!error)
	{	if (*next==1)
		{	output("End missing!\n");
			error=401; goto end;
		}
		h=command();
		if (udfon!=1 || h==c_return) break;
		if (h==c_break) { scan_end(); break; }
		if (h==c_end)
		{	rv.value+=vstep;
			if (signum>0 && rv.value>vend) break;
			else if (signum<0 && rv.value<vend) break;
			else next=jump;
			if (test_key()==escape)
			{   output("User interrupted!\n");
				error=1; break;
			}
		}
	}
	end : kill_local(name);
}