1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
/* kc3
* Copyright 2022,2023,2024 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
/**
* @file tag.h
* @brief Run-time type annotations.
*
* Structure to add a type tag to data.
*/
#ifndef LIBKC3_TAG_H
#define LIBKC3_TAG_H
#include <stdarg.h>
#include "tag_init.h"
#include "tag_type.h"
#define TAG_FIRST (&g_tag_first)
#define TAG_LAST (&g_tag_last)
extern s_tag g_tag_first;
extern s_tag g_tag_last;
/* Stack-allocation compatible functions, call tag_clean after use. */
void tag_clean (s_tag *tag);
s_tag * tag_init (s_tag *tag);
s_tag * tag_init_1 (s_tag *tag, const char *p);
s_tag * tag_init_call_cast (s_tag *tag, const s_sym *type);
/* Heap-allocation functions, call tag_delete after use. */
void tag_delete (s_tag *tag);
s_tag * tag_new (void);
s_tag * tag_new_1 (const char *p);
/* Observers */
s8 tag_arity (const s_tag *tag);
u64 * tag_hash_u64 (const s_tag *tag, u64 *dest);
uw * tag_hash_uw (const s_tag *tag, uw *dest);
bool tag_ident_is_bound (const s_tag *tag);
bool tag_is_alist (const s_tag *tag);
bool tag_is_bound_var (const s_tag *tag);
bool tag_is_number (const s_tag *tag);
bool * tag_is_unbound_var (const s_tag *tag, bool *dest);
bool tag_is_zero(const s_tag *tag);
s8 tag_number_compare (const s_tag *a, const s_tag *b);
const s_tag * tag_resolve_cow (const s_tag *tag);
uw * tag_size (const s_tag *tag, uw *dest);
ffi_type tag_to_ffi_type(const s_tag *tag);
const s_sym ** tag_type (const s_tag *tag, const s_sym **type);
/* Operators. */
s_tag * tag_1 (s_tag *tag, const char *p);
s_tag * tag_integer_cast_to_s16 (const s_tag *tag, s_tag *dest);
s_tag * tag_integer_cast_to_s32 (const s_tag *tag, s_tag *dest);
s_tag * tag_integer_cast_to_s64 (const s_tag *tag, s_tag *dest);
s_tag * tag_integer_cast_to_s8 (const s_tag *tag, s_tag *dest);
s_tag * tag_integer_cast_to_u16 (const s_tag *tag, s_tag *dest);
s_tag * tag_integer_cast_to_u32 (const s_tag *tag, s_tag *dest);
s_tag * tag_integer_cast_to_u64 (const s_tag *tag, s_tag *dest);
s_tag * tag_integer_cast_to_u8 (const s_tag *tag, s_tag *dest);
s_tag * tag_integer_reduce (s_tag *tag);
s_tag * tag_list_1 (s_tag *tag, const char *p);
bool tag_to_const_pointer (const s_tag *tag, const s_sym *type,
const void **dest);
bool tag_to_ffi_pointer (s_tag *tag, const s_sym *type, void **dest);
bool tag_to_pointer (s_tag *tag, const s_sym *type, void **dest);
/* KC3 operators. */
s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest);
bool * tag_and (const s_tag *a, const s_tag *b, bool *dest);
s_tag * tag_band (const s_tag *a, const s_tag *b, s_tag *dest);
s_tag * tag_bnot (const s_tag *tag, s_tag *dest);
s_tag * tag_bor (const s_tag *a, const s_tag *b, s_tag *dest);
s_tag * tag_brackets (const s_tag *tag, const s_tag *address,
s_tag *dest);
s_tag * tag_bxor (const s_tag *a, const s_tag *b, s_tag *dest);
s_tag * tag_div (const s_tag *a, const s_tag *b, s_tag *dest);
bool * tag_lt (const s_tag *a, const s_tag *b, bool *dest);
bool * tag_lte (const s_tag *a, const s_tag *b, bool *dest);
bool * tag_gt (const s_tag *a, const s_tag *b, bool *dest);
bool * tag_gte (const s_tag *a, const s_tag *b, bool *dest);
bool * tag_eq (const s_tag *a, const s_tag *b, bool *dest);
s_tag * tag_equal (const s_tag *a, const s_tag *b, s_tag *dest);
s_tag * tag_mod (const s_tag *a, const s_tag *b, s_tag *dest);
s_tag * tag_mul (const s_tag *a, const s_tag *b, s_tag *dest);
s_tag * tag_neg (const s_tag *tag, s_tag *dest);
bool * tag_not (const s_tag *tag, bool *dest);
bool * tag_not_eq (const s_tag *a, const s_tag *b, bool *dest);
bool * tag_or (const s_tag *a, const s_tag *b, bool *dest);
s_tag * tag_paren (const s_tag *tag, s_tag *dest);
s_tag * tag_shift_left (const s_tag *a, const s_tag *b, s_tag *dest);
s_tag * tag_shift_right (const s_tag *a, const s_tag *b, s_tag *dest);
s_tag * tag_sqrt (const s_tag *tag, s_tag *dest);
s_tag * tag_sub (const s_tag *a, const s_tag *b, s_tag *dest);
#endif /* LIBKC3_TAG_H */