Browse Source

refactoring

Kajetan Johannes Hammerle 3 years ago
parent
commit
f254ef5e08
23 changed files with 39 additions and 34 deletions
  1. 3 3
      Compiler.c
  2. 1 1
      Compiler.h
  3. 1 1
      Main.c
  4. 2 2
      Test.c
  5. 8 8
      meson.build
  6. 1 1
      tokenizer/Tokenizer.c
  7. 1 1
      utils/ByteCodePrinter.c
  8. 1 1
      utils/ByteCodePrinter.h
  9. 9 5
      utils/FunctionMap.c
  10. 0 0
      utils/FunctionMap.h
  11. 3 2
      utils/StringIntMap.c
  12. 0 0
      utils/StringIntMap.h
  13. 1 1
      utils/Utils.c
  14. 0 0
      utils/Utils.h
  15. 1 1
      vm/Allocator.c
  16. 0 0
      vm/Allocator.h
  17. 1 1
      vm/ByteCode.c
  18. 0 0
      vm/ByteCode.h
  19. 1 1
      vm/Object.c
  20. 0 0
      vm/Object.h
  21. 0 0
      vm/Operation.h
  22. 2 2
      vm/Script.c
  23. 3 3
      vm/Script.h

+ 3 - 3
Compiler.c

@@ -4,10 +4,10 @@
 #include <string.h>
 
 #include "Compiler.h"
-#include "FunctionMap.h"
-#include "Operation.h"
-#include "StringIntMap.h"
 #include "tokenizer/Tokenizer.h"
+#include "utils/FunctionMap.h"
+#include "utils/StringIntMap.h"
+#include "vm/Operation.h"
 
 #define ERROR_LENGTH 256
 #define RETURN_BUFFER 16

+ 1 - 1
Compiler.h

@@ -1,7 +1,7 @@
 #ifndef COMPILER_H
 #define COMPILER_H
 
-#include "ByteCode.h"
+#include "vm/ByteCode.h"
 
 ByteCode* cCompile();
 const char* cGetError();

+ 1 - 1
Main.c

@@ -3,9 +3,9 @@
 #include <time.h>
 
 #include "Compiler.h"
-#include "Script.h"
 #include "Test.h"
 #include "tokenizer/Tokenizer.h"
