Make arena global
This commit is contained in:
parent
656424c9d1
commit
20f44d6ad8
|
|
@ -70,7 +70,6 @@ typedef u8 bool;
|
|||
|
||||
#define MAX_LEN_REAL32 12
|
||||
#define MAX_LEN_INT32 11
|
||||
#define MAX_LEN_UINT32 10
|
||||
const char radix_set[11] = "0123456789";
|
||||
|
||||
typedef struct arena_s Arena;
|
||||
|
|
@ -158,48 +157,59 @@ snlen(const char *str, u32 max_len)
|
|||
return i;
|
||||
}
|
||||
|
||||
u8 tape[__UNDAR_ARENA_SIZE__];
|
||||
Arena arena = {tape, 0, __UNDAR_ARENA_SIZE__};
|
||||
|
||||
static inline void *
|
||||
aalloc(Arena *arena, u32 size)
|
||||
aalloc(u32 size)
|
||||
{
|
||||
u32 pos;
|
||||
if(arena == nil) return nil;
|
||||
if(arena->count + size > arena->capacity) return nil;
|
||||
if(arena.count + size > arena.capacity) return nil;
|
||||
|
||||
pos = arena->count;
|
||||
arena->count += size;
|
||||
return (void *)&arena->tape[pos];
|
||||
pos = arena.count;
|
||||
arena.count += size;
|
||||
return (void *)&arena.tape[pos];
|
||||
}
|
||||
|
||||
static inline void *
|
||||
areturn(Arena *arena, u32 checkpoint, const void *src, u32 size)
|
||||
aend()
|
||||
{
|
||||
i32 pos = arena.count;
|
||||
return (void *)&arena.tape[pos];
|
||||
}
|
||||
|
||||
static inline void *
|
||||
areturn(u32 checkpoint, const void *src, u32 size)
|
||||
{
|
||||
void *dest;
|
||||
if(arena == nil || src == nil) return nil;
|
||||
if(src == nil) return nil;
|
||||
|
||||
u32 current = arena->count;
|
||||
u32 current = arena.count;
|
||||
|
||||
dest = (void *)&arena->tape[checkpoint];
|
||||
dest = (void *)&arena.tape[checkpoint];
|
||||
if(src == dest) return dest;
|
||||
|
||||
mcpy(dest, (void *)src, size);
|
||||
arena->count = checkpoint + size;
|
||||
|
||||
// This is better but slower
|
||||
//for (u32 i = checkpoint + size; i < current; i++) {
|
||||
// arena->tape[i] = 0;
|
||||
//}
|
||||
arena.count = checkpoint + size;
|
||||
|
||||
// zero out the end of the memory copy (for strings mostly)
|
||||
arena->tape[arena->count] = 0;
|
||||
arena.tape[arena.count] = 0;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
#define ARENA_RETURN(arena, ckpt, src_ptr, type) \
|
||||
return (type *)areturn((arena), (ckpt), (src_ptr), sizeof(type))
|
||||
#define ARENA_RETURN(ckpt, src_ptr, type) \
|
||||
return (type *)areturn((ckpt), (src_ptr), sizeof(type))
|
||||
|
||||
#define ARENA_RETURN_ARRAY(arena, ckpt, src_ptr, type, count) \
|
||||
return (type *)areturn((arena), (ckpt), (src_ptr), sizeof(type) * (count))
|
||||
#define ARENA_RETURN_ARRAY(ckpt, src_ptr, type, count) \
|
||||
return (type *)areturn((ckpt), (src_ptr), sizeof(type) * (count))
|
||||
|
||||
#define ARENA_RETURN_STR(ckpt, src_ptr) \
|
||||
return (char *)areturn((ckpt), (src_ptr), slen(src_ptr))
|
||||
|
||||
#define ARENA_RETURN_STRBUF(ckpt, sbuf) \
|
||||
char *to_return = StrBuf_toS(sbuf); \
|
||||
return (char *)areturn((ckpt), (to_return), slen(to_return))
|
||||
|
||||
static inline r32
|
||||
int_to_real(i32 i)
|
||||
|
|
@ -307,29 +317,29 @@ real_abs(r32 f)
|
|||
}
|
||||
|
||||
static inline char *
|
||||
ascpy(Arena *arena, const char *start, u32 length)
|
||||
ascpy(const char *start, u32 length)
|
||||
{
|
||||
char *str;
|
||||
if(!start) return nil;
|
||||
str = (char *)aalloc(arena, length + 1);
|
||||
str = (char *)aalloc(length + 1);
|
||||
if(!str) return nil;
|
||||
scpy(str, start, length);
|
||||
return str;
|
||||
}
|
||||
|
||||
static inline void *
|
||||
amcpy(Arena *arena, void *from, u32 length)
|
||||
amcpy(void *from, u32 length)
|
||||
{
|
||||
void *ptr;
|
||||
if(!from) return nil;
|
||||
ptr = aalloc(arena, length);
|
||||
ptr = aalloc(length);
|
||||
if(!ptr) return nil;
|
||||
mcpy(ptr, from, length);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static inline char*
|
||||
int_to_string(Arena *arena, i32 v)
|
||||
int_to_string(i32 v)
|
||||
{
|
||||
char buffer[MAX_LEN_INT32] = {0};
|
||||
i32 n;
|
||||
|
|
@ -348,11 +358,11 @@ int_to_string(Arena *arena, i32 v)
|
|||
/* Ensure at least one digit is written for 0 */
|
||||
if(v == 0) buffer[--i] = '0';
|
||||
|
||||
return ascpy(arena, buffer + i, MAX_LEN_INT32 - i);
|
||||
return ascpy(buffer + i, MAX_LEN_INT32 - i);
|
||||
}
|
||||
|
||||
static inline char*
|
||||
nat_to_string(Arena *arena, u32 v)
|
||||
nat_to_string(u32 v)
|
||||
{
|
||||
char buffer[MAX_LEN_INT32] = {0};
|
||||
u32 n;
|
||||
|
|
@ -366,11 +376,11 @@ nat_to_string(Arena *arena, u32 v)
|
|||
/* Ensure at least one digit is written for 0 */
|
||||
if(v == 0) buffer[--i] = '0';
|
||||
|
||||
return ascpy(arena, buffer + i, MAX_LEN_INT32 - i);
|
||||
return ascpy(buffer + i, MAX_LEN_INT32 - i);
|
||||
}
|
||||
|
||||
static inline char*
|
||||
real_to_string(Arena *arena, r32 q)
|
||||
real_to_string(r32 q)
|
||||
{
|
||||
char buffer[MAX_LEN_REAL32] = {0};
|
||||
bool neg;
|
||||
|
|
@ -401,7 +411,7 @@ real_to_string(Arena *arena, r32 q)
|
|||
|
||||
if(neg) buffer[--i] = '-';
|
||||
|
||||
return ascpy(arena, buffer + i, MAX_LEN_REAL32 - i);
|
||||
return ascpy(buffer + i, MAX_LEN_REAL32 - i);
|
||||
}
|
||||
|
||||
typedef struct node_s Node;
|
||||
|
|
@ -423,7 +433,7 @@ typedef bool (*list_iter_fn)(void *data);
|
|||
List *
|
||||
List_init(Arena *arena)
|
||||
{
|
||||
List *l = (List*)aalloc(arena, sizeof(List));
|
||||
List *l = (List*)aalloc(sizeof(List));
|
||||
if (!l) return nil;
|
||||
|
||||
l->head = nil;
|
||||
|
|
@ -440,10 +450,10 @@ node_value(Node *n)
|
|||
}
|
||||
|
||||
void *
|
||||
List_push(Arena *arena, List *list, void *data, u32 data_size)
|
||||
List_push(List *list, void *data, u32 data_size)
|
||||
{
|
||||
void *dest;
|
||||
void *ptr = aalloc(arena, sizeof(Node) + data_size);
|
||||
void *ptr = aalloc(sizeof(Node) + data_size);
|
||||
Node *node = (Node *)ptr;
|
||||
|
||||
if (!node) return nil;
|
||||
|
|
@ -531,9 +541,9 @@ struct strbuf_s {
|
|||
};
|
||||
|
||||
StrBuf *
|
||||
StrBuf_init(Arena *arena)
|
||||
StrBuf_init()
|
||||
{
|
||||
StrBuf *l = (StrBuf*)aalloc(arena, sizeof(StrBuf));
|
||||
StrBuf *l = (StrBuf*)aalloc(sizeof(StrBuf));
|
||||
if (!l) return nil;
|
||||
|
||||
l->head = nil;
|
||||
|
|
@ -544,12 +554,12 @@ StrBuf_init(Arena *arena)
|
|||
}
|
||||
|
||||
void *
|
||||
StrBuf_append(Arena *arena, StrBuf *buf, char *str)
|
||||
StrBuf_append(StrBuf *buf, char *str)
|
||||
{
|
||||
u32 length = slen(str);
|
||||
|
||||
void *dest;
|
||||
void *ptr = aalloc(arena, sizeof(Node) + length);
|
||||
void *ptr = aalloc(sizeof(Node) + length);
|
||||
Node *node = (Node *)ptr;
|
||||
|
||||
if (!node) return nil;
|
||||
|
|
@ -575,20 +585,19 @@ StrBuf_append(Arena *arena, StrBuf *buf, char *str)
|
|||
}
|
||||
|
||||
char *
|
||||
StrBuf_toS(Arena *arena, StrBuf *buf)
|
||||
StrBuf_toS(StrBuf *buf)
|
||||
{
|
||||
Node *curr;
|
||||
char *tmp_str;
|
||||
|
||||
i32 pos = arena->count;
|
||||
char *str = (char *)&arena->tape[pos];
|
||||
char *str = (char *)aend();
|
||||
|
||||
if (!buf || !str) return nil;
|
||||
|
||||
curr = buf->head;
|
||||
while (curr) {
|
||||
tmp_str = node_value(curr);
|
||||
amcpy(arena, tmp_str, curr->size);
|
||||
amcpy(tmp_str, curr->size);
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
|
|
|
|||
170
test/plex.c
170
test/plex.c
|
|
@ -1,3 +1,5 @@
|
|||
#define __UNDAR_ARENA_SIZE__ 64000
|
||||
|
||||
#if defined(__has_include)
|
||||
#if __has_include(<stdint.h>)
|
||||
#define HAVE_STDINT 1
|
||||
|
|
@ -70,7 +72,6 @@ typedef u8 bool;
|
|||
|
||||
#define MAX_LEN_REAL32 12
|
||||
#define MAX_LEN_INT32 11
|
||||
#define MAX_LEN_UINT32 10
|
||||
const char radix_set[11] = "0123456789";
|
||||
|
||||
typedef struct arena_s Arena;
|
||||
|
|
@ -158,48 +159,59 @@ snlen(const char *str, u32 max_len)
|
|||
return i;
|
||||
}
|
||||
|
||||
u8 tape[__UNDAR_ARENA_SIZE__];
|
||||
Arena arena = {tape, 0, __UNDAR_ARENA_SIZE__};
|
||||
|
||||
static inline void *
|
||||
aalloc(Arena *arena, u32 size)
|
||||
aalloc(u32 size)
|
||||
{
|
||||
u32 pos;
|
||||
if(arena == nil) return nil;
|
||||
if(arena->count + size > arena->capacity) return nil;
|
||||
if(arena.count + size > arena.capacity) return nil;
|
||||
|
||||
pos = arena->count;
|
||||
arena->count += size;
|
||||
return (void *)&arena->tape[pos];
|
||||
pos = arena.count;
|
||||
arena.count += size;
|
||||
return (void *)&arena.tape[pos];
|
||||
}
|
||||
|
||||
static inline void *
|
||||
areturn(Arena *arena, u32 checkpoint, const void *src, u32 size)
|
||||
aend()
|
||||
{
|
||||
i32 pos = arena.count;
|
||||
return (void *)&arena.tape[pos];
|
||||
}
|
||||
|
||||
static inline void *
|
||||
areturn(u32 checkpoint, const void *src, u32 size)
|
||||
{
|
||||
void *dest;
|
||||
if(arena == nil || src == nil) return nil;
|
||||
if(src == nil) return nil;
|
||||
|
||||
u32 current = arena->count;
|
||||
u32 current = arena.count;
|
||||
|
||||
dest = (void *)&arena->tape[checkpoint];
|
||||
dest = (void *)&arena.tape[checkpoint];
|
||||
if(src == dest) return dest;
|
||||
|
||||
mcpy(dest, (void *)src, size);
|
||||
arena->count = checkpoint + size;
|
||||
|
||||
// This is better but slower
|
||||
//for (u32 i = checkpoint + size; i < current; i++) {
|
||||
// arena->tape[i] = 0;
|
||||
//}
|
||||
arena.count = checkpoint + size;
|
||||
|
||||
// zero out the end of the memory copy (for strings mostly)
|
||||
arena->tape[arena->count] = 0;
|
||||
arena.tape[arena.count] = 0;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
#define ARENA_RETURN(arena, ckpt, src_ptr, type) \
|
||||
return (type *)areturn((arena), (ckpt), (src_ptr), sizeof(type))
|
||||
#define ARENA_RETURN(ckpt, src_ptr, type) \
|
||||
return (type *)areturn((ckpt), (src_ptr), sizeof(type))
|
||||
|
||||
#define ARENA_RETURN_ARRAY(arena, ckpt, src_ptr, type, count) \
|
||||
return (type *)areturn((arena), (ckpt), (src_ptr), sizeof(type) * (count))
|
||||
#define ARENA_RETURN_ARRAY(ckpt, src_ptr, type, count) \
|
||||
return (type *)areturn((ckpt), (src_ptr), sizeof(type) * (count))
|
||||
|
||||
#define ARENA_RETURN_STR(ckpt, src_ptr) \
|
||||
return (char *)areturn((ckpt), (src_ptr), slen(src_ptr))
|
||||
|
||||
#define ARENA_RETURN_STRBUF(ckpt, sbuf) \
|
||||
char *to_return = StrBuf_toS(sbuf); \
|
||||
return (char *)areturn((ckpt), (to_return), slen(to_return))
|
||||
|
||||
static inline r32
|
||||
int_to_real(i32 i)
|
||||
|
|
@ -307,29 +319,29 @@ real_abs(r32 f)
|
|||
}
|
||||
|
||||
static inline char *
|
||||
ascpy(Arena *arena, const char *start, u32 length)
|
||||
ascpy(const char *start, u32 length)
|
||||
{
|
||||
char *str;
|
||||
if(!start) return nil;
|
||||
str = (char *)aalloc(arena, length + 1);
|
||||
str = (char *)aalloc(length + 1);
|
||||
if(!str) return nil;
|
||||
scpy(str, start, length);
|
||||
return str;
|
||||
}
|
||||
|
||||
static inline void *
|
||||
amcpy(Arena *arena, void *from, u32 length)
|
||||
amcpy(void *from, u32 length)
|
||||
{
|
||||
void *ptr;
|
||||
if(!from) return nil;
|
||||
ptr = aalloc(arena, length);
|
||||
ptr = aalloc(length);
|
||||
if(!ptr) return nil;
|
||||
mcpy(ptr, from, length);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static inline char*
|
||||
int_to_string(Arena *arena, i32 v)
|
||||
int_to_string(i32 v)
|
||||
{
|
||||
char buffer[MAX_LEN_INT32] = {0};
|
||||
i32 n;
|
||||
|
|
@ -348,11 +360,11 @@ int_to_string(Arena *arena, i32 v)
|
|||
/* Ensure at least one digit is written for 0 */
|
||||
if(v == 0) buffer[--i] = '0';
|
||||
|
||||
return ascpy(arena, buffer + i, MAX_LEN_INT32 - i);
|
||||
return ascpy(buffer + i, MAX_LEN_INT32 - i);
|
||||
}
|
||||
|
||||
static inline char*
|
||||
nat_to_string(Arena *arena, u32 v)
|
||||
nat_to_string(u32 v)
|
||||
{
|
||||
char buffer[MAX_LEN_INT32] = {0};
|
||||
u32 n;
|
||||
|
|
@ -366,11 +378,11 @@ nat_to_string(Arena *arena, u32 v)
|
|||
/* Ensure at least one digit is written for 0 */
|
||||
if(v == 0) buffer[--i] = '0';
|
||||
|
||||
return ascpy(arena, buffer + i, MAX_LEN_INT32 - i);
|
||||
return ascpy(buffer + i, MAX_LEN_INT32 - i);
|
||||
}
|
||||
|
||||
static inline char*
|
||||
real_to_string(Arena *arena, r32 q)
|
||||
real_to_string(r32 q)
|
||||
{
|
||||
char buffer[MAX_LEN_REAL32] = {0};
|
||||
bool neg;
|
||||
|
|
@ -401,7 +413,7 @@ real_to_string(Arena *arena, r32 q)
|
|||
|
||||
if(neg) buffer[--i] = '-';
|
||||
|
||||
return ascpy(arena, buffer + i, MAX_LEN_REAL32 - i);
|
||||
return ascpy(buffer + i, MAX_LEN_REAL32 - i);
|
||||
}
|
||||
|
||||
typedef struct node_s Node;
|
||||
|
|
@ -423,7 +435,7 @@ typedef bool (*list_iter_fn)(void *data);
|
|||
List *
|
||||
List_init(Arena *arena)
|
||||
{
|
||||
List *l = (List*)aalloc(arena, sizeof(List));
|
||||
List *l = (List*)aalloc(sizeof(List));
|
||||
if (!l) return nil;
|
||||
|
||||
l->head = nil;
|
||||
|
|
@ -440,10 +452,10 @@ node_value(Node *n)
|
|||
}
|
||||
|
||||
void *
|
||||
List_push(Arena *arena, List *list, void *data, u32 data_size)
|
||||
List_push(List *list, void *data, u32 data_size)
|
||||
{
|
||||
void *dest;
|
||||
void *ptr = aalloc(arena, sizeof(Node) + data_size);
|
||||
void *ptr = aalloc(sizeof(Node) + data_size);
|
||||
Node *node = (Node *)ptr;
|
||||
|
||||
if (!node) return nil;
|
||||
|
|
@ -531,9 +543,9 @@ struct strbuf_s {
|
|||
};
|
||||
|
||||
StrBuf *
|
||||
StrBuf_init(Arena *arena)
|
||||
StrBuf_init()
|
||||
{
|
||||
StrBuf *l = (StrBuf*)aalloc(arena, sizeof(StrBuf));
|
||||
StrBuf *l = (StrBuf*)aalloc(sizeof(StrBuf));
|
||||
if (!l) return nil;
|
||||
|
||||
l->head = nil;
|
||||
|
|
@ -544,12 +556,12 @@ StrBuf_init(Arena *arena)
|
|||
}
|
||||
|
||||
void *
|
||||
StrBuf_append(Arena *arena, StrBuf *buf, char *str)
|
||||
StrBuf_append(StrBuf *buf, char *str)
|
||||
{
|
||||
u32 length = slen(str);
|
||||
|
||||
void *dest;
|
||||
void *ptr = aalloc(arena, sizeof(Node) + length);
|
||||
void *ptr = aalloc(sizeof(Node) + length);
|
||||
Node *node = (Node *)ptr;
|
||||
|
||||
if (!node) return nil;
|
||||
|
|
@ -575,20 +587,19 @@ StrBuf_append(Arena *arena, StrBuf *buf, char *str)
|
|||
}
|
||||
|
||||
char *
|
||||
StrBuf_toS(Arena *arena, StrBuf *buf)
|
||||
StrBuf_toS(StrBuf *buf)
|
||||
{
|
||||
Node *curr;
|
||||
char *tmp_str;
|
||||
|
||||
i32 pos = arena->count;
|
||||
char *str = (char *)&arena->tape[pos];
|
||||
char *str = (char *)aend();
|
||||
|
||||
if (!buf || !str) return nil;
|
||||
|
||||
curr = buf->head;
|
||||
while (curr) {
|
||||
tmp_str = node_value(curr);
|
||||
amcpy(arena, tmp_str, curr->size);
|
||||
amcpy(tmp_str, curr->size);
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
|
|
@ -604,28 +615,27 @@ struct Point {
|
|||
};
|
||||
|
||||
Point *
|
||||
Point_init(Arena *a, u32 x, u32 y)
|
||||
Point_init(u32 x, u32 y)
|
||||
{
|
||||
Point *this = (Point *)aalloc(a, sizeof(Point));
|
||||
Point *this = (Point *)aalloc(sizeof(Point));
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
char*
|
||||
Point_toS(Arena *a, Point *this)
|
||||
Point_toS(Point *this)
|
||||
{
|
||||
u32 __UNDAR_FN_CHECKPOINT_REF__ = a->count;
|
||||
u32 __UNDAR_FN_CHECKPOINT_REF__ = arena.count;
|
||||
|
||||
StrBuf *buf = StrBuf_init(a);
|
||||
StrBuf_append(a, buf, "[x:");
|
||||
StrBuf_append(a, buf,nat_to_string(a, this->x));
|
||||
StrBuf_append(a, buf, ", y:");
|
||||
StrBuf_append(a, buf,nat_to_string(a, this->y));
|
||||
StrBuf_append(a, buf, "]");
|
||||
StrBuf *buf = StrBuf_init();
|
||||
StrBuf_append(buf, "[x:");
|
||||
StrBuf_append(buf,nat_to_string(this->x));
|
||||
StrBuf_append(buf, ", y:");
|
||||
StrBuf_append(buf,nat_to_string(this->y));
|
||||
StrBuf_append(buf, "]");
|
||||
|
||||
char *to_return = StrBuf_toS(a, buf);
|
||||
ARENA_RETURN_ARRAY(a, __UNDAR_FN_CHECKPOINT_REF__, to_return, char, slen(to_return));
|
||||
ARENA_RETURN_STRBUF(__UNDAR_FN_CHECKPOINT_REF__, buf);
|
||||
}
|
||||
|
||||
typedef struct Rect Rect;
|
||||
|
|
@ -637,9 +647,9 @@ struct Rect {
|
|||
};
|
||||
|
||||
Rect *
|
||||
Rect_init(Arena *a, Point *tl, Point *br, u32 width, u32 height)
|
||||
Rect_init(Point *tl, Point *br, u32 width, u32 height)
|
||||
{
|
||||
Rect *this = (Rect *)aalloc(a, sizeof(Rect));
|
||||
Rect *this = (Rect *)aalloc(sizeof(Rect));
|
||||
mcpy(&this->top_left, tl, sizeof(Point));
|
||||
mcpy(&this->bottom_right, br, sizeof(Point));
|
||||
this->width = width;
|
||||
|
|
@ -648,41 +658,39 @@ Rect_init(Arena *a, Point *tl, Point *br, u32 width, u32 height)
|
|||
}
|
||||
|
||||
char*
|
||||
Rect_toS(Arena *a, Rect *this)
|
||||
Rect_toS(Rect *this)
|
||||
{
|
||||
u32 __UNDAR_FN_CHECKPOINT_REF__ = a->count;
|
||||
u32 __UNDAR_FN_CHECKPOINT_REF__ = arena.count;
|
||||
|
||||
StrBuf *buf = StrBuf_init(a);
|
||||
StrBuf_append(a, buf, "[top_left: ");
|
||||
StrBuf_append(a, buf,Point_toS(a, &this->top_left));
|
||||
StrBuf_append(a, buf,", bottom_right: ");
|
||||
StrBuf_append(a, buf,Point_toS(a, &this->bottom_right));
|
||||
StrBuf_append(a, buf, ", width:");
|
||||
StrBuf_append(a, buf,nat_to_string(a, this->width));
|
||||
StrBuf_append(a, buf, ", height:");
|
||||
StrBuf_append(a, buf,nat_to_string(a, this->height));
|
||||
StrBuf_append(a, buf, "]");
|
||||
StrBuf *buf = StrBuf_init();
|
||||
StrBuf_append(buf, "[top_left: ");
|
||||
StrBuf_append(buf,Point_toS(&this->top_left));
|
||||
StrBuf_append(buf,", bottom_right: ");
|
||||
StrBuf_append(buf,Point_toS(&this->bottom_right));
|
||||
StrBuf_append(buf, ", width:");
|
||||
StrBuf_append(buf,nat_to_string(this->width));
|
||||
StrBuf_append(buf, ", height:");
|
||||
StrBuf_append(buf,nat_to_string(this->height));
|
||||
StrBuf_append(buf, "]");
|
||||
|
||||
char *to_return = StrBuf_toS(a, buf);
|
||||
ARENA_RETURN_ARRAY(a, __UNDAR_FN_CHECKPOINT_REF__, to_return, char, slen(to_return));
|
||||
ARENA_RETURN_STRBUF(__UNDAR_FN_CHECKPOINT_REF__, buf);
|
||||
}
|
||||
|
||||
Rect *
|
||||
create_geometry(Arena *a)
|
||||
create_geometry()
|
||||
{
|
||||
u32 __UNDAR_FN_CHECKPOINT_REF__ = a->count;
|
||||
u32 __UNDAR_FN_CHECKPOINT_REF__ = arena.count;
|
||||
|
||||
Point *tl = Point_init(a, 10, 20);
|
||||
Point *br = Point_init(a, 100, 200);
|
||||
Rect *final_rect = Rect_init(a, tl, br, 90, 180);
|
||||
Point *tl = Point_init(10, 20);
|
||||
Point *br = Point_init(100, 200);
|
||||
Rect *final_rect = Rect_init(tl, br, 90, 180);
|
||||
|
||||
ARENA_RETURN(a, __UNDAR_FN_CHECKPOINT_REF__, final_rect, Rect);
|
||||
ARENA_RETURN(__UNDAR_FN_CHECKPOINT_REF__, final_rect, Rect);
|
||||
}
|
||||
|
||||
int main() {
|
||||
unsigned char tape[64000];
|
||||
Arena a = {tape, 0, 64000};
|
||||
Rect *r = create_geometry(&a);
|
||||
printf("%s\n", Rect_toS(&a, r));
|
||||
|
||||
Rect *r = create_geometry();
|
||||
printf("%s\n", Rect_toS(r));
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue