meta: replace bluelib with fx

This commit is contained in:
2026-03-16 14:07:33 +00:00
parent d2abb6faa3
commit e5546f97c2
105 changed files with 1668 additions and 1668 deletions

View File

@@ -1,6 +1,6 @@
#include "assembler.h"
#include <blue/core/queue.h>
#include <fx/core/queue.h>
#include <ivy/asm/assembler.h>
#include <ivy/asm/bin.h>
#include <stdio.h>
@@ -19,13 +19,13 @@ static const struct assembler_scope_type *scope_types[] = {
static const size_t nr_scope_types = sizeof scope_types / sizeof scope_types[0];
struct asm_table_entry {
b_queue_entry e_entry;
fx_queue_entry e_entry;
struct ivy_bin_table_entry e_data;
};
struct ivy_assembler {
struct assembler_scope *as_scope;
b_queue as_table;
fx_queue as_table;
FILE *as_data;
size_t as_data_offset;
@@ -48,7 +48,7 @@ enum ivy_status ivy_assembler_create(FILE *fp, struct ivy_assembler **as)
out->as_xdat = tmpfile();
struct ivy_bin_header header = {0};
header.h_magic = b_i32_htob(0xAABBCCDD);
header.h_magic = fx_i32_htob(0xAABBCCDD);
fseek(fp, 0, SEEK_SET);
fwrite(&header, sizeof header, 1, fp);
@@ -86,9 +86,9 @@ enum ivy_status ivy_assembler_finish(struct ivy_assembler *as)
pad(as, 16);
struct ivy_bin_table_entry xdat = {0};
xdat.e_offset = b_i64_htob(as->as_data_offset);
xdat.e_size = b_i32_htob((uint32_t)xdat_len);
xdat.e_type = b_i32_htob(IVY_TABLE_XDAT);
xdat.e_offset = fx_i64_htob(as->as_data_offset);
xdat.e_size = fx_i32_htob((uint32_t)xdat_len);
xdat.e_type = fx_i32_htob(IVY_TABLE_XDAT);
while (1) {
size_t r = fread(buf, 1, buf_len, as->as_xdat);
@@ -114,14 +114,14 @@ enum ivy_status ivy_assembler_finish(struct ivy_assembler *as)
pad(as, 16);
struct ivy_bin_header header = {0};
header.h_table_offset = b_i64_htob(as->as_data_offset);
header.h_table_len = b_i16_htob(0);
header.h_magic = b_i32_htob(IVY_BIN_MAGIC);
header.h_table_offset = fx_i64_htob(as->as_data_offset);
header.h_table_len = fx_i16_htob(0);
header.h_magic = fx_i32_htob(IVY_BIN_MAGIC);
b_queue_entry *entry = b_queue_first(&as->as_table);
fx_queue_entry *entry = fx_queue_first(&as->as_table);
while (entry) {
struct asm_table_entry *e
= b_unbox(struct asm_table_entry, entry, e_entry);
= fx_unbox(struct asm_table_entry, entry, e_entry);
size_t w = fwrite(&e->e_data, 1, sizeof e->e_data, as->as_data);
if (w < sizeof e->e_data) {
@@ -129,13 +129,13 @@ enum ivy_status ivy_assembler_finish(struct ivy_assembler *as)
}
nr_table_entries++;
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
fwrite(&xdat, 1, sizeof xdat, as->as_data);
nr_table_entries++;
header.h_table_len = b_i16_htob(nr_table_entries);
header.h_table_len = fx_i16_htob(nr_table_entries);
fseek(as->as_data, 0, SEEK_SET);
fwrite(&header, 1, sizeof header, as->as_data);
@@ -257,28 +257,28 @@ enum ivy_status ivy_assembler_end_scope(struct ivy_assembler *as)
memset(entry, 0x0, sizeof *entry);
entry->e_data.e_offset
= b_i64_htob((uint64_t)as->as_scope->s_start_offset);
entry->e_data.e_size = b_i32_htob(
= fx_i64_htob((uint64_t)as->as_scope->s_start_offset);
entry->e_data.e_size = fx_i32_htob(
(uint32_t)(as->as_data_offset - as->as_scope->s_start_offset));
switch (as->as_scope->s_type) {
case IVY_ASM_SCOPE_CLASS:
entry->e_data.e_type = b_i32_htob(IVY_TABLE_CLASS);
entry->e_data.e_type = fx_i32_htob(IVY_TABLE_CLASS);
break;
case IVY_ASM_SCOPE_BLOCK:
entry->e_data.e_type = b_i32_htob(IVY_TABLE_BLOCK);
entry->e_data.e_type = fx_i32_htob(IVY_TABLE_BLOCK);
break;
case IVY_ASM_SCOPE_CONSTPOOL:
entry->e_data.e_type = b_i32_htob(IVY_TABLE_POOL);
entry->e_data.e_type = fx_i32_htob(IVY_TABLE_POOL);
break;
case IVY_ASM_SCOPE_IMPORT:
entry->e_data.e_type = b_i32_htob(IVY_TABLE_IMPORT);
entry->e_data.e_type = fx_i32_htob(IVY_TABLE_IMPORT);
break;
default:
break;
}
b_queue_push_back(&as->as_table, &entry->e_entry);
fx_queue_push_back(&as->as_table, &entry->e_entry);
free(as->as_scope);
as->as_scope = NULL;

View File

@@ -1,9 +1,9 @@
#include "assembler.h"
#include <blue/core/hash.h>
#include <blue/ds/hashmap.h>
#include <blue/ds/number.h>
#include <blue/ds/string.h>
#include <fx/core/hash.h>
#include <fx/ds/hashmap.h>
#include <fx/ds/number.h>
#include <fx/ds/string.h>
#include <ivy/asm/bin.h>
#include <ivy/asm/instr.h>
#include <ivy/asm/lex.h>
@@ -19,15 +19,15 @@ enum label_state {
struct label {
enum label_state l_state;
b_queue_entry l_entry;
fx_queue_entry l_entry;
const struct ivy_asm_token *l_name;
size_t l_offset;
};
struct block_assembler_scope {
struct assembler_scope s_base;
b_hashmap *s_labels;
b_queue s_label_refs;
fx_hashmap *s_labels;
fx_queue s_label_refs;
size_t s_text_start;
};
@@ -57,10 +57,10 @@ static enum ivy_status init_scope(
struct ivy_bin_block header = {0};
struct block_assembler_scope *c = (struct block_assembler_scope *)scope;
c->s_labels = b_hashmap_create(NULL, NULL);
c->s_labels = fx_hashmap_create(NULL, NULL);
c->s_text_start = ivy_assembler_get_ptr(as);
header.b_index = b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_INDEX]);
header.b_index = fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_INDEX]);
assembler_write_data(as, &header, sizeof header);
return IVY_OK;
@@ -68,12 +68,12 @@ static enum ivy_status init_scope(
static struct label *get_label(struct block_assembler_scope *scope, const char *name)
{
b_hashmap_key key = {
fx_hashmap_key key = {
.key_data = name,
.key_size = strlen(name),
};
const b_hashmap_value *v = b_hashmap_get(scope->s_labels, &key);
const fx_hashmap_value *v = fx_hashmap_get(scope->s_labels, &key);
if (!v) {
return NULL;
}
@@ -88,9 +88,9 @@ static enum ivy_status resolve_label_refs(
enum ivy_status status = IVY_OK;
size_t nr_read = 0;
b_queue_entry *entry = b_queue_first(&c->s_label_refs);
fx_queue_entry *entry = fx_queue_first(&c->s_label_refs);
while (entry) {
struct label *label_ref = b_unbox(struct label, entry, l_entry);
struct label *label_ref = fx_unbox(struct label, entry, l_entry);
struct label *label_dest = get_label(c, label_ref->l_name->t_str);
if (!label_dest) {
@@ -99,7 +99,7 @@ static enum ivy_status resolve_label_refs(
return IVY_ERR_NO_ENTRY;
}
b_i32 x;
fx_i32 x;
status = assembler_read_data_at(
as, &x, label_ref->l_offset, sizeof x, &nr_read);
@@ -109,12 +109,12 @@ static enum ivy_status resolve_label_refs(
return IVY_ERR_IO_FAILURE;
}
uint32_t instr = b_i32_btoh(x);
uint32_t instr = fx_i32_btoh(x);
instr = R_SET_D3(instr, label_dest->l_offset);
x = b_i32_htob(instr);
x = fx_i32_htob(instr);
assembler_write_data_at(as, &x, label_ref->l_offset, sizeof x);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
return status;
@@ -164,7 +164,7 @@ static enum ivy_status put_instr(
return IVY_ERR_INTERNAL_FAILURE;
}
b_i32 x = b_i32_htob(v);
fx_i32 x = fx_i32_htob(v);
assembler_write_data(as, &x, sizeof x);
return IVY_OK;
}
@@ -179,21 +179,21 @@ static enum ivy_status put_label(
label->l_name = label_name;
label->l_offset = label_offset - c->s_text_start;
b_hashmap_key key = {
fx_hashmap_key key = {
.key_data = label_name->t_str,
.key_size = strlen(label_name->t_str),
};
b_hashmap_value value = {
fx_hashmap_value value = {
.value_data = label,
.value_size = sizeof *label,
};
if (b_hashmap_get(c->s_labels, &key)) {
if (fx_hashmap_get(c->s_labels, &key)) {
return IVY_ERR_NAME_EXISTS;
}
b_status status = b_hashmap_put(c->s_labels, &key, &value);
fx_status status = fx_hashmap_put(c->s_labels, &key, &value);
return ivy_status_from_b_status(status);
}
@@ -208,7 +208,7 @@ static enum ivy_status put_label_ref(
label->l_name = label_name;
label->l_offset = ref_offset;
b_queue_push_back(&c->s_label_refs, &label->l_entry);
fx_queue_push_back(&c->s_label_refs, &label->l_entry);
return IVY_OK;
}

View File

@@ -8,7 +8,7 @@ static enum ivy_status init_scope(
{
struct ivy_bin_class header = {0};
header.c_ident = b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
header.c_ident = fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
assembler_write_data(as, &header, sizeof header);
@@ -22,27 +22,27 @@ static enum ivy_status put_xval(
struct ivy_bin_class_table_entry entry = {0};
switch (type) {
case IVY_ASM_XVAL_PROPERTY:
entry.e_type = b_i32_htob(IVY_CLASS_TABLE_PROP);
entry.e_type = fx_i32_htob(IVY_CLASS_TABLE_PROP);
entry.e_property.p_ident
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
= fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
entry.e_property.p_get
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_GET]);
= fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_GET]);
entry.e_property.p_set
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_SET]);
= fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_SET]);
break;
case IVY_ASM_XVAL_MEMBER_VAR:
entry.e_type = b_i32_htob(IVY_CLASS_TABLE_MVAR);
entry.e_type = fx_i32_htob(IVY_CLASS_TABLE_MVAR);
entry.e_mvar.m_ident
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
= fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
entry.e_mvar.m_index
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_INDEX]);
= fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_INDEX]);
break;
case IVY_ASM_XVAL_MESSAGE_HANDLER:
entry.e_type = b_i32_htob(IVY_CLASS_TABLE_MSGH);
entry.e_type = fx_i32_htob(IVY_CLASS_TABLE_MSGH);
entry.e_msgh.msg_selector
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_SELECTOR]);
= fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_SELECTOR]);
entry.e_msgh.msg_block
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_BLOCK]);
= fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_BLOCK]);
break;
default:
return IVY_ERR_NOT_SUPPORTED;

