Commit ba72dd16 authored by zygzagZ's avatar zygzagZ

Most base tests work

parent 391da1d4
......@@ -15,8 +15,11 @@ int printString(const char *c) {
char * readString() {
char *line = NULL;
size_t bufLen = 0;
getline(&line, &bufLen, stdin);
size_t len = 0;
getline(&line, &len, stdin);
while (line[len]) len++;
line[len-1] = 0;
return line;
}
......
......@@ -370,8 +370,7 @@ void Compiler::generateQJumpCond(QJumpCond &q) {
return;
}
auto tg = moveToAnyRegister(q.right);
append("TEST", tg, tg);
op = op.neg();
append("CMP", "$1", tg);
}
if (op.kind() != Op::CMP && op.kind() != Op::UNARY) throw runtime_error("Unexpected operator in compare");
string operand = getOpName(op);
......@@ -394,8 +393,7 @@ void Compiler::generateQAssign(QAssign &q) {
moveTo(arg, tg);
reg = tg;
}
// append("CMP", "$1", reg); // dziala
append("TEST", reg, reg);
append("CMP", "$1", reg);
break;
}
case Op::Copy: {
......@@ -404,6 +402,10 @@ void Compiler::generateQAssign(QAssign &q) {
return;
} else {
moveTo(arg, tg);
if (tg == 0) {
append("MOVL", tg, getRef(q.loc));
}
return;
}
break;
}
......
......@@ -397,7 +397,7 @@ void QuadrupleGenerator::visitEApp(EApp *p) {
addQuad(call);
Bool b;
if (info->type->isEqual(&b)) {
if (ret->type->isEqual(&b)) {
addLastVarCondJump(nullptr, Op::Copy, lastVar);
}
}
......
......@@ -109,7 +109,9 @@ private:
} else if (labelFalse) {
addQuad<QJumpCond>(labelFalse, l, op.neg(), r);
lastVar = alloc(1);
}
} else if (lastVar == l || lastVar == r) return;
// return needed because otherwise we get multiple lastVar assignments
// assign needed because otherwise some vars never have assignments
addQuad<QAssign>(lastVar, l, op, r);
}
......
class A {
int x;
}
int main() {
A a = new A;
A b = a;
a.x++;
a.x = a.x+1;
a.x = 123;
if (a.x == 123 || 123*456 < -1) {
b.x = 456;
} else {
a.x = 123;
b = a;
}
int[] arr = new int[10];
for (int i : arr) {
i = 10;
}
return a.x;
}
int write_to_local() {
int a;
a = 123;
return a;
}
......@@ -19,8 +19,13 @@ make -j8 && for i in lat/lattests/good/*.lat; do
$BIN "$i"
exit 1;
fi
if [ -f "${i%.*}.input" ]; then
inp="${i%.*}.input"
else
inp=/dev/null
fi
if ! diff <( timeout 2 ${i%.*} ) "${i%.*}.output"; then
if ! diff <( timeout 2 ${i%.*} < "$inp" ) "${i%.*}.output"; then
red "ERROR $i"
exit 1
fi
......
class A {
int x;
}
int main() {
A a = new A;
A b = a;
a.x++;
a.x = a.x+1;
a.x = 123;
if (a.x == 123 || 123*456 < -1) {
b.x = 456;
} else {
a.x = 123;
b = a;
}
int[] arr = new int[10];
int i = 0;
while (i < 10) {
i++;
i = 10;
}
if (true) {
b.x = 456;
a = b;
}
return a.x;
}
int write_to_local() {
int a;
a = 123;
return a;
}
int t() {
if (true) {
return 0;
}
}
int main() {
int a = 2;
while (a < 10) {
a = a + 1;
a = a + 2;
}
return 0;
}
int test(int a, int b, int c, int d, int e, int f, int g, int h) {
return a+b+c+d+e+f+g+h;
}
int main() {
return test(1,2,3,4,5,6,7,8);
}
\ No newline at end of file
int main() {
int a = 2;
a = 3;
while (a < 10) {
if (false) {
a = a + 1;
} else {
if (true) {
a = 100;
}
}
}
return 0;
}
int main() {
int a = 1;
int b = 2;
int c = 3;
while (a < 10) {
if (true) {
a = 10;
} else {
while (b < 2) {
if (c == 3) {
c = 4;
} else {
c = 23;
}
a = a + 1;
}
}
}
return 0;
}
int test(int a, int b, int c) {
{
int e, a = 1, b = 2, c = 3, d = 4, f = 5, g = 6;
if (a + b == 3 && e+f == f) {
printInt(a+b);
printInt(c-d);
printInt(e/f);
printInt(g%a);
} else if (!(b==c) || false) {
printInt(2);
}
}
return a+b+c;
}
int main() {
int e, a = 1, b = 2, c = 3, d = 4, f = 5, g = 6;
if (a + b == 3 && e+f == f) {
printInt(a+b);
printInt(c-d);
printInt(e/f);
printInt(g%a);
} else if (!(b==c) || false) {
printInt(2);
}
test(d,f,g);
return 0;
}
int z() {
return 1;
}
int a() {
return z();
}
int main() {
{
string a = "Hello", b = " ", c = "world!";
printString(a + b + c);
printString("Quote test \" works \" yay");
}
{
int e, a = 1, b = 2, c = 3, d = 4, f = 5, g = 6;
while (e < 10) {
a++;
b++;
c++;
d++;
e++;
f++;
g++;
}
printInt(a);
printInt(b);
printInt(c);
printInt(d);
printInt(e);
printInt(f);
printInt(g);
}
printInt(ifac2f(1, 10));
return a();
}
int ifac2f(int l, int h) {
if (l == h)
return l;
if (l > h)
return 1;
int m;
m = (l + h) / 2;
return ifac2f(l,m) * ifac2f(m+1,h);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment