Skip to content

Commit

Permalink
fix: actual formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
skifli authored Jan 2, 2025
1 parent b57fbba commit de2eac7
Show file tree
Hide file tree
Showing 16 changed files with 2,715 additions and 2,720 deletions.
5 changes: 3 additions & 2 deletions src/.clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
BasedOnStyle: LLVM
IndentWidth: 4
UseTab: Never
UseTab: Always
IndentWidth: 3
TabWidth: 3
ColumnLimit: 125
ReflowComments: true
BreakBeforeBraces: Attach
Expand Down
845 changes: 421 additions & 424 deletions src/args/args.c

Large diffs are not rendered by default.

134 changes: 67 additions & 67 deletions src/compiler/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "./tokens.c"

struct Compiler {
struct Parser *parser;
struct Parser *parser;
};

#define COMPILER_STRUCT_SIZE sizeof(struct Compiler)
Expand All @@ -24,11 +24,11 @@ struct Compiler {
* @return The created Compiler struct.
*/
struct Compiler *compiler_new(const char *FILE_PATH) {
struct Compiler *compiler = malloc(COMPILER_STRUCT_SIZE);
struct Compiler *compiler = malloc(COMPILER_STRUCT_SIZE);

compiler->parser = parser_new(FILE_PATH);
compiler->parser = parser_new(FILE_PATH);

return compiler;
return compiler;
}

/**
Expand All @@ -37,14 +37,14 @@ struct Compiler *compiler_new(const char *FILE_PATH) {
* @param self The current Compiler struct.
*/
void compiler_free(struct Compiler **self) {
if (self && *self) {
parser_free(&(*self)->parser);

free(*self);
*self = NULL;
} else {
panic("Compiler struct has already been freed");
}
if (self && *self) {
parser_free(&(*self)->parser);

free(*self);
*self = NULL;
} else {
panic("Compiler struct has already been freed");
}
}

/**
Expand Down Expand Up @@ -137,7 +137,7 @@ void compiler_compileBitwiseNotAssignment(struct Compiler *self) { printf("compi
* @param self The current Compiler struct.
*/
void compiler_compileBitwiseLeftShiftAssignment(struct Compiler *self) {
printf("compiling bitwise left shift assignment\n");
printf("compiling bitwise left shift assignment\n");
}

/**
Expand All @@ -146,7 +146,7 @@ void compiler_compileBitwiseLeftShiftAssignment(struct Compiler *self) {
* @param self The current Compiler struct.
*/
void compiler_compileBitwiseRightShiftAssignment(struct Compiler *self) {
printf("compiling bitwise right shift assignment\n");
printf("compiling bitwise right shift assignment\n");
}

/**
Expand All @@ -155,54 +155,54 @@ void compiler_compileBitwiseRightShiftAssignment(struct Compiler *self) {
* @param self The current Compiler struct.
*/
void compiler_compileNext(struct Compiler *self) {
switch (self->parser->AST->IDENTIFIER) {
case ASTTOKENS_ASSIGNMENT:
compiler_compileAssignment(self);
break;
case ASTTOKENS_MODULO_ASSIGNMENT:
compiler_compileModuloAssignment(self);
break;
case ASTTOKENS_MULTIPLICATION_ASSIGNMENT:
compiler_compileMultiplicationAssignment(self);
break;
case ASTTOKENS_EXPONENT_ASSIGNMENT:
compiler_compileExponentAssignment(self);
break;
case ASTTOKENS_DIVISION_ASSIGNMENT:
compiler_compileDivisionAssignment(self);
break;
case ASTTOKENS_FLOOR_DIVISION_ASSIGNMENT:
compiler_compileFloorDivisionAssignment(self);
break;
case ASTTOKENS_ADDITION_ASSIGNMENT:
compiler_compileAdditionAssignment(self);
break;
case ASTTOKENS_SUBTRACTION_ASSIGNMENT:
compiler_compileSubtractionAssignment(self);
break;
case ASTTOKENS_BITWISE_AND_ASSIGNMENT:
compiler_compileBitwiseAndAssignment(self);
break;
case ASTTOKENS_BITWISE_OR_ASSIGNMENT:
compiler_compileBitwiseOrAssignment(self);
break;
case ASTTOKENS_BITWISE_XOR_ASSIGNMENT:
compiler_compileBitwiseXorAssignment(self);
break;
case ASTTOKENS_BITWISE_NOT_ASSIGNMENT:
compiler_compileBitwiseNotAssignment(self);
break;
case ASTTOKENS_BITWISE_LEFT_SHIFT_ASSIGNMENT:
compiler_compileBitwiseLeftShiftAssignment(self);
break;
case ASTTOKENS_BITWISE_RIGHT_SHIFT_ASSIGNMENT:
compiler_compileBitwiseRightShiftAssignment(self);
break;
default:
printf("unsupported parser token for compiler: %s\n",
astTokens_getName(self->parser->AST->IDENTIFIER)); // TODO: fix
break;
}
switch (self->parser->AST->IDENTIFIER) {
case ASTTOKENS_ASSIGNMENT:
compiler_compileAssignment(self);
break;
case ASTTOKENS_MODULO_ASSIGNMENT:
compiler_compileModuloAssignment(self);
break;
case ASTTOKENS_MULTIPLICATION_ASSIGNMENT:
compiler_compileMultiplicationAssignment(self);
break;
case ASTTOKENS_EXPONENT_ASSIGNMENT:
compiler_compileExponentAssignment(self);
break;
case ASTTOKENS_DIVISION_ASSIGNMENT:
compiler_compileDivisionAssignment(self);
break;
case ASTTOKENS_FLOOR_DIVISION_ASSIGNMENT:
compiler_compileFloorDivisionAssignment(self);
break;
case ASTTOKENS_ADDITION_ASSIGNMENT:
compiler_compileAdditionAssignment(self);
break;
case ASTTOKENS_SUBTRACTION_ASSIGNMENT:
compiler_compileSubtractionAssignment(self);
break;
case ASTTOKENS_BITWISE_AND_ASSIGNMENT:
compiler_compileBitwiseAndAssignment(self);
break;
case ASTTOKENS_BITWISE_OR_ASSIGNMENT:
compiler_compileBitwiseOrAssignment(self);
break;
case ASTTOKENS_BITWISE_XOR_ASSIGNMENT:
compiler_compileBitwiseXorAssignment(self);
break;
case ASTTOKENS_BITWISE_NOT_ASSIGNMENT:
compiler_compileBitwiseNotAssignment(self);
break;
case ASTTOKENS_BITWISE_LEFT_SHIFT_ASSIGNMENT:
compiler_compileBitwiseLeftShiftAssignment(self);
break;
case ASTTOKENS_BITWISE_RIGHT_SHIFT_ASSIGNMENT:
compiler_compileBitwiseRightShiftAssignment(self);
break;
default:
printf("unsupported parser token for compiler: %s\n",
astTokens_getName(self->parser->AST->IDENTIFIER)); // TODO: fix
break;
}
}

/**
Expand All @@ -213,11 +213,11 @@ void compiler_compileNext(struct Compiler *self) {
* @return Whether compiling succeeded.
*/
bool compiler_compile(struct Compiler *self) {
if (!parser_parse(self->parser, true, true)) {
return false;
}
if (!parser_parse(self->parser, true, true)) {
return false;
}

compiler_compileNext(self);
compiler_compileNext(self);

return true;
return true;
}
48 changes: 24 additions & 24 deletions src/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@
* Used to identify errors.
*/
enum ErrorIdentifiers {
// Argument parser
A0001,
A0002,
A0003,
A0004,

// Lexer
L0001,
L0002,
L0003,
L0004,
L0005,
L0006,
L0007,

// Parser
P0001,
P0002,
P0003,
// Argument parser
A0001,
A0002,
A0003,
A0004,

// Lexer
L0001,
L0002,
L0003,
L0004,
L0005,
L0006,
L0007,

// Parser
P0001,
P0002,
P0003,
};

/**
* Contains the names of each of the error identifiers.
*/
const struct Array ERRORIDENTIFIER_NAMES = array_new_stack("A0001", "A0002", "A0003", "A0004", "L0001", "L0002", "L0003",
"L0004", "L0005", "L0006", "L0007", "P0001", "P0002", "P0003");
"L0004", "L0005", "L0006", "L0007", "P0001", "P0002", "P0003");

