Пример #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;
        }
    }
}
Пример #2
0
VAL bigMod(VM* vm, VAL x, VAL y) {
    mpz_t* bigint;
    VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
    bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
    mpz_mod(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
    SETTY(cl, BIGINT);
    cl -> info.ptr = (void*)bigint;
    return cl;
}
Пример #3
0
VAL bigMul(VM* vm, VAL x, VAL y) {
    mpz_t* bigint;
    VAL cl = allocate(vm, sizeof(ClosureType) + sizeof(void*) + 
                          sizeof(mpz_t), 0);
    bigint = (mpz_t*)(((char*)cl) + sizeof(ClosureType) + sizeof(void*));
    mpz_mul(*bigint, GETMPZ(x), GETMPZ(y));
    SETTY(cl, BIGINT);
    cl -> info.ptr = (void*)bigint;
    return cl;
}
Пример #4
0
VAL bigDiv(VM* vm, VAL x, VAL y) {
    idris_requireAlloc(IDRIS_MAXGMP);

    mpz_t* bigint;
    VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
    bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
    mpz_tdiv_q(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
    SETTY(cl, BIGINT);
    cl -> info.ptr = (void*)bigint;
    return cl;
}
Пример #5
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;
}
Пример #6
0
VAL MKBIGSI(VM* vm, signed long val) {
    mpz_t* bigint;
    VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
    bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));

    mpz_init_set_si(*bigint, val);

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

    return cl;
}
Пример #7
0
VAL MKBIGMc(VM* vm, void* big) {
    mpz_t* bigint;
    VAL cl = allocate(vm, sizeof(Closure) + 
                          sizeof(mpz_t), 0);
    bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));

    mpz_init_set(*bigint, *((mpz_t*)big));

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

    return cl;
}
Пример #8
0
VAL MKBIGUI(VM* vm, unsigned long val) {
    idris_requireAlloc(IDRIS_MAXGMP);

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

    mpz_init_set_ui(*bigint, val);

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

    return cl;
}
Пример #9
0
VAL MKBIGM(VM* vm, void* big) {
    idris_requireAlloc(IDRIS_MAXGMP);

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

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

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

    return cl;
}
Пример #10
0
VAL MKBIGC(VM* vm, char* val) {
    mpz_t* bigint;
    
    VAL cl = allocate(vm, sizeof(Closure) + 
                          sizeof(mpz_t), 0);
    bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
    
    mpz_init(*bigint);
    mpz_set_str(*bigint, val, 10);

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

    return cl;
}
Пример #11
0
/*
**	Reset line discipline to the shell state
**
**	Written by Kiem-Phong Vo
*/
int reset_shell_mode()
{
#ifdef TCHARS
	if(SETCHARS(_orgchars) < 0)
		return ERR;
#endif
#ifdef LTCHARS
	if(SETLCHARS(_orglchars) < 0)
		return ERR;
#endif
#ifdef TAUXIL
	if(SETTAUXIL(_orgtauxil) < 0)
		return ERR;
#endif
	return SETTY(_orgtty) < 0 ? ERR : _tty_mode(&(_orgtty));
}
Пример #12
0
VAL GETBIG(VM * vm, VAL x) {
    if (ISINT(x)) {
        mpz_t* bigint;
        VAL cl = allocate(vm, sizeof(ClosureType) + sizeof(void*) + 
                              sizeof(mpz_t), 0);
        bigint = (mpz_t*)(((char*)cl) + sizeof(ClosureType) + sizeof(void*));

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

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

        return cl;
    } else {
        return x;
    }
}
Пример #13
0
// FIXME: Do this properly!
void* freadStr(void* h) {
    static char bufin[128];
    bufin[0]='\0';

    FILE* f = (FILE*)h;
    fgets(bufin,128,f);
    int len = strlen(bufin);

    VAL c = GC_MALLOC_ATOMIC(sizeof(Closure)+len*sizeof(char)+sizeof(char)+1);
    SETTY(c, STRING);
    c->info = ((void*)(c+1));
    char *buf = (char*)(c->info);
    strcpy(buf,bufin);

    char *loc = strchr(buf,'\n');
    if (loc) *loc = '\0'; else buf[0]='\0';
    return ((void*)c);
}
Пример #14
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;
    }
}
Пример #15
0
VAL GETBIG(VM * vm, VAL x) {
    if (ISINT(x)) {
        mpz_t* bigint;
        VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
        bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));

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

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

        return cl;
    } else {
        switch(GETTY(x)) {
        case FWD:
            return GETBIG(vm, x->info.ptr);
        default:
            return x;
        }
    }
}
Пример #16
0
VAL copy(VM* vm, VAL x) {
    int i, ar;
    Closure* cl = NULL;
    if (x==NULL || ISINT(x)) {
        return x;
    }
    switch(GETTY(x)) {
    case CT_CON:
        ar = CARITY(x);
        if (ar == 0 && CTAG(x) < 256) {
            return x;
        } else {
            allocCon(cl, vm, CTAG(x), ar, 1);
            for(i = 0; i < ar; ++i) {
                cl->info.c.args[i] = x->info.c.args[i];
            }
        }
        break;
    case CT_FLOAT:
        cl = MKFLOATc(vm, x->info.f);
        break;
    case CT_STRING:
        cl = MKSTRc(vm, x->info.str);
        break;
    case CT_STROFFSET:
        cl = MKSTROFFc(vm, x->info.str_offset);
        break;
    case CT_BIGINT:
        cl = MKBIGMc(vm, x->info.ptr);
        break;
    case CT_PTR:
        cl = MKPTRc(vm, x->info.ptr);
        break;
    case CT_MANAGEDPTR:
        cl = MKMPTRc(vm, x->info.mptr->data, x->info.mptr->size);
        break;
    case CT_BITS8:
        cl = idris_b8CopyForGC(vm, x);
        break;
    case CT_BITS16:
        cl = idris_b16CopyForGC(vm, x);
        break;
    case CT_BITS32:
        cl = idris_b32CopyForGC(vm, x);
        break;
    case CT_BITS64:
        cl = idris_b64CopyForGC(vm, x);
        break;
    case CT_FWD:
        return x->info.ptr;
    case CT_RAWDATA:
        {
            size_t size = x->info.size + sizeof(Closure);
            cl = allocate(size, 0);
            memcpy(cl, x, size);
        }
        break;
    case CT_CDATA:
        cl = MKCDATAc(vm, x->info.c_heap_item);
        c_heap_mark_item(x->info.c_heap_item);
        break;
    default:
        break;
    }
    SETTY(x, CT_FWD);
    x->info.ptr = cl;
    return cl;
}
Пример #17
0
VAL copy(VM* vm, VAL x) {
    int i, ar;
    Closure* cl = NULL;
    if (x==NULL || ISINT(x)) {
        return x;
    }
    switch(GETTY(x)) {
    case CON:
        ar = CARITY(x);
        if (ar == 0 && CTAG(x) < 256) {
            return x;
        } else {
            allocCon(cl, vm, CTAG(x), ar, 1);
            for(i = 0; i < ar; ++i) {
    //            *argptr = copy(vm, *((VAL*)(x->info.c.args)+i)); // recursive version
                cl->info.c.args[i] = x->info.c.args[i];
            }
        }
        break;
    case FLOAT:
        cl = MKFLOATc(vm, x->info.f);
        break;
    case STRING:
        cl = MKSTRc(vm, x->info.str);
        break;
    case STROFFSET:
        cl = MKSTROFFc(vm, x->info.str_offset);
        break;
    case BUFFER:
        cl = MKBUFFERc(vm, x->info.buf);
        break;
    case BIGINT:
        cl = MKBIGMc(vm, x->info.ptr);
        break;
    case PTR:
        cl = MKPTRc(vm, x->info.ptr);
        break;
    case MANAGEDPTR:
        cl = MKMPTRc(vm, x->info.mptr->data, x->info.mptr->size);
        break;
    case BITS8:
        cl = idris_b8CopyForGC(vm, x);
        break;
    case BITS16:
        cl = idris_b16CopyForGC(vm, x);
        break;
    case BITS32:
        cl = idris_b32CopyForGC(vm, x);
        break;
    case BITS64:
        cl = idris_b64CopyForGC(vm, x);
        break;
    case FWD:
        return x->info.ptr;
    default:
        break;
    }
    SETTY(x, FWD);
    x->info.ptr = cl;
    return cl;
}
Пример #18
0
void* idris_alloc(size_t size) {
    Closure* cl = (Closure*) allocate(sizeof(Closure)+size, 0);
    SETTY(cl, CT_RAWDATA);
    cl->info.size = size;
    return (void*)((char *)cl+sizeof(Closure));
}