Browse Source

refactored to have readable stack, simpler more Java like syntax

Kajetan Johannes Hammerle 2 years ago
parent
commit
2d725611e3
100 changed files with 581 additions and 1058 deletions
  1. 168 249
      Compiler.c
  2. 41 97
      DataType.c
  3. 35 36
      DataType.h
  4. 6 2
      Error.c
  5. 2 0
      Error.h
  6. 21 34
      Test.c
  7. 5 0
      Types.h
  8. 3 3
      libraries/Math.c
  9. 59 56
      libraries/Time.c
  10. 0 0
      old_tests/pre/include
  11. 0 0
      old_tests/pre/include.out
  12. 0 0
      old_tests/pre/list
  13. 0 0
      old_tests/pre/list.out
  14. 0 0
      old_tests/pre/list_test
  15. 0 0
      old_tests/pre/list_test.out
  16. 0 0
      old_tests/pre/pre
  17. 0 0
      old_tests/pre/pre.out
  18. 3 8
      tests/arrays/alloc
  19. 2 4
      tests/arrays/alloc.out
  20. 1 1
      tests/arrays/and
  21. 1 1
      tests/arrays/dec
  22. 1 1
      tests/arrays/inc
  23. 0 27
      tests/arrays/multi
  24. 0 6
      tests/arrays/multi.out
  25. 1 1
      tests/arrays/or
  26. 1 1
      tests/arrays/setop
  27. 1 1
      tests/arrays/shift
  28. 30 0
      tests/arrays/struct_array
  29. 10 0
      tests/arrays/struct_array.out
  30. 3 21
      tests/arrays/types
  31. 1 6
      tests/arrays/types.out
  32. 1 1
      tests/arrays/xor
  33. 0 6
      tests/bits/and
  34. 0 2
      tests/bits/and.out
  35. 0 2
      tests/bits/invert
  36. 0 2
      tests/bits/invert.out
  37. 0 6
      tests/bits/or
  38. 0 2
      tests/bits/or.out
  39. 0 10
      tests/bits/shift
  40. 0 2
      tests/bits/shift.out
  41. 0 6
      tests/bits/xor
  42. 0 2
      tests/bits/xor.out
  43. 0 1
      tests/calc/add
  44. 0 1
      tests/calc/add.out
  45. 0 1
      tests/calc/div
  46. 0 1
      tests/calc/div.out
  47. 0 1
      tests/calc/mod
  48. 0 1
      tests/calc/mod.out
  49. 0 1
      tests/calc/mul
  50. 0 1
      tests/calc/mul.out
  51. 0 1
      tests/calc/sub
  52. 0 1
      tests/calc/sub.out
  53. 0 14
      tests/cast/cast_float_long
  54. 0 8
      tests/cast/cast_float_long.out
  55. 0 11
      tests/cast/cast_int_long
  56. 0 6
      tests/cast/cast_int_long.out
  57. 14 14
      tests/comparison/equal.out
  58. 10 10
      tests/comparison/greater.out
  59. 10 10
      tests/comparison/greater_equal.out
  60. 10 10
      tests/comparison/less.out
  61. 10 10
      tests/comparison/less_equal.out
  62. 14 14
      tests/comparison/not_equal.out
  63. 0 53
      tests/const
  64. 0 5
      tests/const.out
  65. 1 1
      tests/functions/arguments
  66. 1 1
      tests/functions/arguments.out
  67. 2 2
      tests/if/and
  68. 8 8
      tests/if/and.out
  69. 6 6
      tests/if/invert.out
  70. 1 1
      tests/if/or
  71. 7 7
      tests/if/or.out
  72. 0 11
      tests/loops/while_post_dec
  73. 0 10
      tests/loops/while_post_dec.out
  74. 0 11
      tests/loops/while_post_inc
  75. 0 10
      tests/loops/while_post_inc.out
  76. 0 11
      tests/loops/while_pre_dec
  77. 0 10
      tests/loops/while_pre_dec.out
  78. 0 11
      tests/loops/while_pre_inc
  79. 0 10
      tests/loops/while_pre_inc.out
  80. 19 12
      tests/mix
  81. 3 3
      tests/mix.out
  82. 2 16
      tests/strings/string
  83. 0 5
      tests/strings/string.out
  84. 10 15
      tests/strings/string_lib
  85. 5 5
      tests/strings/string_lib.out
  86. 3 3
      tests/struct_ref/alloc
  87. 1 1
      tests/struct_ref/alloc.out
  88. 10 10
      tests/struct_ref/bool_reference
  89. 2 4
      tests/struct_ref/bool_reference.out
  90. 10 11
      tests/struct_ref/float_reference
  91. 1 3
      tests/struct_ref/float_reference.out
  92. 11 11
      tests/struct_ref/int_reference
  93. 1 3
      tests/struct_ref/int_reference.out
  94. 0 16
      tests/struct_ref/long_reference
  95. 0 4
      tests/struct_ref/long_reference.out
  96. 1 4
      tests/struct_ref/nested
  97. 3 19
      tests/struct_ref/pass_struct
  98. 3 9
      tests/struct_ref/pass_struct.out
  99. 3 19
      tests/struct_ref/struct_access
  100. 3 4
      tests/struct_ref/struct_access.out

+ 168 - 249
Compiler.c

@@ -18,13 +18,11 @@ static int16 line = 1;
 
 static jmp_buf errorJump;
 
