toolchain: xpcg: replace bluelib with fx

This commit is contained in:
2026-03-21 10:33:39 +00:00
parent 68ae449731
commit ffc2ed735e
15 changed files with 524 additions and 538 deletions

View File

@@ -3,12 +3,12 @@
#include "line-source.h"
#include "token.h"
#include <blue/core/hash.h>
#include <blue/core/misc.h>
#include <blue/core/queue.h>
#include <blue/ds/dict.h>
#include <blue/ds/number.h>
#include <blue/ds/string.h>
#include <fx/core/hash.h>
#include <fx/core/misc.h>
#include <fx/core/queue.h>
#include <fx/ds/dict.h>
#include <fx/ds/number.h>
#include <fx/ds/string.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
@@ -21,10 +21,10 @@
#define LEX_TOKEN_DEF(i, n) {.id = (i), .name = (n)}
#define IS_VALID_IDENT_CHAR(c) \
(b_wchar_is_alnum(c) || c == '.' || c == '-' || c == '_')
(fx_wchar_is_alnum(c) || c == '.' || c == '-' || c == '_')
#define IS_VALID_IDENT_START_CHAR(c) \
(b_wchar_is_alpha(c) || c == '.' || c == '_')
#define IS_VALID_REG_START_CHAR(c) (b_wchar_is_alnum(c) || c == '.' || c == '_')
(fx_wchar_is_alpha(c) || c == '.' || c == '_')
#define IS_VALID_REG_START_CHAR(c) (fx_wchar_is_alnum(c) || c == '.' || c == '_')
static struct lex_token_def symbols[] = {
LEX_TOKEN_DEF(SYM_COMMA, ","),
@@ -51,27 +51,27 @@ static struct lex_symbol_node *get_symbol_node(
struct lex_symbol_node *node,
char c)
{
b_queue_entry *entry = b_queue_first(&node->s_children);
fx_queue_entry *entry = fx_queue_first(&node->s_children);
while (entry) {
struct lex_symbol_node *child
= b_unbox(struct lex_symbol_node, entry, s_entry);
= fx_unbox(struct lex_symbol_node, entry, s_entry);
if (child->s_char == c) {
return child;
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
return NULL;
}
static b_string *get_temp_string(struct lex *lex)
static fx_string *get_temp_string(struct lex *lex)
{
if (!lex->lex_temp) {
lex->lex_temp = b_string_create();
lex->lex_temp = fx_string_create();
}
b_string_clear(lex->lex_temp);
fx_string_clear(lex->lex_temp);
return lex->lex_temp;
}
@@ -97,7 +97,7 @@ static enum status put_symbol(
child->s_def = NULL;
child->s_char = c;
b_queue_push_back(&tree->s_children, &child->s_entry);
fx_queue_push_back(&tree->s_children, &child->s_entry);
tree = child;
}
@@ -107,12 +107,12 @@ static enum status put_symbol(
static void destroy_symbol_tree(struct lex_symbol_node *tree)
{
b_queue_entry *entry = b_queue_first(&tree->s_children);
fx_queue_entry *entry = fx_queue_first(&tree->s_children);
while (entry) {
struct lex_symbol_node *node
= b_unbox(struct lex_symbol_node, entry, s_entry);
b_queue_entry *next = b_queue_next(entry);
b_queue_delete(&tree->s_children, entry);
= fx_unbox(struct lex_symbol_node, entry, s_entry);
fx_queue_entry *next = fx_queue_next(entry);
fx_queue_delete(&tree->s_children, entry);
destroy_symbol_tree(node);
@@ -168,12 +168,12 @@ struct lex *lex_create(struct line_source *src)
void lex_destroy(struct lex *lex)
{
b_queue_entry *entry = b_queue_first(&lex->lex_queue);
fx_queue_entry *entry = fx_queue_first(&lex->lex_queue);
while (entry) {
struct token *tok = b_unbox(struct token, entry, tok_entry);
b_queue_entry *next = b_queue_next(entry);
b_queue_delete(&lex->lex_queue, entry);
struct token *tok = fx_unbox(struct token, entry, tok_entry);
fx_queue_entry *next = fx_queue_next(entry);
fx_queue_delete(&lex->lex_queue, entry);
token_destroy(tok);
@@ -185,7 +185,7 @@ void lex_destroy(struct lex *lex)
}
if (lex->lex_temp) {
b_string_unref(lex->lex_temp);
fx_string_unref(lex->lex_temp);
}
free(lex);
@@ -245,7 +245,7 @@ static enum status push_token(struct lex *lex, struct token *tok)
tok->tok_location.s_start = lex->lex_token_start;
tok->tok_location.s_end = lex->lex_token_end;
b_queue_push_back(&lex->lex_queue, &tok->tok_entry);
fx_queue_push_back(&lex->lex_queue, &tok->tok_entry);
return SUCCESS;
}
@@ -326,7 +326,7 @@ static enum status push_int(struct lex *lex, unsigned long long v)
static enum status read_line_comment(struct lex *lex)
{
while (true) {
b_wchar c = line_source_getc(lex->lex_source);
fx_wchar c = line_source_getc(lex->lex_source);
if (c == -ERR_EOF || c == '\n') {
break;
@@ -345,14 +345,14 @@ static enum status read_number(struct lex *lex, bool negate)
int token_len = 0;
int base = 10;
int dots = 0;
b_string *str = get_temp_string(lex);
fx_string *str = get_temp_string(lex);
if (!negate) {
set_token_start(lex);
}
while (true) {
b_wchar c = line_source_peekc(lex->lex_source);
fx_wchar c = line_source_peekc(lex->lex_source);
if (c == -ERR_EOF) {
break;
}
@@ -372,7 +372,7 @@ static enum status read_number(struct lex *lex, bool negate)
return ERR_BAD_SYNTAX;
}
if (b_wchar_is_space(c) || b_wchar_is_punct(c)) {
if (fx_wchar_is_space(c) || fx_wchar_is_punct(c)) {
break;
}
@@ -404,7 +404,7 @@ static enum status read_number(struct lex *lex, bool negate)
return ERR_BAD_SYNTAX;
}
b_string_append_wc(str, c);
fx_string_append_wc(str, c);
set_token_end(lex);
line_source_getc(lex->lex_source);
token_len++;
@@ -414,7 +414,7 @@ static enum status read_number(struct lex *lex, bool negate)
return push_int(lex, 0);
}
const char *s = b_string_ptr(str);
const char *s = fx_string_ptr(str);
char *ep = NULL;
/* negative numbers will be lexed as a hyphen followed by a positive
@@ -447,15 +447,15 @@ static enum token_keyword find_keyword(const char *s)
static enum status read_ident(struct lex *lex, enum token_type type)
{
int dots = 0;
b_string *str = get_temp_string(lex);
b_wchar prev = 0;
fx_string *str = get_temp_string(lex);
fx_wchar prev = 0;
if (type == TOK_NONE) {
set_token_start(lex);
}
while (1) {
b_wchar c = line_source_peekc(lex->lex_source);
fx_wchar c = line_source_peekc(lex->lex_source);
if ((c == '.' || c == '-') && prev == c) {
return ERR_BAD_SYNTAX;
@@ -470,7 +470,7 @@ static enum status read_ident(struct lex *lex, enum token_type type)
}
prev = c;
b_string_append_wc(str, c);
fx_string_append_wc(str, c);
set_token_end(lex);
line_source_getc(lex->lex_source);
}
@@ -479,7 +479,7 @@ static enum status read_ident(struct lex *lex, enum token_type type)
type = dots > 0 ? TOK_NAME : TOK_WORD;
}
char *s = b_string_steal(str);
char *s = fx_string_steal(str);
enum token_keyword kw = find_keyword(s);
if (kw != KW_NONE) {
free(s);
@@ -491,9 +491,9 @@ static enum status read_ident(struct lex *lex, enum token_type type)
static enum status read_string(struct lex *lex)
{
b_string *str = get_temp_string(lex);
fx_string *str = get_temp_string(lex);
b_wchar c = line_source_peekc(lex->lex_source);
fx_wchar c = line_source_peekc(lex->lex_source);
bool esc = false;
if (c != '"') {
@@ -503,13 +503,13 @@ static enum status read_string(struct lex *lex)
line_source_getc(lex->lex_source);
while (1) {
b_wchar c = line_source_peekc(lex->lex_source);
fx_wchar c = line_source_peekc(lex->lex_source);
if (esc) {
switch (c) {
case '\\':
case '"':
b_string_append_wc(str, c);
fx_string_append_wc(str, c);
break;
default:
return ERR_BAD_SYNTAX;
@@ -531,11 +531,11 @@ static enum status read_string(struct lex *lex)
break;
}
b_string_append_wc(str, c);
fx_string_append_wc(str, c);
line_source_getc(lex->lex_source);
}
char *s = b_string_steal(str);
char *s = fx_string_steal(str);
return push_string_token(lex, TOK_STRING, s);
}
@@ -543,10 +543,10 @@ static enum status read_symbol(struct lex *lex)
{
struct lex_symbol_node *node = lex->lex_sym_tree;
set_token_start(lex);
b_wchar prev = 0;
fx_wchar prev = 0;
while (true) {
b_wchar c = line_source_peekc(lex->lex_source);
fx_wchar c = line_source_peekc(lex->lex_source);
if (c < 0) {
break;
}
@@ -576,17 +576,17 @@ static enum status read_symbol(struct lex *lex)
static void skip_whitespace(struct lex *lex)
{
b_wchar c = line_source_peekc(lex->lex_source);
fx_wchar c = line_source_peekc(lex->lex_source);
while (b_wchar_is_space(c)) {
while (fx_wchar_is_space(c)) {
line_source_getc(lex->lex_source);
c = line_source_peekc(lex->lex_source);
}
}
static bool should_skip(b_wchar c, bool skip_linefeeds)
static bool should_skip(fx_wchar c, bool skip_linefeeds)
{
bool skip = b_wchar_is_space(c);
bool skip = fx_wchar_is_space(c);
if (!skip_linefeeds) {
skip = (skip && c != '\n');
@@ -597,7 +597,7 @@ static bool should_skip(b_wchar c, bool skip_linefeeds)
static void skip_ignored_chars(struct lex *lex, bool include_linefeeds)
{
b_wchar c = line_source_peekc(lex->lex_source);
fx_wchar c = line_source_peekc(lex->lex_source);
while (1) {
while (should_skip(c, include_linefeeds)) {
@@ -624,14 +624,14 @@ static void skip_ignored_chars(struct lex *lex, bool include_linefeeds)
static enum status pump_tokens(struct lex *lex)
{
b_wchar c = line_source_peekc(lex->lex_source);
fx_wchar c = line_source_peekc(lex->lex_source);
if (c < 0) {
return -c;
}
while (1) {
if (c == '#' || (b_wchar_is_space(c) && c != '\n')) {
if (c == '#' || (fx_wchar_is_space(c) && c != '\n')) {
skip_ignored_chars(lex, false);
} else {
break;
@@ -667,7 +667,7 @@ static enum status pump_tokens(struct lex *lex)
return SUCCESS;
}
while (b_wchar_is_space(c) && c != '\n') {
while (fx_wchar_is_space(c) && c != '\n') {
line_source_getc(lex->lex_source);
c = line_source_peekc(lex->lex_source);
}
@@ -695,7 +695,7 @@ struct token *lex_peek(struct lex *lex)
{
enum status status = SUCCESS;
while (b_queue_empty(&lex->lex_queue)) {
while (fx_queue_empty(&lex->lex_queue)) {
status = pump_tokens(lex);
if (status != SUCCESS) {
@@ -706,8 +706,8 @@ struct token *lex_peek(struct lex *lex)
lex->lex_status = status;
b_queue_entry *entry = b_queue_first(&lex->lex_queue);
struct token *tok = b_unbox(struct token, entry, tok_entry);
fx_queue_entry *entry = fx_queue_first(&lex->lex_queue);
struct token *tok = fx_unbox(struct token, entry, tok_entry);
return tok;
}
@@ -715,7 +715,7 @@ void lex_advance(struct lex *lex)
{
enum status status = SUCCESS;
while (b_queue_empty(&lex->lex_queue)) {
while (fx_queue_empty(&lex->lex_queue)) {
status = pump_tokens(lex);
if (status != SUCCESS) {
@@ -724,14 +724,14 @@ void lex_advance(struct lex *lex)
}
}
b_queue_entry *entry = b_queue_pop_front(&lex->lex_queue);
struct token *tok = b_unbox(struct token, entry, tok_entry);
fx_queue_entry *entry = fx_queue_pop_front(&lex->lex_queue);
struct token *tok = fx_unbox(struct token, entry, tok_entry);
token_destroy(tok);
}
bool lex_tokens_available(struct lex *lex)
{
if (!b_queue_empty(&lex->lex_queue)) {
if (!fx_queue_empty(&lex->lex_queue)) {
return true;
}