From bbfc2b5a03f693012fc2da4141288d27e5e93c73 Mon Sep 17 00:00:00 2001 From: Theo Souchon Date: Mon, 20 Mar 2023 15:23:30 +0900 Subject: [PATCH] test fix + add rules number --- src/c | 15 ++ src/ccmeta.leg | 150 ++++++++++++------ src/object.c | 2 + src/parsimonyLibrary/boot.mc | 2 +- src/parsimonyLibrary/dynamicObjectExtDecl.mc | 26 +-- src/parsimonyLibrary/dynamicObjectParsFrom.mc | 24 +-- src/tests/tests-c/00104.c | 4 + src/tests/tests-c/00187.c | 2 + src/tests/tests-c/00189.c | 3 + src/tests/tests-c/00220.c | 2 + .../00062.c.err => tests-cpp/00062.c} | 0 .../00063.c.err => tests-cpp/00063.c} | 0 .../00066.c.err => tests-cpp/00066.c} | 0 .../00067.c.err => tests-cpp/00067.c} | 0 .../00068.c.err => tests-cpp/00068.c} | 0 .../00069.c.err => tests-cpp/00069.c} | 0 .../00070.c.err => tests-cpp/00070.c} | 0 .../00071.c.err => tests-cpp/00071.c} | 0 .../00074.c.err => tests-cpp/00074.c} | 0 src/tests/{tests-c => tests-cpp}/00115.c | 0 src/tests/{tests-c => tests-cpp}/00122.c | 0 src/tests/{tests-c => tests-cpp}/00137.c | 0 src/tests/{tests-c => tests-cpp}/00162.c | 0 src/tests/{tests-c => tests-cpp}/00200.c | 0 src/tests/{tests-c => tests-cpp}/00202.c | 0 src/tests/{tests-c => tests-cpp}/00210.c | 0 src/tests/{tests-c => tests-cpp}/00219.c | 0 src/tests/{tests-c => tests-err}/00204.c | 0 src/tests/tests-parsimony/008.c | 14 +- src/tests/tests-parsimony/009 | 9 +- src/tests/tests-parsimony/009.c | 19 ++- src/tests/tests-parsimony/010 | 8 - src/tests/tests-parsimony/010.c | 15 -- src/tests/tests-parsimony/realObjectED | 4 +- src/tests/tests-parsimony/realObjectPF | 4 +- 35 files changed, 178 insertions(+), 125 deletions(-) create mode 100644 src/c rename src/tests/{tests-c/00062.c.err => tests-cpp/00062.c} (100%) rename src/tests/{tests-c/00063.c.err => tests-cpp/00063.c} (100%) rename src/tests/{tests-c/00066.c.err => tests-cpp/00066.c} (100%) rename src/tests/{tests-c/00067.c.err => tests-cpp/00067.c} (100%) rename src/tests/{tests-c/00068.c.err => tests-cpp/00068.c} (100%) rename src/tests/{tests-c/00069.c.err => tests-cpp/00069.c} (100%) rename src/tests/{tests-c/00070.c.err => tests-cpp/00070.c} (100%) rename src/tests/{tests-c/00071.c.err => tests-cpp/00071.c} (100%) rename src/tests/{tests-c/00074.c.err => tests-cpp/00074.c} (100%) rename src/tests/{tests-c => tests-cpp}/00115.c (100%) rename src/tests/{tests-c => tests-cpp}/00122.c (100%) rename src/tests/{tests-c => tests-cpp}/00137.c (100%) rename src/tests/{tests-c => tests-cpp}/00162.c (100%) rename src/tests/{tests-c => tests-cpp}/00200.c (100%) rename src/tests/{tests-c => tests-cpp}/00202.c (100%) rename src/tests/{tests-c => tests-cpp}/00210.c (100%) rename src/tests/{tests-c => tests-cpp}/00219.c (100%) rename src/tests/{tests-c => tests-err}/00204.c (100%) delete mode 100644 src/tests/tests-parsimony/010 delete mode 100644 src/tests/tests-parsimony/010.c diff --git a/src/c b/src/c new file mode 100644 index 0000000..0c535d6 --- /dev/null +++ b/src/c @@ -0,0 +1,15 @@ +ccmeta.c: oop idKeys = map_keys(keys); +ccmeta.c:oop prim_keys(oop scope, oop params) +ccmeta.c: if (is(Map, arg)) return map_keys(arg); +ccmeta.c:oop prim_all_keys(oop scope, oop params) +ccmeta.c: println(map_keys(yylval)); +ccmeta.c: map_set(globals, intern("keys" ), makeFunction(prim_keys, intern("keys" ), null, null, globals, null)); +ccmeta.c: map_set(globals, intern("_keys" ), makeFunction(prim_all_keys, intern("_keys" ), null, null, globals, null)); +ccmeta.leg: oop idKeys = map_keys(keys); +ccmeta.leg:oop prim_keys(oop scope, oop params) +ccmeta.leg: if (is(Map, arg)) return map_keys(arg); +ccmeta.leg:oop prim_all_keys(oop scope, oop params) +ccmeta.leg: println(map_keys(yylval)); +ccmeta.leg: map_set(globals, intern("keys" ), makeFunction(prim_keys, intern("keys" ), null, null, globals, null)); +ccmeta.leg: map_set(globals, intern("_keys" ), makeFunction(prim_all_keys, intern("_keys" ), null, null, globals, null)); +object.c:oop map_keys(oop map) diff --git a/src/ccmeta.leg b/src/ccmeta.leg index 795b3cc..b2cf436 100644 --- a/src/ccmeta.leg +++ b/src/ccmeta.leg @@ -103,24 +103,16 @@ jb_record *jbs= NULL; assert(jbs == &jbrec); \ jbs= jbrec.next -// this is the global scope -oop globals= 0; - -oop program= 0; - -oop prog_last= 0; - -oop prog_objects= 0; -oop objects_elements= 0; -oop objects_last= 0; - -oop prog_enums= 0; -oop prog_structs= 0; -oop prog_unions= 0; - -oop enum_last= 0; -oop struct_last= 0; -oop union_last= 0; +// this is the global scope and other global variable for parsimony lang +oop globals = 0; +oop program = 0; +oop prog_last = 0; +oop prog_unions = 0; +oop prog_enums = 0; +oop prog_structs = 0; +oop union_last = 0; +oop enum_last = 0; +oop struct_last = 0; #define DO_SYMBOLS() \ DO_PROTOS() _DO(__proto__) _DO(__name__) _DO(__default__) _DO(__arguments__) \ @@ -1482,8 +1474,11 @@ start = m:metaCatch { yylval= m } error = EOL* < (!EOL .)* EOL* (!EOL .)* > &{ error(yytext), 1 } +### A.1.3 Identifiers # Identifiers rules +# 6.4.2.1 + idOpt = id | {$$=newNullObject()} id = { $$= new_C_id(yytext) } - @@ -1505,22 +1500,28 @@ IDREST = IDFIRST | [0-9] digit = [0-9] -# universalCharacterName +### A.1.4 Universal character names +# universalCharacterName rule + +# 6.4.3 universalCharacterName = "\\u" hexQuad | "\\U" hexQuad hexQuad hexQuad = hexadecimalDigit hexadecimalDigit hexadecimalDigit hexadecimalDigit +### A.1.5 Constants # constant rule +# 6.4.4 + constant = characterConstant | floatingConstant | integerConstant | META_AT m:mvalue - +# 6.4.4.1 # integerConstant rule integerConstant = < ( hexadecimalConstant @@ -1549,6 +1550,7 @@ integerSuffix = ( [uU][lL]?[lL]? | [lL][lL]?[uU]? ) ( imaginarySuffix &{gn imaginarySuffix = [ij] +# 6.4.4.2 # floatingConstant rule floatingConstant = <( decimalFloatingConstant | hexadecimalFloatingConstant )> { $$= new_C_float(yytext); } - @@ -1577,6 +1579,7 @@ hexadecimalDigitSequence = hexadecimalDigit+ floatingSuffix = [fFlL] imaginarySuffix? # 6.4.4.4 +# characterConstant rule characterConstant = < "'" cCharSequence "'" > { $$= new_C_char(yytext) } - | < "L'" cCharSequence "'" > { $$= new_C_char(yytext) } - @@ -1597,8 +1600,11 @@ octalEscapeSequence = '\\' octalDigit octalDigit? octalDigit? hexadecimalEscapeSequence = '\\x' hexadecimalDigit+ +### A.1.6 String literals # stringLiteral rule +# 6.4.5 + stringLiteral = { listBegin(); } ( s:stringLiteralPart { listAppend(s) } | META_AT META_AT META_LPAREN m:meta_exp META_RPAREN { listAppend(m) } @@ -1609,8 +1615,11 @@ stringLiteralPart = < '"' sCharSequence '"' > { $$= new_C_string(y sCharSequence = ( escapeSequence | !EOL [^\"\\] )* #" +### A.2.1 Expressions # primaryExpression rule +# 6.5.1 + primaryExpression = META_AT ( META_LCB mstmts #| < [a-zA-Z][a-zA-Z0-9]* > @{ printf("<%s>\n", yytext); exit(0) } | mvalue @@ -1619,6 +1628,7 @@ primaryExpression = META_AT ( META_LCB mstmts | l:LPAREN x:expression r:RPAREN { $$= new_C_subexpr(l, x, r) } | l:LPAREN x:compoundStatement r:RPAREN &{gnu} { $$= new_C_subexpr(l, x, r) } +# 6.5.2 # postfixExpression rule postfixExpression = o:LPAREN l:typeName p:RPAREN @@ -1638,6 +1648,7 @@ argumentExpressionList = { listBegin() } )* )? { $$= listEnd() } +# 6.5.3 # unaryExpression rule unaryExpression = o:INC x:unaryExpression { $$= new_C_prefix(o, x) } @@ -1657,11 +1668,13 @@ unaryOperator = BAND | STAR | PLUS | MINUS | BNOT | LNOT | REAL &{gnu} | IMAG &{gnu} +# 6.5.4 # castExpression rule castExpression = l:LPAREN t:typeName r:RPAREN x:castExpression { $$= new_C_cast(l, t, r, x) } | unaryExpression +# 6.5.5 # multiplicativeExpression rule multiplicativeExpression = l:castExpression @@ -1670,6 +1683,7 @@ multiplicativeExpression = l:castExpression multiplicativeOperator = STAR | DIV | MOD +# 6.5.6 # additiveExpression rule additiveExpression = l:multiplicativeExpression @@ -1678,6 +1692,7 @@ additiveExpression = l:multiplicativeExpression additiveOperator = PLUS | MINUS +# 6.5.7 # shiftExpression rule shiftExpression = l:additiveExpression @@ -1686,6 +1701,7 @@ shiftExpression = l:additiveExpression shiftOperator = LSHIFT | RSHIFT +# 6.5.8 # relationalExpression rule relationalExpression = l:shiftExpression @@ -1694,6 +1710,7 @@ relationalExpression = l:shiftExpression relationalOperator = LT | LTE | GT | GTE +# 6.5.9 # equalityExpression rule equalityExpression = l:relationalExpression @@ -1702,36 +1719,42 @@ equalityExpression = l:relationalExpression equalityOperator = EQUAL | NOT_EQUAL +# 6.5.10 # andExpression rule andExpression = l:equalityExpression ( o:BAND r:equalityExpression { l= new_C_binary(l, o, r) } )* { $$= l } +# 6.5.11 # exclusiveOrExpression rule exclusiveOrExpression = l:andExpression ( o:BXOR r:andExpression { l= new_C_binary(l, o, r) } )* { $$= l } +# 6.5.12 # inclusiveOrExpression rule inclusiveOrExpression = l:exclusiveOrExpression ( o:BOR r:exclusiveOrExpression { l= new_C_binary(l, o, r) } )* { $$= l } +# 6.5.13 # logicalAndExpression rule logicalAndExpression = l:inclusiveOrExpression ( o:LAND r:inclusiveOrExpression { l= new_C_binary(l, o, r) } )* { $$= l } +# 6.5.14 # logicalOrExpression rule logicalOrExpression = l:logicalAndExpression ( o:LOR r:logicalAndExpression { l= new_C_binary(l, o, r) } )* { $$= l } +# 6.5.15 # conditionalExpression rule conditionalExpression = l:logicalOrExpression @@ -1740,6 +1763,7 @@ conditionalExpression = l:logicalOrExpression | { $$= l } ) +# 6.5.16 # assignmentExpressionOpt rule assignmentExpressionOpt = assignmentExpression | {$$=newNullObject()} @@ -1751,6 +1775,7 @@ assignmentOperator = ASSIGN | STAR_ASSIGN | DIV_ASSIGN | MOD_ASSIGN | PLUS_ASSIGN | MINUS_ASSIGN | LSHIFT_ASSIGN | RSHIFT_ASSIGN | BAND_ASSIGN | BXOR_ASSIGN | BOR_ASSIGN +# 6.5.17 # expression rule expression = l:assignmentExpression @@ -1761,8 +1786,11 @@ expressionOpt = expression | { $$= newNullObject() } constantExpression = conditionalExpression +### A.2.2 Declarations # declaration rule +# 6.7 + declaration = @{ C_declarationBegin() } ( s:declarationSpecifiers d:initDeclaratorListOpt @@ -1793,6 +1821,7 @@ initDeclarator = d:declarator ( a:ASSIGN i:initializer &{ !typedeffing } { d= new_C_binary(d, a, i) } )? { $$= d } +# 6.7.1 # storageClassSpecifier rule storageClassSpecifier = TYPEDEF @{ declarationTypedef() } @@ -1804,6 +1833,7 @@ parameterStorageClassSpecifier = REGISTER functionStorageClassSpecifier = EXTERN | STATIC +# 6.7.2 # typeSpecifier rule typeSpecifier = VOID | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | SIGNED | UNSIGNED | BOOL | COMPLEX @@ -1811,6 +1841,7 @@ typeSpecifier = VOID | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | SIGNED | U | structOrUnionSpecifier | enumSpecifier +# 6.7.2.1 # structOrUnionSpecifier rule structOrUnionSpecifier = s:structOrUnion @@ -1859,6 +1890,7 @@ structDeclarator = ( c:COLON e:constantExpression ( a:attributeSpecifiers { d= new_C_attribution(d, a) } )? { $$= d } +# 6.7.2.2 # enumSpecifier rule enumSpecifier = e:ENUM @@ -1879,16 +1911,19 @@ enumerator = i:id )* ( a:ASSIGN e:constantExpression | {a=e=newNullObject()} ) { $$= new_C_enumerator(i, a, e) } +# 6.7.3 # typeQualifier rule typeQualifier = CONST | RESTRICT | VOLATILE | __RESTRICT +# 6.7.4 # functionSpecifier rule functionSpecifier = INLINE | __INLINE +# 6.7.5 # declarator rule declarator = # An attribute specifier list may appear immediately before a declarator @@ -1959,6 +1994,7 @@ identifierList = i:id { listWith(i) } ( c:COMMA i:id { listAppend2(c, i) } )* { $$= listEnd() } +# 6.7.6 # typeName rule typeName = s:specifierQualifierList d:abstractDeclaratorOpt { $$= new_C_declaration(s, d, newNullObject()) } @@ -1982,6 +2018,7 @@ directAbstractDeclarator = @{int nonEmpty= 0} ) r:RBRACKET @{++nonEmpty} { d= new_C_array(d, l, s, q, t, e, r) } )* &{nonEmpty} { $$= d } +# 6.7.7 # typedefName rule typedefName = &{ isTypedefName(yytext) } { $$= new_C_id(yytext) } - @@ -1990,6 +2027,7 @@ typedefName = &{ isTypedefName(yytext) } { $$= new_C_id(yytext) } - | x:typeName r:RPAREN { $$= new_C_typeOf(t, l, x, newNullObject(), r) } ) &{gnu} +# 6.7.8 # initializer rule initializer = l:LCURLY i:initializerList ( c:COMMA | {c=newNullObject()} ) r:RCURLY { $$= new_C_initializer(l, i, c, r) } @@ -2014,8 +2052,11 @@ designatorList = { listB | l:DOT x:id { listAppend(new_C_binary(newNullObject(), l, x)) } )+ { $$= listEnd() } +### A.2.3 Statements # statement rule +# 6.8 + statement = expressionStatement | labeledStatement | compoundStatement @@ -2023,6 +2064,7 @@ statement = expressionStatement | iterationStatement | jumpStatement +# 6.8.1 # labeledStatement rule labeledStatement = i:id c:COLON @@ -2034,6 +2076,7 @@ labeledStatement = i:id c:COLON | c:CASE x:constantRange d:COLON s:statement &{gnu} { $$= new_C_case(c, x, d, s) } | d:DEFAULT c:COLON s:statement { $$= new_C_default(d, c, s) } +# 6.8.2 # compoundStatement rule compoundStatement = @{ C_scopeBegin() } @@ -2049,17 +2092,20 @@ compoundStatement = @{ C_scopeBegin() } @{ C_scopeEnd() } | &{ C_scopeAbort() } +# 6.8.3 # expressionStatement rule expressionStatement = SEMI | x:expression s:SEMI { $$= new_C_exprStatement(x, s) } +# 6.8.4 # selectionStatement rule selectionStatement = i:IF l:LPAREN x:expression r:RPAREN s:statement ( e:ELSE t:statement | {e=t=newNullObject()} ) { $$= new_C_if(i, l, x, r, s, e, t) } | s:SWITCH l:LPAREN x:expression r:RPAREN t:statement { $$= new_C_switch(s, l, x, r, t) } +# 6.8.5 # iterationStatement rule iterationStatement = w:WHILE l:LPAREN x:expression r:RPAREN s:statement { $$= new_C_while(w, l, x, r, s) } @@ -2069,6 +2115,7 @@ iterationStatement = w:WHILE l:LPAREN x:expression r:RPAREN s:statement | f:FOR l:LPAREN a:declaration b:expressionOpt u:SEMI c:expressionOpt r:RPAREN s:statement { $$= new_C_for(f, l, a, newNullObject(), b, u, c, r, s) } +# 6.8.6 # jumpStatement rule jumpStatement = g:GOTO i:id t:SEMI { $$= new_C_goto(g, newNullObject(), i, t) } @@ -2077,8 +2124,11 @@ jumpStatement = g:GOTO i:id t:SEMI { $$= new_C_goto(g, | r:RETURN x:expressionOpt t:SEMI { $$= new_C_return(r, x, t) } | g:GOTO s:STAR x:expression t:SEMI &{gnu} { $$= new_C_goto(g, s, x, t) } +### A.2.4 External definitions # externalDeclaration rule +# 6.9 + ## translationUnit = externalDeclaration+ externalDeclaration = { $$= newComment(yytext); } @@ -3603,15 +3653,6 @@ oop prim_keys(oop scope, oop params) return null; } -oop prim_all_keys(oop scope, oop params) -{ - if (map_hasIntegerKey(params, 0)) { - oop arg= get(params, Map, elements)[0].value; - if (is(Map, arg)) return map_allKeys(arg); - } - return null; -} - oop prim_values(oop scope, oop params) { if (map_hasIntegerKey(params, 0)) { @@ -4843,7 +4884,7 @@ void printTree(oop element, language id) { void init() { - # if (USE_GC) +# if (USE_GC) GC_INIT(); # endif @@ -4853,7 +4894,6 @@ void init() map_set(globals, intern("exit" ), makeFunction(prim_exit, intern("exit" ), null, null, globals, null)); map_set(globals, intern("keys" ), makeFunction(prim_keys, intern("keys" ), null, null, globals, null)); - map_set(globals, intern("_keys" ), makeFunction(prim_all_keys, intern("_keys" ), null, null, globals, null)); map_set(globals, intern("values" ), makeFunction(prim_values, intern("values" ), null, null, globals, null)); map_set(globals, intern("length" ), makeFunction(prim_length, intern("length" ), null, null, globals, null)); map_set(globals, intern("print" ), makeFunction(prim_print, intern("print" ), null, null, globals, null)); @@ -4889,22 +4929,28 @@ void init() DO_PROTOS() #undef _DO - program = makeMap(); - prog_enums = makeMap(); - prog_structs = makeMap(); - prog_unions = makeMap(); - prog_last = makeMap(); - enum_last = makeMap(); - struct_last = makeMap(); - union_last = makeMap(); - - map_set(prog_enums , intern("last" ), enum_last ); - map_set(prog_structs , intern("last" ), struct_last ); - map_set(prog_unions , intern("last" ), union_last ); - map_set(program , intern("structs" ), prog_structs ); - map_set(program , intern("unions" ), prog_unions ); - map_set(program , intern("enums" ), prog_enums ); - map_set(globals , intern("program" ), program ); + + // Initialisation of parsimony global variable + program = makeMap(); + prog_enums = makeMap(); + prog_structs = makeMap(); + prog_unions = makeMap(); + prog_last = makeMap(); + enum_last = makeMap(); + struct_last = makeMap(); + union_last = makeMap(); + + map_set(globals , intern("program"), program ); + + map_set(program , intern("structs"), prog_structs); + map_set(prog_structs, intern("last" ), struct_last ); + + map_set(program , intern("unions" ), prog_unions ); + map_set(prog_unions , intern("last" ), union_last ); + + map_set(program , intern("enums" ), prog_enums ); + map_set(prog_enums , intern("last" ), enum_last ); + fixScope(globals); @@ -4945,10 +4991,10 @@ int main(int argc, char **argv) } if (opt_g) { - if (nalloc < 1024) printf("[GC: %lli bytes allocated]\n", nalloc ); - else if (nalloc < 1024*1024) printf("[GC: %lli kB allocated]\n", nalloc / 1024 ); - else if (nalloc < 1024*1024*1024) printf("[GC: %.2f MB allocated]\n", (double)nalloc / ( 1024*1024)); - else printf("[GC: %.2f GB allocated]\n", (double)nalloc / (1024*1024*1024)); + if (nalloc < 1024) printf("[GC: %lli bytes allocated]\n", nalloc ); + else if (nalloc < 1024*1024) printf("[GC: %lli kB allocated]\n", nalloc / 1024 ); + else if (nalloc < 1024*1024*1024) printf("[GC: %.2f MB allocated]\n", (double)nalloc / ( 1024*1024)); + else printf("[GC: %.2f GB allocated]\n", (double)nalloc / (1024*1024*1024)); } @@ -4961,4 +5007,4 @@ int main(int argc, char **argv) // Local Variables: // indent-tabs-mode: nil -// End:- \ No newline at end of file +// End: diff --git a/src/object.c b/src/object.c index 22211f4..153931e 100644 --- a/src/object.c +++ b/src/object.c @@ -428,6 +428,8 @@ int oopcmp(oop a, oop b) } case String: return strcmp(get(a, String, value), get(b, String, value)); + case Symbol: + return strcmp(get(a, Symbol, name), get(b, Symbol, name)); default: { intptr_t l= (intptr_t)a, r= (intptr_t)b; if (l < r) return -1; diff --git a/src/parsimonyLibrary/boot.mc b/src/parsimonyLibrary/boot.mc index 6dd1ad6..593b3b5 100644 --- a/src/parsimonyLibrary/boot.mc +++ b/src/parsimonyLibrary/boot.mc @@ -59,7 +59,7 @@ continue; append(t, s[i]); } - s = treeCopy(t); + s = t; ret; } diff --git a/src/parsimonyLibrary/dynamicObjectExtDecl.mc b/src/parsimonyLibrary/dynamicObjectExtDecl.mc index 98f8b5c..401dc73 100644 --- a/src/parsimonyLibrary/dynamicObjectExtDecl.mc +++ b/src/parsimonyLibrary/dynamicObjectExtDecl.mc @@ -159,7 +159,7 @@ typedef struct __oop *oop; send(object, method) { - treeCopy(rmSemi(`declaration send(@@(newText(object)), @@(newText(method)));)); + rmSemi(`declaration send(@@(newText(object)), @@(newText(method)));); } everyExternalDeclaration(s) @@ -170,7 +170,7 @@ typedef struct __oop *oop; for (i=length(program.last.declarationL); i>0; i--) { program.last.declarationL[i] = program.last.declarationL[i-1]; }; - program.last.declarationL[0] = treeCopy(`declaration int class; ); + program.last.declarationL[0] = `declaration int class; ; program.objects.function = "none"; return s; } @@ -184,14 +184,14 @@ typedef struct __oop *oop; param = rmSemi(`declaration struct __oop *__self;); if (length(s.declarators.paramTypeL) > 0) { append(s.declarators.paramTypeL, newComma()); - append(s.declarators.paramTypeL, treeCopy(param)); + append(s.declarators.paramTypeL, param); } else { s.declarators.paramTypeL = {}; - s.declarators.paramTypeL[0] = treeCopy(param); + s.declarators.paramTypeL[0] = param; } tmp = {}; tmp[0] = makeln(`declaration struct @@(newId(program.objects.currentClassName, " ")) *self = (struct @@(newId(program.objects.currentClassName, " ")) *) __self;, 1); - s.compoundS.expression = treeCopy(fusion(tmp, s.compoundS.expression)); + s.compoundS.expression = fusion(tmp, s.compoundS.expression); program.objects.function = "none"; return s; } @@ -199,7 +199,7 @@ typedef struct __oop *oop; if (program.objects.function == "constructor") { rawDeclaration = makeln(`declaration class = findClass(@@(newText("\"" + program.objects.currentClassName + "\"")));, 1); t = {}; - append(t, treeCopy(makeln(`declaration struct @@(newId(program.objects.currentClassName, " ")) *self = calloc(1, sizeof *self);, 1))); + append(t, makeln(`declaration struct @@(newId(program.objects.currentClassName, " ")) *self = calloc(1, sizeof *self);, 1)); // take the structure of self->foo lhs = treeCopy(s.compoundS.expression[0].expression.lhs); lhs.rhs = newId("class", " "); @@ -217,15 +217,15 @@ typedef struct __oop *oop; t = {}; for(i in program.objects.methods) { methodName = string(program.objects.methods[i]); - append(t, treeCopy(makeln(`declaration int @@(newId("_selector_" + methodName)) = findSelector(@@(newId("\"" + methodName + "\"")));, 1))); + append(t, makeln(`declaration int @@(newId("_selector_" + methodName)) = findSelector(@@(newId("\"" + methodName + "\"")));, 1)); } for (i in program.objects.class) { - className = string(i); // can't work other way - append(t, treeCopy(makeln(`declaration int @@(newId("_class_" + className)) = findClass(@@(newId("\"" + className + "\"")));, 1))); + className = string(i); + append(t, makeln(`declaration int @@(newId("_class_" + className)) = findClass(@@(newId("\"" + className + "\"")));, 1)); for (k in program.objects.class[i]) { - linkedMethod = string(program.objects.class[i][k]); - castMethod = "(method_t) " + className + "_" + linkedMethod; - append(t, treeCopy(makeln(`declaration addMethod(@@(newId("_class_" + className)), @@(newId("_selector_" + linkedMethod)), @@(newId(castMethod)));, 1))); + linkedMethod = string(program.objects.class[i][k]); + castMethod = "(method_t) " + className + "_" + linkedMethod; + append(t, makeln(`declaration addMethod(@@(newId("_class_" + className)), @@(newId("_selector_" + linkedMethod)), @@(newId(castMethod)));, 1)); } } s.compoundS.expression = fusion(t, s.compoundS.expression); @@ -235,4 +235,4 @@ typedef struct __oop *oop; } nil; -} \ No newline at end of file +} diff --git a/src/parsimonyLibrary/dynamicObjectParsFrom.mc b/src/parsimonyLibrary/dynamicObjectParsFrom.mc index 23b96ef..26c89b7 100644 --- a/src/parsimonyLibrary/dynamicObjectParsFrom.mc +++ b/src/parsimonyLibrary/dynamicObjectParsFrom.mc @@ -145,7 +145,7 @@ typedef struct __oop *oop; for (i=length(exp.specifiers[0].declarationL); i>0; i--) { exp.specifiers[0].declarationL[i] = exp.specifiers[0].declarationL[i-1]; }; - exp.specifiers[0].declarationL[0] = treeCopy(`declaration int class; ); + exp.specifiers[0].declarationL[0] = `declaration int class; ; exp; } @@ -161,14 +161,14 @@ typedef struct __oop *oop; param = rmSemi(`declaration struct __oop *__self;); if (length(decl.declarators.paramTypeL) > 0) { append(decl.declarators.paramTypeL, newComma()); - append(decl.declarators.paramTypeL, treeCopy(param)); + append(decl.declarators.paramTypeL, param); } else { decl.declarators.paramTypeL = {}; - decl.declarators.paramTypeL[0] = treeCopy(param); + decl.declarators.paramTypeL[0] = param; } tmp = {}; tmp[0] = makeln(`declaration struct @@(newId(id, " ")) *self = (struct @@(newId(id, " ")) *) __self;, 1); - decl.compoundS.expression = treeCopy(fusion(tmp, decl.compoundS.expression)); + decl.compoundS.expression = fusion(tmp, decl.compoundS.expression); program.objects.function = "none"; decl; } @@ -178,7 +178,7 @@ typedef struct __oop *oop; decl = parseFrom("func"); rawDeclaration = makeln(`declaration class = findClass(@@(newText("\"" + id + "\"")));, 1); t = {}; - append(t, treeCopy(makeln(`declaration struct @@(newId(id, " ")) *self = calloc(1, sizeof *self);, 1))); + append(t, makeln(`declaration struct @@(newId(id, " ")) *self = calloc(1, sizeof *self);, 1)); // take the structure of self->foo lhs = treeCopy(decl.compoundS.expression[0].expression.lhs); lhs.rhs = newId("class", " "); @@ -197,13 +197,13 @@ typedef struct __oop *oop; { // object = string(parseFrom("id").identifier); method = parseFrom("error"); - // treeCopy(rmSemi(`declaration send(@@(newText(object)), @@(newText(method)));)); + // rmSemi(`declaration send(@@(newText(object)), @@(newText(method)));); nil; } send(object, method) { - treeCopy(rmSemi(`declaration send(@@(newText(object)), @@(newText(method)));)); + rmSemi(`declaration send(@@(newText(object)), @@(newText(method)));); } everyExternalDeclaration(s) @@ -213,15 +213,15 @@ typedef struct __oop *oop; t = {}; for(i in program.objects.methods) { methodName = string(program.objects.methods[i]); - append(t, treeCopy(makeln(`declaration int @@(newId("_selector_" + methodName)) = findSelector(@@(newId("\"" + methodName + "\"")));, 1))); + append(t, makeln(`declaration int @@(newId("_selector_" + methodName)) = findSelector(@@(newId("\"" + methodName + "\"")));, 1)); } for (i in program.objects.class) { - className = string(i); // can't work other way - append(t, treeCopy(makeln(`declaration int @@(newId("_class_" + className)) = findClass(@@(newId("\"" + className + "\"")));, 1))); + className = string(i); + append(t, makeln(`declaration int @@(newId("_class_" + className)) = findClass(@@(newId("\"" + className + "\"")));, 1)); for (k in program.objects.class[i]) { linkedMethod = string(program.objects.class[i][k]); castMethod = "(method_t) " + className + "_" + linkedMethod; - append(t, treeCopy(makeln(`declaration addMethod(@@(newId("_class_" + className)), @@(newId("_selector_" + linkedMethod)), @@(newId(castMethod)));, 1))); + append(t, makeln(`declaration addMethod(@@(newId("_class_" + className)), @@(newId("_selector_" + linkedMethod)), @@(newId(castMethod)));, 1)); } } s.compoundS.expression = fusion(t, s.compoundS.expression); @@ -231,4 +231,4 @@ typedef struct __oop *oop; } nil; -} \ No newline at end of file +} diff --git a/src/tests/tests-c/00104.c b/src/tests/tests-c/00104.c index d28acef..a55a71e 100644 --- a/src/tests/tests-c/00104.c +++ b/src/tests/tests-c/00104.c @@ -1,5 +1,9 @@ #include +typedef int int32_t; +typedef long int64_t; + + int main() { diff --git a/src/tests/tests-c/00187.c b/src/tests/tests-c/00187.c index b986093..26bc680 100644 --- a/src/tests/tests-c/00187.c +++ b/src/tests/tests-c/00187.c @@ -1,5 +1,7 @@ #include +typedef struct FILE FILE; + int main() { FILE *f = fopen("fred.txt", "w"); diff --git a/src/tests/tests-c/00189.c b/src/tests/tests-c/00189.c index 697bd79..57df055 100644 --- a/src/tests/tests-c/00189.c +++ b/src/tests/tests-c/00189.c @@ -1,5 +1,8 @@ #include +typedef struct FILE FILE; +FILE *stdout; + int fred(int p) { printf("yo %d\n", p); diff --git a/src/tests/tests-c/00220.c b/src/tests/tests-c/00220.c index 96fbab0..460fb3f 100644 --- a/src/tests/tests-c/00220.c +++ b/src/tests/tests-c/00220.c @@ -2,6 +2,8 @@ #include #include +typedef int wchar_t; + int main() { wchar_t s[] = L"hello$$你好¢¢世界€€world"; diff --git a/src/tests/tests-c/00062.c.err b/src/tests/tests-cpp/00062.c similarity index 100% rename from src/tests/tests-c/00062.c.err rename to src/tests/tests-cpp/00062.c diff --git a/src/tests/tests-c/00063.c.err b/src/tests/tests-cpp/00063.c similarity index 100% rename from src/tests/tests-c/00063.c.err rename to src/tests/tests-cpp/00063.c diff --git a/src/tests/tests-c/00066.c.err b/src/tests/tests-cpp/00066.c similarity index 100% rename from src/tests/tests-c/00066.c.err rename to src/tests/tests-cpp/00066.c diff --git a/src/tests/tests-c/00067.c.err b/src/tests/tests-cpp/00067.c similarity index 100% rename from src/tests/tests-c/00067.c.err rename to src/tests/tests-cpp/00067.c diff --git a/src/tests/tests-c/00068.c.err b/src/tests/tests-cpp/00068.c similarity index 100% rename from src/tests/tests-c/00068.c.err rename to src/tests/tests-cpp/00068.c diff --git a/src/tests/tests-c/00069.c.err b/src/tests/tests-cpp/00069.c similarity index 100% rename from src/tests/tests-c/00069.c.err rename to src/tests/tests-cpp/00069.c diff --git a/src/tests/tests-c/00070.c.err b/src/tests/tests-cpp/00070.c similarity index 100% rename from src/tests/tests-c/00070.c.err rename to src/tests/tests-cpp/00070.c diff --git a/src/tests/tests-c/00071.c.err b/src/tests/tests-cpp/00071.c similarity index 100% rename from src/tests/tests-c/00071.c.err rename to src/tests/tests-cpp/00071.c diff --git a/src/tests/tests-c/00074.c.err b/src/tests/tests-cpp/00074.c similarity index 100% rename from src/tests/tests-c/00074.c.err rename to src/tests/tests-cpp/00074.c diff --git a/src/tests/tests-c/00115.c b/src/tests/tests-cpp/00115.c similarity index 100% rename from src/tests/tests-c/00115.c rename to src/tests/tests-cpp/00115.c diff --git a/src/tests/tests-c/00122.c b/src/tests/tests-cpp/00122.c similarity index 100% rename from src/tests/tests-c/00122.c rename to src/tests/tests-cpp/00122.c diff --git a/src/tests/tests-c/00137.c b/src/tests/tests-cpp/00137.c similarity index 100% rename from src/tests/tests-c/00137.c rename to src/tests/tests-cpp/00137.c diff --git a/src/tests/tests-c/00162.c b/src/tests/tests-cpp/00162.c similarity index 100% rename from src/tests/tests-c/00162.c rename to src/tests/tests-cpp/00162.c diff --git a/src/tests/tests-c/00200.c b/src/tests/tests-cpp/00200.c similarity index 100% rename from src/tests/tests-c/00200.c rename to src/tests/tests-cpp/00200.c diff --git a/src/tests/tests-c/00202.c b/src/tests/tests-cpp/00202.c similarity index 100% rename from src/tests/tests-c/00202.c rename to src/tests/tests-cpp/00202.c diff --git a/src/tests/tests-c/00210.c b/src/tests/tests-cpp/00210.c similarity index 100% rename from src/tests/tests-c/00210.c rename to src/tests/tests-cpp/00210.c diff --git a/src/tests/tests-c/00219.c b/src/tests/tests-cpp/00219.c similarity index 100% rename from src/tests/tests-c/00219.c rename to src/tests/tests-cpp/00219.c diff --git a/src/tests/tests-c/00204.c b/src/tests/tests-err/00204.c similarity index 100% rename from src/tests/tests-c/00204.c rename to src/tests/tests-err/00204.c diff --git a/src/tests/tests-parsimony/008.c b/src/tests/tests-parsimony/008.c index 039f6da..52dc0d5 100644 --- a/src/tests/tests-parsimony/008.c +++ b/src/tests/tests-parsimony/008.c @@ -1,16 +1,6 @@ @{ - newText(x) { { value: x, __proto__: C_string }; } - f(n) { - program.tmp = n; - `declaration int @@(newText(treeCopy(program.tmp)));; - } - - + `declaration int @@(n);; + } f("x"); -} - -@{ - program.tmp = "y"; - nil; } \ No newline at end of file diff --git a/src/tests/tests-parsimony/009 b/src/tests/tests-parsimony/009 index 4c2f455..2c1ccd8 100644 --- a/src/tests/tests-parsimony/009 +++ b/src/tests/tests-parsimony/009 @@ -1 +1,8 @@ -int x; \ No newline at end of file +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 diff --git a/src/tests/tests-parsimony/009.c b/src/tests/tests-parsimony/009.c index 818e2d6..aba28cf 100644 --- a/src/tests/tests-parsimony/009.c +++ b/src/tests/tests-parsimony/009.c @@ -1,10 +1,15 @@ @{ - newText(x) { { value: x, __proto__: C_string }; } - - f(n) { - `declaration int @@(newText(treeCopy(n)));; - } + f(x, y, z) { + print("x = ", x, ", y = ", y, ", z = ", z, "\n"); + nil; + } - - f("x"); + 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); } \ No newline at end of file diff --git a/src/tests/tests-parsimony/010 b/src/tests/tests-parsimony/010 deleted file mode 100644 index 2c1ccd8..0000000 --- a/src/tests/tests-parsimony/010 +++ /dev/null @@ -1,8 +0,0 @@ -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 diff --git a/src/tests/tests-parsimony/010.c b/src/tests/tests-parsimony/010.c deleted file mode 100644 index aba28cf..0000000 --- a/src/tests/tests-parsimony/010.c +++ /dev/null @@ -1,15 +0,0 @@ -@{ - 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); -} \ No newline at end of file diff --git a/src/tests/tests-parsimony/realObjectED b/src/tests/tests-parsimony/realObjectED index 5af0df4..a4ebc37 100644 --- a/src/tests/tests-parsimony/realObjectED +++ b/src/tests/tests-parsimony/realObjectED @@ -134,11 +134,11 @@ double Point_getX(struct __oop *__self) int main() { - int _selector_magnitude= findSelector("magnitude"); int _selector_getX= findSelector("getX"); + int _selector_magnitude= findSelector("magnitude"); int _class_Point= findClass("Point"); - addMethod(_class_Point, _selector_magnitude, (method_t) Point_magnitude); addMethod(_class_Point, _selector_getX, (method_t) Point_getX); + addMethod(_class_Point, _selector_magnitude, (method_t) Point_magnitude); oop p = newPoint(3, 4); send(p, magnitude); diff --git a/src/tests/tests-parsimony/realObjectPF b/src/tests/tests-parsimony/realObjectPF index dbfa178..724be22 100644 --- a/src/tests/tests-parsimony/realObjectPF +++ b/src/tests/tests-parsimony/realObjectPF @@ -134,11 +134,11 @@ double Point_getX(struct __oop *__self) int main() { - int _selector_magnitude= findSelector("magnitude"); int _selector_getX= findSelector("getX"); + int _selector_magnitude= findSelector("magnitude"); int _class_Point= findClass("Point"); - addMethod(_class_Point, _selector_magnitude, (method_t) Point_magnitude); addMethod(_class_Point, _selector_getX, (method_t) Point_getX); + addMethod(_class_Point, _selector_magnitude, (method_t) Point_magnitude); oop p = newPoint(3, 4); // @send p magnitude();