summaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-24 12:14:48 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-24 12:14:48 +0000
commit812fe9cbe124bf39a06f58a538c8c01f7402fb09 (patch)
tree8ea1f8258714e7dd8916eb221006e45082a129bb /src/codegen
parent22035400ed7b7fcda088a1a5b1ca6505b23bf63f (diff)
Fix for #110
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/codegen.c11
-rw-r--r--src/codegen/codegen_stmt.c5
-rw-r--r--src/codegen/codegen_utils.c10
3 files changed, 14 insertions, 12 deletions
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
@@ -12,21 +12,22 @@
#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";
}