From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id yBrlGSQECGdrgwEAe85BDQ:P1 (envelope-from ) for ; Thu, 10 Oct 2024 18:43:16 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id yBrlGSQECGdrgwEAe85BDQ (envelope-from ) for ; Thu, 10 Oct 2024 18:43:16 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b="h/xZgmVg"; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=W8M78u3b; dmarc=pass (policy=none) header.from=maniero.me; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; arc=pass ("mailchannels.net:s=arc-2022:i=1") ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1728577782; a=rsa-sha256; cv=pass; b=i6SuadXOX6r/gy4LFmu6Udz/3/Okda9UvA+5i7zM4QOfhxQ5fKtvaCak25xg+7bVFyi7IT OlP30anXIw2LM0sbn8Ch5BvozMsJKgBzstlow/K9SCTHnCSI48orcz+5J6qINAfde8y2ez 1Xm+WFKyn1Z7cPuhGINi6ZP3S/+vWAFwweDszYl6Y+VHoWUgnJgsIhe1dtqGg/d4zLVGyX FjA2zB3hK4PKRvMBRKlU4Z4jLLWZJfCLkyl/duOUMvq2Rsid2ObVQbUS7j/BBpyaBdj4j0 Vtbe65SNZUHXE8+37DuwDnTc9EUrFrMyCAuAHpMjbRcUCtB5Chp6gZVjAXl6Vg== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b="h/xZgmVg"; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=W8M78u3b; dmarc=pass (policy=none) header.from=maniero.me; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; 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=1728577782; h=from:from:sender:sender: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:list-id: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=W6TCSrHJym9C0Whfz1lCqvdx9qyVfpEcd/ox169ZJbY=; b=NEGBKvgkL1ZjA/IvqBpxNCD16q0XRBj5XE1w/v6YGsGB9NyDMtBhXgnFzF4hAX9DlS3tOJ KdZXZdBdESQG27YRQCkypkvWue+XRVtuSVJDHaZUrkgic+B4MFCyWeq9pY9AIBlj4nBzBA tM1EInqKTCsQz1x3l9kCOo43V6egqechLOvLTzRzCnGrn3z6e+rdxqhgys0Euz8G2hxHta wl5V4WztkuuqKwYGFMxvstyV7Idbzg+nt0Aq9yBCkd6HGrKufg1+rd1Y/3zoDW+E04mL8p UF30mfkgywDdUq6+EzuSjghmAlcjNiSKehKjiv5hMyJjcqAzLfsELhx125+vCw== 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 9EF64658DB for ; Thu, 10 Oct 2024 18:29:41 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=jw6gJnl6kSh7HyX4slWQuur6x1bxHTUX+KUGURCfVvA=; 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=1728577781; v=1; b=h/xZgmVgKT4cL96TC6Xkkn0B/shJjkL3UMIb4RKnbp5epJjl+37npuVtgK8A4jXn4vrHASdS ZzNIJRKWuMkiOel3MuNkrRcflp+ERvrTOfqixJ0jfYxnuTdT+1p9++txWyUrvP4sj/NCSLD4Ixu qHilxVrBdwYNaaMqu7sNTEU7n55RdYYt+RgQxGbgZOrNNJjzcQ6sa6oCOhv58zI4+OnVa/ybCxg NSUctLRgqywq8lm3Tuz/RiVAkh7rRU7H4DXLlNoRniwWdN+Sezhn56tNTjyLdxzxZk+0ZM71rF3 o6AU3uB4hlQYr2sYWU01l3aivkln7pu6H8gfvQzkr3M0w== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 16EF620218 for ; Thu, 10 Oct 2024 16:29:41 +0000 (UTC) Received: from hamster.cherry.relay.mailchannels.net (hamster.cherry.relay.mailchannels.net [23.83.223.80]) by mail-a.sr.ht (Postfix) with ESMTPS id 5965E201E1 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 10 Oct 2024 16:29:36 +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 9658F8A2A43 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 10 Oct 2024 16:29:34 +0000 (UTC) Received: from uk-fast-smtpout10.hostinger.io (100-100-145-244.trex-nlb.outbound.svc.cluster.local [100.100.145.244]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id C29898A66E2 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 10 Oct 2024 16:29:33 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1728577774; a=rsa-sha256; cv=none; b=MTthBRUFKPq8M5uq50DYP8ydNM29FOi3UP8Eb3/9ZgJTgvdNHIUhBIZf9tK/f3C/A2NvAq su9yZW+wW0/dZFH47Ia9Xe3SZyjt69xQgtEUP9eqFBgW+NpOqKaeszgDpwSaz54wsKN/q9 5KUIbLTasRYPyb53Jmb+2scX+Fo5+Dn7mhTizzNAqk96Wtmlr6sPDWzCkmJraKdhrSwQfD 9gYkDAoE/QCaZGkLeUZMHDOoW8gTJiXBwE1+MhqunxagRpZ3IhLFHr+LWYHFZ4gWIsn+Cb lNvxqLNpke8T/Dz0Q3Ksjt7uTXxKkFkQ5WX251TAnNBKy8Yx4o1QFR9GIg/LlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1728577774; 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:dkim-signature; bh=W6TCSrHJym9C0Whfz1lCqvdx9qyVfpEcd/ox169ZJbY=; b=7vKl3QvTTxrGDWZOxYykH800GmnllBfjARX9ccFEF0gW3onEqTB75ri12KqlbbZrhcNLXE SSmWMdy18xkhDopCj+vflMOG0ZROK268XoszbfaShvooKF4TT0kBHumjheX5VVMJbWhCwo H4fHDozrr5buIV4tyF44uQbtdWuI6GxvolcvTLUBNap2KhQs44sKhLVMqWTNbCf+g6CzIN 9T9iBE0hCSZqpyMfSFdQDNIBBSblnS+/X7A9r6TCnTqjZwdvOiYQjbGaQOjdYoJlFfm1K5 3nDEJ3oEAweMrlzen5wMLWXGESJ+MXlDV9cKIqk41IPURfMTIBNTrBlQdwE3EQ== ARC-Authentication-Results: i=1; rspamd-585564d48b-zgfkc; auth=pass smtp.auth=hostingeremail smtp.mailfrom=carlos@maniero.me X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me X-MC-Relay: Good X-MailChannels-SenderId: hostingeremail|x-authuser|carlos@maniero.me X-MailChannels-Auth-Id: hostingeremail X-Spicy-Eyes: 0a95a06d58e589e9_1728577774467_3448845991 X-MC-Loop-Signature: 1728577774467:4210656181 X-MC-Ingress-Time: 1728577774466 Received: from uk-fast-smtpout10.hostinger.io (uk-fast-smtpout10.hostinger.io [145.14.155.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.100.145.244 (trex/7.0.2); Thu, 10 Oct 2024 16:29:34 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1728577771; 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=W6TCSrHJym9C0Whfz1lCqvdx9qyVfpEcd/ox169ZJbY=; b=W8M78u3b+/wKLyVEnneUEbZ6XGfBv5zf6Rn0p9NC1rkNqYFNTy1QFp+A/wS8j7ZeBalJct ZwtCG3sckoRqTkwyhOoiMH1uixpKntRbXyn4SuZIeVkZsd9YZ1Iq2puWWG1N4YNlnAoiQa d4Ps2Vy9HeY448FUej0CT8SXVkkB+hD0+kW9mOCEYaXgpo2q24rBjghaxXg2HL+dW997J0 D3y6cIpUYZhvgv5ppnQJsvVmWqJCR8+rhKygGXTOvpqafRm9clJmxJ4qABq/DJsT4BX5LB pC0K04IWU61rFoqg/Uat+GD5OOTCP0kA4ZaNoEZnQ4tKQl41svrPyxduWDb9LQ== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang v3 1/2] spec: parser: enable expression on function level Message-ID: <20241010162918.338338-2-carlos@maniero.me> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241010162918.338338-1-carlos@maniero.me> References: <20241010162918.338338-1-carlos@maniero.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Date: Thu, 10 Oct 2024 16:29:31 +0000 (UTC) X-CM-Analysis: v=2.4 cv=TcnEtgQh c=1 sm=1 tr=0 ts=670800eb a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=3AFDrYDMNALC6tnY2qcA:9 a=BXDaF_L80NY05PYiAFlV:22 X-CM-Envelope: MS4xfM9sm0KJguOMzWwedFcF9GwQ4YexrnFKluKSHL5jyuDZzYmMVKlnAdYCJ9BHY1MZwLOGYGK44KaoY++f/Znboq+svSv1xTbviGhwmwcK7/K9i43bzdcp Eaa+64P3k8GUZ2SWmX+yZCl0ZKY9tC3qjq6gITUEbhw/je2Os9PZd3zD0D+iGWzhkjmrRD1+H253KPs4wF7oBrQ6/3hx0laACQQEhRYGHFAnHtnEjdf3VeDQ 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-Flow: FLOW_IN X-Migadu-Country: NL X-Migadu-Spam-Score: -0.80 X-Spam-Score: -0.80 X-Migadu-Queue-Id: 9EF64658DB X-Migadu-Scanner: mx12.migadu.com X-TUID: WYJYzb7SyIgK Previously, assignment statements were restricted to variable assignments. This commit extends their functionality by: 1. Enabling unary operators on the left-hand side (LHS) of assignments: This allows for expressions like { *a = 1 } to be valid. 2. Permitting function calls within assignment statements: This enables calling functions without explicitly capturing their return values, as demonstrated in { my_fn() }. Signed-off-by: Carlos Maniero --- docs/info/specification.texi | 18 +++++++------- src/ast.c | 14 ----------- src/ast.h | 2 +- src/checker.c | 8 ------ src/codegen_linux_x86_64.c | 35 +++++++++++++++----------- src/lexer.c | 1 + src/parser.c | 41 +++++-------------------------- src/pretty_print_ast.c | 40 ++++++++++++++++++------------ tests/olc/0029_var_assigment.ol | 2 +- tests/olc/0030_while_statement.ol | 2 +- 10 files changed, 63 insertions(+), 100 deletions(-) diff --git a/docs/info/specification.texi b/docs/info/specification.texi index a466331..e1c9d76 100644 --- a/docs/info/specification.texi +++ b/docs/info/specification.texi @@ -48,8 +48,7 @@ language. (* Statements *) ::= ';' | - ::= | | - ::= + ::= | | ::= '=' | '*=' | '/=' @@ -64,7 +63,8 @@ language. (* Expressions *) ::= - ::= + ::= + ::= ( )* ::= ( '||' )* ::= ( '&&' )* ::= ( '|' )* @@ -82,12 +82,12 @@ language. | '(' ')' ::= - ::= & - | * - | + - | - - | ~ - | ! + ::= '&' + | '*' + | '+' + | '-' + | '~' + | '!' (* Identifiers *) ::= 'u32' diff --git a/src/ast.c b/src/ast.c index 5a36ccb..c64e660 100644 --- a/src/ast.c +++ b/src/ast.c @@ -158,20 +158,6 @@ ast_new_node_ref(arena_t *arena, token_loc_t loc, string_view_t id) return node_ref; } -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; - node_var_assign_stmt->loc = loc; - node_var_assign_stmt->as_var_assign_stmt.ref = ref; - node_var_assign_stmt->as_var_assign_stmt.expr = expr; - - return node_var_assign_stmt; -} - ast_node_t * ast_new_node_return_stmt(arena_t *arena, token_loc_t loc, ast_node_t *expr) { diff --git a/src/ast.h b/src/ast.h index ee94f57..6da11cf 100644 --- a/src/ast.h +++ b/src/ast.h @@ -37,7 +37,6 @@ typedef enum AST_NODE_VAR_DEF, AST_NODE_BINARY_OP, AST_NODE_UNARY_OP, - AST_NODE_VAR_ASSIGN_STMT, AST_NODE_RETURN_STMT, AST_NODE_IF_STMT, AST_NODE_WHILE_STMT, @@ -139,6 +138,7 @@ typedef enum ast_binary_op_kind AST_BINOP_CMP_NEQ, AST_BINOP_LOGICAL_AND, AST_BINOP_LOGICAL_OR, + AST_BINOP_ASSIGN, } ast_binary_op_kind_t; typedef struct ast_binary_op diff --git a/src/checker.c b/src/checker.c index 62d612f..e06cfe9 100644 --- a/src/checker.c +++ b/src/checker.c @@ -184,14 +184,6 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast) return; } - case AST_NODE_VAR_ASSIGN_STMT: { - ast_var_assign_stmt_t var_assign_stmt = ast->as_var_assign_stmt; - - populate_scope(checker, scope, var_assign_stmt.ref); - populate_scope(checker, scope, var_assign_stmt.expr); - return; - } - case AST_NODE_RETURN_STMT: { ast_return_stmt_t return_stmt = ast->as_return_stmt; diff --git a/src/codegen_linux_x86_64.c b/src/codegen_linux_x86_64.c index ae28aa5..8a73263 100644 --- a/src/codegen_linux_x86_64.c +++ b/src/codegen_linux_x86_64.c @@ -524,6 +524,24 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr return 1; } + case AST_BINOP_ASSIGN: { + // FIXME: It may not be a ref + ast_ref_t ref = bin_op.lhs->as_ref; + scope_t *scope = ref.scope; + + symbol_t *symbol = scope_lookup(scope, ref.id); + assert(symbol); + + size_t offset = codegen_linux_x86_64_get_stack_offset(codegen, symbol); + + codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs); + + 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); + + // FIXME: we don't support a = b = c + return 0; + } default: { assert(0 && "unsupported binary operation"); return 0; @@ -599,21 +617,8 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block) break; } - case AST_NODE_VAR_ASSIGN_STMT: { - ast_var_assign_stmt_t var_assign = node->as_var_assign_stmt; - ast_ref_t ref = var_assign.ref->as_ref; - scope_t *scope = ref.scope; - - symbol_t *symbol = scope_lookup(scope, ref.id); - assert(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); - + case AST_NODE_BINARY_OP: { + codegen_linux_x86_64_emit_expression(codegen, node); break; } diff --git a/src/lexer.c b/src/lexer.c index 9e012bd..c4f645c 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -339,6 +339,7 @@ bool token_kind_is_binary_op(token_kind_t kind) { switch (kind) { + case TOKEN_EQ: case TOKEN_PLUS: case TOKEN_DASH: case TOKEN_SLASH: diff --git a/src/parser.c b/src/parser.c index f712bfc..44a4900 100644 --- a/src/parser.c +++ b/src/parser.c @@ -52,9 +52,6 @@ parser_parse_while_stmt(parser_t *parser); static ast_node_t * parser_parse_var_def(parser_t *parser); -static ast_node_t * -parser_parse_var_assign_stmt(parser_t *parser); - static ast_node_t * parser_parse_fn_definition(parser_t *parser); @@ -150,6 +147,8 @@ token_kind_to_binary_op_kind(token_kind_t kind) return AST_BINOP_LOGICAL_AND; case TOKEN_LOGICAL_OR: return AST_BINOP_LOGICAL_OR; + case TOKEN_EQ: + return AST_BINOP_ASSIGN; default: { fprintf(stderr, "error: token kind (%s) not compatible with binary op kind\n", token_kind_to_cstr(kind)); assert(false); @@ -160,6 +159,7 @@ token_kind_to_binary_op_kind(token_kind_t kind) typedef enum { BINOP_MIN_PREC, + BINOP_ASSIGN_PREC, BINOP_LOGICAL_OR_PREC, BINOP_LOGICAL_AND_PREC, BINOP_BITWISE_OR_PREC, @@ -204,6 +204,8 @@ get_binary_op_precedence(token_kind_t kind) return BINOP_LOGICAL_AND_PREC; case TOKEN_LOGICAL_OR: return BINOP_LOGICAL_OR_PREC; + case TOKEN_EQ: + return BINOP_ASSIGN_PREC; default: assert(false); } @@ -293,7 +295,6 @@ parser_parse_factor(parser_t *parser) 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_ref(parser->arena, token_id.loc, token_id.value); } case TOKEN_AND: @@ -536,20 +537,11 @@ StartLoop: node = parser_parse_var_def(parser); break; } - case TOKEN_ID: { - lexer_lookahead(parser->lexer, &next_token, 2); - if (!expected_token(&next_token, TOKEN_EQ)) { - return NULL; - } - node = parser_parse_var_assign_stmt(parser); - break; - } case TOKEN_CCURLY: { goto EndLoop; } default: { - // FIXME: write a better error message - goto EndLoop; + node = parser_parse_expr(parser); } } @@ -711,27 +703,6 @@ parser_parse_var_def(parser_t *parser) return var_node; } -static ast_node_t * -parser_parse_var_assign_stmt(parser_t *parser) -{ - token_t token_id; - - if (!expected_next_token(parser, &token_id, TOKEN_ID)) { - return NULL; - } - - token_t token_eq; - - if (!expected_next_token(parser, &token_eq, TOKEN_EQ)) { - return NULL; - } - - 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); -} - static bool skip_expected_token(parser_t *parser, token_kind_t expected_kind) { diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c index 3a42412..387cde4 100644 --- a/src/pretty_print_ast.c +++ b/src/pretty_print_ast.c @@ -193,20 +193,6 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) } return node; } - case AST_NODE_VAR_ASSIGN_STMT: { - pretty_print_node_t *node = pretty_print_node_new(arena); - ast_var_assign_stmt_t var_assign_stmt = ast->as_var_assign_stmt; - - 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); - - list_append(node->children, ref); - list_append(node->children, expr); - - return node; - } case AST_NODE_RETURN_STMT: { pretty_print_node_t *node = pretty_print_node_new(arena); ast_return_stmt_t return_stmt = ast->as_return_stmt; @@ -371,6 +357,10 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) node->name = "Binary_Operation (|)"; break; } + case AST_BINOP_ASSIGN: { + node->name = "Binary_Operation (=)"; + break; + } default: assert(false && "binop not implemented"); } @@ -393,8 +383,26 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) node->name = "Unary_Operation (~)"; break; } - default: - assert(false && "unary operation kind not implemented"); + case AST_UNARY_DEREFERENCE: { + node->name = "Unary_Operation (*)"; + break; + } + case AST_UNARY_NEGATIVE: { + node->name = "Unary_Operation (-)"; + break; + } + case AST_UNARY_LOGICAL_NOT: { + node->name = "Unary_Operation (!)"; + break; + } + case AST_UNARY_POSITIVE: { + node->name = "Unary_Operation (+)"; + break; + } + case AST_UNARY_ADDRESSOF: { + node->name = "Unary_Operation (&)"; + break; + } } pretty_print_node_t *expr = ast_node_to_pretty_print_node(unary_op.expr, arena); diff --git a/tests/olc/0029_var_assigment.ol b/tests/olc/0029_var_assigment.ol index 0e04fcc..402d73a 100644 --- a/tests/olc/0029_var_assigment.ol +++ b/tests/olc/0029_var_assigment.ol @@ -29,7 +29,7 @@ fn main(): u32 { # `-Block # |-Var_Definition # | `-Literal -# |-Var_Assigment +# |-Binary_Operation (=) # | |-Reference # | `-Literal # `-Return_Statement diff --git a/tests/olc/0030_while_statement.ol b/tests/olc/0030_while_statement.ol index 0eca528..0ce0185 100644 --- a/tests/olc/0030_while_statement.ol +++ b/tests/olc/0030_while_statement.ol @@ -38,7 +38,7 @@ fn main(): u32 { # | | |-Reference # | | `-Literal # | `-Block -# | `-Var_Assigment +# | `-Binary_Operation (=) # | |-Reference # | `-Binary_Operation (+) # | |-Reference -- 2.46.1