frontend: update bluelib api usage

This commit is contained in:
2025-11-06 10:39:08 +00:00
parent 9622e30e0f
commit 24eef25147
10 changed files with 50 additions and 39 deletions

View File

@@ -21,7 +21,7 @@ target_link_libraries(
ivy-lang ivy-lang
ivy-common ivy-common
Bluelib::Core Bluelib::Core
Bluelib::Object Bluelib::Ds
Bluelib::Cmd) Bluelib::Cmd)
target_compile_definitions(ivy PRIVATE IVY_STATIC=${IVY_STATIC}) target_compile_definitions(ivy PRIVATE IVY_STATIC=${IVY_STATIC})

View File

@@ -2,7 +2,7 @@
#include "cmd.h" #include "cmd.h"
#include <blue/cmd.h> #include <blue/cmd.h>
#include <blue/object/string.h> #include <blue/ds/string.h>
#include <blue/term.h> #include <blue/term.h>
#include <errno.h> #include <errno.h>
#include <ivy/asm/assembler.h> #include <ivy/asm/assembler.h>
@@ -127,7 +127,7 @@ static b_string *get_source_filename(const char *src_path)
} }
if (b_string_get_size(name, B_STRLEN_NORMAL) == 0) { if (b_string_get_size(name, B_STRLEN_NORMAL) == 0) {
b_string_release(name); b_string_unref(name);
name = NULL; name = NULL;
} }
@@ -184,8 +184,8 @@ static int assemble(const b_command *cmd, const b_arglist *args, const b_array *
int r = assemble_file(in_path, out_path); int r = assemble_file(in_path, out_path);
b_string_release(in_name); b_string_unref(in_name);
b_string_release(out_name); b_string_unref(out_name);
return r; return r;
#if 0 #if 0

View File

@@ -229,19 +229,22 @@ static b_result generate_mie_ir(struct compile_ctx *ctx)
static b_result build_block_isel_graph( static b_result build_block_isel_graph(
struct compile_ctx *ctx, struct mie_func *func, struct mie_block *block) struct compile_ctx *ctx, struct mie_func *func, struct mie_block *block)
{ {
b_queue_iterator instr_it; b_queue_entry *entry = b_queue_first(&block->b_phi);
b_queue_foreach (&instr_it, &block->b_phi) { while (entry) {
struct mie_value *instr_v struct mie_value *instr_v
= b_unbox(struct mie_value, instr_it.entry, v_entry); = b_unbox(struct mie_value, entry, v_entry);
mie_select_builder_push_instr( mie_select_builder_push_instr(
ctx->select, (struct mie_instr *)instr_v); ctx->select, (struct mie_instr *)instr_v);
entry = b_queue_next(entry);
} }
b_queue_foreach (&instr_it, &block->b_instr) { entry = b_queue_first(&block->b_instr);
while (entry) {
struct mie_value *instr_v struct mie_value *instr_v
= b_unbox(struct mie_value, instr_it.entry, v_entry); = b_unbox(struct mie_value, entry, v_entry);
mie_select_builder_push_instr( mie_select_builder_push_instr(
ctx->select, (struct mie_instr *)instr_v); ctx->select, (struct mie_instr *)instr_v);
entry = b_queue_next(entry);
} }
if (block->b_terminator) { if (block->b_terminator) {
@@ -262,16 +265,18 @@ static b_result build_block_isel_graph(
static b_result build_func_isel_graph(struct compile_ctx *ctx, struct mie_func *func) static b_result build_func_isel_graph(struct compile_ctx *ctx, struct mie_func *func)
{ {
b_queue_iterator it; b_queue_entry *entry = b_queue_first(&func->f_blocks);
b_queue_foreach (&it, &func->f_blocks) { while (entry) {
struct mie_value *block_v struct mie_value *block_v
= b_unbox(struct mie_value, it.entry, v_entry); = b_unbox(struct mie_value, entry, v_entry);
struct mie_block *block = (struct mie_block *)block_v; struct mie_block *block = (struct mie_block *)block_v;
b_result result = build_block_isel_graph(ctx, func, block); b_result result = build_block_isel_graph(ctx, func, block);
if (b_result_is_error(result)) { if (b_result_is_error(result)) {
return b_result_propagate(result); return b_result_propagate(result);
} }
entry = b_queue_next(entry);
} }
return B_RESULT_SUCCESS; return B_RESULT_SUCCESS;
@@ -279,17 +284,18 @@ static b_result build_func_isel_graph(struct compile_ctx *ctx, struct mie_func *
static b_result build_isel_graph(struct compile_ctx *ctx) static b_result build_isel_graph(struct compile_ctx *ctx)
{ {
b_queue_iterator it; b_queue_entry *entry = b_queue_first(&ctx->mod->m_func);
while (entry) {
b_queue_foreach (&it, &ctx->mod->m_func) {
struct mie_value *func_v struct mie_value *func_v
= b_unbox(struct mie_value, it.entry, v_entry); = b_unbox(struct mie_value, entry, v_entry);
struct mie_func *func = (struct mie_func *)func_v; struct mie_func *func = (struct mie_func *)func_v;
b_result result = build_func_isel_graph(ctx, func); b_result result = build_func_isel_graph(ctx, func);
if (b_result_is_error(result)) { if (b_result_is_error(result)) {
return b_result_propagate(result); return b_result_propagate(result);
} }
entry = b_queue_next(entry);
} }
return B_RESULT_SUCCESS; return B_RESULT_SUCCESS;

View File

@@ -1,7 +1,7 @@
#include "cmd.h" #include "cmd.h"
#include <blue/cmd.h> #include <blue/cmd.h>
#include <blue/object/string.h> #include <blue/ds/string.h>
#include <blue/term.h> #include <blue/term.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>

View File

@@ -1,6 +1,6 @@
#include "debug.h" #include "debug.h"
#include <blue/object/string.h> #include <blue/ds/string.h>
#include <blue/term.h> #include <blue/term.h>
#include <ivy/asm/lex.h> #include <ivy/asm/lex.h>
#include <ivy/lang/ast.h> #include <ivy/lang/ast.h>
@@ -212,7 +212,7 @@ extern enum ivy_status print_ast_node(
b_string *str = b_string_create(); b_string *str = b_string_create();
ivy_ast_node_to_string(node, str); ivy_ast_node_to_string(node, str);
b_printf("%s", b_string_ptr(str)); b_printf("%s", b_string_ptr(str));
b_string_release(str); b_string_unref(str);
#if 0 #if 0
b_puts(ivy_ast_node_type_to_string(node->n_type)); b_puts(ivy_ast_node_type_to_string(node->n_type));

View File

@@ -1,7 +1,7 @@
#include "line-ed.h" #include "line-ed.h"
#include <blue/object/array.h> #include <blue/ds/array.h>
#include <blue/object/string.h> #include <blue/ds/string.h>
void alloc_empty_history_entry(struct line_ed *ed) void alloc_empty_history_entry(struct line_ed *ed)
{ {

View File

@@ -36,16 +36,16 @@ struct hl_range *get_hl_range(struct line_ed *ed, size_t x, size_t y)
struct hl_range *best_match = NULL; struct hl_range *best_match = NULL;
b_queue_iterator it; b_queue_entry *entry = b_queue_first(&ed->l_hl_ranges);
b_queue_foreach (&it, &ed->l_hl_ranges) { while (entry) {
struct hl_range *cur = b_unbox(struct hl_range, it.entry, h_entry); struct hl_range *cur = b_unbox(struct hl_range, entry, h_entry);
int cmp_end = compare_coords(x, y, cur->h_end_x, cur->h_end_y); int cmp_end = compare_coords(x, y, cur->h_end_x, cur->h_end_y);
if (cmp_end == 1) { if (cmp_end != 1) {
continue; return cur;
} }
return cur; entry = b_queue_next(entry);
} }
return NULL; return NULL;
@@ -276,10 +276,11 @@ void line_ed_clear_highlights(struct line_ed *ed)
void line_ed_print_highlights(struct line_ed *ed) void line_ed_print_highlights(struct line_ed *ed)
{ {
b_queue_iterator it; b_queue_entry *entry = b_queue_first(&ed->l_hl_ranges);
b_queue_foreach (&it, &ed->l_hl_ranges) { while (entry) {
struct hl_range *h = b_unbox(struct hl_range, it.entry, h_entry); struct hl_range *h = b_unbox(struct hl_range, entry, h_entry);
printf("(%zu, %zu) -> (%zu, %zu)\n", h->h_start_x, h->h_start_y, printf("(%zu, %zu) -> (%zu, %zu)\n", h->h_start_x, h->h_start_y,
h->h_end_x, h->h_end_y); h->h_end_x, h->h_end_y);
entry = b_queue_next(entry);
} }
} }

View File

@@ -14,24 +14,28 @@ void line_ed_remove_hook(struct line_ed *ed, struct line_ed_hook *hook)
void hook_keypress(struct line_ed *ed, b_keycode key) void hook_keypress(struct line_ed *ed, b_keycode key)
{ {
b_queue_iterator it; b_queue_entry *entry = b_queue_first(&ed->l_hooks);
b_queue_foreach (&it, &ed->l_hooks) { while (entry) {
struct line_ed_hook *hook struct line_ed_hook *hook
= b_unbox(struct line_ed_hook, it.entry, hook_entry); = b_unbox(struct line_ed_hook, entry, hook_entry);
if (hook->hook_keypress) { if (hook->hook_keypress) {
hook->hook_keypress(ed, hook, key); hook->hook_keypress(ed, hook, key);
} }
entry = b_queue_next(entry);
} }
} }
void hook_buffer_modified(struct line_ed *ed) void hook_buffer_modified(struct line_ed *ed)
{ {
b_queue_iterator it; b_queue_entry *entry = b_queue_first(&ed->l_hooks);
b_queue_foreach (&it, &ed->l_hooks) { while (entry) {
struct line_ed_hook *hook struct line_ed_hook *hook
= b_unbox(struct line_ed_hook, it.entry, hook_entry); = b_unbox(struct line_ed_hook, entry, hook_entry);
if (hook->hook_buffer_modified) { if (hook->hook_buffer_modified) {
hook->hook_buffer_modified(ed, hook); hook->hook_buffer_modified(ed, hook);
} }
entry = b_queue_next(entry);
} }
} }

View File

@@ -71,7 +71,7 @@ struct line_ed *line_ed_create(void)
void line_ed_destroy(struct line_ed *ed) void line_ed_destroy(struct line_ed *ed)
{ {
b_array_release(ed->l_history); b_array_unref(ed->l_history);
line_ed_clear_highlights(ed); line_ed_clear_highlights(ed);
free(ed->l_buf); free(ed->l_buf);
free(ed); free(ed);

View File

@@ -5,7 +5,7 @@
#include <blue/term/tty.h> #include <blue/term/tty.h>
#include <blue/core/queue.h> #include <blue/core/queue.h>
#include <blue/object/array.h> #include <blue/ds/array.h>
#include <ivy/line-source.h> #include <ivy/line-source.h>
#include <stddef.h> #include <stddef.h>