Skip to content

Commit da6186f

Browse files
Fix/build issue fix (#2)
* accidentally left out a function in the wrong utils * Added missing dependency of `data_structures` to main target * CMake: added source file to main target that was missed * Updated platform.c, added missing macro definitions in utils.h * Added missing includes * Fixed comments for `https://` got affected accidentally by formatting change * Removed test code from main * formatting, removed college-related information * Added needed stdio.h include * Updated "server" target
1 parent c06fd2d commit da6186f

26 files changed

Lines changed: 3257 additions & 2731 deletions

File tree

CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,33 @@ add_subdirectory("lib/basic_system_interface/")
1313
add_subdirectory("lib/data_structures/")
1414

1515
# Build the main project executable
16-
add_executable(${CMAKE_PROJECT_NAME}
17-
"src/main.c"
16+
add_executable(server
17+
"src/http_server_main.c"
1818

1919
"src/http.c"
2020
"src/http.h"
2121
"src/tcpserver.c"
2222
"src/tcpserver.h"
2323
"src/utils.c"
2424
"src/utils.h"
25+
"src/platform/platform.c"
26+
"src/platform/platform.h"
2527
)
2628

2729
# Add some preprocessor defines
28-
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC "$<$<CONFIG:DEBUG>:DEBUG>")
30+
target_compile_definitions(server
31+
PUBLIC "$<$<CONFIG:DEBUG>:DEBUG>"
32+
)
2933

30-
add_dependencies(${CMAKE_PROJECT_NAME} basic)
34+
add_dependencies(server
35+
basic
36+
data_structures
37+
)
3138

32-
target_link_libraries(${CMAKE_PROJECT_NAME}
39+
target_link_libraries(server
3340
PRIVATE
3441
basic::basic
42+
data_structures::data_structures
3543
)
3644

3745
# Build the main project executable

lib/basic/include/basic/ast.h

Lines changed: 76 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,95 +4,103 @@ typedef char StringLiteral[101];
44

55
/* Abstract Syntax Tree */
66

7-
typedef union {
8-
float flt;
9-
int num;
10-
StringLiteral str;
7+
typedef union
8+
{
9+
float flt;
10+
int num;
11+
StringLiteral str;
1112
} Literal;
1213

13-
typedef enum {
14-
OP_NONE,
15-
16-
// Unary
17-
OP_NOT,
18-
OP_NEGATE,
19-
20-
// Binary
21-
OP_ADD,
22-
OP_SUB,
23-
OP_MUL,
24-
OP_DIV,
25-
OP_MOD,
26-
OP_EQ,
27-
OP_LT,
28-
OP_GT,
29-
OP_ASSIGN,
30-
31-
// Separator, only used during parsing
32-
OP_OPEN_PAREN,
33-
OP_CLOSE_PAREN
14+
typedef enum
15+
{
16+
OP_NONE,
17+
18+
// Unary
19+
OP_NOT,
20+
OP_NEGATE,
21+
22+
// Binary
23+
OP_ADD,
24+
OP_SUB,
25+
OP_MUL,
26+
OP_DIV,
27+
OP_MOD,
28+
OP_EQ,
29+
OP_LT,
30+
OP_GT,
31+
OP_ASSIGN,
32+
33+
// Separator, only used during parsing
34+
OP_OPEN_PAREN,
35+
OP_CLOSE_PAREN
3436
} ASTOperator;
3537

36-
typedef enum {
37-
OPTYPE_NONE,
38-
OPTYPE_UNARY,
39-
OPTYPE_BINARY,
40-
OPTYPE_TERNARY
38+
typedef enum
39+
{
40+
OPTYPE_NONE,
41+
OPTYPE_UNARY,
42+
OPTYPE_BINARY,
43+
OPTYPE_TERNARY
4144
} ASTOperatorType;
4245

43-
typedef union {
44-
int generic;
45-
// For keyword / operation / function call
46-
StringLiteral kw;
46+
typedef union
47+
{
48+
int generic;
49+
// For keyword / operation / function call
50+
StringLiteral kw;
4751

48-
// For a variable name
49-
StringLiteral variable_name;
52+
// For a variable name
53+
StringLiteral variable_name;
5054

51-
// token_type is used for following
55+
// token_type is used for following
5256

53-
// For a literal number/string
54-
Literal literal;
55-
// For ALU operation
56-
ASTOperator op;
57+
// For a literal number/string
58+
Literal literal;
59+
// For ALU operation
60+
ASTOperator op;
5761
} ASTData;
5862

59-
typedef enum {
60-
DTYPE_NONE,
61-
DTYPE_STR,
62-
DTYPE_NUM,
63-
DTYPE_FLT,
64-
DTYPE_SYMB
63+
typedef enum
64+
{
65+
DTYPE_NONE,
66+
DTYPE_STR,
67+
DTYPE_NUM,
68+
DTYPE_FLT,
69+
DTYPE_SYMB
6570
} ASTDType;
6671

67-
typedef struct {
68-
ASTData token;
69-
ASTDType token_type;
72+
typedef struct
73+
{
74+
ASTData token;
75+
ASTDType token_type;
7076
} ASTNodeData;
7177

72-
typedef enum {
73-
AST_NONE,
74-
AST_PROGRAM_SEQUENCE,
78+
typedef enum
79+
{
80+
AST_NONE,
81+
AST_PROGRAM_SEQUENCE,
7582

76-
// Operation
77-
AST_KEYWORD,
78-
AST_EXPRESSION,
79-
AST_OPERATION,
80-
AST_CONDITION,
83+
// Operation
84+
AST_KEYWORD,
85+
AST_EXPRESSION,
86+
AST_OPERATION,
87+
AST_CONDITION,
8188

82-
// Data
83-
AST_IMMEDIATE,
84-
AST_VARIABLE,
89+
// Data
90+
AST_IMMEDIATE,
91+
AST_VARIABLE,
8592

86-
// Call to function
87-
AST_FUNC_CALL,
93+
// Call to function
94+
AST_FUNC_CALL,
8895
} ASTNodeType;
8996

90-
typedef struct _ast_node {
91-
ASTNodeType type;
92-
ASTNodeData data;
97+
typedef struct _ast_node
98+
{
99+
ASTNodeType type;
100+
ASTNodeData data;
93101

94-
struct _ast_node *next;
95-
struct _ast_node *child;
102+
struct _ast_node *next;
103+
struct _ast_node *child;
96104
} ASTNode;
97105

98106
// Void data

lib/basic/include/basic/basic.h

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
/**
66
* BASIC interpreter steps:
7-
*
7+
*
88
* 0. BASIC program source code input
99
* 1. BASIC Lexer (Program source to tokens)
1010
* 2. BASIC Parser (Tokens to AST)
1111
* 3. Execute AST sequentially (Program run)
12-
*
12+
*
1313
* */
1414

1515
#include "ast.h"
@@ -19,49 +19,53 @@
1919
extern unsigned int log_print_mask;
2020

2121
// Log level mask
22-
#define LOGTYPE_DEBUG (1 << 0)
23-
#define LOGTYPE_INFO (1 << 1)
22+
#define LOGTYPE_DEBUG (1 << 0)
23+
#define LOGTYPE_INFO (1 << 1)
2424
#define LOGTYPE_MESSAGE (1 << 2)
25-
#define LOGTYPE_ERROR (1 << 3)
26-
#define LOGMASK_ALL 0xffff
25+
#define LOGTYPE_ERROR (1 << 3)
26+
#define LOGMASK_ALL 0xffff
2727

2828
// Printf modified to allow only selected messages
2929
void lprintf(const char *tag, unsigned int level_mask, const char *format, ...);
3030

3131
/* AST parser (tokenizer) */
3232

33-
typedef enum {
34-
TOKEN_IDENTIFIER,
35-
TOKEN_KEYWORD,
36-
TOKEN_WHITESPACE,
37-
TOKEN_OPERATOR,
38-
TOKEN_SEPARATOR,
39-
TOKEN_NUM,
40-
TOKEN_BOOL,
41-
TOKEN_STRING,
42-
TOKEN_END
33+
typedef enum
34+
{
35+
TOKEN_IDENTIFIER,
36+
TOKEN_KEYWORD,
37+
TOKEN_WHITESPACE,
38+
TOKEN_OPERATOR,
39+
TOKEN_SEPARATOR,
40+
TOKEN_NUM,
41+
TOKEN_BOOL,
42+
TOKEN_STRING,
43+
TOKEN_END
4344
} BASICTokenType;
4445

45-
typedef struct {
46-
StringLiteral token;
47-
BASICTokenType token_type;
48-
char *token_at;
46+
typedef struct
47+
{
48+
StringLiteral token;
49+
BASICTokenType token_type;
50+
char *token_at;
4951
} BASICToken;
5052

5153
// Structure with all the stuff needed to convert a BASIC program to an AST
52-
typedef struct {
53-
// List of tokens
54-
BASICToken *tokens;
55-
int tokens_length;
56-
// Stack for knowning current scope
54+
typedef struct
55+
{
56+
// List of tokens
57+
BASICToken *tokens;
58+
int tokens_length;
59+
// Stack for knowning current scope
5760
} BASICParseTree;
5861

59-
typedef struct {
60-
char *program_source;
61-
BASICParseTree program_tokens;
62-
ASTNode *program_sequence;
63-
// Map between line number and which instruction to execute on that line. For non-linear control flow
64-
// BASICLineNode program_line_instruction;
62+
typedef struct
63+
{
64+
char *program_source;
65+
BASICParseTree program_tokens;
66+
ASTNode *program_sequence;
67+
// Map between line number and which instruction to execute on that line. For non-linear control flow
68+
// BASICLineNode program_line_instruction;
6569
} BASICProgram;
6670

6771
BASICProgram *basic_create_program();
@@ -77,12 +81,12 @@ extern char PARSE_SEPARATOR[];
7781
extern char PARSE_WS_CHAR[];
7882

7983
// Index of the keyword in the above PARSE_KEYWORDS array
80-
#define KEYWORD_IDX_WHILE 0
81-
#define KEYWORD_IDX_IF 1
82-
#define KEYWORD_IDX_THEN 2
83-
#define KEYWORD_IDX_ELSE 3
84-
#define KEYWORD_IDX_END 4
85-
#define KEYWORD_IDX_GOTO 5
84+
#define KEYWORD_IDX_WHILE 0
85+
#define KEYWORD_IDX_IF 1
86+
#define KEYWORD_IDX_THEN 2
87+
#define KEYWORD_IDX_ELSE 3
88+
#define KEYWORD_IDX_END 4
89+
#define KEYWORD_IDX_GOTO 5
8690

8791
// Lexer
8892
int basic_tokenize(BASICProgram *program);
@@ -96,30 +100,32 @@ int basic_parse_to_ast_between_onlyexpr(BASICParseTree *ptree, ASTNode *root, in
96100
int basic_parse_to_ast_between(BASICParseTree *ptree, ASTNode *root, int from, int to);
97101
int basic_parse_to_ast(BASICProgram *program);
98102

99-
100103
/* BASIC interpreter */
101104

102-
typedef enum {
103-
KW_DO_NOTHING,
104-
KW_JMP_ONLY,
105-
KW_JMP_AND_RET_NEXT,
106-
KW_JMP_AND_RET_CURR
105+
typedef enum
106+
{
107+
KW_DO_NOTHING,
108+
KW_JMP_ONLY,
109+
KW_JMP_AND_RET_NEXT,
110+
KW_JMP_AND_RET_CURR
107111
} KeywordAction;
108112

109-
typedef struct {
110-
ASTNodeData value;
111-
StringLiteral name;
113+
typedef struct
114+
{
115+
ASTNodeData value;
116+
StringLiteral name;
112117
} BASICVariable;
113118

114-
typedef struct {
115-
BASICProgram *program;
116-
int halt;
117-
BASICVariable *variables;
118-
int var_count;
119-
StackNode *traverse_stack;
119+
typedef struct
120+
{
121+
BASICProgram *program;
122+
int halt;
123+
BASICVariable *variables;
124+
int var_count;
125+
StackNode *traverse_stack;
120126
} BASICRuntime;
121127

122-
typedef ASTNodeData(*basic_function)(BASICRuntime *runtime, ASTNode *args);
128+
typedef ASTNodeData (*basic_function)(BASICRuntime *runtime, ASTNode *args);
123129

124130
/* Public functions */
125131
BASICRuntime *basic_create_runtime(BASICProgram *program);

0 commit comments

Comments
 (0)