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,9 +1,9 @@
#include "../debug.h"
#include "cmd.h"
#include <blue/cmd.h>
#include <blue/ds/string.h>
#include <blue/term.h>
#include <fx/cmd.h>
#include <fx/ds/string.h>
#include <fx/term.h>
#include <errno.h>
#include <ivy/asm/assembler.h>
#include <ivy/asm/lex.h>
@@ -24,15 +24,15 @@ static int assemble_file(const char *in_path, const char *out_path)
struct ivy_file *src = NULL;
status = ivy_file_open(in_path, &src);
if (!src) {
b_err("cannot open source file '%s'", in_path);
b_i("reason: %s", ivy_status_to_string(status));
fx_err("cannot open source file '%s'", in_path);
fx_i("reason: %s", ivy_status_to_string(status));
return -1;
}
FILE *out = fopen(out_path, "w+b");
if (!out) {
b_err("cannot open output file '%s'", out_path);
b_i("reason: %s", strerror(errno));
fx_err("cannot open output file '%s'", out_path);
fx_i("reason: %s", strerror(errno));
return -1;
}
@@ -40,8 +40,8 @@ static int assemble_file(const char *in_path, const char *out_path)
status = ivy_assembler_create(out, &as);
if (status != IVY_OK) {
b_err("failed to initialise Ivy assembler");
b_i("reason: %s", ivy_status_to_string(status));
fx_err("failed to initialise Ivy assembler");
fx_i("reason: %s", ivy_status_to_string(status));
ivy_file_close(src);
fclose(out);
@@ -51,8 +51,8 @@ static int assemble_file(const char *in_path, const char *out_path)
struct ivy_asm_lexer *lex;
status = ivy_asm_lexer_create(&lex);
if (status != IVY_OK) {
b_err("failed to initialise Ivy assembly lexer");
b_i("reason: %s", ivy_status_to_string(status));
fx_err("failed to initialise Ivy assembly lexer");
fx_i("reason: %s", ivy_status_to_string(status));
ivy_file_close(src);
fclose(out);
@@ -63,8 +63,8 @@ static int assemble_file(const char *in_path, const char *out_path)
struct ivy_asm_parser *parser;
status = ivy_asm_parser_create(&parser);
if (status != IVY_OK) {
b_err("failed to initialise Ivy assembly parser");
b_i("reason: %s", ivy_status_to_string(status));
fx_err("failed to initialise Ivy assembly parser");
fx_i("reason: %s", ivy_status_to_string(status));
ivy_asm_lexer_destroy(lex);
ivy_file_close(src);
@@ -85,8 +85,8 @@ static int assemble_file(const char *in_path, const char *out_path)
}
if (status != IVY_OK) {
b_err("failed to parse '%s'", in_path);
b_i("reason: lex error (%s)",
fx_err("failed to parse '%s'", in_path);
fx_i("reason: lex error (%s)",
ivy_status_to_string(ivy_asm_lexer_get_status(lex)));
break;
}
@@ -95,8 +95,8 @@ static int assemble_file(const char *in_path, const char *out_path)
status = ivy_asm_parser_push_token(parser, tok);
if (status != IVY_OK) {
b_err("failed to parse '%s'", in_path);
b_i("reason: parse error (%s)",
fx_err("failed to parse '%s'", in_path);
fx_i("reason: parse error (%s)",
ivy_status_to_string(status));
break;
}
@@ -112,31 +112,31 @@ static int assemble_file(const char *in_path, const char *out_path)
return r;
}
static b_string *get_source_filename(const char *src_path)
static fx_string *get_source_filename(const char *src_path)
{
b_string *name = b_string_create();
fx_string *name = fx_string_create();
for (unsigned int i = 0; src_path[i]; i++) {
if (src_path[i] == '/' || src_path[i] == '\\') {
b_string_clear(name);
fx_string_clear(name);
continue;
}
char s[] = {src_path[i], 0};
b_string_append_cstr(name, s);
fx_string_append_cstr(name, s);
}
if (b_string_get_size(name, B_STRLEN_NORMAL) == 0) {
b_string_unref(name);
if (fx_string_get_size(name, FX_STRLEN_NORMAL) == 0) {
fx_string_unref(name);
name = NULL;
}
return name;
}
static b_string *generate_object_filename(const char *src_filename)
static fx_string *generate_object_filename(const char *src_filename)
{
b_string *name = b_string_create();
fx_string *name = fx_string_create();
for (unsigned int i = 0; src_filename[i]; i++) {
if (src_filename[i] == '.') {
@@ -144,53 +144,53 @@ static b_string *generate_object_filename(const char *src_filename)
}
char s[] = {src_filename[i], 0};
b_string_append_cstr(name, s);
fx_string_append_cstr(name, s);
}
if (b_string_get_size(name, B_STRLEN_NORMAL) == 0) {
b_string_append_cstr(name, "out");
if (fx_string_get_size(name, FX_STRLEN_NORMAL) == 0) {
fx_string_append_cstr(name, "out");
}
b_string_append_cstr(name, ".io");
fx_string_append_cstr(name, ".io");
return name;
}
static int assemble(const b_command *cmd, const b_arglist *args, const b_array *_)
static int assemble(const fx_command *cmd, const fx_arglist *args, const fx_array *_)
{
const char *in_path = NULL;
const char *out_path = NULL;
b_string *in_name = NULL;
b_string *out_name = NULL;
fx_string *in_name = NULL;
fx_string *out_name = NULL;
b_arglist_get_string(
args, B_COMMAND_INVALID_ID, ARG_SOURCE_FILE, 0, &in_path);
fx_arglist_get_string(
args, FX_COMMAND_INVALID_ID, ARG_SOURCE_FILE, 0, &in_path);
if (!in_path) {
b_err("no source file specified.");
fx_err("no source file specified.");
return -1;
}
in_name = get_source_filename(in_path);
if (!in_path) {
b_err("source filepath is not a file.");
fx_err("source filepath is not a file.");
return -1;
}
b_arglist_get_string(args, OPT_OUT_FILE, ARG_OUT_FILE, 0, &out_path);
fx_arglist_get_string(args, OPT_OUT_FILE, ARG_OUT_FILE, 0, &out_path);
if (!out_path) {
out_name = generate_object_filename(b_string_ptr(in_name));
out_path = b_string_ptr(out_name);
out_name = generate_object_filename(fx_string_ptr(in_name));
out_path = fx_string_ptr(out_name);
}
int r = assemble_file(in_path, out_path);
b_string_unref(in_name);
b_string_unref(out_name);
fx_string_unref(in_name);
fx_string_unref(out_name);
return r;
#if 0
const char *path = NULL;
b_arglist_get_string(args, OPT_OUT_FILE, ARG_OUT_FILE, 0, &path);
fx_arglist_get_string(args, OPT_OUT_FILE, ARG_OUT_FILE, 0, &path);
if (!path) {
printf("no output path specified.\n");
@@ -202,8 +202,8 @@ static int assemble(const b_command *cmd, const b_arglist *args, const b_array *
enum ivy_status status = ivy_assembler_create(out, &as);
if (status != IVY_OK) {
b_err("failed to initialise assembler");
b_i("reason: ", ivy_status_to_string(status));
fx_err("failed to initialise assembler");
fx_i("reason: ", ivy_status_to_string(status));
fclose(out);
return -1;
}
@@ -231,32 +231,32 @@ static int assemble(const b_command *cmd, const b_arglist *args, const b_array *
B_COMMAND(CMD_ASSEMBLE, CMD_ROOT)
{
B_COMMAND_NAME("assemble");
B_COMMAND_SHORT_NAME('A');
B_COMMAND_DESC(
FX_COMMAND_NAME("assemble");
FX_COMMAND_SHORT_NAME('A');
FX_COMMAND_DESC(
"assemble one or more Ivy assembly source files into Ivy "
"object files.");
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
B_COMMAND_FUNCTION(assemble);
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
FX_COMMAND_FUNCTION(assemble);
B_COMMAND_ARG(ARG_SOURCE_FILE)
FX_COMMAND_ARG(ARG_SOURCE_FILE)
{
B_ARG_NAME("source file");
B_ARG_DESC("the .iasm assembly file to compile.");
B_ARG_NR_VALUES(1);
FX_ARG_NAME("source file");
FX_ARG_DESC("the .iasm assembly file to compile.");
FX_ARG_NR_VALUES(1);
}
B_COMMAND_OPTION(OPT_OUT_FILE)
FX_COMMAND_OPTION(OPT_OUT_FILE)
{
B_OPTION_SHORT_NAME('o');
B_OPTION_LONG_NAME("out");
B_OPTION_DESC("the path to write the output binary file to.");
B_OPTION_ARG(ARG_OUT_FILE)
FX_OPTION_SHORT_NAME('o');
FX_OPTION_LONG_NAME("out");
FX_OPTION_DESC("the path to write the output binary file to.");
FX_OPTION_ARG(ARG_OUT_FILE)
{
B_ARG_NAME("path");
B_ARG_NR_VALUES(1);
FX_ARG_NAME("path");
FX_ARG_NR_VALUES(1);
}
}
B_COMMAND_HELP_OPTION();
FX_COMMAND_HELP_OPTION();
}

View File

@@ -2,9 +2,9 @@
#include "cmd.h"
#include "mie/select/builder.h"
#include <blue/cmd.h>
#include <blue/core/error.h>
#include <blue/term.h>
#include <fx/cmd.h>
#include <fx/core/error.h>
#include <fx/term.h>
#include <errno.h>
#include <ivy/asm/mie.h>
#include <ivy/diag.h>
@@ -68,19 +68,19 @@ static enum ivy_status node_codegen(
return ivy_codegen_push_node(ctx->codegen, node, node->n_it.it_depth);
}
static b_result compile_ctx_init(struct compile_ctx *ctx, const b_arglist *args)
static fx_result compile_ctx_init(struct compile_ctx *ctx, const fx_arglist *args)
{
memset(ctx, 0x0, sizeof *ctx);
b_arglist_get_count(args, OPT_SHOW_LEX_TOKENS, B_COMMAND_INVALID_ID)
fx_arglist_get_count(args, OPT_SHOW_LEX_TOKENS, FX_COMMAND_INVALID_ID)
&& (ctx->flags |= FLAG_SHOW_LEX_TOKENS);
b_arglist_get_count(args, OPT_SHOW_AST_NODES, B_COMMAND_INVALID_ID)
fx_arglist_get_count(args, OPT_SHOW_AST_NODES, FX_COMMAND_INVALID_ID)
&& (ctx->flags |= FLAG_SHOW_AST_NODES);
b_arglist_get_count(args, OPT_SHOW_IR, B_COMMAND_INVALID_ID)
fx_arglist_get_count(args, OPT_SHOW_IR, FX_COMMAND_INVALID_ID)
&& (ctx->flags |= FLAG_SHOW_IR);
b_arglist_get_count(args, OPT_SHOW_ISEL_PRE, B_COMMAND_INVALID_ID)
fx_arglist_get_count(args, OPT_SHOW_ISEL_PRE, FX_COMMAND_INVALID_ID)
&& (ctx->flags |= FLAG_SHOW_PRE_SELECT_GRAPH);
b_arglist_get_count(args, OPT_SHOW_ISEL_POST, B_COMMAND_INVALID_ID)
fx_arglist_get_count(args, OPT_SHOW_ISEL_POST, FX_COMMAND_INVALID_ID)
&& (ctx->flags |= FLAG_SHOW_POST_SELECT_GRAPH);
enum mie_status mie_status = MIE_SUCCESS;
@@ -96,14 +96,14 @@ static b_result compile_ctx_init(struct compile_ctx *ctx, const b_arglist *args)
= mie_select_builder_create(ctx->mie_ctx, ivy_asm_mie_target());
ivy_lang_diag_ctx_init(ctx->diag);
ivy_diag_stream_init_tty(&ctx->diag_stream, b_stdtty);
ivy_diag_stream_init_tty(&ctx->diag_stream, fx_stdtty);
ivy_lexer_set_diag_ctx(ctx->lex, ctx->diag);
ivy_parser_set_diag_ctx(ctx->parser, ctx->diag);
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result compile_ctx_cleanup(struct compile_ctx *ctx)
static fx_result compile_ctx_cleanup(struct compile_ctx *ctx)
{
if (ctx->mod) {
mie_value_destroy(MIE_VALUE(ctx->mod));
@@ -139,10 +139,10 @@ static b_result compile_ctx_cleanup(struct compile_ctx *ctx)
mie_ctx_destroy(ctx->mie_ctx);
}
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result open_file(struct compile_ctx *ctx, const char *path)
static fx_result open_file(struct compile_ctx *ctx, const char *path)
{
enum ivy_status status = ivy_file_open(path, &ctx->src);
@@ -151,10 +151,10 @@ static b_result open_file(struct compile_ctx *ctx, const char *path)
ctx->src_path = path;
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result parse_file_tokens(struct compile_ctx *ctx)
static fx_result parse_file_tokens(struct compile_ctx *ctx)
{
enum ivy_status status = IVY_OK;
@@ -166,7 +166,7 @@ static b_result parse_file_tokens(struct compile_ctx *ctx)
ivy_diag_ctx_write(
ctx->diag, IVY_DIAG_FORMAT_PRETTY,
&ctx->diag_stream);
return b_error_with_code(
return fx_error_with_code(
IVY_ERROR_VENDOR, IVY_ERR_BAD_SYNTAX);
}
@@ -181,12 +181,12 @@ static b_result parse_file_tokens(struct compile_ctx *ctx)
ctx->diag, IVY_DIAG_FORMAT_PRETTY,
&ctx->diag_stream);
ivy_token_destroy(tok);
return b_error_with_code(
return fx_error_with_code(
IVY_ERROR_VENDOR, IVY_ERR_BAD_SYNTAX);
}
if (status != IVY_OK) {
return b_error_caused_by_code(
return fx_error_caused_by_code(
IVY_ERROR_VENDOR, IVY_ERR_PARSE_FAILURE,
IVY_ERROR_VENDOR, status);
}
@@ -196,10 +196,10 @@ static b_result parse_file_tokens(struct compile_ctx *ctx)
}
}
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result generate_mie_ir(struct compile_ctx *ctx)
static fx_result generate_mie_ir(struct compile_ctx *ctx)
{
ivy_codegen_start_module(ctx->codegen);
@@ -209,45 +209,45 @@ static b_result generate_mie_ir(struct compile_ctx *ctx)
enum ivy_status status
= ivy_ast_node_iterate(node, &it, node_codegen, ctx);
if (status != IVY_OK) {
return b_error_caused_by_code(
return fx_error_caused_by_code(
IVY_ERROR_VENDOR, IVY_ERR_CODEGEN_FAILURE,
IVY_ERROR_VENDOR, status);
}
status = ivy_codegen_push_eof(ctx->codegen);
if (status != IVY_OK) {
return b_error_caused_by_code(
return fx_error_caused_by_code(
IVY_ERROR_VENDOR, IVY_ERR_CODEGEN_FAILURE,
IVY_ERROR_VENDOR, status);
}
ivy_codegen_end_module(ctx->codegen, &ctx->mod);
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result build_block_isel_graph(
static fx_result build_block_isel_graph(
struct compile_ctx *ctx, struct mie_func *func, struct mie_block *block)
{
printf("selecting %s.%s...\n", func->f_base.v_name.n_str,
block->b_base.v_name.n_str);
b_queue_entry *entry = b_queue_first(&block->b_phi);
fx_queue_entry *entry = fx_queue_first(&block->b_phi);
while (entry) {
struct mie_value *instr_v
= b_unbox(struct mie_value, entry, v_entry);
= fx_unbox(struct mie_value, entry, v_entry);
mie_select_builder_push_instr(
ctx->select, (struct mie_instr *)instr_v);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
entry = b_queue_first(&block->b_instr);
entry = fx_queue_first(&block->b_instr);
while (entry) {
struct mie_value *instr_v
= b_unbox(struct mie_value, entry, v_entry);
= fx_unbox(struct mie_value, entry, v_entry);
mie_select_builder_push_instr(
ctx->select, (struct mie_instr *)instr_v);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
if (block->b_terminator) {
@@ -267,48 +267,48 @@ static b_result build_block_isel_graph(
mie_select_graph_destroy(graph);
}
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result build_func_isel_graph(struct compile_ctx *ctx, struct mie_func *func)
static fx_result build_func_isel_graph(struct compile_ctx *ctx, struct mie_func *func)
{
b_queue_entry *entry = b_queue_first(&func->f_blocks);
fx_queue_entry *entry = fx_queue_first(&func->f_blocks);
while (entry) {
struct mie_value *block_v
= b_unbox(struct mie_value, entry, v_entry);
= fx_unbox(struct mie_value, entry, v_entry);
struct mie_block *block = (struct mie_block *)block_v;
b_result result = build_block_isel_graph(ctx, func, block);
if (b_result_is_error(result)) {
return b_result_propagate(result);
fx_result result = build_block_isel_graph(ctx, func, block);
if (fx_result_is_error(result)) {
return fx_result_propagate(result);
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result build_isel_graph(struct compile_ctx *ctx)
static fx_result build_isel_graph(struct compile_ctx *ctx)
{
b_queue_entry *entry = b_queue_first(&ctx->mod->m_func);
fx_queue_entry *entry = fx_queue_first(&ctx->mod->m_func);
while (entry) {
struct mie_value *func_v
= b_unbox(struct mie_value, entry, v_entry);
= fx_unbox(struct mie_value, entry, v_entry);
struct mie_func *func = (struct mie_func *)func_v;
b_result result = build_func_isel_graph(ctx, func);
if (b_result_is_error(result)) {
return b_result_propagate(result);
fx_result result = build_func_isel_graph(ctx, func);
if (fx_result_is_error(result)) {
return fx_result_propagate(result);
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result dump_ast(struct compile_ctx *ctx)
static fx_result dump_ast(struct compile_ctx *ctx)
{
struct ivy_ast_node *node = ivy_parser_root_node(ctx->parser);
struct ivy_ast_node_iterator it = {0};
@@ -318,10 +318,10 @@ static b_result dump_ast(struct compile_ctx *ctx)
ivy_ast_node_iterate(node, &it, print_ast_node, &args);
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result dump_ir(struct compile_ctx *ctx)
static fx_result dump_ir(struct compile_ctx *ctx)
{
struct mie_ir_converter *convert
= mie_ir_converter_create(ctx->mie_ctx, MIE_IR_MEM, MIE_IR_TEXT);
@@ -331,24 +331,24 @@ static b_result dump_ir(struct compile_ctx *ctx)
mie_ir_converter_destroy(convert);
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static int compile_file(const char *path, const b_arglist *args)
static int compile_file(const char *path, const fx_arglist *args)
{
#define THROW_AND_RETURN(result, error_code) \
do { \
if (b_result_is(result, IVY_ERROR_VENDOR, IVY_ERR_BAD_SYNTAX)) { \
if (fx_result_is(result, IVY_ERROR_VENDOR, IVY_ERR_BAD_SYNTAX)) { \
return error_code; \
} \
if (b_result_is_error(result)) { \
b_throw(result); \
if (fx_result_is_error(result)) { \
fx_throw(result); \
return error_code; \
} \
} while (0)
struct compile_ctx ctx;
b_result result = compile_ctx_init(&ctx, args);
fx_result result = compile_ctx_init(&ctx, args);
THROW_AND_RETURN(result, -1);
int progress = 0;
@@ -397,13 +397,13 @@ end:
return 0;
}
static int compile(const b_command *cmd, const b_arglist *args, const b_array *_)
static int compile(const fx_command *cmd, const fx_arglist *args, const fx_array *_)
{
b_arglist_iterator it;
b_arglist_foreach_filtered(&it, args, B_COMMAND_INVALID_ID, ARG_SOURCE_FILE)
fx_arglist_iterator it;
fx_arglist_foreach_filtered(&it, args, FX_COMMAND_INVALID_ID, ARG_SOURCE_FILE)
{
b_arglist_value *path = it.value;
if (path->val_type != B_COMMAND_ARG_STRING) {
fx_arglist_value *path = it.value;
if (path->val_type != FX_COMMAND_ARG_STRING) {
continue;
}
@@ -418,64 +418,64 @@ static int compile(const b_command *cmd, const b_arglist *args, const b_array *_
B_COMMAND(CMD_COMPILE, CMD_ROOT)
{
B_COMMAND_NAME("compile");
B_COMMAND_SHORT_NAME('C');
B_COMMAND_DESC(
FX_COMMAND_NAME("compile");
FX_COMMAND_SHORT_NAME('C');
FX_COMMAND_DESC(
"compile one or more Ivy source files into Ivy object files.");
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
B_COMMAND_FUNCTION(compile);
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
FX_COMMAND_FUNCTION(compile);
B_COMMAND_OPTION(OPT_SHOW_LEX_TOKENS)
FX_COMMAND_OPTION(OPT_SHOW_LEX_TOKENS)
{
B_OPTION_LONG_NAME("show-lex");
B_OPTION_SHORT_NAME('l');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("show-lex");
FX_OPTION_SHORT_NAME('l');
FX_OPTION_DESC(
"print the lexical tokens generated from the input "
"files.");
}
B_COMMAND_OPTION(OPT_SHOW_AST_NODES)
FX_COMMAND_OPTION(OPT_SHOW_AST_NODES)
{
B_OPTION_LONG_NAME("show-ast");
B_OPTION_SHORT_NAME('a');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("show-ast");
FX_OPTION_SHORT_NAME('a');
FX_OPTION_DESC(
"print the abstract syntax tree generated from the "
"input files.");
}
B_COMMAND_OPTION(OPT_SHOW_IR)
FX_COMMAND_OPTION(OPT_SHOW_IR)
{
B_OPTION_LONG_NAME("show-ir");
B_OPTION_SHORT_NAME('i');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("show-ir");
FX_OPTION_SHORT_NAME('i');
FX_OPTION_DESC(
"print the Mie IR generated from the "
"input files.");
}
B_COMMAND_OPTION(OPT_SHOW_ISEL_PRE)
FX_COMMAND_OPTION(OPT_SHOW_ISEL_PRE)
{
B_OPTION_LONG_NAME("show-isel-pre");
B_OPTION_SHORT_NAME('s');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("show-isel-pre");
FX_OPTION_SHORT_NAME('s');
FX_OPTION_DESC(
"print the instruction selection graph before "
"selection has taken place.");
}
B_COMMAND_OPTION(OPT_SHOW_ISEL_POST)
FX_COMMAND_OPTION(OPT_SHOW_ISEL_POST)
{
B_OPTION_LONG_NAME("show-isel-post");
B_OPTION_SHORT_NAME('m');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("show-isel-post");
FX_OPTION_SHORT_NAME('m');
FX_OPTION_DESC(
"print the instruction selection graph after "
"selection has taken place.");
}
B_COMMAND_ARG(ARG_SOURCE_FILE)
FX_COMMAND_ARG(ARG_SOURCE_FILE)
{
B_ARG_NAME("source file");
B_ARG_DESC("the .im source files to compile.");
B_ARG_NR_VALUES(B_ARG_1_OR_MORE_VALUES);
FX_ARG_NAME("source file");
FX_ARG_DESC("the .im source files to compile.");
FX_ARG_NR_VALUES(FX_ARG_1_OR_MORE_VALUES);
}
B_COMMAND_HELP_OPTION();
FX_COMMAND_HELP_OPTION();
}

View File

@@ -1,8 +1,8 @@
#include "cmd.h"
#include <blue/cmd.h>
#include <blue/ds/string.h>
#include <blue/term.h>
#include <fx/cmd.h>
#include <fx/ds/string.h>
#include <fx/term.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
@@ -30,7 +30,7 @@ enum {
OPT_CONSTPOOL,
};
static void dump_instruction(b_i32 x)
static void dump_instruction(fx_i32 x)
{
struct ivy_instr instr = {};
enum ivy_status status = ivy_instr_decode(x, &instr);
@@ -226,7 +226,7 @@ static enum ivy_status dump_class(
}
status = ivy_asm_constpool_reader_read_value(
pool, b_i32_btoh(class_header.c_ident), &class_ident);
pool, fx_i32_btoh(class_header.c_ident), &class_ident);
if (status != IVY_OK) {
goto cleanup;
}
@@ -262,13 +262,13 @@ static enum ivy_status dump_class(
printf(" [%03zu] ", i);
char s[256];
uint32_t type = b_i32_btoh(entry.e_type);
uint32_t type = fx_i32_btoh(entry.e_type);
switch (type) {
case IVY_CLASS_TABLE_PROP: {
printf("type:property\n");
struct ivy_asm_constpool_value *prop_ident = NULL;
status = ivy_asm_constpool_reader_read_value(
pool, b_i32_btoh(entry.e_property.p_ident),
pool, fx_i32_btoh(entry.e_property.p_ident),
&prop_ident);
if (status != IVY_OK) {
break;
@@ -279,8 +279,8 @@ static enum ivy_status dump_class(
break;
}
uint32_t get = b_i32_btoh(entry.e_property.p_get);
uint32_t set = b_i32_btoh(entry.e_property.p_set);
uint32_t get = fx_i32_btoh(entry.e_property.p_get);
uint32_t set = fx_i32_btoh(entry.e_property.p_set);
ivy_ident_to_string(prop_ident->v_ident, s, sizeof s);
ivy_asm_constpool_value_destroy(prop_ident);
@@ -305,7 +305,7 @@ static enum ivy_status dump_class(
printf("type:variable\n");
struct ivy_asm_constpool_value *var_ident = NULL;
status = ivy_asm_constpool_reader_read_value(
pool, b_i32_btoh(entry.e_mvar.m_ident), &var_ident);
pool, fx_i32_btoh(entry.e_mvar.m_ident), &var_ident);
if (status != IVY_OK) {
break;
}
@@ -315,7 +315,7 @@ static enum ivy_status dump_class(
break;
}
uint32_t index = b_i32_btoh(entry.e_mvar.m_index);
uint32_t index = fx_i32_btoh(entry.e_mvar.m_index);
ivy_ident_to_string(var_ident->v_ident, s, sizeof s);
ivy_asm_constpool_value_destroy(var_ident);
printf(" ident:%s, index:0x%" PRIx32
@@ -328,7 +328,7 @@ static enum ivy_status dump_class(
printf("type:method\n");
struct ivy_asm_constpool_value *sel = NULL;
status = ivy_asm_constpool_reader_read_value(
pool, b_i32_btoh(entry.e_msgh.msg_selector), &sel);
pool, fx_i32_btoh(entry.e_msgh.msg_selector), &sel);
if (status != IVY_OK) {
break;
}
@@ -338,7 +338,7 @@ static enum ivy_status dump_class(
break;
}
uint32_t block = b_i32_btoh(entry.e_msgh.msg_block);
uint32_t block = fx_i32_btoh(entry.e_msgh.msg_block);
ivy_selector_to_string(sel->v_sel, s, sizeof s);
ivy_asm_constpool_value_destroy(sel);
@@ -399,7 +399,7 @@ static enum ivy_status dump_constpool(struct ivy_asm_reader *object)
enum ivy_status status
= ivy_asm_reader_open_constpool(object, 0, 0, &pool);
if (status == IVY_ERR_NO_ENTRY) {
b_err("object file has no constpool.\n");
fx_err("object file has no constpool.\n");
return status;
}
@@ -409,8 +409,8 @@ static enum ivy_status dump_constpool(struct ivy_asm_reader *object)
struct ivy_asm_constpool_value *v;
status = ivy_asm_constpool_reader_read_value(pool, i, &v);
if (status != IVY_OK) {
b_err("cannot read constpool value");
b_i("reason: %s", ivy_status_to_string(status));
fx_err("cannot read constpool value");
fx_i("reason: %s", ivy_status_to_string(status));
break;
}
@@ -455,7 +455,7 @@ static enum ivy_status dump_constpool(struct ivy_asm_reader *object)
return status;
}
static void dump_instructions(b_i32 *x, size_t buffer_size)
static void dump_instructions(fx_i32 *x, size_t buffer_size)
{
size_t nr_instr = buffer_size / sizeof *x;
@@ -503,7 +503,7 @@ static enum ivy_status dump_header(
break;
}
printf(" ident=0x%04x\n", b_i32_btoh(xcls.c_ident));
printf(" ident=0x%04x\n", fx_i32_btoh(xcls.c_ident));
*dump_offset = sizeof xcls;
break;
}
@@ -520,7 +520,7 @@ static enum ivy_status dump_header(
break;
}
long index = b_i32_btoh(text.b_index);
long index = fx_i32_btoh(text.b_index);
printf(" index=0x%04lx [%ld]\n", index, index);
*dump_offset = sizeof text;
break;
@@ -584,7 +584,7 @@ static enum ivy_status dump_section(
printf(" | ");
if (flags & DUMP_INSTRUCTIONS) {
dump_instructions((b_i32 *)x, buffer_size);
dump_instructions((fx_i32 *)x, buffer_size);
} else {
dump_strings(x, buffer_size);
}
@@ -649,31 +649,31 @@ static enum ivy_status dump_section_table(struct ivy_asm_reader *reader, bool du
}
static int disassemble(
const b_command *cmd, const b_arglist *args, const b_array *_)
const fx_command *cmd, const fx_arglist *args, const fx_array *_)
{
bool header = b_arglist_get_count(args, OPT_HEADER, B_COMMAND_INVALID_ID)
bool header = fx_arglist_get_count(args, OPT_HEADER, FX_COMMAND_INVALID_ID)
> 0;
bool sections
= b_arglist_get_count(args, OPT_SECTIONS, B_COMMAND_INVALID_ID) > 0;
bool dump = b_arglist_get_count(args, OPT_DUMP, B_COMMAND_INVALID_ID) > 0;
= fx_arglist_get_count(args, OPT_SECTIONS, FX_COMMAND_INVALID_ID) > 0;
bool dump = fx_arglist_get_count(args, OPT_DUMP, FX_COMMAND_INVALID_ID) > 0;
bool constpool
= b_arglist_get_count(args, OPT_CONSTPOOL, B_COMMAND_INVALID_ID)
= fx_arglist_get_count(args, OPT_CONSTPOOL, FX_COMMAND_INVALID_ID)
> 0;
bool classes
= b_arglist_get_count(args, OPT_CLASSES, B_COMMAND_INVALID_ID) > 0;
= fx_arglist_get_count(args, OPT_CLASSES, FX_COMMAND_INVALID_ID) > 0;
const char *in_path = NULL;
b_arglist_get_string(args, B_COMMAND_INVALID_ID, ARG_BIN_FILE, 0, &in_path);
fx_arglist_get_string(args, FX_COMMAND_INVALID_ID, ARG_BIN_FILE, 0, &in_path);
if (!in_path) {
b_err("no input file specified.");
fx_err("no input file specified.");
return -1;
}
FILE *in = fopen(in_path, "rb");
if (!in) {
b_err("cannot open object file");
b_i("reason: %s", strerror(errno));
fx_err("cannot open object file");
fx_i("reason: %s", strerror(errno));
return -1;
}
@@ -682,8 +682,8 @@ static int disassemble(
enum ivy_status status = ivy_asm_reader_open(in, &reader);
if (status != IVY_OK) {
b_err("cannot open object file");
b_i("reason: %s", ivy_status_to_string(status));
fx_err("cannot open object file");
fx_i("reason: %s", ivy_status_to_string(status));
fclose(in);
return -1;
@@ -719,59 +719,59 @@ static int disassemble(
B_COMMAND(CMD_DISASSEMBLE, CMD_ROOT)
{
B_COMMAND_NAME("disassemble");
B_COMMAND_SHORT_NAME('D');
B_COMMAND_DESC("disassemble an Ivy object file.");
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
B_COMMAND_FUNCTION(disassemble);
FX_COMMAND_NAME("disassemble");
FX_COMMAND_SHORT_NAME('D');
FX_COMMAND_DESC("disassemble an Ivy object file.");
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
FX_COMMAND_FUNCTION(disassemble);
B_COMMAND_ARG(ARG_BIN_FILE)
FX_COMMAND_ARG(ARG_BIN_FILE)
{
B_ARG_NAME("input file");
B_ARG_DESC("the Ivy object file to disassemble.");
B_ARG_NR_VALUES(1);
FX_ARG_NAME("input file");
FX_ARG_DESC("the Ivy object file to disassemble.");
FX_ARG_NR_VALUES(1);
}
B_COMMAND_OPTION(OPT_HEADER)
FX_COMMAND_OPTION(OPT_HEADER)
{
B_OPTION_SHORT_NAME('h');
B_OPTION_LONG_NAME("header");
B_OPTION_DESC("print the object file header.");
FX_OPTION_SHORT_NAME('h');
FX_OPTION_LONG_NAME("header");
FX_OPTION_DESC("print the object file header.");
}
B_COMMAND_OPTION(OPT_SECTIONS)
FX_COMMAND_OPTION(OPT_SECTIONS)
{
B_OPTION_SHORT_NAME('s');
B_OPTION_LONG_NAME("section-table");
B_OPTION_DESC("print the object file section table.");
FX_OPTION_SHORT_NAME('s');
FX_OPTION_LONG_NAME("section-table");
FX_OPTION_DESC("print the object file section table.");
}
B_COMMAND_OPTION(OPT_DUMP)
FX_COMMAND_OPTION(OPT_DUMP)
{
B_OPTION_SHORT_NAME('d');
B_OPTION_LONG_NAME("dump");
B_OPTION_DESC(
FX_OPTION_SHORT_NAME('d');
FX_OPTION_LONG_NAME("dump");
FX_OPTION_DESC(
"decode and print the contents of each object "
"section.");
}
B_COMMAND_OPTION(OPT_CLASSES)
FX_COMMAND_OPTION(OPT_CLASSES)
{
B_OPTION_SHORT_NAME('c');
B_OPTION_LONG_NAME("classes");
B_OPTION_DESC(
FX_OPTION_SHORT_NAME('c');
FX_OPTION_LONG_NAME("classes");
FX_OPTION_DESC(
"print the classes contained in the object "
"file.");
}
B_COMMAND_OPTION(OPT_CONSTPOOL)
FX_COMMAND_OPTION(OPT_CONSTPOOL)
{
B_OPTION_SHORT_NAME('p');
B_OPTION_LONG_NAME("pool-data");
B_OPTION_DESC(
FX_OPTION_SHORT_NAME('p');
FX_OPTION_LONG_NAME("pool-data");
FX_OPTION_DESC(
"print the constant pool data in the object "
"file.");
}
B_COMMAND_HELP_OPTION();
FX_COMMAND_HELP_OPTION();
}

View File

@@ -1,41 +1,41 @@
#include "cmd.h"
#include <blue/cmd.h>
#include <fx/cmd.h>
enum {
ARG_FILE
};
static int exec(const b_command *cmd, const b_arglist *args, const b_array *_)
static int exec(const fx_command *cmd, const fx_arglist *args, const fx_array *_)
{
return 0;
}
B_COMMAND(CMD_ROOT, B_COMMAND_INVALID_ID)
B_COMMAND(CMD_ROOT, FX_COMMAND_INVALID_ID)
{
B_COMMAND_NAME("ivy");
B_COMMAND_DESC("evaluate an Ivy source file or Ivy object file.");
B_COMMAND_HELP_OPTION();
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
B_COMMAND_FUNCTION(exec);
FX_COMMAND_NAME("ivy");
FX_COMMAND_DESC("evaluate an Ivy source file or Ivy object file.");
FX_COMMAND_HELP_OPTION();
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
FX_COMMAND_FUNCTION(exec);
B_COMMAND_ARG(ARG_FILE)
FX_COMMAND_ARG(ARG_FILE)
{
B_ARG_NAME("file");
B_ARG_DESC("The file to execute.");
B_ARG_NR_VALUES(1);
FX_ARG_NAME("file");
FX_ARG_DESC("The file to execute.");
FX_ARG_NR_VALUES(1);
}
B_COMMAND_USAGE()
FX_COMMAND_USAGE()
{
B_COMMAND_USAGE_OPT_PLACEHOLDER();
B_COMMAND_USAGE_ARG(ARG_FILE);
FX_COMMAND_USAGE_OPT_PLACEHOLDER();
FX_COMMAND_USAGE_ARG(ARG_FILE);
}
B_COMMAND_USAGE()
FX_COMMAND_USAGE()
{
B_COMMAND_USAGE_COMMAND_PLACEHOLDER();
B_COMMAND_USAGE_OPT_PLACEHOLDER();
B_COMMAND_USAGE_ARG_PLACEHOLDER();
FX_COMMAND_USAGE_COMMAND_PLACEHOLDER();
FX_COMMAND_USAGE_OPT_PLACEHOLDER();
FX_COMMAND_USAGE_ARG_PLACEHOLDER();
}
}

View File

@@ -1,30 +1,30 @@
#include <blue/cmd.h>
#include <fx/cmd.h>
#include "cmd.h"
#include <ivy/lang/lex.h>
#include <ivy/lang/internal.h>
#include <blue/term.h>
#include <fx/term.h>
enum {
OPT_PRINT_SYMBOLS = 0x1000,
OPT_PRINT_KEYWORDS,
};
static int internal(const b_command *cmd, const b_arglist *args, const b_array *_)
static int internal(const fx_command *cmd, const fx_arglist *args, const fx_array *_)
{
struct ivy_lexer *lex;
enum ivy_status status = ivy_lexer_create(&lex);
if (status != IVY_OK) {
b_err("failed to initialise lexer (error %s)",
fx_err("failed to initialise lexer (error %s)",
ivy_status_to_string(status));
return -1;
}
if (b_arglist_get_count(args, OPT_PRINT_SYMBOLS, B_COMMAND_INVALID_ID)) {
if (fx_arglist_get_count(args, OPT_PRINT_SYMBOLS, FX_COMMAND_INVALID_ID)) {
internal_lexer_print_symbol_tree(lex);
}
if (b_arglist_get_count(args, OPT_PRINT_KEYWORDS, B_COMMAND_INVALID_ID)) {
if (fx_arglist_get_count(args, OPT_PRINT_KEYWORDS, FX_COMMAND_INVALID_ID)) {
internal_lexer_print_keyword_dict(lex);
}
@@ -35,26 +35,26 @@ static int internal(const b_command *cmd, const b_arglist *args, const b_array *
B_COMMAND(CMD_INTERNAL, CMD_ROOT)
{
B_COMMAND_NAME("internal");
B_COMMAND_SHORT_NAME('X');
B_COMMAND_DESC("internal frontend debugging tools.");
B_COMMAND_FUNCTION(internal);
FX_COMMAND_NAME("internal");
FX_COMMAND_SHORT_NAME('X');
FX_COMMAND_DESC("internal frontend debugging tools.");
FX_COMMAND_FUNCTION(internal);
B_COMMAND_OPTION(OPT_PRINT_SYMBOLS)
FX_COMMAND_OPTION(OPT_PRINT_SYMBOLS)
{
B_OPTION_LONG_NAME("print-symbols");
B_OPTION_SHORT_NAME('s');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("print-symbols");
FX_OPTION_SHORT_NAME('s');
FX_OPTION_DESC(
"print the symbol tree used by the language lexer.");
}
B_COMMAND_OPTION(OPT_PRINT_KEYWORDS)
FX_COMMAND_OPTION(OPT_PRINT_KEYWORDS)
{
B_OPTION_LONG_NAME("print-keywords");
B_OPTION_SHORT_NAME('k');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("print-keywords");
FX_OPTION_SHORT_NAME('k');
FX_OPTION_DESC(
"print the keyword dictionary used by the language lexer.");
}
B_COMMAND_HELP_OPTION();
FX_COMMAND_HELP_OPTION();
}

View File

@@ -2,8 +2,8 @@
#include "../line-ed/line-ed.h"
#include "cmd.h"
#include <blue/cmd.h>
#include <blue/term.h>
#include <fx/cmd.h>
#include <fx/term.h>
#include <ivy/lang/ast.h>
#include <ivy/lang/codegen.h>
#include <ivy/lang/lex.h>
@@ -180,26 +180,26 @@ static enum ivy_status repl_create(struct repl **out)
return IVY_OK;
}
int repl(const b_command *cmd, const b_arglist *args, const b_array *_)
int repl(const fx_command *cmd, const fx_arglist *args, const fx_array *_)
{
#if 0
b_printf(
fx_printf(
"[bold,bright_red]error[[E0384][reset,bold,white]: cannot "
"assign twice to immutable variable `i`[reset]\n");
b_printf("[bold,bright_blue] -->[reset] src/main.rs:7:3\n");
b_printf("[bold,bright_blue] |[reset]\n");
b_printf("[bold,bright_blue]4 |[reset] let i = 0;\n");
b_printf("[bold,bright_blue] | -[reset]\n");
b_printf("[bold,bright_blue] | |[reset]\n");
b_printf(
fx_printf("[bold,bright_blue] -->[reset] src/main.rs:7:3\n");
fx_printf("[bold,bright_blue] |[reset]\n");
fx_printf("[bold,bright_blue]4 |[reset] let i = 0;\n");
fx_printf("[bold,bright_blue] | -[reset]\n");
fx_printf("[bold,bright_blue] | |[reset]\n");
fx_printf(
"[bold,bright_blue] | first assignment to "
"`i`[reset]\n");
b_printf(
fx_printf(
"[bold,bright_blue] | help: make this binding "
"mutable: `mut i`[reset]\n");
b_printf("[bold,bright_blue]...[reset]\n");
b_printf("[bold,bright_blue]7 |[reset] i += 1;\n");
b_printf(
fx_printf("[bold,bright_blue]...[reset]\n");
fx_printf("[bold,bright_blue]7 |[reset] i += 1;\n");
fx_printf(
"[bold,bright_blue] |[bold,bright_red] ^^^^^^ cannot "
"assign twice to immutable variable[reset]\n");
#endif
@@ -210,14 +210,14 @@ int repl(const b_command *cmd, const b_arglist *args, const b_array *_)
return -1;
}
repl->r_show_lex = b_arglist_get_count(
args, OPT_SHOW_LEX_TOKENS, B_COMMAND_INVALID_ID)
repl->r_show_lex = fx_arglist_get_count(
args, OPT_SHOW_LEX_TOKENS, FX_COMMAND_INVALID_ID)
> 0;
repl->r_show_ast = b_arglist_get_count(
args, OPT_SHOW_AST_NODES, B_COMMAND_INVALID_ID)
repl->r_show_ast = fx_arglist_get_count(
args, OPT_SHOW_AST_NODES, FX_COMMAND_INVALID_ID)
> 0;
repl->r_show_ir
= b_arglist_get_count(args, OPT_SHOW_IR, B_COMMAND_INVALID_ID) > 0;
= fx_arglist_get_count(args, OPT_SHOW_IR, FX_COMMAND_INVALID_ID) > 0;
while (true) {
struct ivy_token *tok = ivy_lexer_read(repl->r_lex);
@@ -227,7 +227,7 @@ int repl(const b_command *cmd, const b_arglist *args, const b_array *_)
}
if (status != IVY_OK) {
b_err("lex error (%s)",
fx_err("lex error (%s)",
ivy_status_to_string(
ivy_lexer_get_status(repl->r_lex)));
continue;
@@ -240,7 +240,7 @@ int repl(const b_command *cmd, const b_arglist *args, const b_array *_)
status = ivy_parser_push_token(repl->r_parse, tok);
if (status != IVY_OK) {
b_err("parse error (%s)", ivy_status_to_string(status));
fx_err("parse error (%s)", ivy_status_to_string(status));
ivy_token_destroy(tok);
skip_line(repl->r_lex);
continue;
@@ -273,33 +273,33 @@ int repl(const b_command *cmd, const b_arglist *args, const b_array *_)
B_COMMAND(CMD_REPL, CMD_ROOT)
{
B_COMMAND_NAME("shell");
B_COMMAND_SHORT_NAME('S');
B_COMMAND_DESC("start an interactive Ivy shell.");
B_COMMAND_HELP_OPTION();
B_COMMAND_FUNCTION(repl);
FX_COMMAND_NAME("shell");
FX_COMMAND_SHORT_NAME('S');
FX_COMMAND_DESC("start an interactive Ivy shell.");
FX_COMMAND_HELP_OPTION();
FX_COMMAND_FUNCTION(repl);
B_COMMAND_OPTION(OPT_SHOW_LEX_TOKENS)
FX_COMMAND_OPTION(OPT_SHOW_LEX_TOKENS)
{
B_OPTION_LONG_NAME("show-lex");
B_OPTION_SHORT_NAME('l');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("show-lex");
FX_OPTION_SHORT_NAME('l');
FX_OPTION_DESC(
"print the lexical tokens generated from the input.");
}
B_COMMAND_OPTION(OPT_SHOW_AST_NODES)
FX_COMMAND_OPTION(OPT_SHOW_AST_NODES)
{
B_OPTION_LONG_NAME("show-ast");
B_OPTION_SHORT_NAME('a');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("show-ast");
FX_OPTION_SHORT_NAME('a');
FX_OPTION_DESC(
"print the abstract syntax tree generated from the "
"input.");
}
B_COMMAND_OPTION(OPT_SHOW_IR)
FX_COMMAND_OPTION(OPT_SHOW_IR)
{
B_OPTION_LONG_NAME("show-ir");
B_OPTION_SHORT_NAME('i');
B_OPTION_DESC("print the Mie IR generated from the input.");
FX_OPTION_LONG_NAME("show-ir");
FX_OPTION_SHORT_NAME('i');
FX_OPTION_DESC("print the Mie IR generated from the input.");
}
}