示例#1
0
void generate_FUNCSTART(quad *q){
	SymbolTableEntry *f;
	instruction * t;
	if (funcStack == NULL) funcStack = newStack_func();

	if(q->result) f = q->result->sym;
	f->taddress = NEXTINSTRUCTIONLABEL;

	LIST_INSERT(f->returnList, LABELSTATEMENT(NEXTINSTRUCTIONLABEL), returnElem, ADD_2_BACK);

	q->taddress = NEXTINSTRUCTIONLABEL;

	LIST_INSERT(userFuncs, FUNCTIONSTATEMENT(f->taddress+1, f->totallocals, f->value.funcVal->name), userfunc, ADD_2_BACK);
	
	push_func(funcStack, f);
	totalUserFuncs++;

	t = (instruction *) malloc (sizeof(instruction));
	t->opcode = jump_v;
	RESET_OPERAND(&(t->arg1));
	RESET_OPERAND(&(t->arg2));
	t->result.type = label_a;
	emit_t(t);

	t = (instruction *) malloc (sizeof(instruction));
	t->srcLine= q->line;
	t->opcode = funcenter_v;
	if(q->result) make_operand(q->result, &(t->result));
	emit_t(t);
}
示例#2
0
void BucketSort(int* arr, int num)
{
	int max = 0x80000001, min = 0x7fffffff;
	ListNode* bucket[BUCKET_NUM_MAX] = {0};
	int bucketNum;
	int i;
	for (i = 0; i < num; i++) {
		if (arr[i] < min) min = arr[i];
		if (arr[i] > max) max = arr[i];
	}
	int gop = (max + BUCKET_NUM_MAX - min) / BUCKET_NUM_MAX;
	if (gop == 1) {
		bucketNum = max - min;
	}
	else {
		bucketNum = BUCKET_NUM_MAX;
	}
	int location;
	ListNode *node = nullptr, *cur = nullptr, *pre = nullptr;
	for (i = 0; i < num; i++) {
		location = (arr[i] - min) / gop;
		node = new ListNode(arr[i]);
		LIST_INSERT(bucket[location], node, cur, pre);
	}
	int j;
	for (i = 0, j = 0, cur = nullptr; i < bucketNum; i++) {
		cur = bucket[i];
		while (cur) {
			arr[j++] = cur->key;
			pre = cur;
			cur = cur->next;
			delete pre;
		}
	}
}
示例#3
0
void INSERT(Node* root,int i)
{

	if(root->l <= i  && root->u > i)
	{
		//printf("Here %d %d \n",root->l,root->u);
		if(root->list==NULL)
		{
			List* curr=malloc(sizeof(List));
			curr->data = i;
			//printf("ERROR \n");
			root->list=curr;
			//printf("ERROR \n");
			curr->next=NULL;
		}
		else
			LIST_INSERT(root->list,i);
		
	}
	else if(root->l > i)
	{
		INSERT(root->left,i);
	}
	else
		INSERT(root->right,i);
}
示例#4
0
void LIST_INSERT(List *node,int i)
{
	if(node->next==NULL)
	{	
		if(node->data>i)
		{
			List* curr=malloc(sizeof(List));
			curr->data = i;
			curr->next=node;
			node=curr;
			curr->next=NULL;
		}
		else
		{
			List* curr=malloc(sizeof(List));
			curr->data = i;
			node->next=curr;
			curr->next=NULL;
		}
		//printf("Goinf to insert \n");
		
	}
	if(node->data < i)
	{
		if(node->next->data < i)
		{
			LIST_INSERT(node->next,i);
		}
		else
		{
			List* curr=malloc(sizeof(List));
			curr->data = i;
			curr->next = node->next;
			node=curr;
		}
	}
	/*else
	{
		if()
	}
	else if(node->next->data > i)
	{
		List* curr=malloc(sizeof(List));
		curr->data = i;
		curr->next = node->next;
		node=curr;
	}
	else if(node->next==NULL)
	{
		List* curr=malloc(sizeof(List));
		curr->data = i;
		node->next=curr;
		curr->next=NULL;
	}
	else
		LIST_INSERT(node->next,i);*/
}
示例#5
0
void generate_relational (vmopcode op, quad *q){
	instruction *t = (instruction *) malloc (sizeof(instruction));
	q->taddress = NEXTINSTRUCTIONLABEL;
	t->srcLine= q->line;
	t->opcode = op;
	if(q->arg1) make_operand(q->arg1, &(t->arg1));
	if(q->arg2) make_operand(q->arg2, &(t->arg2));
	t->result.type = label_a;
	if(q->label < CURRPROCESSEDQUAD){
		t->result.val = Quads[q->label].taddress;
	} else {
		LIST_INSERT(ij_head, INCJMPSTATEMENT(NEXTINSTRUCTIONLABEL, q->label), incomplete_jump, ADD_2_FRONT);
	}
	emit_t(t);
}
示例#6
0
文件: mcl_list.c 项目: lishengwen/mcl
int mcl_list_insert(void *data, mcl_list *list_ptr)
{
	if (list_ptr->_list_sz >= MCL_LIST_MAX_SIZE) {
		fprintf(stderr, "list [%p] size beyond max size [%d]", list_ptr, MCL_LIST_MAX_SIZE);
		return 0;
	}

	mcl_list_node *node = (mcl_list_node *)malloc(sizeof(*node));

	node->_data = data;
	LIST_INSERT(&node->_entry, &list_ptr->_entries);
	++ list_ptr->_list_sz;

	return 1;
}
示例#7
0
void generate_RETURN(quad *q){
	SymbolTableEntry *f;
	instruction * t = (instruction *) malloc (sizeof(instruction));
	q->taddress = NEXTINSTRUCTIONLABEL;
	t->srcLine= q->line;
	t->opcode = assign_v;
	if(q->result) make_operand(q->result, &(t->arg1));
	make_retvaloperand(&(t->result));
	emit_t(t);

	f = top_func(funcStack);
	LIST_INSERT(f->returnList, LABELSTATEMENT(NEXTINSTRUCTIONLABEL), returnElem, ADD_2_BACK);

	t = (instruction *) malloc (sizeof(instruction));
	t->opcode = jump_v;
	RESET_OPERAND(&(t->arg1));
	RESET_OPERAND(&(t->arg2));
	t->result.type = label_a;
	emit_t(t);
}
s32int main()
{
  list_t list;
  STATIC_TYPE_LIST_INIT(list, u32int);

  //Test variables
  u32int test = 100, mid = 200, end = 300;
  u32int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  //Test variables

  LIST_INSERT_ARRAY(list, 0, arr + 1, 4);

  LIST_PUSH_BACK(list, test);
  LIST_PUSH_BACK(list, mid);
  LIST_PUSH_BACK(list, end);

  LIST_PUSH_FRONT(list, end);
  LIST_PUSH_FRONT(list, end);
  LIST_PUSH_FRONT(list, end);
  LIST_POP_BACK(list);

  LIST_INSERT(list, 1, mid);

  u32int foreachTmp;
  size_t sizer;

  LIST_FRONT(list, foreachTmp);
  printf("FRONT %d\n", foreachTmp);
  LIST_BACK_WITH_SIZE(list, foreachTmp, sizer);
  printf("BACK %d size %zu\n\n", foreachTmp, sizer);

  LIST_ERASE(list, 0);
  
  LIST_FOREACH(foreachTmp, list)
  {
    printf("Test %d\n", foreachTmp);
  }
示例#9
0
unsigned consts_newlibfunc(char *s){
	LIST_INSERT(namedLibfuncs, STRINGSTATEMENT(s), stringElem, ADD_2_BACK);
	return totalNamedLibfuncs++;
}
示例#10
0
unsigned consts_newnumber(double n){
	LIST_INSERT(numConsts, NUMBERSTATEMENT(n), numElem, ADD_2_BACK);
	return totalNumConsts++;
}
示例#11
0
unsigned consts_newstring(char *s){
	LIST_INSERT(stringConsts, STRINGSTATEMENT(s), stringElem, ADD_2_BACK);
	return totalStringConsts++;
}