From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id SL8cDt8wy2ZsXQEAe85BDQ:P1 (envelope-from ) for ; Sun, 25 Aug 2024 15:25:51 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id SL8cDt8wy2ZsXQEAe85BDQ (envelope-from ) for ; Sun, 25 Aug 2024 15:25:51 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; none Received: from mail-a.sr.ht (mail-a.sr.ht [46.23.81.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 284737466C for ; Sun, 25 Aug 2024 15:25:51 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=PJA9sW/aAA8vm37LQgcwtSSDIDyp4LioY05wNPs8pL8=; c=simple/simple; d=lists.sr.ht; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1724592351; v=1; b=FCsP+mJ7XCKapfCOQfQvV4FRYiNOECNTN6Yaow66Td5xOUX+NT+ZhgK54GOgDCwTx6IgUaoS C8+dHoun9FD6vWZ2F6nNV8aMb8S0vu2hReLemt1gW2qtCRbl5hNUkz9ywOycqepk0NDh3qR+Sfm Qjwa0Yz502ZqodfMikPeACm6axKI5MFmY6D/jlkLFIuLd0sBIiiyZXdBg0tcsnP0h5hb3CMwMCI gPfZMDSI7X8qU+X4XL1pC41DwzhpxBDt+1JWIt0e+fPDLTHN3COZ/oYuA8h4aES2McR4t3iVcYe 4l3znkc1LF5suQuxpqGaj1gk/8lF17zQbmFpHEC1MfpNA== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id EDE6620207 for ; Sun, 25 Aug 2024 13:25:50 +0000 (UTC) Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) by mail-a.sr.ht (Postfix) with ESMTPS id 590A1201FA for <~johnnyrichard/olang-devel@lists.sr.ht>; Sun, 25 Aug 2024 13:25:50 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1724592350; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y9jd/67cK1Wj4ZYGI3XEZyTbbGg0nSguuM7wUfzZmog=; b=jQGcpLYWJ2+e1fsQC8fVSlrWZBz11s1ywBL6N37ROkK2B1DIINP9G4UCOpsTZJ4lArYuM2 h+8+sBPfyh5o1FO8+RAz7YmzT5EqREgqtUzdLEHVT5LaPavqCLUgJzVim4Xe0vLjGK2xmH xOS2m0ghPvVV02l5CNS8hFDVa5g7TiZsPmuqGAQj+HTPV6jQWEamh0kGff2uzbdVQMlRkK owT0t3rybC0BScNkNVql68Idg23+HCXR0Mbkp0uOvxDXmp7lEECkqsUwjiyHWlrb0g+UN8 I01DiuUej5ItZ/iv1KF1mLLJ0RWqy4Cvf1+ZytWaCEq8Y6Hh2c14l1Xq4Y6dQQ== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Johnny Richard Subject: [PATCH olang v2 2/2] codegen: x86_64: implement binary operations Date: Sun, 25 Aug 2024 15:16:44 +0200 Message-ID: <20240825132523.253490-3-johnny@johnnyrichard.com> In-Reply-To: <20240825132523.253490-1-johnny@johnnyrichard.com> References: <20240825132523.253490-1-johnny@johnnyrichard.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Sourcehut-Patchset-Status: PROPOSED List-Unsubscribe: List-Subscribe: List-Archive: Archived-At: List-Post: List-ID: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel.lists.sr.ht> Sender: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel@lists.sr.ht> X-Migadu-Flow: FLOW_IN X-Migadu-Country: NL X-Migadu-Spam-Score: -4.00 X-Spam-Score: -4.00 X-Migadu-Queue-Id: 284737466C X-Migadu-Scanner: mx11.migadu.com X-TUID: EjJqSKVTDZlv 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 --- 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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 . + +# 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