Skip to content

Commit

Permalink
Fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ParfenovIgor committed Jan 4, 2025
1 parent 4cafe86 commit 7064561
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 73 deletions.
9 changes: 9 additions & 0 deletions 1
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions compiler/include/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ enum NodeType {
NodeBitwiseOr,
NodeBitwiseXor,
NodeBitwiseNot,
NodeBitwiseLeft,
NodeBitwiseRight,
NodeBitwiseShiftLeft,
NodeBitwiseShiftRight,
NodeAddition,
NodeSubtraction,
NodeMultiplication,
Expand Down
4 changes: 2 additions & 2 deletions compiler/include/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ enum TokenType {
TokenPipe,
TokenCaret,
TokenTilde,
TokenBitwiseLeft,
TokenBitwiseRight,
TokenBitwiseShiftLeft,
TokenBitwiseShiftRight,
TokenDereference,
TokenGetField,
TokenSharp,
Expand Down
30 changes: 15 additions & 15 deletions compiler/src/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {}
Expand Down Expand Up @@ -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,
Expand Down
100 changes: 50 additions & 50 deletions compiler/src/syntax.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 7064561

Please sign in to comment.