From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.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 cFbHJgQvB2ecLQEA62LTzQ:P1 (envelope-from ) for ; Thu, 10 Oct 2024 03:33:56 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id cFbHJgQvB2ecLQEA62LTzQ (envelope-from ) for ; Thu, 10 Oct 2024 03:33:56 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=aUR6ZiFG; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=vQLKu7rp; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=none) header.from=maniero.me; arc=pass ("mailchannels.net:s=arc-2022:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1728524036; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=gOJEdb/LujIYJSmzmBj71H5ulx11JXKiMDZR7YVQ5f0=; b=JTEGXSkh1YijZsy1ra4BO8xw66HCNG97YjUfN2gdg3faMUmBayxtIrisXumpU4Q4btNFqU /dgeCEsSdGS94ps7lmtxEMiw7jm+eAzDjrbSttK8YxI8YRFVxCX3eDFUhJwMNQiRykwkWC Euy2QlM+gWbHSuTMigxtgK20Ct8y6E4bXFIuB7oDUCm/eov11s579X7ZvyDT8wRI5DGYdb 582I5C5cz2zH6EzjXK3fBQJh+PaizTksGmmmnin5BhzVqRt8d3Wgg3CR3DR05aqkg3zi2C RTRMsA3BFGPygOc5g7f3ksiBpBX6Q1v9RPAlD0ON32lvqHc9WFwRkC0h4M2W2A== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=aUR6ZiFG; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=vQLKu7rp; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=none) header.from=maniero.me; arc=pass ("mailchannels.net:s=arc-2022:i=1") ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1728524036; a=rsa-sha256; cv=pass; b=lHYZTdqYCvkmk0TNfdZS5tKYO+m3SBnqeoxKNdYOoJDhKJSVV6VIoZbNKURaouM62G27wf v6hsuVorMjZ9gkXm/wiUp34769pVZvJQqVr2RGNJVYOkCsnUY5AfF5Fbfss2RqMMyh8kVc dGZOFXCVOlHgRzYFJHSMSn/LKDaX0/51ZgW0WdJug4da7WyN3w8tW/KU4VCC8zVhHfs3fs z+5na1p0XOuoKXVJZ4tC0B4RBh9VB/TXzPE4O575H9oIgrfZ7X02/Hj/xv2pbH/HWIwMPT kkaFL4u5zc4bHcdC1MpjnEB4Fvu0ryHlT2B4m8WqYMmpkxrZoq4TCd7hI0vOnA== 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 85E5286F62 for ; Thu, 10 Oct 2024 03:33:56 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=Z1HKiUmBl8AhHFXIe4wtAc/DtQDZARH3iH42fWjGJBE=; c=simple/simple; d=lists.sr.ht; h=From:To:Cc:Subject:In-Reply-To:References:Date:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1728524036; v=1; b=aUR6ZiFG6U48OkSI6YrzWiynIMvBgv2tOezmSY8QLm2KmWGFFrJAuhMpRSZJuQfAYZiDERFG JgHi/eJiNYbAYtzHQSBIjdXQHNmalgFY1vC8iZa7ghnyGOvzF4PY7waNUlHBXcXZdcoPyiBFhEb 8/CGKZyJiCA1kGpJiZ4g3xOoHgFAIKLP6EiWq3y4HR6cACNcXzBctXoBkD+t9D/aEvEei3Jqpx3 azZN4e3bmJQM/9DWJ2s1CKjXG4dJRa0C4TyODwoZUBuzDh6XoD8/OCdW49OaTdQHnRGUr3VWCJS oUYcCmXRj9veL7Y9TGSObofQDqIJOEXhh6RdWvabOPRcw== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 3906E20201 for ; Thu, 10 Oct 2024 01:33:56 +0000 (UTC) Received: from dragonfly.ash.relay.mailchannels.net (dragonfly.ash.relay.mailchannels.net [23.83.222.51]) by mail-a.sr.ht (Postfix) with ESMTPS id F304F201EF for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 10 Oct 2024 01:33:53 +0000 (UTC) X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 3C3718A52AD for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 10 Oct 2024 01:33:51 +0000 (UTC) Received: from nl-srv-smtpout1.hostinger.io (trex-13.trex.outbound.svc.cluster.local [100.100.145.244]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id 485218A50A0 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 10 Oct 2024 01:33:50 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1728524030; a=rsa-sha256; cv=none; b=MIz7NxKoQ77d2XtZ6yDwsvav4HMac8QLwpvBV8phx3MnWPa4BOF07IopLlnDHoFRwldkIV 41qIlYSicUFpDKfNM26v4tIK0YN9nIGrVs+mpiEPPh1FhXUdTUrkcpovEIhMjCYcdn4wyq NTxAMWASIJgBbr296fOxIn3+/PyR4c5W5AFHxT3b6uubXyj94YtwaqFiTk2ZtSu4zeNtYI FUf3Ba5PqmkMRKK4c2kG3ekimEqE1csjZ5WonAn0gldr113t0J7AvP8TgrH5kxFZGUiNJC NL+R6ssTGIbRXPvkOjaJQ2SN1XG+01Y7is0nlMw8Hh/trZPWIPtylyK5I6K5Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1728524030; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gOJEdb/LujIYJSmzmBj71H5ulx11JXKiMDZR7YVQ5f0=; b=vYefp+6bvY/9LIKehNtDTVF2rRl3gPqGG9DoJl5/AnvQb/JkQlE4BOGbpF03OKeyeUH6b+ 7Xda1i+4nLNSvkJxS5ELjWB1+DLW/7D1P4/eDiTWsTtnQFLiMOZUoWD8D058SRzEb+WXrl 96cz+hiISowgP8ZWgvt/Rhtnf+AX4uXiOaQ7J912yDhZrXUEPQ+EmTOqBekbnJ2SZnAAOr gUPCVsXJfEQY4KHFIVKnuV89amRDK88zEEmsS5cU3mVyAMVzMpXAvpvDS5R8T3pLWn6PNy 5ID/FiZpeTjA9yjkXFY47wIm4KSAcYZfp//OJ6KKOrubFtbWlnIjsl2xuKv/Xg== ARC-Authentication-Results: i=1; rspamd-585564d48b-6gdlk; auth=pass smtp.auth=hostingeremail smtp.mailfrom=carlos@maniero.me X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me X-MC-Relay: Neutral X-MailChannels-SenderId: hostingeremail|x-authuser|carlos@maniero.me X-MailChannels-Auth-Id: hostingeremail X-Zesty-Trade: 66a9a9d66de51dcf_1728524031170_1649783687 X-MC-Loop-Signature: 1728524031170:3945533129 X-MC-Ingress-Time: 1728524031170 Received: from nl-srv-smtpout1.hostinger.io (nl-srv-smtpout1.hostinger.io [145.14.150.87]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.100.145.244 (trex/7.0.2); Thu, 10 Oct 2024 01:33:51 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1728524028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gOJEdb/LujIYJSmzmBj71H5ulx11JXKiMDZR7YVQ5f0=; b=vQLKu7rpw91Hcapfa+W61FGs3JESaHBXQBerQCOl6e51YvN9dzZTOhTELmxvGBuZiT+Rjy ZRot+AbtLQ6D1+YIwGXjQmKAMpbH96sMzva/Tijz3+wSu9+vcsHGUgdKEfI8DW2utBBrMf 0Peiaf+910ub2169cx6Hs8Ooz87QhmlagAT44cVft4f3a6hVValB2g8Jt9xUPfQkyZtafr deSr6eWJHME84xMD+6HDsNz02KhPysQkoJQ97Byf9zI4IEuZPKw83TTDdyMPqcK6ajM1jl EeL/Mkp53ZaK2lcUA6N8bpyUblOnCT4jpexpIWp6i2VCQN+ZJhDZ9b9MDsN8sQ== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang v1 6/6] codestyle: limit the code to 80 characters Message-ID: <20241010013318.222905-7-carlos@maniero.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241010013318.222905-1-carlos@maniero.me> References: <20241010013318.222905-1-carlos@maniero.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: Thu, 10 Oct 2024 01:33:47 +0000 (UTC) X-CM-Envelope: MS4xfEJGu99vVpwiQW7ESfHTRtzJAmv6D8qJZgOV+khtkBigrgeMGpNSKp3h4C0wq01n1TGp2xOtOqvbGa53ZuSzXpeD4bh0+o0jNxrWmebbbLNQiy8VCp9R PKWhatF/pBFx/cEDCmZH5pNMgICtRhVOtri1pUK7FYvLMEAgcdFkhut1KXqI8cIW2PRVXDSqKWjwVEO5Z7OaRszwm20lZIgGHPRfgPWCdrsNdLdgt82/HANZ X-CM-Analysis: v=2.4 cv=bZY5U/PB c=1 sm=1 tr=0 ts=67072efc a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=IkcTkHD0fZMA:10 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=Nr8eyNsbxsX-LJanrpwA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=BXDaF_L80NY05PYiAFlV:22 X-AuthUser: carlos@maniero.me 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-Country: NL X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -2.10 X-Spam-Score: -2.10 X-Migadu-Queue-Id: 85E5286F62 X-TUID: Xd0uorfQuBHf Signed-off-by: Carlos Maniero --- .clang-format | 4 +- src/ast.c | 82 +++++-- src/ast.h | 52 +++- src/checker.c | 13 +- src/cli.c | 3 +- src/codegen_linux_x86_64.c | 434 +++++++++++++++++++++++++++------- src/codegen_linux_x86_64.h | 5 +- src/lexer.c | 61 +++-- src/main.c | 26 +- src/map.c | 15 +- src/parser.c | 95 ++++++-- src/pretty_print_ast.c | 100 +++++--- src/scope.c | 12 +- tests/unit/arena_test.c | 26 +- tests/unit/list_test.c | 33 ++- tests/unit/map_test.c | 25 +- tests/unit/string_view_test.c | 30 ++- 17 files changed, 799 insertions(+), 217 deletions(-) diff --git a/.clang-format b/.clang-format index a1e9892..bdc2904 100644 --- a/.clang-format +++ b/.clang-format @@ -77,7 +77,7 @@ BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeComma BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true -ColumnLimit: 120 +ColumnLimit: 80 CommentPragmas: '^ IWYU pragma:' QualifierAlignment: Leave CompactNamespaces: false @@ -145,7 +145,7 @@ ObjCSpaceBeforeProtocolList: false PenaltyBreakAssignment: 2 PenaltyBreakBeforeFirstCallParameter: 19 PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 +PenaltyBreakFirstLessLess: 80 PenaltyBreakOpenParenthesis: 0 PenaltyBreakString: 1000 PenaltyBreakTemplateDeclaration: 10 diff --git a/src/ast.c b/src/ast.c index 1a23864..dd8dd66 100644 --- a/src/ast.c +++ b/src/ast.c @@ -51,7 +51,8 @@ ast_new_node_fn_def( assert(params); assert(block); - ast_node_t *node_fn_def = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); + ast_node_t *node_fn_def = + (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); assert(node_fn_def); node_fn_def->kind = AST_NODE_FN_DEF; @@ -67,11 +68,17 @@ ast_new_node_fn_def( } ast_node_t * -ast_new_node_fn_call(arena_t *arena, token_loc_t loc, string_view_t id, list_t *args) { +ast_new_node_fn_call( + arena_t *arena, + token_loc_t loc, + string_view_t id, + list_t *args +) { assert(arena); assert(args); - ast_node_t *node_fn_call = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); + ast_node_t *node_fn_call = + (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); assert(node_fn_call); node_fn_call->kind = AST_NODE_FN_CALL; @@ -85,8 +92,15 @@ ast_new_node_fn_call(arena_t *arena, token_loc_t loc, string_view_t id, list_t * } ast_node_t * -ast_new_node_var_def(arena_t *arena, token_loc_t loc, string_view_t id, type_t *type, ast_node_t *value) { - ast_node_t *node_var_def = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); +ast_new_node_var_def( + arena_t *arena, + token_loc_t loc, + string_view_t id, + type_t *type, + ast_node_t *value +) { + ast_node_t *node_var_def = + (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); assert(node_var_def); node_var_def->kind = AST_NODE_VAR_DEF; @@ -101,8 +115,15 @@ ast_new_node_var_def(arena_t *arena, token_loc_t loc, string_view_t id, type_t * } ast_node_t * -ast_new_node_bin_op(arena_t *arena, token_loc_t loc, 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)); +ast_new_node_bin_op( + arena_t *arena, + token_loc_t loc, + 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; @@ -115,8 +136,14 @@ ast_new_node_bin_op(arena_t *arena, token_loc_t loc, ast_binary_op_kind_t kind, } ast_node_t * -ast_new_node_unary_op(arena_t *arena, token_loc_t loc, ast_unary_op_kind_t kind, ast_node_t *expr) { - ast_node_t *node_unary_op = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); +ast_new_node_unary_op( + arena_t *arena, + token_loc_t loc, + ast_unary_op_kind_t kind, + ast_node_t *expr +) { + ast_node_t *node_unary_op = + (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); assert(node_unary_op); node_unary_op->kind = AST_NODE_UNARY_OP; @@ -129,7 +156,8 @@ ast_new_node_unary_op(arena_t *arena, token_loc_t loc, ast_unary_op_kind_t kind, ast_node_t * ast_new_node_literal_u32(arena_t *arena, token_loc_t loc, uint32_t value) { - ast_node_t *node_literal = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); + ast_node_t *node_literal = + (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); assert(node_literal); node_literal->kind = AST_NODE_LITERAL; @@ -153,8 +181,14 @@ ast_new_node_ref(arena_t *arena, token_loc_t loc, string_view_t id) { } ast_node_t * -ast_new_node_var_assign_stmt(arena_t *arena, token_loc_t loc, ast_node_t *ref, ast_node_t *expr) { - ast_node_t *node_var_assign_stmt = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); +ast_new_node_var_assign_stmt( + arena_t *arena, + token_loc_t loc, + ast_node_t *ref, + ast_node_t *expr +) { + ast_node_t *node_var_assign_stmt = + (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); assert(node_var_assign_stmt); node_var_assign_stmt->kind = AST_NODE_VAR_ASSIGN_STMT; @@ -167,7 +201,8 @@ ast_new_node_var_assign_stmt(arena_t *arena, token_loc_t loc, ast_node_t *ref, a ast_node_t * ast_new_node_return_stmt(arena_t *arena, token_loc_t loc, ast_node_t *expr) { - ast_node_t *node_return_stmt = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); + ast_node_t *node_return_stmt = + (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); assert(node_return_stmt); node_return_stmt->kind = AST_NODE_RETURN_STMT; @@ -178,7 +213,13 @@ ast_new_node_return_stmt(arena_t *arena, token_loc_t loc, ast_node_t *expr) { } ast_node_t * -ast_new_node_if_stmt(arena_t *arena, token_loc_t loc, ast_node_t *cond, ast_node_t *then, ast_node_t *_else) { +ast_new_node_if_stmt( + arena_t *arena, + token_loc_t loc, + ast_node_t *cond, + ast_node_t *then, + ast_node_t *_else +) { ast_node_t *node_if_stmt = arena_alloc(arena, sizeof(ast_node_t)); assert(node_if_stmt); @@ -192,7 +233,12 @@ ast_new_node_if_stmt(arena_t *arena, token_loc_t loc, ast_node_t *cond, ast_node } ast_node_t * -ast_new_node_while_stmt(arena_t *arena, token_loc_t loc, ast_node_t *cond, ast_node_t *then) { +ast_new_node_while_stmt( + arena_t *arena, + token_loc_t loc, + ast_node_t *cond, + ast_node_t *then +) { ast_node_t *node_while_stmt = arena_alloc(arena, sizeof(ast_node_t)); assert(node_while_stmt); @@ -206,7 +252,8 @@ ast_new_node_while_stmt(arena_t *arena, token_loc_t loc, ast_node_t *cond, ast_n ast_node_t * ast_new_node_block(arena_t *arena) { - ast_node_t *node_block = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); + ast_node_t *node_block = + (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t)); assert(node_block); node_block->kind = AST_NODE_BLOCK; @@ -221,7 +268,8 @@ ast_new_node_block(arena_t *arena) { ast_fn_param_t * ast_new_fn_param(arena_t *arena, string_view_t id, type_t *type) { - ast_fn_param_t *fn_param = (ast_fn_param_t *)arena_alloc(arena, sizeof(ast_fn_param_t)); + ast_fn_param_t *fn_param = + (ast_fn_param_t *)arena_alloc(arena, sizeof(ast_fn_param_t)); assert(fn_param); fn_param->id = id; diff --git a/src/ast.h b/src/ast.h index 98e035f..8380b38 100644 --- a/src/ast.h +++ b/src/ast.h @@ -209,16 +209,38 @@ ast_new_node_fn_def( ); ast_node_t * -ast_new_node_fn_call(arena_t *arena, token_loc_t loc, string_view_t id, list_t *args); +ast_new_node_fn_call( + arena_t *arena, + token_loc_t loc, + string_view_t id, + list_t *args +); ast_node_t * -ast_new_node_var_def(arena_t *arena, token_loc_t loc, string_view_t id, type_t *type, ast_node_t *value); +ast_new_node_var_def( + arena_t *arena, + token_loc_t loc, + string_view_t id, + type_t *type, + ast_node_t *value +); ast_node_t * -ast_new_node_bin_op(arena_t *arena, token_loc_t loc, ast_binary_op_kind_t kind, ast_node_t *lhs, ast_node_t *rhs); +ast_new_node_bin_op( + arena_t *arena, + token_loc_t loc, + ast_binary_op_kind_t kind, + ast_node_t *lhs, + ast_node_t *rhs +); ast_node_t * -ast_new_node_unary_op(arena_t *arena, token_loc_t loc, ast_unary_op_kind_t kind, ast_node_t *expr); +ast_new_node_unary_op( + arena_t *arena, + token_loc_t loc, + ast_unary_op_kind_t kind, + ast_node_t *expr +); ast_node_t * ast_new_node_literal_u32(arena_t *arena, token_loc_t loc, uint32_t value); @@ -227,16 +249,32 @@ ast_node_t * ast_new_node_ref(arena_t *arena, token_loc_t loc, string_view_t id); ast_node_t * -ast_new_node_var_assign_stmt(arena_t *arena, token_loc_t loc, ast_node_t *ref, ast_node_t *expr); +ast_new_node_var_assign_stmt( + arena_t *arena, + token_loc_t loc, + ast_node_t *ref, + ast_node_t *expr +); ast_node_t * ast_new_node_return_stmt(arena_t *arena, token_loc_t loc, ast_node_t *expr); ast_node_t * -ast_new_node_if_stmt(arena_t *arena, token_loc_t loc, ast_node_t *cond, ast_node_t *then, ast_node_t *_else); +ast_new_node_if_stmt( + arena_t *arena, + token_loc_t loc, + ast_node_t *cond, + ast_node_t *then, + ast_node_t *_else +); ast_node_t * -ast_new_node_while_stmt(arena_t *arena, token_loc_t loc, ast_node_t *cond, ast_node_t *then); +ast_new_node_while_stmt( + arena_t *arena, + token_loc_t loc, + ast_node_t *cond, + ast_node_t *then +); ast_node_t * ast_new_node_block(arena_t *arena); diff --git a/src/checker.c b/src/checker.c index 1613c04..28df2d6 100644 --- a/src/checker.c +++ b/src/checker.c @@ -29,7 +29,9 @@ checker_new(arena_t *arena) { checker_t *checker = (checker_t *)arena_alloc(arena, sizeof(checker_t)); if (checker == NULL) { - fprintf(stderr, "[FATAL] Out of memory: checker_new: %s\n", strerror(errno)); + fprintf( + stderr, "[FATAL] Out of memory: checker_new: %s\n", strerror(errno) + ); exit(EXIT_FAILURE); } checker->arena = arena; @@ -114,7 +116,8 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast) { fn_def->scope = scope_push(scope); type_resolve(fn_def->return_type); - symbol_t *symbol = symbol_new(checker->arena, fn_def->id, fn_def->return_type); + symbol_t *symbol = + symbol_new(checker->arena, fn_def->id, fn_def->return_type); scope_insert(scope, symbol); list_item_t *item = list_head(fn_def->params); @@ -123,7 +126,8 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast) { ast_fn_param_t *param = (ast_fn_param_t *)item->value; type_resolve(param->type); - symbol_t *symbol = symbol_new(checker->arena, param->id, param->type); + symbol_t *symbol = + symbol_new(checker->arena, param->id, param->type); scope_insert(fn_def->scope, symbol); item = list_next(item); @@ -213,7 +217,8 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast) { type_resolve(ast->as_var_def.type); - symbol_t *symbol = symbol_new(checker->arena, id, ast->as_var_def.type); + symbol_t *symbol = + symbol_new(checker->arena, id, ast->as_var_def.type); scope_insert(scope, symbol); ast->as_var_def.scope = scope; diff --git a/src/cli.c b/src/cli.c index 1f30ea3..1765ecf 100644 --- a/src/cli.c +++ b/src/cli.c @@ -64,7 +64,8 @@ cli_parse_args(int argc, char **argv) { arg = cli_args_shift(&args); } - if (opts.options & CLI_OPT_OUTPUT || opts.options & CLI_OPT_DUMP_TOKENS || opts.options & CLI_OPT_DUMP_AST) { + if (opts.options & CLI_OPT_OUTPUT || opts.options & CLI_OPT_DUMP_TOKENS || + opts.options & CLI_OPT_DUMP_AST) { return opts; } diff --git a/src/codegen_linux_x86_64.c b/src/codegen_linux_x86_64.c index c0b7326..aa9cfb4 100644 --- a/src/codegen_linux_x86_64.c +++ b/src/codegen_linux_x86_64.c @@ -57,22 +57,34 @@ typedef enum x86_64_register_type { * ────────────────────────────────────────────────────────────── * x86-64 rdi rsi rdx r10 r8 r9 - */ -static int x86_call_args[X86_CALL_ARG_SIZE] = { REG_DEST_IDX, REG_SRC_IDX, REG_DATA, REG_R10, REG_R8, REG_R9 }; +static int x86_call_args[X86_CALL_ARG_SIZE] = { REG_DEST_IDX, REG_SRC_IDX, + REG_DATA, REG_R10, + REG_R8, REG_R9 }; static void codegen_linux_x86_64_emit_start_entrypoint(codegen_x86_64_t *codegen); static void -codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen, ast_fn_definition_t *fn); +codegen_linux_x86_64_emit_function( + codegen_x86_64_t *codegen, + ast_fn_definition_t *fn +); static void codegen_linux_x86_64_emit_if(codegen_x86_64_t *codegen, ast_if_stmt_t is_stmt); static void -codegen_linux_x86_64_put_stack_offset(codegen_x86_64_t *codegen, symbol_t *symbol, size_t offset); +codegen_linux_x86_64_put_stack_offset( + codegen_x86_64_t *codegen, + symbol_t *symbol, + size_t offset +); static size_t -codegen_linux_x86_64_get_stack_offset(codegen_x86_64_t *codegen, symbol_t *symbol); +codegen_linux_x86_64_get_stack_offset( + codegen_x86_64_t *codegen, + symbol_t *symbol +); static size_t type_to_bytes(type_t *type); @@ -81,7 +93,11 @@ static char * get_reg_for(x86_64_register_type_t type, size_t bytes); void -codegen_linux_x86_64_init(codegen_x86_64_t *codegen, arena_t *arena, FILE *out) { +codegen_linux_x86_64_init( + codegen_x86_64_t *codegen, + arena_t *arena, + FILE *out +) { assert(codegen); assert(arena); assert(codegen); @@ -92,7 +108,10 @@ codegen_linux_x86_64_init(codegen_x86_64_t *codegen, arena_t *arena, FILE *out) } void -codegen_linux_x86_64_emit_translation_unit(codegen_x86_64_t *codegen, ast_node_t *node) { +codegen_linux_x86_64_emit_translation_unit( + codegen_x86_64_t *codegen, + ast_node_t *node +) { codegen->label_index = 0; codegen_linux_x86_64_emit_start_entrypoint(codegen); @@ -141,7 +160,10 @@ codegen_linux_x86_64_get_next_label(codegen_x86_64_t *codegen) { typedef size_t size_in_bytes_t; static size_in_bytes_t -codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr_node) { +codegen_linux_x86_64_emit_expression( + codegen_x86_64_t *codegen, + ast_node_t *expr_node +) { switch (expr_node->kind) { case AST_NODE_LITERAL: { ast_literal_t literal_u32 = expr_node->as_literal; @@ -157,11 +179,17 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr symbol_t *symbol = scope_lookup(ref.scope, ref.id); assert(symbol); - size_t offset = codegen_linux_x86_64_get_stack_offset(codegen, symbol); + size_t offset = + codegen_linux_x86_64_get_stack_offset(codegen, symbol); size_t bytes = type_to_bytes(symbol->type); - fprintf(codegen->out, " mov -%ld(%%rbp), %s\n", offset, get_reg_for(REG_ACCUMULATOR, bytes)); + fprintf( + codegen->out, + " mov -%ld(%%rbp), %s\n", + offset, + get_reg_for(REG_ACCUMULATOR, bytes) + ); return bytes; } case AST_NODE_FN_CALL: { @@ -171,7 +199,8 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr assert(symbol); size_t i = 0; - for (list_item_t *item = list_head(fn_call.args); item != NULL; item = list_next(item)) { + for (list_item_t *item = list_head(fn_call.args); item != NULL; + item = list_next(item)) { // FIXME: add support for more args than X86_CALL_ARG_SIZE assert(i < X86_CALL_ARG_SIZE); @@ -179,12 +208,20 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr codegen_linux_x86_64_emit_expression(codegen, arg_node); - fprintf(codegen->out, " push %s\n", get_reg_for(REG_ACCUMULATOR, 8)); + fprintf( + codegen->out, + " push %s\n", + get_reg_for(REG_ACCUMULATOR, 8) + ); ++i; } for (; i > 0; --i) { - fprintf(codegen->out, " pop %s\n", get_reg_for(x86_call_args[i - 1], 8)); + fprintf( + codegen->out, + " pop %s\n", + get_reg_for(x86_call_args[i - 1], 8) + ); } fprintf(codegen->out, " call " SV_FMT "\n", SV_ARG(fn_call.id)); @@ -196,13 +233,20 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr switch (bin_op.kind) { case AST_BINOP_ADDITION: { fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); - size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); + size_in_bytes_t expr_bytes = + bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); fprintf( @@ -216,48 +260,81 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr } case AST_BINOP_MULTIPLICATION: { fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); - size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); + size_in_bytes_t expr_bytes = + bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); - fprintf(codegen->out, " mul %s\n", get_reg_for(REG_COUNTER, expr_bytes)); + fprintf( + codegen->out, + " mul %s\n", + get_reg_for(REG_COUNTER, expr_bytes) + ); return expr_bytes; } case AST_BINOP_DIVISION: { fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); - size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); + size_in_bytes_t expr_bytes = + bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); fprintf(codegen->out, " xor %%rdx, %%rdx\n"); - fprintf(codegen->out, " div %s\n", get_reg_for(REG_COUNTER, expr_bytes)); + fprintf( + codegen->out, + " div %s\n", + get_reg_for(REG_COUNTER, expr_bytes) + ); return expr_bytes; } case AST_BINOP_REMINDER: { fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); - size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); + size_in_bytes_t expr_bytes = + bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); fprintf(codegen->out, " xor %%rdx, %%rdx\n"); - fprintf(codegen->out, " div %s\n", get_reg_for(REG_COUNTER, expr_bytes)); + fprintf( + codegen->out, + " div %s\n", + get_reg_for(REG_COUNTER, expr_bytes) + ); fprintf( codegen->out, " mov %s, %s\n", @@ -269,13 +346,20 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr } case AST_BINOP_SUBTRACTION: { fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); - size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); + size_in_bytes_t expr_bytes = + bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); fprintf( @@ -289,13 +373,20 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr } case AST_BINOP_CMP_EQ: { fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); - size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); + size_in_bytes_t expr_bytes = + bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); fprintf( @@ -305,19 +396,30 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr get_reg_for(REG_ACCUMULATOR, expr_bytes) ); fprintf(codegen->out, " sete %%al\n"); - fprintf(codegen->out, " movzb %%al, %s\n", get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " movzb %%al, %s\n", + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); return expr_bytes; } case AST_BINOP_CMP_LT: { fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); - size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); + size_in_bytes_t expr_bytes = + bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); fprintf( @@ -327,19 +429,30 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr get_reg_for(REG_ACCUMULATOR, expr_bytes) ); fprintf(codegen->out, " setl %%al\n"); - fprintf(codegen->out, " movzb %%al, %s\n", get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " movzb %%al, %s\n", + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); return expr_bytes; } case AST_BINOP_CMP_GT: { fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); - size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); + size_in_bytes_t expr_bytes = + bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); fprintf( @@ -349,19 +462,30 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr get_reg_for(REG_ACCUMULATOR, expr_bytes) ); fprintf(codegen->out, " setg %%al\n"); - fprintf(codegen->out, " movzb %%al, %s\n", get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " movzb %%al, %s\n", + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); return expr_bytes; } case AST_BINOP_CMP_NEQ: { fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); - size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); + size_in_bytes_t expr_bytes = + bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); fprintf( @@ -371,19 +495,30 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr get_reg_for(REG_ACCUMULATOR, expr_bytes) ); fprintf(codegen->out, " setne %%al\n"); - fprintf(codegen->out, " movzb %%al, %s\n", get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " movzb %%al, %s\n", + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); return expr_bytes; } case AST_BINOP_CMP_LEQ: { fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); - size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); + size_in_bytes_t expr_bytes = + bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); fprintf( @@ -393,19 +528,30 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr get_reg_for(REG_ACCUMULATOR, expr_bytes) ); fprintf(codegen->out, " setle %%al\n"); - fprintf(codegen->out, " movzb %%al, %s\n", get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " movzb %%al, %s\n", + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); return expr_bytes; } case AST_BINOP_CMP_GEQ: { fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); - size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); + size_in_bytes_t expr_bytes = + bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); fprintf( @@ -415,7 +561,11 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr get_reg_for(REG_ACCUMULATOR, expr_bytes) ); fprintf(codegen->out, " setge %%al\n"); - fprintf(codegen->out, " movzb %%al, %s\n", get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " movzb %%al, %s\n", + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); return expr_bytes; } @@ -425,10 +575,17 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); fprintf(codegen->out, " pop %%rcx\n"); - fprintf(codegen->out, " shl %%cl, %s\n", get_reg_for(REG_ACCUMULATOR, lhs_bytes)); + fprintf( + codegen->out, + " shl %%cl, %s\n", + get_reg_for(REG_ACCUMULATOR, lhs_bytes) + ); return lhs_bytes; } @@ -438,22 +595,36 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); fprintf(codegen->out, " pop %%rcx\n"); - fprintf(codegen->out, " shr %%cl, %s\n", get_reg_for(REG_ACCUMULATOR, lhs_bytes)); + fprintf( + codegen->out, + " shr %%cl, %s\n", + get_reg_for(REG_ACCUMULATOR, lhs_bytes) + ); return lhs_bytes; } case AST_BINOP_BITWISE_XOR: { fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); - size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); + size_in_bytes_t expr_bytes = + bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); fprintf( @@ -467,13 +638,20 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr } case AST_BINOP_BITWISE_AND: { fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); - size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); + size_in_bytes_t expr_bytes = + bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); fprintf( @@ -487,13 +665,20 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr } case AST_BINOP_BITWISE_OR: { fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); fprintf(codegen->out, " push %%rax\n"); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); - size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); + size_in_bytes_t expr_bytes = + bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); fprintf( @@ -506,16 +691,31 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr return expr_bytes; } case AST_BINOP_LOGICAL_AND: { - size_t label_exit = codegen_linux_x86_64_get_next_label(codegen); + size_t label_exit = + codegen_linux_x86_64_get_next_label(codegen); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); - fprintf(codegen->out, " cmp $0, %s\n", get_reg_for(REG_ACCUMULATOR, lhs_bytes)); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); + fprintf( + codegen->out, + " cmp $0, %s\n", + get_reg_for(REG_ACCUMULATOR, lhs_bytes) + ); fprintf(codegen->out, " je .L%ld\n", label_exit); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); - fprintf(codegen->out, " cmp $0, %s\n", get_reg_for(REG_ACCUMULATOR, rhs_bytes)); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); + fprintf( + codegen->out, + " cmp $0, %s\n", + get_reg_for(REG_ACCUMULATOR, rhs_bytes) + ); fprintf(codegen->out, " je .L%ld\n", label_exit); fprintf(codegen->out, " mov $1, %%rax\n"); fprintf(codegen->out, ".L%ld:\n", label_exit); @@ -523,17 +723,33 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr return 1; } case AST_BINOP_LOGICAL_OR: { - size_t label_t = codegen_linux_x86_64_get_next_label(codegen); - size_t label_f = codegen_linux_x86_64_get_next_label(codegen); + size_t label_t = + codegen_linux_x86_64_get_next_label(codegen); + size_t label_f = + codegen_linux_x86_64_get_next_label(codegen); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t lhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.lhs); - fprintf(codegen->out, " cmp $0, %s\n", get_reg_for(REG_ACCUMULATOR, lhs_bytes)); + size_in_bytes_t lhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.lhs + ); + fprintf( + codegen->out, + " cmp $0, %s\n", + get_reg_for(REG_ACCUMULATOR, lhs_bytes) + ); fprintf(codegen->out, " jne .L%ld\n", label_t); fprintf(codegen->out, " xor %%rax, %%rax\n"); - size_in_bytes_t rhs_bytes = codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); - fprintf(codegen->out, " cmp $0, %s\n", get_reg_for(REG_ACCUMULATOR, rhs_bytes)); + size_in_bytes_t rhs_bytes = + codegen_linux_x86_64_emit_expression( + codegen, bin_op.rhs + ); + fprintf( + codegen->out, + " cmp $0, %s\n", + get_reg_for(REG_ACCUMULATOR, rhs_bytes) + ); fprintf(codegen->out, " je .L%ld\n", label_f); fprintf(codegen->out, ".L%ld:\n", label_t); @@ -553,9 +769,16 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr ast_unary_op_t unary_op = expr_node->as_unary_op; switch (unary_op.kind) { case AST_UNARY_BITWISE_NOT: { - size_in_bytes_t expr_bytes = codegen_linux_x86_64_emit_expression(codegen, unary_op.expr); + size_in_bytes_t expr_bytes = + codegen_linux_x86_64_emit_expression( + codegen, unary_op.expr + ); - fprintf(codegen->out, " not %s\n", get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " not %s\n", + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); return expr_bytes; } @@ -599,10 +822,14 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block) { symbol_t *symbol = scope_lookup(scope, var_def.id); assert(symbol); - codegen_linux_x86_64_put_stack_offset(codegen, symbol, codegen->base_offset); + codegen_linux_x86_64_put_stack_offset( + codegen, symbol, codegen->base_offset + ); if (var_def.value) { - codegen_linux_x86_64_emit_expression(codegen, var_def.value); + codegen_linux_x86_64_emit_expression( + codegen, var_def.value + ); } size_t type_size = type_to_bytes(symbol->type); @@ -626,12 +853,18 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block) { symbol_t *symbol = scope_lookup(scope, ref.id); assert(symbol); - size_t offset = codegen_linux_x86_64_get_stack_offset(codegen, symbol); + size_t offset = + codegen_linux_x86_64_get_stack_offset(codegen, symbol); codegen_linux_x86_64_emit_expression(codegen, var_assign.expr); size_t type_size = type_to_bytes(symbol->type); - fprintf(codegen->out, " mov %s, -%ld(%%rbp)\n", get_reg_for(REG_ACCUMULATOR, type_size), offset); + fprintf( + codegen->out, + " mov %s, -%ld(%%rbp)\n", + get_reg_for(REG_ACCUMULATOR, type_size), + offset + ); break; } @@ -647,7 +880,8 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block) { ast_node_t *cond = while_stmt.cond; ast_node_t *then = while_stmt.then; - size_t begin_label = codegen_linux_x86_64_get_next_label(codegen); + size_t begin_label = + codegen_linux_x86_64_get_next_label(codegen); size_t end_label = codegen_linux_x86_64_get_next_label(codegen); fprintf(codegen->out, ".L%ld:\n", begin_label); @@ -655,7 +889,9 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block) { fprintf(codegen->out, " cmp $1, %%rax\n"); fprintf(codegen->out, " jnz .L%ld\n", end_label); - assert(then->kind == AST_NODE_BLOCK && "invalid while-then block"); + assert( + then->kind == AST_NODE_BLOCK && "invalid while-then block" + ); ast_block_t then_block = then->as_block; codegen_linux_x86_64_emit_block(codegen, &then_block); @@ -754,7 +990,8 @@ calculate_fn_local_size(scope_t *scope) { list_item_t *item = list_head(scope->children); while (item != NULL) { - size_t child_local_size = calculate_fn_local_size((scope_t *)item->value); + size_t child_local_size = + calculate_fn_local_size((scope_t *)item->value); if (child_local_size > max_child_local_size) { max_child_local_size = child_local_size; @@ -767,7 +1004,10 @@ calculate_fn_local_size(scope_t *scope) { } static void -codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen, ast_fn_definition_t *fn_def) { +codegen_linux_x86_64_emit_function( + codegen_x86_64_t *codegen, + ast_fn_definition_t *fn_def +) { codegen->base_offset = X86_CALL_EIP_STACK_OFFSET; ast_node_t *block_node = fn_def->block; @@ -777,7 +1017,8 @@ codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen, ast_fn_definition_ fprintf(codegen->out, " mov %%rsp, %%rbp\n"); size_t i = 0; - for (list_item_t *item = list_head(fn_def->params); item != NULL; item = list_next(item)) { + for (list_item_t *item = list_head(fn_def->params); item != NULL; + item = list_next(item)) { assert(i < X86_CALL_ARG_SIZE); ast_fn_param_t *param = item->value; @@ -787,7 +1028,9 @@ codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen, ast_fn_definition_ size_t offset = codegen->base_offset; - codegen_linux_x86_64_put_stack_offset(codegen, symbol, codegen->base_offset); + codegen_linux_x86_64_put_stack_offset( + codegen, symbol, codegen->base_offset + ); fprintf( codegen->out, @@ -815,7 +1058,11 @@ codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen, ast_fn_definition_ } static void -codegen_linux_x86_64_put_stack_offset(codegen_x86_64_t *codegen, symbol_t *symbol, size_t offset) { +codegen_linux_x86_64_put_stack_offset( + codegen_x86_64_t *codegen, + symbol_t *symbol, + size_t offset +) { size_t *stack_offset = arena_alloc(codegen->arena, sizeof(size_t)); *stack_offset = offset; @@ -826,7 +1073,10 @@ codegen_linux_x86_64_put_stack_offset(codegen_x86_64_t *codegen, symbol_t *symbo } static size_t -codegen_linux_x86_64_get_stack_offset(codegen_x86_64_t *codegen, symbol_t *symbol) { +codegen_linux_x86_64_get_stack_offset( + codegen_x86_64_t *codegen, + symbol_t *symbol +) { char symbol_ptr[PTR_HEX_CSTR_SIZE]; sprintf(symbol_ptr, "%lx", (uintptr_t)symbol); diff --git a/src/codegen_linux_x86_64.h b/src/codegen_linux_x86_64.h index 3c5a10e..a1de3ab 100644 --- a/src/codegen_linux_x86_64.h +++ b/src/codegen_linux_x86_64.h @@ -34,6 +34,9 @@ void codegen_linux_x86_64_init(codegen_x86_64_t *codegen, arena_t *arena, FILE *out); void -codegen_linux_x86_64_emit_translation_unit(codegen_x86_64_t *codegen, ast_node_t *prog); +codegen_linux_x86_64_emit_translation_unit( + codegen_x86_64_t *codegen, + ast_node_t *prog +); #endif /* CODEGEN_X86_64_H */ diff --git a/src/lexer.c b/src/lexer.c index c11bacf..633f0ed 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -49,7 +49,12 @@ static void lexer_init_char_value_token(lexer_t *lexer, token_t *token, token_kind_t kind); static void -lexer_init_str_value_token(lexer_t *lexer, token_t *token, token_kind_t kind, lexer_cursor_t cur); +lexer_init_str_value_token( + lexer_t *lexer, + token_t *token, + token_kind_t kind, + lexer_cursor_t cur +); static void lexer_init_eof_token(lexer_t *lexer, token_t *token); @@ -93,7 +98,9 @@ lexer_next_token(lexer_t *lexer, token_t *token) { .size = lexer->cur.offset - start_cur.offset, }; - lexer_init_str_value_token(lexer, token, lexer_str_to_token_kind(text), start_cur); + lexer_init_str_value_token( + lexer, token, lexer_str_to_token_kind(text), start_cur + ); return; } @@ -115,7 +122,9 @@ lexer_next_token(lexer_t *lexer, token_t *token) { if (lexer_current_char(lexer) == '=') { lexer_skip_char(lexer); - lexer_init_str_value_token(lexer, token, TOKEN_CMP_EQ, start_cur); + lexer_init_str_value_token( + lexer, token, TOKEN_CMP_EQ, start_cur + ); return; } @@ -128,7 +137,9 @@ lexer_next_token(lexer_t *lexer, token_t *token) { if (lexer_current_char(lexer) == '=') { lexer_skip_char(lexer); - lexer_init_str_value_token(lexer, token, TOKEN_CMP_NEQ, start_cur); + lexer_init_str_value_token( + lexer, token, TOKEN_CMP_NEQ, start_cur + ); return; } @@ -141,7 +152,9 @@ lexer_next_token(lexer_t *lexer, token_t *token) { if (lexer_current_char(lexer) == '&') { lexer_skip_char(lexer); - lexer_init_str_value_token(lexer, token, TOKEN_LOGICAL_AND, start_cur); + lexer_init_str_value_token( + lexer, token, TOKEN_LOGICAL_AND, start_cur + ); return; } @@ -154,7 +167,9 @@ lexer_next_token(lexer_t *lexer, token_t *token) { if (lexer_current_char(lexer) == '|') { lexer_skip_char(lexer); - lexer_init_str_value_token(lexer, token, TOKEN_LOGICAL_OR, start_cur); + lexer_init_str_value_token( + lexer, token, TOKEN_LOGICAL_OR, start_cur + ); return; } @@ -168,16 +183,22 @@ lexer_next_token(lexer_t *lexer, token_t *token) { switch (lexer_current_char(lexer)) { case '<': { lexer_skip_char(lexer); - lexer_init_str_value_token(lexer, token, TOKEN_BITWISE_LSHIFT, start_cur); + lexer_init_str_value_token( + lexer, token, TOKEN_BITWISE_LSHIFT, start_cur + ); return; } case '=': { lexer_skip_char(lexer); - lexer_init_str_value_token(lexer, token, TOKEN_CMP_LEQ, start_cur); + lexer_init_str_value_token( + lexer, token, TOKEN_CMP_LEQ, start_cur + ); return; } default: { - lexer_init_str_value_token(lexer, token, TOKEN_LT, start_cur); + lexer_init_str_value_token( + lexer, token, TOKEN_LT, start_cur + ); return; } } @@ -189,16 +210,22 @@ lexer_next_token(lexer_t *lexer, token_t *token) { switch (lexer_current_char(lexer)) { case '>': { lexer_skip_char(lexer); - lexer_init_str_value_token(lexer, token, TOKEN_BITWISE_RSHIFT, start_cur); + lexer_init_str_value_token( + lexer, token, TOKEN_BITWISE_RSHIFT, start_cur + ); return; } case '=': { lexer_skip_char(lexer); - lexer_init_str_value_token(lexer, token, TOKEN_CMP_GEQ, start_cur); + lexer_init_str_value_token( + lexer, token, TOKEN_CMP_GEQ, start_cur + ); return; } default: { - lexer_init_str_value_token(lexer, token, TOKEN_GT, start_cur); + lexer_init_str_value_token( + lexer, token, TOKEN_GT, start_cur + ); return; } } @@ -410,7 +437,12 @@ lexer_init_char_value_token(lexer_t *lexer, token_t *token, token_kind_t kind) { } static void -lexer_init_str_value_token(lexer_t *lexer, token_t *token, token_kind_t kind, lexer_cursor_t cur) { +lexer_init_str_value_token( + lexer_t *lexer, + token_t *token, + token_kind_t kind, + lexer_cursor_t cur +) { string_view_t str = { .chars = lexer->src.code.chars + cur.offset, .size = lexer->cur.offset - cur.offset, @@ -493,7 +525,8 @@ token_loc_to_line(token_loc_t loc) { .size = 0, }; - while ((line.size + offset) < loc.src.code.size && line.chars[line.size] != '\n' && line.chars[line.size] != 0) { + while ((line.size + offset) < loc.src.code.size && + line.chars[line.size] != '\n' && line.chars[line.size] != 0) { ++line.size; } diff --git a/src/main.c b/src/main.c index 0e174a1..bc2eabf 100644 --- a/src/main.c +++ b/src/main.c @@ -154,7 +154,9 @@ handle_codegen_linux(cli_opts_t *opts) { } else if (strcmp(opts->arch, "aarch64") == 0) { codegen_linux_aarch64_emit_translation_unit(out, ast); } else { - fprintf(stderr, "error: architecture '%s' not supported\n", opts->arch); + fprintf( + stderr, "error: architecture '%s' not supported\n", opts->arch + ); cli_print_usage(stderr, opts->compiler_path); exit(EXIT_FAILURE); } @@ -167,7 +169,13 @@ handle_codegen_linux(cli_opts_t *opts) { } char command[512]; - sprintf(command, "%s/bin/as %s -o " SV_FMT ".o", opts->sysroot, asm_file, SV_ARG(opts->output_bin)); + sprintf( + command, + "%s/bin/as %s -o " SV_FMT ".o", + opts->sysroot, + asm_file, + SV_ARG(opts->output_bin) + ); int exit_code = system(command); @@ -207,7 +215,12 @@ read_entire_file(char *filepath, arena_t *arena) { FILE *stream = fopen(filepath, "rb"); if (stream == NULL) { - fprintf(stderr, "error: could not open file %s: %s\n", filepath, strerror(errno)); + fprintf( + stderr, + "error: could not open file %s: %s\n", + filepath, + strerror(errno) + ); exit(EXIT_FAILURE); } @@ -222,7 +235,12 @@ read_entire_file(char *filepath, arena_t *arena) { code.chars = (char *)arena_alloc(arena, (size_t)code.size); if (code.chars == NULL) { - fprintf(stderr, "error: could not read file %s: %s\n", filepath, strerror(errno)); + fprintf( + stderr, + "error: could not read file %s: %s\n", + filepath, + strerror(errno) + ); exit(EXIT_FAILURE); } diff --git a/src/map.c b/src/map.c index 31100b4..0c6ccd6 100644 --- a/src/map.c +++ b/src/map.c @@ -41,7 +41,9 @@ map_t * map_new(arena_t *arena) { map_t *map = (map_t *)arena_alloc(arena, sizeof(map_t)); if (map == NULL) { - fprintf(stderr, "[FATAL] Out of memory: map_new: %s\n", strerror(errno)); + fprintf( + stderr, "[FATAL] Out of memory: map_new: %s\n", strerror(errno) + ); exit(EXIT_FAILURE); } map->arena = arena; @@ -52,11 +54,15 @@ map_new(arena_t *arena) { static void map_init(map_t *map) { assert(map); - map->entries = (map_entry_t *)arena_alloc(map->arena, MAP_INITIAL_CAPACITY * sizeof(map_entry_t)); + map->entries = (map_entry_t *)arena_alloc( + map->arena, MAP_INITIAL_CAPACITY * sizeof(map_entry_t) + ); assert(map->entries != NULL); memset(map->entries, 0, MAP_INITIAL_CAPACITY * sizeof(map_entry_t)); if (map->entries == NULL) { - fprintf(stderr, "[FATAL] Out of memory: map_init: %s\n", strerror(errno)); + fprintf( + stderr, "[FATAL] Out of memory: map_init: %s\n", strerror(errno) + ); exit(EXIT_FAILURE); } map->capacity = MAP_INITIAL_CAPACITY; @@ -97,7 +103,8 @@ map_put(map_t *map, char *key, void *value) { break; } if (entry->next == NULL) { - entry->next = (map_entry_t *)arena_alloc(map->arena, sizeof(map_entry_t)); + entry->next = + (map_entry_t *)arena_alloc(map->arena, sizeof(map_entry_t)); *entry->next = (map_entry_t){ .key = _strdup(key, map->arena), .hash = hash, diff --git a/src/parser.c b/src/parser.c index 385d1a5..29cfbe8 100644 --- a/src/parser.c +++ b/src/parser.c @@ -148,7 +148,11 @@ token_kind_to_binary_op_kind(token_kind_t kind) { case TOKEN_LOGICAL_OR: return AST_BINOP_LOGICAL_OR; default: { - fprintf(stderr, "error: token kind (%s) not compatible with binary op kind\n", token_kind_to_cstr(kind)); + fprintf( + stderr, + "error: token kind (%s) not compatible with binary op kind\n", + token_kind_to_cstr(kind) + ); assert(false); } } @@ -220,7 +224,9 @@ token_kind_to_unary_op_kind(token_kind_t token_kind) { case TOKEN_BANG: return AST_UNARY_LOGICAL_NOT; default: - assert(false && "unable to covert the token_kind_t to unary_op_kind_t"); + assert( + false && "unable to covert the token_kind_t to unary_op_kind_t" + ); } } @@ -242,12 +248,21 @@ parser_parse_expr_1(parser_t *parser, ast_node_t *lhs, size_t prev_precedence) { lexer_peek_next(parser->lexer, &lookahead_token); while (token_kind_is_binary_op(lookahead_token.kind) && - get_binary_op_precedence(lookahead_token.kind) > get_binary_op_precedence(token_op.kind)) { - rhs = parser_parse_expr_1(parser, rhs, get_binary_op_precedence(token_op.kind)); + get_binary_op_precedence(lookahead_token.kind) > + get_binary_op_precedence(token_op.kind)) { + rhs = parser_parse_expr_1( + parser, rhs, get_binary_op_precedence(token_op.kind) + ); lexer_peek_next(parser->lexer, &lookahead_token); } - lhs = ast_new_node_bin_op(parser->arena, token_op.loc, token_kind_to_binary_op_kind(token_op.kind), lhs, rhs); + lhs = ast_new_node_bin_op( + parser->arena, + token_op.loc, + token_kind_to_binary_op_kind(token_op.kind), + lhs, + rhs + ); if (lhs == NULL) { return NULL; } @@ -273,7 +288,9 @@ parser_parse_factor(parser_t *parser) { switch (token.kind) { case TOKEN_NUMBER: - return ast_new_node_literal_u32(parser->arena, token.loc, string_view_to_u32(token.value)); + return ast_new_node_literal_u32( + parser->arena, token.loc, string_view_to_u32(token.value) + ); case TOKEN_ID: { token_t token_id = token; @@ -282,10 +299,14 @@ parser_parse_factor(parser_t *parser) { if (token.kind == TOKEN_OPAREN) { list_t *args = parser_parse_fn_args(parser); - return ast_new_node_fn_call(parser->arena, token_id.loc, token_id.value, args); + return ast_new_node_fn_call( + parser->arena, token_id.loc, token_id.value, args + ); } - return ast_new_node_ref(parser->arena, token_id.loc, token_id.value); + return ast_new_node_ref( + parser->arena, token_id.loc, token_id.value + ); } case TOKEN_AND: case TOKEN_STAR: @@ -315,7 +336,11 @@ parser_parse_factor(parser_t *parser) { return expr; } default: { - fprintf(stderr, "error: parse_factor: unsupported or invalid token (%s)\n", token_kind_to_cstr(token.kind)); + fprintf( + stderr, + "error: parse_factor: unsupported or invalid token (%s)\n", + token_kind_to_cstr(token.kind) + ); assert(false); } } @@ -329,7 +354,11 @@ parser_parse_fn_args(parser_t *parser) { list_t *args = arena_alloc(parser->arena, sizeof(list_t)); if (args == NULL) { - fprintf(stderr, "[FATAL] Out of memory: parser_parse_fn_args: %s\n", strerror(errno)); + fprintf( + stderr, + "[FATAL] Out of memory: parser_parse_fn_args: %s\n", + strerror(errno) + ); exit(EXIT_FAILURE); } @@ -370,7 +399,11 @@ parser_parse_fn_params(parser_t *parser) { list_t *params = arena_alloc(parser->arena, sizeof(list_t)); if (params == NULL) { - fprintf(stderr, "[FATAL] Out of memory: parser_parse_fn_params: %s\n", strerror(errno)); + fprintf( + stderr, + "[FATAL] Out of memory: parser_parse_fn_params: %s\n", + strerror(errno) + ); exit(EXIT_FAILURE); } @@ -398,7 +431,8 @@ parser_parse_fn_params(parser_t *parser) { return NULL; } - ast_fn_param_t *param = ast_new_fn_param(parser->arena, token.value, type); + ast_fn_param_t *param = + ast_new_fn_param(parser->arena, token.value, type); list_append(params, param); skip_line_feeds(parser->lexer); @@ -447,7 +481,14 @@ parser_parse_fn_definition(parser_t *parser) { return NULL; } - return ast_new_node_fn_def(parser->arena, fn_name_token.loc, fn_name_token.value, params, ret_type, block); + return ast_new_node_fn_def( + parser->arena, + fn_name_token.loc, + fn_name_token.value, + params, + ret_type, + block + ); } static type_t * @@ -478,7 +519,8 @@ parser_parse_type(parser_t *parser) { } string_view_t ptr_id = token.value; - ptr_id.size = ptr_token.value.chars - token.value.chars + ptr_token.value.size; + ptr_id.size = + ptr_token.value.chars - token.value.chars + ptr_token.value.size; return type_new_ptr(parser->arena, ptr_id, type); } @@ -574,7 +616,8 @@ parser_parse_return_stmt(parser_t *parser) { return NULL; } - ast_node_t *node_return_stmt = ast_new_node_return_stmt(parser->arena, token_ret.loc, expr); + ast_node_t *node_return_stmt = + ast_new_node_return_stmt(parser->arena, token_ret.loc, expr); assert(node_return_stmt); return node_return_stmt; @@ -624,7 +667,8 @@ parser_parse_if_stmt(parser_t *parser) { } } - ast_node_t *node_if_stmt = ast_new_node_if_stmt(parser->arena, token_if.loc, cond, then, _else); + ast_node_t *node_if_stmt = + ast_new_node_if_stmt(parser->arena, token_if.loc, cond, then, _else); assert(node_if_stmt); @@ -655,7 +699,8 @@ parser_parse_while_stmt(parser_t *parser) { token_t next_token; peek_next_non_lf_token(parser->lexer, &next_token); - ast_node_t *node_while_stmt = ast_new_node_while_stmt(parser->arena, token_while.loc, cond, then); + ast_node_t *node_while_stmt = + ast_new_node_while_stmt(parser->arena, token_while.loc, cond, then); assert(node_while_stmt); @@ -688,7 +733,9 @@ parser_parse_var_def(parser_t *parser) { return NULL; } - ast_node_t *var_node = ast_new_node_var_def(parser->arena, token_id.loc, token_id.value, type, expr); + ast_node_t *var_node = ast_new_node_var_def( + parser->arena, token_id.loc, token_id.value, type, expr + ); return var_node; } @@ -707,7 +754,8 @@ parser_parse_var_assign_stmt(parser_t *parser) { return NULL; } - ast_node_t *ref = ast_new_node_ref(parser->arena, token_id.loc, token_id.value); + ast_node_t *ref = + ast_new_node_ref(parser->arena, token_id.loc, token_id.value); ast_node_t *expr = parser_parse_expr(parser); return ast_new_node_var_assign_stmt(parser->arena, token_eq.loc, ref, expr); @@ -720,7 +768,11 @@ skip_expected_token(parser_t *parser, token_kind_t expected_kind) { } static bool -expected_next_token(parser_t *parser, token_t *token, token_kind_t expected_kind) { +expected_next_token( + parser_t *parser, + token_t *token, + token_kind_t expected_kind +) { lexer_next_token(parser->lexer, token); return expected_token(token, expected_kind); } @@ -730,7 +782,8 @@ expected_token(token_t *token, token_kind_t expected_kind) { if (token->kind != expected_kind) { fprintf( stderr, - "%s:%lu:%lu: syntax error: got '" SV_FMT "' token but expect '%s'\n", + "%s:%lu:%lu: syntax error: got '" SV_FMT + "' token but expect '%s'\n", token->loc.src.filepath, token_loc_to_lineno(token->loc), token_loc_to_colno(token->loc), diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c index 38199ed..c694f82 100644 --- a/src/pretty_print_ast.c +++ b/src/pretty_print_ast.c @@ -76,7 +76,12 @@ pretty_print_print_ident(uint64_t *prefix, size_t level, bool lst_children) { } static void -pretty_print_tree(pretty_print_node_t *node, uint64_t *prefix, size_t level, bool lst_children) { +pretty_print_tree( + pretty_print_node_t *node, + uint64_t *prefix, + size_t level, + bool lst_children +) { pretty_print_print_ident(prefix, level, lst_children); list_t *list = node->children; @@ -89,14 +94,16 @@ pretty_print_tree(pretty_print_node_t *node, uint64_t *prefix, size_t level, boo size_t size = list_size(list); for (size_t i = 0; i < size; ++i) { - pretty_print_node_t *it = (pretty_print_node_t *)list_get(list, i)->value; + pretty_print_node_t *it = + (pretty_print_node_t *)list_get(list, i)->value; pretty_print_tree(it, prefix, level + 1, i + 1 == size); } } static pretty_print_node_t * pretty_print_node_new(arena_t *arena) { - pretty_print_node_t *node = (pretty_print_node_t *)arena_alloc(arena, sizeof(pretty_print_node_t)); + pretty_print_node_t *node = + (pretty_print_node_t *)arena_alloc(arena, sizeof(pretty_print_node_t)); node->children = (list_t *)arena_alloc(arena, sizeof(list_t)); list_init(node->children, arena); return node; @@ -106,7 +113,12 @@ static pretty_print_node_t * pretty_print_new_fn_param(ast_fn_param_t *param, arena_t *arena) { pretty_print_node_t *node = pretty_print_node_new(arena); char name[256]; - sprintf(name, "Param_Definition ", SV_ARG(param->id), SV_ARG(param->type->id)); + sprintf( + name, + "Param_Definition ", + SV_ARG(param->id), + SV_ARG(param->type->id) + ); node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); strcpy(node->name, name); return node; @@ -124,7 +136,8 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) { while (item != NULL) { ast_node_t *decl = (ast_node_t *)item->value; - pretty_print_node_t *fn_node = ast_node_to_pretty_print_node(decl, arena); + pretty_print_node_t *fn_node = + ast_node_to_pretty_print_node(decl, arena); list_append(node->children, fn_node); item = list_next(item); @@ -143,16 +156,21 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) { SV_ARG(fn_def.id), SV_ARG(fn_def.return_type->id) ); - node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); + node->name = + (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); strcpy(node->name, name); list_item_t *param = list_head(fn_def.params); while (param != NULL) { - list_append(node->children, pretty_print_new_fn_param(param->value, arena)); + list_append( + node->children, + pretty_print_new_fn_param(param->value, arena) + ); param = list_next(param); } - pretty_print_node_t *block = ast_node_to_pretty_print_node(fn_def.block, arena); + pretty_print_node_t *block = + ast_node_to_pretty_print_node(fn_def.block, arena); list_append(node->children, block); return node; } @@ -161,13 +179,19 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) { ast_fn_call_t fn_call = ast->as_fn_call; char name[256]; - sprintf(name, "Function_Call ", SV_ARG(fn_call.id)); - node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); + sprintf( + name, "Function_Call ", SV_ARG(fn_call.id) + ); + node->name = + (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); strcpy(node->name, name); list_item_t *item = list_head(fn_call.args); while (item != NULL) { - list_append(node->children, ast_node_to_pretty_print_node(item->value, arena)); + list_append( + node->children, + ast_node_to_pretty_print_node(item->value, arena) + ); item = list_next(item); } @@ -181,8 +205,10 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) { size_t block_nodes_size = list_size(block.nodes); for (size_t i = 0; i < block_nodes_size; ++i) { - ast_node_t *ast_node = (ast_node_t *)list_get(block.nodes, i)->value; - pretty_print_node_t *child = ast_node_to_pretty_print_node(ast_node, arena); + ast_node_t *ast_node = + (ast_node_t *)list_get(block.nodes, i)->value; + pretty_print_node_t *child = + ast_node_to_pretty_print_node(ast_node, arena); list_append(node->children, child); } return node; @@ -193,8 +219,10 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) { node->name = "Var_Assigment"; - pretty_print_node_t *ref = ast_node_to_pretty_print_node(var_assign_stmt.ref, arena); - pretty_print_node_t *expr = ast_node_to_pretty_print_node(var_assign_stmt.expr, arena); + pretty_print_node_t *ref = + ast_node_to_pretty_print_node(var_assign_stmt.ref, arena); + pretty_print_node_t *expr = + ast_node_to_pretty_print_node(var_assign_stmt.expr, arena); list_append(node->children, ref); list_append(node->children, expr); @@ -207,7 +235,8 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) { node->name = "Return_Statement"; - pretty_print_node_t *child = ast_node_to_pretty_print_node(return_stmt.expr, arena); + pretty_print_node_t *child = + ast_node_to_pretty_print_node(return_stmt.expr, arena); list_append(node->children, child); return node; @@ -218,7 +247,8 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) { node->name = "If_Statement"; - pretty_print_node_t *child = ast_node_to_pretty_print_node(if_stmt.cond, arena); + pretty_print_node_t *child = + ast_node_to_pretty_print_node(if_stmt.cond, arena); list_append(node->children, child); child = ast_node_to_pretty_print_node(if_stmt.then, arena); @@ -237,7 +267,8 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) { node->name = "While_Statement"; - pretty_print_node_t *child = ast_node_to_pretty_print_node(while_stmt.cond, arena); + pretty_print_node_t *child = + ast_node_to_pretty_print_node(while_stmt.cond, arena); list_append(node->children, child); child = ast_node_to_pretty_print_node(while_stmt.then, arena); @@ -252,8 +283,12 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) { char name[256]; switch (literal.kind) { case AST_LITERAL_U32: { - sprintf(name, "Literal ", literal.as_u32); - node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); + sprintf( + name, "Literal ", literal.as_u32 + ); + node->name = (char *)arena_alloc( + arena, sizeof(char) * (strlen(name) + 1) + ); strcpy(node->name, name); break; } @@ -268,11 +303,18 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) { ast_var_definition_t var = ast->as_var_def; char name[256]; - sprintf(name, "Var_Definition ", SV_ARG(var.id), SV_ARG(var.type->id)); - node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); + sprintf( + name, + "Var_Definition ", + SV_ARG(var.id), + SV_ARG(var.type->id) + ); + node->name = + (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); strcpy(node->name, name); - pretty_print_node_t *child = ast_node_to_pretty_print_node(var.value, arena); + pretty_print_node_t *child = + ast_node_to_pretty_print_node(var.value, arena); list_append(node->children, child); return node; @@ -283,7 +325,8 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) { char name[256]; sprintf(name, "Reference ", SV_ARG(ref.id)); - node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); + node->name = + (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); strcpy(node->name, name); return node; @@ -369,8 +412,10 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) { assert(false && "binop not implemented"); } - pretty_print_node_t *lhs = ast_node_to_pretty_print_node(binop.lhs, arena); - pretty_print_node_t *rhs = ast_node_to_pretty_print_node(binop.rhs, arena); + pretty_print_node_t *lhs = + ast_node_to_pretty_print_node(binop.lhs, arena); + pretty_print_node_t *rhs = + ast_node_to_pretty_print_node(binop.rhs, arena); list_append(node->children, lhs); list_append(node->children, rhs); @@ -391,7 +436,8 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) { assert(false && "unary operation kind not implemented"); } - pretty_print_node_t *expr = ast_node_to_pretty_print_node(unary_op.expr, arena); + pretty_print_node_t *expr = + ast_node_to_pretty_print_node(unary_op.expr, arena); list_append(node->children, expr); return node; diff --git a/src/scope.c b/src/scope.c index 0cc4a74..f793bba 100644 --- a/src/scope.c +++ b/src/scope.c @@ -27,7 +27,9 @@ scope_new(arena_t *arena) { assert(arena); scope_t *scope = (scope_t *)arena_alloc(arena, sizeof(scope_t)); if (scope == NULL) { - fprintf(stderr, "[FATAL] Out of memory: scope_new: %s\n", strerror(errno)); + fprintf( + stderr, "[FATAL] Out of memory: scope_new: %s\n", strerror(errno) + ); exit(EXIT_FAILURE); } scope->arena = arena; @@ -37,7 +39,9 @@ scope_new(arena_t *arena) { list_t *children = (list_t *)arena_alloc(arena, sizeof(list_t)); if (children == NULL) { - fprintf(stderr, "[FATAL] Out of memory: scope_new: %s\n", strerror(errno)); + fprintf( + stderr, "[FATAL] Out of memory: scope_new: %s\n", strerror(errno) + ); exit(EXIT_FAILURE); } @@ -52,7 +56,9 @@ symbol_new(arena_t *arena, string_view_t id, type_t *type) { assert(arena); symbol_t *symbol = (symbol_t *)arena_alloc(arena, sizeof(symbol_t)); if (symbol == NULL) { - fprintf(stderr, "[FATAL] Out of memory: symbol_new: %s\n", strerror(errno)); + fprintf( + stderr, "[FATAL] Out of memory: symbol_new: %s\n", strerror(errno) + ); exit(EXIT_FAILURE); } symbol->id = id; diff --git a/tests/unit/arena_test.c b/tests/unit/arena_test.c index 81553c9..8acf8ec 100644 --- a/tests/unit/arena_test.c +++ b/tests/unit/arena_test.c @@ -82,11 +82,27 @@ arena_padding_test(const MunitParameter params[], void *user_data_or_fixture) { return MUNIT_OK; } -static MunitTest tests[] = { { "/arena_alloc_test", arena_alloc_test, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, - { "/arena_padding_test", arena_padding_test, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, - { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } }; - -static const MunitSuite suite = { "/arena", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE }; +static MunitTest tests[] = { + { "/arena_alloc_test", + arena_alloc_test, + NULL, + NULL, + MUNIT_TEST_OPTION_NONE, + NULL }, + { "/arena_padding_test", + arena_padding_test, + NULL, + NULL, + MUNIT_TEST_OPTION_NONE, + NULL }, + { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } +}; + +static const MunitSuite suite = { "/arena", + tests, + NULL, + 1, + MUNIT_SUITE_OPTION_NONE }; int main(int argc, char *argv[]) { diff --git a/tests/unit/list_test.c b/tests/unit/list_test.c index fe19a23..f15e16d 100644 --- a/tests/unit/list_test.c +++ b/tests/unit/list_test.c @@ -92,12 +92,33 @@ list_next_test(const MunitParameter params[], void *user_data_or_fixture) { return MUNIT_OK; } -static MunitTest tests[] = { { "/list_append_test", list_append_test, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, - { "/list_get_test", list_get_test, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, - { "/list_next_test", list_next_test, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, - { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } }; - -static const MunitSuite suite = { "/list", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE }; +static MunitTest tests[] = { + { "/list_append_test", + list_append_test, + NULL, + NULL, + MUNIT_TEST_OPTION_NONE, + NULL }, + { "/list_get_test", + list_get_test, + NULL, + NULL, + MUNIT_TEST_OPTION_NONE, + NULL }, + { "/list_next_test", + list_next_test, + NULL, + NULL, + MUNIT_TEST_OPTION_NONE, + NULL }, + { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } +}; + +static const MunitSuite suite = { "/list", + tests, + NULL, + 1, + MUNIT_SUITE_OPTION_NONE }; int main(int argc, char *argv[]) { diff --git a/tests/unit/map_test.c b/tests/unit/map_test.c index 15d82ef..b252b7f 100644 --- a/tests/unit/map_test.c +++ b/tests/unit/map_test.c @@ -37,7 +37,10 @@ test_create_new(const MunitParameter params[], void *user_data_or_fixture) { } static MunitResult -test_map_put_and_get(const MunitParameter params[], void *user_data_or_fixture) { +test_map_put_and_get( + const MunitParameter params[], + void *user_data_or_fixture +) { arena_t arena = arena_new(MAP_TEST_ARENA_CAPACITY); map_t *map = map_new(&arena); @@ -89,12 +92,26 @@ test_map_get_kvs(const MunitParameter params[], void *user_data_or_fixture) { } static MunitTest tests[] = { - { "/test_create_new", test_create_new, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, - { "/test_map_put_and_get", test_map_put_and_get, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, + { "/test_create_new", + test_create_new, + NULL, + NULL, + MUNIT_TEST_OPTION_NONE, + NULL }, + { "/test_map_put_and_get", + test_map_put_and_get, + NULL, + NULL, + MUNIT_TEST_OPTION_NONE, + NULL }, { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } }; -static const MunitSuite suite = { "/map", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE }; +static const MunitSuite suite = { "/map", + tests, + NULL, + 1, + MUNIT_SUITE_OPTION_NONE }; int main(int argc, char *argv[]) { diff --git a/tests/unit/string_view_test.c b/tests/unit/string_view_test.c index 6f42e0c..f5a962d 100644 --- a/tests/unit/string_view_test.c +++ b/tests/unit/string_view_test.c @@ -22,7 +22,10 @@ #include static MunitResult -string_view_eq_to_cstr_test(const MunitParameter params[], void *user_data_or_fixture) { +string_view_eq_to_cstr_test( + const MunitParameter params[], + void *user_data_or_fixture +) { char *name = "John Doe"; string_view_t str = { @@ -45,7 +48,10 @@ string_view_eq_to_cstr_test(const MunitParameter params[], void *user_data_or_fi } static MunitResult -string_view_to_u32_test(const MunitParameter params[], void *user_data_or_fixture) { +string_view_to_u32_test( + const MunitParameter params[], + void *user_data_or_fixture +) { char *number = "69"; string_view_t str = { @@ -66,12 +72,26 @@ string_view_to_u32_test(const MunitParameter params[], void *user_data_or_fixtur } static MunitTest tests[] = { - { "/eq_to_cstr_test", string_view_eq_to_cstr_test, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, - { "/to_u32_test", string_view_to_u32_test, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, + { "/eq_to_cstr_test", + string_view_eq_to_cstr_test, + NULL, + NULL, + MUNIT_TEST_OPTION_NONE, + NULL }, + { "/to_u32_test", + string_view_to_u32_test, + NULL, + NULL, + MUNIT_TEST_OPTION_NONE, + NULL }, { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } }; -static const MunitSuite suite = { "/string_view", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE }; +static const MunitSuite suite = { "/string_view", + tests, + NULL, + 1, + MUNIT_SUITE_OPTION_NONE }; int main(int argc, char *argv[]) { -- 2.46.0