View File

@@ -1,9 +1,9 @@
#include "assembler.h"
#include <blue/core/hash.h>
#include <blue/ds/dict.h>
#include <blue/ds/number.h>
#include <blue/ds/string.h>
#include <fx/core/hash.h>
#include <fx/ds/dict.h>
#include <fx/ds/number.h>
#include <fx/ds/string.h>
#include <ivy/asm/bin.h>
#include <ivy/ident.h>
#include <ivy/selector.h>
@@ -12,7 +12,7 @@
struct constpool_assembler_scope {
struct assembler_scope s_base;
b_dict *s_strings;
fx_dict *s_strings;
size_t s_next_slot;
};
@@ -26,7 +26,7 @@ static enum ivy_status init_scope(
struct constpool_assembler_scope *c
= (struct constpool_assembler_scope *)scope;
c->s_strings = b_dict_create();
c->s_strings = fx_dict_create();
c->s_next_slot = 0;
return IVY_OK;
@@ -35,19 +35,19 @@ static enum ivy_status init_scope(
static ivy_extended_data_key get_cached_string(
struct constpool_assembler_scope *scope, const char *s)
{
b_number *key = b_dict_at(scope->s_strings, s);
fx_number *key = fx_dict_at(scope->s_strings, s);
if (!key) {
return IVY_EX_DATA_KEY_NULL;
}
return (ivy_extended_data_key)b_number_get_int32(key);
return (ivy_extended_data_key)fx_number_get_int32(key);
}
static void put_cached_string(
struct constpool_assembler_scope *scope, const char *s,
ivy_extended_data_key key)
{
b_dict_put(scope->s_strings, s, B_RV_INT32(key));
fx_dict_put(scope->s_strings, s, FX_RV_INT32(key));
}
static ivy_extended_data_key write_string(struct ivy_assembler *as, const char *s)
@@ -63,8 +63,8 @@ static ivy_extended_data_key write_string(struct ivy_assembler *as, const char *
size_t len = strlen(s);
struct ivy_bin_string str = {0};
str.s_hash = b_i32_htob((uint32_t)b_hash_cstr(s));
str.s_len = b_i32_htob((uint32_t)len);
str.s_hash = fx_i32_htob((uint32_t)fx_hash_cstr(s));
str.s_len = fx_i32_htob((uint32_t)len);
key = assembler_write_extended_data(as, &str, sizeof str);
@@ -90,29 +90,29 @@ static ivy_extended_data_key write_selector(
}
if (sel->sel_name) {
dat.sel_name = b_i32_htob(write_string(as, sel->sel_name));
dat.sel_name = fx_i32_htob(write_string(as, sel->sel_name));
}
size_t i = 0;
size_t nr_args = b_queue_length(&sel->sel_args);
size_t nr_args = fx_queue_length(&sel->sel_args);
dat.sel_nr_args = (uint8_t)nr_args;
/* TODO hash. */
ivy_extended_data_key *arg_handles
= calloc(nr_args, sizeof(ivy_extended_data_key));
b_queue_entry *entry = b_queue_first(&sel->sel_args);
fx_queue_entry *entry = fx_queue_first(&sel->sel_args);
while (entry) {
struct ivy_selector_arg *arg
= b_unbox(struct ivy_selector_arg, entry, arg_entry);
= fx_unbox(struct ivy_selector_arg, entry, arg_entry);
arg_handles[i++] = write_string(as, arg->arg_label);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
ivy_extended_data_key selector_handle
= assembler_write_extended_data(as, &dat, sizeof dat);
for (i = 0; i < nr_args; i++) {
b_i32 arg_handle = b_i32_htob(arg_handles[i]);
fx_i32 arg_handle = fx_i32_htob(arg_handles[i]);
assembler_write_extended_data(as, &arg_handle, sizeof arg_handle);
}
@@ -126,17 +126,17 @@ static ivy_extended_data_key write_ident(
struct ivy_bin_ident dat = {0};
/* TODO hash. */
size_t nr_parts = b_queue_length(&id->id_parts);
size_t nr_parts = fx_queue_length(&id->id_parts);
size_t i = 0;
ivy_extended_data_key *part_handles
= calloc(nr_parts, sizeof(ivy_extended_data_key));
b_queue_entry *entry = b_queue_first(&id->id_parts);
fx_queue_entry *entry = fx_queue_first(&id->id_parts);
while (entry) {
struct ivy_ident_part *arg
= b_unbox(struct ivy_ident_part, entry, p_entry);
= fx_unbox(struct ivy_ident_part, entry, p_entry);
part_handles[i++] = write_string(as, arg->p_str);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
dat.id_nr_parts = (uint8_t)nr_parts;
@@ -145,7 +145,7 @@ static ivy_extended_data_key write_ident(
= assembler_write_extended_data(as, &dat, sizeof dat);
for (i = 0; i < nr_parts; i++) {
b_i32 part_handle = b_i32_htob(part_handles[i]);
fx_i32 part_handle = fx_i32_htob(part_handles[i]);
assembler_write_extended_data(as, &part_handle, sizeof part_handle);
}
@@ -170,32 +170,32 @@ static enum ivy_status put_pval(
switch (type) {
case IVY_ASM_PVAL_STRING:
entry.e_type = b_i32_htob(IVY_CONSTPOOL_TABLE_STRING);
entry.e_type = fx_i32_htob(IVY_CONSTPOOL_TABLE_STRING);
k = write_string(as, val);
entry.e_ex_handle = b_i32_htob(k);
entry.e_ex_handle = fx_i32_htob(k);
break;
case IVY_ASM_PVAL_IDENT:
entry.e_type = b_i32_htob(IVY_CONSTPOOL_TABLE_IDENT);
entry.e_type = fx_i32_htob(IVY_CONSTPOOL_TABLE_IDENT);
k = write_ident(as, val);
entry.e_ex_handle = b_i32_htob(k);
entry.e_ex_handle = fx_i32_htob(k);
break;
case IVY_ASM_PVAL_ATOM:
entry.e_type = b_i32_htob(IVY_CONSTPOOL_TABLE_ATOM);
entry.e_type = fx_i32_htob(IVY_CONSTPOOL_TABLE_ATOM);
k = write_string(as, val);
entry.e_ex_handle = b_i32_htob(k);
entry.e_ex_handle = fx_i32_htob(k);
break;
case IVY_ASM_PVAL_SINT:
entry.e_type = b_i32_htob(IVY_CONSTPOOL_TABLE_INT);
entry.e_int = b_i32_htob((uint32_t)i);
entry.e_type = fx_i32_htob(IVY_CONSTPOOL_TABLE_INT);
entry.e_int = fx_i32_htob((uint32_t)i);
break;
case IVY_ASM_PVAL_UINT:
entry.e_type = b_i32_htob(IVY_CONSTPOOL_TABLE_UINT);
entry.e_int = b_i32_htob((uint32_t)i);
entry.e_type = fx_i32_htob(IVY_CONSTPOOL_TABLE_UINT);
entry.e_int = fx_i32_htob((uint32_t)i);
break;
case IVY_ASM_PVAL_SELECTOR:
entry.e_type = b_i32_htob(IVY_CONSTPOOL_TABLE_SELECTOR);
entry.e_type = fx_i32_htob(IVY_CONSTPOOL_TABLE_SELECTOR);
k = write_selector(as, val);
entry.e_ex_handle = b_i32_htob(k);
entry.e_ex_handle = fx_i32_htob(k);
break;
default:
return IVY_ERR_NOT_SUPPORTED;