summaryrefslogtreecommitdiff
path: root/mem.h
blob: d13e02faee667e56173c69759b58fb067ec9e9de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef _mem_h
#define _mem_h

#include <stddef.h>
#include "val.h"
#include "vm.h"
#include "state.h"

void *M(State *S, void *ptr, size_t old, size_t new);

#define NEW(S,ty) (ty*)M(S, NULL, 0, sizeof(ty))
#define NEW_ARR(S,ty,n) (ty*)M(S, NULL, 0, (n)*sizeof(ty))
#define RENEW_ARR(S,p,ty,old,new) (ty*)M(S, (p), (old)*sizeof(ty), (new)*sizeof(ty))
#define NEW_OBJ(S,ty, oty) (ty*)alloc_obj(S, sizeof(ty), oty)

#define FREE(S,p,ty) M(S, p, sizeof(ty), 0)
#define FREE_ARR(S,p,ty,old) M(S, p, (old)*sizeof(ty), 0)

Obj *alloc_obj(State *S, size_t sz, ObjTy oty);


#endif