Skip to content

Commit

Permalink
codegen parentheses expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
omdxp committed Sep 1, 2024
1 parent 30f309d commit 692c779
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void codegen_generate_body(struct node *node, struct history *history);

void codegen_generate_exp_node(struct node *node, struct history *history);
const char *codegen_sub_register(const char *original_register, size_t size);
int codegen_remove_uninheritable_flags(int flags);

void codegen_new_scope(int flags) {
resolver_default_new_scope(current_process->resolver, flags);
Expand Down Expand Up @@ -801,6 +802,13 @@ void codegen_generate_string(struct node *node, struct history *history) {
&(struct stack_frame_data){.dtype = datatype_for_string()});
}

void codegen_generate_exp_paren_node(struct node *node,
struct history *history) {
codegen_generate_expressionable(
node->paren.exp, history_down(history, codegen_remove_uninheritable_flags(
history->flags)));
}

void codegen_generate_expressionable(struct node *node,
struct history *history) {
bool is_root = codegen_is_exp_root(history);
Expand All @@ -827,6 +835,9 @@ void codegen_generate_expressionable(struct node *node,

case NODE_TYPE_STRING:
codegen_generate_string(node, history);

case NODE_TYPE_EXPRESSION_PARENTHESIS:
codegen_generate_exp_paren_node(node, history);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions test.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
int printf(const char *s);

int main() {
const char *msg = "Hello, World!\n";
printf(msg);
int x;
x = (5);
}

0 comments on commit 692c779

Please sign in to comment.