/**
* Gets the name of an error.
Expand All @@ -49,9 +49,9 @@ const struct Array ERRORIDENTIFIER_NAMES = array_new_stack("A0001", "A0002", "A0
* @return The name of the error.
*/
const char *error_get(const enum ErrorIdentifiers IDENTIFIER) {
if ((size_t)IDENTIFIER + 1 > ERRORIDENTIFIER_NAMES.length) {
panic("ErrorIdentifiers get index out of bounds");
}
if ((size_t)IDENTIFIER + 1 > ERRORIDENTIFIER_NAMES.length) {
panic("ErrorIdentifiers get index out of bounds");
}

return ERRORIDENTIFIER_NAMES._values[IDENTIFIER];
return ERRORIDENTIFIER_NAMES._values[IDENTIFIER];
}
18 changes: 9 additions & 9 deletions src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ const size_t negativeULL = (size_t)-1;
* Used to identify variable types.
*/
enum VariableType {
VARIABLE_TYPE_NONE,
VARIABLE_TYPE_STRING,
VARIABLE_TYPE_INT,
VARIABLE_TYPE_FLOAT,
VARIABLE_TYPE_BOOL,
VARIABLE_TYPE_NONE,
VARIABLE_TYPE_STRING,
VARIABLE_TYPE_INT,
VARIABLE_TYPE_FLOAT,
VARIABLE_TYPE_BOOL,
};

/**
Expand All @@ -38,9 +38,9 @@ const struct Array VARIABLETYPE_NAMES = array_new_stack("none", "string", "int",
* @return The name of the variable type.
*/
const char *variableType_get(const enum VariableType TYPE) {
if ((size_t)TYPE + 1 > VARIABLETYPE_NAMES.length) {
panic("VariableType get index out of bounds");
}
if ((size_t)TYPE + 1 > VARIABLETYPE_NAMES.length) {
panic("VariableType get index out of bounds");
}

return VARIABLETYPE_NAMES._values[TYPE];
return VARIABLETYPE_NAMES._values[TYPE];
}
2 changes: 1 addition & 1 deletion src/includes.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#pragma once

#define _CRT_SECURE_NO_WARNINGS // What is deprecated on Windows isn't always on
// other OSes.
// other OSes.

#include <ctype.h>
#include <locale.h>
Expand Down
Loading

0 comments on commit de2eac7

Please sign in to comment.