core: Add program data types

Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
2026-02-15 18:08:20 -05:00
parent a2a866a010
commit 1ad72ea5a2
4 changed files with 80 additions and 0 deletions

View File

@@ -231,6 +231,28 @@ lexer_check_kw(struct rifle_state *state, struct token *tok)
}
switch (*tok->s) {
case 'u':
if (strcmp(tok->s, "u8") == 0) {
tok->type = TT_U8;
return;
}
if (strcmp(tok->s, "u16") == 0) {
tok->type = TT_U16;
return;
}
if (strcmp(tok->s, "u32") == 0) {
tok->type = TT_U32;
return;
}
if (strcmp(tok->s, "u64") == 0) {
tok->type = TT_U64;
return;
}
break;
case '.':
lexer_check_direc(state, tok);
break;

View File

@@ -61,6 +61,10 @@ static const char *toktab[] = {
[TT_F] = qtok(".f"),
[TT_STRUCT] = qtok(".struct"),
[TT_EXTERN] = qtok(".extern"),
[TT_U8] = qtok("u8"),
[TT_U16] = qtok("u16"),
[TT_U32] = qtok("u32"),
[TT_U64] = qtok("u64"),
[TT_DEFINE] = qtok("#define"),
[TT_IFDEF] = qtok("#ifdef"),
[TT_IFNDEF] = qtok("#ifndef"),

View File

@@ -22,6 +22,10 @@ typedef enum {
TT_F, /* '.f' */
TT_STRUCT, /* '.struct' */
TT_EXTERN, /* '.extern' */
TT_U8, /* 'u8' */
TT_U16, /* 'u16' */
TT_U32, /* 'u32' */
TT_U64, /* 'u64' */
TT_DEFINE, /* '#define' */
TT_IFDEF, /* '#ifdef' */
TT_IFNDEF, /* '#ifndef' */

50
inc/rifle/types.h Normal file
View File

@@ -0,0 +1,50 @@
#ifndef RIFLE_TYPES_H
#define RIFLE_TYPES_H
#include <stdint.h>
#include "rifle/token.h"
/*
* Represents basic data types
*/
typedef enum {
DATA_TYPE_BAD,
DATA_TYPE_U8,
DATA_TYPE_U16,
DATA_TYPE_U32,
DATA_TYPE_U64
} data_type_t;
/*
* Represents an actual data type along with metadata
* like pointer depth.
*
* @type: Data type
* @ptr_depth: Depth within pointer
*/
struct data_type {
data_type_t type;
uint8_t ptr_depth;
};
/*
* Convert a token type into a data type GRAB IT
* CHOKE IT! FUCK FUCK FUCK FUCK anyways
*
* @token: The token type to convert
*/
static inline data_type_t
token_to_data_type(tt_t token)
{
switch (token) {
case TT_U8: return DATA_TYPE_U8;
case TT_U16: return DATA_TYPE_U16;
case TT_U32: return DATA_TYPE_U32;
case TT_U64: return DATA_TYPE_U64;
default: return DATA_TYPE_BAD;
}
return DATA_TYPE_BAD;
}
#endif /* !RIFLE_TYPES_H */