Skip to content

Commit

Permalink
expr: Power operator for ints
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Sep 3, 2024
1 parent b43c80a commit b493016
Show file tree
Hide file tree
Showing 3 changed files with 794 additions and 731 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cc_flags="-std=c11 -g -Wall -Wextra -Werror -Iflamingo/runtime -Iflamingo -Wno-u
cc $cc_flags -ferror-limit=0 -c flamingo/flamingo.c -o bin/flamingo.o
cc $cc_flags -c main.c -o bin/main.o

cc $(find bin -name "*.o") $cc_flags -o bin/flamingo
cc $(find bin -name "*.o") -lm $cc_flags -o bin/flamingo

bin/flamingo hello_world.fl

Expand Down
7 changes: 7 additions & 0 deletions flamingo/grammar/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "literal.h"

#include <common.h>
#include <math.h>

static int parse_binary_expr(flamingo_t* flamingo, TSNode node, flamingo_val_t** val) {
assert(strcmp(ts_node_type(node), "binary_expression") == 0);
Expand Down Expand Up @@ -124,6 +125,12 @@ static int parse_binary_expr(flamingo_t* flamingo, TSNode node, flamingo_val_t**
goto done;
}

if (strncmp(operator, "**", operator_size) == 0) {
(*val)->kind = FLAMINGO_VAL_KIND_INT;
(*val)->integer.integer = pow(left_val->integer.integer, right_val->integer.integer);
goto done;
}

// Comparisons.

if (strncmp(operator, "==", operator_size) == 0) {
Expand Down
Loading

0 comments on commit b493016

Please sign in to comment.