示例#1
0
static int assignment (LexState *ls, struct LHS_assign *lh, int nvars,
                       lu_byte *from_var)
{
  expdesc e;
  int from = 0;
  check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,
                      "syntax error");
  if (testnext(ls, ',')) {  /* assignment -> `,' primaryexp assignment */
    struct LHS_assign nv;
    nv.prev = lh;
    primaryexp(ls, &nv.v);
    if (nv.v.k == VLOCAL)
      check_conflict(ls, lh, &nv.v);
    luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,
                    "variables in assignment");
    from = assignment(ls, &nv, nvars+1, from_var);
  }
  else {  /* assignment -> IN primaryexp | `=' explist1 */
    int nexps;
    if (testnext(ls, TK_IN)) {
      new_localvarliteral(ls, "(from)", 0);
      primaryexp(ls, &e);
      luaK_exp2nextreg(ls->fs, &e);
      *from_var = ls->fs->nactvar;
      adjustlocalvars(ls, 1);

      luaK_setoneret(ls->fs, &e);  /* close last expression */
      getfrom(ls, &e, &lh->v);
      luaK_storevar(ls->fs, &lh->v, &e);
      return 1;  /* avoid default */
    }
    else {
      checknext(ls, '=');
      nexps = explist1(ls, &e);
    }

    if (nexps == nvars) {
      luaK_setoneret(ls->fs, &e);  /* close last expression */
      luaK_storevar(ls->fs, &lh->v, &e);
      return 0;  /* avoid default */
    }
    else {
      adjust_assign(ls, nvars, nexps, &e);
      if (nexps > nvars)
        ls->fs->freereg -= nexps - nvars;  /* remove extra values */
    }
  }
  init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */
  if (from) getfrom(ls, &e, &lh->v);
   luaK_storevar(ls->fs, &lh->v, &e);
  return from;
}
示例#2
0
int main(int argc, char *argv[])
{

    int a, i, novo=0;
    char c;
    int amax, amin;
    double x2;

    int last=0;
    char str[TAM];
    clock_t clock1, clock2, diffclock;

    if(argc==2)
        if(!strcmp(argv[1],"-n"))
            novo=1;

    printf("\nlibecoteste version v0.1.090902.000301\n\n");

    if(!novo)
    {
        printf("Teste getch()\n");
        c=getch();
        printf("Char: %c ASCII: %d\n", c, c);
        printf("Teste ok\n\n");

        printf("Teste kbhit()\n");
        clock1 = clock() / CLOCKS_PER_SEC;
        clock2 = clock1;
        diffclock = clock2 - clock1;
        printf("Tecle algo no tempo de: ");
        while(diffclock<10)
        {
            if((a=kbhit())) /* kbbuff() deprecated */
                break;
            clock2 = clock() / CLOCKS_PER_SEC;
            diffclock = clock2 - clock1;
            if(diffclock>last)
            {
                printf("%lus ", 10-diffclock);
                last++;
            }
            fflush(stdout);
        }
        if(a)
            printf("\nTecla disponivel no buffer\n");
        else
            printf("\nTecla nao pressionada\n");
        printf("Teste ok\n\n");

        printf("Teste min(3,2)\n");
        printf("%d\n", min(3,2));
        printf("Teste min(-3,-2)\n");
        printf("%d\n", min(-3,-2));
        printf("Teste ok\n\n");


        printf("Teste kbwait(1000)\n");
        //sleep(1);
        printf("Tecle algo 10s\n");
        a=kbwait(1000);
        if(a)
            printf("Tecla disponivel no buffer\n");
        else
            printf("Tecla nao pressionada\n");
        printf("Teste ok\n\n");

        printf("Teste getfrom(\"0a\")\n");
        c=getfrom("0a");
        if(c!='a' && c!='0')
            printf("\nTeste FALHOU!\n\n");
        else
            printf("Teste ok\n\n");



        printf("Teste rand_minmax(0,10) em 10000 iteracoes\n");
        amax = -1;
        amin = 11;
        for(i=0; i<10000; i++)
        {
            a=rand_minmax(0, 10);

            if(a>amax)
                amax=a;
            if(a<amin)
                amin=a;
        }
        printf("max=%d, min=%d\n", amax, amin);
        if(amax<10 && amin>=0)
            printf("\nTeste ok\n\n");
        else
            printf("\nTeste FALHOU!\n\n");


        printf("Teste x2=mudaintervalo(0.0, 50.0, 0.0, 100.0, 25.0)\n");
        x2=mudaintervalo(0.0, 50.0, 0.0, 100.0, 25.0);
        printf("x2: %f\n", x2);
        if(x2!=50.0)
            printf("\nTeste FALHOU!\n\n");
        printf("Teste x2=mudaintervalo(0.0, 100.0, 0.0, 0.4, 50.0)\n");
        x2=mudaintervalo(0.0, 100.0, 0.0, 0.4, 50.0);
        printf("x2: %f\n", x2);
        printf("\nTeste ok\n\n");


        printf("Teste de limites dos tipos\n");
        printf("--------------------------\n");
        printf("unsigned %lu bits %lu bytes\n", sizeof(unsigned)*CHAR_BIT,(sizeof(unsigned)*CHAR_BIT)/8);
        printf("max unsigned %u, min unsigned %u\n\n", UINT_MAX, 0);

        printf("int %lu bits %lu bytes\n", sizeof(int) * CHAR_BIT, (sizeof(int) * CHAR_BIT)/8);
        printf("max int %d, min int %d\n\n", INT_MAX, INT_MIN);

        printf("long int %lu bits %lu bytes\n", sizeof(long) * CHAR_BIT, (sizeof(long) * CHAR_BIT)/8);
        printf("max %ld, min %ld\n\n", (long)LONG_MAX, (long)LONG_MIN);

        printf("long long int %lu bits %lu bytes\n\n", sizeof(long long) * CHAR_BIT, (sizeof(long long) * CHAR_BIT)/8);
    //    printf("max %d, min %d\n\n", LLONG_MAX, LLONG_MIN);

        printf("float %lu bits %lu bytes\n", sizeof(float) * CHAR_BIT, (sizeof(float) * CHAR_BIT)/8);
        printf("max, min float +-%f\n", (double)FLT_MAX);
        printf("max float 10^%f-1 is valid\n", (double)FLT_MAX_10_EXP);
        printf("min float 10^%f-1 is valid\n\n", (double)FLT_MIN_10_EXP);

        printf("double %lu bits %lu bytes\n", sizeof(double) * CHAR_BIT, (sizeof(double) * CHAR_BIT)/8);
        printf("max, min double +-%f\n", (double)DBL_MAX);
        printf("max double 10^%f-1 is valid\n", (double)DBL_MAX_10_EXP);
        printf("min double 10^%f-1 is valid\n\n", (double)DBL_MIN_10_EXP);
        //FLT_MAX_EXP
        //FLT_RADIX^FLT_MAX_EXP-1 is valid
        //DBL_MAX_EXP
        printf("FLT_ROUNDS: %d\n", FLT_ROUNDS);
        printf("--------------------------\n");

        printf("%f+%f=%f\n", 83484516925440.000000, 1.1, 83484516925440.000000+1.1);
        x2=5000000000000.0;
        x2+=1.1;
        printf("x:%.15f\n", x2);

        printf("%f+%f=%f\n", 340282346638528859811704183484516925440.0, 1.1, (double)((double)340282346638528859811704183484516925440.0+(double)1.1));


        printf("\nchar getfrom(\"01923456789.-\\n\");");
        printf("Press ENTER to end, or fill %d chars.\n", TAM-1);
        i=0;
        str[0]=str[TAM-1]='\0';
        while(1)
        {
            a=getfrom("01923456789.-\n");
            if(a>=32&&a<=127)
            {
                str[i]=a;
                str[i+1]='\0';
                printf("%c", a);
                if(i==TAM-2)
                    break;
                i++;
            }
            else if(a=='\n')
                break;
        }
        printf("\ns='%s'\nlength: %lu\n", str, strlen(str));
        printf("sizeof(s): %lu\n", sizeof(str));
        printf("s[%d]:'%d'\n", TAM-1, str[TAM-1]);
        printf("s[%d]:'%d'\n", TAM-2, str[TAM-2]);
        printf("s[%d]:'%d'\n", TAM-3, str[TAM-3]);
        printf("\nTeste ok\n\n");

    }

    printf("Teste chkpipe()\n");
    printf("Teste nao implementado\n\n");



    // printf("Teste ok\n\n");
    printf("Fim dos testes\n");
    printf("Nota: para compilar use: gcc libecoteste.c -o libecoteste\n\n");
}