1#ifndef REDUCT_ATOM_IMPL_H
2#define REDUCT_ATOM_IMPL_H 1
19 *current = atom->
next;
22 current = &(*current)->
next;
38 unsigned long long uval;
43 uval = (
unsigned long long)(-value);
48 uval = (
unsigned long long)value;
53 buf[
sizeof(buf) - 1 - len++] =
'0';
57 buf[
sizeof(buf) - 1 - len++] = (
char)(
'0' + (uval % 10));
62 buf[
sizeof(buf) - 1 - len++] =
'-';
65 const char* str = buf +
sizeof(buf) - len;
67 atom->integerValue = value;
88 unsigned long long intPart = (
unsigned long long)val;
89 double fracPart = val - (double)intPart;
97 unsigned long long uIntPart = intPart;
108 *--p = (char)(
'0' + (uIntPart % 10));
122 for (
int i = 0; i < 6; i++)
125 int digit = (int)fracPart;
126 res[len++] = (char)(
'0' + digit);
127 fracPart -= (double)digit;
130 while (len > 1 && res[len - 1] ==
'0' && res[len - 2] !=
'.')
166 *current = atom->
next;
172 current = &(*current)->
next;
191 atom->
small[len] =
'\0';
217 if (str[i] ==
'\\' && i + 1 < len)
226 else if (str[i] ==
'x' && i + 2 < len)
228 unsigned char high =
reductCharTable[(
unsigned char)str[i + 1]].integer;
229 unsigned char low =
reductCharTable[(
unsigned char)str[i + 2]].integer;
230 str[j++] = (char)((high << 4) | low);
270 const char* p = atom->
string;
271 const char* end = p + atom->
length;
272 const char* start = p;
275 if (p < end && (*p ==
'+' || *p ==
'-'))
307 if (p + 1 < end && *p ==
'0')
338 if (!sectionHasDigits)
348 unsigned char c = (
unsigned char)*p;
354 if (d >= 0 && d < base)
356 intValue = intValue * base + d;
367 if (valid && hasDigits && p == end && *(end - 1) !=
'_')
381 double floatValue = 0.0;
382 double fractionDiv = 10.0;
400 if (!sectionHasDigits)
409 unsigned char c = (
unsigned char)*p;
430 else if (c ==
'.' && !inFraction && !inExponent)
452 if (p < end && (*p ==
'+' || *p ==
'-'))
470 if (inExponent && exponentDigits == 0)
475 if (valid && hasDigits && p == end && *(end - 1) !=
'_')
480 double finalVal = floatValue;
481 if (inExponent && expValue != 0)
484 double baseMult = 10.0;
492 baseMult *= baseMult;
Atom representation and operations.
REDUCT_API void reduct_atom_normalize(reduct_t *reduct, reduct_atom_t *atom)
REDUCT_API reduct_atom_t * reduct_atom_lookup(reduct_t *reduct, const char *str, reduct_size_t len, reduct_atom_lookup_flags_t flags)
REDUCT_API reduct_atom_t * reduct_atom_lookup_float(reduct_t *reduct, reduct_float_t value)
REDUCT_API void reduct_atom_deinit(reduct_t *reduct, reduct_atom_t *atom)
static void reduct_atom_normalize_escape(reduct_atom_t *atom)
REDUCT_API reduct_atom_t * reduct_atom_lookup_int(reduct_t *reduct, reduct_int64_t value)
Core definitions and structures.
#define REDUCT_MALLOC(_size)
reduct_bool_t
Boolean type.
#define REDUCT_INF
INFINITY constant.
#define REDUCT_CONTAINER_OF(_ptr, _type, _member)
Container of macro.
#define REDUCT_NAN
NAN constant.
#define REDUCT_MEMCPY(_dest, _src, _size)
#define REDUCT_ASSERT(_cond)
#define REDUCT_FREE(_ptr)
#define REDUCT_UNUSED(_x)
reduct_atom_lookup_flags_t
Atom lookup flags.
static REDUCT_ALWAYS_INLINE reduct_bool_t reduct_atom_is_equal(reduct_atom_t *atom, const char *str, reduct_size_t len)
Check if an atom is equal to a string.
#define REDUCT_ATOM_SMALL_MAX
The maximum length of a small atom.
static REDUCT_ALWAYS_INLINE reduct_uint32_t reduct_hash(const char *str, reduct_size_t len)
Hash a string.
@ REDUCT_ATOM_LOOKUP_NONE
No flags.
@ REDUCT_ATOM_LOOKUP_QUOTED
Atom should be explicitly quoted.
#define REDUCT_CHAR_TO_LOWER(_c)
Get the lowercase equivalent of a character.
reduct_char_info_t reductCharTable[256]
Global character lookup table.
#define REDUCT_CHAR_IS_DIGIT(_c)
Check if a character is a decimal digit.
#define REDUCT_CHAR_IS_HEX_DIGIT(_c)
Check if a character is a hexidecimal digit.
#define REDUCT_BUCKETS_MAX
Amount of buckets used for intering atoms.
#define REDUCT_ERROR_INTERNAL(_reduct,...)
Throw an internal error using the jump buffer in the error structure.
#define REDUCT_INTRINSIC_NONE
None.
#define REDUCT_ITEM_TYPE_ATOM
An atom.
#define REDUCT_ITEM_FLAG_INT_SHAPED
Item is an integer shaped atom.
#define REDUCT_ITEM_FLAG_FLOAT_SHAPED
Item is a float shaped atom.
REDUCT_API reduct_item_t * reduct_item_new(struct reduct *reduct)
Allocate a new Reduct item.
#define REDUCT_ITEM_FLAG_FALSY
Item is falsy.
#define REDUCT_ITEM_FLAG_QUOTED
Item is a quoted atom.
char small[REDUCT_ATOM_SMALL_MAX]
The small string buffer.
reduct_int64_t integerValue
Pre-computed integer value, item must have REDUCT_ITEM_FLAG_INT_SHAPED.
reduct_uint32_t hash
The hash of the string.
reduct_uint32_t length
The length of the string (must be first, check the reduct_item_t structure).
char * string
Pointer to the string.
struct reduct_atom * next
Pointer to the next atom in the hash map.
reduct_float_t floatValue
Pre-computed float value, item must have REDUCT_ITEM_FLAG_FLOAT_SHAPED.
reduct_intrinsic_t intrinsic
Cached intrinsic, item must have REDUCT_ITEM_FLAG_INTRINSIC.
char decodeEscape
The char to decode to when escaped.
unsigned char integer
Integer value.
reduct_item_flags_t flags
Flags for the item.
reduct_atom_t atom
An atom.
reduct_item_type_t type
The type of the item.
struct reduct_atom * atomBuckets[REDUCT_BUCKETS_MAX]