diff --git a/ccmeta.leg b/ccmeta.leg index a3b3bec..ff5f2f2 100644 --- a/ccmeta.leg +++ b/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 = { $$= 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 = &{ !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) } - | &( @{ declarationId(yytext) } ) + | &( @{ 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); } diff --git a/parsimonyLibrary/boot.mc b/parsimonyLibrary/boot.mc index 943a613..f6b6b4a 100644 --- a/parsimonyLibrary/boot.mc +++ b/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 }; } diff --git a/parsimonyLibrary/dynamicObject.mc b/parsimonyLibrary/dynamicObject.mc index 87ce333..fc6e10e 100644 --- a/parsimonyLibrary/dynamicObject.mc +++ b/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; } diff --git a/testPars.sh b/testPars.sh index 4b94d0e..2413932 100755 --- a/testPars.sh +++ b/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 !" \ No newline at end of file +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 \ No newline at end of file diff --git a/tests-parsimony/parsimony-lang/001.c b/tests-parsimony/parsimony-lang/001.c index c2c5bec..18279dc 100644 --- a/tests-parsimony/parsimony-lang/001.c +++ b/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" }); diff --git a/tests-parsimony/parsimony-lang/001.out b/tests-parsimony/parsimony-lang/001.out new file mode 100644 index 0000000..8cf8ff2 --- /dev/null +++ b/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" }; diff --git a/tests-parsimony/parsimony-lang/002.c b/tests-parsimony/parsimony-lang/002.c index 765de03..e6c5ccb 100644 --- a/tests-parsimony/parsimony-lang/002.c +++ b/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; \ No newline at end of file diff --git a/tests-parsimony/parsimony-lang/002.out b/tests-parsimony/parsimony-lang/002.out new file mode 100644 index 0000000..2234be8 --- /dev/null +++ b/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; \ No newline at end of file diff --git a/tests-parsimony/parsimony-lang/003.c b/tests-parsimony/parsimony-lang/003.c index aa234d5..6383fea 100644 --- a/tests-parsimony/parsimony-lang/003.c +++ b/tests-parsimony/parsimony-lang/003.c @@ -9,7 +9,7 @@ } int main() -{ +{ @{ l = {}; append(l, forLoop); diff --git a/tests-parsimony/parsimony-lang/003.out b/tests-parsimony/parsimony-lang/003.out new file mode 100644 index 0000000..216820f --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/tests-parsimony/parsimony-lang/004.c b/tests-parsimony/parsimony-lang/004.c index bf0f89d..3231b0a 100644 --- a/tests-parsimony/parsimony-lang/004.c +++ b/tests-parsimony/parsimony-lang/004.c @@ -15,4 +15,4 @@ int main() { `initializer 2 * @num; }; return 0; -} +} \ No newline at end of file diff --git a/tests-parsimony/parsimony-lang/004.out b/tests-parsimony/parsimony-lang/004.out new file mode 100644 index 0000000..5fee3e3 --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/tests-parsimony/parsimony-lang/005.out b/tests-parsimony/parsimony-lang/005.out new file mode 100644 index 0000000..9b122a2 --- /dev/null +++ b/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; + }; +} \ No newline at end of file diff --git a/tests-parsimony/parsimony-lang/006.out b/tests-parsimony/parsimony-lang/006.out new file mode 100644 index 0000000..29f4f9d --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/tests-parsimony/parsimony-lang/007.c b/tests-parsimony/parsimony-lang/007.c index c1172f1..d047403 100644 --- a/tests-parsimony/parsimony-lang/007.c +++ b/tests-parsimony/parsimony-lang/007.c @@ -13,5 +13,4 @@ l; }; -@a; - +@a; \ No newline at end of file diff --git a/tests-parsimony/parsimony-lang/007.out b/tests-parsimony/parsimony-lang/007.out new file mode 100644 index 0000000..f343edd --- /dev/null +++ b/tests-parsimony/parsimony-lang/007.out @@ -0,0 +1,3 @@ +int a = 0;int b = 0;int c = 0;; + +int b = 0;; \ No newline at end of file diff --git a/tests-parsimony/parsimony-lang/map.c b/tests-parsimony/parsimony-lang/map.c index 58e2bfd..85de001 100644 --- a/tests-parsimony/parsimony-lang/map.c +++ b/tests-parsimony/parsimony-lang/map.c @@ -19,7 +19,4 @@ char *a[] = { @a }; char *b[] = { @b }; -char *c[] = { @c }; - - - +char *c[] = { @c }; \ No newline at end of file diff --git a/tests-parsimony/parsimony-lang/map.out b/tests-parsimony/parsimony-lang/map.out new file mode 100644 index 0000000..cc6745c --- /dev/null +++ b/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"}; \ No newline at end of file diff --git a/tests-parsimony/projectExample.c b/tests-parsimony/parsimony-lang/projectExample.c similarity index 100% rename from tests-parsimony/projectExample.c rename to tests-parsimony/parsimony-lang/projectExample.c diff --git a/tests-parsimony/parsimony-lang/projectExample.out b/tests-parsimony/parsimony-lang/projectExample.out new file mode 100644 index 0000000..535b3db --- /dev/null +++ b/tests-parsimony/parsimony-lang/projectExample.out @@ -0,0 +1,3 @@ +enum foo { Closed = 0, ReadOnly = 1, WriteOnly = 2 }; + +static char *stateNames[] = { "Closed", "ReadOnly", "WriteOnly"}; \ No newline at end of file diff --git a/tests-parsimony/realObject.c b/tests-parsimony/realObject.c index 5adb552..73904ee 100644 --- a/tests-parsimony/realObject.c +++ b/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()