Commit 5fc95c2a53

Andrew Kelley <superjoe30@gmail.com>
2016-12-22 06:55:21
IR: port some tests
1 parent 46033a2
src/ir.cpp
@@ -5462,7 +5462,7 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst
         ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
         if (!val)
             return ira->codegen->builtin_types.entry_invalid;
-        bool ptr_is_const = true;
+        bool ptr_is_const = false;
         return ir_analyze_const_ptr(ira, source_instruction, val, value->type_entry,
                 false, ConstPtrSpecialNone, ptr_is_const);
     }
test/cases3/array.zig
@@ -0,0 +1,31 @@
+fn arrays() {
+    @setFnTest(this);
+
+    var array : [5]u32 = undefined;
+
+    var i : u32 = 0;
+    while (i < 5) {
+        array[i] = i + 1;
+        i = array[i];
+    }
+
+    i = 0;
+    var accumulator = u32(0);
+    while (i < 5) {
+        accumulator += array[i];
+
+        i += 1;
+    }
+
+    assert(accumulator == 15);
+    assert(getArrayLen(array) == 5);
+}
+fn getArrayLen(a: []u32) -> usize {
+    a.len
+}
+
+// TODO const assert = @import("std").debug.assert;
+fn assert(ok: bool) {
+    if (!ok)
+        @unreachable();
+}
test/cases3/fn.zig
@@ -32,6 +32,36 @@ fn voidFun(a: i32, b: void, c: i32, d: void) {
 }
 
 
+fn mutableLocalVariables() {
+    @setFnTest(this);
+
+    var zero : i32 = 0;
+    assert(zero == 0);
+
+    var i = i32(0);
+    while (i != 3) {
+        i += 1;
+    }
+    assert(i == 3);
+}
+
+fn separateBlockScopes() {
+    @setFnTest(this);
+
+    {
+        const no_conflict : i32 = 5;
+        assert(no_conflict == 5);
+    }
+
+    const c = {
+        const no_conflict = i32(10);
+        no_conflict
+    };
+    assert(c == 10);
+}
+
+
+
 // TODO const assert = @import("std").debug.assert;
 fn assert(ok: bool) {
     if (!ok)
test/cases3/math.zig
@@ -50,6 +50,25 @@ fn countTrailingZeroes() {
     assert(@ctz(u8(0b00000000)) == 8);
 }
 
+fn modifyOperators() {
+    @setFnTest(this);
+
+    var i : i32 = 0;
+    i += 5;  assert(i == 5);
+    i -= 2;  assert(i == 3);
+    i *= 20; assert(i == 60);
+    i /= 3;  assert(i == 20);
+    i %= 11; assert(i == 9);
+    i <<= 1; assert(i == 18);
+    i >>= 2; assert(i == 4);
+    i = 6;
+    i &= 5;  assert(i == 4);
+    i ^= 6;  assert(i == 2);
+    i = 6;
+    i |= 3;  assert(i == 7);
+}
+
+
 // TODO const assert = @import("std").debug.assert;
 fn assert(ok: bool) {
     if (!ok)
test/cases3/struct.zig
@@ -21,6 +21,47 @@ fn invokeStaticMethodInGlobalScope() {
     assert(should_be_11 == 11);
 }
 
+fn voidStructFields() {
+    @setFnTest(this);
+
+    const foo = VoidStructFieldsFoo {
+        .a = void{},
+        .b = 1,
+        .c = void{},
+    };
+    assert(foo.b == 1);
+    assert(@sizeOf(VoidStructFieldsFoo) == 4);
+}
+const VoidStructFieldsFoo = struct {
+    a : void,
+    b : i32,
+    c : void,
+};
+
+
+pub fn structs() {
+    @setFnTest(this);
+
+    var foo: StructFoo = undefined;
+    @memset((&u8)(&foo), 0, @sizeOf(StructFoo));
+    foo.a += 1;
+    foo.b = foo.a == 1;
+    testFoo(foo);
+    testMutation(&foo);
+    assert(foo.c == 100);
+}
+const StructFoo = struct {
+    a : i32,
+    b : bool,
+    c : f32,
+};
+fn testFoo(foo : StructFoo) {
+    assert(foo.b);
+}
+fn testMutation(foo : &StructFoo) {
+    foo.c = 100;
+}
+
 
 
 // TODO const assert = @import("std").debug.assert;
test/self_hosted.zig
@@ -17,121 +17,6 @@ const test_this = @import("cases/this.zig");
 
 
 
-fn mutableLocalVariables() {
-    @setFnTest(this, true);
-
-    var zero : i32 = 0;
-    assert(zero == 0);
-
-    var i = i32(0);
-    while (i != 3) {
-        i += 1;
-    }
-    assert(i == 3);
-}
-
-fn arrays() {
-    @setFnTest(this, true);
-
-    var array : [5]u32 = undefined;
-
-    var i : u32 = 0;
-    while (i < 5) {
-        array[i] = i + 1;
-        i = array[i];
-    }
-
-    i = 0;
-    var accumulator = u32(0);
-    while (i < 5) {
-        accumulator += array[i];
-
-        i += 1;
-    }
-
-    assert(accumulator == 15);
-    assert(getArrayLen(array) == 5);
-}
-fn getArrayLen(a: []u32) -> usize {
-    a.len
-}
-
-fn modifyOperators() {
-    @setFnTest(this, true);
-
-    var i : i32 = 0;
-    i += 5;  assert(i == 5);
-    i -= 2;  assert(i == 3);
-    i *= 20; assert(i == 60);
-    i /= 3;  assert(i == 20);
-    i %= 11; assert(i == 9);
-    i <<= 1; assert(i == 18);
-    i >>= 2; assert(i == 4);
-    i = 6;
-    i &= 5;  assert(i == 4);
-    i ^= 6;  assert(i == 2);
-    i = 6;
-    i |= 3;  assert(i == 7);
-}
-
-
-fn separateBlockScopes() {
-    @setFnTest(this, true);
-
-    {
-        const no_conflict : i32 = 5;
-        assert(no_conflict == 5);
-    }
-
-    const c = {
-        const no_conflict = i32(10);
-        no_conflict
-    };
-    assert(c == 10);
-}
-
-
-fn voidStructFields() {
-    @setFnTest(this, true);
-
-    const foo = VoidStructFieldsFoo {
-        .a = void{},
-        .b = 1,
-        .c = void{},
-    };
-    assert(foo.b == 1);
-    assert(@sizeOf(VoidStructFieldsFoo) == 4);
-}
-struct VoidStructFieldsFoo {
-    a : void,
-    b : i32,
-    c : void,
-}
-
-
-
-pub fn structs() {
-    @setFnTest(this, true);
-
-    var foo : StructFoo = undefined;
-    @memset(&foo, 0, @sizeOf(StructFoo));
-    foo.a += 1;
-    foo.b = foo.a == 1;
-    testFoo(foo);
-    testMutation(&foo);
-    assert(foo.c == 100);
-}
-struct StructFoo {
-    a : i32,
-    b : bool,
-    c : f32,
-}
-fn testFoo(foo : StructFoo) {
-    assert(foo.b);
-}
-fn testMutation(foo : &StructFoo) {
-    foo.c = 100;
-}
 struct Node {
     val: Val,
     next: &Node,
test/self_hosted3.zig
@@ -1,4 +1,5 @@
 // TODO '_' identifier for unused variable bindings
+const test_array = @import("cases3/array.zig");
 const test_atomics = @import("cases3/atomics.zig");
 const test_defer = @import("cases3/defer.zig");
 const test_enum = @import("cases3/enum.zig");