2024-02-04 15:04:41 -08:00
|
|
|
#pragma once
|
|
|
|
|
2024-03-18 09:57:49 -07:00
|
|
|
// A few helper macros
|
|
|
|
|
2024-02-04 15:04:41 -08:00
|
|
|
#include <gc.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2024-04-16 10:50:07 -07:00
|
|
|
#define heap(x) (__typeof(x)*)memcpy(GC_MALLOC(sizeof(x)), (__typeof(x)[1]){x}, sizeof(x))
|
2024-05-12 17:12:00 -07:00
|
|
|
#define stack(x) (__typeof(x)*)((__typeof(x)[1]){x})
|
2024-04-16 10:50:07 -07:00
|
|
|
#define tagged(obj_expr, type_name, tag_name) ({ __typeof(obj_expr) obj = obj_expr; \
|
|
|
|
obj.$tag == $tag$##type_name##$##tag_name ? &obj.tag_name : NULL; })
|