Kajetan Johannes Hammerle 3 rokov pred
rodič
commit
c0b0ff7378
4 zmenil súbory, kde vykonal 34 pridanie a 5 odobranie
  1. 31 2
      Main.c
  2. 1 1
      Script.h
  3. 1 1
      Tokenizer.c
  4. 1 1
      meson.build

+ 31 - 2
Main.c

@@ -1,8 +1,37 @@
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#include "Compiler.h"
+#include "Script.h"
 #include "Test.h"
+#include "Tokenizer.h"
+
+long getNanos() {
+    struct timespec time;
+    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time);
+    return time.tv_nsec + time.tv_sec * 1000000000l;
+}
 
 int main(int argAmount, const char** args) {
-    if(argAmount >= 2) {
-        tsStart(args[1]);
+    if(argAmount >= 3 && strcmp(args[1], "test") == 0) {
+        tsStart(args[2]);
+    } else if(argAmount >= 2) {
+        if(tTokenize(args[1])) {
+            puts(tGetError());
+            return 0;
+        }
+        ByteCode* code = cCompile();
+        if(code == NULL) {
+            puts(tGetError());
+            return 0;
+        }
+        Script* sc = sInit(code);
+        long time = -getNanos();
+        sRun(sc);
+        time += getNanos();
+        printf("----------------\n%ld ns\n", time);
+        sDelete(sc);
     }
     return 0;
 }

+ 1 - 1
Script.h

@@ -6,7 +6,7 @@
 #include "ByteCode.h"
 #include "Object.h"
 
-#define SCRIPT_STACK_SIZE 100
+#define SCRIPT_STACK_SIZE 1000
 #define SCRIPT_ERROR_SIZE 256
 
 typedef struct Script {

+ 1 - 1
Tokenizer.c

@@ -271,7 +271,7 @@ void tPrint() {
         if(t == T_END) {
             break;
         }
-        int line;
+        int line = 0;
         tReadInt(&line);
         printf("%d: %s\n", line, tGetTokenName(t));
         if(t == T_INT) {

+ 1 - 1
meson.build

@@ -14,4 +14,4 @@ src = [
 
 executable('lonely_tiger', 
     sources: src,
-    c_args: ['-Wall', '-Wextra', '-pedantic', '-Werror'])
+    c_args: ['-Wall', '-Wextra', '-pedantic', '-Werror', '-O3'])