diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-05-14 21:12:58 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-05-15 22:25:45 +0100 |
commit | 12de1e8db90bccd5a0eefd21075f07c7b7e3dfaa (patch) | |
tree | 0434141f2bfd24207a2864f613a1c2e3ee7181fc /tag.h | |
parent | ba5c0a4579ece5d53c009a14d00e683e70b982f4 (diff) | |
download | oats-12de1e8db90bccd5a0eefd21075f07c7b7e3dfaa.tar.gz oats-12de1e8db90bccd5a0eefd21075f07c7b7e3dfaa.tar.bz2 oats-12de1e8db90bccd5a0eefd21075f07c7b7e3dfaa.zip |
Refactor for cleanliness
Move files into separate folders for ease of reading, include source
directory so we can use angle bracket includes, adjust build system to
make directories for objects
Diffstat (limited to 'tag.h')
-rw-r--r-- | tag.h | 90 |
1 files changed, 0 insertions, 90 deletions
@@ -1,90 +0,0 @@ -/* Copyright (C) 2025 Aryadev Chavali - - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License Version 2 for - * details. - - * You may distribute and modify this code under the terms of the GNU General - * Public License Version 2, which you should have received a copy of along with - * this program. If not, please go to <https://www.gnu.org/licenses/>. - - * Created: 2025-04-06 - * Description: - */ - -#ifndef TAG_H -#define TAG_H - -#include "./base.h" - -#include <stdbool.h> -#include <stdlib.h> - -// Opaque structure to make tagged pointers a separate type from general -// pointers -typedef struct Obj lisp_t; - -enum Tag -{ - TAG_NIL = 0b00000000, // Atomic types - TAG_INT = 0b00000001, // special so we can encode 63 bit integers - TAG_SYM = 0b00000100, - TAG_SSYM = 0b00001000, - TAG_CHAR = 0b00001100, - TAG_BOOL = 0b00010000, - // TAG_FLOAT = 0b00010100, - TAG_CONS = 0b00000010, // Container types - TAG_VEC = 0b00000110, - TAG_STR = 0b00001010, - - NUM_TAGS = 9, -}; - -enum Shift -{ - SHIFT_INT = 1, - SHIFT_SSYM = 5, - SHIFT_CHAR = 8, - SHIFT_SYM = 8, - SHIFT_BOOL = 8, - SHIFT_FLOAT = 8, - - SHIFT_CONS = 8, - SHIFT_VEC = 8, - SHIFT_STR = 8, -}; - -enum Mask -{ - MASK_INT = 0b00000001, - MASK_SSYM = 0b00011111, - MASK_SYM = 0b11111111, - MASK_CHAR = 0b11111111, - MASK_BOOL = 0b11111111, - MASK_FLOAT = 0b11111111, - - MASK_CONS = 0b11111111, - MASK_VEC = 0b11111111, - MASK_STR = 0b11111111, -}; - -#define TAG(PTR, TYPE) ((lisp_t *)(((PTR) << SHIFT_##TYPE) | TAG_##TYPE)) -#define IS_TAG(PTR, TYPE) (((u64)(PTR) & MASK_##TYPE) == TAG_##TYPE) -#define UNTAG(PTR, TYPE) (((u64)PTR) >> SHIFT_##TYPE) - -enum Tag tag_get(lisp_t *ptr); - -lisp_t *tag_int(i64 i); -lisp_t *tag_char(u32 codepoint); -lisp_t *tag_sym(void *ptr); -lisp_t *tag_ssym(const char *data, size_t size); -lisp_t *tag_bool(bool b); -lisp_t *tag_vec(void *ptr); -lisp_t *tag_str(void *ptr); -lisp_t *tag_cons(void *ptr); - -#define INT_MAX ((1L << 62) - 1) -#define INT_MIN (-(1L << 62)) - -#endif |