Browse Source

line bits reduced to 16

Kajetan Johannes Hammerle 4 years ago
parent
commit
974f3c89b6
4 changed files with 16 additions and 6 deletions
  1. 3 3
      Compiler.c
  2. 1 1
      Script.c
  3. 9 2
      Tokenizer.c
  4. 3 0
      Tokenizer.h

+ 3 - 3
Compiler.c

@@ -14,7 +14,7 @@ static char error[ERROR_LENGTH] = {'\0'};
 
 static unsigned char byteCode[MAX_BYTES];
 static int writeIndex = 0;
-static int line = 1;
+static int16 line = 1;
 
 static void cError(const char* format, ...) {
     va_list args;
@@ -39,12 +39,12 @@ static bool cAddBytes(const void* data, int length) {
 
 static bool cAddOperation(Operation token) {
     unsigned char c = token;
-    return cAddBytes(&c, 1) && cAddBytes(&line, sizeof(int));
+    return cAddBytes(&c, 1) && cAddBytes(&line, sizeof(line));
 }
 
 static Token tReadTokenAndLine() {
     Token t = tReadToken();
-    if(tReadInt(&line)) {
+    if(tReadInt16(&line)) {
         return t;
     }
     return T_END;

+ 1 - 1
Script.c

@@ -37,7 +37,7 @@ static Operation sReadOperation(Script* sc) {
     unsigned char c;
     if(sRead(sc, &c, 1)) {
         return OP_NOTHING;
-    } else if(sRead(sc, &sc->line, sizeof(int))) {
+    } else if(sRead(sc, &sc->line, 2)) {
         sError(sc, "operation without line near line %d", sc->line);
         return OP_NOTHING;
     }

+ 9 - 2
Tokenizer.c

@@ -13,7 +13,7 @@
 static char tokenBuffer[TOKEN_BUFFER_LENGTH];
 static int writeIndex = 0;
 static int readIndex = 0;
-static int line = 1;
+static int16 line = 1;
 static FILE* file = NULL;
 static char error[ERROR_LENGTH] = {'\0'};
 
@@ -35,7 +35,7 @@ static bool tAdd(const void* data, int length) {
 
 static bool tAddToken(Token token) {
     unsigned char c = token;
-    return tAdd(&c, 1) && tAdd(&line, sizeof(int));
+    return tAdd(&c, 1) && tAdd(&line, sizeof(line));
 }
 
 static bool tReadTokens(void* dest, int length) {
@@ -190,6 +190,13 @@ bool tReadInt(int* i) {
     return false;
 }
 
+bool tReadInt16(int16* i) {
+    if(tReadTokens(i, sizeof(int16))) {
+        return true;
+    }
+    return false;
+}
+
 bool tReadFloat(float* f) {
     if(tReadTokens(f, sizeof(float))) {
         return true;

+ 3 - 0
Tokenizer.h

@@ -18,6 +18,8 @@ typedef enum Token {
     T_END
 } Token;
 
+typedef int16_t int16;
+
 bool tTokenize(const char* path);
 const char* tGetError();
 
@@ -25,6 +27,7 @@ void tResetReader();
 Token tPeekToken();
 Token tReadToken();
 bool tReadInt(int* i);
+bool tReadInt16(int16* i);
 bool tReadFloat(float* i);
 
 const char* tGetTokenName(Token token);