From 87fe2d20ec3b76fbfd5e99723f7791a1c59ed663 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sat, 30 May 2026 10:12:28 +0100 Subject: [PATCH] toolchain: xpcg: update libfx usage --- toolchain/xpcg/CMakeLists.txt | 2 +- toolchain/xpcg/backend/c-mpc/backend.c | 44 ++++++++++++++------------ toolchain/xpcg/interface.c | 2 +- toolchain/xpcg/interface.h | 2 +- toolchain/xpcg/lex.c | 16 +++++----- toolchain/xpcg/lex.h | 6 ++-- toolchain/xpcg/line-source.c | 13 +++++--- toolchain/xpcg/line-source.h | 8 ++--- toolchain/xpcg/main.c | 16 +++++++--- toolchain/xpcg/msg.c | 2 +- toolchain/xpcg/msg.h | 2 +- toolchain/xpcg/token.c | 2 ++ toolchain/xpcg/token.h | 2 +- 13 files changed, 66 insertions(+), 51 deletions(-) diff --git a/toolchain/xpcg/CMakeLists.txt b/toolchain/xpcg/CMakeLists.txt index a2ce36a..f711c26 100644 --- a/toolchain/xpcg/CMakeLists.txt +++ b/toolchain/xpcg/CMakeLists.txt @@ -4,4 +4,4 @@ file(GLOB sources add_executable(xpcg ${sources}) -target_link_libraries(xpcg FX::Core FX::Ds FX::Cmd FX::Io) +target_link_libraries(xpcg FX::Runtime FX::Collections FX::Cmdline FX::Io) diff --git a/toolchain/xpcg/backend/c-mpc/backend.c b/toolchain/xpcg/backend/c-mpc/backend.c index 0b2b6f3..5700de2 100644 --- a/toolchain/xpcg/backend/c-mpc/backend.c +++ b/toolchain/xpcg/backend/c-mpc/backend.c @@ -4,7 +4,7 @@ #include "../../msg.h" #include "../../type.h" -#include +#include #include #include #include @@ -55,12 +55,12 @@ static int emit_header_guard_start( { fx_string *header_guard = fx_string_create(); fx_string_append_cstrf(header_guard, "%s_H_", iface->if_name); - fx_string_toupper(header_guard); + fx_string_transform_uppercase(header_guard); emit(ctx, "#ifndef %s\n#define %s\n\n", - fx_string_ptr(header_guard), - fx_string_ptr(header_guard)); + fx_string_get_cstr(header_guard), + fx_string_get_cstr(header_guard)); fx_string_unref(header_guard); return 0; } @@ -115,14 +115,14 @@ static int emit_interface_id_macros( { fx_string *iface_define_name = fx_string_create(); fx_string_append_cstr(iface_define_name, iface->if_name); - fx_string_toupper(iface_define_name); + fx_string_transform_uppercase(iface_define_name); uint32_t protocol_id = iface->if_id; emit(ctx, "/* %s protocol ID */\n#define INTERFACE_%s 0x%08xU\n\n", iface->if_name, - fx_string_ptr(iface_define_name), + fx_string_get_cstr(iface_define_name), protocol_id); fx_string_unref(iface_define_name); @@ -138,7 +138,9 @@ static int emit_interface_id_macros( iface->if_name, msg->msg_name); - emit(ctx, "/* %s message ID */\n", fx_string_ptr(msg_name)); + emit(ctx, + "/* %s message ID */\n", + fx_string_get_cstr(msg_name)); uint16_t msg_id = msg->msg_id; fx_string_clear(msg_name); @@ -147,10 +149,10 @@ static int emit_interface_id_macros( "%s_%s", iface->if_name, msg->msg_name); - fx_string_toupper(msg_name); + fx_string_transform_uppercase(msg_name); emit(ctx, "#define MSG_%s 0x%04xU\n", - fx_string_ptr(msg_name), + fx_string_get_cstr(msg_name), msg_id); entry = fx_queue_next(entry); @@ -316,9 +318,9 @@ static int emit_interface_msg_function_send_impl( const struct msg_definition *msg) { fx_string *iface_ucase = fx_string_create_from_cstr(iface->if_name); - fx_string_toupper(iface_ucase); + fx_string_transform_uppercase(iface_ucase); fx_string *msg_ucase = fx_string_create_from_cstr(msg->msg_name); - fx_string_toupper(msg_ucase); + fx_string_transform_uppercase(msg_ucase); emit(ctx, "struct %s_%s_msg msg_data = {0};\n", @@ -327,9 +329,9 @@ static int emit_interface_msg_function_send_impl( emit(ctx, "xpc_msg_header_init(&msg_data.msg_header, INTERFACE_%s, " "MSG_%s_%s);\n", - fx_string_ptr(iface_ucase), - fx_string_ptr(iface_ucase), - fx_string_ptr(msg_ucase)); + fx_string_get_cstr(iface_ucase), + fx_string_get_cstr(iface_ucase), + fx_string_get_cstr(msg_ucase)); fx_string_unref(iface_ucase); fx_string_unref(msg_ucase); @@ -896,13 +898,13 @@ static int emit_interface_dispatcher_impl( const struct interface_definition *iface) { fx_string *iface_ucase = fx_string_create_from_cstr(iface->if_name); - fx_string_toupper(iface_ucase); + fx_string_transform_uppercase(iface_ucase); fx_string *msg_ucase = fx_string_create(); emit(ctx, "if (msg->msg_header.hdr_interface != INTERFACE_%s) return " "KERN_INVALID_ARGUMENT;\n\n", - fx_string_ptr(iface_ucase)); + fx_string_get_cstr(iface_ucase)); emit(ctx, "kern_status_t status = KERN_OK;\n"); emit(ctx, "switch (msg->msg_header.hdr_func) {\n"); @@ -914,12 +916,12 @@ static int emit_interface_dispatcher_impl( fx_string_clear(msg_ucase); fx_string_append_cstr(msg_ucase, msg->msg_name); - fx_string_toupper(msg_ucase); + fx_string_transform_uppercase(msg_ucase); emit(ctx, "case MSG_%s_%s: {\n", - fx_string_ptr(iface_ucase), - fx_string_ptr(msg_ucase)); + fx_string_get_cstr(iface_ucase), + fx_string_get_cstr(msg_ucase)); emit_indent(ctx); emit_interface_dispatcher_impl_msg(ctx, iface, msg); emit(ctx, "break;\n"); @@ -1121,8 +1123,8 @@ static int emit_header( emit_include(ctx, "xpc/string.h", true); emit_include(ctx, "xpc/buffer.h", true); emit_include(ctx, "xpc/context.h", true); - emit_include(ctx, "mango/msg.h", true); - emit_include(ctx, "mango/types.h", true); + emit_include(ctx, "magenta/msg.h", true); + emit_include(ctx, "magenta/types.h", true); emit(ctx, "\n"); emit_interface_id_macros(ctx, iface); diff --git a/toolchain/xpcg/interface.c b/toolchain/xpcg/interface.c index a721b12..a30e32d 100644 --- a/toolchain/xpcg/interface.c +++ b/toolchain/xpcg/interface.c @@ -2,7 +2,7 @@ #include "msg.h" -#include +#include #include #include diff --git a/toolchain/xpcg/interface.h b/toolchain/xpcg/interface.h index 3601760..964fac8 100644 --- a/toolchain/xpcg/interface.h +++ b/toolchain/xpcg/interface.h @@ -1,7 +1,7 @@ #ifndef XPCG_INTERFACE_H_ #define XPCG_INTERFACE_H_ -#include +#include struct msg_definition; diff --git a/toolchain/xpcg/lex.c b/toolchain/xpcg/lex.c index e4be86d..8d0ffa0 100644 --- a/toolchain/xpcg/lex.c +++ b/toolchain/xpcg/lex.c @@ -3,13 +3,12 @@ #include "line-source.h" #include "token.h" -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include #include #include #include @@ -24,7 +23,8 @@ (fx_wchar_is_alnum(c) || c == '.' || c == '-' || c == '_') #define IS_VALID_IDENT_START_CHAR(c) \ (fx_wchar_is_alpha(c) || c == '.' || c == '_') -#define IS_VALID_REG_START_CHAR(c) (fx_wchar_is_alnum(c) || c == '.' || c == '_') +#define IS_VALID_REG_START_CHAR(c) \ + (fx_wchar_is_alnum(c) || c == '.' || c == '_') static struct lex_token_def symbols[] = { LEX_TOKEN_DEF(SYM_COMMA, ","), @@ -414,7 +414,7 @@ static enum status read_number(struct lex *lex, bool negate) return push_int(lex, 0); } - const char *s = fx_string_ptr(str); + const char *s = fx_string_get_cstr(str); char *ep = NULL; /* negative numbers will be lexed as a hyphen followed by a positive diff --git a/toolchain/xpcg/lex.h b/toolchain/xpcg/lex.h index 53cca1a..2814ab6 100644 --- a/toolchain/xpcg/lex.h +++ b/toolchain/xpcg/lex.h @@ -4,9 +4,9 @@ #include "status.h" #include "token.h" -#include -#include -#include +#include +#include +#include #include struct lex { diff --git a/toolchain/xpcg/line-source.c b/toolchain/xpcg/line-source.c index 9e13f4b..7fe0449 100644 --- a/toolchain/xpcg/line-source.c +++ b/toolchain/xpcg/line-source.c @@ -71,7 +71,7 @@ static enum status refill_linebuf(struct line_source *src) fx_string_replace_all_with_stringstream(line, s); fx_stringstream_unref(s); - fx_array_append(src->s_lines, line); + fx_array_push_back(src->s_lines, FX_VALUE_OBJECT(line)); fx_string_unref(line); src->s_linebuf = line; @@ -96,7 +96,7 @@ static int peek(struct line_source *src) return -ERR_EOF; } - fx_wchar c = fx_iterator_get_value(src->s_linebuf_ptr).v_int; + fx_wchar c = fx_iterator_get_value(src->s_linebuf_ptr)->v_wchar; return c; } @@ -116,7 +116,7 @@ static int advance(struct line_source *src) return -ERR_EOF; } - fx_wchar c = fx_iterator_get_value(src->s_linebuf_ptr).v_int; + fx_wchar c = fx_iterator_get_value(src->s_linebuf_ptr)->v_wchar; fx_iterator_move_next(src->s_linebuf_ptr); src->s_cursor.c_col++; @@ -148,11 +148,14 @@ enum status line_source_get_row( row--; - if (row >= fx_array_size(src->s_lines)) { + if (row >= fx_array_get_size(src->s_lines)) { return ERR_EOF; } - fx_string *line = fx_array_at(src->s_lines, row); + const fx_value *line_v = fx_array_get_ref(src->s_lines, row); + fx_string *line = NULL; + fx_value_get_object(line_v, &line); + *out = line; return SUCCESS; diff --git a/toolchain/xpcg/line-source.h b/toolchain/xpcg/line-source.h index 9202b1f..8885cae 100644 --- a/toolchain/xpcg/line-source.h +++ b/toolchain/xpcg/line-source.h @@ -4,15 +4,15 @@ #include "file-span.h" #include "status.h" -#include -#include -#include +#include +#include +#include struct line_source { fx_stream *s_stream; const char *s_path; fx_string *s_linebuf; - fx_iterator *s_linebuf_ptr; + const fx_iterator *s_linebuf_ptr; fx_array *s_lines; struct file_cell s_cursor; diff --git a/toolchain/xpcg/main.c b/toolchain/xpcg/main.c index 29f8276..d85182f 100644 --- a/toolchain/xpcg/main.c +++ b/toolchain/xpcg/main.c @@ -6,7 +6,7 @@ #include "msg.h" #include "parse.h" -#include +#include #include #include @@ -70,7 +70,12 @@ static int xpcg( const fx_array *args) { const char *path = NULL; - fx_arglist_get_string(opt, FX_COMMAND_INVALID_ID, ARG_SRCPATH, 0, &path); + fx_arglist_get_string( + opt, + FX_COMMAND_INVALID_ID, + ARG_SRCPATH, + 0, + &path); if (!path) { fx_arglist_report_missing_args( opt, @@ -81,8 +86,11 @@ static int xpcg( } fx_file *file = NULL; - fx_result result - = fx_file_open(NULL, FX_RV_PATH(path), FX_FILE_READ_ONLY, &file); + fx_result result = fx_file_open( + NULL, + FX_RV_PATH(path), + FX_FILE_READ_ONLY, + &file); if (fx_result_is_error(result)) { fx_throw(result); return -1; diff --git a/toolchain/xpcg/msg.c b/toolchain/xpcg/msg.c index 73332c5..8daee7f 100644 --- a/toolchain/xpcg/msg.c +++ b/toolchain/xpcg/msg.c @@ -1,6 +1,6 @@ #include "msg.h" -#include +#include #include #include diff --git a/toolchain/xpcg/msg.h b/toolchain/xpcg/msg.h index 79af374..c605422 100644 --- a/toolchain/xpcg/msg.h +++ b/toolchain/xpcg/msg.h @@ -1,7 +1,7 @@ #ifndef XPCG_MSG_H_ #define XPCG_MSG_H_ -#include +#include struct type; diff --git a/toolchain/xpcg/token.c b/toolchain/xpcg/token.c index 4bc401d..0cdd0a6 100644 --- a/toolchain/xpcg/token.c +++ b/toolchain/xpcg/token.c @@ -1,5 +1,7 @@ #include "token.h" +#include + void token_destroy(struct token *tok) { switch (tok->tok_value_type) { diff --git a/toolchain/xpcg/token.h b/toolchain/xpcg/token.h index 5713718..b6d1eea 100644 --- a/toolchain/xpcg/token.h +++ b/toolchain/xpcg/token.h @@ -3,7 +3,7 @@ #include "file-span.h" -#include +#include #define TOKEN_TYPE(tok) ((tok) ? (tok)->tok_type : TOK_NONE) #define TOKEN_IS(tok, type) ((tok) && ((tok)->tok_type & (type)) != 0)