meta: replace bluelib with fx
This commit is contained in:
@@ -11,5 +11,5 @@ else ()
|
||||
endif ()
|
||||
|
||||
target_include_directories(ivy-lang PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)
|
||||
target_link_libraries(ivy-lang mie ivy-diag ivy-common Bluelib::Core Bluelib::Ds Bluelib::Term)
|
||||
target_link_libraries(ivy-lang mie ivy-diag ivy-common FX::Core FX::Ds FX::Term)
|
||||
target_compile_definitions(ivy-lang PRIVATE IVY_EXPORT=1 IVY_STATIC=${IVY_STATIC})
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
static void to_string(struct ivy_ast_node *node, fx_string *str)
|
||||
{
|
||||
struct ivy_ast_atom_node *v = (struct ivy_ast_atom_node *)node;
|
||||
|
||||
b_string_append_cstrf(
|
||||
fx_string_append_cstrf(
|
||||
str, "%s (%s)", ivy_ast_node_type_to_string(node->n_type),
|
||||
v->n_content->t_str);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "iterate.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
|
||||
void block_add_terminator(struct block_parser_state *state, unsigned short tok)
|
||||
@@ -134,7 +134,7 @@ static enum ivy_status add_child(
|
||||
struct ivy_ast_block_node *block
|
||||
= (struct ivy_ast_block_node *)parent->s_node;
|
||||
|
||||
b_queue_push_back(&block->n_expr, &child->n_entry);
|
||||
fx_queue_push_back(&block->n_expr, &child->n_entry);
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
@@ -143,12 +143,12 @@ static void collect_children(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
|
||||
{
|
||||
struct ivy_ast_block_node *block = (struct ivy_ast_block_node *)node;
|
||||
b_queue_entry *entry = b_queue_first(&block->n_expr);
|
||||
fx_queue_entry *entry = fx_queue_first(&block->n_expr);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *expr
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, expr);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,12 +11,12 @@ static void collect_children(
|
||||
ast_node_iterator_enqueue_node(iterator, node, cascade->n_recipient);
|
||||
}
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&cascade->n_msg);
|
||||
fx_queue_entry *entry = fx_queue_first(&cascade->n_msg);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *arg
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, arg);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "iterate.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -130,10 +130,10 @@ static enum ivy_status add_child(
|
||||
|
||||
switch (child->n_type) {
|
||||
case IVY_AST_MSGH:
|
||||
b_queue_push_back(&c->n_msg_handlers, &child->n_entry);
|
||||
fx_queue_push_back(&c->n_msg_handlers, &child->n_entry);
|
||||
break;
|
||||
case IVY_AST_PROPERTY:
|
||||
b_queue_push_back(&c->n_properties, &child->n_entry);
|
||||
fx_queue_push_back(&c->n_properties, &child->n_entry);
|
||||
break;
|
||||
default:
|
||||
return IVY_ERR_NOT_SUPPORTED;
|
||||
@@ -142,11 +142,11 @@ static enum ivy_status add_child(
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
static void to_string(struct ivy_ast_node *node, fx_string *str)
|
||||
{
|
||||
struct ivy_ast_class_node *c = (struct ivy_ast_class_node *)node;
|
||||
|
||||
b_string_append_cstrf(
|
||||
fx_string_append_cstrf(
|
||||
str, "%s (%s)", ivy_ast_node_type_to_string(node->n_type),
|
||||
c->n_ident->t_str);
|
||||
}
|
||||
@@ -162,20 +162,20 @@ static void collect_children(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
|
||||
{
|
||||
struct ivy_ast_class_node *c = (struct ivy_ast_class_node *)node;
|
||||
b_queue_entry *entry = b_queue_first(&c->n_properties);
|
||||
fx_queue_entry *entry = fx_queue_first(&c->n_properties);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *child
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, child);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
entry = b_queue_first(&c->n_msg_handlers);
|
||||
entry = fx_queue_first(&c->n_msg_handlers);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *child
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, child);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ struct cond_group_parser_state {
|
||||
unsigned int s_prev_token;
|
||||
|
||||
struct ivy_ast_cond_node *s_cur_branch;
|
||||
b_queue s_branches;
|
||||
fx_queue s_branches;
|
||||
|
||||
struct ivy_ast_node *s_prev_node;
|
||||
};
|
||||
@@ -26,7 +26,7 @@ static enum ivy_status flush_current_branch(struct cond_group_parser_state *stat
|
||||
return IVY_ERR_INTERNAL_FAILURE;
|
||||
}
|
||||
|
||||
b_queue_push_back(&state->s_branches, &state->s_cur_branch->n_base.n_entry);
|
||||
fx_queue_push_back(&state->s_branches, &state->s_cur_branch->n_base.n_entry);
|
||||
|
||||
state->s_cur_branch
|
||||
= (struct ivy_ast_cond_node *)ast_node_create(IVY_AST_COND);
|
||||
@@ -255,7 +255,7 @@ static enum ivy_status finalise_cond_group(struct cond_group_parser_state *state
|
||||
flush_current_branch(state);
|
||||
|
||||
group->n_branches = state->s_branches;
|
||||
state->s_branches = B_QUEUE_INIT;
|
||||
state->s_branches = FX_QUEUE_INIT;
|
||||
return IVY_OK;
|
||||
} else {
|
||||
/* we have just reached the 'end' keyword. */
|
||||
@@ -274,7 +274,7 @@ static enum ivy_status finalise_cond_group(struct cond_group_parser_state *state
|
||||
flush_current_branch(state);
|
||||
|
||||
group->n_branches = state->s_branches;
|
||||
state->s_branches = B_QUEUE_INIT;
|
||||
state->s_branches = FX_QUEUE_INIT;
|
||||
return IVY_OK;
|
||||
}
|
||||
}
|
||||
@@ -339,12 +339,12 @@ static void cond_group_collect_children(
|
||||
struct ivy_ast_cond_group_node *group
|
||||
= (struct ivy_ast_cond_group_node *)node;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&group->n_branches);
|
||||
fx_queue_entry *entry = fx_queue_first(&group->n_branches);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *branch
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, branch);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "../debug.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/core/queue.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <ivy/diag.h>
|
||||
#include <ivy/lang/ast.h>
|
||||
#include <stddef.h>
|
||||
@@ -14,10 +14,10 @@
|
||||
#ifdef IVY_LANG_DEBUG
|
||||
static void print_state_stack(struct ivy_parser *parser)
|
||||
{
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &parser->p_state) {
|
||||
fx_queue_iterator it = {0};
|
||||
fx_queue_foreach (&it, &parser->p_state) {
|
||||
struct parser_state *state
|
||||
= b_unbox(struct parser_state, it.entry, s_entry);
|
||||
= fx_unbox(struct parser_state, it.entry, s_entry);
|
||||
debug_printf(
|
||||
" %s\n",
|
||||
ivy_ast_node_type_to_string(state->s_node->n_type));
|
||||
@@ -44,13 +44,13 @@ void ivy_parser_destroy(struct ivy_parser *parser, struct ivy_ast_node **result)
|
||||
{
|
||||
struct ivy_ast_node *root = NULL;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&parser->p_state);
|
||||
fx_queue_entry *entry = fx_queue_first(&parser->p_state);
|
||||
;
|
||||
while (entry) {
|
||||
struct parser_state *state
|
||||
= b_unbox(struct parser_state, entry, s_entry);
|
||||
b_queue_entry *next = b_queue_next(entry);
|
||||
b_queue_delete(&parser->p_state, entry);
|
||||
= fx_unbox(struct parser_state, entry, s_entry);
|
||||
fx_queue_entry *next = fx_queue_next(entry);
|
||||
fx_queue_delete(&parser->p_state, entry);
|
||||
|
||||
if (root) {
|
||||
ivy_ast_node_destroy(root);
|
||||
@@ -173,29 +173,29 @@ enum ivy_status ivy_parser_push_eof(struct ivy_parser *parser)
|
||||
|
||||
struct parser_state *parser_get_state_generic(struct ivy_parser *parser)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(&parser->p_state);
|
||||
fx_queue_entry *entry = fx_queue_last(&parser->p_state);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
|
||||
struct parser_state *state = fx_unbox(struct parser_state, entry, s_entry);
|
||||
return state;
|
||||
}
|
||||
|
||||
struct parser_state *parser_get_parent_state_generic(
|
||||
struct ivy_parser *parser, enum ivy_ast_node_type type)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(&parser->p_state);
|
||||
fx_queue_entry *entry = fx_queue_last(&parser->p_state);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
entry = b_queue_prev(entry);
|
||||
entry = fx_queue_prev(entry);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
|
||||
struct parser_state *state = fx_unbox(struct parser_state, entry, s_entry);
|
||||
|
||||
if (state->s_node->n_type != type) {
|
||||
return NULL;
|
||||
@@ -219,15 +219,15 @@ struct parser_state *parser_push_state(
|
||||
|
||||
memset(state, 0x0, node_type->n_state_size);
|
||||
|
||||
b_queue_entry *current_state_entry = b_queue_last(&parser->p_state);
|
||||
fx_queue_entry *current_state_entry = fx_queue_last(&parser->p_state);
|
||||
if (current_state_entry) {
|
||||
struct parser_state *current_state = b_unbox(
|
||||
struct parser_state *current_state = fx_unbox(
|
||||
struct parser_state, current_state_entry, s_entry);
|
||||
state->s_parent = current_state->s_node;
|
||||
}
|
||||
|
||||
state->s_node = ast_node_create(type);
|
||||
b_queue_push_back(&parser->p_state, &state->s_entry);
|
||||
fx_queue_push_back(&parser->p_state, &state->s_entry);
|
||||
|
||||
if (node_type->n_init_state) {
|
||||
node_type->n_init_state(parser, state, arg);
|
||||
@@ -246,9 +246,9 @@ void parser_pop_state(struct ivy_parser *parser, enum pop_state_flags flags)
|
||||
return;
|
||||
}
|
||||
|
||||
b_queue_entry *entry = b_queue_last(&parser->p_state);
|
||||
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
|
||||
b_queue_pop_back(&parser->p_state);
|
||||
fx_queue_entry *entry = fx_queue_last(&parser->p_state);
|
||||
struct parser_state *state = fx_unbox(struct parser_state, entry, s_entry);
|
||||
fx_queue_pop_back(&parser->p_state);
|
||||
|
||||
if (state && state->s_node && (flags & STATE_ADD_NODE_TO_PARENT)) {
|
||||
parser_add_child(parser, state->s_node);
|
||||
@@ -298,15 +298,15 @@ bool ivy_parser_is_node_complete(struct ivy_parser *parser)
|
||||
|
||||
struct ivy_ast_node *ivy_parser_root_node(struct ivy_parser *parser)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&parser->p_state);
|
||||
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
|
||||
fx_queue_entry *entry = fx_queue_first(&parser->p_state);
|
||||
struct parser_state *state = fx_unbox(struct parser_state, entry, s_entry);
|
||||
return state ? state->s_node : NULL;
|
||||
}
|
||||
|
||||
struct ivy_ast_node *ivy_parser_dequeue_node(struct ivy_parser *parser)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&parser->p_state);
|
||||
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
|
||||
fx_queue_entry *entry = fx_queue_first(&parser->p_state);
|
||||
struct parser_state *state = fx_unbox(struct parser_state, entry, s_entry);
|
||||
|
||||
if (!state) {
|
||||
return NULL;
|
||||
@@ -318,13 +318,13 @@ struct ivy_ast_node *ivy_parser_dequeue_node(struct ivy_parser *parser)
|
||||
|
||||
struct ivy_ast_unit_node *unit = (struct ivy_ast_unit_node *)state->s_node;
|
||||
|
||||
entry = b_queue_pop_front(&unit->n_children);
|
||||
entry = fx_queue_pop_front(&unit->n_children);
|
||||
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
return fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
}
|
||||
|
||||
struct ivy_diag *parser_push_diag(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef _AST_CTX_H_
|
||||
#define _AST_CTX_H_
|
||||
|
||||
#include <blue/core/queue.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <ivy/diag.h>
|
||||
#include <ivy/lang/ast.h>
|
||||
#include <ivy/lang/diag.h>
|
||||
@@ -14,7 +14,7 @@
|
||||
((state_type *)parser_get_parent_state_generic(parser, type_id))
|
||||
|
||||
struct parser_state {
|
||||
b_queue_entry s_entry;
|
||||
fx_queue_entry s_entry;
|
||||
struct ivy_ast_node *s_parent;
|
||||
struct ivy_ast_node *s_node;
|
||||
};
|
||||
@@ -22,9 +22,9 @@ struct parser_state {
|
||||
struct ivy_parser {
|
||||
enum ivy_status p_status;
|
||||
struct ivy_diag_ctx *p_diag_ctx;
|
||||
b_queue p_state;
|
||||
b_queue p_token_queue;
|
||||
b_queue p_node_queue;
|
||||
fx_queue p_state;
|
||||
fx_queue p_token_queue;
|
||||
fx_queue p_node_queue;
|
||||
};
|
||||
|
||||
enum pop_state_flags {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
static void to_string(struct ivy_ast_node *node, fx_string *str)
|
||||
{
|
||||
struct ivy_ast_double_node *v = (struct ivy_ast_double_node *)node;
|
||||
|
||||
b_string_append_cstrf(
|
||||
fx_string_append_cstrf(
|
||||
str, "%s (%.2lf)", ivy_ast_node_type_to_string(node->n_type),
|
||||
v->n_value->t_double);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "../node.h"
|
||||
#include "expr.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <ivy/lang/operator.h>
|
||||
#include <stdio.h>
|
||||
@@ -63,7 +63,7 @@ enum ivy_status arith_push_operand(
|
||||
IVY_AST_IDENT);
|
||||
v->n_content = tok;
|
||||
ivy_ast_node_set_bounds_from_token((struct ivy_ast_node *)v, tok);
|
||||
b_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
|
||||
fx_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
|
||||
break;
|
||||
}
|
||||
case IVY_TOK_INT: {
|
||||
@@ -71,7 +71,7 @@ enum ivy_status arith_push_operand(
|
||||
= (struct ivy_ast_int_node *)ast_node_create(IVY_AST_INT);
|
||||
v->n_value = tok;
|
||||
ivy_ast_node_set_bounds_from_token((struct ivy_ast_node *)v, tok);
|
||||
b_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
|
||||
fx_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
|
||||
break;
|
||||
}
|
||||
case IVY_TOK_DOUBLE: {
|
||||
@@ -80,7 +80,7 @@ enum ivy_status arith_push_operand(
|
||||
IVY_AST_DOUBLE);
|
||||
v->n_value = tok;
|
||||
ivy_ast_node_set_bounds_from_token((struct ivy_ast_node *)v, tok);
|
||||
b_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
|
||||
fx_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
|
||||
break;
|
||||
}
|
||||
case IVY_TOK_ATOM: {
|
||||
@@ -88,7 +88,7 @@ enum ivy_status arith_push_operand(
|
||||
= (struct ivy_ast_atom_node *)ast_node_create(IVY_AST_ATOM);
|
||||
v->n_content = tok;
|
||||
ivy_ast_node_set_bounds_from_token((struct ivy_ast_node *)v, tok);
|
||||
b_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
|
||||
fx_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
|
||||
break;
|
||||
}
|
||||
case IVY_TOK_STRING: {
|
||||
@@ -97,7 +97,7 @@ enum ivy_status arith_push_operand(
|
||||
IVY_AST_STRING);
|
||||
v->n_value = tok;
|
||||
ivy_ast_node_set_bounds_from_token((struct ivy_ast_node *)v, tok);
|
||||
b_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
|
||||
fx_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
|
||||
break;
|
||||
}
|
||||
case IVY_TOK_SYMBOL: {
|
||||
@@ -107,7 +107,7 @@ enum ivy_status arith_push_operand(
|
||||
|
||||
struct ivy_ast_node *v = ast_node_create(IVY_AST_DISCARD);
|
||||
ivy_ast_node_set_bounds_from_token((struct ivy_ast_node *)v, tok);
|
||||
b_queue_push_back(&state->s_output_queue, &v->n_entry);
|
||||
fx_queue_push_back(&state->s_output_queue, &v->n_entry);
|
||||
break;
|
||||
}
|
||||
case IVY_TOK_KEYWORD: {
|
||||
@@ -133,7 +133,7 @@ enum ivy_status arith_push_operand(
|
||||
}
|
||||
|
||||
ivy_ast_node_set_bounds_from_token((struct ivy_ast_node *)v, tok);
|
||||
b_queue_push_back(&state->s_output_queue, &v->n_entry);
|
||||
fx_queue_push_back(&state->s_output_queue, &v->n_entry);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -204,20 +204,20 @@ static struct ivy_ast_node *create_operator_node_from_token(struct ivy_token *to
|
||||
#ifdef IVY_LANG_DEBUG
|
||||
static void print_expr_queues(struct expr_parser_state *state)
|
||||
{
|
||||
b_queue_iterator it = {0};
|
||||
fx_queue_iterator it = {0};
|
||||
|
||||
debug_printf("operators:");
|
||||
b_queue_foreach (&it, &state->s_operator_stack) {
|
||||
fx_queue_foreach (&it, &state->s_operator_stack) {
|
||||
struct ivy_ast_node *n
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
debug_printf(" ");
|
||||
print_operand(n);
|
||||
}
|
||||
|
||||
debug_printf("\noperands:");
|
||||
b_queue_foreach (&it, &state->s_output_queue) {
|
||||
fx_queue_foreach (&it, &state->s_output_queue) {
|
||||
struct ivy_ast_node *n
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
debug_printf(" ");
|
||||
print_operand(n);
|
||||
}
|
||||
@@ -234,13 +234,13 @@ void arith_push_operator(struct expr_parser_state *state, struct ivy_ast_node *n
|
||||
}
|
||||
|
||||
while (true) {
|
||||
b_queue_entry *top = b_queue_last(&state->s_operator_stack);
|
||||
fx_queue_entry *top = fx_queue_last(&state->s_operator_stack);
|
||||
if (!top) {
|
||||
break;
|
||||
}
|
||||
|
||||
struct ivy_ast_node *top_node
|
||||
= b_unbox(struct ivy_ast_node, top, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, top, n_entry);
|
||||
const struct ivy_operator *top_op = NULL;
|
||||
|
||||
switch (top_node->n_type) {
|
||||
@@ -266,11 +266,11 @@ void arith_push_operator(struct expr_parser_state *state, struct ivy_ast_node *n
|
||||
break;
|
||||
}
|
||||
|
||||
b_queue_delete(&state->s_operator_stack, top);
|
||||
b_queue_push_back(&state->s_output_queue, top);
|
||||
fx_queue_delete(&state->s_operator_stack, top);
|
||||
fx_queue_push_back(&state->s_output_queue, top);
|
||||
}
|
||||
|
||||
b_queue_push_back(&state->s_operator_stack, &node->n_entry);
|
||||
fx_queue_push_back(&state->s_operator_stack, &node->n_entry);
|
||||
#ifdef IVY_LANG_DEBUG
|
||||
print_expr_queues(state);
|
||||
#endif
|
||||
@@ -296,7 +296,7 @@ enum ivy_status expr_finalise_arith(
|
||||
struct expr_parser_state *state, struct ivy_ast_node **expr_tree,
|
||||
enum ivy_operator_precedence minimum_precedence)
|
||||
{
|
||||
b_queue_entry *entry = NULL;
|
||||
fx_queue_entry *entry = NULL;
|
||||
|
||||
/* first, take all the operators still left on the operator stack and
|
||||
* add them to the output queue.
|
||||
@@ -304,13 +304,13 @@ enum ivy_status expr_finalise_arith(
|
||||
* since each set of parentheses has its own expression context,
|
||||
* we don't have to handle parentheses here */
|
||||
while (true) {
|
||||
entry = b_queue_pop_back(&state->s_operator_stack);
|
||||
entry = fx_queue_pop_back(&state->s_operator_stack);
|
||||
if (!entry) {
|
||||
break;
|
||||
}
|
||||
|
||||
struct ivy_ast_node *node
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
if (!node) {
|
||||
/* this should never happen */
|
||||
return IVY_ERR_INTERNAL_FAILURE;
|
||||
@@ -336,11 +336,11 @@ enum ivy_status expr_finalise_arith(
|
||||
/* if we aren't processing operators below a certain precedence
|
||||
* then leave them on the stack and stop here. */
|
||||
if (op->op_precedence < minimum_precedence) {
|
||||
b_queue_push_back(&state->s_operator_stack, entry);
|
||||
fx_queue_push_back(&state->s_operator_stack, entry);
|
||||
break;
|
||||
}
|
||||
|
||||
b_queue_push_back(&state->s_output_queue, entry);
|
||||
fx_queue_push_back(&state->s_output_queue, entry);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -353,22 +353,22 @@ enum ivy_status expr_finalise_arith(
|
||||
* always follow their operands, so a queue of operands is needed
|
||||
* for the conversion. */
|
||||
|
||||
b_queue q = B_QUEUE_INIT;
|
||||
b_queue_entry *tmp = NULL;
|
||||
entry = b_queue_first(&state->s_output_queue);
|
||||
fx_queue q = FX_QUEUE_INIT;
|
||||
fx_queue_entry *tmp = NULL;
|
||||
entry = fx_queue_first(&state->s_output_queue);
|
||||
int i = 0;
|
||||
|
||||
while (entry) {
|
||||
struct ivy_ast_node *item
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
b_queue_entry *next = b_queue_next(entry);
|
||||
b_queue_delete(&state->s_output_queue, entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
fx_queue_entry *next = fx_queue_next(entry);
|
||||
fx_queue_delete(&state->s_output_queue, entry);
|
||||
|
||||
/* if the node is an operand, just push it to a temporary queue
|
||||
* and come back to it later. */
|
||||
if (item->n_type != IVY_AST_OP && item->n_type != IVY_AST_MSG) {
|
||||
/* operand */
|
||||
b_queue_push_back(&q, &item->n_entry);
|
||||
fx_queue_push_back(&q, &item->n_entry);
|
||||
goto next;
|
||||
}
|
||||
|
||||
@@ -384,11 +384,11 @@ enum ivy_status expr_finalise_arith(
|
||||
* self-contained keyword message, and can be pushed to
|
||||
* the operand queue as-is. */
|
||||
if (!msg->n_recipient) {
|
||||
tmp = b_queue_pop_back(&q);
|
||||
msg->n_recipient = b_unbox(
|
||||
tmp = fx_queue_pop_back(&q);
|
||||
msg->n_recipient = fx_unbox(
|
||||
struct ivy_ast_node, tmp, n_entry);
|
||||
}
|
||||
b_queue_push_back(&q, &msg->n_base.n_entry);
|
||||
fx_queue_push_back(&q, &msg->n_base.n_entry);
|
||||
goto next;
|
||||
}
|
||||
|
||||
@@ -397,15 +397,15 @@ enum ivy_status expr_finalise_arith(
|
||||
* all the operands it needs, it can be pushed to the operand
|
||||
* queue as-is */
|
||||
if (op_node_is_complete(op_node)) {
|
||||
b_queue_push_back(&q, &item->n_entry);
|
||||
fx_queue_push_back(&q, &item->n_entry);
|
||||
goto next;
|
||||
}
|
||||
|
||||
/* otherwise, pop the relevant operands from the operand
|
||||
* queue... */
|
||||
op = op_node->n_op;
|
||||
tmp = b_queue_pop_back(&q);
|
||||
op_node->n_right = b_unbox(struct ivy_ast_node, tmp, n_entry);
|
||||
tmp = fx_queue_pop_back(&q);
|
||||
op_node->n_right = fx_unbox(struct ivy_ast_node, tmp, n_entry);
|
||||
|
||||
if (op_node->n_right) {
|
||||
op_node->n_right->n_parent = (struct ivy_ast_node *)op_node;
|
||||
@@ -416,9 +416,9 @@ enum ivy_status expr_finalise_arith(
|
||||
}
|
||||
|
||||
if (op->op_arity == IVY_OP_BINARY) {
|
||||
tmp = b_queue_pop_back(&q);
|
||||
tmp = fx_queue_pop_back(&q);
|
||||
op_node->n_left
|
||||
= b_unbox(struct ivy_ast_node, tmp, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, tmp, n_entry);
|
||||
|
||||
if (op_node->n_left) {
|
||||
op_node->n_left->n_parent
|
||||
@@ -432,7 +432,7 @@ enum ivy_status expr_finalise_arith(
|
||||
|
||||
/* ...and push the newly-completed operator node to the operand
|
||||
* queue */
|
||||
b_queue_push_back(&q, &op_node->n_base.n_entry);
|
||||
fx_queue_push_back(&q, &op_node->n_base.n_entry);
|
||||
next:
|
||||
entry = next;
|
||||
}
|
||||
@@ -448,15 +448,15 @@ enum ivy_status expr_finalise_arith(
|
||||
* their operands have just been moved to the temporary operand stack
|
||||
* used above. move them back to the parser state's output queue here
|
||||
* so they can be used later. */
|
||||
entry = b_queue_first(&state->s_operator_stack);
|
||||
entry = fx_queue_first(&state->s_operator_stack);
|
||||
while (entry) {
|
||||
b_queue_entry *entry2 = b_queue_pop_front(&q);
|
||||
fx_queue_entry *entry2 = fx_queue_pop_front(&q);
|
||||
if (!entry2) {
|
||||
return IVY_ERR_INTERNAL_FAILURE;
|
||||
}
|
||||
|
||||
b_queue_push_back(&state->s_output_queue, entry2);
|
||||
entry = b_queue_next(entry);
|
||||
fx_queue_push_back(&state->s_output_queue, entry2);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -468,8 +468,8 @@ enum ivy_status expr_finalise_arith(
|
||||
|
||||
/* the final node remaining on the temp operand stack is the root node
|
||||
* of the new expression tree */
|
||||
tmp = b_queue_pop_back(&q);
|
||||
*expr_tree = b_unbox(struct ivy_ast_node, tmp, n_entry);
|
||||
tmp = fx_queue_pop_back(&q);
|
||||
*expr_tree = fx_unbox(struct ivy_ast_node, tmp, n_entry);
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
@@ -521,7 +521,7 @@ struct token_parse_result arith_parse_operand(
|
||||
memset(empty_label, 0x0, sizeof *empty_label);
|
||||
empty_label->t_type = IVY_TOK_LABEL;
|
||||
|
||||
b_queue_push_back(&state->s_labels, &empty_label->t_entry);
|
||||
fx_queue_push_back(&state->s_labels, &empty_label->t_entry);
|
||||
|
||||
struct expr_parser_state *arg_expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
@@ -695,9 +695,9 @@ struct token_parse_result arith_parse_left_paren(
|
||||
|
||||
if (state->s_prev_token == IVY_TOK_IDENT) {
|
||||
/* this might be the opening parenthesis for a complex message. */
|
||||
b_queue_entry *msg_entry = b_queue_last(&state->s_operator_stack);
|
||||
fx_queue_entry *msg_entry = fx_queue_last(&state->s_operator_stack);
|
||||
struct ivy_ast_node *msg
|
||||
= b_unbox(struct ivy_ast_node, msg_entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, msg_entry, n_entry);
|
||||
|
||||
if (!msg || msg->n_type != IVY_AST_MSG) {
|
||||
/* this is not a complex message, it's probably a
|
||||
@@ -705,7 +705,7 @@ struct token_parse_result arith_parse_left_paren(
|
||||
goto not_complex_msg;
|
||||
}
|
||||
|
||||
b_queue_pop_back(&state->s_operator_stack);
|
||||
fx_queue_pop_back(&state->s_operator_stack);
|
||||
|
||||
struct expr_parser_state *msg_expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
@@ -761,7 +761,7 @@ not_complex_msg:
|
||||
memset(empty_label, 0x0, sizeof *empty_label);
|
||||
empty_label->t_type = IVY_TOK_LABEL;
|
||||
|
||||
b_queue_push_back(&state->s_labels, &empty_label->t_entry);
|
||||
fx_queue_push_back(&state->s_labels, &empty_label->t_entry);
|
||||
|
||||
struct expr_parser_state *arg_expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
@@ -908,21 +908,21 @@ struct token_parse_result arith_parse_right_bracket(
|
||||
return result;
|
||||
}
|
||||
|
||||
static struct ivy_ast_selector_node *keyword_selector_from_label_list(b_queue *labels)
|
||||
static struct ivy_ast_selector_node *keyword_selector_from_label_list(fx_queue *labels)
|
||||
{
|
||||
struct ivy_ast_selector_node *sel
|
||||
= (struct ivy_ast_selector_node *)ast_node_create(IVY_AST_SELECTOR);
|
||||
|
||||
b_queue_entry *entry = b_queue_first(labels);
|
||||
b_queue_entry *next = NULL;
|
||||
fx_queue_entry *entry = fx_queue_first(labels);
|
||||
fx_queue_entry *next = NULL;
|
||||
|
||||
while (entry) {
|
||||
struct ivy_token *label
|
||||
= b_unbox(struct ivy_token, entry, t_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(labels, entry);
|
||||
= fx_unbox(struct ivy_token, entry, t_entry);
|
||||
next = fx_queue_next(entry);
|
||||
fx_queue_delete(labels, entry);
|
||||
|
||||
b_queue_push_back(&sel->n_arg_labels, &label->t_entry);
|
||||
fx_queue_push_back(&sel->n_arg_labels, &label->t_entry);
|
||||
entry = next;
|
||||
}
|
||||
|
||||
@@ -937,16 +937,16 @@ static struct ivy_ast_cascade_node *expr_finalise_cascade(
|
||||
|
||||
cascade->n_recipient = state->s_recipient;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&state->s_cascade_msg);
|
||||
b_queue_entry *next = NULL;
|
||||
fx_queue_entry *entry = fx_queue_first(&state->s_cascade_msg);
|
||||
fx_queue_entry *next = NULL;
|
||||
|
||||
while (entry) {
|
||||
struct ivy_ast_node *msg
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(&state->s_cascade_msg, entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
next = fx_queue_next(entry);
|
||||
fx_queue_delete(&state->s_cascade_msg, entry);
|
||||
|
||||
b_queue_push_back(&cascade->n_msg, &msg->n_entry);
|
||||
fx_queue_push_back(&cascade->n_msg, &msg->n_entry);
|
||||
entry = next;
|
||||
}
|
||||
|
||||
@@ -962,16 +962,16 @@ static struct ivy_ast_msg_node *expr_finalise_keyword_msg(
|
||||
msg->n_recipient = state->s_recipient;
|
||||
msg->n_sel = keyword_selector_from_label_list(&state->s_labels);
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&state->s_args);
|
||||
b_queue_entry *next = NULL;
|
||||
fx_queue_entry *entry = fx_queue_first(&state->s_args);
|
||||
fx_queue_entry *next = NULL;
|
||||
|
||||
while (entry) {
|
||||
struct ivy_ast_node *arg
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(&state->s_args, entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
next = fx_queue_next(entry);
|
||||
fx_queue_delete(&state->s_args, entry);
|
||||
|
||||
b_queue_push_back(&msg->n_arg, &arg->n_entry);
|
||||
fx_queue_push_back(&msg->n_arg, &arg->n_entry);
|
||||
entry = next;
|
||||
}
|
||||
|
||||
@@ -988,26 +988,26 @@ static struct ivy_ast_msg_node *expr_finalise_complex_msg(
|
||||
|
||||
state->s_msg = NULL;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&state->s_labels);
|
||||
b_queue_entry *next = NULL;
|
||||
fx_queue_entry *entry = fx_queue_first(&state->s_labels);
|
||||
fx_queue_entry *next = NULL;
|
||||
while (entry) {
|
||||
struct ivy_token *label
|
||||
= b_unbox(struct ivy_token, entry, t_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(&state->s_labels, entry);
|
||||
b_queue_push_back(&msg->n_sel->n_arg_labels, &label->t_entry);
|
||||
= fx_unbox(struct ivy_token, entry, t_entry);
|
||||
next = fx_queue_next(entry);
|
||||
fx_queue_delete(&state->s_labels, entry);
|
||||
fx_queue_push_back(&msg->n_sel->n_arg_labels, &label->t_entry);
|
||||
|
||||
entry = next;
|
||||
}
|
||||
|
||||
entry = b_queue_first(&state->s_args);
|
||||
entry = fx_queue_first(&state->s_args);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *arg
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(&state->s_args, entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
next = fx_queue_next(entry);
|
||||
fx_queue_delete(&state->s_args, entry);
|
||||
|
||||
b_queue_push_back(&msg->n_arg, &arg->n_entry);
|
||||
fx_queue_push_back(&msg->n_arg, &arg->n_entry);
|
||||
|
||||
entry = next;
|
||||
}
|
||||
@@ -1032,9 +1032,9 @@ static enum ivy_status begin_cascade_operation(struct ivy_parser *ctx)
|
||||
enum ivy_operator_precedence min_precedence
|
||||
= IVY_PRECEDENCE_CASCADE;
|
||||
|
||||
struct ivy_ast_node *prev = b_unbox(
|
||||
struct ivy_ast_node *prev = fx_unbox(
|
||||
struct ivy_ast_node,
|
||||
b_queue_last(&state->s_operator_stack), n_entry);
|
||||
fx_queue_last(&state->s_operator_stack), n_entry);
|
||||
if (prev && prev->n_type == IVY_AST_MSG) {
|
||||
/* unary complex messages (which will be found on the
|
||||
* operator stack) have a very high precedence (much
|
||||
@@ -1079,7 +1079,7 @@ static enum ivy_status begin_cascade_operation(struct ivy_parser *ctx)
|
||||
cascade_expr->s_type = EXPR_TYPE_ARITH;
|
||||
cascade_expr->s_subexpr_depth = state->s_subexpr_depth + 1;
|
||||
|
||||
b_queue_push_back(&cascade_expr->s_cascade_msg, &first_msg->n_base.n_entry);
|
||||
fx_queue_push_back(&cascade_expr->s_cascade_msg, &first_msg->n_base.n_entry);
|
||||
|
||||
struct expr_parser_state *msg_expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
@@ -1338,8 +1338,8 @@ struct token_parse_result arith_parse_caret(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (!b_queue_empty(&state->s_operator_stack)
|
||||
|| !b_queue_empty(&state->s_output_queue)) {
|
||||
if (!fx_queue_empty(&state->s_operator_stack)
|
||||
|| !fx_queue_empty(&state->s_output_queue)) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
@@ -1388,8 +1388,8 @@ struct token_parse_result arith_parse_comma(
|
||||
}
|
||||
|
||||
if (state->s_sub_type == EXPR_SUBTYPE_PAREN
|
||||
&& b_queue_empty(&state->s_output_queue)
|
||||
&& b_queue_empty(&state->s_operator_stack)) {
|
||||
&& fx_queue_empty(&state->s_output_queue)
|
||||
&& fx_queue_empty(&state->s_operator_stack)) {
|
||||
parser_pop_state(ctx, 0);
|
||||
} else {
|
||||
/* the tuple parser will handle the parentheses for us. */
|
||||
@@ -1452,8 +1452,8 @@ struct token_parse_result arith_parse_label(
|
||||
struct expr_parser_state *msg_expr;
|
||||
bool new_parser = true;
|
||||
|
||||
if (b_queue_empty(&state->s_operator_stack)
|
||||
&& b_queue_empty(&state->s_output_queue)) {
|
||||
if (fx_queue_empty(&state->s_operator_stack)
|
||||
&& fx_queue_empty(&state->s_output_queue)) {
|
||||
new_parser = false;
|
||||
}
|
||||
|
||||
@@ -1498,7 +1498,7 @@ struct token_parse_result arith_parse_label(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
b_queue_push_back(&state->s_labels, &tok->t_entry);
|
||||
fx_queue_push_back(&state->s_labels, &tok->t_entry);
|
||||
|
||||
struct expr_parser_state *arg_expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
@@ -1511,7 +1511,7 @@ struct token_parse_result arith_parse_label(
|
||||
/* we may have just finished parsing a keyword-message argument,
|
||||
* and this label marks the start of a new one. store the label
|
||||
* and create a new argument parsing context. */
|
||||
b_queue_push_back(&state->s_labels, &tok->t_entry);
|
||||
fx_queue_push_back(&state->s_labels, &tok->t_entry);
|
||||
|
||||
struct expr_parser_state *arg_expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
@@ -1532,16 +1532,16 @@ enum ivy_status arith_add_child(
|
||||
|
||||
if (state->s_sub_type == EXPR_SUBTYPE_CASCADE) {
|
||||
/* treat the child node as a cascaded message */
|
||||
b_queue_push_back(&state->s_cascade_msg, &child->n_entry);
|
||||
fx_queue_push_back(&state->s_cascade_msg, &child->n_entry);
|
||||
} else if (
|
||||
state->s_sub_type == EXPR_SUBTYPE_KEYWORD_MSG
|
||||
|| state->s_sub_type == EXPR_SUBTYPE_COMPLEX_MSG) {
|
||||
/* treat the child node as a keyword-message argument */
|
||||
b_queue_push_back(&state->s_args, &child->n_entry);
|
||||
fx_queue_push_back(&state->s_args, &child->n_entry);
|
||||
} else if (state->s_sub_type == EXPR_SUBTYPE_KEYWORD_ARG) {
|
||||
/* treat the child node as a sub-expression enclosed in
|
||||
* parentheses (i.e. an operand). */
|
||||
b_queue_push_back(&state->s_output_queue, &child->n_entry);
|
||||
fx_queue_push_back(&state->s_output_queue, &child->n_entry);
|
||||
state->s_prev_component = EXPR_CMP_OPERAND;
|
||||
} else if (child->n_type == IVY_AST_MSG) {
|
||||
arith_push_operator(state, child);
|
||||
@@ -1549,7 +1549,7 @@ enum ivy_status arith_add_child(
|
||||
} else {
|
||||
/* treat the child node as a sub-expression enclosed in
|
||||
* parentheses (i.e. an operand). */
|
||||
b_queue_push_back(&state->s_output_queue, &child->n_entry);
|
||||
fx_queue_push_back(&state->s_output_queue, &child->n_entry);
|
||||
state->s_prev_component = EXPR_CMP_OPERAND;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "../ctx.h"
|
||||
#include "../node.h"
|
||||
|
||||
#include <blue/core/queue.h>
|
||||
#include <fx/core/queue.h>
|
||||
|
||||
#define EXPR_TERMINATOR_MAX 8
|
||||
|
||||
@@ -76,19 +76,19 @@ struct expr_parser_state {
|
||||
unsigned short s_terminators[EXPR_TERMINATOR_MAX];
|
||||
unsigned short s_nr_terminators;
|
||||
|
||||
b_queue s_output_queue;
|
||||
b_queue s_operator_stack;
|
||||
fx_queue s_output_queue;
|
||||
fx_queue s_operator_stack;
|
||||
|
||||
/* these variables are for keyword-message expressions */
|
||||
struct ivy_ast_node *s_recipient;
|
||||
struct ivy_ast_msg_node *s_msg;
|
||||
b_queue s_labels;
|
||||
fx_queue s_labels;
|
||||
|
||||
union {
|
||||
/* for keyword-messages, this is a list of arg values. */
|
||||
b_queue s_args;
|
||||
fx_queue s_args;
|
||||
/* for cascade operators, this is a list of messages to send to the recipient. */
|
||||
b_queue s_cascade_msg;
|
||||
fx_queue s_cascade_msg;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "../node.h"
|
||||
#include "expr.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <ivy/lang/operator.h>
|
||||
#include <stdio.h>
|
||||
@@ -27,8 +27,8 @@ struct token_parse_result stmt_parse_try(
|
||||
|
||||
state->s_prev_token = IVY_KW_TRY;
|
||||
|
||||
if (b_queue_empty(&state->s_operator_stack)
|
||||
&& b_queue_empty(&state->s_output_queue)) {
|
||||
if (fx_queue_empty(&state->s_operator_stack)
|
||||
&& fx_queue_empty(&state->s_output_queue)) {
|
||||
parser_pop_state(ctx, 0);
|
||||
}
|
||||
|
||||
@@ -71,8 +71,8 @@ struct token_parse_result stmt_parse_for(
|
||||
|
||||
state->s_prev_token = IVY_KW_FOR;
|
||||
|
||||
if (b_queue_empty(&state->s_operator_stack)
|
||||
&& b_queue_empty(&state->s_output_queue)) {
|
||||
if (fx_queue_empty(&state->s_operator_stack)
|
||||
&& fx_queue_empty(&state->s_output_queue)) {
|
||||
parser_pop_state(ctx, 0);
|
||||
}
|
||||
|
||||
@@ -107,8 +107,8 @@ struct token_parse_result stmt_parse_while(
|
||||
|
||||
state->s_prev_token = IVY_KW_WHILE;
|
||||
|
||||
if (b_queue_empty(&state->s_operator_stack)
|
||||
&& b_queue_empty(&state->s_output_queue)) {
|
||||
if (fx_queue_empty(&state->s_operator_stack)
|
||||
&& fx_queue_empty(&state->s_output_queue)) {
|
||||
parser_pop_state(ctx, 0);
|
||||
}
|
||||
|
||||
@@ -140,8 +140,8 @@ struct token_parse_result stmt_parse_match(
|
||||
|
||||
state->s_prev_token = IVY_KW_MATCH;
|
||||
|
||||
if (b_queue_empty(&state->s_operator_stack)
|
||||
&& b_queue_empty(&state->s_output_queue)) {
|
||||
if (fx_queue_empty(&state->s_operator_stack)
|
||||
&& fx_queue_empty(&state->s_output_queue)) {
|
||||
parser_pop_state(ctx, 0);
|
||||
}
|
||||
|
||||
@@ -186,8 +186,8 @@ struct token_parse_result stmt_parse_if(
|
||||
|
||||
state->s_prev_token = IVY_KW_IF;
|
||||
|
||||
if (b_queue_empty(&state->s_operator_stack)
|
||||
&& b_queue_empty(&state->s_output_queue)) {
|
||||
if (fx_queue_empty(&state->s_operator_stack)
|
||||
&& fx_queue_empty(&state->s_output_queue)) {
|
||||
parser_pop_state(ctx, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
static void to_string(struct ivy_ast_node *node, fx_string *str)
|
||||
{
|
||||
struct ivy_ast_ident_node *ident = (struct ivy_ast_ident_node *)node;
|
||||
|
||||
b_string_append_cstrf(
|
||||
fx_string_append_cstrf(
|
||||
str, "%s (%s)", ivy_ast_node_type_to_string(node->n_type),
|
||||
ident->n_content->t_str);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
static void to_string(struct ivy_ast_node *node, fx_string *str)
|
||||
{
|
||||
struct ivy_ast_int_node *v = (struct ivy_ast_int_node *)node;
|
||||
|
||||
b_string_append_cstrf(
|
||||
fx_string_append_cstrf(
|
||||
str, "%s (%llu)", ivy_ast_node_type_to_string(node->n_type),
|
||||
v->n_value->t_int);
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@ enum ivy_status iterate_regular(
|
||||
ivy_ast_node_iteration_callback callback)
|
||||
{
|
||||
#if 0
|
||||
b_queue_push_back(&it->it_queue, &node->n_it.it_entry);
|
||||
fx_queue_push_back(&it->it_queue, &node->n_it.it_entry);
|
||||
node->n_it.it_depth = 0;
|
||||
|
||||
while (!b_queue_empty(&it->it_queue)) {
|
||||
b_queue_entry *entry = b_queue_first(&it->it_queue);
|
||||
struct ivy_ast_node_iterator_entry *it_entry = b_unbox(
|
||||
while (!fx_queue_empty(&it->it_queue)) {
|
||||
fx_queue_entry *entry = fx_queue_first(&it->it_queue);
|
||||
struct ivy_ast_node_iterator_entry *it_entry = fx_unbox(
|
||||
struct ivy_ast_node_iterator_entry, entry, it_entry);
|
||||
node = b_unbox(struct ivy_ast_node, it_entry, n_it);
|
||||
node = fx_unbox(struct ivy_ast_node, it_entry, n_it);
|
||||
|
||||
if (!node) {
|
||||
/* this should never happen. */
|
||||
@@ -32,7 +32,7 @@ enum ivy_status iterate_regular(
|
||||
type->n_collect_children(node, it);
|
||||
}
|
||||
|
||||
b_queue_delete(&it->it_queue, entry);
|
||||
fx_queue_delete(&it->it_queue, entry);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -60,15 +60,15 @@ enum ivy_status iterate_postorder(
|
||||
* - should probably use this just for the executable parts of the AST,
|
||||
* not for nodes defining classes, function metadata, etc.
|
||||
*/
|
||||
b_queue_push_back(&it->it_queue, &node->n_it.it_entry);
|
||||
fx_queue_push_back(&it->it_queue, &node->n_it.it_entry);
|
||||
node->n_it.it_depth = 0;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&it->it_queue);
|
||||
fx_queue_entry *entry = fx_queue_first(&it->it_queue);
|
||||
|
||||
while (entry) {
|
||||
struct ivy_ast_node_iterator_entry *it_entry = b_unbox(
|
||||
struct ivy_ast_node_iterator_entry *it_entry = fx_unbox(
|
||||
struct ivy_ast_node_iterator_entry, entry, it_entry);
|
||||
node = b_unbox(struct ivy_ast_node, it_entry, n_it);
|
||||
node = fx_unbox(struct ivy_ast_node, it_entry, n_it);
|
||||
|
||||
if (!node) {
|
||||
/* this should never happen. */
|
||||
@@ -81,16 +81,16 @@ enum ivy_status iterate_postorder(
|
||||
type->n_collect_children(node, it);
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
while (!b_queue_empty(&it->it_queue)) {
|
||||
b_queue_entry *entry = b_queue_pop_back(&it->it_queue);
|
||||
while (!fx_queue_empty(&it->it_queue)) {
|
||||
fx_queue_entry *entry = fx_queue_pop_back(&it->it_queue);
|
||||
if (!entry) {
|
||||
break;
|
||||
}
|
||||
|
||||
node = b_unbox(struct ivy_ast_node, entry, n_it);
|
||||
node = fx_unbox(struct ivy_ast_node, entry, n_it);
|
||||
|
||||
if (!node) {
|
||||
/* this should never happen. */
|
||||
@@ -107,15 +107,15 @@ enum ivy_status ivy_ast_node_iterate(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *it,
|
||||
ivy_ast_node_iteration_callback callback, void *arg)
|
||||
{
|
||||
b_queue_push_back(&it->it_queue, &node->n_it.it_entry);
|
||||
fx_queue_push_back(&it->it_queue, &node->n_it.it_entry);
|
||||
node->n_it.it_depth = 0;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&it->it_queue);
|
||||
fx_queue_entry *entry = fx_queue_first(&it->it_queue);
|
||||
|
||||
while (entry) {
|
||||
struct ivy_ast_node_iterator_entry *it_entry = b_unbox(
|
||||
struct ivy_ast_node_iterator_entry *it_entry = fx_unbox(
|
||||
struct ivy_ast_node_iterator_entry, entry, it_entry);
|
||||
node = b_unbox(struct ivy_ast_node, it_entry, n_it);
|
||||
node = fx_unbox(struct ivy_ast_node, it_entry, n_it);
|
||||
|
||||
if (!node) {
|
||||
/* this should never happen. */
|
||||
@@ -134,16 +134,16 @@ enum ivy_status ivy_ast_node_iterate(
|
||||
type->n_collect_children(node, it);
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
while (!b_queue_empty(&it->it_queue)) {
|
||||
b_queue_entry *entry = b_queue_pop_back(&it->it_queue);
|
||||
while (!fx_queue_empty(&it->it_queue)) {
|
||||
fx_queue_entry *entry = fx_queue_pop_back(&it->it_queue);
|
||||
if (!entry) {
|
||||
break;
|
||||
}
|
||||
|
||||
node = b_unbox(struct ivy_ast_node, entry, n_it);
|
||||
node = fx_unbox(struct ivy_ast_node, entry, n_it);
|
||||
|
||||
if (!node) {
|
||||
/* this should never happen. */
|
||||
@@ -165,10 +165,10 @@ void ast_node_iterator_enqueue_node(
|
||||
struct ivy_ast_node *node)
|
||||
{
|
||||
if (it->it_insert_after) {
|
||||
b_queue_insert_after(
|
||||
fx_queue_insert_after(
|
||||
&it->it_queue, &node->n_it.it_entry, it->it_insert_after);
|
||||
} else {
|
||||
b_queue_push_back(&it->it_queue, &node->n_it.it_entry);
|
||||
fx_queue_push_back(&it->it_queue, &node->n_it.it_entry);
|
||||
}
|
||||
|
||||
node->n_it.it_depth = parent->n_it.it_depth + 1;
|
||||
|
||||
@@ -11,7 +11,7 @@ struct lambda_parser_state {
|
||||
struct ivy_ast_node *s_prev_node;
|
||||
unsigned int s_prev;
|
||||
|
||||
b_queue s_args;
|
||||
fx_queue s_args;
|
||||
struct ivy_ast_node *s_body;
|
||||
};
|
||||
|
||||
@@ -56,7 +56,7 @@ static struct token_parse_result parse_ident(
|
||||
}
|
||||
|
||||
arg->n_content = tok;
|
||||
b_queue_push_back(&state->s_args, &arg->n_base.n_entry);
|
||||
fx_queue_push_back(&state->s_args, &arg->n_base.n_entry);
|
||||
state->s_prev = IVY_TOK_IDENT;
|
||||
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
@@ -101,7 +101,7 @@ static void finalise_lambda(struct lambda_parser_state *state)
|
||||
lambda->n_arg = state->s_args;
|
||||
lambda->n_body = state->s_body;
|
||||
|
||||
state->s_args = B_QUEUE_INIT;
|
||||
state->s_args = FX_QUEUE_INIT;
|
||||
state->s_body = NULL;
|
||||
}
|
||||
|
||||
@@ -147,12 +147,12 @@ static void collect_children(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
|
||||
{
|
||||
struct ivy_ast_lambda_node *lambda = (struct ivy_ast_lambda_node *)node;
|
||||
b_queue_entry *entry = b_queue_first(&lambda->n_arg);
|
||||
fx_queue_entry *entry = fx_queue_first(&lambda->n_arg);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *expr
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, expr);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
if (lambda->n_body) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
static void to_string(struct ivy_ast_node *node, fx_string *str)
|
||||
{
|
||||
b_string_append_cstrf(str, "%s", ivy_ast_node_type_to_string(node->n_type));
|
||||
fx_string_append_cstrf(str, "%s", ivy_ast_node_type_to_string(node->n_type));
|
||||
}
|
||||
|
||||
struct ast_node_type loop_break_node_ops = {
|
||||
|
||||
@@ -9,7 +9,7 @@ struct match_parser_state {
|
||||
struct ivy_ast_node *s_cond;
|
||||
|
||||
struct ivy_ast_cond_node *s_cur_branch;
|
||||
b_queue s_branches;
|
||||
fx_queue s_branches;
|
||||
|
||||
struct ivy_ast_node *s_prev_node;
|
||||
};
|
||||
@@ -52,7 +52,7 @@ static enum ivy_status flush_current_branch(struct match_parser_state *state)
|
||||
return IVY_ERR_INTERNAL_FAILURE;
|
||||
}
|
||||
|
||||
b_queue_push_back(&state->s_branches, &state->s_cur_branch->n_base.n_entry);
|
||||
fx_queue_push_back(&state->s_branches, &state->s_cur_branch->n_base.n_entry);
|
||||
|
||||
state->s_cur_branch
|
||||
= (struct ivy_ast_cond_node *)ast_node_create(IVY_AST_COND);
|
||||
@@ -107,7 +107,7 @@ static enum ivy_status finalise_match(struct match_parser_state *state)
|
||||
|
||||
match->n_cond = state->s_cond;
|
||||
match->n_branches = state->s_branches;
|
||||
state->s_branches = B_QUEUE_INIT;
|
||||
state->s_branches = FX_QUEUE_INIT;
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
@@ -262,10 +262,10 @@ static void match_collect_children(
|
||||
|
||||
ast_node_iterator_enqueue_node(iterator, node, match->n_cond);
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&match->n_branches);
|
||||
fx_queue_entry *entry = fx_queue_first(&match->n_branches);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *branch
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, branch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@ static void collect_children(
|
||||
iterator, node, (struct ivy_ast_node *)msg->n_sel);
|
||||
}
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&msg->n_arg);
|
||||
fx_queue_entry *entry = fx_queue_first(&msg->n_arg);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *arg
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, arg);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "ivy/status.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
|
||||
struct msgh_parser_state {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/ast.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -250,7 +250,7 @@ struct ivy_ast_node *ast_node_create(enum ivy_ast_node_type type)
|
||||
return node;
|
||||
}
|
||||
|
||||
void ivy_ast_node_to_string(struct ivy_ast_node *node, b_string *out)
|
||||
void ivy_ast_node_to_string(struct ivy_ast_node *node, fx_string *out)
|
||||
{
|
||||
const struct ast_node_type *type_info = get_ast_node_type(node->n_type);
|
||||
if (!type_info) {
|
||||
@@ -260,7 +260,7 @@ void ivy_ast_node_to_string(struct ivy_ast_node *node, b_string *out)
|
||||
if (type_info->n_to_string) {
|
||||
type_info->n_to_string(node, out);
|
||||
} else {
|
||||
b_string_append_cstr(
|
||||
fx_string_append_cstr(
|
||||
out, ivy_ast_node_type_to_string(node->n_type));
|
||||
}
|
||||
}
|
||||
@@ -301,15 +301,15 @@ void ivy_ast_node_extend_bounds_recursive(
|
||||
void ivy_ast_node_destroy(struct ivy_ast_node *node)
|
||||
{
|
||||
struct ivy_ast_node_iterator it = {};
|
||||
b_queue_push_back(&it.it_queue, &node->n_it.it_entry);
|
||||
fx_queue_push_back(&it.it_queue, &node->n_it.it_entry);
|
||||
node->n_it.it_depth = 0;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&it.it_queue);
|
||||
fx_queue_entry *entry = fx_queue_first(&it.it_queue);
|
||||
|
||||
while (entry) {
|
||||
struct ivy_ast_node_iterator_entry *it_entry = b_unbox(
|
||||
struct ivy_ast_node_iterator_entry *it_entry = fx_unbox(
|
||||
struct ivy_ast_node_iterator_entry, entry, it_entry);
|
||||
node = b_unbox(struct ivy_ast_node, it_entry, n_it);
|
||||
node = fx_unbox(struct ivy_ast_node, it_entry, n_it);
|
||||
|
||||
if (!node) {
|
||||
/* this should never happen. */
|
||||
@@ -322,16 +322,16 @@ void ivy_ast_node_destroy(struct ivy_ast_node *node)
|
||||
type->n_collect_children(node, &it);
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
while (!b_queue_empty(&it.it_queue)) {
|
||||
b_queue_entry *entry = b_queue_pop_back(&it.it_queue);
|
||||
while (!fx_queue_empty(&it.it_queue)) {
|
||||
fx_queue_entry *entry = fx_queue_pop_back(&it.it_queue);
|
||||
if (!entry) {
|
||||
break;
|
||||
}
|
||||
|
||||
node = b_unbox(struct ivy_ast_node, entry, n_it);
|
||||
node = fx_unbox(struct ivy_ast_node, entry, n_it);
|
||||
|
||||
const struct ast_node_type *type = get_ast_node_type(node->n_type);
|
||||
if (type && type->n_destroy) {
|
||||
@@ -397,15 +397,15 @@ const char *ivy_ast_node_type_to_string(enum ivy_ast_node_type v)
|
||||
|
||||
void ivy_ast_unit_add_node(struct ivy_ast_unit_node *unit, struct ivy_ast_node *child)
|
||||
{
|
||||
b_queue_push_back(&unit->n_children, &child->n_entry);
|
||||
fx_queue_push_back(&unit->n_children, &child->n_entry);
|
||||
}
|
||||
|
||||
struct ivy_ast_node *ivy_ast_unit_dequeue_node(struct ivy_ast_unit_node *unit)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_pop_front(&unit->n_children);
|
||||
fx_queue_entry *entry = fx_queue_pop_front(&unit->n_children);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
return fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef _AST_NODE_H_
|
||||
#define _AST_NODE_H_
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/ast.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
|
||||
@@ -47,7 +47,7 @@ typedef struct token_parse_result (*token_parse_function)(
|
||||
struct ast_node_type {
|
||||
enum ivy_status (*n_add_child)(
|
||||
struct parser_state *, struct ivy_ast_node *);
|
||||
void (*n_to_string)(struct ivy_ast_node *, b_string *);
|
||||
void (*n_to_string)(struct ivy_ast_node *, fx_string *);
|
||||
void (*n_init_state)(struct ivy_parser *, struct parser_state *, uintptr_t);
|
||||
void (*n_collect_children)(
|
||||
struct ivy_ast_node *, struct ivy_ast_node_iterator *);
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
#include "iterate.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
static void to_string(struct ivy_ast_node *node, fx_string *str)
|
||||
{
|
||||
struct ivy_ast_op_node *op = (struct ivy_ast_op_node *)node;
|
||||
|
||||
b_string_append_cstrf(
|
||||
fx_string_append_cstrf(
|
||||
str, "%s (%s)", ivy_ast_node_type_to_string(node->n_type),
|
||||
ivy_operator_id_to_string(op->n_op->op_id));
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "iterate.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
|
||||
enum package_type {
|
||||
@@ -23,7 +23,7 @@ struct package_parser_state {
|
||||
unsigned int s_prev;
|
||||
|
||||
/* only used for PACKAGE_STATIC */
|
||||
b_queue s_items;
|
||||
fx_queue s_items;
|
||||
struct ivy_ast_node *s_next_index;
|
||||
unsigned int s_next_implicit_index;
|
||||
|
||||
@@ -53,7 +53,7 @@ static enum ivy_status add_package_item(
|
||||
item->n_implicit_index = state->s_next_implicit_index++;
|
||||
}
|
||||
|
||||
b_queue_push_back(&state->s_items, &item->n_base.n_entry);
|
||||
fx_queue_push_back(&state->s_items, &item->n_base.n_entry);
|
||||
|
||||
state->s_next_index = NULL;
|
||||
state->s_prev_node = NULL;
|
||||
@@ -76,7 +76,7 @@ static struct ivy_ast_node *finalise_package(struct package_parser_state *state)
|
||||
}
|
||||
|
||||
s->n_items = state->s_items;
|
||||
state->s_items = B_QUEUE_INIT;
|
||||
state->s_items = FX_QUEUE_INIT;
|
||||
return (struct ivy_ast_node *)s;
|
||||
case PACKAGE_DYNAMIC:
|
||||
d = (struct ivy_ast_pkg_dynamic_node *)ast_node_create(
|
||||
@@ -374,24 +374,24 @@ static void pkg_static_collect_children(
|
||||
struct ivy_ast_pkg_static_node *pkg
|
||||
= (struct ivy_ast_pkg_static_node *)node;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&pkg->n_items);
|
||||
fx_queue_entry *entry = fx_queue_first(&pkg->n_items);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *item
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, item);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
static void pkg_static_item_to_string(struct ivy_ast_node *node, b_string *str)
|
||||
static void pkg_static_item_to_string(struct ivy_ast_node *node, fx_string *str)
|
||||
{
|
||||
struct ivy_ast_pkg_static_item_node *item
|
||||
= (struct ivy_ast_pkg_static_item_node *)node;
|
||||
|
||||
b_string_append_cstr(str, ivy_ast_node_type_to_string(node->n_type));
|
||||
fx_string_append_cstr(str, ivy_ast_node_type_to_string(node->n_type));
|
||||
|
||||
if (!item->n_index) {
|
||||
b_string_append_cstrf(str, " (%u)", item->n_implicit_index);
|
||||
fx_string_append_cstrf(str, " (%u)", item->n_implicit_index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "ivy/status.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -371,28 +371,28 @@ static void collect_children(
|
||||
}
|
||||
}
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
static void to_string(struct ivy_ast_node *node, fx_string *str)
|
||||
{
|
||||
struct ivy_ast_property_node *prop = (struct ivy_ast_property_node *)node;
|
||||
|
||||
b_string_append_cstrf(
|
||||
fx_string_append_cstrf(
|
||||
str, "%s (%s) [", ivy_ast_node_type_to_string(node->n_type),
|
||||
prop->n_ident->t_str);
|
||||
|
||||
if (prop->n_flags & IVY_AST_PROPERTY_GET) {
|
||||
b_string_append_cstr(str, "get");
|
||||
fx_string_append_cstr(str, "get");
|
||||
}
|
||||
|
||||
if ((prop->n_flags & IVY_AST_PROPERTY_GET)
|
||||
&& prop->n_flags & IVY_AST_PROPERTY_SET) {
|
||||
b_string_append_cstr(str, ", ");
|
||||
fx_string_append_cstr(str, ", ");
|
||||
}
|
||||
|
||||
if (prop->n_flags & IVY_AST_PROPERTY_SET) {
|
||||
b_string_append_cstr(str, "set");
|
||||
fx_string_append_cstr(str, "set");
|
||||
}
|
||||
|
||||
b_string_append_cstr(str, "]");
|
||||
fx_string_append_cstr(str, "]");
|
||||
}
|
||||
|
||||
struct ast_node_type property_node_ops = {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "ivy/status.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -75,7 +75,7 @@ static struct token_parse_result parse_ident(
|
||||
|
||||
if (state->s_prev == IVY_TOK_LABEL) {
|
||||
/* internal parameter name */
|
||||
b_queue_push_back(&sel->n_arg_names, &tok->t_entry);
|
||||
fx_queue_push_back(&sel->n_arg_names, &tok->t_entry);
|
||||
state->s_prev = IVY_TOK_IDENT;
|
||||
state->s_complete = true;
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
@@ -101,7 +101,7 @@ static struct token_parse_result parse_label(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
b_queue_push_back(&sel->n_arg_labels, &tok->t_entry);
|
||||
fx_queue_push_back(&sel->n_arg_labels, &tok->t_entry);
|
||||
state->s_prev = IVY_TOK_LABEL;
|
||||
state->s_complete = false;
|
||||
|
||||
@@ -119,7 +119,7 @@ static struct token_parse_result parse_linefeed(
|
||||
|
||||
CHECK_SELECTOR_COMPLETE();
|
||||
|
||||
if (!b_queue_empty(&sel->n_arg_labels)
|
||||
if (!fx_queue_empty(&sel->n_arg_labels)
|
||||
&& state->s_prev != IVY_SYM_RIGHT_PAREN) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
@@ -142,7 +142,7 @@ static struct token_parse_result parse_left_paren(
|
||||
struct ivy_ast_selector_node *sel
|
||||
= (struct ivy_ast_selector_node *)state->s_base.s_node;
|
||||
|
||||
if (state->s_prev != IVY_TOK_IDENT || !b_queue_empty(&sel->n_arg_labels)) {
|
||||
if (state->s_prev != IVY_TOK_IDENT || !fx_queue_empty(&sel->n_arg_labels)) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ static struct token_parse_result parse_right_paren(
|
||||
struct ivy_ast_selector_node *sel
|
||||
= (struct ivy_ast_selector_node *)state->s_base.s_node;
|
||||
|
||||
if (state->s_prev != IVY_TOK_IDENT || b_queue_empty(&sel->n_arg_labels)) {
|
||||
if (state->s_prev != IVY_TOK_IDENT || fx_queue_empty(&sel->n_arg_labels)) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
@@ -181,8 +181,8 @@ static struct token_parse_result parse_pipe(
|
||||
switch (state->s_prev) {
|
||||
case IVY_SYM_RIGHT_PAREN:
|
||||
/* this looks like a complex message selector */
|
||||
if (b_queue_empty(&sel->n_arg_labels)
|
||||
|| b_queue_empty(&sel->n_arg_names)) {
|
||||
if (fx_queue_empty(&sel->n_arg_labels)
|
||||
|| fx_queue_empty(&sel->n_arg_names)) {
|
||||
/* no message args */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
@@ -194,8 +194,8 @@ static struct token_parse_result parse_pipe(
|
||||
break;
|
||||
case IVY_TOK_IDENT:
|
||||
/* this looks like a unary or keyword message. */
|
||||
if (!b_queue_empty(&sel->n_arg_labels)
|
||||
&& b_queue_empty(&sel->n_arg_names)) {
|
||||
if (!fx_queue_empty(&sel->n_arg_labels)
|
||||
&& fx_queue_empty(&sel->n_arg_names)) {
|
||||
/* keyword message with no arg names. */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
@@ -223,19 +223,19 @@ static struct token_parse_result parse_other(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
static void to_string(struct ivy_ast_node *node, fx_string *str)
|
||||
{
|
||||
struct ivy_ast_selector_node *sel = (struct ivy_ast_selector_node *)node;
|
||||
|
||||
b_string_append_cstrf(
|
||||
fx_string_append_cstrf(
|
||||
str, "%s [", ivy_ast_node_type_to_string(node->n_type));
|
||||
|
||||
switch (sel->n_recipient) {
|
||||
case IVY_SELECTOR_RECIPIENT_CLASS:
|
||||
b_string_append_cstr(str, "+");
|
||||
fx_string_append_cstr(str, "+");
|
||||
break;
|
||||
case IVY_SELECTOR_RECIPIENT_OBJECT:
|
||||
b_string_append_cstr(str, "-");
|
||||
fx_string_append_cstr(str, "-");
|
||||
break;
|
||||
default:
|
||||
/* this will occur if the selector is being used to send a
|
||||
@@ -245,50 +245,50 @@ static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
}
|
||||
|
||||
if (sel->n_msg_name) {
|
||||
b_string_append_cstr(str, sel->n_msg_name->t_str);
|
||||
fx_string_append_cstr(str, sel->n_msg_name->t_str);
|
||||
}
|
||||
|
||||
if (sel->n_msg_name && !b_queue_empty(&sel->n_arg_labels)) {
|
||||
b_string_append_cstr(str, "(");
|
||||
if (sel->n_msg_name && !fx_queue_empty(&sel->n_arg_labels)) {
|
||||
fx_string_append_cstr(str, "(");
|
||||
}
|
||||
|
||||
b_queue_entry *label_entry = b_queue_first(&sel->n_arg_labels);
|
||||
b_queue_entry *name_entry = b_queue_first(&sel->n_arg_names);
|
||||
fx_queue_entry *label_entry = fx_queue_first(&sel->n_arg_labels);
|
||||
fx_queue_entry *name_entry = fx_queue_first(&sel->n_arg_names);
|
||||
|
||||
int i = 0;
|
||||
while (label_entry) {
|
||||
if (i > 0) {
|
||||
b_string_append_cstr(str, " ");
|
||||
fx_string_append_cstr(str, " ");
|
||||
}
|
||||
|
||||
struct ivy_token *label, *name;
|
||||
|
||||
label = b_unbox(struct ivy_token, label_entry, t_entry);
|
||||
name = b_unbox(struct ivy_token, name_entry, t_entry);
|
||||
label = fx_unbox(struct ivy_token, label_entry, t_entry);
|
||||
name = fx_unbox(struct ivy_token, name_entry, t_entry);
|
||||
|
||||
if (label && label->t_type == IVY_TOK_LABEL && label->t_str) {
|
||||
b_string_append_cstrf(str, "%s:", label->t_str);
|
||||
fx_string_append_cstrf(str, "%s:", label->t_str);
|
||||
} else {
|
||||
b_string_append_cstrf(str, "_:");
|
||||
fx_string_append_cstrf(str, "_:");
|
||||
}
|
||||
|
||||
if (name) {
|
||||
b_string_append_cstrf(str, "%s", name->t_str);
|
||||
fx_string_append_cstrf(str, "%s", name->t_str);
|
||||
}
|
||||
|
||||
if (name) {
|
||||
i++;
|
||||
}
|
||||
|
||||
label_entry = b_queue_next(label_entry);
|
||||
name_entry = b_queue_next(name_entry);
|
||||
label_entry = fx_queue_next(label_entry);
|
||||
name_entry = fx_queue_next(name_entry);
|
||||
}
|
||||
|
||||
if (sel->n_msg_name && !b_queue_empty(&sel->n_arg_labels)) {
|
||||
b_string_append_cstr(str, ")");
|
||||
if (sel->n_msg_name && !fx_queue_empty(&sel->n_arg_labels)) {
|
||||
fx_string_append_cstr(str, ")");
|
||||
}
|
||||
|
||||
b_string_append_cstr(str, "]");
|
||||
fx_string_append_cstr(str, "]");
|
||||
}
|
||||
|
||||
static void init_state(struct ivy_parser *ctx, struct parser_state *sp, uintptr_t arg)
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
#include "iterate.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
static void to_string(struct ivy_ast_node *node, fx_string *str)
|
||||
{
|
||||
struct ivy_ast_string_node *s = (struct ivy_ast_string_node *)node;
|
||||
b_string_append_cstrf(
|
||||
fx_string_append_cstrf(
|
||||
str, "%s (\"%s\")", ivy_ast_node_type_to_string(node->n_type),
|
||||
s->n_value->t_str);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ struct token_parse_result parse_string(struct ivy_parser *ctx, struct ivy_token
|
||||
}
|
||||
|
||||
child->n_value = tok;
|
||||
b_queue_push_back(&parent->n_value, &child->n_base.n_entry);
|
||||
fx_queue_push_back(&parent->n_value, &child->n_base.n_entry);
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ static enum ivy_status add_child(
|
||||
struct ivy_ast_fstring_node *str
|
||||
= (struct ivy_ast_fstring_node *)parent->s_node;
|
||||
|
||||
b_queue_push_back(&str->n_value, &child->n_entry);
|
||||
fx_queue_push_back(&str->n_value, &child->n_entry);
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
@@ -68,12 +68,12 @@ static void collect_children(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
|
||||
{
|
||||
struct ivy_ast_fstring_node *str = (struct ivy_ast_fstring_node *)node;
|
||||
b_queue_entry *entry = b_queue_first(&str->n_value);
|
||||
fx_queue_entry *entry = fx_queue_first(&str->n_value);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *child
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, child);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ struct try_parser_state {
|
||||
|
||||
struct ivy_ast_block_node *s_try, *s_finally;
|
||||
|
||||
b_queue s_catch_branches;
|
||||
fx_queue s_catch_branches;
|
||||
struct ivy_ast_try_catch_node *s_cur_catch_branch;
|
||||
};
|
||||
|
||||
static enum ivy_status flush_catch_branch(struct try_parser_state *state)
|
||||
{
|
||||
b_queue_push_back(
|
||||
fx_queue_push_back(
|
||||
&state->s_catch_branches,
|
||||
&state->s_cur_catch_branch->n_base.n_entry);
|
||||
|
||||
@@ -41,7 +41,7 @@ static enum ivy_status finalise_try(struct try_parser_state *state)
|
||||
|
||||
state->s_try = NULL;
|
||||
state->s_finally = NULL;
|
||||
state->s_catch_branches = B_QUEUE_INIT;
|
||||
state->s_catch_branches = FX_QUEUE_INIT;
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
@@ -236,12 +236,12 @@ static void try_collect_children(
|
||||
|
||||
ast_node_iterator_enqueue_node(iterator, node, try->n_try);
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&try->n_catch);
|
||||
fx_queue_entry *entry = fx_queue_first(&try->n_catch);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *catch
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, catch);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
if (try->n_finally) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "ivy/status.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -14,7 +14,7 @@ struct tuple_parser_state {
|
||||
struct ivy_ast_node *s_prev_node;
|
||||
unsigned int s_prev;
|
||||
|
||||
b_queue s_items;
|
||||
fx_queue s_items;
|
||||
};
|
||||
|
||||
static void finalise_tuple(struct tuple_parser_state *state)
|
||||
@@ -23,7 +23,7 @@ static void finalise_tuple(struct tuple_parser_state *state)
|
||||
= (struct ivy_ast_tuple_node *)state->s_base.s_node;
|
||||
|
||||
tuple->n_members = state->s_items;
|
||||
state->s_items = B_QUEUE_INIT;
|
||||
state->s_items = FX_QUEUE_INIT;
|
||||
}
|
||||
|
||||
struct token_parse_result parse_comma(struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
@@ -40,7 +40,7 @@ struct token_parse_result parse_comma(struct ivy_parser *ctx, struct ivy_token *
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
b_queue_push_back(&state->s_items, &state->s_prev_node->n_entry);
|
||||
fx_queue_push_back(&state->s_items, &state->s_prev_node->n_entry);
|
||||
state->s_prev_node = NULL;
|
||||
state->s_prev = IVY_SYM_COMMA;
|
||||
|
||||
@@ -69,7 +69,7 @@ struct token_parse_result parse_right_paren(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
b_queue_push_back(&state->s_items, &state->s_prev_node->n_entry);
|
||||
fx_queue_push_back(&state->s_items, &state->s_prev_node->n_entry);
|
||||
state->s_prev_node = NULL;
|
||||
state->s_prev = IVY_SYM_RIGHT_PAREN;
|
||||
|
||||
@@ -100,7 +100,7 @@ static void init_state(struct ivy_parser *ctx, struct parser_state *sp, uintptr_
|
||||
if (arg) {
|
||||
/* arg is the first node in the tuple */
|
||||
struct ivy_ast_node *item = (struct ivy_ast_node *)arg;
|
||||
b_queue_push_back(&state->s_items, &item->n_entry);
|
||||
fx_queue_push_back(&state->s_items, &item->n_entry);
|
||||
state->s_prev = IVY_SYM_COMMA;
|
||||
}
|
||||
|
||||
@@ -117,12 +117,12 @@ static void collect_children(
|
||||
{
|
||||
struct ivy_ast_tuple_node *tuple = (struct ivy_ast_tuple_node *)node;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&tuple->n_members);
|
||||
fx_queue_entry *entry = fx_queue_first(&tuple->n_members);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *item
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, item);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -37,7 +37,7 @@ static struct token_parse_result parse_ident(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
b_queue_push_back(&node->n_ident, &tok->t_entry);
|
||||
fx_queue_push_back(&node->n_ident, &tok->t_entry);
|
||||
|
||||
state->s_prev_token = IVY_TOK_IDENT;
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
@@ -57,31 +57,31 @@ static struct token_parse_result parse_linefeed(
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
}
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
static void to_string(struct ivy_ast_node *node, fx_string *str)
|
||||
{
|
||||
struct ivy_ast_unit_import_node *unit_import
|
||||
= (struct ivy_ast_unit_import_node *)node;
|
||||
|
||||
b_string_append_cstr(str, ivy_ast_node_type_to_string(node->n_type));
|
||||
fx_string_append_cstr(str, ivy_ast_node_type_to_string(node->n_type));
|
||||
|
||||
b_string_append_cstr(str, " (");
|
||||
fx_string_append_cstr(str, " (");
|
||||
|
||||
int i = 0;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&unit_import->n_ident);
|
||||
fx_queue_entry *entry = fx_queue_first(&unit_import->n_ident);
|
||||
while (entry) {
|
||||
struct ivy_token *tok = b_unbox(struct ivy_token, entry, t_entry);
|
||||
struct ivy_token *tok = fx_unbox(struct ivy_token, entry, t_entry);
|
||||
|
||||
if (i > 0) {
|
||||
b_string_append_cstr(str, ".");
|
||||
fx_string_append_cstr(str, ".");
|
||||
}
|
||||
|
||||
b_string_append_cstr(str, tok->t_str);
|
||||
fx_string_append_cstr(str, tok->t_str);
|
||||
i++;
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
b_string_append_cstr(str, ")");
|
||||
fx_string_append_cstr(str, ")");
|
||||
}
|
||||
|
||||
static void init_state(struct ivy_parser *ctx, struct parser_state *sp, uintptr_t arg)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -37,7 +37,7 @@ static struct token_parse_result parse_ident(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
b_queue_push_back(&node->n_ident, &tok->t_entry);
|
||||
fx_queue_push_back(&node->n_ident, &tok->t_entry);
|
||||
|
||||
state->s_prev_token = IVY_TOK_IDENT;
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
@@ -57,30 +57,30 @@ static struct token_parse_result parse_linefeed(
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
}
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
static void to_string(struct ivy_ast_node *node, fx_string *str)
|
||||
{
|
||||
struct ivy_ast_unit_package_node *unit_package
|
||||
= (struct ivy_ast_unit_package_node *)node;
|
||||
b_string_append_cstr(str, ivy_ast_node_type_to_string(node->n_type));
|
||||
fx_string_append_cstr(str, ivy_ast_node_type_to_string(node->n_type));
|
||||
|
||||
b_string_append_cstr(str, " (");
|
||||
fx_string_append_cstr(str, " (");
|
||||
|
||||
int i = 0;
|
||||
b_queue_entry *entry = b_queue_first(&unit_package->n_ident);
|
||||
fx_queue_entry *entry = fx_queue_first(&unit_package->n_ident);
|
||||
while (entry) {
|
||||
struct ivy_token *tok = b_unbox(struct ivy_token, entry, t_entry);
|
||||
struct ivy_token *tok = fx_unbox(struct ivy_token, entry, t_entry);
|
||||
|
||||
if (i > 0) {
|
||||
b_string_append_cstr(str, ".");
|
||||
fx_string_append_cstr(str, ".");
|
||||
}
|
||||
|
||||
b_string_append_cstr(str, tok->t_str);
|
||||
fx_string_append_cstr(str, tok->t_str);
|
||||
i++;
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
b_string_append_cstr(str, ")");
|
||||
fx_string_append_cstr(str, ")");
|
||||
}
|
||||
|
||||
static void init_state(struct ivy_parser *ctx, struct parser_state *sp, uintptr_t arg)
|
||||
|
||||
@@ -50,7 +50,7 @@ static enum ivy_status add_child(
|
||||
struct parser_state *parent, struct ivy_ast_node *child)
|
||||
{
|
||||
struct ivy_ast_unit_node *unit = (struct ivy_ast_unit_node *)parent->s_node;
|
||||
b_queue_push_back(&unit->n_children, &child->n_entry);
|
||||
fx_queue_push_back(&unit->n_children, &child->n_entry);
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
@@ -58,12 +58,12 @@ static void collect_children(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
|
||||
{
|
||||
struct ivy_ast_unit_node *unit = (struct ivy_ast_unit_node *)node;
|
||||
b_queue_entry *entry = b_queue_first(&unit->n_children);
|
||||
fx_queue_entry *entry = fx_queue_first(&unit->n_children);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *child
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
= fx_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, child);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* - each node type (var, msg, expr) gets its own code generator type
|
||||
* - expr code generator is limited to simple operator arithmetic.
|
||||
* - when a code generator encounters a node of an equal or lower depth than
|
||||
* the node that started it, it has reached the end of its subtree.
|
||||
* the node that started it, it has reached the end of its subst.
|
||||
* - depth is supplied by the ast iterator.
|
||||
* - need to devise a way for expression code generator to "return" a
|
||||
* mie_value for its parent generator to use.
|
||||
@@ -21,12 +21,12 @@
|
||||
static struct code_generator_state *get_current_generator_state(
|
||||
struct ivy_codegen *gen)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(&gen->c_state);
|
||||
fx_queue_entry *entry = fx_queue_last(&gen->c_state);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct code_generator_state, entry, s_entry);
|
||||
return fx_unbox(struct code_generator_state, entry, s_entry);
|
||||
}
|
||||
|
||||
static void code_generator_state_inherit(
|
||||
@@ -76,7 +76,7 @@ enum ivy_status codegen_push_generator(
|
||||
return status;
|
||||
}
|
||||
|
||||
b_queue_push_back(&gen->c_state, &state->s_entry);
|
||||
fx_queue_push_back(&gen->c_state, &state->s_entry);
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
@@ -84,13 +84,13 @@ enum ivy_status codegen_push_generator(
|
||||
enum ivy_status codegen_pop_generator(
|
||||
struct ivy_codegen *gen, struct code_generator_value *result)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_pop_back(&gen->c_state);
|
||||
fx_queue_entry *entry = fx_queue_pop_back(&gen->c_state);
|
||||
if (!entry) {
|
||||
return IVY_ERR_BAD_STATE;
|
||||
}
|
||||
|
||||
struct code_generator_state *state
|
||||
= b_unbox(struct code_generator_state, entry, s_entry);
|
||||
= fx_unbox(struct code_generator_state, entry, s_entry);
|
||||
|
||||
enum ivy_status status = IVY_OK;
|
||||
|
||||
@@ -109,7 +109,7 @@ enum ivy_status codegen_pop_generator(
|
||||
enum ivy_status codegen_define_variable(
|
||||
struct ivy_codegen *gen, const char *ident, const struct codegen_var *var)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(&gen->c_state);
|
||||
fx_queue_entry *entry = fx_queue_last(&gen->c_state);
|
||||
if (!entry) {
|
||||
return IVY_ERR_NO_ENTRY;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ enum ivy_status codegen_define_variable(
|
||||
|
||||
while (entry) {
|
||||
struct code_generator_state *state
|
||||
= b_unbox(struct code_generator_state, entry, s_entry);
|
||||
= fx_unbox(struct code_generator_state, entry, s_entry);
|
||||
const struct code_generator *generator = state->s_gen;
|
||||
enum ivy_status status = IVY_ERR_NO_ENTRY;
|
||||
|
||||
@@ -130,7 +130,7 @@ enum ivy_status codegen_define_variable(
|
||||
break;
|
||||
}
|
||||
|
||||
entry = b_queue_prev(entry);
|
||||
entry = fx_queue_prev(entry);
|
||||
}
|
||||
|
||||
return IVY_ERR_NOT_SUPPORTED;
|
||||
@@ -155,7 +155,7 @@ enum ivy_status resolve_global_variable(
|
||||
enum ivy_status codegen_resolve_variable(
|
||||
struct ivy_codegen *gen, const char *ident, struct codegen_var *out)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(&gen->c_state);
|
||||
fx_queue_entry *entry = fx_queue_last(&gen->c_state);
|
||||
if (!entry) {
|
||||
return IVY_ERR_NO_ENTRY;
|
||||
}
|
||||
@@ -164,7 +164,7 @@ enum ivy_status codegen_resolve_variable(
|
||||
|
||||
while (entry) {
|
||||
struct code_generator_state *state
|
||||
= b_unbox(struct code_generator_state, entry, s_entry);
|
||||
= fx_unbox(struct code_generator_state, entry, s_entry);
|
||||
const struct code_generator *generator = state->s_gen;
|
||||
enum ivy_status status = IVY_ERR_NO_ENTRY;
|
||||
|
||||
@@ -177,7 +177,7 @@ enum ivy_status codegen_resolve_variable(
|
||||
break;
|
||||
}
|
||||
|
||||
entry = b_queue_prev(entry);
|
||||
entry = fx_queue_prev(entry);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -187,12 +187,12 @@ enum ivy_status codegen_resolve_variable(
|
||||
#endif
|
||||
|
||||
if (entry) {
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
while (entry) {
|
||||
struct code_generator_state *state
|
||||
= b_unbox(struct code_generator_state, entry, s_entry);
|
||||
= fx_unbox(struct code_generator_state, entry, s_entry);
|
||||
const struct code_generator *generator = state->s_gen;
|
||||
enum ivy_status status = IVY_OK;
|
||||
|
||||
@@ -204,7 +204,7 @@ enum ivy_status codegen_resolve_variable(
|
||||
return status;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
return IVY_OK;
|
||||
@@ -371,7 +371,7 @@ enum ivy_status ivy_codegen_push_node(
|
||||
return IVY_ERR_BAD_STATE;
|
||||
}
|
||||
|
||||
if (b_queue_empty(&gen->c_state)) {
|
||||
if (fx_queue_empty(&gen->c_state)) {
|
||||
const struct code_generator *generator
|
||||
= get_root_code_generator(node->n_type);
|
||||
if (!generator) {
|
||||
@@ -441,7 +441,7 @@ enum ivy_status ivy_codegen_push_eof(struct ivy_codegen *gen)
|
||||
.r_status = IVY_OK,
|
||||
};
|
||||
|
||||
while (!b_queue_empty(&gen->c_state)) {
|
||||
while (!fx_queue_empty(&gen->c_state)) {
|
||||
struct code_generator_value value = {0};
|
||||
status = codegen_pop_generator(gen, &value);
|
||||
if (status != IVY_OK) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "var-map.h"
|
||||
|
||||
#include <blue/core/queue.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <ivy/lang/ast.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <mie/ctx.h>
|
||||
@@ -124,7 +124,7 @@ struct code_generator {
|
||||
};
|
||||
|
||||
struct code_generator_state {
|
||||
b_queue_entry s_entry;
|
||||
fx_queue_entry s_entry;
|
||||
uintptr_t s_argv;
|
||||
void *s_argp;
|
||||
const struct code_generator *s_gen;
|
||||
@@ -135,9 +135,9 @@ struct code_generator_state {
|
||||
};
|
||||
|
||||
struct ivy_codegen {
|
||||
b_queue c_values;
|
||||
b_queue c_state;
|
||||
b_queue c_scope;
|
||||
fx_queue c_values;
|
||||
fx_queue c_state;
|
||||
fx_queue c_scope;
|
||||
struct mie_builder *c_builder;
|
||||
struct mie_ctx *c_ctx;
|
||||
struct mie_module *c_module;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
struct cond_group_codegen_state {
|
||||
struct code_generator_state s_base;
|
||||
struct mie_block *s_end;
|
||||
b_queue s_edges;
|
||||
fx_queue s_edges;
|
||||
};
|
||||
|
||||
static struct code_generator_result gen_cond_group(
|
||||
@@ -55,10 +55,10 @@ static enum ivy_status get_eval_type(
|
||||
{
|
||||
struct mie_type *type = NULL;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&state->s_edges);
|
||||
fx_queue_entry *entry = fx_queue_first(&state->s_edges);
|
||||
while (entry) {
|
||||
struct mie_phi_edge *edge
|
||||
= b_unbox(struct mie_phi_edge, entry, e_entry);
|
||||
= fx_unbox(struct mie_phi_edge, entry, e_entry);
|
||||
if (!edge->e_value) {
|
||||
goto next;
|
||||
}
|
||||
@@ -71,7 +71,7 @@ static enum ivy_status get_eval_type(
|
||||
}
|
||||
|
||||
next:
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
*out = type;
|
||||
@@ -82,7 +82,7 @@ static enum ivy_status emit_phi_instr(
|
||||
struct ivy_codegen *gen, struct cond_group_codegen_state *state,
|
||||
struct mie_type *type, struct mie_value **result)
|
||||
{
|
||||
size_t nr_edges = b_queue_length(&state->s_edges);
|
||||
size_t nr_edges = fx_queue_length(&state->s_edges);
|
||||
if (!nr_edges) {
|
||||
return IVY_OK;
|
||||
}
|
||||
@@ -94,14 +94,14 @@ static enum ivy_status emit_phi_instr(
|
||||
|
||||
size_t i = 0;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&state->s_edges);
|
||||
fx_queue_entry *entry = fx_queue_first(&state->s_edges);
|
||||
while (entry) {
|
||||
struct mie_phi_edge *edge
|
||||
= b_unbox(struct mie_phi_edge, entry, e_entry);
|
||||
= fx_unbox(struct mie_phi_edge, entry, e_entry);
|
||||
|
||||
memcpy(&edges[i], edge, sizeof *edge);
|
||||
i++;
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
struct mie_value *phi = mie_builder_phi(
|
||||
@@ -159,7 +159,7 @@ static struct code_generator_result value_received(
|
||||
assert(value->v_type == CODE_GENERATOR_VALUE_PHI_EDGE);
|
||||
|
||||
struct mie_phi_edge *edge = code_generator_value_get_phi_edge(value);
|
||||
b_queue_push_back(&cond->s_edges, &edge->e_entry);
|
||||
fx_queue_push_back(&cond->s_edges, &edge->e_entry);
|
||||
|
||||
return CODEGEN_RESULT_OK(0);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ enum expr_operand_type {
|
||||
};
|
||||
|
||||
struct expr_item {
|
||||
b_queue_entry i_entry;
|
||||
fx_queue_entry i_entry;
|
||||
enum expr_item_type i_type;
|
||||
enum expr_operand_type i_operand_type;
|
||||
struct ivy_ast_node *i_node;
|
||||
@@ -29,7 +29,7 @@ struct expr_codegen_state {
|
||||
struct code_generator_state s_base;
|
||||
struct ivy_ast_node *s_expr_root;
|
||||
uintptr_t s_flags;
|
||||
b_queue s_item_queue;
|
||||
fx_queue s_item_queue;
|
||||
};
|
||||
|
||||
#if 0
|
||||
@@ -66,7 +66,7 @@ static enum ivy_status push_operand(
|
||||
item->i_operand_type = EXPR_OPERAND_VAR;
|
||||
}
|
||||
|
||||
b_queue_push_back(&expr->s_item_queue, &item->i_entry);
|
||||
fx_queue_push_back(&expr->s_item_queue, &item->i_entry);
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ static enum ivy_status push_operator(
|
||||
item->i_type = EXPR_OPERATOR;
|
||||
item->i_node = node;
|
||||
|
||||
b_queue_push_back(&expr->s_item_queue, &item->i_entry);
|
||||
fx_queue_push_back(&expr->s_item_queue, &item->i_entry);
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
@@ -543,24 +543,24 @@ static enum ivy_status state_fini(
|
||||
|
||||
struct expr_codegen_state *expr = (struct expr_codegen_state *)state;
|
||||
enum ivy_status status = IVY_OK;
|
||||
b_queue stack = B_QUEUE_INIT;
|
||||
fx_queue stack = FX_QUEUE_INIT;
|
||||
|
||||
b_queue_entry *cur = NULL;
|
||||
while ((cur = b_queue_pop_back(&expr->s_item_queue))) {
|
||||
struct expr_item *item = b_unbox(struct expr_item, cur, i_entry);
|
||||
fx_queue_entry *cur = NULL;
|
||||
while ((cur = fx_queue_pop_back(&expr->s_item_queue))) {
|
||||
struct expr_item *item = fx_unbox(struct expr_item, cur, i_entry);
|
||||
|
||||
if (item->i_type == EXPR_OPERAND) {
|
||||
b_queue_push_back(&stack, &item->i_entry);
|
||||
fx_queue_push_back(&stack, &item->i_entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
struct ivy_ast_op_node *op = (struct ivy_ast_op_node *)item->i_node;
|
||||
b_queue_entry *left_entry = b_queue_pop_back(&stack);
|
||||
b_queue_entry *right_entry = b_queue_pop_back(&stack);
|
||||
fx_queue_entry *left_entry = fx_queue_pop_back(&stack);
|
||||
fx_queue_entry *right_entry = fx_queue_pop_back(&stack);
|
||||
struct expr_item *left
|
||||
= b_unbox(struct expr_item, left_entry, i_entry);
|
||||
= fx_unbox(struct expr_item, left_entry, i_entry);
|
||||
struct expr_item *right
|
||||
= b_unbox(struct expr_item, right_entry, i_entry);
|
||||
= fx_unbox(struct expr_item, right_entry, i_entry);
|
||||
|
||||
struct mie_value *left_value = left->i_value;
|
||||
struct mie_value *right_value = right->i_value;
|
||||
@@ -670,19 +670,19 @@ static enum ivy_status state_fini(
|
||||
|
||||
skip_op:
|
||||
item->i_value = op_value;
|
||||
b_queue_push_back(&stack, &item->i_entry);
|
||||
fx_queue_push_back(&stack, &item->i_entry);
|
||||
}
|
||||
|
||||
if (status != IVY_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
cur = b_queue_pop_back(&stack);
|
||||
cur = fx_queue_pop_back(&stack);
|
||||
if (!cur) {
|
||||
return IVY_ERR_INTERNAL_FAILURE;
|
||||
}
|
||||
|
||||
struct expr_item *result_item = b_unbox(struct expr_item, cur, i_entry);
|
||||
struct expr_item *result_item = fx_unbox(struct expr_item, cur, i_entry);
|
||||
struct mie_value *result_value;
|
||||
if (result_item->i_operand_type == EXPR_OPERAND_VAR) {
|
||||
result_value = load_variable(gen, &result_item->i_var);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "../debug.h"
|
||||
#include "codegen.h"
|
||||
|
||||
#include <blue/core/stringstream.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -98,7 +98,7 @@ static struct code_generator_result gen_selector(
|
||||
msg->s_prev_part = MSG_SELECTOR;
|
||||
|
||||
msg->s_nr_args = 0;
|
||||
msg->s_max_args = b_queue_length(&msg->s_selector->n_arg_labels);
|
||||
msg->s_max_args = fx_queue_length(&msg->s_selector->n_arg_labels);
|
||||
msg->s_args = calloc(msg->s_max_args, sizeof(struct mie_value *));
|
||||
|
||||
if (!msg->s_args) {
|
||||
@@ -126,38 +126,38 @@ static enum ivy_status state_init(
|
||||
}
|
||||
|
||||
static void serialise_selector(
|
||||
struct ivy_ast_selector_node *sel, b_stringstream *out)
|
||||
struct ivy_ast_selector_node *sel, fx_stringstream *out)
|
||||
{
|
||||
b_stream_write_string(out, "_M", NULL);
|
||||
fx_stream_write_string(out, "_M", NULL);
|
||||
|
||||
if (sel->n_msg_name) {
|
||||
const char *msg_name = sel->n_msg_name->t_str;
|
||||
b_stream_write_fmt(out, NULL, "%zu%s", strlen(msg_name), msg_name);
|
||||
fx_stream_write_fmt(out, NULL, "%zu%s", strlen(msg_name), msg_name);
|
||||
} else {
|
||||
b_stream_write_char(out, '0');
|
||||
fx_stream_write_char(out, '0');
|
||||
}
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&sel->n_arg_labels);
|
||||
fx_queue_entry *entry = fx_queue_first(&sel->n_arg_labels);
|
||||
while (entry) {
|
||||
struct ivy_token *arg = b_unbox(struct ivy_token, entry, t_entry);
|
||||
struct ivy_token *arg = fx_unbox(struct ivy_token, entry, t_entry);
|
||||
|
||||
if (arg->t_type != IVY_TOK_IDENT && arg->t_type != IVY_TOK_LABEL) {
|
||||
b_stream_write_char(out, '0');
|
||||
fx_stream_write_char(out, '0');
|
||||
goto next;
|
||||
}
|
||||
|
||||
const char *label = arg->t_str;
|
||||
|
||||
if (label) {
|
||||
b_stream_write_fmt(out, NULL, "%zu%s", strlen(label), label);
|
||||
fx_stream_write_fmt(out, NULL, "%zu%s", strlen(label), label);
|
||||
} else {
|
||||
b_stream_write_char(out, '0');
|
||||
fx_stream_write_char(out, '0');
|
||||
}
|
||||
next:
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
b_stream_write_char(out, 'E');
|
||||
fx_stream_write_char(out, 'E');
|
||||
}
|
||||
|
||||
static enum ivy_status state_fini(
|
||||
@@ -168,10 +168,10 @@ static enum ivy_status state_fini(
|
||||
|
||||
struct msg_codegen_state *msg = (struct msg_codegen_state *)state;
|
||||
|
||||
b_stringstream *str = b_stringstream_create();
|
||||
fx_stringstream *str = fx_stringstream_create();
|
||||
serialise_selector(msg->s_selector, str);
|
||||
char *sel = b_stringstream_steal(str);
|
||||
b_stringstream_unref(str);
|
||||
char *sel = fx_stringstream_steal(str);
|
||||
fx_stringstream_unref(str);
|
||||
|
||||
struct mie_value *sel_value = mie_ctx_get_selector(gen->c_ctx, sel);
|
||||
free(sel);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "codegen.h"
|
||||
#include "var-map.h"
|
||||
|
||||
#include <blue/core/stringstream.h>
|
||||
#include <blue/ds/list.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/ds/list.h>
|
||||
#include <mie/ir/block.h>
|
||||
#include <mie/ir/func.h>
|
||||
#include <mie/ir/module.h>
|
||||
@@ -142,19 +142,19 @@ static struct code_generator_result gen_while_loop(
|
||||
return CODEGEN_RESULT_OK(CODEGEN_R_REPEAT_NODE);
|
||||
}
|
||||
|
||||
static void serialise_package_name(b_queue *parts, b_stringstream *out)
|
||||
static void serialise_package_name(fx_queue *parts, fx_stringstream *out)
|
||||
{
|
||||
b_stream_write_string(out, "_ZN", NULL);
|
||||
fx_stream_write_string(out, "_ZN", NULL);
|
||||
|
||||
b_queue_entry *entry = b_queue_first(parts);
|
||||
fx_queue_entry *entry = fx_queue_first(parts);
|
||||
while (entry) {
|
||||
struct ivy_token *tok = b_unbox(struct ivy_token, entry, t_entry);
|
||||
struct ivy_token *tok = fx_unbox(struct ivy_token, entry, t_entry);
|
||||
size_t len = strlen(tok->t_str);
|
||||
b_stream_write_fmt(out, NULL, "%zu%s", len, tok->t_str);
|
||||
entry = b_queue_next(entry);
|
||||
fx_stream_write_fmt(out, NULL, "%zu%s", len, tok->t_str);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
b_stream_write_char(out, 'E');
|
||||
fx_stream_write_char(out, 'E');
|
||||
}
|
||||
|
||||
static struct code_generator_result gen_unit_package(
|
||||
@@ -165,10 +165,10 @@ static struct code_generator_result gen_unit_package(
|
||||
struct ivy_ast_unit_package_node *pkg
|
||||
= (struct ivy_ast_unit_package_node *)node;
|
||||
|
||||
b_stringstream *str = b_stringstream_create();
|
||||
fx_stringstream *str = fx_stringstream_create();
|
||||
serialise_package_name(&pkg->n_ident, str);
|
||||
char *ident = b_stringstream_steal(str);
|
||||
b_stringstream_unref(str);
|
||||
char *ident = fx_stringstream_steal(str);
|
||||
fx_stringstream_unref(str);
|
||||
struct mie_value *ident_val = mie_ctx_get_string(gen->c_ctx, ident);
|
||||
free(ident);
|
||||
|
||||
@@ -198,14 +198,14 @@ static struct code_generator_result gen_unit_import(
|
||||
import_list = MIE_ARRAY(rec->r_value);
|
||||
}
|
||||
|
||||
b_stringstream *str = b_stringstream_create();
|
||||
fx_stringstream *str = fx_stringstream_create();
|
||||
serialise_package_name(&pkg->n_ident, str);
|
||||
char *ident = b_stringstream_steal(str);
|
||||
b_stringstream_unref(str);
|
||||
char *ident = fx_stringstream_steal(str);
|
||||
fx_stringstream_unref(str);
|
||||
struct mie_value *ident_val = mie_ctx_get_string(gen->c_ctx, ident);
|
||||
free(ident);
|
||||
|
||||
b_list_push_back(import_list->a_values, ident_val);
|
||||
fx_list_push_back(import_list->a_values, ident_val);
|
||||
|
||||
return CODEGEN_RESULT_OK(0);
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
#include "var-map.h"
|
||||
|
||||
#include <blue/ds/hashmap.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/hashmap.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
enum ivy_status codegen_var_map_init(struct codegen_var_map *map)
|
||||
{
|
||||
memset(map, 0x0, sizeof *map);
|
||||
map->m_map = b_hashmap_create(free, free);
|
||||
map->m_map = fx_hashmap_create(free, free);
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
enum ivy_status codegen_var_map_fini(struct codegen_var_map *map)
|
||||
{
|
||||
b_hashmap_unref(map->m_map);
|
||||
fx_hashmap_unref(map->m_map);
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
enum ivy_status codegen_var_map_get(
|
||||
struct codegen_var_map *map, const char *ident, struct codegen_var **out)
|
||||
{
|
||||
b_hashmap_key key = {
|
||||
fx_hashmap_key key = {
|
||||
.key_data = ident,
|
||||
.key_size = strlen(ident),
|
||||
};
|
||||
|
||||
const b_hashmap_value *value = b_hashmap_get(map->m_map, &key);
|
||||
const fx_hashmap_value *value = fx_hashmap_get(map->m_map, &key);
|
||||
|
||||
if (!value) {
|
||||
return IVY_ERR_NO_ENTRY;
|
||||
@@ -42,8 +42,8 @@ enum ivy_status codegen_var_map_put(
|
||||
struct codegen_var_map *map, const char *ident,
|
||||
const struct codegen_var *var)
|
||||
{
|
||||
b_hashmap_key key = {
|
||||
.key_data = b_strdup(ident),
|
||||
fx_hashmap_key key = {
|
||||
.key_data = fx_strdup(ident),
|
||||
.key_size = strlen(ident),
|
||||
};
|
||||
|
||||
@@ -51,7 +51,7 @@ enum ivy_status codegen_var_map_put(
|
||||
return IVY_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
b_hashmap_value value = {
|
||||
fx_hashmap_value value = {
|
||||
.value_data = malloc(sizeof *var),
|
||||
.value_size = sizeof *var,
|
||||
};
|
||||
@@ -63,8 +63,8 @@ enum ivy_status codegen_var_map_put(
|
||||
|
||||
memcpy(value.value_data, var, sizeof *var);
|
||||
|
||||
b_status status = b_hashmap_put(map->m_map, &key, &value);
|
||||
if (!B_OK(status)) {
|
||||
fx_status status = fx_hashmap_put(map->m_map, &key, &value);
|
||||
if (!FX_OK(status)) {
|
||||
free((void *)key.key_data);
|
||||
free(value.value_data);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef CODEGEN_VAR_MAP_H_
|
||||
#define CODEGEN_VAR_MAP_H_
|
||||
|
||||
#include <blue/ds/hashmap.h>
|
||||
#include <fx/ds/hashmap.h>
|
||||
#include <ivy/status.h>
|
||||
|
||||
struct mie_value;
|
||||
@@ -20,7 +20,7 @@ struct codegen_var {
|
||||
};
|
||||
|
||||
struct codegen_var_map {
|
||||
b_hashmap *m_map;
|
||||
fx_hashmap *m_map;
|
||||
};
|
||||
|
||||
extern enum ivy_status codegen_var_map_init(struct codegen_var_map *map);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef IVY_LANG_AST_H_
|
||||
#define IVY_LANG_AST_H_
|
||||
|
||||
#include <blue/core/queue.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/operator.h>
|
||||
#include <ivy/lang/selector.h>
|
||||
#include <ivy/misc.h>
|
||||
@@ -11,7 +11,7 @@
|
||||
struct ivy_diag_ctx;
|
||||
struct ivy_token;
|
||||
struct ivy_parser;
|
||||
struct b_string;
|
||||
struct fx_string;
|
||||
|
||||
enum ivy_ast_node_type {
|
||||
IVY_AST_NONE = 0x00,
|
||||
@@ -69,12 +69,12 @@ enum ivy_ast_iteration_type {
|
||||
};
|
||||
|
||||
struct ivy_ast_node_iterator {
|
||||
b_queue it_queue;
|
||||
b_queue_entry *it_insert_after;
|
||||
fx_queue it_queue;
|
||||
fx_queue_entry *it_insert_after;
|
||||
};
|
||||
|
||||
struct ivy_ast_node_iterator_entry {
|
||||
b_queue_entry it_entry;
|
||||
fx_queue_entry it_entry;
|
||||
unsigned int it_depth;
|
||||
};
|
||||
|
||||
@@ -82,13 +82,13 @@ struct ivy_ast_node {
|
||||
enum ivy_ast_node_type n_type;
|
||||
struct ivy_ast_node *n_parent;
|
||||
struct ivy_char_cell n_start, n_end;
|
||||
b_queue_entry n_entry;
|
||||
fx_queue_entry n_entry;
|
||||
struct ivy_ast_node_iterator_entry n_it;
|
||||
};
|
||||
|
||||
struct ivy_ast_unit_node {
|
||||
struct ivy_ast_node n_base;
|
||||
b_queue n_children;
|
||||
fx_queue n_children;
|
||||
};
|
||||
|
||||
struct ivy_ast_op_node {
|
||||
@@ -116,9 +116,9 @@ struct ivy_ast_selector_node {
|
||||
/* NULL for keyword messages. */
|
||||
struct ivy_token *n_msg_name;
|
||||
/* queue of struct ivy_token; empty for unary messages. */
|
||||
b_queue n_arg_labels;
|
||||
fx_queue n_arg_labels;
|
||||
/* queue of struct ivy_token; empty for unary messages. */
|
||||
b_queue n_arg_names;
|
||||
fx_queue n_arg_names;
|
||||
};
|
||||
|
||||
struct ivy_ast_msg_node {
|
||||
@@ -126,7 +126,7 @@ struct ivy_ast_msg_node {
|
||||
struct ivy_ast_node *n_recipient;
|
||||
struct ivy_ast_selector_node *n_sel;
|
||||
/* queue of struct ivy_ast_node; empty for unary messages. */
|
||||
b_queue n_arg;
|
||||
fx_queue n_arg;
|
||||
};
|
||||
|
||||
struct ivy_ast_class_node {
|
||||
@@ -135,9 +135,9 @@ struct ivy_ast_class_node {
|
||||
struct ivy_token *n_ident;
|
||||
|
||||
/* queue of struct ivy_ast_property_node */
|
||||
b_queue n_properties;
|
||||
fx_queue n_properties;
|
||||
/* queue of struct ivy_ast_msgh_node */
|
||||
b_queue n_msg_handlers;
|
||||
fx_queue n_msg_handlers;
|
||||
};
|
||||
|
||||
struct ivy_ast_msgh_node {
|
||||
@@ -176,7 +176,7 @@ struct ivy_ast_lambda_node {
|
||||
struct ivy_ast_node n_base;
|
||||
/* queue of struct ivy_ast_ident_node; contains the names of the lambda
|
||||
* parameters. */
|
||||
b_queue n_arg;
|
||||
fx_queue n_arg;
|
||||
/* expressions to evaluate when lambda is executed. */
|
||||
struct ivy_ast_node *n_body;
|
||||
};
|
||||
@@ -184,13 +184,13 @@ struct ivy_ast_lambda_node {
|
||||
struct ivy_ast_unit_package_node {
|
||||
struct ivy_ast_node n_base;
|
||||
/* queue of struct ivy_token; list of multi-part identifier parts. */
|
||||
b_queue n_ident;
|
||||
fx_queue n_ident;
|
||||
};
|
||||
|
||||
struct ivy_ast_unit_import_node {
|
||||
struct ivy_ast_node n_base;
|
||||
/* queue of struct ivy_token; list of multi-part identifier parts. */
|
||||
b_queue n_ident;
|
||||
fx_queue n_ident;
|
||||
};
|
||||
|
||||
struct ivy_ast_expr_node {
|
||||
@@ -223,7 +223,7 @@ struct ivy_ast_string_node {
|
||||
struct ivy_ast_fstring_node {
|
||||
struct ivy_ast_node n_base;
|
||||
/* list of struct ivy_ast_node. nodes are evaluated and combined in-order into a string. */
|
||||
b_queue n_value;
|
||||
fx_queue n_value;
|
||||
};
|
||||
|
||||
struct ivy_ast_atom_node {
|
||||
@@ -266,13 +266,13 @@ struct ivy_ast_cascade_node {
|
||||
struct ivy_ast_node n_base;
|
||||
struct ivy_ast_node *n_recipient;
|
||||
/* queue of struct ivy_ast_msg_node, all with NULL recipients. */
|
||||
b_queue n_msg;
|
||||
fx_queue n_msg;
|
||||
};
|
||||
|
||||
struct ivy_ast_cond_group_node {
|
||||
struct ivy_ast_node n_base;
|
||||
/* queue of struct ivy_ast_cond_node. */
|
||||
b_queue n_branches;
|
||||
fx_queue n_branches;
|
||||
};
|
||||
|
||||
struct ivy_ast_try_catch_node {
|
||||
@@ -284,7 +284,7 @@ struct ivy_ast_try_catch_node {
|
||||
struct ivy_ast_try_node {
|
||||
struct ivy_ast_node n_base;
|
||||
struct ivy_ast_node *n_try;
|
||||
b_queue n_catch;
|
||||
fx_queue n_catch;
|
||||
struct ivy_ast_node *n_finally;
|
||||
};
|
||||
|
||||
@@ -293,7 +293,7 @@ struct ivy_ast_match_node {
|
||||
/* the match condition. the branch that matches this condition will be evaluated. */
|
||||
struct ivy_ast_node *n_cond;
|
||||
/* queue of struct ivy_ast_cond_node. */
|
||||
b_queue n_branches;
|
||||
fx_queue n_branches;
|
||||
};
|
||||
|
||||
struct ivy_ast_cond_node {
|
||||
@@ -309,7 +309,7 @@ struct ivy_ast_cond_node {
|
||||
struct ivy_ast_tuple_node {
|
||||
struct ivy_ast_node n_base;
|
||||
/* queue of struct ivy_ast_node. each can be either an identifier, a constant, or a tuple. */
|
||||
b_queue n_members;
|
||||
fx_queue n_members;
|
||||
};
|
||||
|
||||
struct ivy_ast_pkg_static_item_node {
|
||||
@@ -325,7 +325,7 @@ struct ivy_ast_pkg_static_item_node {
|
||||
struct ivy_ast_pkg_static_node {
|
||||
struct ivy_ast_node n_base;
|
||||
/* queue of struct ivy_ast_pkg_static_item_node */
|
||||
b_queue n_items;
|
||||
fx_queue n_items;
|
||||
};
|
||||
|
||||
struct ivy_ast_pkg_dynamic_node {
|
||||
@@ -339,7 +339,7 @@ struct ivy_ast_pkg_dynamic_node {
|
||||
struct ivy_ast_block_node {
|
||||
struct ivy_ast_node n_base;
|
||||
/* queue of struct ivy_ast_node. expressions to evaluate when the do node itself is evaluated. */
|
||||
b_queue n_expr;
|
||||
fx_queue n_expr;
|
||||
};
|
||||
|
||||
typedef enum ivy_status (*ivy_ast_node_iteration_callback)(
|
||||
@@ -365,7 +365,7 @@ IVY_API struct ivy_ast_node *ivy_ast_node_create(enum ivy_ast_node_type type);
|
||||
IVY_API enum ivy_status ivy_ast_node_iterate(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *it,
|
||||
ivy_ast_node_iteration_callback callback, void *arg);
|
||||
IVY_API void ivy_ast_node_to_string(struct ivy_ast_node *node, b_string *out);
|
||||
IVY_API void ivy_ast_node_to_string(struct ivy_ast_node *node, fx_string *out);
|
||||
IVY_API void ivy_ast_node_set_bounds_from_token(
|
||||
struct ivy_ast_node *parent, const struct ivy_token *tok);
|
||||
IVY_API void ivy_ast_node_extend_bounds(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef IVY_LANG_LEX_H_
|
||||
#define IVY_LANG_LEX_H_
|
||||
|
||||
#include <blue/core/queue.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <ivy/line-source.h>
|
||||
#include <ivy/misc.h>
|
||||
#include <ivy/status.h>
|
||||
@@ -123,7 +123,7 @@ struct ivy_token {
|
||||
|
||||
struct ivy_char_cell t_start, t_end;
|
||||
|
||||
b_queue_entry t_entry;
|
||||
fx_queue_entry t_entry;
|
||||
|
||||
union {
|
||||
enum ivy_keyword t_keyword;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "lex.h"
|
||||
|
||||
#include <blue/ds/number.h>
|
||||
#include <blue/term/print.h>
|
||||
#include <fx/ds/number.h>
|
||||
#include <fx/term/print.h>
|
||||
#include <ivy/lang/internal.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <stdio.h>
|
||||
@@ -12,23 +12,23 @@ static void print_symbol_node(struct ivy_lexer_symbol_node *node, int depth)
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
|
||||
b_printf("[cyan]%c[reset]", node->s_char);
|
||||
fx_printf("[cyan]%c[reset]", node->s_char);
|
||||
|
||||
if (node->s_def != NULL) {
|
||||
b_printf(
|
||||
fx_printf(
|
||||
" ([magenta]%s[reset])",
|
||||
ivy_symbol_to_string(node->s_def->id));
|
||||
}
|
||||
|
||||
b_printf("\n");
|
||||
fx_printf("\n");
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&node->s_children);
|
||||
fx_queue_entry *entry = fx_queue_first(&node->s_children);
|
||||
while (entry) {
|
||||
struct ivy_lexer_symbol_node *child
|
||||
= b_unbox(struct ivy_lexer_symbol_node, entry, s_entry);
|
||||
= fx_unbox(struct ivy_lexer_symbol_node, entry, s_entry);
|
||||
|
||||
print_symbol_node(child, depth + 1);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,14 +39,14 @@ void internal_lexer_print_symbol_tree(struct ivy_lexer *lex)
|
||||
|
||||
void internal_lexer_print_keyword_dict(struct ivy_lexer *lex)
|
||||
{
|
||||
b_iterator *it = b_iterator_begin(lex->lex_keywords);
|
||||
b_foreach_ptr(b_dict_item, item, it)
|
||||
fx_iterator *it = fx_iterator_begin(lex->lex_keywords);
|
||||
fx_foreach_ptr(fx_dict_item, item, it)
|
||||
{
|
||||
const b_string *kw_name = item->key;
|
||||
enum ivy_keyword kw_id = b_number_get_int(item->value);
|
||||
const fx_string *kw_name = item->key;
|
||||
enum ivy_keyword kw_id = fx_number_get_int(item->value);
|
||||
|
||||
b_printf(
|
||||
fx_printf(
|
||||
"([magenta]%s[reset]) = [green]%s[reset]\n",
|
||||
ivy_keyword_to_string(kw_id), b_string_ptr(kw_name));
|
||||
ivy_keyword_to_string(kw_id), fx_string_ptr(kw_name));
|
||||
}
|
||||
}
|
||||
|
||||
124
lang/lex.c
124
lang/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/diag.h>
|
||||
#include <ivy/lang/diag.h>
|
||||
@@ -163,40 +163,40 @@ static struct lexer_state *push_lexer_state(
|
||||
|
||||
state->s_type = state_type;
|
||||
state->s_brace_depth = lex->lex_brace_depth;
|
||||
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_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_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);
|
||||
|
||||
@@ -207,27 +207,27 @@ static void destroy_state_stack(b_queue *state)
|
||||
static struct ivy_lexer_symbol_node *get_symbol_node(
|
||||
struct ivy_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_lexer_symbol_node *child
|
||||
= b_unbox(struct ivy_lexer_symbol_node, entry, s_entry);
|
||||
= fx_unbox(struct ivy_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_lexer *lex)
|
||||
static fx_string *get_temp_string(struct ivy_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;
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ static enum ivy_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;
|
||||
}
|
||||
|
||||
@@ -262,12 +262,12 @@ static enum ivy_status put_symbol(
|
||||
|
||||
static void destroy_symbol_tree(struct ivy_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_lexer_symbol_node *node
|
||||
= b_unbox(struct ivy_lexer_symbol_node, entry, s_entry);
|
||||
b_queue_entry *next = b_queue_next(entry);
|
||||
b_queue_delete(&tree->s_children, entry);
|
||||
= fx_unbox(struct ivy_lexer_symbol_node, entry, s_entry);
|
||||
fx_queue_entry *next = fx_queue_next(entry);
|
||||
fx_queue_delete(&tree->s_children, entry);
|
||||
|
||||
destroy_symbol_tree(node);
|
||||
|
||||
@@ -300,22 +300,22 @@ static struct ivy_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_keyword find_keyword_by_name(struct ivy_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_KW_NONE;
|
||||
}
|
||||
|
||||
return b_number_get_int(id);
|
||||
return fx_number_get_int(id);
|
||||
}
|
||||
|
||||
enum ivy_status ivy_lexer_create(struct ivy_lexer **lexp)
|
||||
@@ -346,7 +346,7 @@ enum ivy_status ivy_lexer_create(struct ivy_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;
|
||||
|
||||
@@ -355,12 +355,12 @@ enum ivy_status ivy_lexer_create(struct ivy_lexer **lexp)
|
||||
|
||||
void ivy_lexer_destroy(struct ivy_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_token *tok = b_unbox(struct ivy_token, entry, t_entry);
|
||||
b_queue_entry *next = b_queue_next(entry);
|
||||
b_queue_delete(&lex->lex_queue, entry);
|
||||
struct ivy_token *tok = fx_unbox(struct ivy_token, entry, t_entry);
|
||||
fx_queue_entry *next = fx_queue_next(entry);
|
||||
fx_queue_delete(&lex->lex_queue, entry);
|
||||
|
||||
ivy_token_destroy(tok);
|
||||
|
||||
@@ -376,11 +376,11 @@ void ivy_lexer_destroy(struct ivy_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);
|
||||
@@ -546,7 +546,7 @@ static enum ivy_status push_token(struct ivy_lexer *lex, struct ivy_token *tok)
|
||||
tok->t_end.c_row = lex->lex_token_end_row;
|
||||
tok->t_end.c_col = lex->lex_token_end_col;
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -772,7 +772,7 @@ static enum ivy_status read_dquote_marker(struct ivy_lexer *lex)
|
||||
|
||||
static enum ivy_status read_atom(struct ivy_lexer *lex)
|
||||
{
|
||||
b_string *str = get_temp_string(lex);
|
||||
fx_string *str = get_temp_string(lex);
|
||||
|
||||
while (true) {
|
||||
int c = peek(lex);
|
||||
@@ -790,24 +790,24 @@ static enum ivy_status read_atom(struct ivy_lexer *lex)
|
||||
}
|
||||
|
||||
char s[] = {c, 0};
|
||||
b_string_append_cstr(str, s);
|
||||
fx_string_append_cstr(str, s);
|
||||
set_token_end(lex);
|
||||
advance(lex);
|
||||
}
|
||||
|
||||
if (b_string_get_size(str, B_STRLEN_NORMAL) == 0) {
|
||||
if (fx_string_get_size(str, FX_STRLEN_NORMAL) == 0) {
|
||||
/* TODO report empty atom error */
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
char *s = b_string_steal(str);
|
||||
char *s = fx_string_steal(str);
|
||||
return push_atom(lex, s);
|
||||
}
|
||||
|
||||
static enum ivy_status read_string_content(struct ivy_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) {
|
||||
@@ -830,16 +830,16 @@ static enum ivy_status read_string_content(struct ivy_lexer *lex)
|
||||
}
|
||||
|
||||
char s[2] = {c, 0};
|
||||
b_string_append_cstr(str, s);
|
||||
fx_string_append_cstr(str, s);
|
||||
set_token_end(lex);
|
||||
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) {
|
||||
@@ -854,7 +854,7 @@ static enum ivy_status read_number(struct ivy_lexer *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);
|
||||
@@ -889,7 +889,7 @@ static enum ivy_status read_number(struct ivy_lexer *lex, bool negate)
|
||||
token_len++;
|
||||
dots++;
|
||||
char s[] = {c, 0};
|
||||
b_string_append_cstr(str, s);
|
||||
fx_string_append_cstr(str, s);
|
||||
set_token_end(lex);
|
||||
advance(lex);
|
||||
continue;
|
||||
@@ -936,7 +936,7 @@ static enum ivy_status read_number(struct ivy_lexer *lex, bool negate)
|
||||
}
|
||||
|
||||
char s[] = {c, 0};
|
||||
b_string_append_cstr(str, s);
|
||||
fx_string_append_cstr(str, s);
|
||||
set_token_end(lex);
|
||||
advance(lex);
|
||||
token_len++;
|
||||
@@ -946,7 +946,7 @@ static enum ivy_status read_number(struct ivy_lexer *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
|
||||
@@ -1057,7 +1057,7 @@ static enum ivy_status read_symbol(struct ivy_lexer *lex)
|
||||
|
||||
static enum ivy_status read_ident(struct ivy_lexer *lex)
|
||||
{
|
||||
b_string *str = get_temp_string(lex);
|
||||
fx_string *str = get_temp_string(lex);
|
||||
bool label = false;
|
||||
set_token_start(lex);
|
||||
char prev = 0;
|
||||
@@ -1085,13 +1085,13 @@ static enum ivy_status read_ident(struct ivy_lexer *lex)
|
||||
}
|
||||
|
||||
char s[2] = {c, 0};
|
||||
b_string_append_cstr(str, s);
|
||||
fx_string_append_cstr(str, s);
|
||||
set_token_end(lex);
|
||||
advance(lex);
|
||||
prev = c;
|
||||
}
|
||||
|
||||
const char *s = b_string_ptr(str);
|
||||
const char *s = fx_string_ptr(str);
|
||||
if (!label && !strcmp(s, "_")) {
|
||||
return push_symbol(lex, IVY_SYM_UNDERSCORE);
|
||||
}
|
||||
@@ -1103,7 +1103,7 @@ static enum ivy_status read_ident(struct ivy_lexer *lex)
|
||||
|
||||
struct ivy_token *tok
|
||||
= create_token(label ? IVY_TOK_LABEL : IVY_TOK_IDENT);
|
||||
tok->t_str = b_string_steal(str);
|
||||
tok->t_str = fx_string_steal(str);
|
||||
|
||||
return push_token(lex, tok);
|
||||
}
|
||||
@@ -1177,7 +1177,7 @@ struct ivy_token *ivy_lexer_peek(struct ivy_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) {
|
||||
@@ -1188,8 +1188,8 @@ struct ivy_token *ivy_lexer_peek(struct ivy_lexer *lex)
|
||||
|
||||
lex->lex_status = status;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&lex->lex_queue);
|
||||
struct ivy_token *tok = b_unbox(struct ivy_token, entry, t_entry);
|
||||
fx_queue_entry *entry = fx_queue_first(&lex->lex_queue);
|
||||
struct ivy_token *tok = fx_unbox(struct ivy_token, entry, t_entry);
|
||||
return tok;
|
||||
}
|
||||
|
||||
@@ -1197,7 +1197,7 @@ struct ivy_token *ivy_lexer_read(struct ivy_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) {
|
||||
@@ -1206,14 +1206,14 @@ struct ivy_token *ivy_lexer_read(struct ivy_lexer *lex)
|
||||
}
|
||||
}
|
||||
|
||||
b_queue_entry *entry = b_queue_pop_front(&lex->lex_queue);
|
||||
struct ivy_token *tok = b_unbox(struct ivy_token, entry, t_entry);
|
||||
fx_queue_entry *entry = fx_queue_pop_front(&lex->lex_queue);
|
||||
struct ivy_token *tok = fx_unbox(struct ivy_token, entry, t_entry);
|
||||
return tok;
|
||||
}
|
||||
|
||||
bool ivy_lexer_tokens_available(struct ivy_lexer *lex)
|
||||
{
|
||||
if (!b_queue_empty(&lex->lex_queue)) {
|
||||
if (!fx_queue_empty(&lex->lex_queue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1235,7 +1235,7 @@ struct ivy_token *ivy_token_create_ident(const char *s)
|
||||
memset(tok, 0x0, sizeof *tok);
|
||||
|
||||
tok->t_type = IVY_TOK_IDENT;
|
||||
tok->t_str = b_strdup(s);
|
||||
tok->t_str = fx_strdup(s);
|
||||
|
||||
if (!tok->t_str) {
|
||||
free(tok);
|
||||
|
||||
20
lang/lex.h
20
lang/lex.h
@@ -1,9 +1,9 @@
|
||||
#ifndef _LEX_H_
|
||||
#define _LEX_H_
|
||||
|
||||
#include <blue/core/queue.h>
|
||||
#include <blue/ds/dict.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/ds/dict.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <ivy/status.h>
|
||||
#include <stdint.h>
|
||||
@@ -16,15 +16,15 @@ struct ivy_lexer {
|
||||
struct ivy_lexer_symbol_node *lex_sym_tree;
|
||||
struct ivy_diag_ctx *lex_diag_ctx;
|
||||
struct ivy_line_source *lex_source;
|
||||
b_dict *lex_keywords;
|
||||
fx_dict *lex_keywords;
|
||||
enum ivy_status lex_status;
|
||||
int lex_prev_char, lex_cur_char;
|
||||
|
||||
b_queue lex_queue;
|
||||
fx_queue lex_queue;
|
||||
enum ivy_token_type lex_prev_token;
|
||||
|
||||
b_string *lex_temp;
|
||||
b_queue lex_state;
|
||||
fx_string *lex_temp;
|
||||
fx_queue lex_state;
|
||||
unsigned int lex_brace_depth;
|
||||
|
||||
unsigned long lex_token_start_row, lex_token_start_col;
|
||||
@@ -47,15 +47,15 @@ enum lexer_state_type {
|
||||
struct lexer_state {
|
||||
enum lexer_state_type s_type;
|
||||
unsigned int s_brace_depth;
|
||||
b_queue_entry s_entry;
|
||||
fx_queue_entry s_entry;
|
||||
};
|
||||
|
||||
struct ivy_lexer_symbol_node {
|
||||
char s_char;
|
||||
struct lex_token_def *s_def;
|
||||
|
||||
b_queue_entry s_entry;
|
||||
b_queue s_children;
|
||||
fx_queue_entry s_entry;
|
||||
fx_queue s_children;
|
||||
};
|
||||
|
||||
struct lex_token_def {
|
||||
|
||||
Reference in New Issue
Block a user