* [PATCH olang v2 2/2] codegen: x86_64: implement binary operations
2024-08-25 13:16 [PATCH olang v2 0/2] codegen: x86_64: implement binary operations Johnny Richard
2024-08-25 13:16 ` [PATCH olang v2 1/2] codegen: x86_64: extract function to emit expression Johnny Richard
@ 2024-08-25 13:16 ` Johnny Richard
2024-08-25 13:26 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-09-05 22:49 ` [PATCH olang v2 0/2] codegen: x86_64: implement binary operations Carlos Maniero
2 siblings, 1 reply; 5+ messages in thread
From: Johnny Richard @ 2024-08-25 13:16 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Johnny Richard
In order to simplify most of the binary operation expressions we are
using stack to store previous execution. It makes the implementation
easy but inefficient.
We can optimize this codegen in a near future as soon as re get IR in
place.
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
CHANGES
- V2: add integration tests
src/codegen_linux_x86_64.c | 234 +++++++++++++++++-
src/parser.c | 2 +-
.../tests/0002_binary_operator_addition.ol | 22 ++
.../0003_binary_operator_multiplication.ol | 22 ++
.../tests/0004_binary_operator_division.ol | 22 ++
.../tests/0005_binary_operator_reminder.ol | 22 ++
.../tests/0006_binary_operator_subtraction.ol | 22 ++
.../tests/0007_binary_operator_eq.ol | 22 ++
.../tests/0008_binary_operator_lt.ol | 22 ++
.../tests/0009_binary_operator_gt.ol | 22 ++
.../tests/0010_binary_operator_neq.ol | 22 ++
.../tests/0011_binary_operator_leq.ol | 22 ++
.../tests/0012_binary_operator_geq.ol | 22 ++
.../tests/0013_binary_operator_lshift.ol | 22 ++
.../tests/0014_binary_operator_rshift.ol | 22 ++
.../tests/0015_binary_operator_xor.ol | 22 ++
.../tests/0016_binary_operator_and.ol | 22 ++
.../tests/0017_binary_operator_or.ol | 22 ++
.../tests/0018_binary_operator_logical_and.ol | 22 ++
.../tests/0019_binary_operator_logical_or.ol | 22 ++
20 files changed, 627 insertions(+), 5 deletions(-)
create mode 100644 tests/integration/tests/0002_binary_operator_addition.ol
create mode 100644 tests/integration/tests/0003_binary_operator_multiplication.ol
create mode 100644 tests/integration/tests/0004_binary_operator_division.ol
create mode 100644 tests/integration/tests/0005_binary_operator_reminder.ol
create mode 100644 tests/integration/tests/0006_binary_operator_subtraction.ol
create mode 100644 tests/integration/tests/0007_binary_operator_eq.ol
create mode 100644 tests/integration/tests/0008_binary_operator_lt.ol
create mode 100644 tests/integration/tests/0009_binary_operator_gt.ol
create mode 100644 tests/integration/tests/0010_binary_operator_neq.ol
create mode 100644 tests/integration/tests/0011_binary_operator_leq.ol
create mode 100644 tests/integration/tests/0012_binary_operator_geq.ol
create mode 100644 tests/integration/tests/0013_binary_operator_lshift.ol
create mode 100644 tests/integration/tests/0014_binary_operator_rshift.ol
create mode 100644 tests/integration/tests/0015_binary_operator_xor.ol
create mode 100644 tests/integration/tests/0016_binary_operator_and.ol
create mode 100644 tests/integration/tests/0017_binary_operator_or.ol
create mode 100644 tests/integration/tests/0018_binary_operator_logical_and.ol
create mode 100644 tests/integration/tests/0019_binary_operator_logical_or.ol
diff --git a/src/codegen_linux_x86_64.c b/src/codegen_linux_x86_64.c
index b277014..64ec0e0 100644
--- a/src/codegen_linux_x86_64.c
+++ b/src/codegen_linux_x86_64.c
@@ -23,6 +23,8 @@
#define SYS_exit (60)
+size_t label_index;
+
static void
codegen_linux_x86_64_emit_start_entrypoint(FILE *out);
@@ -32,6 +34,7 @@ codegen_linux_x86_64_emit_function(FILE *out, ast_fn_definition_t *fn);
void
codegen_linux_x86_64_emit_program(FILE *out, ast_node_t *node)
{
+ label_index = 0;
codegen_linux_x86_64_emit_start_entrypoint(out);
assert(node->kind == AST_NODE_PROGRAM);
@@ -56,6 +59,12 @@ codegen_linux_x86_64_emit_start_entrypoint(FILE *out)
fprintf(out, " syscall\n");
}
+static size_t
+codegen_linux_x86_64_get_next_label(void)
+{
+ return ++label_index;
+}
+
static void
codegen_linux_x86_64_emit_expression(FILE *out, ast_node_t *expr_node)
{
@@ -63,14 +72,231 @@ codegen_linux_x86_64_emit_expression(FILE *out, ast_node_t *expr_node)
case AST_NODE_LITERAL: {
ast_literal_t literal_u32 = expr_node->as_literal;
assert(literal_u32.kind == AST_LITERAL_U32);
- uint32_t exit_code = literal_u32.as_u32;
+ uint32_t n = literal_u32.as_u32;
- fprintf(out, " mov $%d, %%eax\n", exit_code);
+ fprintf(out, " mov $%d, %%rax\n", n);
return;
}
- case AST_NODE_BINARY_OP:
+ case AST_NODE_BINARY_OP: {
+ ast_binary_op_t bin_op = expr_node->as_bin_op;
+ switch (bin_op.kind) {
+ case AST_BINOP_ADDITION: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " add %%rcx, %%rax\n");
+
+ return;
+ }
+ case AST_BINOP_MULTIPLICATION: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " mul %%rcx\n");
+
+ return;
+ }
+ case AST_BINOP_DIVISION: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " xor %%rdx, %%rdx\n");
+ fprintf(out, " div %%rcx\n");
+
+ return;
+ }
+ case AST_BINOP_REMINDER: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+ fprintf(out, " xor %%edx, %%edx\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " xor %%rdx, %%rdx\n");
+ fprintf(out, " div %%rcx\n");
+ fprintf(out, " mov %%edx, %%eax\n");
+
+ return;
+ }
+ case AST_BINOP_SUBTRACTION: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " sub %%rcx, %%rax\n");
+
+ return;
+ }
+ case AST_BINOP_CMP_EQ: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " cmp %%rcx, %%rax\n");
+ fprintf(out, " sete %%al\n");
+ fprintf(out, " movzb %%al, %%rax\n");
+
+ return;
+ }
+ case AST_BINOP_CMP_LT: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " cmp %%rcx, %%rax\n");
+ fprintf(out, " setl %%al\n");
+ fprintf(out, " movzb %%al, %%rax\n");
+
+ return;
+ }
+ case AST_BINOP_CMP_GT: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " cmp %%rcx, %%rax\n");
+ fprintf(out, " setg %%al\n");
+ fprintf(out, " movzb %%al, %%rax\n");
+
+ return;
+ }
+ case AST_BINOP_CMP_NEQ: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " cmp %%rcx, %%rax\n");
+ fprintf(out, " setne %%al\n");
+ fprintf(out, " movzb %%al, %%rax\n");
+
+ return;
+ }
+ case AST_BINOP_CMP_LEQ: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " cmp %%rcx, %%rax\n");
+ fprintf(out, " setle %%al\n");
+ fprintf(out, " movzb %%al, %%rax\n");
+
+ return;
+ }
+ case AST_BINOP_CMP_GEQ: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " cmp %%rcx, %%rax\n");
+ fprintf(out, " setge %%al\n");
+ fprintf(out, " movzb %%al, %%rax\n");
+
+ return;
+ }
+ case AST_BINOP_BITWISE_LSHIFT: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " shl %%cl, %%rax\n");
+
+ return;
+ }
+ case AST_BINOP_BITWISE_RSHIFT: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " shr %%cl, %%rax\n");
+
+ return;
+ }
+ case AST_BINOP_BITWISE_XOR: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " xor %%ecx, %%eax\n");
+
+ return;
+ }
+ case AST_BINOP_BITWISE_AND: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " and %%ecx, %%eax\n");
+
+ return;
+ }
+ case AST_BINOP_BITWISE_OR: {
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " push %%rax\n");
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " pop %%rcx\n");
+ fprintf(out, " or %%ecx, %%eax\n");
+
+ return;
+ }
+ case AST_BINOP_LOGICAL_AND: {
+ size_t label_exit = codegen_linux_x86_64_get_next_label();
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " cmp $0, %%rax\n");
+ fprintf(out, " je .L%ld\n", label_exit);
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " cmp $0, %%rax\n");
+ fprintf(out, " je .L%ld\n", label_exit);
+ fprintf(out, " mov $1, %%rax\n");
+ fprintf(out, ".L%ld:\n", label_exit);
+
+ return;
+ }
+ case AST_BINOP_LOGICAL_OR: {
+ size_t label_t = codegen_linux_x86_64_get_next_label();
+ size_t label_f = codegen_linux_x86_64_get_next_label();
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
+ fprintf(out, " cmp $0, %%rax\n");
+ fprintf(out, " jne .L%ld\n", label_t);
+
+ codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
+ fprintf(out, " cmp $0, %%rax\n");
+ fprintf(out, " je .L%ld\n", label_f);
+
+ fprintf(out, ".L%ld:\n", label_t);
+ fprintf(out, " mov $1, %%rax\n");
+ fprintf(out, ".L%ld:\n", label_f);
+
+ return;
+ }
+ default: {
+ assert(0 && "unsupported binary operation");
+ return;
+ }
+ }
+ }
default:
- assert(0 && "NOT IMPLEMENTED");
+ assert(0 && "unsupported expression");
}
}
diff --git a/src/parser.c b/src/parser.c
index eefca01..24094b3 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -152,7 +152,7 @@ get_binary_op_precedence(token_kind_t kind)
case TOKEN_CMP_LEQ:
case TOKEN_CMP_GEQ:
return BINOP_CMP_RELATIONAL_PREC;
- case TOKEN_EQ:
+ case TOKEN_CMP_EQ:
case TOKEN_CMP_NEQ:
return BINOP_CMP_EQUALITY_PREC;
case TOKEN_AND:
diff --git a/tests/integration/tests/0002_binary_operator_addition.ol b/tests/integration/tests/0002_binary_operator_addition.ol
new file mode 100644
index 0000000..e408b47
--- /dev/null
+++ b/tests/integration/tests/0002_binary_operator_addition.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator +
+fn main(): u32 {
+ return 10 + 11
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=21)
diff --git a/tests/integration/tests/0003_binary_operator_multiplication.ol b/tests/integration/tests/0003_binary_operator_multiplication.ol
new file mode 100644
index 0000000..8826d5d
--- /dev/null
+++ b/tests/integration/tests/0003_binary_operator_multiplication.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator *
+fn main(): u32 {
+ return 10 * 11
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=110)
diff --git a/tests/integration/tests/0004_binary_operator_division.ol b/tests/integration/tests/0004_binary_operator_division.ol
new file mode 100644
index 0000000..0578fc7
--- /dev/null
+++ b/tests/integration/tests/0004_binary_operator_division.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator /
+fn main(): u32 {
+ return 13 / 3 / 3
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=1)
diff --git a/tests/integration/tests/0005_binary_operator_reminder.ol b/tests/integration/tests/0005_binary_operator_reminder.ol
new file mode 100644
index 0000000..e4d0276
--- /dev/null
+++ b/tests/integration/tests/0005_binary_operator_reminder.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator %
+fn main(): u32 {
+ return 13 % 3 % 3
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=1)
diff --git a/tests/integration/tests/0006_binary_operator_subtraction.ol b/tests/integration/tests/0006_binary_operator_subtraction.ol
new file mode 100644
index 0000000..cf16f4a
--- /dev/null
+++ b/tests/integration/tests/0006_binary_operator_subtraction.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator -
+fn main(): u32 {
+ return 2024 - 1988
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=36)
diff --git a/tests/integration/tests/0007_binary_operator_eq.ol b/tests/integration/tests/0007_binary_operator_eq.ol
new file mode 100644
index 0000000..08dd243
--- /dev/null
+++ b/tests/integration/tests/0007_binary_operator_eq.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator ==
+fn main(): u32 {
+ return 10 == 10 == 1 == 1
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=1)
diff --git a/tests/integration/tests/0008_binary_operator_lt.ol b/tests/integration/tests/0008_binary_operator_lt.ol
new file mode 100644
index 0000000..bd175fa
--- /dev/null
+++ b/tests/integration/tests/0008_binary_operator_lt.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator <
+fn main(): u32 {
+ return 10 < 11
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=1)
diff --git a/tests/integration/tests/0009_binary_operator_gt.ol b/tests/integration/tests/0009_binary_operator_gt.ol
new file mode 100644
index 0000000..69d6cec
--- /dev/null
+++ b/tests/integration/tests/0009_binary_operator_gt.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator >
+fn main(): u32 {
+ return 128 > 255
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=0)
diff --git a/tests/integration/tests/0010_binary_operator_neq.ol b/tests/integration/tests/0010_binary_operator_neq.ol
new file mode 100644
index 0000000..db4efe8
--- /dev/null
+++ b/tests/integration/tests/0010_binary_operator_neq.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator !=
+fn main(): u32 {
+ return 10 != 20
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=1)
diff --git a/tests/integration/tests/0011_binary_operator_leq.ol b/tests/integration/tests/0011_binary_operator_leq.ol
new file mode 100644
index 0000000..63927ee
--- /dev/null
+++ b/tests/integration/tests/0011_binary_operator_leq.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator <=
+fn main(): u32 {
+ return 10 <= 20
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=1)
diff --git a/tests/integration/tests/0012_binary_operator_geq.ol b/tests/integration/tests/0012_binary_operator_geq.ol
new file mode 100644
index 0000000..4737bc3
--- /dev/null
+++ b/tests/integration/tests/0012_binary_operator_geq.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator >=
+fn main(): u32 {
+ return 10 >= 11
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=0)
diff --git a/tests/integration/tests/0013_binary_operator_lshift.ol b/tests/integration/tests/0013_binary_operator_lshift.ol
new file mode 100644
index 0000000..8239114
--- /dev/null
+++ b/tests/integration/tests/0013_binary_operator_lshift.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator <<
+fn main(): u32 {
+ return 11 << 1
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=22)
diff --git a/tests/integration/tests/0014_binary_operator_rshift.ol b/tests/integration/tests/0014_binary_operator_rshift.ol
new file mode 100644
index 0000000..fc40e92
--- /dev/null
+++ b/tests/integration/tests/0014_binary_operator_rshift.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator >>
+fn main(): u32 {
+ return 10 >> 1
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=5)
diff --git a/tests/integration/tests/0015_binary_operator_xor.ol b/tests/integration/tests/0015_binary_operator_xor.ol
new file mode 100644
index 0000000..c5c0568
--- /dev/null
+++ b/tests/integration/tests/0015_binary_operator_xor.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator ^
+fn main(): u32 {
+ return 10 ^ 11
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=1)
diff --git a/tests/integration/tests/0016_binary_operator_and.ol b/tests/integration/tests/0016_binary_operator_and.ol
new file mode 100644
index 0000000..7a60ac3
--- /dev/null
+++ b/tests/integration/tests/0016_binary_operator_and.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator &
+fn main(): u32 {
+ return 10 & 11
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=10)
diff --git a/tests/integration/tests/0017_binary_operator_or.ol b/tests/integration/tests/0017_binary_operator_or.ol
new file mode 100644
index 0000000..4c82b49
--- /dev/null
+++ b/tests/integration/tests/0017_binary_operator_or.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator |
+fn main(): u32 {
+ return 10 | 11
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=11)
diff --git a/tests/integration/tests/0018_binary_operator_logical_and.ol b/tests/integration/tests/0018_binary_operator_logical_and.ol
new file mode 100644
index 0000000..aeb0885
--- /dev/null
+++ b/tests/integration/tests/0018_binary_operator_logical_and.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator &&
+fn main(): u32 {
+ return 10 && 11
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=1)
diff --git a/tests/integration/tests/0019_binary_operator_logical_or.ol b/tests/integration/tests/0019_binary_operator_logical_or.ol
new file mode 100644
index 0000000..f889afe
--- /dev/null
+++ b/tests/integration/tests/0019_binary_operator_logical_or.ol
@@ -0,0 +1,22 @@
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# spec: Binary operator ||
+fn main(): u32 {
+ return 10 || 11
+}
+
+# TEST test_compile(exit_code=0)
+# TEST test_run_binary(exit_code=1)
--
2.46.0
^ permalink raw reply [flat|nested] 5+ messages in thread