コード例 #1
0
ファイル: Interpreter.c プロジェクト: marstau/shinsango
void Interpreter_Init(Interpreter *pinterpreter, LPCSTR name, List *pflist)
{
    memset(pinterpreter, 0, sizeof(Interpreter));
    StackedSymbolTable_Init(&(pinterpreter->theSymbolTable), name);
    Parser_Init(&(pinterpreter->theParser));
    pinterpreter->ptheFunctionList = pflist;
    List_Init(&(pinterpreter->theImportList));
    List_Init(&(pinterpreter->theInstructionList));
    List_Init(&(pinterpreter->paramList));
    Stack_Init(&(pinterpreter->theDataStack));
    Stack_Init(&(pinterpreter->theLabelStack));
    pp_context_init(&(pinterpreter->theContext));
}
コード例 #2
0
ファイル: utils.c プロジェクト: yuejoo/APEUFinal
int sperateCMD(char* in){
	int i=0;
	int len = strlen(in);
	/* flag to determine if we should skip the space in 
	   a string */
	int findQuote = 0;
	/* Stack to valid the quotes pair */
	Stack	stk;
	Stack_Init(&stk);

	for(; i<len; i++){
		if(in[i] == ' ' && !findQuote)
			in[i]='\0';
		if( in[i] == '\'' || in[i] == '\"' ){

			if( stk.size > 0 && Stack_Top(&stk) == in[i])
				Stack_Pop(&stk);
			else
				Stack_Push(&stk,in[i]);
			findQuote++;
			if(stk.size == 0)
				findQuote = 0;
			in[i] = '\0';
		}
	}
	return len;
}
コード例 #3
0
ファイル: blocks.c プロジェクト: 8l/openvmtil
void
CfrTil_TurnOnBlockCompiler ( )
{
    Compiler * compiler = _Context_->Compiler0 ;
    Compiler_SetState ( compiler, COMPILE_MODE, true ) ;
    Stack_Init ( compiler->WordStack ) ;
}
コード例 #4
0
//******************************************************************************************
//
//! \brief  Create An New Stack.
//!
//! \param  [in] StackSize is the size of stack.
//! \param  [in] UnitSize is the size of base element.
//! \retval The Pointer of new create stack.
//! \note   -# If StackSize <= UnitSize or memory allocate failure, this function will return
//!            with NULL pointer, So, Caller must check return pointer carefully.
//!
//! \note   -# You must enable USE_MEMORY_ALLOC macro and ensure your system have <stdlib.h>
//!            Header file before use this function.
//******************************************************************************************
Stack_t* Stack_Create(uint32_t StackSize, uint32_t UnitSize)
{
    Stack_t*  pStack         = NULL;         //!< Stack Pointer
    uint8_t*  pStackBaseAddr = NULL;         //!< Stack Memory Base Address

    //! Check stack parameters.
    ASSERT(StackSize > UnitSize);

    //! Allocate Memory for pointer of new stack.
    pStack = (Stack_t*) malloc(sizeof(Stack_t));
    if(NULL == pStack)
    {
        //! Allocate Failure, exit now.
        return (NULL);
    }

    //! Allocate memory for stack.
    pStackBaseAddr = malloc(StackSize);
    if(NULL == pStackBaseAddr)
    {
        //! Allocate Failure, exit now.
        return (NULL);
    }

    //! Initialize General Stack.
    Stack_Init(pStack, pStackBaseAddr, StackSize, UnitSize);

    return (pStack);
}
コード例 #5
0
ファイル: dataObjectNew.c プロジェクト: dennisj001/openvmtil
void
Class_Object_Init ( Word * word, Namespace * ns )
{
    DebugShow_Off ;
    Stack * nsstack = _Context_->Compiler0->NamespacesStack ;
    Stack_Init ( nsstack ) ; // !! ?? put this in Compiler ?? !!
    // init needs to be done by the most super class first successively down to the current class 
    do
    {
        Word * initWord ;
        if ( ( initWord = Word_FindInOneNamespace ( ns, ( byte* ) "init" ) ) )
        {
            _Stack_Push ( nsstack, ( int32 ) initWord ) ;
        }
        ns = ns->ContainingNamespace ;
    }
    while ( ns ) ;
    int32 i, * svDsp = Dsp ;
    //DebugShow_Off ;
    SetState ( _Debugger_, DEBUG_SHTL_OFF, true ) ;
    for ( i = Stack_Depth ( nsstack ) ; i > 0 ; i -- )
    {
        _Push ( ( int32 ) * word->W_PtrToValue ) ;
        Word * initWord = ( Word* ) _Stack_Pop ( nsstack ) ;
        _Word_Eval ( initWord ) ;
    }
    Dsp = svDsp ; // this seems a little too presumptive -- a finer tuned stack adjust maybe be more correct
    SetState ( _Debugger_, DEBUG_SHTL_OFF, false ) ;
    //DebugShow_StateRestore ;
}
コード例 #6
0
ファイル: Dispatch.cpp プロジェクト: Kallameet/TPG2
NTSTATUS Wdm1Create(IN PDEVICE_OBJECT fdo,
	IN PIRP Irp)
{
	PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp);
	DebugPrint("Create File is %T", &(IrpStack->FileObject->FileName));

	Stack_Init(&s);

	// Complete successfully
	return CompleteIrp(Irp, STATUS_SUCCESS, 0);
}
コード例 #7
0
ファイル: Cstack.c プロジェクト: ozzieem/UniCpp
int main()
{
	Stack_Init(&stack);

	Stack_Size(&stack);

	Stack_Push(&stack, 32);
	Stack_Push(&stack, 23);
	Stack_Push(&stack, 49);
	Stack_Push(&stack, 68);

	Stack_Peek(&stack);
	Stack_Pop(&stack);
	Stack_Pop(&stack);
	Stack_Pop(&stack);
	Stack_Pop(&stack);

	_getch();
}
コード例 #8
0
ファイル: list_test.c プロジェクト: xhnsworks/v-engine
void TestData_stack_uint_test(TestData _test)
{
    Stack _stk = Stack_new(Vptr);
    Stack stk = Stack_Init(_stk, Uint32);
    uint i = 0;

    for (; i < _test->count; i++)
    {
        _test->data[i].uint32_var = i;
    }

    for (i = 0; i < _test->count; i++)
    {
        Stack_push(stk, _test->data[i]);
    }
    for (i = 0; i < _test->count; i++)
    {
        if (Stack_find(stk, i)->uint32_var != _test->data[i].uint32_var)
        {
            printf("data error");
            getchar();
            exit(0);
        }
    }
    for (i = _test->count - 1; i; i--)
    {
        var tmp;
        Stack_pop(stk, &tmp);
        if (tmp.uint32_var != _test->data[i].uint32_var)
        {
            printf("data error");
            getchar();
            exit(0);
        }
    }

    Stack_Dest(stk);

    printf("test succ\n");
}
コード例 #9
0
ファイル: main.c プロジェクト: AnswerInTheWind/Data_Structure
int main()
{
    uint8_t len = 0;
    Stack_Init();
    Stack_PushData(temp_buf8,8);//0
    Stack_PushData(temp_buf9,9);//1
    Stack_PushData(temp_buf10,10);//2
    Stack_PushData(temp_buf11,11);//3
    Stack_PushData(temp_buf12,12);//4 12
    Stack_PushData(temp_buf13,13);//5 13
    Stack_PushData(temp_buf8,8);//6 64 //在不造成断包的情况下最大限度的拼包
    Stack_PushData(temp_buf8,8);//7 56
    Stack_PushData(temp_buf8,8);//8 48
    Stack_PushData(temp_buf8,8);//9 40
    Stack_PushData(temp_buf8,8);//0 32//由于之前的数据还未读取,此时又进行了写入操作,故之前的数据会被覆盖掉
    Stack_PushData(temp_buf8,8);//1 24
    Stack_PushData(temp_buf8,8);//2 16
    Stack_PushData(temp_buf8,8);//3 8  //因为帧的数量超过MAX_STACK_FRAME_NUM,也就是超过最大的栈存储帧数,所以之前的数据会丢失掉,如果希望调大,可以修改这个宏定义的大小

//    len += Stack_PopData(dest_buf+len);
//    len += Stack_PopData(dest_buf+len);
//    len += Stack_PopData(dest_buf+len);
//    len += Stack_PopData(dest_buf+len);
//    len += Stack_PopData(dest_buf+len);
//    len += Stack_PopData(dest_buf+len);

    while(Stack_GetFrameCount() >0)//如果栈中的帧未被取完,则一直取,直至取完
    {
        len = SpliceFrame(dest_buf);//将包取出,并且拼包
        printf_data(dest_buf,len);
    }

//    while(1)
//    {
//    }

    return 0;
}
コード例 #10
0
ファイル: quick_sort.cpp プロジェクト: luisfergromo/distrib
void SortArr(int *numbers)
{
	Stack_Init(&S);
	Stack_Push(&S,0,N);
	
	#pragma omp parallel 
	{
		#pragma omp single
		{
			while(Stack_Size(&S)>0)
			{
				struct LR data= Stack_Pop(&S);
				int l= data.L;
				int r= data.R;

				#pragma omp taskwait
				quickSort(numbers,l,r);
			}
			
		}
	}
	
}
コード例 #11
0
ファイル: stack.cpp プロジェクト: rodrigobmg/v-engine
Stack Stack_new(etype _value_type)
{
    Stack ret = (Stack)SMalloc(sizeof(stack));
    Stack_Init(ret, _value_type);
    return ret;
}
コード例 #12
0
ファイル: expr.c プロジェクト: mrc0mmand/ifj2015
int syntax_precedence()
{
	int i=1;

	Stack stack;
	Stack stack_index;

	Stack_Init(&stack_index);
	Stack_Init(&stack);

	stack_push(&stack, symbol_dollar);

	do
	{
		if(current_token.type == LEX_IDENTIFIER && !stable_search_scopes(&symbol_table, current_token.val, &ptr_data))
		{
			syntax_match(LEX_IDENTIFIER);
			if(current_token.type != LEX_LPAREN) {
				syntax_error_ec(IFJ_DEF_ERR, "Undefined variable");
			} else {
				return -1;
			}
		}


		if(stack_top(&stack) == 'E')
			i=2;
		else
			i=1;

		switch(precedence_table[stack_offset(&stack, i)][get_sign(&current_token)])
		{
			case '=':
				if((stack_top(&stack) == sign_lparen) && (get_sign(&current_token) == sign_rparen))
				{
					fprintf(stderr,"%s:() ilegal operation\n", __func__);
					exit(IFJ_SYNTAX_ERR);

				}
				stack_push(&stack, get_sign(&current_token));
				lex_get_token(&lex_data, &current_token);
				break;

			case '<':
				if(stack_top(&stack) == 'E')
				{
					stack_pop(&stack);
					stack_push(&stack, '<');
					stack_push(&stack, 'E');
					stack_push(&stack, get_sign(&current_token));

				}
				else
				{
					stack_push(&stack,'<');
					if((current_token.type == LEX_INTEGER) || (current_token.type == LEX_DOUBLE) || (current_token.type == LEX_STRING) || (current_token.type == LEX_LITERAL))
					{
						constant_check(&current_token, &stack_index);
					}
					else if(current_token.type == LEX_IDENTIFIER)
					{
						stable_search_scopes(&symbol_table, current_token.val, &ptr_data);
						int offset = symbol_table.active->stack_idx++;
						if(ptr_data->var.dtype == 0)
							curr_instr = instr_insert_after_instr(&instr_list, curr_instr, INSTR_MOVI, offset, ptr_data->var.offset, 0);
						else if(ptr_data->var.dtype == 1)
							curr_instr = instr_insert_after_instr(&instr_list, curr_instr, INSTR_MOVD, offset, ptr_data->var.offset, 0);
						else if(ptr_data->var.dtype == 2)
							curr_instr = instr_insert_after_instr(&instr_list, curr_instr, INSTR_MOVS, offset, ptr_data->var.offset, 0);
						stack_push(&stack_index, offset);
						final_index = offset;
					}
					stack_push(&stack, get_sign(&current_token));
				}

				lex_get_token(&lex_data, &current_token);
				break;

			/*
			   -----REDUCTION-----
			   according to rules that are described in expr.h
		   */	   

			case '>':
				//E->i
				if(stack_top(&stack) == symbol_id)
				{
					stack_pop(&stack);
					
					if(stack_top(&stack) == '<')
					{
						stack_pop(&stack);
						stack_push(&stack, 'E');
						//printf("Reduction rule E->i used\n");
					}
					else
					{
						fprintf(stderr,"%s: Precedence error in stack\n", __func__);
						exit(IFJ_SYNTAX_ERR);
					}
				}

				//E->(E)
				else if(stack_top(&stack) == sign_rparen)
				{
					stack_pop(&stack);
					if(stack_top(&stack) == 'E')
					{
						stack_pop(&stack);
						if(stack_top(&stack) == sign_lparen)
						{
							stack_pop(&stack);
							if(stack_top(&stack) == '<')
							{
								stack_pop(&stack);
								stack_push(&stack, 'E');
								//printf("Reduction rule E->(E) used\n");
							}
						}
					}
					else
					{
						fprintf(stderr,"%s: Precedence error in stack\n", __func__);
						exit(IFJ_SYNTAX_ERR);
					}

					
				}
				
				//E->E_sign_E
				else if(stack_top(&stack) == 'E')
				{
					stack_pop(&stack);

					switch(stack_top(&stack))
					{
						case sign_not_equal:
							type(&stack, &stack_index, INSTR_NEQ);
							break;

						case sign_equal:
							type(&stack, &stack_index, INSTR_EQ);
							break;

						case sign_greater_equal:
							type(&stack, &stack_index, INSTR_GTE);
							break;

						case sign_less_equal:
							type(&stack, &stack_index, INSTR_LTE);
							break;

						case sign_less:
							type(&stack, &stack_index, INSTR_LT);
							break;

						case sign_greater:
							type(&stack, &stack_index, INSTR_GT);
							break;

						case sign_slash:
							type(&stack, &stack_index, INSTR_DIV);
							break;

						case sign_times:
							type(&stack, &stack_index, INSTR_MUL);
							break;

						case sign_minus:
							type(&stack, &stack_index, INSTR_SUB);
							break;
						case sign_plus:
							type(&stack, &stack_index, INSTR_ADD);
							break;
						default:
							fprintf(stderr,"%s: Expected sign token\n", __func__);
							exit(IFJ_SYNTAX_ERR);
							break;
					}
				}
				
			case '#':

				/* Check for function call, if ID( then we will expect it to be function and return &current_token to syntax. analyator
				   */
				if(stack_top(&stack) == symbol_id)
				{
					if(get_sign(&current_token) == sign_lparen) {
						if(syntax_data.id != NULL) {
							free(syntax_data.id);
							syntax_data.id = ifj_strdup(current_token.val);
						}
						return -1; 
					}
					else
					{
						fprintf(stderr, "%s: Variable after variable is not allowed without sign between them\n", __func__);
						exit(IFJ_SEM_OTHER_ERR);
					}
				}
		}

		if(current_token.type == LEX_IDENTIFIER)
		{
			if(syntax_data.id != NULL)
			{
				free(syntax_data.id);
			}
			syntax_data.id = ifj_strdup(current_token.val);
		}
	}while(!(((stack_top(&stack) == 'E') && (stack_offset(&stack, 2) == symbol_dollar)) && ((get_sign(&current_token) == sign_rparen) || (current_token.type ==
						LEX_SEMICOLON))));

return final_index;	
}
コード例 #13
0
ファイル: dwarfclient.c プロジェクト: blucia0a/Legerdemain
static void decode_location(Dwarf_Locdesc *locationList, Dwarf_Signed listLength, long *offset, long *init_val, int *frameRel){

  /*Location Decoding Code from http://ns.dyninst.org/coverage/dyninstAPI/src/parseDwarf.C.gcov.html*/
  Stack *opStack = (Stack*)malloc(sizeof(Stack));
  Stack_Init(opStack);
  assert( listLength > 0 );
 
  if( listLength > 1 ) { fprintf( stderr, "Warning: more than one location, ignoring all but first.\n" ); }
 
  /* Initialize the stack. */
  if( init_val != NULL ) { Stack_Push(opStack, * init_val); }
 
  /* Variable can only become frame-relative by using the frame pointer operand. */
  if( frameRel != NULL ) { * frameRel = false; }
 
  /* Ignore all but the first location, for now. */
  Dwarf_Locdesc location = locationList[0];
  Dwarf_Loc * locations = location.ld_s;
  unsigned int i;
  for( i = 0; i < location.ld_cents; i++ ) {
    /* Handle the literals w/o 32 case statements. */
    if( DW_OP_lit0 <= locations[i].lr_atom && locations[i].lr_atom <= DW_OP_lit31 ) {
      //fprintf( stderr, "Pushing named constant: %d\n", locations[i].lr_atom - DW_OP_lit0 );
      Stack_Push(opStack, locations[i].lr_atom - DW_OP_lit0 );
      continue;
    }
 
    if( (DW_OP_breg0 <= locations[i].lr_atom && locations[i].lr_atom <= DW_OP_breg31) || locations[i].lr_atom == DW_OP_bregx ) {
      /* Offsets from the specified register.  Since we're not
         doing this at runtime, we can't do anything useful here. */
      fprintf( stderr, "Warning: location decode requires run-time information, giving up.\n" );
      *offset = -1;
      return;
    }
 
    if( (DW_OP_reg0 <= locations[i].lr_atom && locations[i].lr_atom <= DW_OP_reg31) || locations[i].lr_atom == DW_OP_regx ) {
      /* The variable resides in the particular register.  We can't do anything
         useful with this information yet. */
      fprintf( stderr, "Warning: location decode indicates register, giving up.\n" );
      *offset = -1;
      return;
    }
 
    switch( locations[i].lr_atom ) {
      case DW_OP_addr:
      case DW_OP_const1u:
      case DW_OP_const2u:
      case DW_OP_const4u:
      case DW_OP_const8u:
      case DW_OP_constu:
        // fprintf( stderr, "Pushing constant %lu\n", (unsigned long)locations[i].lr_number );
        Stack_Push(opStack, (Dwarf_Unsigned)locations[i].lr_number );
        break;
 
      case DW_OP_const1s:
      case DW_OP_const2s:
      case DW_OP_const4s:
      case DW_OP_const8s:
      case DW_OP_consts:
        // fprintf( stderr, "Pushing constant %ld\n", (signed long)(locations[i].lr_number) );
        Stack_Push(opStack, (Dwarf_Signed)(locations[i].lr_number) );
        break;
 
      case DW_OP_fbreg:
        /* We're only interested in offsets, so don't add the FP. */
        // fprintf( stderr, "Pushing FP offset %ld\n", (signed long)(locations[i].lr_number) );
        Stack_Push(opStack, (Dwarf_Signed)(locations[i].lr_number) );
        if( frameRel != NULL ) { * frameRel = true; }
        break;
 
      case DW_OP_dup:
        Stack_Push(opStack, Stack_Top(opStack) );
        break;
 
      case DW_OP_drop:
        Stack_Pop(opStack);
        break;
 
      case DW_OP_over: {
          long int first = Stack_Top(opStack); Stack_Pop(opStack);
          long int second = Stack_Top(opStack); Stack_Pop(opStack);
          Stack_Push(opStack, second ); Stack_Push(opStack, first ); Stack_Push(opStack, second );
        } break;
 
      case DW_OP_pick: {
        /* Duplicate the entry at index locations[i].lr_number. */
        Stack temp;
        Stack_Init(&temp);
        unsigned int i;
        for( i = 0; i < locations[i].lr_number; i++ ) {
          Stack_Push(&temp, Stack_Top(opStack) ); Stack_Pop(opStack);
        }
        long int dup = Stack_Top(opStack);
        for( i = 0; i < locations[i].lr_number; i++ ) {
          Stack_Push(opStack, Stack_Top(&temp) ); Stack_Pop(&temp);
        }
        Stack_Push(opStack, dup );
        } break;
 
      case DW_OP_swap: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, first ); Stack_Push(opStack, second );
      } break;
 
      case DW_OP_rot: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        long int third = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, first ); Stack_Push(opStack, third ); Stack_Push(opStack, second );
      } break;
 
      case DW_OP_deref:
      case DW_OP_deref_size:
      case DW_OP_xderef:
      case DW_OP_xderef_size:
        // fprintf( stderr, "Warning: location decode requires run-time information, giving up.\n" );
        * offset = -1;
        return;
 
      case DW_OP_abs: {
        long int top = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, abs( top ) );
        } break;
 
      case DW_OP_and: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, second & first );
      } break;
                  
      case DW_OP_div: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, second / first );
      } break;
 
      case DW_OP_minus: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, second - first );
      } break;
 
      case DW_OP_mod: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, second % first );
      } break;
 
      case DW_OP_mul: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, second * first );
      } break;
 
      case DW_OP_neg: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, first * (-1) );
      } break;
 
      case DW_OP_not: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, ~ first );
      } break;
 
      case DW_OP_or: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, second | first );
      } break;
 
      case DW_OP_plus: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, second + first );
      } break;
 
      case DW_OP_plus_uconst: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, first + locations[i].lr_number );
      } break;
 
      case DW_OP_shl: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, second << first );
      } break;
 
      case DW_OP_shr: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, (long int)((unsigned long)second >> (unsigned long)first) );
      } break;
 
      case DW_OP_shra: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, second >> first );
      } break;
 
      case DW_OP_xor: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, second ^ first );
      } break;
 
      case DW_OP_le: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, first <= second ? 1 : 0 );
      } break;
 
      case DW_OP_ge: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, first >= second ? 1 : 0 );
      } break;
 
      case DW_OP_eq: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, first == second ? 1 : 0 );
      } break;
 
      case DW_OP_lt: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, first < second ? 1 : 0 );
      } break;
 
      case DW_OP_gt: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, first > second ? 1 : 0 );
      } break;
 
      case DW_OP_ne: {
        long int first = Stack_Top(opStack); Stack_Pop(opStack);
        long int second = Stack_Top(opStack); Stack_Pop(opStack);
        Stack_Push(opStack, first != second ? 1 : 0 );
      } break;
 
      case DW_OP_bra:
        if( Stack_Top(opStack) == 0 ) { break; }
        Stack_Pop(opStack);
        break;/*Right?*/
      case DW_OP_skip: {
        int bytes = (int)(Dwarf_Signed)locations[i].lr_number;
        unsigned int target = locations[i].lr_offset + bytes;
 
        int j = i;
        if( bytes < 0 ) {
          for( j = i - 1; j >= 0; j-- ) {
            if( locations[j].lr_offset == target ) { break; }
          } /* end search backward */
        } else {
          for( j = i + 1; j < location.ld_cents; j ++ ) {
            if( locations[j].lr_offset == target ) { break; }
          } /* end search forward */
        } /* end if positive offset */
 
        /* Because i will be incremented the next time around the loop. */
        i = j - 1;
      } break;
 
      case DW_OP_piece:
        /* For multi-part variables, which we don't handle. */
        break;
 
      case DW_OP_nop:
        break;
 
      default:
        fprintf( stderr, "Unrecognized location opcode 0x%x, returning offset -1.\n", locations[i].lr_atom );
        *offset = -1;
        return;
    } /* end operand switch */
  } /* end iteration over Dwarf_Loc entries. */
 
  /* The top of the stack is the computed location. */
  //fprintf( stderr, "Location decoded: %ld\n", Stack_Top(opStack) );
  *offset = Stack_Top(opStack);
}  
コード例 #14
0
ファイル: ImmixGC.c プロジェクト: Sciss/scala-native
NOINLINE void scalanative_init() {
    Heap_Init(&heap, Settings_MinHeapSize(), Settings_MaxHeapSize());
    Stack_Init(&stack, INITIAL_STACK_SIZE);
    atexit(scalanative_afterexit);
}
コード例 #15
0
ファイル: calculator.c プロジェクト: Inventor22/Projects
/// <summary>
/// Evaluate_exps evaluates the specified expression.
/// </summary>
/// <param name="exp">The expression.</param>
/// <returns>The evaluated result</returns>
struct Result evaluate_expr(char* exp) {
    static const char* ods = "0123456789(";
    static const char* ops = "+-*/_"; // '_' is unary '-'
    struct Stack operands;
    struct Stack operators;
    Stack_Init(&operators);
    Stack_Init(&operands);

