Skip to content

Commit

Permalink
fix: Fix some 30cc self-compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
keyvank committed Dec 3, 2024
1 parent 81571cf commit a587365
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
15 changes: 11 additions & 4 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def compile(path):
text=True,
)
if out.returncode != 0:
raise Exception(out.stderr)
raise Exception(out.stderr + "\n" + out.stdout)
else:
return out.stdout

Expand All @@ -33,12 +33,19 @@ def compile(path):
except Exception as e:
has_error = True
print("Error compiling:", f, e)


objs = list(glob.glob("target/obj/**/*.o", recursive=True))

if not has_error:
subprocess.run(
["ld", "-dynamic-linker", "/lib64/ld-linux-x86-64.so.2", "-lc", "-o", "target/30cc"]
[
"ld",
"-dynamic-linker",
"/lib64/ld-linux-x86-64.so.2",
"-lc",
"-o",
"target/30cc",
]
+ objs
)
)
2 changes: 1 addition & 1 deletion parser/expr/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ apply_result *binary_op_apply(parser_node *node, context *ctx)
}

// TODO: clag gives warning when comparing int* and int
if (binop->op != TKN_ASSIGN && binop->op != TKN_EQ &&
if (binop->op != TKN_ASSIGN && binop->op != TKN_EQ && binop->op != TKN_NEQ && binop->op != TKN_ANDAND &&
(left->type->kind == TYPE_POINTER || right->type->kind == TYPE_POINTER))
{
switch (binop->op)
Expand Down
2 changes: 1 addition & 1 deletion parser/switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ parser_node *parse_switch(typed_token **tkns_ptr)
tkn = tkn->next;
*tkns_ptr = tkn;

parser_node *node = malloc(sizeof(parser_node));
parser_node *node = (parser_node *)malloc(sizeof(parser_node));
node->data = (void *)malloc(sizeof(node_switch));
node->debug = switch_debug;
node->apply = switch_apply;
Expand Down
6 changes: 3 additions & 3 deletions parser/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ parser_node *parse_type(typed_token **tkns_ptr, int allow_naming)

if (allow_naming && tkn->type_id == TKN_ID)
{
fun_name = tkn->data;
fun_name = (char *)tkn->data;
tkn = tkn->next;
}

Expand All @@ -93,7 +93,7 @@ parser_node *parse_type(typed_token **tkns_ptr, int allow_naming)
if (tkn->type_id == TKN_L_PAREN)
{
tkn = tkn->next;
parser_node **arg_types = malloc(sizeof(parser_node *) * 128);
parser_node **arg_types = (parser_node **)malloc(sizeof(parser_node *) * 128);
int arg_count = 0;
while (1)
{
Expand Down Expand Up @@ -134,7 +134,7 @@ parser_node *parse_type(typed_token **tkns_ptr, int allow_naming)
if (allow_naming && tkn->type_id == TKN_ID)
{
node_type *par = (node_type *)node->data;
par->name = tkn->data;
par->name = (char *)tkn->data;
tkn = tkn->next;
}

Expand Down
2 changes: 1 addition & 1 deletion preprocess/macro_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ linked_list *seg_macro_call_gen(seg *self, prep_ctx *ctx)
else if (tkn->type_id == TKN_SHARP)
{
repl_tkn = repl_tkn->next;
tkn = repl_tkn->value;
tkn = (typed_token *)repl_tkn->value;
if (tkn->type_id != TKN_ID)
{
fprintf(stderr, "Expected identifier!\n");
Expand Down

0 comments on commit a587365

Please sign in to comment.