예제 #1
0
파일: post_tree.c 프로젝트: yaspr/optexpr
leaf *build(char *expr, hashtab *h)
{
  lstack s;
  char opr;
  int i = -1, num;
  char str[MAX_STR];
  leaf *l = NULL, *r = NULL, *tmp = NULL;
  
  lstack_init(&s, 1024);
  
  while (expr[++i])
    {
      if (is_digit(expr[i]))
	{
	  num = get_number(expr, &i);
	  l = new_num_leaf(num, INT, NULL, NULL, -1);
	  lpush(&s, l);
	}
      else
	if (is_opr(expr[i]))
	  {
	    lpop(&s, &r);
	    lpop(&s, &l);
	    
	    //Optimization : reducing the amount of registers !!
	    if ((expr[i] == '+' || expr[i] == '*') && l->typ == INT && r->typ != INT) 
	      tmp = l, l = r, r = tmp;

	    l = new_num_leaf(expr[i], CHAR, l, r, get_reg_num(l, r));
	    lpush(&s, l);
	  }
	else
	  if (is_alpha(expr[i]))
	    {
	      get_string(expr, str, &i);
	      
	      if (search(h, str))
		{
		  lpop(&s, &r);	  
		  r->reg = 1; //Premice to register allocation !!!
		  l = new_str_leaf(str, FUNC, NULL, r, 1);
		  lpush(&s, l);
		}
	      else //If not a function then a variable identifier ! [extend the grammar]
		{
		  l = new_str_leaf(str, VAR, NULL, NULL, -1);
		  lpush(&s, l);
		}
	    }
    }
   
  lstack_free(&s);

  return l;
}
예제 #2
0
파일: t_list.cpp 프로젝트: huokedu/ardb
 void Ardb::WakeBlockedConnCallback(Channel* ch, void* data)
 {
     if (NULL != ch)
     {
         Context* ctx = (Context*) data;
         if (-1 != ctx->block->blocking_timer_task_id)
         {
             ch->GetService().GetTimer().Cancel(ctx->block->blocking_timer_task_id);
             ctx->block->blocking_timer_task_id = -1;
         }
         if (ctx->block->dest_key.empty())
         {
             ctx->reply.type = REDIS_REPLY_ARRAY;
             if (!ctx->block->waked_value.empty())
             {
                 RedisReply& r1 = ctx->reply.AddMember();
                 RedisReply& r2 = ctx->reply.AddMember();
                 fill_str_reply(r1, ctx->block->waked_key.key);
                 fill_str_reply(r2, ctx->block->waked_value);
                 RedisCommandFrame lpop("lpop");
                 lpop.AddArg(ctx->block->waked_key.key);
                 g_db->m_master.FeedSlaves(ctx->currentDB, lpop);
             }
         }
         else
         {
             if (!ctx->block->waked_value.empty())
             {
                 fill_str_reply(ctx->reply, ctx->block->waked_value);
                 RedisCommandFrame lpush("lpush");
                 lpush.AddArg(ctx->block->dest_key);
                 lpush.AddArg(ctx->block->waked_value);
                 g_db->LPush(*ctx, lpush);
                 RedisCommandFrame lpop("lpop");
                 lpop.AddArg(ctx->block->waked_key.key);
                 g_db->m_master.FeedSlaves(ctx->currentDB, lpop);
                 g_db->m_master.FeedSlaves(ctx->currentDB, lpush);
             }
             else
             {
                 ctx->reply.type = REDIS_REPLY_NIL;
             }
         }
         ch->Write(ctx->reply);
         g_db->ClearBlockKeys(*ctx);
         ch->AttachFD();
     }
 }
예제 #3
0
파일: lists-ay.c 프로젝트: ayourtch/libay
void
ldelete(listitem_t ** li, listitem_t * li_el)
{
  //listitem_t *li2;

  debug(DBG_GLOBAL, 10, "deleting item %p from list %p/%p", li_el, li, li ? *li : NULL);
  if(li == NULL) {
    return;
  }
  if(*li == NULL) {
    return;
  }
  listitem_checksig(*li);
  if(li_el == *li) {
    debug(DBG_GLOBAL, 10, "lpop");
    lpop(li);
  } else {
    // we have at least two elements - else we'd do lpop
    if(li_el == (*li)->prev) {
      debug(DBG_GLOBAL, 10, "rpop");
      rpop(li);
    } else {
      li_el->prev->next = li_el->next;
      li_el->next->prev = li_el->prev;
      li_el->listitem_sig = 0;
      free(li_el);
    }
  }
}
예제 #4
0
int main(void) {
  ACData tk = make_token("barf");
  ACData n = make_int(3);
  ACData bs = give_binding(tk,n);
  ACData tk2 = make_token("frab");
  ACData n2 = make_int(-3);
  ACData bs2 = give_binding(tk2,n2);
  ACData bs3, bs4;
  ACData t,l;
  bs3 = give_overriding(bs,bs2);
  bs4 = give_disjoint_union(bs3,bs2);
  print_ac_data(bs3);
  t = make_tuple(tk,bs3);
  print_ac_data(t);
  printf("\n");
  l = make_list(tk,bs3);
  print_ac_data(l);
  printf("\n");
  l = lpush(l,l);
  print_ac_data(l);
  printf("\n");
  l = lpop(l);
  print_ac_data(l);
  printf("\n");
  return 0;
}
예제 #5
0
파일: post_tree.c 프로젝트: yaspr/optexpr
int main(int argc, char **argv)
{  
  //No checks, make sure the parameters are OK, otherwise SEGFAULT!
  if (argc < 6)
    return printf("%s [outfile.dot] [graph name] [reg file] [x86 file] [stack file] [postfix expression]\n", argv[0]), 0;
  
  hashtab h;
  
  hashtab_init(&h, hash_2, 20);
  
  insert(&h, "ln");
  insert(&h, "log");
  insert(&h, "exp");
  insert(&h, "cos");
  insert(&h, "sin");
  insert(&h, "tan");
  insert(&h, "cosh");
  insert(&h, "sinh");
  insert(&h, "acos");
  insert(&h, "asin");
  insert(&h, "cotan");

  tree t = build(argv[6], &h);
  
  printf("Expr : ");
  print_expr(t);
  printf("\n\n");

  printf("Tree :\n");
  print_tree(t);

  //Fictional register machine code generation
  gen_reg_asm_code(argv[3], t);
  
  //x86 machine code generation
  gen_x86_asm_code(argv[4], t);

  //Stack machine code generation
  gen_stack_code(argv[5], t);

  printf("\nParallel sub expressions : \n");
  leaf *l;
  lstack *s = get_par_subtrees(t);

  //Write the AST with some nice colors
  write_tree_dot(argv[1], argv[2], t, s); 
  
  while (lpop(s, &l))
    print_tree(l), printf("\n");

  lstack_free(s);
  hashtab_free(&h);

  return 0;
}
예제 #6
0
파일: timers-ay.c 프로젝트: ayourtch/libay
/**
 * the function to be called with each tick
 */
void
timer_tick_processor(void)
{
  uint32_t timer_idx;

  while((timer_idx = (uint32_t) ((long int)lpop(&timerwheel[timerwheel_idx]))) != 0) {
    fire_timer(timer_idx);
  }
  if(++timerwheel_idx >= TIMER_WHEEL_SIZE) {
    timerwheel_idx = 0;
  }
}