Ver código fonte

Add parsimony tests.

master
Ian Piumarta 2 anos atrás
pai
commit
b86284cba0
20 arquivos alterados com 268 adições e 0 exclusões
  1. +7
    -0
      tests/parsimony/001
  2. +19
    -0
      tests/parsimony/001.c
  3. +6
    -0
      tests/parsimony/002
  4. +17
    -0
      tests/parsimony/002.c
  5. +6
    -0
      tests/parsimony/003
  6. +35
    -0
      tests/parsimony/003.c
  7. +8
    -0
      tests/parsimony/004
  8. +18
    -0
      tests/parsimony/004.c
  9. +5
    -0
      tests/parsimony/005
  10. +22
    -0
      tests/parsimony/005.c
  11. +12
    -0
      tests/parsimony/006
  12. +36
    -0
      tests/parsimony/006.c
  13. +3
    -0
      tests/parsimony/007
  14. +16
    -0
      tests/parsimony/007.c
  15. +1
    -0
      tests/parsimony/008
  16. +6
    -0
      tests/parsimony/008.c
  17. +8
    -0
      tests/parsimony/009
  18. +15
    -0
      tests/parsimony/009.c
  19. +8
    -0
      tests/parsimony/map
  20. +20
    -0
      tests/parsimony/map.c

+ 7
- 0
tests/parsimony/001 Ver arquivo

@ -0,0 +1,7 @@
enum foo { FOO, BAR, BAZ };
char *x[] = {"X","Y","Z"};
int i = 42;
char *c = "42";
int i = 14;
char *foos[] = { "FOO", "BAR", "BAZ" };

+ 19
- 0
tests/parsimony/001.c Ver arquivo

@ -0,0 +1,19 @@
@{
newObject(type, fields) { fields.__proto__ = type; fields }
newCint(text) { newObject(C_int, { text: text }) }
newCstring(text) { newObject(C_stringLiteral, { text: "\""+text+"\"" }) }
newCinitializer(list) { { __proto__: C_initializer, leftCurly: lcurly, initList: list, rightCurly: rcurly } }
newToken(text) { { __proto__: Token, text: text } }
comma = newToken(",");
lcurly = newToken("{");
rcurly = newToken("}");
nil;
}
enum foo { FOO, BAR, BAZ };
char *x[] = @(newCinitializer([newCstring("X"), comma, newCstring("Y"), comma, newCstring("Z")]));
int i = @(newCint("42"));
char *c = @(newCstring("42"));
int i = @({ __proto__: Token, text: "14" });
char *foos[] = { "FOO", "BAR", "BAZ" };

+ 6
- 0
tests/parsimony/002 Ver arquivo

@ -0,0 +1,6 @@
char t = 10;
int i = 2;
int q = 10;
int k = (1,2,"stringy thingy",21<<1);
int i = (1,2,"string",21<<1);
int w = 10;

+ 17
- 0
tests/parsimony/002.c Ver arquivo

@ -0,0 +1,17 @@
@{
saved = `expression (1,2,"string",21<<1);
first = `constant 2;
nil;
}
@{
second = `constant 10;
nil;
}
char t = @(`constant @second);
int i = @first;
int q = @(`constant 10);
int k = @(`expression (1,2,"stringy thingy",21<<1));
int i = @saved;
int w = @second;

+ 6
- 0
tests/parsimony/003 Ver arquivo

@ -0,0 +1,6 @@
int main()
{
for (int i = 0; i < 10; ++i) printf("%d\n", i);for (int i = 0; i < 10; ++i) printf("%d\n", i);;
for (int i = 0; i < 10; ++i) printf("%d\n", i);while (i < 10) { printf("%d\n", i); ++il; };
return 0;
}

+ 35
- 0
tests/parsimony/003.c Ver arquivo

