Added / started some infrastructure / boilerplate code.

This commit is contained in:
2024-10-30 00:28:11 -05:00
parent 8923a2006d
commit 2c85077031
12 changed files with 273 additions and 27 deletions
+4
View File
@@ -0,0 +1,4 @@
#ifndef AST_H
#define AST_H
#endif
+16
View File
@@ -0,0 +1,16 @@
#ifndef DICTIONARY_H
#define DICTIONARY_H
typedef struct {
const char* Key;
void* Value;
} KeyValPair;
typedef struct _dictionary Dictionary;
Dictionary* DictionaryCreate(void);
KeyValPair* KeyValPairCreate(const char* key, void* value);
int DictionaryAdd(Dictionary* dict, const char* key, void* value);
void* DictionaryGetValue(const Dictionary* dict, const char* key);
#endif
+15
View File
@@ -0,0 +1,15 @@
#ifndef FUTIL_H
#define FUTIL_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#ifndef FUTIL_READ_SIZE
#define FUTIL_READ_SIZE 2097152 //Default here is 2MiB
#endif
int ReadAllString(const char*, char**, size_t*);
#endif
+11
View File
@@ -0,0 +1,11 @@
#ifndef KEYWORDS_H
#define KEYWORDS_H
typedef enum {
FN, ORG
} Keyword;
int IsKeyword(const char* text, Keyword* keyword);
void GetKeywordText(Keyword keyword, char buffer[16]);
#endif
+1 -1
View File
@@ -10,7 +10,7 @@ typedef enum {
} Registers;
typedef enum {
ADD = 0x01, SUB, MUL, DIV, AND, OR, XOR, NOT, SHL, SHR, NOP, CMP, JMP, JG, JL,
ADD = 0x01, SUB, MUL, DIV, MOV, AND, OR, XOR, NOT, SHL, SHR, NOP, CMP, JMP, JG, JL,
OUTB, INB, HLT, ENI, INT, LIVT, PUSHA, POPA, CALL, RET, PUSH, POP
} Mnemonic;
+35
View File
@@ -0,0 +1,35 @@
#ifndef TOKEN_H
#define TOKEN_H
enum TokenType {
Empty,
String,
Number,
Symbol,
Plus = '+',
Minus = '-',
Star = '*',
Slash = '/',
Carot = '^',
OpenParen = '(',
CloseParen = ')',
FileEnd
};
typedef struct _token {
TokenType Type;
char* Name;
union {
char* String;
int Number;
} Value;
int LineNumber;
int ColumnNumber;
int Index;
int Length;
int Resolved;
} Token;
Token* TokenCreate(char* name, TokenType type, int lineNumber, int columnNumber, int index, int length, int resolved);
#endif