Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
omdxp committed Sep 8, 2024
1 parent 5aa7cb8 commit 7521c33
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
Binary file added .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions cprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ compile_process_create(const char *filename, const char *filename_out,
struct compile_process *process = calloc(1, sizeof(struct compile_process));
process->node_vec = vector_create(sizeof(struct node *));
process->node_tree_vec = vector_create(sizeof(struct node *));
process->token_vec = vector_create(sizeof(struct token *));
process->token_vec_original = vector_create(sizeof(struct token *));
process->token_vec = vector_create(sizeof(struct token));
process->token_vec_original = vector_create(sizeof(struct token));

process->flags = flags;
process->cfile.fp = file;
Expand Down
29 changes: 14 additions & 15 deletions expressionable.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ int expressionable_parser_get_precedence_for_operator(
const char *op, struct expressionable_op_precedence_group **group_out) {
*group_out = NULL;
for (int i = 0; i < TOTAL_OPERATOR_GROUPS; i++) {
struct expressionable_op_precedence_group *group = &op_precedence[i];
for (int j = 0; group->operators[j]; j++) {
if (S_EQ(group->operators[j], op)) {
*group_out = group;
return 0;
for (int j = 0; op_precedence[i].operators[j]; j++) {
if (S_EQ(op, op_precedence[i].operators[j])) {
*group_out = &op_precedence[i];
return i;
}
}
}
Expand Down Expand Up @@ -206,7 +205,7 @@ void expressionable_parser_reorder_expression(
void *node = *node_out;
int node_type = expressionable_callbacks(expressionable)
->get_node_type(expressionable, node);
if (node_type == EXPRESSIONABLE_GENERIC_TYPE_EXPRESSION) {
if (node_type != EXPRESSIONABLE_GENERIC_TYPE_EXPRESSION) {
return;
}

Expand All @@ -220,19 +219,19 @@ void expressionable_parser_reorder_expression(
->get_node_type(expressionable, right_node);
assert(left_node_type >= 0 && right_node_type >= 0);

if (left_node_type == EXPRESSIONABLE_GENERIC_TYPE_EXPRESSION && right_node &&
right_node_type == EXPRESSIONABLE_GENERIC_TYPE_EXPRESSION) {
if (left_node_type != EXPRESSIONABLE_GENERIC_TYPE_EXPRESSION && right_node &&
right_node_type != EXPRESSIONABLE_GENERIC_TYPE_EXPRESSION) {
return;
}

if (left_node_type == EXPRESSIONABLE_GENERIC_TYPE_EXPRESSION && right_node &&
if (left_node_type != EXPRESSIONABLE_GENERIC_TYPE_EXPRESSION && right_node &&
right_node_type == EXPRESSIONABLE_GENERIC_TYPE_EXPRESSION) {
const char *right_op = expressionable_callbacks(expressionable)
->get_node_op(expressionable, right_node);
const char *main_op = expressionable_callbacks(expressionable)
->get_node_op(expressionable, node);

if (expressionable_parser_left_op_has_priority(main_op, right_node)) {
if (expressionable_parser_left_op_has_priority(main_op, right_op)) {
expressionable_parser_node_shift_children_left(expressionable, node);

void **address_of_left =
Expand Down Expand Up @@ -266,7 +265,7 @@ void expressionable_expect_op(struct expressionable *expressionable,

void expressionable_expect_sym(struct expressionable *expressionable, char c) {
struct token *next_token = expressionable_token_next(expressionable);
if (!next_token || !token_is_symbol(next_token, c)) {
if (next_token && !token_is_symbol(next_token, c)) {
expressionable_error(expressionable, "Expected symbol");
}
}
Expand All @@ -278,13 +277,13 @@ void expressionable_deal_with_additional_expression(
}
}

void expressionable_parse_parenteses(struct expressionable *expressionable) {
void expressionable_parse_parentheses(struct expressionable *expressionable) {
void *left_node = NULL;
void *tmp_node = expressionable_node_peek_or_null(expressionable);
int tmp_type = tmp_node ? expressionable_callbacks(expressionable)
->get_node_type(expressionable, tmp_node)
: -1;
if (tmp_type &&
if (tmp_node &&
expressionable_generic_type_is_value_expressionable(tmp_type)) {
left_node = tmp_node;
expressionable_node_pop(expressionable);
Expand Down Expand Up @@ -367,7 +366,7 @@ void expressionable_parse_for_operator(struct expressionable *expressionable) {

if (expressionable_peek_next(expressionable)->type == TOKEN_TYPE_OPERATOR) {
if (S_EQ(expressionable_peek_next(expressionable)->sval, "(")) {
expressionable_parse_parenteses(expressionable);
expressionable_parse_parentheses(expressionable);
} else if (is_unary_operator(
expressionable_peek_next(expressionable)->sval)) {
expressionable_parse_unary(expressionable);
Expand Down Expand Up @@ -410,7 +409,7 @@ void expressionable_parse_tenary(struct expressionable *expressionable) {
int expressionable_parse_exp(struct expressionable *expressionable,
struct token *token) {
if (S_EQ(expressionable_peek_next(expressionable)->sval, "(")) {
expressionable_parse_parenteses(expressionable);
expressionable_parse_parentheses(expressionable);
} else if (S_EQ(expressionable_peek_next(expressionable)->sval, "?")) {
expressionable_parse_tenary(expressionable);
} else {
Expand Down
6 changes: 3 additions & 3 deletions preprocessor/preprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ void preprocessor_token_vec_push_keyword_and_identifier(
vector_push(token_vec, &t2);
}

struct preprocessor_node *
preprocessor_node_create(struct preprocessor_node *node) {
void *preprocessor_node_create(struct preprocessor_node *node) {
struct preprocessor_node *res = malloc(sizeof(struct preprocessor_node));
memcpy(res, node, sizeof(struct preprocessor_node));
return res;
Expand Down Expand Up @@ -261,7 +260,7 @@ preprocessor_peek_next_token_skip_nl(struct compile_process *compiler) {
void *preprocessor_handle_number_token(struct expressionable *expressionable) {
struct token *token = expressionable_token_next(expressionable);
return preprocessor_node_create(&(struct preprocessor_node){
.type = PREPROCESSOR_NUMBER_NODE, .const_val = token->llnum});
.type = PREPROCESSOR_NUMBER_NODE, .const_val.llnum = token->llnum});
}

void *
Expand Down Expand Up @@ -677,6 +676,7 @@ int preprocessor_definition_evaluated_value(
return preprocessor_definition_evaluated_value_for_standard(def);
} else if (def->type == PREPROCESSOR_DEFINITION_NATIVE_CALLBACK) {
#warning "impl native callback"
return -1;
}

compiler_error(def->preprocessor->compiler, "Cannot evaluate to number");
Expand Down

0 comments on commit 7521c33

Please sign in to comment.