tomo/builtins/integers.h

45 lines
1.5 KiB
C
Raw Normal View History

2024-02-17 16:32:30 -08:00
#pragma once
2024-03-18 09:57:49 -07:00
// Integer type infos and methods
2024-02-17 16:32:30 -08:00
#include <gc/cord.h>
#include <stdbool.h>
#include <stdint.h>
#include "datatypes.h"
2024-02-17 16:32:30 -08:00
#include "types.h"
#define Int_t int64_t
#define Int32_t int32_t
#define Int16_t int16_t
#define Int8_t int8_t
#define I64(x) ((int64_t)x)
#define I32(x) ((int32_t)x)
#define I16(x) ((int16_t)x)
#define I8(x) ((int8_t)x)
2024-02-17 16:52:37 -08:00
#define DEFINE_INT_TYPE(c_type, type_name) \
2024-03-03 15:16:33 -08:00
CORD type_name ## __as_text(const c_type *i, bool colorize, const TypeInfo *type); \
2024-02-17 16:52:37 -08:00
int32_t type_name ## __compare(const c_type *x, const c_type *y, const TypeInfo *type); \
bool type_name ## __equal(const c_type *x, const c_type *y, const TypeInfo *type); \
2024-02-17 16:52:37 -08:00
CORD type_name ## __format(c_type i, int64_t digits); \
CORD type_name ## __hex(c_type i, int64_t digits, bool uppercase, bool prefix); \
CORD type_name ## __octal(c_type i, int64_t digits, bool prefix); \
array_t type_name ## __bits(c_type x); \
2024-02-17 16:52:37 -08:00
c_type type_name ## __random(int64_t min, int64_t max); \
2024-02-27 10:39:12 -08:00
extern const c_type type_name ## __min, type_name##__max; \
2024-02-27 10:47:29 -08:00
extern const TypeInfo type_name;
2024-02-17 16:52:37 -08:00
DEFINE_INT_TYPE(int64_t, Int);
2024-02-17 16:32:30 -08:00
DEFINE_INT_TYPE(int32_t, Int32);
DEFINE_INT_TYPE(int16_t, Int16);
DEFINE_INT_TYPE(int8_t, Int8);
#undef DEFINE_INT_TYPE
2024-02-27 10:39:12 -08:00
#define Int__abs(...) I64(labs(__VA_ARGS__))
#define Int32__abs(...) I32(abs(__VA_ARGS__))
#define Int16__abs(...) I16(abs(__VA_ARGS__))
#define Int8__abs(...) I8(abs(__VA_ARGS__))
2024-02-17 16:32:30 -08:00
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0