Esempio n. 1
0
static ptr eval(ptr x) {
  if (Spairp(x)) {
    switch (Schar_value(Scar(x))) {
      case '+': return S_add(First(x), Second(x));
      case '-': return S_sub(First(x), Second(x));
      case '*': return S_mul(First(x), Second(x));
      case '/': return S_div(First(x), Second(x));
      case 'q': return S_trunc(First(x), Second(x));
      case 'r': return S_rem(First(x), Second(x));
      case 'g': return S_gcd(First(x), Second(x));
      case '=': {
        ptr x1 = First(x), x2 = Second(x);
        if (Sfixnump(x1) && Sfixnump(x2))
          return Sboolean(x1 == x2);
        else if (Sbignump(x1) && Sbignump(x2))
          return Sboolean(S_big_eq(x1, x2));
        else return Sfalse;
      }
      case '<': {
        ptr x1 = First(x), x2 = Second(x);
        if (Sfixnump(x1))
          if (Sfixnump(x2))
            return Sboolean(x1 < x2);
          else
            return Sboolean(!BIGSIGN(x2));
        else
          if (Sfixnump(x2))
            return Sboolean(BIGSIGN(x1));
          else
            return Sboolean(S_big_lt(x1, x2));
      }
      case 'f': return Sflonum(S_floatify(First(x)));
      case 'c':
        S_gc(get_thread_context(), UNFIX(First(x)),UNFIX(Second(x)));
        return Svoid;
      case 'd': return S_decode_float(Sflonum_value(First(x)));
      default:
        S_prin1(x);
        putchar('\n');
        printf("unrecognized operator, returning zero\n");
        return FIX(0);
    }
  } else
    return x;
}
Esempio n. 2
0
void query_type(ptr x) {
  printf("Object is a: ");
  if (Sinexactnump(x))  printf("inexact ");
  if (Sexactnump(x))  printf("exact ");
  if (Sfixnump(x))  printf("fixnum ");
  if (Scharp(x))  printf("char ");
  if (Snullp(x))  printf("nil ");
  if (Seof_objectp(x))  printf("eof ");
  if (Sbwp_objectp(x))  printf("bwp ");
  if (Sbooleanp(x))  printf("bool ");  
  if (Spairp(x))  printf("pair ");
  if (Ssymbolp(x))  printf("symbol ");
  if (Sprocedurep(x))  printf("procedure ");
  if (Sflonump(x))  printf("flonum ");
  if (Svectorp(x))  printf("vector ");
  if (Sstringp(x))  printf("string ");
  if (Sbignump(x))  printf("bignum ");
  if (Sboxp(x))  printf("box ");
  if (Sratnump(x))  printf("rational ");
  if (Sinputportp(x))  printf("inputport ");
  if (Soutputportp(x))  printf("outputport ");
  if (Srecordp(x))  printf("record ");
  printf("\n");  
}