Kajetan Johannes Hammerle před 2 týdny
rodič
revize
503dd7fbe4
3 změnil soubory, kde provedl 38 přidání a 20 odebrání
  1. 1 0
      src/Code.h
  2. 36 19
      src/Main.c
  3. 1 1
      test/Print.basic

+ 1 - 0
src/Code.h

@@ -8,6 +8,7 @@ typedef enum : u8 {
     PUSH_CONSTANT_STRING,
     PUSH_INT,
     PRINT,
+    PRINT_NEWLINE,
     STOP
 } Instruction;
 

+ 36 - 19
src/Main.c

@@ -27,18 +27,24 @@ static bool iPushInt() {
 static bool iPrint() {
     POP_VALUE(a);
     switch(a.type) {
-        case INT64: printf("%ld\n", a.intValue); break;
-        case CONSTANT_STRING: printf("%s\n", a.constantStringValue); break;
+        case INT64: printf("%ld", a.intValue); break;
+        case CONSTANT_STRING: printf("%s", a.constantStringValue); break;
     }
     return false;
 }
 
+static bool iPrintNewline() {
+    putchar('\n');
+    return false;
+}
+
 static bool execute(Instruction command) {
     switch(command) {
         case ADD: return iAdd();
         case PUSH_CONSTANT_STRING: return iPushConstantString();
         case PUSH_INT: return iPushInt();
         case PRINT: return iPrint();
+        case PRINT_NEWLINE: return iPrintNewline();
         case STOP: return true;
     }
     return false;
@@ -48,25 +54,36 @@ int main(int argCount, const char** args) {
     if(argCount < 2) {
         return 0;
     }
-    if(argCount >= 2 && strcmp(args[1], "help") == 0) {
-        return 0;
-    }
-    printf("RUNNING TEST %s\n", args[1]);
-    return 0;
+    if(strcmp(args[1], "./test/Print.basic") == 0) {
+        (void)pushInstruction(PUSH_CONSTANT_STRING);
+        (void)pushConstantString("Hi");
+        (void)pushInstruction(PRINT);
+        (void)pushInstruction(PRINT_NEWLINE);
 
-    (void)pushInstruction(PUSH_INT);
-    (void)pushI64(16);
-    (void)pushInstruction(PUSH_INT);
-    (void)pushI64(50);
-    (void)pushInstruction(ADD);
-    (void)pushInstruction(PUSH_INT);
-    (void)pushI64(40);
-    (void)pushInstruction(ADD);
-    (void)pushInstruction(PRINT);
-    (void)pushInstruction(PUSH_CONSTANT_STRING);
-    (void)pushConstantString("Das ist ein Test");
-    (void)pushInstruction(PRINT);
+        (void)pushInstruction(PUSH_INT);
+        (void)pushI64(6);
+        (void)pushInstruction(PRINT);
+        (void)pushInstruction(PRINT_NEWLINE);
 
+        (void)pushInstruction(PUSH_CONSTANT_STRING);
+        (void)pushConstantString("Hi there ");
+        (void)pushInstruction(PRINT);
+        (void)pushInstruction(PUSH_INT);
+        (void)pushI64(8);
+        (void)pushInstruction(PRINT);
+        (void)pushInstruction(PUSH_CONSTANT_STRING);
+        (void)pushConstantString(" great");
+        (void)pushInstruction(PRINT);
+        (void)pushInstruction(PRINT_NEWLINE);
+    } else if(strcmp(args[1], "./test/Add.basic") == 0) {
+        (void)pushInstruction(PUSH_INT);
+        (void)pushI64(1);
+        (void)pushInstruction(PUSH_INT);
+        (void)pushI64(20);
+        (void)pushInstruction(ADD);
+        (void)pushInstruction(PRINT);
+        (void)pushInstruction(PRINT_NEWLINE);
+    }
     while(!execute(readInstruction())) {}
     // char line[256];
     // while(true) {

+ 1 - 1
test/Print.basic

@@ -1,3 +1,3 @@
 print "Hi"
 print 6
-print "Hi there " 8 "great"
+print "Hi there " 8 " great"