瀏覽代碼

new test file and some advances in realObject

develop-theo
Theo Souchon 2 年之前
父節點
當前提交
3693a7364f
共有 21 個檔案被更改,包括 116 行新增65 行删除
  1. +16
    -6
      ccmeta.leg
  2. +3
    -1
      parsimonyLibrary/boot.mc
  3. +13
    -12
      parsimonyLibrary/dynamicObject.mc
  4. +18
    -29
      testPars.sh
  5. +1
    -1
      tests-parsimony/parsimony-lang/001.c
  6. +7
    -0
      tests-parsimony/parsimony-lang/001.out
  7. +3
    -6
      tests-parsimony/parsimony-lang/002.c
  8. +6
    -0
      tests-parsimony/parsimony-lang/002.out
  9. +1
    -1
      tests-parsimony/parsimony-lang/003.c
  10. +6
    -0
      tests-parsimony/parsimony-lang/003.out
  11. +1
    -1
      tests-parsimony/parsimony-lang/004.c
  12. +8
    -0
      tests-parsimony/parsimony-lang/004.out
  13. +5
    -0
      tests-parsimony/parsimony-lang/005.out
  14. +12
    -0
      tests-parsimony/parsimony-lang/006.out
  15. +1
    -2
      tests-parsimony/parsimony-lang/007.c
  16. +3
    -0
      tests-parsimony/parsimony-lang/007.out
  17. +1
    -4
      tests-parsimony/parsimony-lang/map.c
  18. +8
    -0
      tests-parsimony/parsimony-lang/map.out
  19. +0
    -0
      tests-parsimony/parsimony-lang/projectExample.c
  20. +3
    -0
      tests-parsimony/parsimony-lang/projectExample.out
  21. +0
    -2
      tests-parsimony/realObject.c

+ 16
- 6
ccmeta.leg 查看文件

