diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-21 21:48:53 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-21 21:48:53 -0400 |
| commit | 5ee185a4896e43c67b6d299becfa616da78fb9f4 (patch) | |
| tree | 183ceef2fd21230c89334d7d039255d1c86c5dca /src/stdlib/pointers.h | |
| parent | f4aaf7b73481248f6768302be688700a364a1af8 (diff) | |
Move stdlib into src/
Diffstat (limited to 'src/stdlib/pointers.h')
| -rw-r--r-- | src/stdlib/pointers.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/stdlib/pointers.h b/src/stdlib/pointers.h new file mode 100644 index 00000000..165a5184 --- /dev/null +++ b/src/stdlib/pointers.h @@ -0,0 +1,36 @@ +#pragma once + +// Type infos and methods for Pointer types + +#include <stdbool.h> +#include <stdint.h> + +#include "datatypes.h" +#include "types.h" +#include "util.h" + +Text_t Pointer$as_text(const void *x, bool colorize, const TypeInfo_t *type); +PUREFUNC int32_t Pointer$compare(const void *x, const void *y, const TypeInfo_t *type); +PUREFUNC bool Pointer$equal(const void *x, const void *y, const TypeInfo_t *type); +PUREFUNC bool Pointer$is_none(const void *x, const TypeInfo_t*); +void Pointer$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type); +void Pointer$deserialize(FILE *in, void *outval, Array_t *pointers, const TypeInfo_t *type); + +#define Null(t) (t*)NULL +#define POINTER_TYPE(_sigil, _pointed) (&(TypeInfo_t){\ + .size=sizeof(void*), .align=alignof(void*), .tag=PointerInfo, .PointerInfo.sigil=_sigil, .PointerInfo.pointed=_pointed}) + +#define Pointer$metamethods { \ + .as_text=Pointer$as_text, \ + .compare=Pointer$compare, \ + .equal=Pointer$equal, \ + .is_none=Pointer$is_none, \ + .serialize=Pointer$serialize, \ + .deserialize=Pointer$deserialize, \ +} + +#define Pointer$info(sigil_expr, pointed_info) &((TypeInfo_t){.size=sizeof(void*), .align=__alignof__(void*), \ + .tag=PointerInfo, .PointerInfo={.sigil=sigil_expr, .pointed=pointed_info}, \ + .metamethods=Pointer$metamethods}) + +// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 |
