Example #1
0
VAL GETBIG(VM * vm, VAL x) {
    idris_requireAlloc(IDRIS_MAXGMP);

    if (ISINT(x)) {
        mpz_t* bigint;
        VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
        idris_doneAlloc();
        bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));

        mpz_init(*bigint);
        mpz_set_si(*bigint, GETINT(x));

        SETTY(cl, CT_BIGINT);
        cl -> info.ptr = (void*)bigint;

        return cl;
    } else {
        idris_doneAlloc();
        switch(GETTY(x)) {
        case CT_FWD:
            return GETBIG(vm, x->info.ptr);
        default:
            return x;
        }
    }
}
Example #2
0
void* processEvent(VM* vm, int r, SDL_Event * e) {
  VAL idris_event;

  SDL_Event event = *e;
  idris_requireAlloc(128); // Conservative!


  if (r==0) {
    idris_constructor(idris_event, vm, 0, 0, 0); // Nothing
  }
  else {
    VAL ievent = NULL;
    switch(event.type) {
    case SDL_KEYDOWN:
      ievent = KEY(vm, 0, event.key.keysym.sym);
      break;
    case SDL_KEYUP:
      ievent = KEY(vm, 1, event.key.keysym.sym);
      break;
    case SDL_MOUSEMOTION:
      ievent = MOTION(vm, event.motion.x, event.motion.y,
		      event.motion.xrel, event.motion.yrel);
      break;
    case SDL_MOUSEBUTTONDOWN:
      ievent = BUTTON(vm, 3, event.button.button, event.button.x, event.button.y);
      break;
    case SDL_MOUSEBUTTONUP:
      ievent = BUTTON(vm, 4, event.button.button, event.button.x, event.button.y);
      break;
    case SDL_MOUSEWHEEL:
      idris_constructor(ievent, vm, 5, 1, 0);
      idris_setConArg(ievent, 0, MKINT((intptr_t) event.wheel.y));
      break;
    case SDL_WINDOWEVENT:
      switch(event.window.event) {
      case SDL_WINDOWEVENT_RESIZED:
	ievent = RESIZE(vm, event.window.data1, event.window.data2);
	break;
      default:
	// TODO: other window event
	idris_constructor(ievent, vm, 8, 0, 0);
      }
      break;
    case SDL_QUIT:
      idris_constructor(ievent, vm, 7, 0, 0);
      break;
    default:
      idris_constructor(idris_event, vm, 0, 0, 0); // Nothing
      idris_doneAlloc(vm);
      return idris_event;
    }
    idris_constructor(idris_event, vm, 1, 1, 0);
    idris_setConArg(idris_event, 0, ievent); // Just ievent
  }
  
  idris_doneAlloc(vm);
  return idris_event;
}
Example #3
0
VAL bigAShiftRight(VM* vm, VAL x, VAL y) {
    idris_requireAlloc(IDRIS_MAXGMP);

    mpz_t* bigint;
    VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
    idris_doneAlloc();
    bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
    mpz_fdiv_q_2exp(*bigint, GETMPZ(GETBIG(vm,x)), GETINT(y));
    SETTY(cl, CT_BIGINT);
    cl -> info.ptr = (void*)bigint;
    return cl;
}
Example #4
0
VAL MKBIGSI(VM* vm, signed long val) {
    idris_requireAlloc(IDRIS_MAXGMP);

    mpz_t* bigint;
    VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
    idris_doneAlloc();
    bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));

    mpz_init_set_si(*bigint, val);

    SETTY(cl, CT_BIGINT);
    cl -> info.ptr = (void*)bigint;

    return cl;
}
Example #5
0
VAL idr_lock_texture(SDL_Texture* texture, VM* vm) {
  VAL m;

  void *pixels;
  int pitch;
  SDL_LockTexture(texture, NULL, &pixels, &pitch);  

  idris_requireAlloc(128); // Conservative!

  idris_constructor(m, vm, 0, 0, 0);
  idris_setConArg(m, 0, MKPTR(vm, pixels));
  idris_setConArg(m, 1, MKINT((intptr_t) pitch));
  idris_doneAlloc(vm);

  return m;
}
Example #6
0
VAL MKBIGM(VM* vm, void* big) {
    idris_requireAlloc(IDRIS_MAXGMP);

    mpz_t* bigint;
    VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
    idris_doneAlloc();
    bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));

    mpz_init(*bigint);
    mpz_set(*bigint, *((mpz_t*)big));

    SETTY(cl, CT_BIGINT);
    cl -> info.ptr = (void*)bigint;

    return cl;
}
Example #7
0
VAL MKBIGC(VM* vm, char* val) {
    if (*val == '\0') {
        return MKBIGI(0);
    }
    else {
        idris_requireAlloc(IDRIS_MAXGMP);
        mpz_t* bigint;
        
        VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
        idris_doneAlloc();
        bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
        
        mpz_init(*bigint);
        mpz_set_str(*bigint, val, 10);

        SETTY(cl, CT_BIGINT);
        cl -> info.ptr = (void*)bigint;

        return cl;
    }
}