From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:700:3204::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id iCfAF4wM8mUHVgEAbAwnHQ (envelope-from ) for ; Wed, 13 Mar 2024 21:29:00 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id KG1kEIwM8mVBEAEAe85BDQ (envelope-from ) for ; Wed, 13 Mar 2024 21:29:00 +0100 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 2C937204A8 for ; Wed, 13 Mar 2024 21:29:00 +0100 (CET) DKIM-Signature: a=rsa-sha256; bh=ccYkwZWB+v1h9af5BhPuweVh+gvGeH8WRSEsk5n1Pmk=; 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=1710361739; v=1; b=Bu0IpfzLun7Zcq+yfdardT9MWJKfRYkmFPHShfWWwLNCZs/R4y78DKq1utyCF0maLMj72nbq T+opttfYY1pHBv8XWUFQMn9jeHeMjTevy+uERYHHqayUyUdUzUJIoKUAUOQzVWW25yuXLG1qmYb VfeG43q7/cuQbgGAzJ7dfR9Gqyga98WpxCXXIFwTUxltbpdrRd1ckZDWS1J2Tijz4cr6FjMmcGd 5A2638SOrMUapVuSkUKZNfAvU+LhYFWYG92pZgiX6e8k62n0M8O3U2frc+0A911yRWMEzE5Lv4s xPVR1o05uz347ADRTg/MzTUhg+uLiY4pm1hLiT5mpRYHQ== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id DA33620280 for ; Wed, 13 Mar 2024 20:28:59 +0000 (UTC) Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) by mail-a.sr.ht (Postfix) with ESMTPS id 3073720280 for <~johnnyrichard/olang-devel@lists.sr.ht>; Wed, 13 Mar 2024 20:28:59 +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=1710361738; 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=Uc2+zJqBaC9o/e3iNfz2uyQ4dtGUJTEbYjsVdu3BvXo=; b=bOdOoETiLj90n/q3a+dU3CG1UKmed49O0vju9//GKWcf/cLfLfgAWSqQ8IZcDZMI1X2YzL 2VOW8HbG6S7bSaIUzxBXIpnniLGETHS6/A1KCRbm2I6s7eH+kF0WLcahefFqyQIpyBZLUw mDt2IGGL5SOQ11G1oPWEgyrzvX4vosCmkia+tkT+Glq2NWyTlPBrmPpRJAEj/ng3f5n9CM HtoEFQUJVyq5c/eDF/AsAYonYqrOpx7bo+4K3c5wfsAgT9JFrTVZnP+l5BEoBwvtWOP5lz IVKKhg+4854lPUEjZvt3r6pIqCj4pBeA7TzRodE6VRT//770EUz8P5ykSrFN6g== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Johnny Richard Subject: [PATCH olang v1 2/3] ast: create binary operation ast node Date: Wed, 13 Mar 2024 22:21:51 +0100 Message-ID: <20240313212855.174554-3-johnny@johnnyrichard.com> In-Reply-To: <20240313212855.174554-1-johnny@johnnyrichard.com> References: <20240313212855.174554-1-johnny@johnnyrichard.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Sourcehut-Patchset-Status: UNKNOWN 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-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -4.00 X-Spam-Score: -4.00 X-Migadu-Queue-Id: 2C937204A8 X-TUID: 1BS4RB8+U5L4 Signed-off-by: Johnny Richard --- src/ast.c | 14 ++++++++++++++ src/ast.h | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/ast.c b/src/ast.c index ab56c96..c9f33a4 100644 --- a/src/ast.c +++ b/src/ast.c @@ -52,6 +52,20 @@ ast_new_node_fn_def(arena_t *arena, string_view_t identifier, type_t return_type return node_fn_def; } +ast_node_t * +ast_new_node_bin_op(arena_t *arena, ast_binary_op_kind_t kind, ast_node_t *lhs, ast_node_t *rhs) +{ + ast_node_t *node_bin_op = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); + assert(node_bin_op); + + node_bin_op->kind = AST_NODE_BINARY_OP; + node_bin_op->data.as_bin_op.kind = kind; + node_bin_op->data.as_bin_op.lhs = lhs; + node_bin_op->data.as_bin_op.rhs = rhs; + + return node_bin_op; +} + ast_node_t * ast_new_node_literal_u32(arena_t *arena, uint32_t value) { diff --git a/src/ast.h b/src/ast.h index 2b42781..206a827 100644 --- a/src/ast.h +++ b/src/ast.h @@ -30,6 +30,7 @@ typedef enum AST_NODE_PROGRAM, AST_NODE_BLOCK, AST_NODE_FN_DEF, + AST_NODE_BINARY_OP, AST_NODE_RETURN_STMT, AST_NODE_LITERAL, AST_NODE_UNKNOWN @@ -73,6 +74,21 @@ typedef struct ast_literal ast_literal_value_t value; } ast_literal_t; +typedef enum ast_binary_op_kind +{ + AST_BINOP_ADDITION, + AST_BINOP_SUBTRACTION, + AST_BINOP_MULTIPLICATION, + AST_BINOP_DIVISION, +} ast_binary_op_kind_t; + +typedef struct ast_binary_op +{ + ast_binary_op_kind_t kind; + ast_node_t *lhs; + ast_node_t *rhs; +} ast_binary_op_t; + typedef struct ast_return_stmt { ast_node_t *data; @@ -82,6 +98,7 @@ typedef union { ast_program_t as_program; ast_fn_definition_t as_fn_def; + ast_binary_op_t as_bin_op; ast_literal_t as_literal; ast_block_t as_block; ast_return_stmt_t as_return_stmt; @@ -99,6 +116,9 @@ ast_new_program(arena_t *arena, ast_node_t *fn_def); ast_node_t * ast_new_node_fn_def(arena_t *arena, string_view_t identifier, type_t return_type, ast_node_t *block); +ast_node_t * +ast_new_node_bin_op(arena_t *arena, ast_binary_op_kind_t kind, ast_node_t *lhs, ast_node_t *rhs); + ast_node_t * ast_new_node_literal_u32(arena_t *arena, uint32_t value); -- 2.44.0