From 7064561b24ba42a2bc963fd5d70e3be5029c5886 Mon Sep 17 00:00:00 2001 From: Igor Parfenov Date: Sat, 4 Jan 2025 18:57:08 +0300 Subject: [PATCH] Fix naming --- 1 | 9 ++++ compiler/include/ast.h | 4 +- compiler/include/token.h | 4 +- compiler/src/compile.c | 30 ++++++------ compiler/src/lexer.c | 8 ++-- compiler/src/syntax.c | 100 +++++++++++++++++++-------------------- 6 files changed, 82 insertions(+), 73 deletions(-) create mode 100644 1 diff --git a/1 b/1 new file mode 100644 index 0000000..a60a26d --- /dev/null +++ b/1 @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Year Full name + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/compiler/include/ast.h b/compiler/include/ast.h index 19d7f19..fe5c252 100644 --- a/compiler/include/ast.h +++ b/compiler/include/ast.h @@ -41,8 +41,8 @@ enum NodeType { NodeBitwiseOr, NodeBitwiseXor, NodeBitwiseNot, - NodeBitwiseLeft, - NodeBitwiseRight, + NodeBitwiseShiftLeft, + NodeBitwiseShiftRight, NodeAddition, NodeSubtraction, NodeMultiplication, diff --git a/compiler/include/token.h b/compiler/include/token.h index 93abc68..4508296 100644 --- a/compiler/include/token.h +++ b/compiler/include/token.h @@ -40,8 +40,8 @@ enum TokenType { TokenPipe, TokenCaret, TokenTilde, - TokenBitwiseLeft, - TokenBitwiseRight, + TokenBitwiseShiftLeft, + TokenBitwiseShiftRight, TokenDereference, TokenGetField, TokenSharp, diff --git a/compiler/src/compile.c b/compiler/src/compile.c index 1f80072..9344290 100644 --- a/compiler/src/compile.c +++ b/compiler/src/compile.c @@ -1083,7 +1083,7 @@ struct TypeNode *compile_bitwise_not(struct Node *node, struct BinaryOperator *t return _type; } -struct TypeNode *compile_bitwise_left(struct Node *node, struct BinaryOperator *this, struct CPContext *context) { +struct TypeNode *compile_bitwise_shift_left(struct Node *node, struct BinaryOperator *this, struct CPContext *context) { struct TypeNode *_type = compile_arithmetic(node, this, context); _fputs(context->fd_text, "mov rax, [rsp - 8]\n"); _fputs(context->fd_text, "mov rcx, [rsp - 16]\n"); @@ -1092,7 +1092,7 @@ struct TypeNode *compile_bitwise_left(struct Node *node, struct BinaryOperator * return _type; } -struct TypeNode *compile_bitwise_right(struct Node *node, struct BinaryOperator *this, struct CPContext *context) { +struct TypeNode *compile_bitwise_shift_right(struct Node *node, struct BinaryOperator *this, struct CPContext *context) { struct TypeNode *_type = compile_arithmetic(node, this, context); _fputs(context->fd_text, "mov rax, [rsp - 8]\n"); _fputs(context->fd_text, "mov rcx, [rsp - 16]\n"); @@ -1358,40 +1358,40 @@ struct TypeNode *compile_node(struct Node *node, struct CPContext *context) { } else if (node->node_type == NodeAnd) { - _fputs(context->fd_text, "addition\n"); + _fputs(context->fd_text, "and\n"); return compile_and(node, (struct BinaryOperator*)node->node_ptr, context); } else if (node->node_type == NodeOr) { - _fputs(context->fd_text, "addition\n"); + _fputs(context->fd_text, "or\n"); return compile_or(node, (struct BinaryOperator*)node->node_ptr, context); } else if (node->node_type == NodeNot) { - _fputs(context->fd_text, "addition\n"); + _fputs(context->fd_text, "not\n"); return compile_not(node, (struct BinaryOperator*)node->node_ptr, context); } else if (node->node_type == NodeBitwiseAnd) { - _fputs(context->fd_text, "addition\n"); + _fputs(context->fd_text, "bitwise and\n"); return compile_bitwise_and(node, (struct BinaryOperator*)node->node_ptr, context); } else if (node->node_type == NodeBitwiseOr) { - _fputs(context->fd_text, "addition\n"); + _fputs(context->fd_text, "bitwise or\n"); return compile_bitwise_or(node, (struct BinaryOperator*)node->node_ptr, context); } else if (node->node_type == NodeBitwiseXor) { - _fputs(context->fd_text, "addition\n"); + _fputs(context->fd_text, "bitwise xor\n"); return compile_bitwise_xor(node, (struct BinaryOperator*)node->node_ptr, context); } else if (node->node_type == NodeBitwiseNot) { - _fputs(context->fd_text, "addition\n"); + _fputs(context->fd_text, "bitwise not\n"); return compile_bitwise_not(node, (struct BinaryOperator*)node->node_ptr, context); } - else if (node->node_type == NodeBitwiseLeft) { - _fputs(context->fd_text, "addition\n"); - return compile_bitwise_left(node, (struct BinaryOperator*)node->node_ptr, context); + else if (node->node_type == NodeBitwiseShiftLeft) { + _fputs(context->fd_text, "bitwise shift left\n"); + return compile_bitwise_shift_left(node, (struct BinaryOperator*)node->node_ptr, context); } - else if (node->node_type == NodeBitwiseRight) { - _fputs(context->fd_text, "addition\n"); - return compile_bitwise_right(node, (struct BinaryOperator*)node->node_ptr, context); + else if (node->node_type == NodeBitwiseShiftRight) { + _fputs(context->fd_text, "bitwise shift right\n"); + return compile_bitwise_shift_right(node, (struct BinaryOperator*)node->node_ptr, context); } else if (node->node_type == NodeAddition) { _fputs(context->fd_text, "addition\n"); diff --git a/compiler/src/lexer.c b/compiler/src/lexer.c index d1053d4..eae04b2 100644 --- a/compiler/src/lexer.c +++ b/compiler/src/lexer.c @@ -174,8 +174,8 @@ struct TokenStream *lexer_process(const char *str, const char *filename) { else if (append_token(str, N, &i, "|", TokenPipe, true, line, &position, filename, token_stream)) {} else if (append_token(str, N, &i, "^", TokenCaret, true, line, &position, filename, token_stream)) {} else if (append_token(str, N, &i, "~", TokenTilde, true, line, &position, filename, token_stream)) {} - else if (append_token(str, N, &i, "<<", TokenBitwiseLeft, true, line, &position, filename, token_stream)) {} - else if (append_token(str, N, &i, ">>", TokenBitwiseRight, true, line, &position, filename, token_stream)) {} + else if (append_token(str, N, &i, "<<", TokenBitwiseShiftLeft, true, line, &position, filename, token_stream)) {} + else if (append_token(str, N, &i, ">>", TokenBitwiseShiftRight, true, line, &position, filename, token_stream)) {} else if (append_token(str, N, &i, "$", TokenDereference, true, line, &position, filename, token_stream)) {} else if (append_token(str, N, &i, "->", TokenGetField, true, line, &position, filename, token_stream)) {} else if (append_token(str, N, &i, "#", TokenSharp, true, line, &position, filename, token_stream)) {} @@ -398,8 +398,8 @@ const char *TokenColor(enum TokenType type, Color_Black, // TokenPipe, Color_Black, // TokenCaret, Color_Black, // TokenTilde, - Color_Black, // TokenBitwiseLeft, - Color_Black, // TokenBitwiseRight, + Color_Black, // TokenBitwiseShiftLeft, + Color_Black, // TokenBitwiseShiftRight, Color_Black, // TokenDereference, Color_Black, // TokenGetField, Color_Black, // TokenSharp, diff --git a/compiler/src/syntax.c b/compiler/src/syntax.c index 40b5ce2..23def52 100644 --- a/compiler/src/syntax.c +++ b/compiler/src/syntax.c @@ -168,55 +168,55 @@ struct TypeNode *syntax_process_type(struct TokenStream *ts, struct Settings *st bool next_is_operation(struct TokenStream *ts) { return ( - tokenstream_get(ts).type == TokenAnd || - tokenstream_get(ts).type == TokenOr || - tokenstream_get(ts).type == TokenNot || - tokenstream_get(ts).type == TokenAmpersand || - tokenstream_get(ts).type == TokenPipe || - tokenstream_get(ts).type == TokenCaret || - tokenstream_get(ts).type == TokenTilde || - tokenstream_get(ts).type == TokenBitwiseLeft || - tokenstream_get(ts).type == TokenBitwiseRight || - tokenstream_get(ts).type == TokenPlus || - tokenstream_get(ts).type == TokenMinus || - tokenstream_get(ts).type == TokenMult || - tokenstream_get(ts).type == TokenDiv || - tokenstream_get(ts).type == TokenMod || - tokenstream_get(ts).type == TokenLess || - tokenstream_get(ts).type == TokenGreater || - tokenstream_get(ts).type == TokenEqual || - tokenstream_get(ts).type == TokenLessEqual || - tokenstream_get(ts).type == TokenGreaterEqual || + tokenstream_get(ts).type == TokenAnd || + tokenstream_get(ts).type == TokenOr || + tokenstream_get(ts).type == TokenNot || + tokenstream_get(ts).type == TokenAmpersand || + tokenstream_get(ts).type == TokenPipe || + tokenstream_get(ts).type == TokenCaret || + tokenstream_get(ts).type == TokenTilde || + tokenstream_get(ts).type == TokenBitwiseShiftLeft || + tokenstream_get(ts).type == TokenBitwiseShiftRight || + tokenstream_get(ts).type == TokenPlus || + tokenstream_get(ts).type == TokenMinus || + tokenstream_get(ts).type == TokenMult || + tokenstream_get(ts).type == TokenDiv || + tokenstream_get(ts).type == TokenMod || + tokenstream_get(ts).type == TokenLess || + tokenstream_get(ts).type == TokenGreater || + tokenstream_get(ts).type == TokenEqual || + tokenstream_get(ts).type == TokenLessEqual || + tokenstream_get(ts).type == TokenGreaterEqual || tokenstream_get(ts).type == TokenNotEqual); } int operation_priority(struct Token *token) { - if (token->type == -TokenMinus || - token->type == -TokenTilde || + if (token->type == -TokenMinus || + token->type == -TokenTilde || token->type == -TokenNot ) { return 2; } - if (token->type == TokenMult || - token->type == TokenDiv || + if (token->type == TokenMult || + token->type == TokenDiv || token->type == TokenMod ) { return 3; } - if (token->type == TokenPlus || + if (token->type == TokenPlus || token->type == TokenMinus ) { return 4; } - if (token->type == TokenBitwiseLeft || - token->type == TokenBitwiseRight ) { + if (token->type == TokenBitwiseShiftLeft || + token->type == TokenBitwiseShiftRight ) { return 5; } - if (token->type == TokenLess || - token->type == TokenGreater || - token->type == TokenLessEqual || + if (token->type == TokenLess || + token->type == TokenGreater || + token->type == TokenLessEqual || token->type == TokenGreaterEqual ) { return 6; } if ( - token->type == TokenEqual || + token->type == TokenEqual || token->type == TokenNotEqual ) { return 7; } @@ -285,26 +285,26 @@ struct Node *process_operation(struct Vector *primaries, struct Vector *operatio vpop(primaries); } - if (token->type == TokenAnd) root->node_type = NodeAnd; - if (token->type == TokenOr) root->node_type = NodeOr; - if (token->type == TokenNot) root->node_type = NodeNot; - if (token->type == TokenAmpersand) root->node_type = NodeBitwiseAnd; - if (token->type == TokenPipe) root->node_type = NodeBitwiseOr; - if (token->type == TokenCaret) root->node_type = NodeBitwiseXor; - if (token->type == TokenTilde) root->node_type = NodeBitwiseNot; - if (token->type == TokenBitwiseLeft) root->node_type = NodeBitwiseLeft; - if (token->type == TokenBitwiseRight) root->node_type = NodeBitwiseRight; - if (token->type == TokenPlus) root->node_type = NodeAddition; - if (token->type == TokenMinus) root->node_type = NodeSubtraction; - if (token->type == TokenMult) root->node_type = NodeMultiplication; - if (token->type == TokenDiv) root->node_type = NodeDivision; - if (token->type == TokenMod) root->node_type = NodeModulo; - if (token->type == TokenLess) root->node_type = NodeLess; - if (token->type == TokenGreater) root->node_type = NodeGreater; - if (token->type == TokenEqual) root->node_type = NodeEqual; - if (token->type == TokenLessEqual) root->node_type = NodeLessEqual; - if (token->type == TokenGreaterEqual) root->node_type = NodeGreaterEqual; - if (token->type == TokenNotEqual) root->node_type = NodeNotEqual; + if (token->type == TokenAnd) root->node_type = NodeAnd; + if (token->type == TokenOr) root->node_type = NodeOr; + if (token->type == TokenNot) root->node_type = NodeNot; + if (token->type == TokenAmpersand) root->node_type = NodeBitwiseAnd; + if (token->type == TokenPipe) root->node_type = NodeBitwiseOr; + if (token->type == TokenCaret) root->node_type = NodeBitwiseXor; + if (token->type == TokenTilde) root->node_type = NodeBitwiseNot; + if (token->type == TokenBitwiseShiftLeft) root->node_type = NodeBitwiseShiftLeft; + if (token->type == TokenBitwiseShiftRight) root->node_type = NodeBitwiseShiftRight; + if (token->type == TokenPlus) root->node_type = NodeAddition; + if (token->type == TokenMinus) root->node_type = NodeSubtraction; + if (token->type == TokenMult) root->node_type = NodeMultiplication; + if (token->type == TokenDiv) root->node_type = NodeDivision; + if (token->type == TokenMod) root->node_type = NodeModulo; + if (token->type == TokenLess) root->node_type = NodeLess; + if (token->type == TokenGreater) root->node_type = NodeGreater; + if (token->type == TokenEqual) root->node_type = NodeEqual; + if (token->type == TokenLessEqual) root->node_type = NodeLessEqual; + if (token->type == TokenGreaterEqual) root->node_type = NodeGreaterEqual; + if (token->type == TokenNotEqual) root->node_type = NodeNotEqual; if (root->node_ptr == NULL) { error_syntax("Fatal Error", tokenstream_get(ts));