meta: replace bluelib with fx
This commit is contained in:
128
asm/lex.c
128
asm/lex.c
@@ -1,10 +1,10 @@
|
||||
#include "lex.h"
|
||||
|
||||
#include <blue/core/hash.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/queue.h>
|
||||
#include <fx/ds/dict.h>
|
||||
#include <fx/ds/number.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ctype.h>
|
||||
#include <ivy/asm/lex.h>
|
||||
#include <stdbool.h>
|
||||
@@ -63,40 +63,40 @@ static struct lexer_state *push_lexer_state(
|
||||
memset(state, 0x0, sizeof *state);
|
||||
|
||||
state->s_type = state_type;
|
||||
b_queue_push_back(&lex->lex_state, &state->s_entry);
|
||||
fx_queue_push_back(&lex->lex_state, &state->s_entry);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
static void pop_lexer_state(struct ivy_asm_lexer *lex)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_pop_back(&lex->lex_state);
|
||||
fx_queue_entry *entry = fx_queue_pop_back(&lex->lex_state);
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct lexer_state *state = b_unbox(struct lexer_state, entry, s_entry);
|
||||
struct lexer_state *state = fx_unbox(struct lexer_state, entry, s_entry);
|
||||
free(state);
|
||||
}
|
||||
|
||||
static struct lexer_state *get_lexer_state(struct ivy_asm_lexer *lex)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(&lex->lex_state);
|
||||
fx_queue_entry *entry = fx_queue_last(&lex->lex_state);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct lexer_state, entry, s_entry);
|
||||
return fx_unbox(struct lexer_state, entry, s_entry);
|
||||
}
|
||||
|
||||
static void destroy_state_stack(b_queue *state)
|
||||
static void destroy_state_stack(fx_queue *state)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(state);
|
||||
fx_queue_entry *entry = fx_queue_first(state);
|
||||
while (entry) {
|
||||
struct lexer_state *node
|
||||
= b_unbox(struct lexer_state, entry, s_entry);
|
||||
b_queue_entry *next = b_queue_next(entry);
|
||||
b_queue_delete(state, entry);
|
||||
= fx_unbox(struct lexer_state, entry, s_entry);
|
||||
fx_queue_entry *next = fx_queue_next(entry);
|
||||
fx_queue_delete(state, entry);
|
||||
|
||||
free(node);
|
||||
|
||||
@@ -107,27 +107,27 @@ static void destroy_state_stack(b_queue *state)
|
||||
static struct ivy_asm_lexer_symbol_node *get_symbol_node(
|
||||
struct ivy_asm_lexer_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 ivy_asm_lexer_symbol_node *child = b_unbox(
|
||||
struct ivy_asm_lexer_symbol_node *child = fx_unbox(
|
||||
struct ivy_asm_lexer_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 ivy_asm_lexer *lex)
|
||||
static fx_string *get_temp_string(struct ivy_asm_lexer *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;
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ static enum ivy_status put_symbol(
|
||||
child->s_id = IVY_ASM_SYM_NONE;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -162,12 +162,12 @@ static enum ivy_status put_symbol(
|
||||
|
||||
static void destroy_symbol_tree(struct ivy_asm_lexer_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 ivy_asm_lexer_symbol_node *node = b_unbox(
|
||||
struct ivy_asm_lexer_symbol_node *node = fx_unbox(
|
||||
struct ivy_asm_lexer_symbol_node, entry, s_entry);
|
||||
b_queue_entry *next = b_queue_next(entry);
|
||||
b_queue_delete(&tree->s_children, entry);
|
||||
fx_queue_entry *next = fx_queue_next(entry);
|
||||
fx_queue_delete(&tree->s_children, entry);
|
||||
|
||||
destroy_symbol_tree(node);
|
||||
|
||||
@@ -200,23 +200,23 @@ static struct ivy_asm_lexer_symbol_node *build_symbol_tree(void)
|
||||
return root;
|
||||
}
|
||||
|
||||
static void init_keywords(b_dict *keyword_dict)
|
||||
static void init_keywords(fx_dict *keyword_dict)
|
||||
{
|
||||
for (size_t i = 0; i < nr_keywords; i++) {
|
||||
struct lex_token_def *keyword = &keywords[i];
|
||||
b_dict_put(keyword_dict, keyword->name, B_RV_INT(keyword->id));
|
||||
fx_dict_put(keyword_dict, keyword->name, FX_RV_INT(keyword->id));
|
||||
}
|
||||
}
|
||||
|
||||
static enum ivy_asm_keyword find_keyword_by_name(
|
||||
struct ivy_asm_lexer *lex, const char *s)
|
||||
{
|
||||
b_number *id = b_dict_at(lex->lex_keywords, s);
|
||||
fx_number *id = fx_dict_at(lex->lex_keywords, s);
|
||||
if (!id) {
|
||||
return IVY_ASM_KW_NONE;
|
||||
}
|
||||
|
||||
return b_number_get_int(id);
|
||||
return fx_number_get_int(id);
|
||||
}
|
||||
|
||||
enum ivy_status ivy_asm_lexer_create(struct ivy_asm_lexer **lexp)
|
||||
@@ -245,7 +245,7 @@ enum ivy_status ivy_asm_lexer_create(struct ivy_asm_lexer **lexp)
|
||||
return IVY_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
lex->lex_keywords = b_dict_create();
|
||||
lex->lex_keywords = fx_dict_create();
|
||||
init_keywords(lex->lex_keywords);
|
||||
*lexp = lex;
|
||||
|
||||
@@ -254,13 +254,13 @@ enum ivy_status ivy_asm_lexer_create(struct ivy_asm_lexer **lexp)
|
||||
|
||||
void ivy_asm_lexer_destroy(struct ivy_asm_lexer *lex)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&lex->lex_queue);
|
||||
fx_queue_entry *entry = fx_queue_first(&lex->lex_queue);
|
||||
|
||||
while (entry) {
|
||||
struct ivy_asm_token *tok
|
||||
= b_unbox(struct ivy_asm_token, entry, t_entry);
|
||||
b_queue_entry *next = b_queue_next(entry);
|
||||
b_queue_delete(&lex->lex_queue, entry);
|
||||
= fx_unbox(struct ivy_asm_token, entry, t_entry);
|
||||
fx_queue_entry *next = fx_queue_next(entry);
|
||||
fx_queue_delete(&lex->lex_queue, entry);
|
||||
|
||||
ivy_asm_token_destroy(tok);
|
||||
|
||||
@@ -276,11 +276,11 @@ void ivy_asm_lexer_destroy(struct ivy_asm_lexer *lex)
|
||||
}
|
||||
|
||||
if (lex->lex_temp) {
|
||||
b_string_unref(lex->lex_temp);
|
||||
fx_string_unref(lex->lex_temp);
|
||||
}
|
||||
|
||||
if (lex->lex_keywords) {
|
||||
b_dict_unref(lex->lex_keywords);
|
||||
fx_dict_unref(lex->lex_keywords);
|
||||
}
|
||||
|
||||
destroy_state_stack(&lex->lex_state);
|
||||
@@ -411,7 +411,7 @@ static struct ivy_asm_token *create_token(enum ivy_asm_token_type type)
|
||||
static enum ivy_status push_token(
|
||||
struct ivy_asm_lexer *lex, struct ivy_asm_token *tok)
|
||||
{
|
||||
b_queue_push_back(&lex->lex_queue, &tok->t_entry);
|
||||
fx_queue_push_back(&lex->lex_queue, &tok->t_entry);
|
||||
lex->lex_prev_token = tok->t_type;
|
||||
return IVY_OK;
|
||||
}
|
||||
@@ -610,7 +610,7 @@ static enum ivy_status read_dquote_marker(struct ivy_asm_lexer *lex)
|
||||
static enum ivy_status read_string_content(struct ivy_asm_lexer *lex)
|
||||
{
|
||||
int c;
|
||||
b_string *str = get_temp_string(lex);
|
||||
fx_string *str = get_temp_string(lex);
|
||||
struct lexer_state *state = get_lexer_state(lex);
|
||||
|
||||
if (!str) {
|
||||
@@ -629,15 +629,15 @@ static enum ivy_status read_string_content(struct ivy_asm_lexer *lex)
|
||||
}
|
||||
|
||||
char s[2] = {c, 0};
|
||||
b_string_append_cstr(str, s);
|
||||
fx_string_append_cstr(str, s);
|
||||
advance(lex);
|
||||
}
|
||||
|
||||
if (b_string_get_size(str, B_STRLEN_NORMAL) == 0) {
|
||||
if (fx_string_get_size(str, FX_STRLEN_NORMAL) == 0) {
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
char *s = b_string_steal(str);
|
||||
char *s = fx_string_steal(str);
|
||||
|
||||
enum ivy_status status = push_string_content(lex, s);
|
||||
if (status != IVY_OK) {
|
||||
@@ -692,7 +692,7 @@ static enum ivy_status read_number(struct ivy_asm_lexer *lex)
|
||||
int base = 10;
|
||||
int dots = 0;
|
||||
bool neg = false;
|
||||
b_string *str = get_temp_string(lex);
|
||||
fx_string *str = get_temp_string(lex);
|
||||
|
||||
while (true) {
|
||||
int c = peek(lex);
|
||||
@@ -733,7 +733,7 @@ static enum ivy_status read_number(struct ivy_asm_lexer *lex)
|
||||
token_len++;
|
||||
dots++;
|
||||
char s[] = {c, 0};
|
||||
b_string_append_cstr(str, s);
|
||||
fx_string_append_cstr(str, s);
|
||||
advance(lex);
|
||||
continue;
|
||||
}
|
||||
@@ -776,7 +776,7 @@ static enum ivy_status read_number(struct ivy_asm_lexer *lex)
|
||||
}
|
||||
|
||||
char s[] = {c, 0};
|
||||
b_string_append_cstr(str, s);
|
||||
fx_string_append_cstr(str, s);
|
||||
token_len++;
|
||||
advance(lex);
|
||||
}
|
||||
@@ -785,7 +785,7 @@ static enum ivy_status read_number(struct ivy_asm_lexer *lex)
|
||||
return push_uint(lex, 0);
|
||||
}
|
||||
|
||||
const char *s = b_string_ptr(str);
|
||||
const char *s = fx_string_ptr(str);
|
||||
char *ep = NULL;
|
||||
|
||||
if (dots > 0) {
|
||||
@@ -826,8 +826,8 @@ static enum ivy_status read_keyword(struct ivy_asm_lexer *lex)
|
||||
{
|
||||
advance(lex);
|
||||
|
||||
b_string *str = get_temp_string(lex);
|
||||
b_string_append_cstr(str, "@");
|
||||
fx_string *str = get_temp_string(lex);
|
||||
fx_string_append_cstr(str, "@");
|
||||
|
||||
bool label = false;
|
||||
|
||||
@@ -843,11 +843,11 @@ static enum ivy_status read_keyword(struct ivy_asm_lexer *lex)
|
||||
}
|
||||
|
||||
char s[2] = {c, 0};
|
||||
b_string_append_cstr(str, s);
|
||||
fx_string_append_cstr(str, s);
|
||||
advance(lex);
|
||||
}
|
||||
|
||||
const char *s = b_string_ptr(str);
|
||||
const char *s = fx_string_ptr(str);
|
||||
|
||||
enum ivy_asm_keyword keyword = find_keyword_by_name(lex, s);
|
||||
|
||||
@@ -862,7 +862,7 @@ static enum ivy_status read_label_ref(struct ivy_asm_lexer *lex)
|
||||
{
|
||||
advance(lex);
|
||||
|
||||
b_string *str = get_temp_string(lex);
|
||||
fx_string *str = get_temp_string(lex);
|
||||
bool label = false;
|
||||
|
||||
while (true) {
|
||||
@@ -883,21 +883,21 @@ static enum ivy_status read_label_ref(struct ivy_asm_lexer *lex)
|
||||
}
|
||||
|
||||
char s[2] = {c, 0};
|
||||
b_string_append_cstr(str, s);
|
||||
fx_string_append_cstr(str, s);
|
||||
advance(lex);
|
||||
}
|
||||
|
||||
const char *s = b_string_ptr(str);
|
||||
const char *s = fx_string_ptr(str);
|
||||
|
||||
struct ivy_asm_token *tok = create_token(IVY_ASM_TOK_LABEL_REF);
|
||||
tok->t_str = b_string_steal(str);
|
||||
tok->t_str = fx_string_steal(str);
|
||||
|
||||
return push_token(lex, tok);
|
||||
}
|
||||
|
||||
static enum ivy_status read_ident(struct ivy_asm_lexer *lex)
|
||||
{
|
||||
b_string *str = get_temp_string(lex);
|
||||
fx_string *str = get_temp_string(lex);
|
||||
bool label = false;
|
||||
|
||||
while (true) {
|
||||
@@ -918,15 +918,15 @@ static enum ivy_status read_ident(struct ivy_asm_lexer *lex)
|
||||
}
|
||||
|
||||
char s[2] = {c, 0};
|
||||
b_string_append_cstr(str, s);
|
||||
fx_string_append_cstr(str, s);
|
||||
advance(lex);
|
||||
}
|
||||
|
||||
const char *s = b_string_ptr(str);
|
||||
const char *s = fx_string_ptr(str);
|
||||
|
||||
struct ivy_asm_token *tok
|
||||
= create_token(label ? IVY_ASM_TOK_LABEL : IVY_ASM_TOK_IDENT);
|
||||
tok->t_str = b_string_steal(str);
|
||||
tok->t_str = fx_string_steal(str);
|
||||
|
||||
return push_token(lex, tok);
|
||||
}
|
||||
@@ -1003,7 +1003,7 @@ struct ivy_asm_token *ivy_asm_lexer_peek(struct ivy_asm_lexer *lex)
|
||||
{
|
||||
enum ivy_status status = IVY_OK;
|
||||
|
||||
while (b_queue_empty(&lex->lex_queue)) {
|
||||
while (fx_queue_empty(&lex->lex_queue)) {
|
||||
status = pump_tokens(lex);
|
||||
|
||||
if (status != IVY_OK) {
|
||||
@@ -1013,8 +1013,8 @@ struct ivy_asm_token *ivy_asm_lexer_peek(struct ivy_asm_lexer *lex)
|
||||
}
|
||||
|
||||
lex->lex_status = status;
|
||||
b_queue_entry *entry = b_queue_first(&lex->lex_queue);
|
||||
struct ivy_asm_token *tok = b_unbox(struct ivy_asm_token, entry, t_entry);
|
||||
fx_queue_entry *entry = fx_queue_first(&lex->lex_queue);
|
||||
struct ivy_asm_token *tok = fx_unbox(struct ivy_asm_token, entry, t_entry);
|
||||
return tok;
|
||||
}
|
||||
|
||||
@@ -1022,7 +1022,7 @@ struct ivy_asm_token *ivy_asm_lexer_read(struct ivy_asm_lexer *lex)
|
||||
{
|
||||
enum ivy_status status = IVY_OK;
|
||||
|
||||
while (b_queue_empty(&lex->lex_queue)) {
|
||||
while (fx_queue_empty(&lex->lex_queue)) {
|
||||
status = pump_tokens(lex);
|
||||
|
||||
if (status != IVY_OK) {
|
||||
@@ -1031,8 +1031,8 @@ struct ivy_asm_token *ivy_asm_lexer_read(struct ivy_asm_lexer *lex)
|
||||
}
|
||||
}
|
||||
|
||||
b_queue_entry *entry = b_queue_pop_front(&lex->lex_queue);
|
||||
struct ivy_asm_token *tok = b_unbox(struct ivy_asm_token, entry, t_entry);
|
||||
fx_queue_entry *entry = fx_queue_pop_front(&lex->lex_queue);
|
||||
struct ivy_asm_token *tok = fx_unbox(struct ivy_asm_token, entry, t_entry);
|
||||
|
||||
return tok;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user