48 lines
1 KiB
C
48 lines
1 KiB
C
#include <stdio.h>
|
|
#include <inttypes.h>
|
|
|
|
#include "meri_object.h"
|
|
#include "meri_bigint.h"
|
|
|
|
static void print_bigint(struct meri_bigint const *bigint) {
|
|
printf("limbs %u:", bigint->nlimbs);
|
|
for (unsigned int i = 0; i < bigint->nlimbs; i++) {
|
|
printf(" [%d] %08" PRIx32, i, bigint->limbs[i]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
static void print_obj(struct meri_object const *obj) {
|
|
printf("%p refcount %u type ", obj, obj->refcount);
|
|
switch (obj->type) {
|
|
case MERI_BIGINT:
|
|
printf("bigint ");
|
|
print_bigint((struct meri_bigint const*)obj);
|
|
break;
|
|
default:
|
|
printf("unknown(%d)\n", obj->type);
|
|
}
|
|
}
|
|
|
|
#define MAX ((1u<<31)-1)
|
|
|
|
#define RELEASE(x) (meri_release(&x->header))
|
|
#define COPY(x) (meri_retain(&x->header), x)
|
|
#define PRINT(x) (print_obj(&x->header))
|
|
|
|
int main(void) {
|
|
struct meri_bigint *a = meri_bigint_from_u32(0);
|
|
struct meri_bigint *b = meri_bigint_from_u32(MAX);
|
|
|
|
printf("a: "); PRINT(a);
|
|
printf("b: "); PRINT(b);
|
|
|
|
struct meri_bigint *result = meri_bigint_add(COPY(a), /*move*/ b);
|
|
|
|
PRINT(a);
|
|
PRINT(result);
|
|
|
|
RELEASE(a);
|
|
RELEASE(result);
|
|
return 0;
|
|
}
|