@ -0,0 +1,35 @@
@{import("../src/parsimonyLibrary/boot.mc");}
@{
nTimes = `constant 10;
forLoop = `statement for (int i = 0; i < 10; ++i) printf("%d\n", i);;
whileLoop = `statement while (i < 10) { printf("%d\n", i); ++il; };
useForLoop = 1;
nil;
}
int main()
{
@{
l = {};
append(l, forLoop);
if (useForLoop) {
append(l, forLoop);
} else {
append(l, whileLoop);
}
l;
};
@{
l = {};
useForLoop = 0;
append(l, forLoop);
if (useForLoop) {
append(l, forLoop);
} else {
append(l, whileLoop);
}
l;
};
return 0;
}

+ 8
- 0
tests/parsimony/004 Ver arquivo

@ -0,0 +1,8 @@
int x = 2 * 21;
int main() {
int i = 2 * 21;
int y = 2 * 10;
int a = 2 * 21;
return 0;
}

+ 18
- 0
tests/parsimony/004.c Ver arquivo

@ -0,0 +1,18 @@
@{
num = `constant 21;
test = `expression 2 * 10;
nil;
}
int x = @{`expression 2 * @num;};
int main() {
int i = @(`expression 2 * @num);
int y = @test;
int a = @{
num = `constant 21;
test = 2;
`expression 2 * @num;
};
return 0;
}

+ 5
- 0
tests/parsimony/005 Ver arquivo

@ -0,0 +1,5 @@
int a = 5;int b = 2;int main() {
int c = 5;int d = 2;for(int i =0; i < 10; i++) {
a = 2;
};
}

+ 22
- 0
tests/parsimony/005.c Ver arquivo

@ -0,0 +1,22 @@
@{import("../src/parsimonyLibrary/boot.mc");}
@{
l = {};
append(l, `declaration int a = 5;);
append(l, `declaration int b = 2;);
l;
}
int main() {
@{
l = {};
a = (`declaration int a = 2;);
append(l, `declaration int c = 5;);
b = 5;
append(l, `declaration int d = 2;);
append(l, `statement for(int i =0; i < 10; i++) {
a = 2;
});
l;
};
}

+ 12
- 0
tests/parsimony/006 Ver arquivo

@ -0,0 +1,12 @@
int a = 5;int a = 5;;
int a = 5;;
int abc = 2;;
int main() {
int a = 5;;
int b = 0;
int c = 0;int d = 5;int d = 5;;
int e = 0;
return 0;
}

+ 36
- 0
tests/parsimony/006.c Ver arquivo

@ -0,0 +1,36 @@
@{import("../src/parsimonyLibrary/boot.mc");}
@{
l = {};
append(l, `declaration int a = 5;);
a = (`declaration int a = 5;);
append(l, `declaration int a = 5;);
l;
};
@a;
@{
t = `constant 2;
nil;
}
@(`declaration int abc = @t;);
int main() {
@a;
int b = 0;
@{
l = {};
append(l, `declaration int c = 0;);
x = (`declaration int d = 5;);
append(l, x);
if (1) {
if (1) {
x = (`declaration int d = 5;);
append(l, x);
}
}
l;
};
int e = 0;
return 0;
}

+ 3
- 0
tests/parsimony/007 Ver arquivo

@ -0,0 +1,3 @@
int a = 0;int b = 0;int c = 0;;
int b = 0;;

+ 16
- 0
tests/parsimony/007.c Ver arquivo

@ -0,0 +1,16 @@
@{import("../src/parsimonyLibrary/boot.mc");}
@{
l = {};
append(l, `declaration int a = 0;);
a = (`declaration int b = 0;);
append(l, a);
if (1) {
append(l, `declaration int c = 0;);
} else {
append(l, `declaration int c = 1;);
}
l;
};
@a;

+ 1
- 0
tests/parsimony/008 Ver arquivo

@ -0,0 +1 @@
int x;

+ 6
- 0
tests/parsimony/008.c Ver arquivo

@ -0,0 +1,6 @@
@{
f(n) {
`declaration int @@(n);;
}
f("x");
}

+ 8
- 0
tests/parsimony/009 Ver arquivo

@ -0,0 +1,8 @@
x = 1, y = 2, z = 3
x = 1, y = 2, z = 3
x = 1, y = 3, z = null
x = 1, y = null, z = 3
x = 3, y = null, z = 1
x = 3, y = 1, z = null
x = null, y = 1, z = 3
x = null, y = 3, z = 1

+ 15
- 0
tests/parsimony/009.c Ver arquivo

@ -0,0 +1,15 @@
@{
f(x, y, z) {
print("x = ", x, ", y = ", y, ", z = ", z, "\n");
nil;
}
f(1, 2, 3);
f(x:1, y:2, z:3);
f(x:1, y:3);
f(x:1, z:3);
f(z:1,x:3);
f(y:1,x:3);
f(y:1,z:3);
f(z:1,y:3);
}

+ 8
- 0
tests/parsimony/map Ver arquivo

@ -0,0 +1,8 @@
enum foo { A, B, C };
enum oof { A, B, C };
char *a[] = { "A""B""C"};
char *b[] = { "A", "B", "C"};
char *c[] = { "A", "B", "C"};

+ 20
- 0
tests/parsimony/map.c Ver arquivo

@ -0,0 +1,20 @@
@{import("../src/parsimonyLibrary/boot.mc");}
enum foo { A, B, C };
enum oof { A, B, C };
@{
isEnum(x) { x.__proto__ == C_enum }
notToken(x) { x.__proto__ != Token }
to_C_string(x) {{ __proto__: C_string, value: "\"" + string(x.name.identifier) + "\"" }}
a = map(to_C_string, select(isEnum, program.enums.foo.enumList));
b = map(to_C_string, program.enums.foo.enumList, notToken);
c = map(to_C_string, program.enums.foo.enumList, isEnum);
nil;
}
char *a[] = { @a };
char *b[] = { @b };
char *c[] = { @c };

Carregando…
Cancelar
Salvar