From 812fe9cbe124bf39a06f58a538c8c01f7402fb09 Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Sat, 24 Jan 2026 12:14:48 +0000 Subject: Fix for #110 --- src/codegen/codegen.c | 11 ++++++----- src/codegen/codegen_stmt.c | 5 +++-- src/codegen/codegen_utils.c | 10 +++++----- 3 files changed, 14 insertions(+), 12 deletions(-) (limited to 'src/codegen') diff --git a/src/codegen/codegen.c b/src/codegen/codegen.c index 706d613..038f3cb 100644 --- a/src/codegen/codegen.c +++ b/src/codegen/codegen.c @@ -11,22 +11,23 @@ #include "ast.h" #include "zprep_plugin.h" +// Emit literal expression (int, float, string, char) // Emit literal expression (int, float, string, char) static void codegen_literal_expr(ASTNode *node, FILE *out) { - if (node->literal.type_kind == TOK_STRING) + if (node->literal.type_kind == LITERAL_STRING) { fprintf(out, "\"%s\"", node->literal.string_val); } - else if (node->literal.type_kind == TOK_CHAR) + else if (node->literal.type_kind == LITERAL_CHAR) { fprintf(out, "%s", node->literal.string_val); } - else if (node->literal.type_kind == 1) // float + else if (node->literal.type_kind == LITERAL_FLOAT) { fprintf(out, "%f", node->literal.float_val); } - else // int + else // LITERAL_INT { if (node->literal.int_val > 9223372036854775807ULL) { @@ -34,7 +35,7 @@ static void codegen_literal_expr(ASTNode *node, FILE *out) } else { - fprintf(out, "%llu", (unsigned long long)node->literal.int_val); + fprintf(out, "%lld", (long long)node->literal.int_val); } } } diff --git a/src/codegen/codegen_stmt.c b/src/codegen/codegen_stmt.c index 54c6a14..406a6e5 100644 --- a/src/codegen/codegen_stmt.c +++ b/src/codegen/codegen_stmt.c @@ -475,7 +475,8 @@ void codegen_match_internal(ParserContext *ctx, ASTNode *node, FILE *out, int us // Check if body is a string literal (should auto-print). ASTNode *body = c->match_case.body; - int is_string_literal = (body->type == NODE_EXPR_LITERAL && body->literal.type_kind == 2); + int is_string_literal = + (body->type == NODE_EXPR_LITERAL && body->literal.type_kind == LITERAL_STRING); if (is_expr) { @@ -1576,7 +1577,7 @@ void codegen_node_single(ParserContext *ctx, ASTNode *node, FILE *out) } case NODE_EXPR_LITERAL: // String literal statement should auto-print - if (node->literal.type_kind == 2 || node->literal.type_kind == TOK_STRING) + if (node->literal.type_kind == LITERAL_STRING) { fprintf(out, " printf(\"%%s\\n\", "); codegen_expression(ctx, node, out); diff --git a/src/codegen/codegen_utils.c b/src/codegen/codegen_utils.c index fe580bf..a7e4925 100644 --- a/src/codegen/codegen_utils.c +++ b/src/codegen/codegen_utils.c @@ -455,15 +455,15 @@ char *infer_type(ParserContext *ctx, ASTNode *node) if (node->type == NODE_EXPR_LITERAL) { - if (node->literal.type_kind == TOK_STRING) + if (node->literal.type_kind == LITERAL_STRING) { - return "string"; + return xstrdup("string"); } - if (node->literal.type_kind == TOK_CHAR) + if (node->literal.type_kind == LITERAL_CHAR) { - return "char"; + return xstrdup("char"); } - if (node->literal.type_kind == 1) + if (node->literal.type_kind == LITERAL_FLOAT) { return "double"; } -- cgit v1.2.3