    removeSpaces(exp);
    findUnaryOperators(exp);

    //syslog(LOG_INFO, "parsing: %s", exp);

    int i;
    i = 0;
    while (exp[i] != '\0') {
        char c = exp[i++];
        if (strchr(ods, c) != NULL) { // if char == operand
            if (c == '(') {
                Stack_Push(&operators, c);
            } else {
                int iStart = i - 1;
                int iEnd = iStart;
                do {
                    c = exp[i++];
                } while (c != '\n' && isdigit(c));
                iEnd = --i;
                char num[MAX_DIGITS] = "";
                strncat(num, exp + iStart, iEnd - iStart);
                Stack_Push(&operands, atoi(num));
            }
        } else if (strchr(ops, c) != NULL) { // if char == operator
            int currentPres = getPrecendence(c);
            while (Stack_Size(&operators) > 0 &&
                   Stack_Size(&operands)  > 0 &&
                   currentPres < getPrecendence((char)Stack_Top(&operators))) {
                if (evaluate_next_operator(&operands, &operators) == DIVIDED_BY_0) {
                    return inf;
                }
            }
            Stack_Push(&operators, c);
        } else if (c == ')') {
            while (Stack_Top(&operators) != '(') {
                if (evaluate_next_operator(&operands, &operators) == DIVIDED_BY_0) {
                    return inf;
                }
            }
            Stack_Pop(&operators);
        }
    }

    while (Stack_Size(&operators) > 0) {
        if (evaluate_next_operator(&operands, &operators) == DIVIDED_BY_0) {
            return inf;
        }
    }

    int resultInt = Stack_Top(&operands);
    syslog(LOG_INFO, "Result: %d", resultInt);
    struct Result result = {resultInt, false};
    return result;
}