Пример #1
0
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);
    }
  }
}
Пример #2
0
/**
 * the socket in index idx got closed 
 */
int
ev_closed(int idx, void *u_ptr)
{
  dbuf_t *d;

#ifdef WITH_SSL
  if(cdata[idx].is_ssl) {
    SSL_shutdown(cdata[idx].ssl);
    SSL_free(cdata[idx].ssl);
    cdata[idx].ssl = NULL;
  }
#endif

  while((d = rpop(&cdata[idx].xmit_list))) {
    dunlock(d);
  }
  if(cdata[idx].handlers.ev_closed) {
    cdata[idx].handlers.ev_closed(idx, u_ptr);
  }
  dunlock(cdata[idx].appdata);

  if(cdata[idx].inbound) {
    nclients--;
    /*
       if(nclients == 0) {
       debug(DBG_GLOBAL, 1, "Last client went away, close the outbound connection");
       close(ufds[delayed_idx].fd);
       ufds[delayed_idx].fd = -1;
       }
     */
  }
  return 1;
}
Пример #3
0
uforth_stat exec(CELL wd_idx, char toplevelprim,uint8_t last_exec_rdix) {
  while(1) {
    if (wd_idx == 0) {
      uforth_abort_request(ABORT_ILLEGAL);
      uforth_abort();           /* bad instruction */
      return E_NOT_A_WORD;
    }
    cmd = uforth_dict[wd_idx++];
    switch (cmd) {
    case 0:
      uforth_abort_request(ABORT_ILLEGAL);
      uforth_abort();           /* bad instruction */
      return E_NOT_A_WORD;
    case ABORT:
      uforth_abort_request(ABORT_WORD);
      break;
    case IMMEDIATE:
      make_immediate();
      break;
    case IRAM_FETCH:
      r1 = dpop();
      dpush(((DCELL*)uforth_iram)[r1]);
      break;
    case URAM_BASE_ADDR:
      dpush((RAM_START_IDX + (sizeof(struct uforth_iram))) + curtask_idx);
      break;
    case SKIP_IF_ZERO:
      r1 = dpop(); r2 = dpop();
      if (r2 == 0) wd_idx += r1;
      break;
    case DROP:
      dpop();
      break;
    case JMP:
      wd_idx = dpop();
      break;
    case JMP_IF_ZERO:
      r1 = dpop(); r2 = dpop();
      if (r2 == 0) wd_idx = r1;
      break;
    case HERE:
      dpush(dict_here());
      break;
    case INCR_HERE:
      dict_incr_here(1);
      break;
    case LIT:  
      dpush(uforth_dict[wd_idx++]);
      break;
    case DLIT:  
      dpush((((uint32_t)uforth_dict[wd_idx])<<16) |
            (uint16_t)uforth_dict[wd_idx+1]); 
      wd_idx+=2;
      break;
    case LESS_THAN:
      r1 = dpop(); r2 = dpop();
      dpush(r2 < r1);
      break;
    case ABS:
      r1 = dpop(); 
      dpush(abs32(r1)); 
      break;
    case ADD:
      r1 = dpop(); r2 = dtop(); 
      dtop() = r1+r2;
      break;
    case SUB:
      r1 = dpop(); r2 = dtop(); 
      dtop() = r2-r1;
      break;
    case AND:
      r1 = dpop(); r2 = dtop();
      dtop() = r1&r2;
      break;
    case LSHIFT:
      r1 = dpop(); r2 = dtop();
      dtop() = r2<<r1;
      break;
    case RSHIFT:
      r1 = dpop(); r2 = dtop(); 
      dtop() = r2>>r1;
      break;
    case OR:
      r1 = dpop(); r2 = dtop(); 
      dtop() = r1|r2;
      break;
    case XOR:
      r1 = dpop(); r2 = dtop(); 
      dtop() = r1^r2;
      break;
    case INVERT:
      dtop() = ~dtop();
      break;
    case MULT:
      r1 = dpop(); r2 = dtop(); 
      dtop() = r1*r2;
      break;
    case DIV :
      r1 = dpop(); r2 = dtop(); 
      dtop() = r2/r1;
      break;
    case SWAP:
      r1 = dpop(); r2 = dpop(); 
      dpush(r1); dpush(r2);
      break;
    case RPICK:
      r1 = dpop();
      r2 = rpick(r1);
      dpush(r2);
      break;
    case PICK:
      r1 = dpop();
      r2 = dpick(r1);
      dpush(r2);
      break;
    case EQ_ZERO:
      dtop() = (dtop() == 0);
      break;
    case RPUSH:
      rpush(dpop());
      break;
    case RPOP:
      dpush(rpop());
      break;
    case FETCH:
      r1 = dpop();
      if (r1 >= RAM_START_IDX) {
        dpush(uforth_ram[r1-RAM_START_IDX]);
      } else {
        dpush(uforth_dict[r1]);
      }
      break;
    case STORE:
      r1 = dpop();
      r2 = dpop();
      if (r1 >= RAM_START_IDX) {
        uforth_ram[r1-RAM_START_IDX] = r2;
      } else {
        dict_write(r1,r2);
      }
      break;
    case EXEC:
      r1 = dpop();
      rpush(wd_idx);
      wd_idx = r1;
      break;
    case EXIT:
      if (uforth_uram->ridx > last_exec_rdix) return OK;
      wd_idx = rpop();
      break;
    case CNEXT:
      b = next_char();
      dpush(b);
      break;
    case STR_STORE:
      r1 = dpop();
      r2 = uforth_ram[(r1-RAM_START_IDX)];
      str1 =(char*)&uforth_ram[(r1-RAM_START_IDX)+1];
      str1+=r2;
      b = dpop();
      *str1 = b;
      uforth_ram[(r1-RAM_START_IDX)]++;
      break;
    case NEXT:
      str2 = PAD_STR;
      str1 = uforth_next_word();
      memcpy(str2,str1, uforth_iram->currwordlen);
      PAD_STRLEN = uforth_iram->currwordlen;            /* length */
      dpush(PAD_ADDR+RAM_START_IDX);
      break;
    case COMMA_STRING:
      if (uforth_iram->compiling > 0) {
        dict_append(LIT);
        dict_append(dict_here()+4); /* address of counted string */

        dict_append(LIT);
        rpush(dict_here());     /* address holding adress  */
        dict_incr_here(1);      /* place holder for jump address */
        dict_append(JMP);
      }
      rpush(dict_here());
      dict_incr_here(1);        /* place holder for count*/
      r1 = 0;
      b = next_char();          /* eat space */
      while (b != 0 && b!= '"') {
        r2 = 0;
        b = next_char();
        if (b == 0 || b == '"') break;
        r2 |= BYTEPACK_FIRST(b);
        ++r1;
        b = next_char();
        if (b != 0 && b != '"') {
          ++r1;
          r2 |= BYTEPACK_SECOND(b);
        }
        dict_append(r2);
      } 
      dict_write(rpop(),r1);
      if (uforth_iram->compiling > 0) {
        dict_write(rpop(),dict_here()); /* jump over string */
      }
      break;
    case CALLC:
      r1 = c_handle();
      if (r1 != OK) return (uforth_stat)r1;
      break;
    case VAR_ALLOT:
      dpush(VAR_ALLOT_1());
      break;
    case DEF:
      uforth_iram->compiling = 1;
    case _CREATE:
      dict_start_def();
      uforth_next_word();
      make_word(uforth_iram->currword,uforth_iram->currwordlen);
      if (cmd == _CREATE) {
        dict_end_def();
      } else {
        defining_word = dict_here();
      }
      break;
    case COMMA:
      dict_append(dpop());
      break;
    case DCOMMA:
      r1 = dpop();
      dict_append((uint32_t)r1>>16);
      dict_append(r1);
      break;
    case PARSE_NUM:
      r1 = dpop();
      str1=uforth_count_str((CELL)r1,(CELL*)&r1);
      str1[r1] = '\0';
      dpush(parse_num(str1,uforth_uram->base));
      break;
    case PARSE_FNUM:
      r1 = dpop();
      str1=uforth_count_str((CELL)r1,(CELL*)&r1);
      str1[r1] = '.';
      str1[r1+1] = '\0';
      dpush(parse_num(str1,uforth_uram->base));
      break;
    case FIND:
    case FIND_ADDR:
      r1 = dpop();
      str1=uforth_count_str((CELL)r1,(CELL*)&r1);
      r1 = find_word(str1, r1, &r2, 0, &b);
      if (r1 > 0) {
        if (b) r1 = uforth_dict[r1];
      }
      if (cmd == FIND) {
        dpush(r1);
      } else {
        dpush(r2);
      }
      break;
    case POSTPONE:
      str1 = uforth_next_word();
      r1 = find_word(str1, uforth_iram->currwordlen, 0, 0, &b);
      if (r1 == 0) {
        uforth_abort_request(ABORT_NAW);
        uforth_abort();
        return E_NOT_A_WORD;
      }
      if (b) {
        dict_append(uforth_dict[r1]);
      } else {
        dict_append(r1);
      }
      break;
    case MOVE:
      r1 = dpop();              /* count */
      rpush(r1);

      r1 = dpop();              /* dest */
      r2 = dpop();              /* source */

      if (r1 < RAM_START_IDX) {
        (void)rpop();
        uforth_abort_request(ABORT_ILLEGAL);
        uforth_abort();         /* can't cmove into dictionary */
        return E_ABORT;
      }
      str1 =(char*)&uforth_ram[(r1-RAM_START_IDX)];

      if (r2 > RAM_START_IDX) {
        str2 =(char*)&uforth_ram[(r2-RAM_START_IDX)];
      } else {
        str2 =  (char*)&uforth_dict[r2];
      }
      memcpy(str1, str2, rpop());
      break;
    case MAKE_TASK:
      r1 = dpop();
      r2 = dpop();
      r3 = dpop();
      r4 = dpop();
      uforth_make_task(r1-RAM_START_IDX, r2, r3, r4);
      dpush(r1-RAM_START_IDX);
      break;
    case SELECT_TASK:
      uforth_select_task(dpop());
      break;
    default:
      /* Execute user word by calling until we reach primitives */
      rpush(wd_idx);
      wd_idx = uforth_dict[wd_idx-1]; /* wd_idx-1 is current word */
      break;
    }
    if (uforth_aborting()) {
      uforth_abort();
      return E_ABORT;
    }
    if (toplevelprim) return OK;
  } /* while(1) */
}
Пример #4
0
void
do_exit(void)
{
    ip = rpop();
}