From 9d438d7347386f5c439fe7a99f3a1c1f1eb8be5b Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Mon, 15 Jan 2024 22:38:30 +0000 Subject: [PATCH] Add basic comp ops implementations --- include/ops.h | 28 ++++++++++++++++++++++++++++ src/ops.c | 10 ++++++++++ 2 files changed, 38 insertions(+) create mode 100644 include/ops.h create mode 100644 src/ops.c diff --git a/include/ops.h b/include/ops.h new file mode 100644 index 0000000..c883f21 --- /dev/null +++ b/include/ops.h @@ -0,0 +1,28 @@ +#ifndef COMP_OPS_H +#define COMP_OPS_H + +#include "aliases/aliases.h" +#include "nodes.h" + +enum comp_ops { + COMP_OP_ADD, + COMP_OP_SUB, + COMP_OP_MUL, + COMP_OP_DIV, + + COUNT_COMP_OPS, +}; + +i32 comp_add(i32 a, i32 b); +i32 comp_sub(i32 a, i32 b); +i32 comp_mul(i32 a, i32 b); +i32 comp_div(i32 a, i32 b); + +INTERNAL node_func_t ops[COUNT_COMP_OPS] = { + [COMP_OP_ADD] = comp_add, + [COMP_OP_SUB] = comp_sub, + [COMP_OP_MUL] = comp_mul, + [COMP_OP_DIV] = comp_div, +}; + +#endif // !COMP_OPS_H diff --git a/src/ops.c b/src/ops.c new file mode 100644 index 0000000..fef0692 --- /dev/null +++ b/src/ops.c @@ -0,0 +1,10 @@ +#include "ops.h" +#include "aliases/aliases.h" + +i32 comp_add(i32 a, i32 b) { return a + b; } + +i32 comp_sub(i32 a, i32 b) { return a - b; } + +i32 comp_mul(i32 a, i32 b) { return a * b; } + +i32 comp_div(i32 a, i32 b) { return a / b; }