+#include "vm/Script.h"
 
 long getNanos() {
     struct timespec time;

+ 2 - 2
Test.c

@@ -6,10 +6,10 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "ByteCodePrinter.h"
 #include "Compiler.h"
-#include "Script.h"
 #include "tokenizer/Tokenizer.h"
+#include "utils/ByteCodePrinter.h"
+#include "vm/Script.h"
 
 static int doneTests = 0;
 static int allTests = 0;

+ 8 - 8
meson.build

@@ -5,16 +5,16 @@ src = [
     'tokenizer/Tokenizer.c', 
     'tokenizer/Token.c', 
     'tokenizer/File.c', 
+    'utils/Utils.c', 
+    'utils/StringIntMap.c',
+    'utils/FunctionMap.c',
+    'utils/ByteCodePrinter.c',
     'Compiler.c', 
-    'Utils.c', 
-    'Script.c', 
     'Test.c', 
-    'StringIntMap.c',
-    'ByteCode.c',
-    'ByteCodePrinter.c',
-    'FunctionMap.c',
-    'Object.c',
-    'Allocator.c'
+    'vm/ByteCode.c',
+    'vm/Script.c', 
+    'vm/Object.c',
+    'vm/Allocator.c'
 ]
 
 executable('lonely_tiger', 

+ 1 - 1
tokenizer/Tokenizer.c

@@ -4,9 +4,9 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "Utils.h"
 #include "tokenizer/File.h"
 #include "tokenizer/Tokenizer.h"
+#include "utils/Utils.h"
 
 #define TOKEN_BUFFER_LENGTH (1024 * 1024)
 #define ERROR_LENGTH 256

+ 1 - 1
ByteCodePrinter.c → utils/ByteCodePrinter.c

@@ -2,7 +2,7 @@
 #include <stdio.h>
 #include <string.h>
 
-#include "ByteCodePrinter.h"
+#include "utils/ByteCodePrinter.h"
 
 #define LINE_LENGTH 80
 

+ 1 - 1
ByteCodePrinter.h → utils/ByteCodePrinter.h

@@ -1,7 +1,7 @@
 #ifndef BYTECODEPRINTER_H
 #define BYTECODEPRINTER_H
 
-#include "ByteCode.h"
+#include "vm/ByteCode.h"
 
 void btPrint(ByteCode* bt);
 

+ 9 - 5
FunctionMap.c → utils/FunctionMap.c

@@ -1,7 +1,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "FunctionMap.h"
+#include "utils/FunctionMap.h"
 
 void fmInit(FunctionMap* fm) {
     fm->capacity = 16;
@@ -19,14 +19,16 @@ void fmDelete(FunctionMap* fm) {
 
 Function* fmSearch(FunctionMap* fm, const char* name, int arguments) {
     for(int i = 0; i < fm->entries; i++) {
-        if(fm->data[i].arguments == arguments && strcmp(fm->data[i].name, name) == 0) {
+        if(fm->data[i].arguments == arguments &&
+           strcmp(fm->data[i].name, name) == 0) {
             return fm->data + i;
         }
     }
     return NULL;
 }
 
-bool fmAdd(FunctionMap* fm, const char* name, int arguments, int address, bool returns) {
+bool fmAdd(FunctionMap* fm, const char* name, int arguments, int address,
+           bool returns) {
     if(fmSearch(fm, name, arguments) != NULL) {
         return false;
     }
@@ -42,10 +44,12 @@ bool fmAdd(FunctionMap* fm, const char* name, int arguments, int address, bool r
     return true;
 }
 
-void fmEnqueue(FunctionMap* fm, const char* name, int arguments, int line, int reserved, bool noReturn) {
+void fmEnqueue(FunctionMap* fm, const char* name, int arguments, int line,
+               int reserved, bool noReturn) {
     if(fm->queueEntries >= fm->queueCapacity) {
         fm->queueCapacity *= 2;
-        fm->queue = realloc(fm->queue, sizeof(LingeringFunction) * fm->queueCapacity);
+        fm->queue =
+            realloc(fm->queue, sizeof(LingeringFunction) * fm->queueCapacity);
     }
     int index = fm->queueEntries++;
     fm->queue[index].name = name;

+ 0 - 0
FunctionMap.h → utils/FunctionMap.h


+ 3 - 2
StringIntMap.c → utils/StringIntMap.c

@@ -2,7 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "StringIntMap.h"
+#include "utils/StringIntMap.h"
 
 void simInit(StringIntMap* sim) {
     sim->capacity = 16;
@@ -31,7 +31,8 @@ bool simAdd(StringIntMap* sim, const char* s, int* mapping) {
         return false;
     } else if(sim->entries >= sim->capacity) {
         sim->capacity *= 2;
-        sim->stringData = realloc(sim->stringData, sizeof(const char*) * sim->capacity);
+        sim->stringData =
+            realloc(sim->stringData, sizeof(const char*) * sim->capacity);
         sim->intData = realloc(sim->intData, sizeof(int) * sim->capacity);
     }
     int index = sim->entries++;

+ 0 - 0
StringIntMap.h → utils/StringIntMap.h


+ 1 - 1
Utils.c → utils/Utils.c

@@ -1,4 +1,4 @@
-#include "Utils.h"
+#include "utils/Utils.h"
 
 bool isLetter(int c) {
     return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');

+ 0 - 0
Utils.h → utils/Utils.h


+ 1 - 1
Allocator.c → vm/Allocator.c

@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "Allocator.h"
+#include "vm/Allocator.h"
 
 void aInit(Allocator* a) {
     a->capacity = 0;

+ 0 - 0
Allocator.h → vm/Allocator.h


+ 1 - 1
ByteCode.c → vm/ByteCode.c

@@ -2,7 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "ByteCode.h"
+#include "vm/ByteCode.h"
 
 ByteCode* bcInit() {
     ByteCode* bc = malloc(sizeof(ByteCode));

+ 0 - 0
ByteCode.h → vm/ByteCode.h


+ 1 - 1
Object.c → vm/Object.c

@@ -1,4 +1,4 @@
-#include "Object.h"
+#include "vm/Object.h"
 
 const char* oGetName(ObjectType ot) {
     switch(ot) {

+ 0 - 0
Object.h → vm/Object.h


+ 0 - 0
Operation.h → vm/Operation.h


+ 2 - 2
Script.c → vm/Script.c

@@ -4,8 +4,8 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "Operation.h"
-#include "Script.h"
+#include "vm/Operation.h"
+#include "vm/Script.h"
 
 static void sError(Script* sc, const char* format, ...) {
     va_list args;

+ 3 - 3
Script.h → vm/Script.h

@@ -3,9 +3,9 @@
 
 #include <stdbool.h>
 
-#include "Allocator.h"
-#include "ByteCode.h"
-#include "Object.h"
+#include "vm/Allocator.h"
+#include "vm/ByteCode.h"
+#include "vm/Object.h"
 
 #define SCRIPT_STACK_SIZE 1000
 #define SCRIPT_ERROR_SIZE 256