Skip to content

Commit

Permalink
bool: Rename val to boolean in val union struct to be more consis…
Browse files Browse the repository at this point in the history
…tent
  • Loading branch information
obiwac committed Sep 13, 2024
1 parent 57e91f3 commit dea6e98
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion flamingo/flamingo.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct flamingo_val_t {

union {
struct {
bool val;
bool boolean;
} boolean;

struct {
Expand Down
2 changes: 1 addition & 1 deletion flamingo/grammar/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static int parse_assert(flamingo_t* flamingo, TSNode node) {
char const* const test_str = flamingo->src + start;
size_t const test_size = end - start;

if (!val->boolean.val) {
if (!val->boolean.boolean) {
return error(flamingo, "assertion test '%.*s' failed", (int) test_size, test_str);
}

Expand Down
30 changes: 15 additions & 15 deletions flamingo/grammar/binary_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ static int parse_binary_expr(flamingo_t* flamingo, TSNode node, flamingo_val_t**
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;

if (strncmp(op, "==", op_size) == 0) {
(*val)->boolean.val = same_types;
(*val)->boolean.boolean = same_types;
goto done;
}

if (strncmp(op, "!=", op_size) == 0) {
(*val)->boolean.val = !same_types;
(*val)->boolean.boolean = !same_types;
goto done;
}

Expand Down Expand Up @@ -153,37 +153,37 @@ static int parse_binary_expr(flamingo_t* flamingo, TSNode node, flamingo_val_t**

if (strncmp(op, "==", op_size) == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;
(*val)->boolean.val = left_val->integer.integer == right_val->integer.integer;
(*val)->boolean.boolean = left_val->integer.integer == right_val->integer.integer;
goto done;
}

if (strncmp(op, "!=", op_size) == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;
(*val)->boolean.val = left_val->integer.integer != right_val->integer.integer;
(*val)->boolean.boolean = left_val->integer.integer != right_val->integer.integer;
goto done;
}

if (strncmp(op, "<", op_size) == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;
(*val)->boolean.val = left_val->integer.integer < right_val->integer.integer;
(*val)->boolean.boolean = left_val->integer.integer < right_val->integer.integer;
goto done;
}

if (strncmp(op, "<=", op_size) == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;
(*val)->boolean.val = left_val->integer.integer <= right_val->integer.integer;
(*val)->boolean.boolean = left_val->integer.integer <= right_val->integer.integer;
goto done;
}

if (strncmp(op, ">", op_size) == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;
(*val)->boolean.val = left_val->integer.integer > right_val->integer.integer;
(*val)->boolean.boolean = left_val->integer.integer > right_val->integer.integer;
goto done;
}

if (strncmp(op, ">=", op_size) == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;
(*val)->boolean.val = left_val->integer.integer >= right_val->integer.integer;
(*val)->boolean.boolean = left_val->integer.integer >= right_val->integer.integer;
goto done;
}
}
Expand All @@ -193,33 +193,33 @@ static int parse_binary_expr(flamingo_t* flamingo, TSNode node, flamingo_val_t**

if (strncmp(op, "&&", op_size) == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;
(*val)->boolean.val = left_val->boolean.val && right_val->boolean.val;
(*val)->boolean.boolean = left_val->boolean.boolean && right_val->boolean.boolean;
goto done;
}

if (strncmp(op, "||", op_size) == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;
(*val)->boolean.val = left_val->boolean.val || right_val->boolean.val;
(*val)->boolean.boolean = left_val->boolean.boolean || right_val->boolean.boolean;
goto done;
}

if (strncmp(op, "^^", op_size) == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;
(*val)->boolean.val = (!!left_val->boolean.val) ^ (!!right_val->boolean.val);
(*val)->boolean.boolean = (!!left_val->boolean.boolean) ^ (!!right_val->boolean.boolean);
goto done;
}

// Comparisons.

if (strncmp(op, "==", op_size) == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;
(*val)->boolean.val = left_val->boolean.val == right_val->boolean.val;
(*val)->boolean.boolean = left_val->boolean.boolean == right_val->boolean.boolean;
goto done;
}

if (strncmp(op, "!=", op_size) == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;
(*val)->boolean.val = left_val->boolean.val != right_val->boolean.val;
(*val)->boolean.boolean = left_val->boolean.boolean != right_val->boolean.boolean;
goto done;
}
}
Expand All @@ -245,13 +245,13 @@ static int parse_binary_expr(flamingo_t* flamingo, TSNode node, flamingo_val_t**

if (strncmp(op, "==", op_size) == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;
(*val)->boolean.val = left_val->str.size == right_val->str.size && memcmp(left_val->str.str, right_val->str.str, left_val->str.size) == 0;
(*val)->boolean.boolean = left_val->str.size == right_val->str.size && memcmp(left_val->str.str, right_val->str.str, left_val->str.size) == 0;
goto done;
}

if (strncmp(op, "!=", op_size) == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;
(*val)->boolean.val = left_val->str.size != right_val->str.size || memcmp(left_val->str.str, right_val->str.str, left_val->str.size) != 0;
(*val)->boolean.boolean = left_val->str.size != right_val->str.size || memcmp(left_val->str.str, right_val->str.str, left_val->str.size) != 0;
goto done;
}
}
Expand Down
2 changes: 1 addition & 1 deletion flamingo/grammar/literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static int parse_literal(flamingo_t* flamingo, TSNode node, flamingo_val_t** val

if (strcmp(type, "bool") == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_BOOL;
(*val)->boolean.val = *(flamingo->src + ts_node_start_byte(child)) == 't';
(*val)->boolean.boolean = *(flamingo->src + ts_node_start_byte(child)) == 't';

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion flamingo/grammar/print.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static int parse_print(flamingo_t* flamingo, TSNode node) {
printf("<none>\n");
break;
case FLAMINGO_VAL_KIND_BOOL:
printf("%s\n", val->boolean.val ? "true" : "false");
printf("%s\n", val->boolean.boolean ? "true" : "false");
break;
case FLAMINGO_VAL_KIND_INT:
printf("%ld\n", val->integer.integer);
Expand Down

0 comments on commit dea6e98

Please sign in to comment.