Purple  0.1
Standard Language Specification
Classes | Macros | Typedefs | Enumerations | Functions | Variables
number.h File Reference

Definitions and function headers for the internal "Number" type. More...

#include <limits.h>
Include dependency graph for number.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Number
 Container for various kinds of number data. More...
 

Macros

#define NUMBER_BOOL(v)
 Generates a Number struct with type INT1. More...
 
#define NUMBER_CHAR(v)
 Generates a Number struct with type INT8. More...
 
#define NUMBER_SHORT(v)
 Generates a Number struct with type INT16. More...
 
#define NUMBER_INT(v)
 Generates a Number struct with type INT32. More...
 
#define NUMBER_LONG(v)
 Generates a Number struct with type INT64. More...
 
#define NUMBER_FROM_TYPE_VAL(t, v)
 Generates a Number struct given a NumberType and a value. More...
 
#define NT_MAX(a, b)   (a > b ? a : b)
 Determines the larger NumberType of two. More...
 
#define NT_MIN(a, b)   (NT_MAX(a, b) == a ? b : a)
 Determines the smaller NumberType of two. More...
 

Typedefs

typedef struct Number Number
 Container for various kinds of number data. More...
 

Enumerations

enum  NumberType {
  NT_INT1 , NT_INT8 , NT_INT16 , NT_INT32 ,
  NT_INT64
}
 Types of numbers supported by Purple. More...
 

Functions

NumberType token_type_to_number_type (int token_type)
 Convert a TokenType to a NumberType. More...
 
int number_to_token_type (Number number)
 

Variables

static const int numberTypeByteSizes []
 Size of each NumberType. More...
 
static const int numberTypeBitSizes [] = {1, 8, 16, 32, 64}
 Bit size of each NumberType. More...
 
static const unsigned long long int numberTypeMaxValues []
 Max value of each NumberType. More...
 
static const char * numberTypeFormatStrings [] = {"%d", "%d", "%d", "%d", "%ld"}
 Format strings for each data type. More...
 

Detailed Description

Definitions and function headers for the internal "Number" type.

Author
Charles Averill
Date
12-Sep-2022

Macro Definition Documentation

◆ NT_MAX

#define NT_MAX (   a,
 
)    (a > b ? a : b)

Determines the larger NumberType of two.

◆ NT_MIN

#define NT_MIN (   a,
 
)    (NT_MAX(a, b) == a ? b : a)

Determines the smaller NumberType of two.

◆ NUMBER_BOOL

#define NUMBER_BOOL (   v)
Value:
(Number) \
{ \
.type = NT_INT1, .value = v \
}
struct Number Number
Container for various kinds of number data.
@ NT_INT1
Definition: number.h:18

Generates a Number struct with type INT1.

◆ NUMBER_CHAR

#define NUMBER_CHAR (   v)
Value:
(Number) \
{ \
.type = NT_INT8, .value = v \
}
@ NT_INT8
Definition: number.h:19

Generates a Number struct with type INT8.

◆ NUMBER_FROM_TYPE_VAL

#define NUMBER_FROM_TYPE_VAL (   t,
 
)
Value:
(Number) \
{ \
.type = t, .value = v \
}

Generates a Number struct given a NumberType and a value.

◆ NUMBER_INT

#define NUMBER_INT (   v)
Value:
(Number) \
{ \
.type = NT_INT32, .value = v \
}
@ NT_INT32
Definition: number.h:21

Generates a Number struct with type INT32.

◆ NUMBER_LONG

#define NUMBER_LONG (   v)
Value:
(Number) \
{ \
.type = NT_INT64, .value = v \
}
@ NT_INT64
Definition: number.h:22

Generates a Number struct with type INT64.

◆ NUMBER_SHORT

#define NUMBER_SHORT (   v)
Value:
(Number) \
{ \
.type = NT_INT16, .value = v \
}
@ NT_INT16
Definition: number.h:20

Generates a Number struct with type INT16.

Typedef Documentation

◆ Number

typedef struct Number Number

Container for various kinds of number data.

Enumeration Type Documentation

◆ NumberType

enum NumberType

Types of numbers supported by Purple.

Enumerator
NT_INT1 
NT_INT8 
NT_INT16 
NT_INT32 
NT_INT64 

Function Documentation

◆ number_to_token_type()

int number_to_token_type ( Number  number)

◆ token_type_to_number_type()

NumberType token_type_to_number_type ( int  token_type)

Convert a TokenType to a NumberType.

Parameters
token_typeTokenType to convert
Returns
NumberType Converted TokenType

Variable Documentation

◆ numberTypeBitSizes

const int numberTypeBitSizes[] = {1, 8, 16, 32, 64}
static

Bit size of each NumberType.

◆ numberTypeByteSizes

const int numberTypeByteSizes[]
static
Initial value:
= {
1, 1, 2, 4, 8,
}

Size of each NumberType.

◆ numberTypeFormatStrings

const char* numberTypeFormatStrings[] = {"%d", "%d", "%d", "%d", "%ld"}
static

Format strings for each data type.

◆ numberTypeMaxValues

const unsigned long long int numberTypeMaxValues[]
static
Initial value:
= {1, CHAR_MAX, SHRT_MAX, INT_MAX,
LONG_MAX}

Max value of each NumberType.