@ -1343,7 +1343,7 @@ oop everyExternalDeclaration(oop s)
return s;
}
oop ensure(oop s, int id)
oop ensure(int id, oop s)
{
if (is(Map, s)) {
oop protoSymbol = map_get(s, __proto___symbol);
@ -1380,7 +1380,12 @@ error = EOL* < (!EOL .)* EOL* (!EOL .)* > &{ error(yytext), 1 }
idOpt = id | {$$=newNullObject()}
id = <ID> { $$= new_C_id(yytext) } -
| META_AT META_LPAREN m:meta_exp META_RPAREN { $$= ensure(eval(globals,m), t_C_id) } -
| m:metaId { $$= ensure(t_C_id, eval(globals,m)) } -
| m:mmetaId { $$= m } -
metaId = META_AT META_LPAREN m:meta_exp META_RPAREN { $$= m}
mmetaId = META_AT META_AT META_LPAREN m:meta_exp META_RPAREN { $$= m}
ID = <NAME> &{ !is_C_keyword(yytext) }
@ -1495,9 +1500,10 @@ hexadecimalEscapeSequence = '\\x' hexadecimalDigit+
# 6.4.5
stringLiteral = { listBegin(); }
( s:stringLiteralPart { listAppend(s) }
)+ { $$= new_C_stringLiteral(listEnd()) }
stringLiteral = { listBegin(); }
( s:stringLiteralPart { listAppend(s) }
| META_AT META_AT META_LPAREN m:meta_exp META_RPAREN { listAppend(m) }
)+ { $$= new_C_stringLiteral(listEnd()) }
stringLiteralPart = < '"' sCharSequence '"' > { $$= new_C_string(yytext) } -
| < 'L''"' sCharSequence '"' > { $$= new_C_string(yytext) } -
@ -1803,7 +1809,7 @@ declarator = # An attribute specifier list may appear immediately before a de
) { $$= d }
directDeclarator = ( l:LPAREN d:declarator r:RPAREN { d= new_C_subexpr(l, d, r) }
| &( <ID> @{ declarationId(yytext) } )
| &( <ID> @{ declarationId(yytext) } | metaId | mmetaId ) # fix me for meta typedef
d:id
)
( @{ C_scopeBegin() }
@ -4054,6 +4060,10 @@ void outputNode(oop node)
outputNode(map_get(node, expression_symbol));
break;
default:
if (proto_number < t_C_declaration) {
outputNode(eval(globals, node));
break;
}
printf("I cannot print a node with proto_number %i\n", proto_number);
exit(0);
}

+ 3
- 1
parsimonyLibrary/boot.mc 查看文件

@ -16,7 +16,9 @@
//------------ creation C structure ------------//
newId(x) { treeCopy({ identifier: x, __proto__: C_id }); }
newId(x) { { identifier: x, __proto__: C_id }; }
newText(x) { { value: x, __proto__: C_string }; }
newComment(com) { { text : com, __proto__: Comment }; }

+ 13
- 12
parsimonyLibrary/dynamicObject.mc 查看文件

@ -127,7 +127,6 @@ struct Object {
send(object, method)
{
// program.mem = newId(string(object));
rawSend = (`declaration send(obj, met););
rawSend.semicolon = null;
rawSend.declarators[0].paramTypeL[0].identifier = object;
@ -163,25 +162,27 @@ struct Object {
s.declarators.paramTypeL[0] = treeCopy(param);
}
tmp = {};
tmp[0] = (`declaration struct @(treeCopy(newId(string(program.objects.currentClassName)))) *self = (struct @(newId(string(program.objects.currentClassName))) *) __self;
);
/////////////////////// FIX ME /////////////////////////////// MAYBE CONTEXT WITH GLOBAL
// tmp[0].specifiers[0].name.identifier = string(program.objects.currentClassName);
// tmp[0].declarators[0].rhs.typeName.specifiers[0].name.identifier = string(program.objects.currentClassName);
tmp[0] = (`declaration struct @@(newId(string(program.objects.currentClassName))) *self = (struct @@(newId(string(program.objects.currentClassName))) *) __self;
);
s.compoundS.expression = treeCopy(fusion(tmp, s.compoundS.expression));
program.objects.function = "none";
return s;
}
if (program.objects.function == "constructor") {
rawDeclaration = (`declaration class = findClass("foo");
structDeclaration = (`declaration struct @@(newId(string(program.objects.currentClassName))) *self = calloc(1, sizeof *self);
);
rawDeclaration = (`declaration class = findClass(@@(newText("\"" + string(program.objects.currentClassName) + "\"")));
);
rawDeclaration.declarators[0].rhs.paramTypeL[0].text[0].value = "\"" + string(program.objects.currentClassName) + "\"";
size = length(s.compoundS.expression);
lhs = treeCopy(s.compoundS.expression[size-2].expression.lhs);
returnSTMT = (`statement return (struct __oop *) self;
);
t = {};
append(t, structDeclaration);
lhs = treeCopy(s.compoundS.expression[0].expression.lhs);
lhs.rhs = rawDeclaration.declarators[0].lhs;
rawDeclaration.declarators[0].lhs = lhs;
s.compoundS.expression[size] = s.compoundS.expression[size-1];
s.compoundS.expression[size-1] = rawDeclaration;
append(s.compoundS.expression, rawDeclaration);
append(s.compoundS.expression, returnSTMT);
s.compoundS.expression = fusion(t, s.compoundS.expression);
program.objects.function = "none";
return s;
}

+ 18
- 29
testPars.sh 查看文件

@ -1,29 +1,18 @@
make
echo "\n"
echo "\n"
./ccmeta tests-parsimony/parsimony-lang/001.c
echo "\n"
echo "\n"
./ccmeta tests-parsimony/parsimony-lang/002.c
echo "\n"
echo "\n"
./ccmeta tests-parsimony/parsimony-lang/003.c
echo "\n"
echo "\n"
./ccmeta tests-parsimony/parsimony-lang/004.c
echo "\n"
echo "\n"
./ccmeta tests-parsimony/parsimony-lang/005.c
echo "\n"
echo "\n"
./ccmeta tests-parsimony/parsimony-lang/006.c
echo "\n"
echo "\n"
./ccmeta tests-parsimony/parsimony-lang/007.c
echo "\n"
echo "\n"
./ccmeta tests-parsimony/parsimony-lang/map.c
echo "\n"
./ccmeta tests-parsimony/projExample.c
echo "\n"
echo "ok !"
make
run="./ccmeta"
die()
{
diff $1 $2 | head -20
exit 1
}
for i in tests-parsimony/parsimony-lang/*.c; do
echo $i
j="${i%.c}.out"
k="tmp.out"
$run $i > $k
cmp $k $j || die $k $j
done
rm tmp.out

+ 1
- 1
tests-parsimony/parsimony-lang/001.c 查看文件

@ -12,7 +12,7 @@
enum foo { FOO, BAR, BAZ };
char *x[] = @(newCinitializer([newCstring("X"), comma, newCstring("Y")]));
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" });

+ 7
- 0
tests-parsimony/parsimony-lang/001.out 查看文件

@ -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" };

+ 3
- 6
tests-parsimony/parsimony-lang/002.c 查看文件

@ -5,17 +5,14 @@
nil;
}
@{
print("6 outputs : \n");
nil;
}
@{
a = `constant 10;
nil;
}
char t = @(`constant @a);
char t = @(`constant @a);
int i = @cons;
int q = @(`constant 10);
int k = @(`initializer (1,2,"stringy thingy",21<<1));
int i = @saved;
int w = @a;
int w = @a;

+ 6
- 0
tests-parsimony/parsimony-lang/002.out 查看文件

@ -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;

+ 1
- 1
tests-parsimony/parsimony-lang/003.c 查看文件

@ -9,7 +9,7 @@
}
int main()
{
{
@{
l = {};
append(l, forLoop);

+ 6
- 0
tests-parsimony/parsimony-lang/003.out 查看文件

@ -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;
}

+ 1
- 1
tests-parsimony/parsimony-lang/004.c 查看文件

@ -15,4 +15,4 @@ int main() {
`initializer 2 * @num;
};
return 0;
}
}

+ 8
- 0
tests-parsimony/parsimony-lang/004.out 查看文件

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

+ 5
- 0
tests-parsimony/parsimony-lang/005.out 查看文件

@ -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;
};
}

+ 12
- 0
tests-parsimony/parsimony-lang/006.out 查看文件

@ -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;
}

+ 1
- 2
tests-parsimony/parsimony-lang/007.c 查看文件

@ -13,5 +13,4 @@
l;
};
@a;
@a;

+ 3
- 0
tests-parsimony/parsimony-lang/007.out 查看文件

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

+ 1
- 4
tests-parsimony/parsimony-lang/map.c 查看文件

@ -19,7 +19,4 @@ char *a[] = { @a };
char *b[] = { @b };
char *c[] = { @c };
char *c[] = { @c };

+ 8
- 0
tests-parsimony/parsimony-lang/map.out 查看文件

@ -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"};

tests-parsimony/projectExample.c → tests-parsimony/parsimony-lang/projectExample.c 查看文件


+ 3
- 0
tests-parsimony/parsimony-lang/projectExample.out 查看文件

@ -0,0 +1,3 @@
enum foo { Closed = 0, ReadOnly = 1, WriteOnly = 2 };
static char *stateNames[] = { "Closed", "ReadOnly", "WriteOnly"};

+ 0
- 2
tests-parsimony/realObject.c 查看文件

@ -11,10 +11,8 @@ typedef struct __oop *oop;
@constructor("Point") oop newPoint(double x, double y)
{
struct Point *p = calloc(1, sizeof *p); // auto
self->x = x;
self->y = y;
return self; // need to cast (struct __oop *) self
}
@method("Point") double magnitude()

Loading…
取消
儲存