コード例 #1
0
ファイル: libml.c プロジェクト: Pachot/mlworks
static MLvalue TO_MLvalue(mlval v)
{
  mlval *box;

  if (ISINT(v)) return((MLvalue)v);

  box = next_box();
  *box = v;
  declare_root(box, 0);

  return((MLvalue)MKPTR(box));
}
コード例 #2
0
ファイル: sdlrun2.c プロジェクト: eckart/SDL2-idris
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;
}
コード例 #3
0
ファイル: rawnet.c プロジェクト: edwinb/ResIO
// VAL is RawPacket
VAL prim_recv(int socket)
{
    // TMP HACK: 512 should be enough for the purposes of this experiment...
    // Do it properly some time.
    uint32_t* buf = (uint32_t*)EMALLOC(512*sizeof(uint32_t));

    if (!isReadable(socket, 10000)) {
	return CONSTRUCTOR2(0, EMPTYPKT, NOADDR);
    }

    int recvlen = recv(socket, buf, 512*sizeof(word32), 0);

    if (recvlen==-1) {
	return CONSTRUCTOR2(0, EMPTYPKT, NOADDR);
    } 

    return CONSTRUCTOR2(0, MKPTR(buf), MKINT(recvlen << 3));
}
コード例 #4
0
ファイル: rawnet.c プロジェクト: edwinb/ResIO
// VAL is (RawPacket & SockAddr)
VAL prim_recvFrom(int socket)
{
    struct sockaddr_in other;

    socklen_t slen = sizeof(other);

    // TMP HACK: 512 should be enough for the purposes of this experiment...
    // Do it properly some time.
    uint32_t* buf = (uint32_t*)EMALLOC(512*sizeof(uint32_t));

    if (!isReadable(socket, 10000)) {
	return CONSTRUCTOR2(0, EMPTYPKT, NOADDR);
    }
    int recvlen = recvfrom(socket, buf, 512*sizeof(uint32_t), 0,
			   (struct sockaddr*)&other, &slen);
    if (recvlen == -1) {
	return CONSTRUCTOR2(0, EMPTYPKT, NOADDR);
    }

    return CONSTRUCTOR2(0, 
			CONSTRUCTOR2(0, MKPTR(buf), MKINT(recvlen << 3)),
			CONSTRUCTOR2(0, MKSTR(inet_ntoa(other.sin_addr)),
				     MKINT(ntohs(other.sin_port))));
}