-/*#define RETURN_BUFFER 16
+#define RETURN_BUFFER 16
 #define BREAK_BUFFER 32
 
 #define DT_OPERATION(op)                                                       \
-    case DT_INT32: cAddOperation(OP_##op##_INT32); break;                      \
-    case DT_INT64: cAddOperation(OP_##op##_INT64); break;                      \
-    case DT_BOOL: cAddOperation(OP_##op##_BOOL); break;                        \
+    case DT_INT: cAddOperation(OP_##op##_INT); break;                          \
     case DT_FLOAT: cAddOperation(OP_##op##_FLOAT); break;
 
 typedef DataType (*Parser)(void);
@@ -49,33 +47,30 @@ static int continueAt = 0;
 
 typedef struct {
     Operation intOp;
-    Operation longOp;
     Operation floatOp;
-    Operation boolOp;
     Operation pointerOp;
     const char* name;
 } TypedOp;
 
-#define TYPE_OP(NAME, FLOAT, BOOL, POINTER, text)                              \
-    static const TypedOp TYPED_##NAME = {OP_##NAME##_INT32, OP_##NAME##_INT64, \
-                                         OP_##FLOAT,        OP_##BOOL,         \
-                                         OP_##POINTER,      text};
-TYPE_OP(MUL, MUL_FLOAT, NOTHING, NOTHING, "*")
-TYPE_OP(DIV, DIV_FLOAT, NOTHING, NOTHING, "/")
-TYPE_OP(MOD, NOTHING, NOTHING, NOTHING, "%")
-TYPE_OP(ADD, ADD_FLOAT, NOTHING, NOTHING, "+")
-TYPE_OP(SUB, SUB_FLOAT, NOTHING, NOTHING, "-")
-TYPE_OP(LESS, LESS_FLOAT, NOTHING, NOTHING, "<")
-TYPE_OP(LESS_EQUAL, LESS_EQUAL_FLOAT, NOTHING, NOTHING, "<=")
-TYPE_OP(GREATER, GREATER_FLOAT, NOTHING, NOTHING, ">")
-TYPE_OP(GREATER_EQUAL, GREATER_EQUAL_FLOAT, NOTHING, NOTHING, ">=")
-TYPE_OP(EQUAL, EQUAL_FLOAT, EQUAL_BOOL, EQUAL_POINTER, "==")
-TYPE_OP(NOT_EQUAL, NOT_EQUAL_FLOAT, NOT_EQUAL_BOOL, NOT_EQUAL_POINTER, "!=")
-TYPE_OP(BIT_OR, NOTHING, NOTHING, NOTHING, "|")
-TYPE_OP(BIT_XOR, NOTHING, NOTHING, NOTHING, "^")
-TYPE_OP(BIT_AND, NOTHING, NOTHING, NOTHING, "&")
-TYPE_OP(LEFT_SHIFT, NOTHING, NOTHING, NOTHING, "<<")
-TYPE_OP(RIGHT_SHIFT, NOTHING, NOTHING, NOTHING, ">>")
+#define TYPE_OP(NAME, FLOAT, POINTER, text)                                    \
+    static const TypedOp TYPED_##NAME = {OP_##NAME##_INT, OP_##FLOAT,          \
+                                         OP_##POINTER, text};
+TYPE_OP(MUL, MUL_FLOAT, NOTHING, "*")
+TYPE_OP(DIV, DIV_FLOAT, NOTHING, "/")
+TYPE_OP(MOD, NOTHING, NOTHING, "%")
+TYPE_OP(ADD, ADD_FLOAT, NOTHING, "+")
+TYPE_OP(SUB, SUB_FLOAT, NOTHING, "-")
+TYPE_OP(LESS, LESS_FLOAT, NOTHING, "<")
+TYPE_OP(LESS_EQUAL, LESS_EQUAL_FLOAT, NOTHING, "<=")
+TYPE_OP(GREATER, GREATER_FLOAT, NOTHING, ">")
+TYPE_OP(GREATER_EQUAL, GREATER_EQUAL_FLOAT, NOTHING, ">=")
+TYPE_OP(EQUAL, EQUAL_FLOAT, EQUAL_POINTER, "==")
+TYPE_OP(NOT_EQUAL, NOT_EQUAL_FLOAT, NOT_EQUAL_POINTER, "!=")
+TYPE_OP(BIT_OR, NOTHING, NOTHING, "|")
+TYPE_OP(BIT_XOR, NOTHING, NOTHING, "^")
+TYPE_OP(BIT_AND, NOTHING, NOTHING, "&")
+TYPE_OP(LEFT_SHIFT, NOTHING, NOTHING, "<<")
+TYPE_OP(RIGHT_SHIFT, NOTHING, NOTHING, ">>")
 
 static void cError(const char* format, ...) {
     va_list args;
@@ -109,6 +104,19 @@ static void cUnexpectedToken(Token t) {
     cError("unexpected token: %s", tGetName(t));
 }
 
+#define BUFFER_SIZE 256
+
+static void cUnknownFunction(Function* f) {
+    int max = 0;
+    char buffer[BUFFER_SIZE] = {'\0'};
+    for(int i = 0; i < f->arguments; i++) {
+        const char* name = dtGetName(&structs, f->argumentTypes[i]);
+        max += snprintf(buffer + max, BUFFER_SIZE - max, i > 0 ? ", %s" : "%s",
+                        name);
+    }
+    cError("unknown function: %s(%s)", f->name, buffer);
+}
+
 static void cAddOperation(Operation token) {
     unsigned char c = token;
     bcAddBytes(code, &c, 1);
@@ -126,10 +134,6 @@ static void cAddInt32(int32 i) {
     bcAddBytes(code, &i, sizeof(int32));
 }
 
-static void cAddInt64(int64 i) {
-    bcAddBytes(code, &i, sizeof(int64));
-}
-
 static void cAddInt32Operation(Operation token, int32 i) {
     cAddOperation(token);
     cAddInt32(i);
@@ -140,18 +144,18 @@ static void cAddByteOperation(Operation token, int8 i) {
     bcAddBytes(code, &i, sizeof(int8));
 }
 
-static void cAddLine(int16 i) {
+static void cAddLine(int16 line) {
     cAddOperation(OP_LINE);
-    bcAddBytes(code, &i, sizeof(int16));
+    bcAddBytes(code, &line, sizeof(int16));
 }
 
 static Token cReadTokenAndLine() {
-    // hasReturn--;
-    Token t = tReadToken();
-    if(tReadInt16(&line)) {
-        return t;
+    hasReturn--;
+    Token t;
+    if(tReadTokenAndLine(&t, &line)) {
+        return T_END;
     }
-    return T_END;
+    return t;
 }
 
 static void cConsumeToken(Token wanted) {
@@ -167,24 +171,15 @@ static bool cConsumeTokenIf(Token t) {
 
 static void cConstantInt32() {
     int32 value;
-    if(!tReadInt32(&value)) {
+    if(tReadInt32(&value)) {
         cError("int token without an int");
     }
-    cAddInt32Operation(OP_PUSH_INT32, value);
-}
-
-static void cConstantInt64() {
-    int64 value;
-    if(!tReadInt64(&value)) {
-        cError("long token without an long");
-    }
-    cAddOperation(OP_PUSH_INT64);
-    cAddInt64(value);
+    cAddInt32Operation(OP_PUSH_INT, value);
 }
 
 static void cConstantFloat() {
     float value;
-    if(!tReadFloat(&value)) {
+    if(tReadFloat(&value)) {
         cError("float token without a float");
     }
     cAddOperation(OP_PUSH_FLOAT);
@@ -203,33 +198,18 @@ static int cGetSize(DataType dt) {
     return dtGetSize(dt, &structs);
 }
 
-static DataType cDereference(DataType dt) {
-    if(dtDereference(&dt)) {
-        cError("%s dereferenced too often", cGetName(dt));
-    }
-    return dt;
-}
-
-static DataType cExtendType(DataType dt, bool constant) {
-    while(cConsumeTokenIf(T_MUL)) {
-        dt = cDereference(dt);
-    }
-    if(constant) {
-        dt = dtConst(dt);
+static DataType cExtendType(DataType dt) {
+    if(cConsumeTokenIf(T_OPEN_SQUARE_BRACKET)) {
+        cConsumeToken(T_CLOSE_SQUARE_BRACKET);
+        dt = dtToArray(dt);
     }
     return dt;
 }
 
 static DataType cReadType(Token t, bool force) {
-    bool c = t == T_CONST;
-    if(c) {
-        t = cReadTokenAndLine();
-    }
     switch(t) {
-        case T_INT32: return cExtendType(dtInt32(), c);
-        case T_INT64: return cExtendType(dtInt64(), c);
-        case T_BOOL: return cExtendType(dtBool(), c);
-        case T_FLOAT: return cExtendType(dtFloat(), c);
+        case T_INT: return dtInt();
+        case T_FLOAT: return dtFloat();
         case T_LITERAL: {
             Struct* st = stsSearch(&structs, cReadString());
             if(st == NULL) {
@@ -239,7 +219,7 @@ static DataType cReadType(Token t, bool force) {
                     return dtVoid();
                 }
             }
-            return cExtendType(dtStruct(st), c);
+            return dtStruct(st);
         }
         default:
             if(force) {
@@ -249,22 +229,29 @@ static DataType cReadType(Token t, bool force) {
     }
 }
 
+static DataType cReadExtendedType(Token t, bool force) {
+    DataType dt = cReadType(t, force);
+    if(!dtIsVoid(dt)) {
+        dt = cExtendType(dt);
+    }
+    return dt;
+}
+
 static DataType cExpression();
 
 static void cLoadRef(DataType type) {
-    if(dtIsPointer(type)) {
-        cAddOperation(OP_REFERENCE);
+    if(dtIsArray(type)) {
+        cAddOperation(OP_LOAD_ARRAY);
         return;
     }
     switch(type.type) {
         DT_OPERATION(LOAD);
-        case DT_STRUCT: cAddInt32Operation(OP_LOAD, cGetSize(type)); break;
         default: cError("cannot load type %s", cGetName(type));
     }
 }
 
 static DataType cUnpack(DataType dt) {
-    if(dtRemoveVariable(&dt)) {
+    if(dt.type != DT_STRUCT && dtRemovePointer(&dt)) {
         cLoadRef(dt);
     }
     return dt;
@@ -297,14 +284,14 @@ static DataType cCallFunction(const char* name) {
     onLine = false;
     cCallFunctionArguments(&f);
     onLine = oldOnLine;
-    Function* found = fsSearch(&functions, &f, false);
+    Function* found = fsSearch(&functions, &f);
     if(found == NULL) {
-        cError("unknown function");
+        cUnknownFunction(&f);
     } else if(found->global) {
         cAddInt32Operation(OP_CALL, found->line);
         return found->returnType;
     }
-    char push[1 + sizeof(int32)] = {OP_PUSH_INT32};
+    char push[1 + sizeof(int32)] = {OP_PUSH_INT};
     bcInsertBytes(code, push, sizeof(push), returnAddress);
     cAddOperation(OP_GOSUB);
     if(found->address == -1) {
@@ -319,15 +306,14 @@ static DataType cCallFunction(const char* name) {
 }
 
 static void cStore(DataType left, DataType right, const char* name) {
-    if(dtIsPointer(left)) {
-        if(!dtNullCompare(left, right) &&
-           !dtNullCompare(left, dtConst(right))) {
+    if(dtIsArray(left)) {
+        if(!dtCompare(left, right)) {
             cInvalidOperation(left, right, name);
         }
-        cAddOperation(OP_STORE_POINTER);
+        cAddOperation(OP_STORE_ARRAY);
         return;
     }
-    if(!dtNullCompare(left, right) && !dtNullCompare(dtConst(left), right)) {
+    if(!dtCompare(left, right)) {
         cInvalidOperation(left, right, name);
     }
     switch(left.type) {
@@ -343,11 +329,19 @@ static DataType cLiteral() {
     }
     Variable v;
     if(!vsSearch(&vars, &v, literal)) {
-        cAddInt32Operation(OP_DEREFERENCE_VAR, v.address);
-        return dtToVariable(v.type);
+        if(v.type.pointer != 0) {
+            if(v.type.type != DT_STRUCT) {
+                cError("non struct type %s should not be a pointer here",
+                       cGetName(v.type));
+            }
+            cAddInt32Operation(OP_PUSH_STRUCT_REFERENCE, v.address);
+        } else {
+            cAddInt32Operation(OP_DEREFERENCE_VAR, v.address);
+        }
+        return dtToPointer(v.type);
     } else if(!vsSearch(&globalVars, &v, literal)) {
         cAddInt32Operation(OP_DEREFERENCE_GVAR, v.address);
-        return dtToVariable(v.type);
+        return dtToPointer(v.type);
     }
     cNotDeclared(literal);
     return dtVoid();
@@ -358,12 +352,12 @@ static DataType cText() {
     int32 lengthAddress = cReserveInt32();
     int32 length = 0;
     int32 c;
-    while(tReadInt32(&c) && c != 0) {
+    while(!tReadInt32(&c) && c != 0) {
         cAddInt32(c);
         length++;
     }
     cSetInt32(lengthAddress, length);
-    return dtConst(dtText());
+    return dtText();
 }
 
 static DataType cBracketPrimary() {
@@ -372,39 +366,38 @@ static DataType cBracketPrimary() {
     return result;
 }
 
-static void cArrayIndex(const char* name) {
-    if(!dtIsInt32(cUnpackedExpression())) {
-        cError("array %s must be an int", name);
+static void cArrayIndex() {
+    if(!dtIsInt(cUnpackedExpression())) {
+        cError("array index must be an int");
     }
 }
 
 static DataType cAllocArray() {
     DataType dt = cReadType(cReadTokenAndLine(), true);
+    if(dt.array != 0) {
+        cError("array type must not be an array");
+    }
     cConsumeToken(T_OPEN_SQUARE_BRACKET);
-    cArrayIndex("size");
+    cArrayIndex();
     cConsumeToken(T_CLOSE_SQUARE_BRACKET);
     cAddInt32Operation(OP_NEW, cGetSize(dt));
-    return cDereference(dt);
+    return dtToArray(dt);
 }
 
 static DataType cLength() {
-    DataType pointer = cUnpackedExpression();
-    if(!dtIsPointer(pointer)) {
-        cError("length expects a pointer");
+    DataType array = cUnpackedExpression();
+    if(!dtIsArray(array)) {
+        cError("length expects an array");
     }
     cAddOperation(OP_LENGTH);
-    return dtInt32();
+    return dtInt();
 }
 
 static DataType cPrimary() {
     Token t = cReadTokenAndLine();
     switch(t) {
-        case T_CONST_INT32: cConstantInt32(); return dtInt32();
-        case T_CONST_INT64: cConstantInt64(); return dtInt64();
-        case T_CONST_FLOAT: cConstantFloat(); return dtFloat();
-        case T_TRUE: cAddOperation(OP_PUSH_TRUE); return dtBool();
-        case T_FALSE: cAddOperation(OP_PUSH_FALSE); return dtBool();
-        case T_NULLPTR: cAddOperation(OP_PUSH_NULLPTR); return dtNull();
+        case T_INT_VALUE: cConstantInt32(); return dtInt();
+        case T_FLOAT_VALUE: cConstantFloat(); return dtFloat();
         case T_TEXT: return cText();
         case T_OPEN_BRACKET: return cBracketPrimary();
         case T_LITERAL: return cLiteral();
@@ -415,7 +408,7 @@ static DataType cPrimary() {
 }
 
 static void cRemoveReference(DataType* dt, const char* name) {
-    if(!dtRemoveVariable(dt)) {
+    if(!dtRemovePointer(dt)) {
         cError("%s needs a reference not %s", name, cGetName(*dt));
     }
 }
@@ -438,19 +431,17 @@ static void cChangeType(DataType* dt, Operation op, Operation pushOp,
 
 static void cPostChange(DataType* dt, int change, const char* name) {
     cRemoveReference(dt, name);
-    if(dtIsInt32(*dt)) {
-        cChangeType(dt, OP_CHANGE_INT32, OP_PUSH_POST_CHANGE_INT32, change);
-    } else if(dtIsInt64(*dt)) {
-        cChangeType(dt, OP_CHANGE_INT64, OP_PUSH_POST_CHANGE_INT64, change);
+    if(dtIsInt(*dt)) {
+        cChangeType(dt, OP_CHANGE_INT, OP_PUSH_POST_CHANGE_INT, change);
     } else {
-        cError("%s needs an int or long not %s", name, cGetName(*dt));
+        cError("%s needs an int not %s", name, cGetName(*dt));
     }
 }
 
-static DataType cStructAccess(DataType dt, int pointers) {
+static DataType cStructAccess(DataType dt) {
     Struct* st = dtGetStruct(&structs, dt);
-    if(st == NULL || dt.pointers != pointers) {
-        cError(pointers == 0 ? ". expects a struct" : "-> expects a struct*");
+    if(st == NULL) {
+        cError(". expects a struct not %s", cGetName(dt));
     }
     cConsumeToken(T_LITERAL);
     const char* name = cReadString();
@@ -458,12 +449,10 @@ static DataType cStructAccess(DataType dt, int pointers) {
     if(vSearchStruct(&inner, &structs, st, name)) {
         cError("%s has no member %s", st->name, name);
     } else if(inner.address > 0) {
-        cAddInt32Operation(OP_PUSH_INT32, inner.address);
+        cAddInt32Operation(OP_PUSH_INT, inner.address);
         cAddInt32Operation(OP_ADD_REFERENCE, 1);
     }
-    DataType r = dtToVariable(inner.type);
-    r.constant = dt.constant;
-    return r;
+    return dtToPointer(inner.type);
 }
 
 static DataType cAccess() {
@@ -475,19 +464,17 @@ static DataType cAccess() {
             cPostChange(&dt, -1, "--");
         } else if(cConsumeTokenIf(T_POINT)) {
             cRemoveReference(&dt, ".");
-            dt = cStructAccess(dt, 0);
-        } else if(cConsumeTokenIf(T_ARROW)) {
-            dt = cStructAccess(cUnpack(dt), 1);
+            dt = cStructAccess(dt);
         } else if(cConsumeTokenIf(T_OPEN_SQUARE_BRACKET)) {
-            dt = cUnpack(dt);
-            if(!dtIsPointer(dt)) {
-                cError("[] needs a pointer");
+            if(!dtIsArray(dt)) {
+                cError("[] needs an array");
             }
+            cAddOperation(OP_LOAD_ARRAY);
+            dtRemovePointer(&dt);
             cArrayIndex("index");
             cConsumeToken(T_CLOSE_SQUARE_BRACKET);
-            dt = dtReference(dt);
             cAddInt32Operation(OP_ADD_REFERENCE, cGetSize(dt));
-            dt = dtToVariable(dt);
+            dt = dtToPointer(dtRemoveArray(dt));
         } else {
             return dt;
         }
@@ -496,21 +483,17 @@ static DataType cAccess() {
 
 static DataType cPreChange(DataType dt, int change, const char* name) {
     cRemoveReference(&dt, name);
-    if(dtIsInt32(dt)) {
-        cChangeType(&dt, OP_CHANGE_INT32, OP_PUSH_PRE_CHANGE_INT32, change);
-    } else if(dtIsInt64(dt)) {
-        cChangeType(&dt, OP_CHANGE_INT64, OP_PUSH_PRE_CHANGE_INT64, change);
+    if(dtIsInt(dt)) {
+        cChangeType(&dt, OP_CHANGE_INT, OP_PUSH_PRE_CHANGE_INT, change);
     } else {
-        cError("%s needs an int or long not %s", name, cGetName(dt));
+        cError("%s needs an int not %s", name, cGetName(dt));
     }
     return dt;
 }
 
 static DataType cInvertSign(DataType dt) {
-    if(dtIsInt32(dt)) {
-        cAddOperation(OP_INVERT_SIGN_INT32);
-    } else if(dtIsInt64(dt)) {
-        cAddOperation(OP_INVERT_SIGN_INT64);
+    if(dtIsInt(dt)) {
+        cAddOperation(OP_INVERT_SIGN_INT);
     } else if(dtIsFloat(dt)) {
         cAddOperation(OP_INVERT_SIGN_FLOAT);
     } else {
@@ -519,12 +502,9 @@ static DataType cInvertSign(DataType dt) {
     return dt;
 }
 
-static DataType cCast(DataType in, DataType a, Operation aOp, DataType b,
-                      Operation bOp, DataType out) {
+static DataType cCast(DataType in, DataType a, Operation aOp, DataType out) {
     if(dtCompare(in, a)) {
         cAddOperation(aOp);
-    } else if(dtCompare(in, b)) {
-        cAddOperation(bOp);
     } else {
         cError("cannot cast %s to %s", cGetName(in), cGetName(out));
     }
@@ -532,36 +512,16 @@ static DataType cCast(DataType in, DataType a, Operation aOp, DataType b,
 }
 
 static DataType cUnaryNot(DataType dt) {
-    cExpectType(dt, dtBool(), "!");
+    cExpectType(dt, dtInt(), "!");
     cAddOperation(OP_NOT);
     return dt;
 }
 
 static DataType cUnaryBitNot(DataType dt) {
-    if(dtIsInt32(dt)) {
-        cAddOperation(OP_BIT_NOT_INT32);
-    } else if(dtIsInt64(dt)) {
-        cAddOperation(OP_BIT_NOT_INT64);
+    if(dtIsInt(dt)) {
+        cAddOperation(OP_BIT_NOT_INT);
     } else {
-        cError("~ needs an int or long not %s", cGetName(dt));
-    }
-    return dt;
-}
-
-static DataType cUnaryDereference(DataType dt) {
-    cRemoveReference(&dt, "&");
-    return cDereference(dt);
-}
-
-static DataType cUnaryReference(DataType dt) {
-    if(!dtIsPointer(dt)) {
-        cError("* expects a pointer");
-    }
-    dt = dtReference(dt);
-    if(!dtIsPointer(dt) && !dtIsVariable(dt)) {
-        dt = dtToVariable(dt);
-    } else {
-        cAddOperation(OP_REFERENCE);
+        cError("~ needs an int not %s", cGetName(dt));
     }
     return dt;
 }
@@ -570,16 +530,11 @@ static DataType cPreUnary() {
     int marker = tGetMarker();
     if(cConsumeTokenIf(T_OPEN_BRACKET)) {
         if(cConsumeTokenIf(T_FLOAT) && cConsumeTokenIf(T_CLOSE_BRACKET)) {
-            return cCast(cUnpack(cPreUnary()), dtInt32(), OP_INT32_TO_FLOAT,
-                         dtInt64(), OP_INT64_TO_FLOAT, dtFloat());
-        } else if(cConsumeTokenIf(T_INT32) &&
-                  cConsumeTokenIf(T_CLOSE_BRACKET)) {
-            return cCast(cUnpack(cPreUnary()), dtFloat(), OP_FLOAT_TO_INT32,
-                         dtInt64(), OP_INT64_TO_INT32, dtInt32());
-        } else if(cConsumeTokenIf(T_INT64) &&
-                  cConsumeTokenIf(T_CLOSE_BRACKET)) {
-            return cCast(cUnpack(cPreUnary()), dtInt32(), OP_INT32_TO_INT64,
-                         dtFloat(), OP_FLOAT_TO_INT64, dtInt64());
+            return cCast(cUnpack(cPreUnary()), dtInt(), OP_INT_TO_FLOAT,
+                         dtFloat());
+        } else if(cConsumeTokenIf(T_INT) && cConsumeTokenIf(T_CLOSE_BRACKET)) {
+            return cCast(cUnpack(cPreUnary()), dtFloat(), OP_FLOAT_TO_INT,
+                         dtInt());
         }
     }
     tReset(marker);
@@ -593,10 +548,6 @@ static DataType cPreUnary() {
         return cUnaryNot(cPreUnary());
     } else if(cConsumeTokenIf(T_BIT_NOT)) {
         return cUnaryBitNot(cPreUnary());
-    } else if(cConsumeTokenIf(T_BIT_AND)) {
-        return cUnaryDereference(cPreUnary());
-    } else if(cConsumeTokenIf(T_MUL)) {
-        return cUnaryReference(cPreUnary());
     }
     return cAccess();
 }
@@ -604,19 +555,13 @@ static DataType cPreUnary() {
 static void cAddTypeOperation(DataType* a, Parser bf, const TypedOp* op) {
     *a = cUnpack(*a);
     DataType b = cUnpack(bf());
-    a->constant = 0;
-    b.constant = 0;
-    if(!dtNullCompare(*a, b)) {
+    if(!dtCompare(*a, b)) {
         cInvalidOperation(*a, b, op->name);
-    } else if(dtIsInt32(*a) && op->intOp != OP_NOTHING) {
+    } else if(dtIsInt(*a) && op->intOp != OP_NOTHING) {
         cAddOperation(op->intOp);
-    } else if(dtIsInt64(*a) && op->longOp != OP_NOTHING) {
-        cAddOperation(op->longOp);
     } else if(dtIsFloat(*a) && op->floatOp != OP_NOTHING) {
         cAddOperation(op->floatOp);
-    } else if(dtIsBool(*a) && op->boolOp != OP_NOTHING) {
-        cAddOperation(op->boolOp);
-    } else if(dtIsPointer(*a) && op->pointerOp != OP_NOTHING) {
+    } else if(dtIsArray(*a) && op->pointerOp != OP_NOTHING) {
         cAddOperation(op->pointerOp);
     } else {
         cInvalidOperation(*a, b, op->name);
@@ -669,16 +614,16 @@ static DataType cComparison() {
     while(true) {
         if(cConsumeTokenIf(T_LESS)) {
             cAddTypeOperation(&a, cShift, &TYPED_LESS);
-            a = dtBool();
+            a = dtInt();
         } else if(cConsumeTokenIf(T_LESS_EQUAL)) {
             cAddTypeOperation(&a, cShift, &TYPED_LESS_EQUAL);
-            a = dtBool();
+            a = dtInt();
         } else if(cConsumeTokenIf(T_GREATER)) {
             cAddTypeOperation(&a, cShift, &TYPED_GREATER);
-            a = dtBool();
+            a = dtInt();
         } else if(cConsumeTokenIf(T_GREATER_EQUAL)) {
             cAddTypeOperation(&a, cShift, &TYPED_GREATER_EQUAL);
-            a = dtBool();
+            a = dtInt();
         } else {
             return a;
         }
@@ -690,10 +635,10 @@ static DataType cEqual() {
     while(true) {
         if(cConsumeTokenIf(T_EQUAL)) {
             cAddTypeOperation(&a, cComparison, &TYPED_EQUAL);
-            a = dtBool();
+            a = dtInt();
         } else if(cConsumeTokenIf(T_NOT_EQUAL)) {
             cAddTypeOperation(&a, cComparison, &TYPED_NOT_EQUAL);
-            a = dtBool();
+            a = dtInt();
         } else {
             return a;
         }
@@ -723,11 +668,10 @@ static DataType cBitOr() {
 static DataType cLogical(Parser f, Token t, Operation jump, Operation op) {
     DataType a = f();
     while(cConsumeTokenIf(t)) {
-        a = cUnpack(a);
         cAddOperation(jump);
         int32 p = cReserveInt32();
-        DataType b = cUnpack(f());
-        if(!dtIsBool(a) || !dtIsBool(b)) {
+        DataType b = f();
+        if(!dtIsInt(a) || !dtIsInt(b)) {
             cInvalidOperation(a, b, tGetName(t));
         }
         cAddOperation(op);
@@ -780,18 +724,13 @@ static void cReturn() {
         return;
     }
     DataType dt = cUnpackedExpression();
-    if(!dtNullCompare(returnType, dt) &&
-       !dtNullCompare(returnType, dtConst(dt))) {
+    if(!dtCompare(returnType, dt)) {
         cError("wrong return type, should be %s", cGetName(returnType));
-    } else if(dtIsInt32(dt)) {
-        cAddReturn(OP_RETURN_INT32);
-    } else if(dtIsInt64(dt)) {
-        cAddReturn(OP_RETURN_INT64);
-    } else if(dtIsBool(dt)) {
-        cAddReturn(OP_RETURN_BOOL);
+    } else if(dtIsInt(dt)) {
+        cAddReturn(OP_RETURN_INT);
     } else if(dtIsFloat(dt)) {
         cAddReturn(OP_RETURN_FLOAT);
-    } else if(dtIsPointer(dt) || dtIsNull(dt)) {
+    } else if(dtIsArray(dt)) {
         cAddReturn(OP_RETURN_POINTER);
     } else {
         cError("cannot return %s", cGetName(dt));
@@ -802,7 +741,7 @@ static void cReturn() {
 
 static void cIf() {
     cConsumeToken(T_OPEN_BRACKET);
-    cExpectType(cUnpackedExpression(), dtBool(), "if");
+    cExpectType(cExpression(), dtInt(), "if");
     cConsumeToken(T_CLOSE_BRACKET);
     cAddOperation(OP_IF_GOTO);
     int32 ifP = cReserveInt32();
@@ -833,7 +772,7 @@ static void cConsumeBreaks(int start, int address) {
 static void cWhile() {
     int start = code->length;
     cConsumeToken(T_OPEN_BRACKET);
-    cExpectType(cUnpackedExpression(), dtBool(), "while");
+    cExpectType(cExpression(), dtInt(), "while");
     cConsumeToken(T_CLOSE_BRACKET);
     cAddOperation(OP_IF_GOTO);
     int32 ifP = cReserveInt32();
@@ -850,19 +789,8 @@ static void cWhile() {
     cConsumeBreaks(breakStart, code->length);
 }
 
-static void cDelete() {
-    DataType pointer = cUnpackedExpression();
-    if(!dtIsPointer(pointer) || pointer.constant) {
-        cError("delete expects a non const pointer");
-    }
-    cAddOperation(OP_DELETE);
-}
-
 static void cOperationSet(DataType left, const TypedOp* op) {
     cAddOperation(OP_DUPLICATE_REFERENCE);
-    if(left.constant) {
-        cError("cannot use %s= on const reference", op->name);
-    }
     cLoadRef(left);
     cAddTypeOperation(&left, cUnpackedExpression, op);
     cStore(left, left, "=");
@@ -899,19 +827,16 @@ static void cDeclareSet(Variables* vs, DataType dt, const char* var,
         cDeclared(var);
     }
     Variable* v = vsAdd(vs, var, dt, &structs);
-    if(dt.type != DT_STRUCT || dtIsPointer(dt)) {
+    if(dt.type != DT_STRUCT || dtIsArray(dt)) {
         cConsumeToken(T_SET);
         cAddInt32Operation(op, v->address);
         DataType right = cUnpackedExpression();
-        if(!right.constant) {
-            dt.constant = 0;
-        }
         cStore(dt, right, "=");
     }
 }
 
 static bool cDeclaration(Token t) {
-    DataType dt = cReadType(t, false);
+    DataType dt = cReadExtendedType(t, false);
     if(dtIsVoid(dt)) {
         return false;
     }
@@ -927,10 +852,8 @@ static void cLineExpression() {
     if(cDeclaration(t)) {
         return;
     }
-    switch(t) {
-        case T_DELETE: cDelete(); break;
-        default: tReset(marker); cSetVariable();
-    }
+    tReset(marker);
+    cSetVariable();
 }
 
 static void cFor() {
@@ -941,7 +864,7 @@ static void cFor() {
     cLineExpression();
     cConsumeToken(T_SEMICOLON);
     int startCheck = code->length;
-    cExpectType(cUnpackedExpression(), dtBool(), "for");
+    cExpectType(cExpression(), dtInt(), "for");
     cConsumeToken(T_SEMICOLON);
     cAddOperation(OP_IF_GOTO);
     int32 end = cReserveInt32();
@@ -1006,6 +929,9 @@ static void cLine() {
 }
 
 static void cBuildFunction(Function* f, DataType rType, const char* name) {
+    if(rType.type == DT_STRUCT && rType.array == 0) {
+        cError("structs cannot be returned");
+    }
     fInit(f, name, line);
     f->returnType = rType;
     vsReset(&vars);
@@ -1014,12 +940,15 @@ static void cBuildFunction(Function* f, DataType rType, const char* name) {
         return;
     }
     while(true) {
-        DataType dt = cReadType(cReadTokenAndLine(), true);
+        DataType dt = cReadExtendedType(cReadTokenAndLine(), true);
         cConsumeToken(T_LITERAL);
         const char* name = cReadString();
         if(vsInScope(&vars, name)) {
             cDeclared(name);
         }
+        if(dt.type == DT_STRUCT) {
+            dt = dtToPointer(dt);
+        }
         vsAdd(&vars, name, dt, &structs);
         if(fAddArgument(f, dt, &structs)) {
             cTooMuchArguments();
@@ -1065,7 +994,7 @@ static void cInnerFunction(Function* f) {
 static void cFunction(DataType rType, const char* name) {
     Function f;
     cBuildFunction(&f, rType, name);
-    Function* found = fsSearch(&functions, &f, true);
+    Function* found = fsSearch(&functions, &f);
     if(cConsumeTokenIf(T_SEMICOLON)) {
         cAddFunction(found, &f);
         return;
@@ -1090,7 +1019,7 @@ static void cStruct() {
     DataType self = dtStruct(st);
     cConsumeToken(T_OPEN_CURVED_BRACKET);
     while(!cConsumeTokenIf(T_CLOSE_CURVED_BRACKET)) {
-        DataType dt = cReadType(cReadTokenAndLine(), true);
+        DataType dt = cReadExtendedType(cReadTokenAndLine(), true);
         if(dtCompare(dt, self)) {
             cError("struct %s contains itself", name);
         }
@@ -1108,7 +1037,7 @@ static void cGlobalScope(Token t) {
     }
     DataType dt = dtVoid();
     if(t != T_VOID) {
-        dt = cReadType(t, true);
+        dt = cReadExtendedType(t, true);
     }
     cConsumeToken(T_LITERAL);
     const char* name = cReadString();
@@ -1123,9 +1052,9 @@ static void cGlobalScope(Token t) {
 static void cCallMain() {
     Function f;
     fInit(&f, "main", line);
-    Function* found = fsSearch(&functions, &f, true);
+    Function* found = fsSearch(&functions, &f);
     if(found != NULL && dtIsVoid(found->returnType)) {
-        cAddInt32Operation(OP_PUSH_INT32, 0);
+        cAddInt32Operation(OP_PUSH_INT, 0);
         cAddInt32Operation(OP_GOSUB, found->address);
         cAddInt32(found->size);
     }
@@ -1149,26 +1078,17 @@ static void cForEachLine() {
 static void cLinkQueuedFunctions() {
     for(int i = 0; i < functionQueue.entries; i++) {
         Function* f = functionQueue.data + i;
-        Function* found = fsSearch(&functions, f, false);
+        Function* found = fsSearch(&functions, f);
         if(found == NULL || found->address == -1) {
             line = f->line;
-            cError("unknown function");
+            cUnknownFunction(f);
         }
         cSetInt32(f->address, found->address);
     }
-}*/
-
-static void cScanForFunctions() {
-    /*while(true) {
-        Token t = cReadTokenAndLine();
-        if(t == T_END) {
-            break;
-        }
-    }*/
 }
 
 static void cAllocAndCompile() {
-    /*forWhileStack = 0;
+    forWhileStack = 0;
     breakIndex = 0;
     returnType = dtVoid();
     onLine = false;
@@ -1176,17 +1096,16 @@ static void cAllocAndCompile() {
     vsInit(&globalVars);
     fsInit(&functions);
     fsInit(&functionQueue);
-    stsInit(&structs);*/
+    stsInit(&structs);
     if(!setjmp(errorJump)) {
-        cScanForFunctions();
-        // cForEachLine();
-        // cLinkQueuedFunctions();
+        cForEachLine();
+        cLinkQueuedFunctions();
     }
-    /*stsDelete(&structs);
+    stsDelete(&structs);
     fsDelete(&functionQueue);
     fsDelete(&functions);
     vsDelete(&globalVars);
-    vsDelete(&vars);*/
+    vsDelete(&vars);
 }
 
 ByteCode* cCompile() {

+ 41 - 97
DataType.c

@@ -23,57 +23,46 @@ static void dtAppend(const char* s) {
     typeName[typeNameSwap][typeNameIndex] = '\0';
 }
 
-const char* dtGetName(Structs* sts, DataType dt) {
+const char* dtGetName(const Structs* sts, DataType dt) {
     typeNameSwap = !typeNameSwap;
     typeNameIndex = 0;
-    if(dt.constant) {
-        dtAppend("const ");
-    }
     switch(dt.type) {
-        case DT_INT32: dtAppend("int"); break;
-        case DT_INT64: dtAppend("long"); break;
+        case DT_INT: dtAppend("int"); break;
         case DT_FLOAT: dtAppend("float"); break;
-        case DT_BOOL: dtAppend("bool"); break;
-        case DT_NULL: dtAppend("null"); break;
         case DT_STRUCT: dtAppend(dtGetStruct(sts, dt)->name); break;
         case DT_VOID: dtAppend("void"); break;
         default: dtAppend("unknown");
     }
-    for(unsigned int i = 0; i < dt.pointers; i++) {
+    if(dt.array != 0) {
+        dtAppend("[]");
+    }
+    if(dt.pointer != 0) {
         dtAppend("*");
     }
     return typeName[typeNameSwap];
 }
 
-int dtGetSize(DataType dt, Structs* sts) {
-    if(dt.pointers > 0 || dtIsNull(dt)) {
-        return sizeof(Pointer);
+int dtGetSize(DataType dt, const Structs* sts) {
+    if(dt.pointer != 0) {
+        return 1;
     }
     switch(dt.type) {
-        case DT_INT32: return sizeof(int32);
-        case DT_INT64: return sizeof(int64);
-        case DT_FLOAT: return sizeof(float);
-        case DT_BOOL: return sizeof(bool);
-        case DT_STRUCT:
-            {
-                int size = 0;
-                Struct* st = dtGetStruct(sts, dt);
-                for(int i = 0; i < st->amount; i++) {
-                    size += dtGetSize(st->vars[i].type, sts);
-                }
-                return size;
+        case DT_INT: return 1;
+        case DT_FLOAT: return 1;
+        case DT_STRUCT: {
+            int size = 0;
+            Struct* st = dtGetStruct(sts, dt);
+            for(int i = 0; i < st->amount; i++) {
+                size += dtGetSize(st->vars[i].type, sts);
             }
+            return size;
+        }
         default: return 0;
     }
 }
 
-DataType dtInt32() {
-    DataType dt = {DT_INT32, 0, 0, 0};
-    return dt;
-}
-
-DataType dtInt64() {
-    DataType dt = {DT_INT64, 0, 0, 0};
+DataType dtInt() {
+    DataType dt = {DT_INT, 0, 0, 0};
     return dt;
 }
 
@@ -82,93 +71,66 @@ DataType dtFloat() {
     return dt;
 }
 
-DataType dtBool() {
-    DataType dt = {DT_BOOL, 0, 0, 0};
+DataType dtVoid() {
+    DataType dt = {DT_VOID, 0, 0, 0};
     return dt;
 }
 
-DataType dtNull() {
-    DataType dt = {DT_NULL, 0, 0, 0};
+DataType dtStruct(const Struct* st) {
+    DataType dt = {DT_STRUCT, 0, 0, st->id};
     return dt;
 }
 
 DataType dtText() {
-    DataType dt = {DT_INT32, 1, 0, 0};
+    DataType dt = {DT_INT, 0, 1, 0};
     return dt;
 }
 
-DataType dtVoid() {
-    DataType dt = {DT_VOID, 0, 0, 0};
+DataType dtToArray(DataType dt) {
+    dt.array = 1;
     return dt;
 }
 
-DataType dtStruct(Struct* st) {
-    DataType dt = {DT_STRUCT, 0, 0, st->id};
+DataType dtRemoveArray(DataType dt) {
+    dt.array = 0;
     return dt;
 }
 
-DataType dtReference(DataType dt) {
-    dt.pointers--;
+DataType dtToPointer(DataType dt) {
+    dt.pointer = 1;
     return dt;
 }
 
-bool dtDereference(DataType* dt) {
-    if(dt->pointers == 15) {
+bool dtRemovePointer(DataType* dt) {
+    if(dt->pointer != 0) {
+        dt->pointer = 0;
         return true;
     }
-    dt->pointers++;
     return false;
 }
 
-static bool dtInternCompare(DataType a, DataType b) {
-    return a.pointers == b.pointers && a.structId == b.structId &&
-           a.type == b.type && a.constant == b.constant;
-}
-
 bool dtCompare(DataType a, DataType b) {
-    return dtInternCompare(a, b);
-}
-
-bool dtNullCompare(DataType a, DataType bOrNull) {
-    return dtInternCompare(a, bOrNull) ||
-           (dtIsPointer(a) && dtIsNull(bOrNull) &&
-            a.constant == bOrNull.constant);
-}
-
-bool dtIsInt32(DataType dt) {
-    return dtCompare(dt, dtInt32());
+    return a.array == b.array && a.structId == b.structId && a.type == b.type &&
+           a.pointer == b.pointer;
 }
 
-bool dtIsInt64(DataType dt) {
-    return dtCompare(dt, dtInt64());
+bool dtIsInt(DataType dt) {
+    return dtCompare(dt, dtInt());
 }
 
 bool dtIsFloat(DataType dt) {
     return dtCompare(dt, dtFloat());
 }
 
-bool dtIsBool(DataType dt) {
-    return dtCompare(dt, dtBool());
-}
-
-bool dtIsNull(DataType dt) {
-    dt.constant = 0;
-    return dtCompare(dt, dtNull());
-}
-
 bool dtIsVoid(DataType dt) {
     return dtCompare(dt, dtVoid());
 }
 
-bool dtIsPointer(DataType dt) {
-    return dt.pointers > 0;
+bool dtIsArray(DataType dt) {
+    return dt.array != 0;
 }
 
-bool dtIsVariable(DataType dt) {
-    return dt.type & 8;
-}
-
-Struct* dtGetStruct(Structs* sts, DataType dt) {
+Struct* dtGetStruct(const Structs* sts, DataType dt) {
     if(dt.type != DT_STRUCT) {
         return NULL;
     }
@@ -181,24 +143,6 @@ Struct* dtGetStruct(Structs* sts, DataType dt) {
     return sts->data + (dt.structId >> 1);
 }
 
-DataType dtToVariable(DataType dt) {
-    dt.type |= 8;
-    return dt;
-}
-
-bool dtRemoveVariable(DataType* dt) {
-    if(dtIsVariable(*dt)) {
-        dt->type &= 7;
-        return true;
-    }
-    return false;
-}
-
-DataType dtConst(DataType dt) {
-    dt.constant = 1;
-    return dt;
-}
-
 void stAddVariable(Struct* st, const char* name, DataType type) {
     int index = st->amount;
     st->amount++;

+ 35 - 36
DataType.h

@@ -9,19 +9,31 @@ extern "C" {
 
 #include "Types.h"
 
-#define DT_INT32 0
-#define DT_INT64 1
-#define DT_FLOAT 2
-#define DT_BOOL 3
-#define DT_NULL 4
-#define DT_VOID 5
-#define DT_STRUCT 6
+#define VT_NOT_SET 0
+#define VT_INT 1
+#define VT_FLOAT 2
+#define VT_POINTER 3
+#define VT_ARRAY 4
 
 typedef struct {
     unsigned int type : 4;
-    unsigned int pointers : 4;
-    unsigned int constant : 1;
-    unsigned int structId : 23;
+    unsigned int offset : 28;
+    union {
+        int intValue;
+        float floatValue;
+    } data;
+} Value;
+
+#define DT_INT 0
+#define DT_FLOAT 1
+#define DT_VOID 2
+#define DT_STRUCT 3
+
+typedef struct {
+    uint8 type : 7;
+    uint8 pointer : 1;
+    uint8 array;
+    uint16 structId;
 } DataType;
 
 typedef struct {
@@ -42,41 +54,28 @@ typedef struct {
     Struct* data;
 } Structs;
 
-typedef struct {
-    int32 array;
-    int32 offset;
-} Pointer;
-
-int dtGetSize(DataType dt, Structs* sts);
+int dtGetSize(DataType dt, const Structs* sts);
 
-DataType dtInt32();
-DataType dtInt64();
+DataType dtInt();
 DataType dtFloat();
-DataType dtBool();
-DataType dtNull();
-DataType dtText();
 DataType dtVoid();
-DataType dtStruct(Struct* st);
+DataType dtStruct(const Struct* st);
+DataType dtText();
+
+DataType dtToArray(DataType dt);
+DataType dtRemoveArray(DataType dt);
+Struct* dtGetStruct(const Structs* sts, DataType dt);
 
-DataType dtReference(DataType dt);
-bool dtDereference(DataType* dt);
-Struct* dtGetStruct(Structs* sts, DataType dt);
-DataType dtToVariable(DataType dt);
-bool dtRemoveVariable(DataType* dt);
-DataType dtConst(DataType dt);
+DataType dtToPointer(DataType dt);
+bool dtRemovePointer(DataType* dt);
 
 bool dtCompare(DataType a, DataType b);
-bool dtNullCompare(DataType a, DataType bOrNull);
-bool dtIsInt32(DataType dt);
-bool dtIsInt64(DataType dt);
+bool dtIsInt(DataType dt);
 bool dtIsFloat(DataType dt);
-bool dtIsBool(DataType dt);
-bool dtIsNull(DataType dt);
 bool dtIsVoid(DataType dt);
-bool dtIsPointer(DataType dt);
-bool dtIsVariable(DataType dt);
+bool dtIsArray(DataType dt);
 
-const char* dtGetName(Structs* sts, DataType dt);
+const char* dtGetName(const Structs* sts, DataType dt);
 
 void stAddVariable(Struct* st, const char* name, DataType type);
 

+ 6 - 2
Error.c

@@ -4,13 +4,17 @@
 #include "Error.h"
 
 void eInitError(Error* e, int line, const char* format, ...) {
-    e->line = line;
     va_list args;
     va_start(args, format);
-    vsnprintf(e->message, sizeof(e->message), format, args);
+    eInitErrorV(e, line, format, args);
     va_end(args);
 }
 
+void eInitErrorV(Error* e, int line, const char* format, va_list ap) {
+    e->line = line;
+    vsnprintf(e->message, sizeof(e->message), format, ap);
+}
+
 void eInitSuccess(Error* e) {
     e->line = -1;
     e->message[0] = '\0';

+ 2 - 0
Error.h

@@ -5,6 +5,7 @@
 extern "C" {
 #endif
 
+#include <stdarg.h>
 #include <stdbool.h>
 
 typedef struct Error {
@@ -13,6 +14,7 @@ typedef struct Error {
 } Error;
 
 void eInitError(Error* e, int line, const char* format, ...);
+void eInitErrorV(Error* e, int line, const char* format, va_list ap);
 void eInitSuccess(Error* e);
 bool eHasError(const Error* e);
 

+ 21 - 34
Test.c

@@ -36,45 +36,28 @@ static void tsPrintToBuffer(const char* format, ...) {
 static void tsInt32Printer(Script* sc) {
     int32 i;
     if(sPopInt32(sc, &i)) {
-        tsPrintToBuffer("%d\n", i);
-    }
-}
-
-static void tsInt64Printer(Script* sc) {
-    int64 i;
-    if(sPopInt64(sc, &i)) {
-        tsPrintToBuffer("%ld\n", i);
+        return;
     }
+    tsPrintToBuffer("%d\n", i);
 }
 
 static void tsFloatPrinter(Script* sc) {
     float f;
     if(sPopFloat(sc, &f)) {
-        tsPrintToBuffer("%.2f\n", f);
-    }
-}
-
-static void tsBoolPrinter(Script* sc) {
-    bool b;
-    if(sPopBool(sc, &b)) {
-        tsPrintToBuffer(b ? "true\n" : "false\n");
+        return;
     }
+    tsPrintToBuffer("%.2f\n", f);
 }
 
 static void tsTextPrinter(Script* sc) {
-    Pointer p;
-    if(sPopPointer(sc, &p)) {
-        int32 length;
-        if(sGetPointerLength(sc, &p, &length)) {
-            return;
-        }
-        for(int i = 0; i < length; i++) {
-            int32* ip = sCheckAddress(sc, &p, sizeof(int32));
-            tsPrintToBuffer("%c", (char)*ip);
-            p.offset += sizeof(int32);
-        }
-        tsPrintToBuffer("\n");
+    SnuviArray* array = sGetArray(sc);
+    if(array == NULL) {
+        return;
     }
+    for(int i = 0; i < array->realLength; i++) {
+        tsPrintToBuffer("%c", (char)array->data[i].data.intValue);
+    }
+    tsPrintToBuffer("\n");
 }
 
 static void tsAppend(const char* s) {
@@ -101,7 +84,7 @@ static bool tsCompareResults(FILE* file) {
         char a = fgetc(file);
         char b = testBuffer[i];
         if(a != b) {
-            printf("error in '%s': expected %c, got:\n%s", path, a,
+            printf("error in '%s': expected '%c', got:\n%s", path, a,
                    testBuffer + i);
             return true;
         }
@@ -117,6 +100,12 @@ static bool tsCompareResults(FILE* file) {
 static void tsCheckScript(Script* sc) {
     testBufferIndex = 0;
     sRun(sc);
+    if(sc->error[0] != '\0') {
+        printf("script '%s' had error on line %d: %s\n", path, sc->line,
+               sc->error);
+        btPrint(sc->code);
+        return;
+    }
 
     tsAppend(".out");
     FILE* file = fopen(path, "r");
@@ -190,11 +179,9 @@ static void tsAddPrinter(DataType in, ScriptFunction sf) {
 }
 
 void tsStart(const char* path) {
-    tsAddPrinter(dtConst(dtInt32()), tsInt32Printer);
-    tsAddPrinter(dtConst(dtInt64()), tsInt64Printer);
-    tsAddPrinter(dtConst(dtFloat()), tsFloatPrinter);
-    tsAddPrinter(dtConst(dtBool()), tsBoolPrinter);
-    tsAddPrinter(dtConst(dtText()), tsTextPrinter);
+    tsAddPrinter(dtInt(), tsInt32Printer);
+    tsAddPrinter(dtFloat(), tsFloatPrinter);
+    tsAddPrinter(dtText(), tsTextPrinter);
 
     doneTests = 0;
     allTests = 0;

+ 5 - 0
Types.h

@@ -12,6 +12,11 @@ typedef int16_t int16;
 typedef int32_t int32;
 typedef int64_t int64;
 
+typedef uint8_t uint8;
+typedef uint16_t uint16;
+typedef uint32_t uint32;
+typedef uint64_t uint64;
+
 #ifdef __cplusplus
 }
 #endif

+ 3 - 3
libraries/Math.c

@@ -6,7 +6,7 @@
 #define FLOAT_FUNCTION(Name, Function)                                         \
     static void l##Name(Script* sc) {                                          \
         float f;                                                               \
-        if(sPopFloat(sc, &f)) {                                                \
+        if(!sPopFloat(sc, &f)) {                                               \
             sPushFloat(sc, Function(f));                                       \
         }                                                                      \
     }
@@ -24,12 +24,12 @@ FLOAT_FUNCTION(SquareRoot, sqrtf)
 static void lPow(Script* sc) {
     float x;
     float y;
-    if(sPopFloat(sc, &x) && sPopFloat(sc, &y)) {
+    if(!sPopFloat(sc, &x) && !sPopFloat(sc, &y)) {
         sPushFloat(sc, powf(y, x));
     }
 }
 
-void lAddFloatFunction(const char* name, ScriptFunction sf) {
+static void lAddFloatFunction(const char* name, ScriptFunction sf) {
     Function f;
     gfInit(&f, name, dtFloat(), sf);
     gfAddArgument(&f, dtFloat());

+ 59 - 56
libraries/Time.c

@@ -12,7 +12,12 @@ static void lGetMillis(Script* sc) {
         sError(sc, "cannot get clock time: %s", strerror(errno));
         return;
     }
-    sPushInt64(sc, time.tv_nsec / 1000000L + time.tv_sec * 1000L);
+    Value* v = sPopStructPointer(sc, VT_INT);
+    if(v == NULL) {
+        return;
+    }
+    v[0].data.intValue = time.tv_sec;
+    v[1].data.intValue = (time.tv_nsec / 1000000) * 1000000;
 }
 
 static void lGetNanos(Script* sc) {
@@ -21,97 +26,95 @@ static void lGetNanos(Script* sc) {
         sError(sc, "cannot get clock time: %s", strerror(errno));
         return;
     }
-    sPushInt64(sc, time.tv_nsec + time.tv_sec * 1000000000L);
+    Value* v = sPopStructPointer(sc, VT_INT);
+    if(v == NULL) {
+        return;
+    }
+    v[0].data.intValue = time.tv_sec;
+    v[1].data.intValue = time.tv_nsec;
 }
 
-typedef struct {
-    int32 year;
-    int32 month;
-    int32 day;
-    int32 hours;
-    int32 minutes;
-    int32 seconds;
-    int32 millis;
-    int32 dst;
-} Time;
-
 static void lToTime(Script* sc) {
-    int64 millis;
-    Pointer p;
-    if(!sPopInt64(sc, &millis) || !sPopPointer(sc, &p)) {
-        return;
-    }
-    Time* time = sCheckAddress(sc, &p, sizeof(Time));
-    if(time == NULL) {
+    Value* time = sPopStructPointer(sc, VT_INT);
+    Value* timer = sPopStructPointer(sc, VT_INT);
+    if(time == NULL || timer == NULL) {
         return;
     }
+    long millis =
+        timer[0].data.intValue * 1000l + timer[1].data.intValue / 1000000l;
     time_t t = millis / 1000l;
     struct tm* local = localtime(&t);
     if(local == NULL) {
         sError(sc, "cannot get local time: %s", strerror(errno));
         return;
     }
-    time->year = local->tm_year + 1900;
-    time->month = local->tm_mon;
-    time->day = local->tm_mday;
-    time->hours = local->tm_hour;
-    time->minutes = local->tm_min;
-    time->seconds = local->tm_sec;
-    time->millis = millis % 1000;
-    time->dst = local->tm_isdst;
+    time[0].data.intValue = local->tm_year + 1900;
+    time[1].data.intValue = local->tm_mon;
+    time[2].data.intValue = local->tm_mday;
+    time[3].data.intValue = local->tm_hour;
+    time[4].data.intValue = local->tm_min;
+    time[5].data.intValue = local->tm_sec;
+    time[6].data.intValue = millis % 1000;
+    time[7].data.intValue = local->tm_isdst;
 }
 
 static void lToMillis(Script* sc) {
-    Pointer p;
-    if(!sPopPointer(sc, &p)) {
-        return;
-    }
-    Time* time = sCheckAddress(sc, &p, sizeof(Time));
-    if(time == NULL) {
+    Value* timer = sPopStructPointer(sc, VT_INT);
+    Value* time = sPopStructPointer(sc, VT_INT);
+    if(time == NULL || timer == NULL) {
         return;
     }
     struct tm local;
-    local.tm_year = time->year - 1900;
-    local.tm_mon = time->month;
-    local.tm_mday = time->day;
-    local.tm_hour = time->hours;
-    local.tm_min = time->minutes;
-    local.tm_sec = time->seconds;
-    local.tm_isdst = time->dst;
+    local.tm_year = time[0].data.intValue - 1900;
+    local.tm_mon = time[1].data.intValue;
+    local.tm_mday = time[2].data.intValue;
+    local.tm_hour = time[3].data.intValue;
+    local.tm_min = time[4].data.intValue;
+    local.tm_sec = time[5].data.intValue;
+    local.tm_isdst = time[7].data.intValue;
     int64 seconds = mktime(&local);
     if(seconds == -1) {
         sError(sc, "cannot convert time: %s", strerror(errno));
         return;
     }
-    sPushInt64(sc, seconds * 1000L + time->millis);
+
+    timer[0].data.intValue = seconds;
+    timer[1].data.intValue = time[6].data.intValue * 1000000;
 }
 
 void lTimeRegister() {
+    Struct* timer = gstsAdd("Timer");
+    stAddVariable(timer, "seconds", dtInt());
+    stAddVariable(timer, "nanos", dtInt());
+    DataType timerType = dtToPointer(dtStruct(timer));
+
     Function f;
-    gfInit(&f, "getMillis", dtInt64(), lGetMillis);
+    gfInit(&f, "getMillis", dtVoid(), lGetMillis);
+    gfAddArgument(&f, timerType);
     gfsAdd(&f);
 
-    gfInit(&f, "getNanos", dtInt64(), lGetNanos);
+    gfInit(&f, "getNanos", dtVoid(), lGetNanos);
+    gfAddArgument(&f, timerType);
     gfsAdd(&f);
 
     Struct* time = gstsAdd("Time");
-    stAddVariable(time, "year", dtInt32());
-    stAddVariable(time, "month", dtInt32());
-    stAddVariable(time, "day", dtInt32());
-    stAddVariable(time, "hours", dtInt32());
-    stAddVariable(time, "minutes", dtInt32());
-    stAddVariable(time, "seconds", dtInt32());
-    stAddVariable(time, "millis", dtInt32());
-    stAddVariable(time, "dst", dtInt32());
-    DataType timeType = dtStruct(time);
-    dtDereference(&timeType);
+    stAddVariable(time, "year", dtInt());
+    stAddVariable(time, "month", dtInt());
+    stAddVariable(time, "day", dtInt());
+    stAddVariable(time, "hours", dtInt());
+    stAddVariable(time, "minutes", dtInt());
+    stAddVariable(time, "seconds", dtInt());
+    stAddVariable(time, "millis", dtInt());
+    stAddVariable(time, "dst", dtInt());
+    DataType timeType = dtToPointer(dtStruct(time));
 
     gfInit(&f, "toTime", dtVoid(), lToTime);
+    gfAddArgument(&f, timerType);
     gfAddArgument(&f, timeType);
-    gfAddArgument(&f, dtInt64());
     gfsAdd(&f);
 
-    gfInit(&f, "toMillis", dtInt64(), lToMillis);
+    gfInit(&f, "toMillis", dtVoid(), lToMillis);
     gfAddArgument(&f, timeType);
+    gfAddArgument(&f, timerType);
     gfsAdd(&f);
 }

+ 0 - 0
tests/pre/include → old_tests/pre/include


+ 0 - 0
tests/pre/include.out → old_tests/pre/include.out


+ 0 - 0
tests/pre/list → old_tests/pre/list


+ 0 - 0
tests/pre/list.out → old_tests/pre/list.out


+ 0 - 0
tests/pre/list_test → old_tests/pre/list_test


+ 0 - 0
tests/pre/list_test.out → old_tests/pre/list_test.out


+ 0 - 0
tests/pre/pre → old_tests/pre/pre


+ 0 - 0
tests/pre/pre.out → old_tests/pre/pre.out


+ 3 - 8
tests/arrays/alloc

@@ -1,10 +1,9 @@
 void main() {
     int start = 0;
-    int* a = new int[4];
-    int** b = &a;
-    int* c = *b;
+    int[] a = new int[4];
+    int[] b = a;
+    int[] c = b;
     test(a == c);
-    test(&start != a);
     
     test(length(a));
     test(length(b));
@@ -19,8 +18,4 @@ void main() {
     test(a[1]);
     test(a[2]);
     test(a[3]); 
-       
-    test(*a);
-    
-    delete a;
 }

+ 2 - 4
tests/arrays/alloc.out

@@ -1,10 +1,8 @@
-true
-true
-4
 1
 4
+4
+4
 50
 60
 70
 80
-50

+ 1 - 1
tests/arrays/and

@@ -1,5 +1,5 @@
 void main() {
-    int* a = new int[1];
+    int[] a = new int[1];
     a[0] = 7;
     a[0] &= 15;
     test(a[0]);

+ 1 - 1
tests/arrays/dec

@@ -1,5 +1,5 @@
 void main() {
-    int* a = new int[1];
+    int[] a = new int[1];
     a[0] = 0;
     a[0]--;
     --a[0];

+ 1 - 1
tests/arrays/inc

@@ -1,5 +1,5 @@
 void main() {
-    int* a = new int[1];
+    int[] a = new int[1];
     a[0] = 0;
     a[0]++;
     ++a[0];

+ 0 - 27
tests/arrays/multi

@@ -1,27 +0,0 @@
-int** multiArray(int width, int height) {
-    int** array = new int*[width]; 
-    for(int x = 0; x < length(array); x++) {
-        array[x] = new int[height];
-        for(int y = 0; y < length(array[x]); y++) {
-            array[x][y] = y + x * height;
-        }   
-    }
-    return array;
-}
-
-void deleteMultiArray(int** array) {
-    for(int x = 0; x < length(array); x++) {
-        delete array[x];
-    }
-    delete array;
-}
-
-void main() {
-    int** array = multiArray(2, 3);
-    for(int x = 0; x < length(array); x++) {
-        for(int y = 0; y < length(array[x]); y++) {
-            test(array[x][y]);
-        }   
-    }
-    deleteMultiArray(array);
-}

+ 0 - 6
tests/arrays/multi.out

@@ -1,6 +0,0 @@
-0
-1
-2
-3
-4
-5

+ 1 - 1
tests/arrays/or

@@ -1,5 +1,5 @@
 void main() {
-    int* a = new int[1];
+    int[] a = new int[1];
     a[0] = 0;
     a[0] |= 2;
     test(a[0]);

+ 1 - 1
tests/arrays/setop

@@ -1,5 +1,5 @@
 void main() {
-    int* a = new int[1];
+    int[] a = new int[1];
 
     a[0] = 5;
     a[0] += 5;

+ 1 - 1
tests/arrays/shift

@@ -1,5 +1,5 @@
 void main() {
-    int* a = new int[1];
+    int[] a = new int[1];
     a[0] = 1;
     a[0] <<= 2;
     a[0] <<= 3;

+ 30 - 0
tests/arrays/struct_array

@@ -0,0 +1,30 @@
+struct A {
+    int a;
+    int b;
+};
+
+void main() {
+    A[] a = new A[5];
+    
+    a[0].a = 1;
+    a[0].b = 2;
+    a[1].a = 3;
+    a[1].b = 4;
+    a[2].a = 5;
+    a[2].b = 6;
+    a[3].a = 7;
+    a[3].b = 8;
+    a[4].a = 9;
+    a[4].b = 10;
+    
+    test(a[0].a);
+    test(a[0].b);
+    test(a[1].a);
+    test(a[1].b);
+    test(a[2].a);
+    test(a[2].b);
+    test(a[3].a);
+    test(a[3].b);
+    test(a[4].a);
+    test(a[4].b);
+}

+ 10 - 0
tests/arrays/struct_array.out

@@ -0,0 +1,10 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10

+ 3 - 21
tests/arrays/types

@@ -3,33 +3,15 @@ struct A {
 };
 
 void main() {
-    int* a = new int[4];
-    float* b = new float[4];
-    bool* c = new bool[4];
-    A* d = new A[4];
-    int** e = new int*[4];
-    float** f = new float*[4];
-    bool** g = new bool*[4];
-    A** h = new A*[4];
+    int[] a = new int[4];
+    float[] b = new float[4];
+    A[] d = new A[4];
     
     a[2] = 243;
     b[2] = 23.5;
-    c[2] = true;
     d[2].a = 64560;
-    e[2] = &a[2];
-    f[2] = &b[2];
-    g[2] = &c[2];
-    h[2] = &d[2];
-    
-    h[2]->a += 2;
-    (*h[2]).a += 2;
     
     test(a[2]);
     test(b[2]);
-    test(c[2]);
     test(d[2].a);
-    test(*e[2]);
-    test(*f[2]);
-    test(*g[2]);
-    test((*h[2]).a);
 }

+ 1 - 6
tests/arrays/types.out

@@ -1,8 +1,3 @@
 243
 23.50
-true
-64564
-243
-23.50
-true
-64564
+64560

+ 1 - 1
tests/arrays/xor

@@ -1,5 +1,5 @@
 void main() {
-    int* a = new int[1];
+    int[] a = new int[1];
     a[0] = 0;
     a[0] ^= 2;
     test(a[0]);

+ 0 - 6
tests/bits/and

@@ -4,10 +4,4 @@ void main() {
     test(a);
     a &= 9;
     test(a);
-    
-    long b = 7L;
-    b = b & 15L;
-    test(b);
-    b &= 9L;
-    test(b);
 }

+ 0 - 2
tests/bits/and.out

@@ -1,4 +1,2 @@
 7
 1
-7
-1

+ 0 - 2
tests/bits/invert

@@ -1,6 +1,4 @@
 void main() {
     test(~0);
     test(~~~(~7));
-    test(~0L);
-    test(~~~(~7L));
 }

+ 0 - 2
tests/bits/invert.out

@@ -1,4 +1,2 @@
 -1
 7
--1
-7

+ 0 - 6
tests/bits/or

@@ -4,10 +4,4 @@ void main() {
     test(a);
     a |= 5;
     test(a);
-    
-    long b = 0L;
-    b = b | 2L;
-    test(b);
-    b |= 5L;
-    test(b);
 }

+ 0 - 2
tests/bits/or.out

@@ -1,4 +1,2 @@
 2
 7
-2
-7

+ 0 - 10
tests/bits/shift

@@ -8,14 +8,4 @@ void main() {
     a = a >> 2;
     a >>= 3;
     test(a);
-    
-    long b = 1L;
-    b = b << 2L;
-    b <<= 3L;
-    test(b);
-
-    b = 100L;
-    b = b >> 2L;
-    b >>= 3L;
-    test(b);
 }

+ 0 - 2
tests/bits/shift.out

@@ -1,4 +1,2 @@
 32
 3
-32
-3

+ 0 - 6
tests/bits/xor

@@ -4,10 +4,4 @@ void main() {
     test(a);
     a ^= 7;
     test(a);
-    
-    long b = 0L;
-    b = b ^ 2L;
-    test(b);
-    b ^= 7L;
-    test(b);
 }

+ 0 - 2
tests/bits/xor.out

@@ -1,4 +1,2 @@
 2
 5
-2
-5

+ 0 - 1
tests/calc/add

@@ -7,5 +7,4 @@ void main() {
     test(4.0 + 1.0);
     test(1.0 + -2.0);
     test(6 + -7 + 8 + -9);
-    test(2L + 3L);
 }

+ 0 - 1
tests/calc/add.out

@@ -6,4 +6,3 @@
 5.00
 -1.00
 -2
-5

+ 0 - 1
tests/calc/div

@@ -11,5 +11,4 @@ void main() {
     test(1.0 / 2.0);
     test(20 * 2 / 3 / 5);
     test(20.0 * 2.0 / 3.0 / 5.0);
-    test(7L / 3L);
 }

+ 0 - 1
tests/calc/div.out

@@ -10,4 +10,3 @@
 0.50
 2
 2.67
-2

+ 0 - 1
tests/calc/mod

@@ -4,5 +4,4 @@ void main() {
     test(5 % 5);
     test(7 % 5);
     test(9 % 5);
-    test(9L % 5L);
 }

+ 0 - 1
tests/calc/mod.out

@@ -3,4 +3,3 @@
 0
 2
 4
-4

+ 0 - 1
tests/calc/mul

@@ -7,5 +7,4 @@ void main() {
     test(((3.0 + 2.0) * (5.0 + 1.0)));
     test(((3.0 + 2.0) * (5.0 + 1.0)));
     test(-3 * -5);
-    test(-3L * -5L);
 }

+ 0 - 1
tests/calc/mul.out

@@ -6,4 +6,3 @@
 30.00
 30.00
 15
-15

+ 0 - 1
tests/calc/sub

@@ -3,5 +3,4 @@ void main() {
     test(2 - 5 + 3 - 6);
     test(2 - (5 + 3) - 6);
     test(-(7 - 8));
-    test(-(7L - 8L));
 }

+ 0 - 1
tests/calc/sub.out

@@ -2,4 +2,3 @@
 -6
 -12
 1
-1

+ 0 - 14
tests/cast/cast_float_long

@@ -1,14 +0,0 @@
-void main() {
-    long l = 3L;
-    test((float)l);
-    test((long)(float)l);
-    test((float)(long)(float)l);
-    
-    float f = 4.2;
-    test((long)f);
-    test((float)(long)f);
-    test((long)(float)(long)f);
-    
-    test((float)6 / 5.0);
-    test(6L / (long)5.0);
-}

+ 0 - 8
tests/cast/cast_float_long.out

@@ -1,8 +0,0 @@
-3.00
-3
-3.00
-4
-4.00
-4
-1.20
-1

+ 0 - 11
tests/cast/cast_int_long

@@ -1,11 +0,0 @@
-void main() {
-    long l = 3L;
-    test((int)l);
-    test((long)(int)l);
-    test((int)(long)(int)l);
-    
-    int i = 4;
-    test((long)i);
-    test((int)(long)i);
-    test((long)(int)(long)i);
-}

+ 0 - 6
tests/cast/cast_int_long.out

@@ -1,6 +0,0 @@
-3
-3
-3
-4
-4
-4

+ 14 - 14
tests/comparison/equal.out

@@ -1,14 +1,14 @@
-false
-false
-true
-false
-false
-false
-false
-true
-false
-false
-true
-false
-false
-true
+0
+0
+1
+0
+0
+0
+0
+1
+0
+0
+1
+0
+0
+1

+ 10 - 10
tests/comparison/greater.out

@@ -1,10 +1,10 @@
-false
-false
-false
-true
-true
-false
-false
-false
-true
-true
+0
+0
+0
+1
+1
+0
+0
+0
+1
+1

+ 10 - 10
tests/comparison/greater_equal.out

@@ -1,10 +1,10 @@
-false
-false
-true
-true
-true
-false
-false
-true
-true
-true
+0
+0
+1
+1
+1
+0
+0
+1
+1
+1

+ 10 - 10
tests/comparison/less.out

@@ -1,10 +1,10 @@
-true
-true
-false
-false
-false
-true
-true
-false
-false
-false
+1
+1
+0
+0
+0
+1
+1
+0
+0
+0

+ 10 - 10
tests/comparison/less_equal.out

@@ -1,10 +1,10 @@
-true
-true
-true
-false
-false
-true
-true
-true
-false
-false
+1
+1
+1
+0
+0
+1
+1
+1
+0
+0

+ 14 - 14
tests/comparison/not_equal.out

@@ -1,14 +1,14 @@
-true
-true
-false
-true
-true
-true
-true
-false
-true
-true
-false
-true
-true
-false
+1
+1
+0
+1
+1
+1
+1
+0
+1
+1
+0
+1
+1
+0

+ 0 - 53
tests/const

@@ -1,53 +0,0 @@
-const int* wusi(int i) {
-    return &i;
-}
-
-const int wusi2(int i) {
-    return i;
-}
-
-struct B {
-    int b;
-};
-
-struct A {
-    int a;
-    B b;
-};
-
-void wusi(const A* a) {
-    //a->a += 3;
-    //a->b.b += 3;
-    test(a->a);
-    test(a->b.b);
-}
-
-void main() {
-    const int i = 3;
-    const int* w = &i;
-    int a = i;
-    a = i;
-    const int* b = nullptr;
-    const int** c = &b;
-    const int* d = *c;
-    b = wusi(3);
-    a = wusi2(3);
-    
-    int* test = new int[5];
-    delete test;
-    
-    //i += 3;
-    
-    int* e = nullptr;
-    b = e;
-    
-    test(i + 1);
-    
-    test(e == d);
-    test(e != d);
-    
-    A s;
-    s.a = 3;
-    s.b.b = 5;
-    wusi(&s);
-}

+ 0 - 5
tests/const.out

@@ -1,5 +0,0 @@
-4
-true
-false
-3
-5

+ 1 - 1
tests/functions/arguments

@@ -13,7 +13,7 @@ void test2(float f) {
     test(f);
 }
 
-void test2(bool b) {
+void test2(int b) {
     test(b);
 }
 

+ 1 - 1
tests/functions/arguments.out

@@ -5,4 +5,4 @@
 2
 3
 5.50
-true
+1

+ 2 - 2
tests/if/and

@@ -1,5 +1,5 @@
-bool test() {
-    test(1);
+int test() {
+    test(2);
     return true;
 }
 

+ 8 - 8
tests/if/and.out

@@ -1,10 +1,10 @@
-false
-false
-false
-true
-false
+0
+0
+0
 1
-false
+0
+2
+0
+2
+2
 1
-1
-true

+ 6 - 6
tests/if/invert.out

@@ -1,6 +1,6 @@
-false
-true
-true
-false
-false
-true
+0
+1
+1
+0
+0
+1

+ 1 - 1
tests/if/or

@@ -1,4 +1,4 @@
-bool test() {
+int test() {
     test(1);
     return true;
 }

+ 7 - 7
tests/if/or.out

@@ -1,9 +1,9 @@
-false
-true
-true
-true
+0
+1
+1
+1
+1
+1
+1
 1
-true
 1
-true
-true

+ 0 - 11
tests/loops/while_post_dec

@@ -9,15 +9,4 @@ void main() {
         test(a);
         a--;
     }
-    
-    long b = 5L;
-    while(b > 0L) {
-        test(b--);
-    }
-
-    b = 5L;
-    while(b > 0L) {
-        test(b);
-        b--;
-    }
 }

+ 0 - 10
tests/loops/while_post_dec.out

@@ -8,13 +8,3 @@
 3
 2
 1
-5
-4
-3
-2
-1
-5
-4
-3
-2
-1

+ 0 - 11
tests/loops/while_post_inc

@@ -9,15 +9,4 @@ void main() {
         test(a);
         a++;
     }
-    
-    long b = 0L;
-    while(b < 5L) {
-        test(b++);
-    }
-
-    b = 0L;
-    while(b < 5L) {
-        test(b);
-        b++;
-    }
 }

+ 0 - 10
tests/loops/while_post_inc.out

@@ -8,13 +8,3 @@
 2
 3
 4
-0
-1
-2
-3
-4
-0
-1
-2
-3
-4

+ 0 - 11
tests/loops/while_pre_dec

@@ -9,15 +9,4 @@ void main() {
         test(a);
         --a;
     }
-    
-    long b = 5L;
-    while(b > 0L) {
-        test(--b);
-    }
-
-    b = 5L;
-    while(b > 0L) {
-        test(b);
-        --b;
-    }
 }

+ 0 - 10
tests/loops/while_pre_dec.out

@@ -8,13 +8,3 @@
 3
 2
 1
-4
-3
-2
-1
-0
-5
-4
-3
-2
-1

+ 0 - 11
tests/loops/while_pre_inc

@@ -9,15 +9,4 @@ void main() {
         test(a);
         ++a;
     }
-    
-    long b = 0L;
-    while(b < 5L) {
-        test(++b);
-    }
-
-    b = 0L;
-    while(b < 5L) {
-        test(b);
-        ++b;
-    }
 }

+ 0 - 10
tests/loops/while_pre_inc.out

@@ -8,13 +8,3 @@
 2
 3
 4
-1
-2
-3
-4
-5
-0
-1
-2
-3
-4

+ 19 - 12
tests/mix

@@ -1,3 +1,7 @@
+struct A {
+    int a;
+};
+
 int test() {
     if(false) {
         return 5;
@@ -5,30 +9,33 @@ int test() {
     return 4;
 }
 
-int* wusi(int* a, int t) {
-    return a;
+int wusi(A a, int t) {
+    return a.a + t;
 }
 
 void main() {
     int a = 5;
     int b = 6;
     
-    int* c = &a;
-
+    A c;
+    c.a = 90;
+    
     if(a + b < 20 && a > 3) {
         test(1);
     }
     
-    test(*c);
-    test((&a)[0]);
-    test(*&*&a);
-    a = *&a;
-    
+    test(c.a);
     a = test();
     
     a = - - - 3;
+    a = -a;
+    a = -a;
+    
+    test(a);
+    
+    int wusi = 3;
+    int baum = wusi;
+    baum = wusi;
     
-    (*wusi(c, a++))++;
-    (*wusi(c, a++))++;
-    int h = ~~3;
+    test(wusi(c, 3));
 }

+ 3 - 3
tests/mix.out

@@ -1,4 +1,4 @@
 1
-5
-5
-5
+90
+-3
+93

+ 2 - 16
tests/strings/string

@@ -1,17 +1,7 @@
-void wusi(const int** b) {
-    test("Const Wusi");
-}
-
-void wusi(int** b) {
-    test("Wusi");
-}
-
 void main() {
-    const int* a = "2allo";
+    int[] a = "2allo";
     a = "Hallo";
-    const int** b = &a; 
-    test(a == *b);
-    test(*a);
+
     test(a[0]);
     test(a[1]);
     test(a[2]);
@@ -19,8 +9,4 @@ void main() {
     test(a[4]);
     test(a);
     test(length(a));
-    int** n = nullptr;
-    wusi(n);
-    wusi(nullptr);
-    wusi(b);    
 }

+ 0 - 5
tests/strings/string.out

@@ -1,5 +1,3 @@
-true
-72
 72
 97
 108
@@ -7,6 +5,3 @@ true
 111
 Hallo
 5
-Wusi
-Wusi
-Const Wusi

+ 10 - 15
tests/strings/string_lib

@@ -1,10 +1,7 @@
-#define cstring const int* #end
-#define string int* #end
-
-string concat(cstring a, cstring b) {
+int[] concat(int[] a, int[] b) {
     int la = length(a);
     int lb = length(b);
-    int* s = new int[la + lb];
+    int[] s = new int[la + lb];
     for(int i = 0; i < la; i++) {
         s[i] = a[i];
     }
@@ -14,7 +11,7 @@ string concat(cstring a, cstring b) {
     return s;
 }
 
-bool compare(cstring a, cstring b) {
+int compare(int[] a, int[] b) {
     int l = length(a);
     if(l != length(b)) {   
         return false;
@@ -27,7 +24,7 @@ bool compare(cstring a, cstring b) {
     return true;
 }
 
-void toLower(string s) {
+void toLower(int[] s) {
     int l = length(s);
     for(int i = 0; i < l; i++) {
         int c = s[i];
@@ -39,21 +36,19 @@ void toLower(string s) {
 }
 
 void main() {
-    cstring msg = "Hallo User: ";
-    cstring name = "Kajetan";
-    string together = concat(msg, name);
-    string together2 = concat(together, name);
+    int[] msg = "Hallo User: ";
+    int[] name = "Kajetan";
+    int[] together = concat(msg, name);
+    int[] together2 = concat(together, name);
     test(together2);
     toLower(together);
     test(together);
-    delete together;
-    delete together2;
     
-    cstring a = name;
+    int[] a = name;
     test(a);
     test(a == name);
     
-    cstring baum = "Kajetan";
+    int[] baum = "Kajetan";
     test(name == baum);
     test(compare(name, baum));
     test(compare(name, "Kajetan"));

+ 5 - 5
tests/strings/string_lib.out

@@ -1,8 +1,8 @@
 Hallo User: KajetanKajetan
 hallo user: kajetan
 Kajetan
-true
-false
-true
-true
-false
+1
+0
+1
+1
+0

+ 3 - 3
tests/struct_ref/alloc

@@ -1,15 +1,15 @@
 struct A {
     float f;
     int i;
-    long l;
-    bool b;
+    int l;
+    int b;
 };
 
 void main() {
     A a;
     a.f = 5.0;
     a.i = 7;
-    a.l = 8L;
+    a.l = 8;
     a.b = true;
     test(a.f);
     test(a.i);

+ 1 - 1
tests/struct_ref/alloc.out

@@ -1,4 +1,4 @@
 5.00
 7
 8
-true
+1

+ 10 - 10
tests/struct_ref/bool_reference

@@ -1,15 +1,15 @@
-void test(bool* t) {
-    *t = true;
+struct A {
+    int t;
+};
+
+void test(A t) {
+    t.t = true;
 }
 
 void main() {
-    bool a = true;
-    bool* b = &a;
-    a = false;
-    test(a);
-    test(*b);
-    test(&a);
-    test(b);
+    A a;
+    a.t = false;
+    test(a.t);
     test(a);
-    test(*b);
+    test(a.t);
 }

+ 2 - 4
tests/struct_ref/bool_reference.out

@@ -1,4 +1,2 @@
-false
-false
-true
-true
+0
+1

+ 10 - 11
tests/struct_ref/float_reference

@@ -1,16 +1,15 @@
-void test(float* t) {
-    *t = 8.0;
-    *t += 1.0;
+struct A {
+    float t;
+};
+
+void test(A t) {
+    t.t = 5.0;
 }
 
 void main() {
-    float a = 5.0;
-    float* b = &a;
-    a = 6.0;
-    test(a);
-    test(*b);
-    test(&a);
-    test(b);
+    A a;
+    a.t = 6.0;
+    test(a.t);
     test(a);
-    test(*b);
+    test(a.t);
 }

+ 1 - 3
tests/struct_ref/float_reference.out

@@ -1,4 +1,2 @@
 6.00
-6.00
-9.00
-9.00
+5.00

+ 11 - 11
tests/struct_ref/int_reference

@@ -1,16 +1,16 @@
-void test2(int* t) {
-    *t = 8;
-    *t += 1;
+struct A {
+    int t;
+};
+
+void test(A t) {
+    t.t = 8;
+    t.t += 1;
 }
 
 void main() {
-    int a = 5;
-    int* b = &a;
-    a = 6;
-    test(a);
-    test(*(b));
-    test2(&a);
-    test2(b);
+    A a;
+    a.t = 5;
+    test(a.t);
     test(a);
-    test(*b);
+    test(a.t);
 }

+ 1 - 3
tests/struct_ref/int_reference.out

@@ -1,4 +1,2 @@
-6
-6
-9
+5
 9

+ 0 - 16
tests/struct_ref/long_reference

@@ -1,16 +0,0 @@
-void test(long* t) {
-    *t = 8L;
-    *t += 1L;
-}
-
-void main() {
-    long a = 5L;
-    long* b = &a;
-    a = 6L;
-    test(a);
-    test(*(b));
-    test(&a);
-    test(b);
-    test(a);
-    test(*b);
-}

+ 0 - 4
tests/struct_ref/long_reference.out

@@ -1,4 +0,0 @@
-6
-6
-9
-9

+ 1 - 4
tests/struct_ref/nested

@@ -15,12 +15,9 @@ void main() {
     b.a = 1;
     b.b = 2;
     b.c = 3;
-    b.d.a = 3;
+    b.d.a = 4;
     b.d.b = 5;
     
-    B* ba = &b;
-    ba->d.a = 4;
-    
     test(b.a);
     test(b.b);
     test(b.c);

+ 3 - 19
tests/struct_ref/pass_struct

@@ -1,6 +1,6 @@
 struct A {
     int i;
-    bool b;
+    float b;
 };
 
 void test(A a) {
@@ -8,33 +8,17 @@ void test(A a) {
     test(a.b);
     
     a.i = 2;
-    a.b = false;
+    a.b = 3.0;
     
     test(a.i);
     test(a.b);
 }
 
-void test(A* a) {
-    test(a->i);
-    test(a->b);
-    
-    a->i = 2;
-    a->b = false;
-    
-    test(a->i);
-    test(a->b);
-}
-
 void main() {
     A a;
     a.i = 3;
-    a.b = true;
+    a.b = 4.0;
     test(a);
     test(a.i);
     test(a.b);
-    test(&a);
-    test(a.i);
-    test(a.b);
-    
-    int c = 3;
 }

+ 3 - 9
tests/struct_ref/pass_struct.out

@@ -1,12 +1,6 @@
 3
-true
+4.00
 2
-false
-3
-true
-3
-true
-2
-false
+3.00
 2
-false
+3.00

+ 3 - 19
tests/struct_ref/struct_access

@@ -6,25 +6,9 @@ void main() {
     A a;
     a.w = 3;
     
-    int* ref = &a.w;
-    int** refa = &ref;
-    int*** refb = &refa;
-    A* ap = &a;
-    A** apa = &ap;
-    
-    *ref = 6;
-    **refa = 6;
-    ***refb = 4;
-    (***refb)++;
-    
-    (*apa)->w++;
-    
+    test(a.w);
     a.w++;
+    test(a.w);
     ++a.w;
-    a.w--;
-    --a.w;
-    test(a.w++);
-    test(++a.w);
-    test(a.w--);
-    test(--a.w);
+    test(a.w);
 }

+ 3 - 4
tests/struct_ref/struct_access.out

@@ -1,4 +1,3 @@
-6
-8
-8
-6
+3
+4
+5

Some files were not shown because too many files changed in this diff