meta: replace bluelib with fx
This commit is contained in:
@@ -20,8 +20,8 @@ target_link_libraries(
|
||||
ivy-asm
|
||||
ivy-lang
|
||||
ivy-common
|
||||
Bluelib::Core
|
||||
Bluelib::Ds
|
||||
Bluelib::Cmd)
|
||||
FX::Core
|
||||
FX::Ds
|
||||
FX::Cmd)
|
||||
|
||||
target_compile_definitions(ivy PRIVATE IVY_STATIC=${IVY_STATIC})
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
156
frontend/debug.c
156
frontend/debug.c
@@ -1,7 +1,7 @@
|
||||
#include "debug.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <blue/term.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/term.h>
|
||||
#include <ivy/asm/lex.h>
|
||||
#include <ivy/lang/ast.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
@@ -14,41 +14,41 @@ extern void print_lex_token(struct ivy_token *tok)
|
||||
|
||||
switch (tok->t_type) {
|
||||
case IVY_TOK_KEYWORD:
|
||||
b_puts("[magenta]");
|
||||
fx_puts("[magenta]");
|
||||
break;
|
||||
case IVY_TOK_SYMBOL:
|
||||
b_puts("[blue]");
|
||||
fx_puts("[blue]");
|
||||
break;
|
||||
case IVY_TOK_ATOM:
|
||||
b_puts("[yellow]");
|
||||
fx_puts("[yellow]");
|
||||
break;
|
||||
case IVY_TOK_INT:
|
||||
case IVY_TOK_DOUBLE:
|
||||
b_puts("[yellow]");
|
||||
fx_puts("[yellow]");
|
||||
break;
|
||||
case IVY_TOK_LABEL:
|
||||
b_puts("[red]");
|
||||
fx_puts("[red]");
|
||||
break;
|
||||
case IVY_TOK_IDENT:
|
||||
b_puts("[cyan]");
|
||||
fx_puts("[cyan]");
|
||||
break;
|
||||
case IVY_TOK_STRING:
|
||||
b_puts("[green]");
|
||||
fx_puts("[green]");
|
||||
break;
|
||||
case IVY_TOK_STR_START:
|
||||
b_puts("[green]");
|
||||
fx_puts("[green]");
|
||||
break;
|
||||
case IVY_TOK_STR_END:
|
||||
b_puts("[green]");
|
||||
fx_puts("[green]");
|
||||
break;
|
||||
case IVY_TOK_LINEFEED:
|
||||
b_puts("[dark_grey]");
|
||||
fx_puts("[dark_grey]");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
b_puts(ivy_lex_token_type_to_string(tok->t_type));
|
||||
fx_puts(ivy_lex_token_type_to_string(tok->t_type));
|
||||
|
||||
switch (tok->t_type) {
|
||||
case IVY_TOK_IDENT:
|
||||
@@ -73,40 +73,40 @@ extern void print_lex_token(struct ivy_token *tok)
|
||||
break;
|
||||
}
|
||||
|
||||
b_puts("[reset]\n");
|
||||
fx_puts("[reset]\n");
|
||||
}
|
||||
|
||||
extern void print_asm_lex_token(struct ivy_asm_token *tok)
|
||||
{
|
||||
switch (tok->t_type) {
|
||||
case IVY_ASM_TOK_KEYWORD:
|
||||
b_puts("[magenta]");
|
||||
fx_puts("[magenta]");
|
||||
break;
|
||||
case IVY_ASM_TOK_SYMBOL:
|
||||
b_puts("[blue]");
|
||||
fx_puts("[blue]");
|
||||
break;
|
||||
case IVY_ASM_TOK_INT:
|
||||
case IVY_ASM_TOK_DOUBLE:
|
||||
case IVY_ASM_TOK_LABEL_REF:
|
||||
b_puts("[yellow]");
|
||||
fx_puts("[yellow]");
|
||||
break;
|
||||
case IVY_ASM_TOK_LABEL:
|
||||
b_puts("[red]");
|
||||
fx_puts("[red]");
|
||||
break;
|
||||
case IVY_ASM_TOK_IDENT:
|
||||
b_puts("[cyan]");
|
||||
fx_puts("[cyan]");
|
||||
break;
|
||||
case IVY_ASM_TOK_STRING:
|
||||
b_puts("[green]");
|
||||
fx_puts("[green]");
|
||||
break;
|
||||
case IVY_ASM_TOK_LINEFEED:
|
||||
b_puts("[dark_grey]");
|
||||
fx_puts("[dark_grey]");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
b_puts(ivy_asm_token_type_to_string(tok->t_type));
|
||||
fx_puts(ivy_asm_token_type_to_string(tok->t_type));
|
||||
|
||||
switch (tok->t_type) {
|
||||
case IVY_ASM_TOK_IDENT:
|
||||
@@ -135,7 +135,7 @@ extern void print_asm_lex_token(struct ivy_asm_token *tok)
|
||||
break;
|
||||
}
|
||||
|
||||
b_puts("[reset]\n");
|
||||
fx_puts("[reset]\n");
|
||||
}
|
||||
|
||||
extern enum ivy_status print_ast_node(
|
||||
@@ -154,7 +154,7 @@ extern enum ivy_status print_ast_node(
|
||||
|
||||
if (!args || (args && args->indent)) {
|
||||
for (unsigned int i = 0; i < node->n_it.it_depth; i++) {
|
||||
b_puts(" ");
|
||||
fx_puts(" ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,13 +172,13 @@ extern enum ivy_status print_ast_node(
|
||||
case IVY_AST_TRY:
|
||||
case IVY_AST_RETURN:
|
||||
case IVY_AST_GLOBAL:
|
||||
b_puts("[magenta]");
|
||||
fx_puts("[magenta]");
|
||||
break;
|
||||
case IVY_AST_OP:
|
||||
b_puts("[blue]");
|
||||
fx_puts("[blue]");
|
||||
break;
|
||||
case IVY_AST_MSG:
|
||||
b_puts("[red]");
|
||||
fx_puts("[red]");
|
||||
break;
|
||||
case IVY_AST_INT:
|
||||
case IVY_AST_DOUBLE:
|
||||
@@ -187,73 +187,73 @@ extern enum ivy_status print_ast_node(
|
||||
case IVY_AST_C_TRUE:
|
||||
case IVY_AST_C_FALSE:
|
||||
case IVY_AST_C_NULL:
|
||||
b_puts("[yellow]");
|
||||
fx_puts("[yellow]");
|
||||
break;
|
||||
case IVY_AST_COND:
|
||||
case IVY_AST_BLOCK:
|
||||
case IVY_AST_TRY_CATCH:
|
||||
b_puts("[red]");
|
||||
fx_puts("[red]");
|
||||
break;
|
||||
case IVY_AST_IDENT:
|
||||
case IVY_AST_SELECTOR:
|
||||
b_puts("[cyan]");
|
||||
fx_puts("[cyan]");
|
||||
break;
|
||||
case IVY_AST_STRING:
|
||||
case IVY_AST_FSTRING:
|
||||
b_puts("[green]");
|
||||
fx_puts("[green]");
|
||||
break;
|
||||
case IVY_AST_DISCARD:
|
||||
b_puts("[dark_grey]");
|
||||
fx_puts("[dark_grey]");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
b_string *str = b_string_create();
|
||||
fx_string *str = fx_string_create();
|
||||
ivy_ast_node_to_string(node, str);
|
||||
b_printf("%s", b_string_ptr(str));
|
||||
b_string_unref(str);
|
||||
fx_printf("%s", fx_string_ptr(str));
|
||||
fx_string_unref(str);
|
||||
|
||||
#if 0
|
||||
b_puts(ivy_ast_node_type_to_string(node->n_type));
|
||||
fx_puts(ivy_ast_node_type_to_string(node->n_type));
|
||||
|
||||
switch (node->n_type) {
|
||||
case IVY_AST_INT: {
|
||||
struct ivy_ast_int_node *v = (struct ivy_ast_int_node *)node;
|
||||
b_printf(" (%llu)", v->n_value->t_int);
|
||||
fx_printf(" (%llu)", v->n_value->t_int);
|
||||
break;
|
||||
}
|
||||
case IVY_AST_DOUBLE: {
|
||||
struct ivy_ast_double_node *v = (struct ivy_ast_double_node *)node;
|
||||
b_printf(" (%.2lf)", v->n_value->t_double);
|
||||
fx_printf(" (%.2lf)", v->n_value->t_double);
|
||||
break;
|
||||
}
|
||||
case IVY_AST_IDENT: {
|
||||
struct ivy_ast_ident_node *v = (struct ivy_ast_ident_node *)node;
|
||||
b_printf(" (%s)", v->n_content->t_str);
|
||||
fx_printf(" (%s)", v->n_content->t_str);
|
||||
break;
|
||||
}
|
||||
case IVY_AST_STRING: {
|
||||
struct ivy_ast_string_node *v = (struct ivy_ast_string_node *)node;
|
||||
b_printf(" (\"%s\")", v->n_value->t_str);
|
||||
fx_printf(" (\"%s\")", v->n_value->t_str);
|
||||
break;
|
||||
}
|
||||
case IVY_AST_ATOM: {
|
||||
struct ivy_ast_atom_node *v = (struct ivy_ast_atom_node *)node;
|
||||
b_printf(" (%s)", v->n_content->t_str);
|
||||
fx_printf(" (%s)", v->n_content->t_str);
|
||||
break;
|
||||
}
|
||||
case IVY_AST_SELECTOR: {
|
||||
struct ivy_ast_selector_node *v
|
||||
= (struct ivy_ast_selector_node *)node;
|
||||
b_printf(" [[");
|
||||
fx_printf(" [[");
|
||||
|
||||
switch (v->n_recipient) {
|
||||
case IVY_SELECTOR_RECIPIENT_CLASS:
|
||||
b_putc('+');
|
||||
fx_putc('+');
|
||||
break;
|
||||
case IVY_SELECTOR_RECIPIENT_OBJECT:
|
||||
b_putc('-');
|
||||
fx_putc('-');
|
||||
break;
|
||||
default:
|
||||
/* this will occur if the selector is being used to send
|
||||
@@ -263,101 +263,101 @@ extern enum ivy_status print_ast_node(
|
||||
}
|
||||
|
||||
if (v->n_msg_name) {
|
||||
b_printf("%s", v->n_msg_name->t_str);
|
||||
fx_printf("%s", v->n_msg_name->t_str);
|
||||
}
|
||||
|
||||
if (v->n_msg_name && !b_queue_empty(&v->n_arg_labels)) {
|
||||
b_putc('(');
|
||||
if (v->n_msg_name && !fx_queue_empty(&v->n_arg_labels)) {
|
||||
fx_putc('(');
|
||||
}
|
||||
|
||||
b_queue_iterator label_it = {0};
|
||||
b_queue_iterator name_it = {0};
|
||||
fx_queue_iterator label_it = {0};
|
||||
fx_queue_iterator name_it = {0};
|
||||
|
||||
b_queue_iterator_begin(&v->n_arg_labels, &label_it);
|
||||
b_queue_iterator_begin(&v->n_arg_names, &name_it);
|
||||
fx_queue_iterator_begin(&v->n_arg_labels, &label_it);
|
||||
fx_queue_iterator_begin(&v->n_arg_names, &name_it);
|
||||
|
||||
bool name_present = false;
|
||||
int i = 0;
|
||||
while (b_queue_iterator_is_valid(&label_it)) {
|
||||
while (fx_queue_iterator_is_valid(&label_it)) {
|
||||
if (i > 0 && name_present) {
|
||||
fputc(' ', stdout);
|
||||
}
|
||||
|
||||
struct ivy_token *label = b_unbox(
|
||||
struct ivy_token *label = fx_unbox(
|
||||
struct ivy_token, label_it.entry, t_entry);
|
||||
struct ivy_token *name = b_unbox(
|
||||
struct ivy_token *name = fx_unbox(
|
||||
struct ivy_token, name_it.entry, t_entry);
|
||||
|
||||
if (label) {
|
||||
b_printf("%s:", label->t_str);
|
||||
fx_printf("%s:", label->t_str);
|
||||
}
|
||||
|
||||
if (name) {
|
||||
b_printf("%s", name->t_str);
|
||||
fx_printf("%s", name->t_str);
|
||||
}
|
||||
|
||||
name_present = (name != NULL);
|
||||
|
||||
i++;
|
||||
b_queue_iterator_next(&label_it);
|
||||
b_queue_iterator_next(&name_it);
|
||||
fx_queue_iterator_next(&label_it);
|
||||
fx_queue_iterator_next(&name_it);
|
||||
}
|
||||
|
||||
if (v->n_msg_name && !b_queue_empty(&v->n_arg_labels)) {
|
||||
b_putc(')');
|
||||
if (v->n_msg_name && !fx_queue_empty(&v->n_arg_labels)) {
|
||||
fx_putc(')');
|
||||
}
|
||||
|
||||
b_puts("]");
|
||||
fx_puts("]");
|
||||
break;
|
||||
}
|
||||
case IVY_AST_OP: {
|
||||
struct ivy_ast_op_node *v = (struct ivy_ast_op_node *)node;
|
||||
b_printf(" (%s)", ivy_operator_id_to_string(v->n_op->op_id));
|
||||
fx_printf(" (%s)", ivy_operator_id_to_string(v->n_op->op_id));
|
||||
break;
|
||||
}
|
||||
case IVY_AST_CLASS: {
|
||||
struct ivy_ast_class_node *v = (struct ivy_ast_class_node *)node;
|
||||
b_printf(" (%s)", v->n_ident->t_str);
|
||||
fx_printf(" (%s)", v->n_ident->t_str);
|
||||
break;
|
||||
}
|
||||
case IVY_AST_UNIT_PACKAGE: {
|
||||
struct ivy_ast_unit_package_node *v
|
||||
= (struct ivy_ast_unit_package_node *)node;
|
||||
b_printf(" (");
|
||||
b_queue_iterator it = {0};
|
||||
fx_printf(" (");
|
||||
fx_queue_iterator it = {0};
|
||||
int i = 0;
|
||||
b_queue_foreach (&it, &v->n_ident) {
|
||||
fx_queue_foreach (&it, &v->n_ident) {
|
||||
struct ivy_token *tok
|
||||
= b_unbox(struct ivy_token, it.entry, t_entry);
|
||||
= fx_unbox(struct ivy_token, it.entry, t_entry);
|
||||
|
||||
if (i > 0) {
|
||||
b_printf(".");
|
||||
fx_printf(".");
|
||||
}
|
||||
|
||||
b_printf("%s", tok->t_str);
|
||||
fx_printf("%s", tok->t_str);
|
||||
i++;
|
||||
}
|
||||
b_printf(")");
|
||||
fx_printf(")");
|
||||
break;
|
||||
}
|
||||
case IVY_AST_UNIT_IMPORT: {
|
||||
struct ivy_ast_unit_import_node *v
|
||||
= (struct ivy_ast_unit_import_node *)node;
|
||||
b_printf(" (");
|
||||
b_queue_iterator it = {0};
|
||||
fx_printf(" (");
|
||||
fx_queue_iterator it = {0};
|
||||
int i = 0;
|
||||
b_queue_foreach (&it, &v->n_ident) {
|
||||
fx_queue_foreach (&it, &v->n_ident) {
|
||||
struct ivy_token *tok
|
||||
= b_unbox(struct ivy_token, it.entry, t_entry);
|
||||
= fx_unbox(struct ivy_token, it.entry, t_entry);
|
||||
|
||||
if (i > 0) {
|
||||
b_printf(".");
|
||||
fx_printf(".");
|
||||
}
|
||||
|
||||
b_printf("%s", tok->t_str);
|
||||
fx_printf("%s", tok->t_str);
|
||||
i++;
|
||||
}
|
||||
b_printf(")");
|
||||
fx_printf(")");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -389,6 +389,6 @@ extern enum ivy_status print_ast_node(
|
||||
}
|
||||
#endif
|
||||
|
||||
b_puts("[reset]\n");
|
||||
fx_puts("[reset]\n");
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
#include "line-ed.h"
|
||||
|
||||
#include <blue/ds/array.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/ds/array.h>
|
||||
#include <fx/ds/string.h>
|
||||
|
||||
void alloc_empty_history_entry(struct line_ed *ed)
|
||||
{
|
||||
b_string *str = (b_string *)b_array_at(
|
||||
ed->l_history, b_array_size(ed->l_history) - 1);
|
||||
if (!str || b_string_get_size(str, B_STRLEN_NORMAL) > 0) {
|
||||
str = b_string_create();
|
||||
b_array_append(ed->l_history, (b_object *)str);
|
||||
fx_string *str = (fx_string *)fx_array_at(
|
||||
ed->l_history, fx_array_size(ed->l_history) - 1);
|
||||
if (!str || fx_string_get_size(str, FX_STRLEN_NORMAL) > 0) {
|
||||
str = fx_string_create();
|
||||
fx_array_append(ed->l_history, (fx_object *)str);
|
||||
}
|
||||
|
||||
ed->l_history_pos = b_array_size(ed->l_history) - 1;
|
||||
ed->l_history_pos = fx_array_size(ed->l_history) - 1;
|
||||
}
|
||||
|
||||
void save_buf_to_history(struct line_ed *ed)
|
||||
{
|
||||
b_string *cur = (b_string *)b_array_get(ed->l_history, ed->l_history_pos);
|
||||
b_string_replace_all(cur, ed->l_buf);
|
||||
fx_string *cur = (fx_string *)fx_array_get(ed->l_history, ed->l_history_pos);
|
||||
fx_string_replace_all(cur, ed->l_buf);
|
||||
}
|
||||
|
||||
void append_buf_to_history(struct line_ed *ed)
|
||||
{
|
||||
b_string *cur = (b_string *)b_array_get(ed->l_history, ed->l_history_pos);
|
||||
fx_string *cur = (fx_string *)fx_array_get(ed->l_history, ed->l_history_pos);
|
||||
char s[] = {'\n', 0};
|
||||
b_string_append_cstr(cur, s);
|
||||
b_string_append_cstr(cur, ed->l_buf);
|
||||
fx_string_append_cstr(cur, s);
|
||||
fx_string_append_cstr(cur, ed->l_buf);
|
||||
}
|
||||
|
||||
void load_buf_from_history(struct line_ed *ed)
|
||||
{
|
||||
b_string *cur = (b_string *)b_array_at(ed->l_history, ed->l_history_pos);
|
||||
fx_string *cur = (fx_string *)fx_array_at(ed->l_history, ed->l_history_pos);
|
||||
size_t len
|
||||
= MIN((size_t)(ed->l_buf_end - ed->l_buf - 1),
|
||||
b_string_get_size(cur, B_STRLEN_NORMAL));
|
||||
fx_string_get_size(cur, FX_STRLEN_NORMAL));
|
||||
|
||||
memcpy(ed->l_buf, b_string_ptr(cur), len);
|
||||
memcpy(ed->l_buf, fx_string_ptr(cur), len);
|
||||
ed->l_buf[len] = '\0';
|
||||
|
||||
unsigned int x = 0, y = 0;
|
||||
@@ -57,11 +57,11 @@ void load_buf_from_history(struct line_ed *ed)
|
||||
|
||||
const char *last_history_line(struct line_ed *ed)
|
||||
{
|
||||
size_t nlines = b_array_size(ed->l_history);
|
||||
size_t nlines = fx_array_size(ed->l_history);
|
||||
if (nlines < 2) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_string *last = (b_string *)b_array_at(ed->l_history, nlines - 2);
|
||||
return b_string_ptr(last);
|
||||
fx_string *last = (fx_string *)fx_array_at(ed->l_history, nlines - 2);
|
||||
return fx_string_ptr(last);
|
||||
}
|
||||
|
||||
@@ -30,22 +30,22 @@ int compare_coords(size_t ax, size_t ay, size_t bx, size_t by)
|
||||
|
||||
struct hl_range *get_hl_range(struct line_ed *ed, size_t x, size_t y)
|
||||
{
|
||||
if (b_queue_empty(&ed->l_hl_ranges)) {
|
||||
if (fx_queue_empty(&ed->l_hl_ranges)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct hl_range *best_match = NULL;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&ed->l_hl_ranges);
|
||||
fx_queue_entry *entry = fx_queue_first(&ed->l_hl_ranges);
|
||||
while (entry) {
|
||||
struct hl_range *cur = b_unbox(struct hl_range, entry, h_entry);
|
||||
struct hl_range *cur = fx_unbox(struct hl_range, entry, h_entry);
|
||||
int cmp_end = compare_coords(x, y, cur->h_end_x, cur->h_end_y);
|
||||
|
||||
if (cmp_end != 1) {
|
||||
return cur;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -53,20 +53,20 @@ struct hl_range *get_hl_range(struct line_ed *ed, size_t x, size_t y)
|
||||
|
||||
struct hl_range *get_next_hl_range(struct hl_range *range)
|
||||
{
|
||||
b_queue_entry *entry = &range->h_entry;
|
||||
entry = b_queue_next(entry);
|
||||
fx_queue_entry *entry = &range->h_entry;
|
||||
entry = fx_queue_next(entry);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
range = b_unbox(struct hl_range, entry, h_entry);
|
||||
range = fx_unbox(struct hl_range, entry, h_entry);
|
||||
return range;
|
||||
}
|
||||
|
||||
int apply_hl_range(struct hl_range *range, b_tty *tty, size_t x, size_t y)
|
||||
int apply_hl_range(struct hl_range *range, fx_tty *tty, size_t x, size_t y)
|
||||
{
|
||||
if (!range) {
|
||||
b_tty_reset_vmode(tty);
|
||||
fx_tty_reset_vmode(tty);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -74,11 +74,11 @@ int apply_hl_range(struct hl_range *range, b_tty *tty, size_t x, size_t y)
|
||||
int cmp_end = compare_coords(x, y, range->h_end_x, range->h_end_y);
|
||||
|
||||
if (cmp_start < 0) {
|
||||
b_tty_reset_vmode(tty);
|
||||
fx_tty_reset_vmode(tty);
|
||||
}
|
||||
|
||||
if (cmp_start >= 0 && cmp_end <= 0) {
|
||||
b_tty_set_vmode(tty, &range->h_vmode);
|
||||
fx_tty_set_vmode(tty, &range->h_vmode);
|
||||
}
|
||||
|
||||
if (cmp_end == 1) {
|
||||
@@ -90,7 +90,7 @@ int apply_hl_range(struct hl_range *range, b_tty *tty, size_t x, size_t y)
|
||||
|
||||
struct hl_range *create_highlight(
|
||||
size_t start_x, size_t start_y, size_t end_x, size_t end_y,
|
||||
const b_tty_vmode *vmode)
|
||||
const fx_tty_vmode *vmode)
|
||||
{
|
||||
struct hl_range *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
@@ -179,7 +179,7 @@ static void move_start_to_meet_end(
|
||||
|
||||
void line_ed_put_highlight(
|
||||
struct line_ed *ed, unsigned long start_x, unsigned long start_y,
|
||||
unsigned long end_x, unsigned long end_y, const struct b_tty_vmode *vmode)
|
||||
unsigned long end_x, unsigned long end_y, const struct fx_tty_vmode *vmode)
|
||||
{
|
||||
struct hl_range *highlight
|
||||
= create_highlight(start_x, start_y, end_x, end_y, vmode);
|
||||
@@ -189,30 +189,30 @@ void line_ed_put_highlight(
|
||||
|
||||
struct hl_range *h2 = NULL;
|
||||
|
||||
b_queue_entry *entry = NULL;
|
||||
entry = b_queue_first(&ed->l_hl_ranges);
|
||||
fx_queue_entry *entry = NULL;
|
||||
entry = fx_queue_first(&ed->l_hl_ranges);
|
||||
|
||||
if (!entry) {
|
||||
b_queue_push_back(&ed->l_hl_ranges, &highlight->h_entry);
|
||||
fx_queue_push_back(&ed->l_hl_ranges, &highlight->h_entry);
|
||||
return;
|
||||
}
|
||||
|
||||
struct hl_range *cur = NULL;
|
||||
enum hl_range_comparison prev_cmp = -1;
|
||||
|
||||
b_queue_entry *insert_before = NULL;
|
||||
b_queue_entry *insert_after = NULL;
|
||||
fx_queue_entry *insert_before = NULL;
|
||||
fx_queue_entry *insert_after = NULL;
|
||||
|
||||
bool end = false;
|
||||
while (entry) {
|
||||
b_queue_entry *next = b_queue_next(entry);
|
||||
cur = b_unbox(struct hl_range, entry, h_entry);
|
||||
fx_queue_entry *next = fx_queue_next(entry);
|
||||
cur = fx_unbox(struct hl_range, entry, h_entry);
|
||||
|
||||
enum hl_range_comparison cmp = compare_hl_ranges(cur, highlight);
|
||||
|
||||
switch (cmp) {
|
||||
case HL_RANGE_A_IN_B:
|
||||
b_queue_delete(&ed->l_hl_ranges, entry);
|
||||
fx_queue_delete(&ed->l_hl_ranges, entry);
|
||||
free(cur);
|
||||
break;
|
||||
case HL_RANGE_B_IN_A:
|
||||
@@ -220,10 +220,10 @@ void line_ed_put_highlight(
|
||||
h2 = create_highlight(
|
||||
0, 0, cur->h_end_x, cur->h_end_y, &cur->h_vmode);
|
||||
move_start_to_meet_end(h2, highlight);
|
||||
b_queue_insert_after(
|
||||
fx_queue_insert_after(
|
||||
&ed->l_hl_ranges, &highlight->h_entry,
|
||||
&cur->h_entry);
|
||||
b_queue_insert_after(
|
||||
fx_queue_insert_after(
|
||||
&ed->l_hl_ranges, &h2->h_entry,
|
||||
&highlight->h_entry);
|
||||
insert_before = insert_after = NULL;
|
||||
@@ -239,7 +239,7 @@ void line_ed_put_highlight(
|
||||
insert_before = entry;
|
||||
break;
|
||||
case HL_RANGE_GREATER:
|
||||
b_queue_insert_before(
|
||||
fx_queue_insert_before(
|
||||
&ed->l_hl_ranges, &highlight->h_entry, entry);
|
||||
insert_before = insert_after = NULL;
|
||||
end = true;
|
||||
@@ -255,32 +255,32 @@ void line_ed_put_highlight(
|
||||
}
|
||||
|
||||
if (insert_before) {
|
||||
b_queue_insert_before(
|
||||
fx_queue_insert_before(
|
||||
&ed->l_hl_ranges, &highlight->h_entry, insert_before);
|
||||
} else if (insert_after) {
|
||||
b_queue_insert_after(
|
||||
fx_queue_insert_after(
|
||||
&ed->l_hl_ranges, &highlight->h_entry, insert_after);
|
||||
}
|
||||
}
|
||||
|
||||
void line_ed_clear_highlights(struct line_ed *ed)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_pop_front(&ed->l_hl_ranges);
|
||||
fx_queue_entry *entry = fx_queue_pop_front(&ed->l_hl_ranges);
|
||||
while (entry) {
|
||||
struct hl_range *range = b_unbox(struct hl_range, entry, h_entry);
|
||||
struct hl_range *range = fx_unbox(struct hl_range, entry, h_entry);
|
||||
free(range);
|
||||
|
||||
entry = b_queue_pop_front(&ed->l_hl_ranges);
|
||||
entry = fx_queue_pop_front(&ed->l_hl_ranges);
|
||||
}
|
||||
}
|
||||
|
||||
void line_ed_print_highlights(struct line_ed *ed)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&ed->l_hl_ranges);
|
||||
fx_queue_entry *entry = fx_queue_first(&ed->l_hl_ranges);
|
||||
while (entry) {
|
||||
struct hl_range *h = b_unbox(struct hl_range, entry, h_entry);
|
||||
struct hl_range *h = fx_unbox(struct hl_range, entry, h_entry);
|
||||
printf("(%zu, %zu) -> (%zu, %zu)\n", h->h_start_x, h->h_start_y,
|
||||
h->h_end_x, h->h_end_y);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef LINE_ED_HL_RANGE_H_
|
||||
#define LINE_ED_HL_RANGE_H_
|
||||
|
||||
#include <blue/term/tty.h>
|
||||
#include <fx/term/tty.h>
|
||||
|
||||
#include <blue/core/queue.h>
|
||||
#include <fx/core/queue.h>
|
||||
|
||||
struct line_ed;
|
||||
|
||||
@@ -20,18 +20,18 @@ enum hl_range_comparison {
|
||||
struct hl_range {
|
||||
size_t h_start_x, h_start_y;
|
||||
size_t h_end_x, h_end_y;
|
||||
b_tty_vmode h_vmode;
|
||||
b_queue_entry h_entry;
|
||||
fx_tty_vmode h_vmode;
|
||||
fx_queue_entry h_entry;
|
||||
};
|
||||
|
||||
extern int compare_coords(size_t ax, size_t ay, size_t bx, size_t by);
|
||||
extern struct hl_range *get_hl_range(struct line_ed *ed, size_t x, size_t y);
|
||||
extern struct hl_range *get_next_hl_range(struct hl_range *range);
|
||||
extern int apply_hl_range(struct hl_range *range, b_tty *tty, size_t x, size_t y);
|
||||
extern int apply_hl_range(struct hl_range *range, fx_tty *tty, size_t x, size_t y);
|
||||
|
||||
extern struct hl_range *create_highlight(
|
||||
size_t start_x, size_t start_y, size_t end_x, size_t end_y,
|
||||
const struct b_tty_vmode *vmode);
|
||||
const struct fx_tty_vmode *vmode);
|
||||
extern enum hl_range_comparison compare_hl_ranges(
|
||||
const struct hl_range *a, const struct hl_range *b);
|
||||
|
||||
|
||||
@@ -4,38 +4,38 @@
|
||||
|
||||
void line_ed_add_hook(struct line_ed *ed, struct line_ed_hook *hook)
|
||||
{
|
||||
b_queue_push_back(&ed->l_hooks, &hook->hook_entry);
|
||||
fx_queue_push_back(&ed->l_hooks, &hook->hook_entry);
|
||||
}
|
||||
|
||||
void line_ed_remove_hook(struct line_ed *ed, struct line_ed_hook *hook)
|
||||
{
|
||||
b_queue_delete(&ed->l_hooks, &hook->hook_entry);
|
||||
fx_queue_delete(&ed->l_hooks, &hook->hook_entry);
|
||||
}
|
||||
|
||||
void hook_keypress(struct line_ed *ed, b_keycode key)
|
||||
void hook_keypress(struct line_ed *ed, fx_keycode key)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&ed->l_hooks);
|
||||
fx_queue_entry *entry = fx_queue_first(&ed->l_hooks);
|
||||
while (entry) {
|
||||
struct line_ed_hook *hook
|
||||
= b_unbox(struct line_ed_hook, entry, hook_entry);
|
||||
= fx_unbox(struct line_ed_hook, entry, hook_entry);
|
||||
if (hook->hook_keypress) {
|
||||
hook->hook_keypress(ed, hook, key);
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
void hook_buffer_modified(struct line_ed *ed)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&ed->l_hooks);
|
||||
fx_queue_entry *entry = fx_queue_first(&ed->l_hooks);
|
||||
while (entry) {
|
||||
struct line_ed_hook *hook
|
||||
= b_unbox(struct line_ed_hook, entry, hook_entry);
|
||||
= fx_unbox(struct line_ed_hook, entry, hook_entry);
|
||||
if (hook->hook_buffer_modified) {
|
||||
hook->hook_buffer_modified(ed, hook);
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef LINE_ED_HOOK_H_
|
||||
#define LINE_ED_HOOK_H_
|
||||
|
||||
#include <blue/term/tty.h>
|
||||
#include <fx/term/tty.h>
|
||||
|
||||
enum hook_id {
|
||||
HOOK_KEYPRESS,
|
||||
@@ -10,7 +10,7 @@ enum hook_id {
|
||||
|
||||
struct line_ed;
|
||||
|
||||
extern void hook_keypress(struct line_ed *ed, b_keycode key);
|
||||
extern void hook_keypress(struct line_ed *ed, fx_keycode key);
|
||||
extern void hook_buffer_modified(struct line_ed *ed);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -113,7 +113,7 @@ void cursor_left(struct line_ed *ed)
|
||||
{
|
||||
if (ed->l_cursor_x != 0) {
|
||||
//fputs("\010", stdout);
|
||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -1);
|
||||
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_CURSOR, -1);
|
||||
fflush(stdout);
|
||||
ed->l_cursor_x--;
|
||||
ed->l_buf_ptr--;
|
||||
@@ -135,8 +135,8 @@ void cursor_left(struct line_ed *ed)
|
||||
ed->l_cursor_x = len - 1;
|
||||
|
||||
//printf("\033[A\033[%dG", len + prompt_len);
|
||||
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, -1);
|
||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_START, (int)(len + prompt_len));
|
||||
fx_tty_move_cursor_y(ed->l_tty, FX_TTY_POS_CURSOR, -1);
|
||||
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_START, (int)(len + prompt_len));
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
@@ -151,7 +151,7 @@ void cursor_right(struct line_ed *ed)
|
||||
ed->l_cursor_x++;
|
||||
ed->l_buf_ptr++;
|
||||
//fputs("\033[C", stdout);
|
||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, 1);
|
||||
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_CURSOR, 1);
|
||||
fflush(stdout);
|
||||
return;
|
||||
}
|
||||
@@ -165,8 +165,8 @@ void cursor_right(struct line_ed *ed)
|
||||
ed->l_buf_ptr++;
|
||||
|
||||
//printf("\033[B\033[G");
|
||||
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, 1);
|
||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_START, 0);
|
||||
fx_tty_move_cursor_y(ed->l_tty, FX_TTY_POS_CURSOR, 1);
|
||||
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_START, 0);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
@@ -178,13 +178,13 @@ void arrow_up(struct line_ed *ed)
|
||||
|
||||
if (ed->l_cursor_y > 0) {
|
||||
//printf("\033[%uA", ed->l_cursor_y);
|
||||
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, (long long)ed->l_cursor_y);
|
||||
fx_tty_move_cursor_y(ed->l_tty, FX_TTY_POS_CURSOR, (long long)ed->l_cursor_y);
|
||||
}
|
||||
|
||||
//printf("\033[%zuG\033[J", prompt_length(ed, PROMPT_MAIN) + 1);
|
||||
b_tty_move_cursor_x(
|
||||
ed->l_tty, B_TTY_POS_START, (long long)prompt_length(ed, PROMPT_MAIN));
|
||||
b_tty_clear(ed->l_tty, B_TTY_CLEAR_SCREEN | B_TTY_CLEAR_FROM_CURSOR);
|
||||
fx_tty_move_cursor_x(
|
||||
ed->l_tty, FX_TTY_POS_START, (long long)prompt_length(ed, PROMPT_MAIN));
|
||||
fx_tty_clear(ed->l_tty, FX_TTY_CLEAR_SCREEN | FX_TTY_CLEAR_FROM_CURSOR);
|
||||
|
||||
save_buf_to_history(ed);
|
||||
ed->l_history_pos--;
|
||||
@@ -196,18 +196,18 @@ void arrow_up(struct line_ed *ed)
|
||||
|
||||
void arrow_down(struct line_ed *ed)
|
||||
{
|
||||
if (ed->l_history_pos == b_array_size(ed->l_history) - 1) {
|
||||
if (ed->l_history_pos == fx_array_size(ed->l_history) - 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ed->l_cursor_y > 0) {
|
||||
//printf("\033[%uA", ed->l_cursor_y);
|
||||
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, (int)ed->l_cursor_y);
|
||||
fx_tty_move_cursor_y(ed->l_tty, FX_TTY_POS_CURSOR, (int)ed->l_cursor_y);
|
||||
}
|
||||
|
||||
//printf("\033[%zuG\033[J", prompt_length(ed, PROMPT_MAIN) + 1);
|
||||
b_tty_move_cursor_x(
|
||||
ed->l_tty, B_TTY_POS_START, prompt_length(ed, PROMPT_MAIN) + 1);
|
||||
fx_tty_move_cursor_x(
|
||||
ed->l_tty, FX_TTY_POS_START, prompt_length(ed, PROMPT_MAIN) + 1);
|
||||
|
||||
save_buf_to_history(ed);
|
||||
ed->l_history_pos++;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "input.h"
|
||||
#include "prompt.h"
|
||||
|
||||
#include <blue/term/tty.h>
|
||||
#include <fx/term/tty.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -49,14 +49,14 @@ struct line_ed *line_ed_create(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out->l_history = b_array_create();
|
||||
out->l_history = fx_array_create();
|
||||
if (!out->l_history) {
|
||||
free(out->l_buf);
|
||||
free(out);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out->l_tty = b_stdtty;
|
||||
out->l_tty = fx_stdtty;
|
||||
out->l_buf_end = out->l_buf + LINE_MAX;
|
||||
out->l_buf_ptr = out->l_buf;
|
||||
out->l_line_end = out->l_buf;
|
||||
@@ -71,7 +71,7 @@ struct line_ed *line_ed_create(void)
|
||||
|
||||
void line_ed_destroy(struct line_ed *ed)
|
||||
{
|
||||
b_array_unref(ed->l_history);
|
||||
fx_array_unref(ed->l_history);
|
||||
line_ed_clear_highlights(ed);
|
||||
free(ed->l_buf);
|
||||
free(ed);
|
||||
@@ -181,8 +181,8 @@ size_t line_ed_readline(struct line_ed *ed, char *out, size_t max)
|
||||
append_to_index = ed->l_history_pos;
|
||||
}
|
||||
|
||||
b_tty *tty = ed->l_tty;
|
||||
b_tty_set_mode(tty, B_TTY_RAW);
|
||||
fx_tty *tty = ed->l_tty;
|
||||
fx_tty_set_mode(tty, FX_TTY_RAW);
|
||||
show_prompt(ed);
|
||||
|
||||
for (int i = 0; ed->l_buf[i]; i++) {
|
||||
@@ -198,10 +198,10 @@ size_t line_ed_readline(struct line_ed *ed, char *out, size_t max)
|
||||
bool eof = false;
|
||||
|
||||
while (!end) {
|
||||
b_keycode key = b_tty_read_key(tty);
|
||||
fx_keycode key = fx_tty_read_key(tty);
|
||||
hook_keypress(ed, key);
|
||||
|
||||
if (key == B_TTY_CTRL_KEY('d')) {
|
||||
if (key == FX_TTY_CTRL_KEY('d')) {
|
||||
if (!input_is_empty(ed)) {
|
||||
continue;
|
||||
}
|
||||
@@ -210,13 +210,13 @@ size_t line_ed_readline(struct line_ed *ed, char *out, size_t max)
|
||||
break;
|
||||
}
|
||||
|
||||
if (key & B_MOD_CTRL) {
|
||||
if (key & FX_MOD_CTRL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
case B_KEY_RETURN:
|
||||
b_tty_reset_vmode(tty);
|
||||
case FX_KEY_RETURN:
|
||||
fx_tty_reset_vmode(tty);
|
||||
if (ed->l_line_end > ed->l_buf
|
||||
&& *(ed->l_line_end - 1) != '\\') {
|
||||
end = true;
|
||||
@@ -243,19 +243,19 @@ size_t line_ed_readline(struct line_ed *ed, char *out, size_t max)
|
||||
// fputs("\033[G\n", stdout);
|
||||
show_prompt(ed);
|
||||
break;
|
||||
case B_KEY_BACKSPACE:
|
||||
case FX_KEY_BACKSPACE:
|
||||
backspace(ed);
|
||||
break;
|
||||
case B_KEY_ARROW_LEFT:
|
||||
case FX_KEY_ARROW_LEFT:
|
||||
cursor_left(ed);
|
||||
break;
|
||||
case B_KEY_ARROW_RIGHT:
|
||||
case FX_KEY_ARROW_RIGHT:
|
||||
cursor_right(ed);
|
||||
break;
|
||||
case B_KEY_ARROW_UP:
|
||||
case FX_KEY_ARROW_UP:
|
||||
arrow_up(ed);
|
||||
break;
|
||||
case B_KEY_ARROW_DOWN:
|
||||
case FX_KEY_ARROW_DOWN:
|
||||
arrow_down(ed);
|
||||
break;
|
||||
default:
|
||||
@@ -266,7 +266,7 @@ size_t line_ed_readline(struct line_ed *ed, char *out, size_t max)
|
||||
}
|
||||
}
|
||||
|
||||
b_tty_set_mode(tty, B_TTY_CANONICAL);
|
||||
fx_tty_set_mode(tty, FX_TTY_CANONICAL);
|
||||
fputc('\n', stdout);
|
||||
|
||||
if (*ed->l_buf == '\0') {
|
||||
@@ -277,7 +277,7 @@ size_t line_ed_readline(struct line_ed *ed, char *out, size_t max)
|
||||
ed->l_history_pos = append_to_index;
|
||||
append_buf_to_history(ed);
|
||||
} else {
|
||||
ed->l_history_pos = b_array_size(ed->l_history) - 1;
|
||||
ed->l_history_pos = fx_array_size(ed->l_history) - 1;
|
||||
|
||||
const char *last = last_history_line(ed);
|
||||
if (!last || strcmp(last, ed->l_buf) != 0) {
|
||||
|
||||
@@ -3,21 +3,21 @@
|
||||
|
||||
#define LINE_MAX 4096
|
||||
|
||||
#include <blue/term/tty.h>
|
||||
#include <blue/core/queue.h>
|
||||
#include <blue/ds/array.h>
|
||||
#include <fx/term/tty.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/ds/array.h>
|
||||
#include <ivy/line-source.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct s_tty;
|
||||
struct b_tty_vmode;
|
||||
struct fx_tty_vmode;
|
||||
|
||||
struct line_ed;
|
||||
|
||||
struct line_ed_hook {
|
||||
void (*hook_keypress)(struct line_ed *, struct line_ed_hook *, b_keycode);
|
||||
void (*hook_keypress)(struct line_ed *, struct line_ed_hook *, fx_keycode);
|
||||
void (*hook_buffer_modified)(struct line_ed *, struct line_ed_hook *);
|
||||
b_queue_entry hook_entry;
|
||||
fx_queue_entry hook_entry;
|
||||
};
|
||||
|
||||
enum line_ed_flags {
|
||||
@@ -57,7 +57,7 @@ struct line_ed {
|
||||
struct ivy_line_source l_line_source;
|
||||
|
||||
/* pointer to tty interface */
|
||||
b_tty *l_tty;
|
||||
fx_tty *l_tty;
|
||||
|
||||
/* the lexical scope that we are currently in.
|
||||
* this is provided by components further up the input pipeline,
|
||||
@@ -65,14 +65,14 @@ struct line_ed {
|
||||
const char *l_scope_type;
|
||||
|
||||
/* array of previously entered commands */
|
||||
b_array *l_history;
|
||||
fx_array *l_history;
|
||||
/* index of the currently selected history entry */
|
||||
size_t l_history_pos;
|
||||
|
||||
/* list of defined highlight ranges */
|
||||
b_queue l_hl_ranges;
|
||||
fx_queue l_hl_ranges;
|
||||
/* list of installed hooks */
|
||||
b_queue l_hooks;
|
||||
fx_queue l_hooks;
|
||||
};
|
||||
|
||||
extern struct line_ed *line_ed_create(void);
|
||||
@@ -82,7 +82,7 @@ extern void line_ed_set_scope_type(struct line_ed *ed, const char *scope_type);
|
||||
|
||||
extern void line_ed_put_highlight(
|
||||
struct line_ed *ed, unsigned long start_x, unsigned long start_y,
|
||||
unsigned long end_x, unsigned long end_y, const struct b_tty_vmode *vmode);
|
||||
unsigned long end_x, unsigned long end_y, const struct fx_tty_vmode *vmode);
|
||||
extern void line_ed_clear_highlights(struct line_ed *ed);
|
||||
extern void line_ed_print_highlights(struct line_ed *ed);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "buffer.h"
|
||||
#include "cursor.h"
|
||||
#include "hl-range.h"
|
||||
#include <blue/term/tty.h>
|
||||
#include <fx/term/tty.h>
|
||||
|
||||
/* prints the provided string to the terminal, applying any relevant highlight ranges.
|
||||
* this function prints all characters in `s` until it encounters a null char (\0) or
|
||||
@@ -16,12 +16,12 @@
|
||||
*/
|
||||
void print_text(struct line_ed *ed, size_t x, size_t y, const char *s)
|
||||
{
|
||||
b_tty *tty = ed->l_tty;
|
||||
fx_tty *tty = ed->l_tty;
|
||||
struct hl_range *cur_range = get_hl_range(ed, x, y);
|
||||
|
||||
for (size_t i = 0; s[i] != '\n' && s[i] != '\0'; i++) {
|
||||
if (!cur_range) {
|
||||
b_tty_reset_vmode(tty);
|
||||
fx_tty_reset_vmode(tty);
|
||||
fputc(s[i], stdout);
|
||||
continue;
|
||||
}
|
||||
@@ -107,7 +107,7 @@ void put_refresh(struct line_ed *ed, struct refresh_state *state)
|
||||
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
|
||||
if (start_x) {
|
||||
//fprintf(stdout, "\033[%uD", start_x);
|
||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -(long long)start_x);
|
||||
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_CURSOR, -(long long)start_x);
|
||||
}
|
||||
|
||||
start_x = 0;
|
||||
@@ -119,7 +119,7 @@ void put_refresh(struct line_ed *ed, struct refresh_state *state)
|
||||
* so that the physical cursor will be placed AFTER the character that
|
||||
* was just inserted. */
|
||||
cursor_rdelta--;
|
||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -cursor_rdelta);
|
||||
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_CURSOR, -cursor_rdelta);
|
||||
|
||||
#if 0
|
||||
for (unsigned int i = 0; i < cursor_rdelta; i++) {
|
||||
@@ -162,21 +162,21 @@ void backspace_nl_refresh(struct line_ed *ed, struct refresh_state *state)
|
||||
* has just been moved up. from here, clear this line and the rest
|
||||
* from the screen. */
|
||||
//fputs("\033[J", stdout);
|
||||
b_tty_clear(ed->l_tty, B_TTY_CLEAR_SCREEN | B_TTY_CLEAR_FROM_CURSOR);
|
||||
fx_tty_clear(ed->l_tty, FX_TTY_CLEAR_SCREEN | FX_TTY_CLEAR_FROM_CURSOR);
|
||||
|
||||
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
|
||||
/* next, move the physical cursor up and to the beginning of the previous line */
|
||||
size_t tmp_x;
|
||||
line_ed_coords_to_physical_coords(ed, 0, ed->l_cursor_y, &tmp_x, NULL);
|
||||
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, -1);
|
||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_START, tmp_x);
|
||||
fx_tty_move_cursor_y(ed->l_tty, FX_TTY_POS_CURSOR, -1);
|
||||
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_START, tmp_x);
|
||||
//fprintf(stdout, "\033[A\033[%uG", tmp_x + 1);
|
||||
start_x = 0;
|
||||
} else {
|
||||
/* next, move the physical cursor up and to the end of the previous line */
|
||||
//fprintf(stdout, "\033[A\033[%uG", new_x);
|
||||
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, -1);
|
||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_START, new_x);
|
||||
fx_tty_move_cursor_y(ed->l_tty, FX_TTY_POS_CURSOR, -1);
|
||||
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_START, new_x);
|
||||
}
|
||||
|
||||
/* now reprint all of the buffer lines, starting with the first of the
|
||||
@@ -202,11 +202,11 @@ void backspace_nl_refresh(struct line_ed *ed, struct refresh_state *state)
|
||||
* were concatenated. */
|
||||
if (ydiff) {
|
||||
//fprintf(stdout, "\033[%uA", ydiff);
|
||||
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, ydiff);
|
||||
fx_tty_move_cursor_y(ed->l_tty, FX_TTY_POS_CURSOR, ydiff);
|
||||
}
|
||||
|
||||
//fprintf(stdout, "\033[%uG", new_x);
|
||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_START, new_x);
|
||||
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_START, new_x);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
@@ -232,14 +232,14 @@ void backspace_simple_refresh(struct line_ed *ed, struct refresh_state *state)
|
||||
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
|
||||
if (start_x) {
|
||||
//fprintf(stdout, "\033[%uD", start_x);
|
||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -(long long)start_x);
|
||||
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_CURSOR, -(long long)start_x);
|
||||
}
|
||||
|
||||
start_x = 0;
|
||||
}
|
||||
|
||||
//fputc('\010', stdout);
|
||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -1);
|
||||
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_CURSOR, -1);
|
||||
print_text(ed, start_x, ed->l_cursor_y, line_buf + start_x);
|
||||
fputc(' ', stdout);
|
||||
|
||||
@@ -248,7 +248,7 @@ void backspace_simple_refresh(struct line_ed *ed, struct refresh_state *state)
|
||||
* the fact that backspace was just pressed) */
|
||||
cursor_rdelta++;
|
||||
|
||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -cursor_rdelta);
|
||||
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_CURSOR, -cursor_rdelta);
|
||||
|
||||
#if 0
|
||||
for (unsigned int i = 0; i < cursor_rdelta; i++) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "cmd/cmd.h"
|
||||
|
||||
#include <blue/cmd.h>
|
||||
#include <fx/cmd.h>
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
return b_command_dispatch(CMD_ROOT, argc, argv);
|
||||
return fx_command_dispatch(CMD_ROOT, argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user