Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4587071d37
Fetching contributors…

Cannot retrieve contributors at this time

file 113 lines (96 sloc) 2.868 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
//
// internal.h
//
// (c) 2008 why the lucky stiff, the freelance professor
//
#ifndef POTION_INTERNAL_H
#define POTION_INTERNAL_H

struct Potion_State;

typedef unsigned char u8;

#define PN_ALLOC(V,T) (T *)potion_gc_alloc(P, V, sizeof(T))
#define PN_ALLOC_N(V,T,C) (T *)potion_gc_alloc(P, V, sizeof(T)+C)
#define PN_CALLOC_N(V,T,C) (T *)potion_gc_calloc(P, V, sizeof(T)+C)
#define PN_REALLOC(X,V,T,N) (X)=(T *)potion_gc_realloc(P, V, (struct PNObject *)(X), sizeof(T) + N)
#define PN_DALLOC_N(T,N) potion_data_alloc(P, sizeof(T)*N)

#define PN_MEMZERO(X,T) memset((X), 0, sizeof(T))
#define PN_MEMZERO_N(X,T,N) memset((X), 0, sizeof(T)*(N))
#define PN_MEMCPY(X,Y,T) memcpy((void *)(X), (void *)(Y), sizeof(T))
#define PN_MEMCPY_N(X,Y,T,N) memcpy((void *)(X), (void *)(Y), sizeof(T)*(N))

#ifndef min
#define min(a, b) ((a) <= (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) >= (b) ? (a) : (b))
#endif

#define TYPE_BATCH_SIZE 4096

#define PN_FLEX_NEW(N, V, T, S) \
(N) = PN_ALLOC_N(V, T, (sizeof(*(N)->ptr) * S)); \
(N)->siz = sizeof(*(N)->ptr) * S; \
(N)->len = 0

#define PN_FLEX_NEEDS(X, N, V, T, S) ({ \
PN_SIZE capa = (N)->siz / sizeof(*(N)->ptr); \
if (capa < (N)->len + X) { \
while (capa < (N)->len + X) \
capa += S; \
capa = sizeof(*(N)->ptr) * capa; \
PN_REALLOC(N, V, T, capa); \
(N)->siz = capa; \
} \
})

#define PN_ATOI(X,N,B) ({ \
char *Ap = X; \
long Ai = 0; \
size_t Al = N; \
while (Al--) { \
if ((*Ap >= '0') && (*Ap <= '9')) \
Ai = (Ai * B) + (*Ap - '0'); \
else if ((*Ap >= 'A') && (*Ap <= 'F')) \
Ai = (Ai * B) + ((*Ap - 'A') + 10); \
else if ((*Ap >= 'a') && (*Ap <= 'f')) \
Ai = (Ai * B) + ((*Ap - 'a') + 10); \
else break; \
Ap++; \
} \
Ai; \
})

struct PNBHeader {
  u8 sig[4];
  u8 major;
  u8 minor;
  u8 vmid;
  u8 pn;
  u8 proto[0];
};

size_t potion_cp_strlen_utf8(const char *);
void *potion_mmap(size_t, const char);
int potion_munmap(void *, size_t);
#define PN_ALLOC_FUNC(size) potion_mmap(size, 1)

//
// stack manipulation routines
//
#if POTION_X86 == POTION_JIT_TARGET
#if __WORDSIZE == 64
#define PN_SAVED_REGS 5
#define POTION_ESP(p) __asm__("mov %%rsp, %0" : "=r" (*p))
#define POTION_EBP(p) __asm__("mov %%rbp, %0" : "=r" (*p))
#else
#define PN_SAVED_REGS 3
#define POTION_ESP(p) __asm__("mov %%esp, %0" : "=r" (*p))
#define POTION_EBP(p) __asm__("mov %%ebp, %0" : "=r" (*p))
#endif
#else
#define PN_SAVED_REGS 0
__attribute__ ((noinline)) void potion_esp(void **);
#define POTION_ESP(p) potion_esp((void **)p)
#define POTION_EBP(p) potion_esp((void **)p)
#endif

#ifndef O_BINARY
#define O_BINARY 0
#endif

#if POTION_STACK_DIR > 0
#define STACK_UPPER(a, b) a
#elif POTION_STACK_DIR < 0
#define STACK_UPPER(a, b) b
#endif

#define GC_PROTECT(P) P->mem->protect = (void *)P->mem->birth_cur

#endif
Something went wrong with that request. Please try again.