lang: update bluelib api usage

This commit is contained in:
2025-11-06 10:38:32 +00:00
parent b26c37c349
commit 4386965cd9
40 changed files with 351 additions and 271 deletions

View File

@@ -55,12 +55,12 @@ static enum ivy_status get_eval_type(
{
struct mie_type *type = NULL;
b_queue_iterator it;
b_queue_foreach (&it, &state->s_edges) {
b_queue_entry *entry = b_queue_first(&state->s_edges);
while (entry) {
struct mie_phi_edge *edge
= b_unbox(struct mie_phi_edge, it.entry, e_entry);
= b_unbox(struct mie_phi_edge, entry, e_entry);
if (!edge->e_value) {
continue;
goto next;
}
struct mie_type *edge_type
@@ -68,8 +68,10 @@ static enum ivy_status get_eval_type(
if (!type) {
type = edge_type;
continue;
}
next:
entry = b_queue_next(entry);
}
*out = type;
@@ -92,13 +94,14 @@ static enum ivy_status emit_phi_instr(
size_t i = 0;
b_queue_iterator it;
b_queue_foreach (&it, &state->s_edges) {
b_queue_entry *entry = b_queue_first(&state->s_edges);
while (entry) {
struct mie_phi_edge *edge
= b_unbox(struct mie_phi_edge, it.entry, e_entry);
= b_unbox(struct mie_phi_edge, entry, e_entry);
memcpy(&edges[i], edge, sizeof *edge);
i++;
entry = b_queue_next(entry);
}
struct mie_value *phi = mie_builder_phi(

View File

@@ -128,35 +128,36 @@ static enum ivy_status state_init(
static void serialise_selector(
struct ivy_ast_selector_node *sel, b_stringstream *out)
{
b_stringstream_add(out, "_M");
b_stream_write_string(out, "_M", NULL);
if (sel->n_msg_name) {
const char *msg_name = sel->n_msg_name->t_str;
b_stringstream_addf(out, "%zu%s", strlen(msg_name), msg_name);
b_stream_write_fmt(out, NULL, "%zu%s", strlen(msg_name), msg_name);
} else {
b_stringstream_add(out, "0");
b_stream_write_char(out, '0');
}
b_queue_iterator it;
b_queue_foreach (&it, &sel->n_arg_labels) {
struct ivy_token *arg
= b_unbox(struct ivy_token, it.entry, t_entry);
b_queue_entry *entry = b_queue_first(&sel->n_arg_labels);
while (entry) {
struct ivy_token *arg = b_unbox(struct ivy_token, entry, t_entry);
if (arg->t_type != IVY_TOK_IDENT && arg->t_type != IVY_TOK_LABEL) {
b_stringstream_addf(out, "0");
continue;
b_stream_write_char(out, '0');
goto next;
}
const char *label = arg->t_str;
if (label) {
b_stringstream_addf(out, "%zu%s", strlen(label), label);
b_stream_write_fmt(out, NULL, "%zu%s", strlen(label), label);
} else {
b_stringstream_addf(out, "0");
b_stream_write_char(out, '0');
}
next:
entry = b_queue_next(entry);
}
b_stringstream_add(out, "E");
b_stream_write_char(out, 'E');
}
static enum ivy_status state_fini(
@@ -167,10 +168,11 @@ static enum ivy_status state_fini(
struct msg_codegen_state *msg = (struct msg_codegen_state *)state;
b_stringstream str;
b_stringstream_begin_dynamic(&str);
serialise_selector(msg->s_selector, &str);
char *sel = b_stringstream_end(&str);
b_stringstream *str = b_stringstream_create();
serialise_selector(msg->s_selector, str);
char *sel = b_stringstream_steal(str);
b_stringstream_unref(str);
struct mie_value *sel_value = mie_ctx_get_selector(gen->c_ctx, sel);
free(sel);

View File

@@ -2,7 +2,7 @@
#include "var-map.h"
#include <blue/core/stringstream.h>
#include <blue/object/list.h>
#include <blue/ds/list.h>
#include <mie/ir/block.h>
#include <mie/ir/func.h>
#include <mie/ir/module.h>
@@ -144,17 +144,17 @@ static struct code_generator_result gen_while_loop(
static void serialise_package_name(b_queue *parts, b_stringstream *out)
{
b_stringstream_add(out, "_ZN");
b_stream_write_string(out, "_ZN", NULL);
b_queue_iterator it;
b_queue_foreach (&it, parts) {
struct ivy_token *tok
= b_unbox(struct ivy_token, it.entry, t_entry);
b_queue_entry *entry = b_queue_first(parts);
while (entry) {
struct ivy_token *tok = b_unbox(struct ivy_token, entry, t_entry);
size_t len = strlen(tok->t_str);
b_stringstream_addf(out, "%zu%s", len, tok->t_str);
b_stream_write_fmt(out, NULL, "%zu%s", len, tok->t_str);
entry = b_queue_next(entry);
}
b_stringstream_add(out, "E");
b_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_begin_dynamic(&str);
serialise_package_name(&pkg->n_ident, &str);
char *ident = b_stringstream_end(&str);
b_stringstream *str = b_stringstream_create();
serialise_package_name(&pkg->n_ident, str);
char *ident = b_stringstream_steal(str);
b_stringstream_unref(str);
struct mie_value *ident_val = mie_ctx_get_string(gen->c_ctx, ident);
free(ident);
@@ -198,10 +198,10 @@ static struct code_generator_result gen_unit_import(
import_list = MIE_ARRAY(rec->r_value);
}
b_stringstream str;
b_stringstream_begin_dynamic(&str);
serialise_package_name(&pkg->n_ident, &str);
char *ident = b_stringstream_end(&str);
b_stringstream *str = b_stringstream_create();
serialise_package_name(&pkg->n_ident, str);
char *ident = b_stringstream_steal(str);
b_stringstream_unref(str);
struct mie_value *ident_val = mie_ctx_get_string(gen->c_ctx, ident);
free(ident);

View File

@@ -1,7 +1,7 @@
#include "var-map.h"
#include <blue/object/hashmap.h>
#include <blue/object/string.h>
#include <blue/ds/hashmap.h>
#include <blue/ds/string.h>
#include <stdlib.h>
#include <string.h>
@@ -15,7 +15,7 @@ enum ivy_status codegen_var_map_init(struct codegen_var_map *map)
enum ivy_status codegen_var_map_fini(struct codegen_var_map *map)
{
b_hashmap_release(map->m_map);
b_hashmap_unref(map->m_map);
return IVY_OK;
}

View File

@@ -1,9 +1,9 @@
#ifndef CODEGEN_VAR_MAP_H_
#define CODEGEN_VAR_MAP_H_
#include <blue/ds/hashmap.h>
#include <ivy/status.h>
struct b_hashmap;
struct mie_value;
struct ivy_ast_node;
@@ -20,7 +20,7 @@ struct codegen_var {
};
struct codegen_var_map {
struct b_hashmap *m_map;
b_hashmap *m_map;
};
extern enum ivy_status codegen_var_map_init(struct codegen_var_map *map);