Bläddra i källkod

Rearranging the repository, and improving the readme

develop-theo
Theo Souchon 2 år sedan
förälder
incheckning
14d9f8fde5
507 ändrade filer med 4308 tillägg och 363 borttagningar
  1. +18
    -2
      README.md
  2. +0
    -161
      parsimonyLibrary/fake-static-classes.mc
  3. +1
    -0
      src/Makefile
  4. +0
    -0
      src/buffer.h
  5. +0
    -0
      src/ccmeta-input.txt
  6. +96
    -87
      src/ccmeta.leg
  7. +0
    -0
      src/debug.c
  8. +15
    -4
      src/dotest
  9. +0
    -0
      src/images/ccmeta.drawio.png
  10. +6
    -0
      src/object.c
  11. +0
    -19
      src/parsimonyLibrary/boot.mc
  12. +0
    -0
      src/parsimonyLibrary/dynamicObject.c
  13. +6
    -4
      src/parsimonyLibrary/dynamicObjectExtDecl.mc
  14. +241
    -0
      src/parsimonyLibrary/dynamicObjectParsFrom.mc
  15. +1
    -0
      src/protoNumber.txt
  16. +0
    -0
      src/scope.c
  17. +0
    -0
      src/tests/tests-c/00001.c
  18. +5
    -0
      src/tests/tests-c/00001.out
  19. +0
    -0
      src/tests/tests-c/00002.c
  20. +5
    -0
      src/tests/tests-c/00002.out
  21. +0
    -0
      src/tests/tests-c/00003.c
  22. +8
    -0
      src/tests/tests-c/00003.out
  23. +0
    -0
      src/tests/tests-c/00004.c
  24. +12
    -0
      src/tests/tests-c/00004.out
  25. +0
    -0
      src/tests/tests-c/00005.c
  26. +23
    -0
      src/tests/tests-c/00005.out
  27. +0
    -0
      src/tests/tests-c/00006.c
  28. +10
    -0
      src/tests/tests-c/00006.out
  29. +0
    -0
      src/tests/tests-c/00007.c
  30. +15
    -0
      src/tests/tests-c/00007.out
  31. +0
    -0
      src/tests/tests-c/00008.c
  32. +11
    -0
      src/tests/tests-c/00008.out
  33. +0
    -0
      src/tests/tests-c/00009.c
  34. +11
    -0
      src/tests/tests-c/00009.out
  35. +0
    -0
      src/tests/tests-c/00010.c
  36. +13
    -0
      src/tests/tests-c/00010.out
  37. +0
    -0
      src/tests/tests-c/00011.c
  38. +8
    -0
      src/tests/tests-c/00011.out
  39. +0
    -0
      src/tests/tests-c/00012.c
  40. +5
    -0
      src/tests/tests-c/00012.out
  41. +0
    -0
      src/tests/tests-c/00013.c
  42. +10
    -0
      src/tests/tests-c/00013.out
  43. +0
    -0
      src/tests/tests-c/00014.c
  44. +11
    -0
      src/tests/tests-c/00014.out
  45. +0
    -0
      src/tests/tests-c/00015.c
  46. +10
    -0
      src/tests/tests-c/00015.out
  47. +0
    -0
      src/tests/tests-c/00016.c
  48. +10
    -0
      src/tests/tests-c/00016.out
  49. +0
    -0
      src/tests/tests-c/00017.c
  50. +9
    -0
      src/tests/tests-c/00017.out
  51. +0
    -0
      src/tests/tests-c/00018.c
  52. +13
    -0
      src/tests/tests-c/00018.out
  53. +0
    -0
      src/tests/tests-c/00019.c
  54. +10
    -0
      src/tests/tests-c/00019.out
  55. +0
    -0
      src/tests/tests-c/00020.c
  56. +10
    -0
      src/tests/tests-c/00020.out
  57. +0
    -0
      src/tests/tests-c/00021.c
  58. +12
    -0
      src/tests/tests-c/00021.out
  59. +0
    -0
      src/tests/tests-c/00022.c
  60. +10
    -0
      src/tests/tests-c/00022.out
  61. +0
    -0
      src/tests/tests-c/00023.c
  62. +9
    -0
      src/tests/tests-c/00023.out
  63. +0
    -0
      src/tests/tests-c/00024.c
  64. +12
    -0
      src/tests/tests-c/00024.out
  65. +0
    -0
      src/tests/tests-c/00025.c
  66. +10
    -0
      src/tests/tests-c/00025.out
  67. +0
    -0
      src/tests/tests-c/00026.c
  68. +8
    -0
      src/tests/tests-c/00026.out
  69. +0
    -0
      src/tests/tests-c/00027.c
  70. +10
    -0
      src/tests/tests-c/00027.out
  71. +0
    -0
      src/tests/tests-c/00028.c
  72. +10
    -0
      src/tests/tests-c/00028.out
  73. +0
    -0
      src/tests/tests-c/00029.c
  74. +10
    -0
      src/tests/tests-c/00029.out
  75. +0
    -0
      src/tests/tests-c/00030.c
  76. +24
    -0
      src/tests/tests-c/00030.out
  77. +0
    -0
      src/tests/tests-c/00031.c
  78. +48
    -0
      src/tests/tests-c/00031.out
  79. +0
    -0
      src/tests/tests-c/00032.c
  80. +30
    -0
      src/tests/tests-c/00032.out
  81. +0
    -0
      src/tests/tests-c/00033.c
  82. +45
    -0
      src/tests/tests-c/00033.out
  83. +0
    -0
      src/tests/tests-c/00034.c
  84. +32
    -0
      src/tests/tests-c/00034.out
  85. +0
    -0
      src/tests/tests-c/00035.c
  86. +15
    -0
      src/tests/tests-c/00035.out
  87. +0
    -0
      src/tests/tests-c/00036.c
  88. +19
    -0
      src/tests/tests-c/00036.out
  89. +0
    -0
      src/tests/tests-c/00037.c
  90. +17
    -0
      src/tests/tests-c/00037.out
  91. +0
    -0
      src/tests/tests-c/00038.c
  92. +17
    -0
      src/tests/tests-c/00038.out
  93. +0
    -0
      src/tests/tests-c/00039.c
  94. +13
    -0
      src/tests/tests-c/00039.out
  95. +0
    -0
      src/tests/tests-c/00040.c
  96. +55
    -0
      src/tests/tests-c/00040.out
  97. +0
    -0
      src/tests/tests-c/00041.c
  98. +26
    -0
      src/tests/tests-c/00041.out
  99. +0
    -0
      src/tests/tests-c/00042.c
  100. +11
    -0
      src/tests/tests-c/00042.out

+ 18
- 2
README.md Visa fil

@ -13,10 +13,11 @@ C compiler with embedded metalanguage.
3. [Usage](#usage)
4. [Help](#help)
- [Peg/Leg](#pegleg)
5. [Authors](#authors)
## <div id="ar">Architecture<div>
![alt text](http://git.piumarta.com/piumarta/ccmeta/raw/branch/develop/media/ccmeta.drawio.png)
![alt text](http://git.piumarta.com/piumarta/ccmeta/raw/branch/develop/src/images/ccmeta.drawio.png)
### [Go to the table of contents](#toc)
## <div id="bp">Build the project<div>
@ -72,4 +73,19 @@ $ ./ccmeta file
``` shell
$ man peg
```
### [Go to the table of contents](#toc)
### [Go to the table of contents](#toc)
## <div id="authors">Authors<div>
#### Ian Piumarta (2016-)
- infrastructure
- parsing framework
- C grammar, C AST
- object system design and implementation
- metalanguage design and implementation
#### Mahe Tardy (2020)
- object system implementation
- metalanguage implementation
#### Nathan Razafimanantsoa, Kumar Mahadayya (2021)
- C AST

+ 0
- 161
parsimonyLibrary/fake-static-classes.mc Visa fil

@ -1,161 +0,0 @@
@import("parsimonyLibrary/boot.mc")
@{
// allows you to retrieve the type if it is pre-existing or created during compilation
checkIdorDecl(x) {
(x.identifier == null) ? x.declarators.identifier : x.identifier;
}
// allows you to retrieve the type if it is pre-existing or created during compilation
checkIdorText(x) {
(x.identifier == null) ? x.text : x.identifier;
}
program.objects = null;
// Initialisation of the object
beginObject(objectName, typeName) {
program.objects = {};
program.objects.elements = {};
program.objects.last = null;
objectName == null ? objectName = "oop" : objectName;
typeName == null ? typeName = "type_t" : typeName;
program.objects.elements[length(program.objects.elements)] = objectName;
program.objects.last = objectName;
l = {};
enum = `declaration typedef enum {_} type_t;;
enum.declarators[0].identifier = typeName;
enum.semicolon.comment = newComment(" ");
program.objects.enum = treeCopy(enum);
append(l, program.objects.enum);
obj = `declaration union object;;
obj.semicolon.comment = newComment(" ");
append(l, treeCopy(obj));
type_obj = `declaration typedef union object *oop;;
type_obj.declarators[0].declarators.identifier = objectName;
type_obj.semicolon.comment = newComment("\n\n");
append(l, treeCopy(type_obj));
l;
}
// Function to add dynamically an object
addObject() {
structName = treeCopy(newEnum(program.last.name.identifier));
l = length(program.enums.last.enumList);
if (string(program.objects.enum.specifiers[1].enumList[0].name.identifier) == "_" && l == 1) {
program.objects.enum.specifiers[1].enumList[0] = structName;
} else {
append(program.objects.enum.specifiers[1].enumList, newComma());
append(program.objects.enum.specifiers[1].enumList, structName);
}
for (i=length(program.last.declarationL); i>0; i--) {
program.last.declarationL[i] = program.last.declarationL[i-1];
};
newType = `declaration int type;;
newType.specifiers[0].text = program.objects.enum.declarators[0].identifier;
newType.semicolon.comment = newComment("\n ");
program.last.declarationL[0] = treeCopy(newType);
nil;
}
// Function triggered each time we met a struct
everyExternalDeclaration(s) {
if (program.objects) {
addObject()
}
s;
}
// Functions to get the macro
getObjectMacro() {
macro = `ed #define get(PTR, TYPE, FIELD) (_checkType(PTR, TYPE, __FILE__, __LINE__)->TYPE.FIELD)
;
macro;
}
// Functions to get the macro
setObjectMacro() {
macro = `ed #define set(PTR, TYPE, FIELD, VALUE) (_checkType(PTR, TYPE, __FILE__, __LINE__)->TYPE.FIELD = VALUE)
;
macro.text = macro.text + "\n";
macro;
}
getGeneralObject(x) {
func = `fun int getfoo(int obj) {
if (!isFoo(obj)) {
fprintf(stderr, "\ngetFoo call on non-foo\n");
exit(1);
}
return get(obj, foo, foo);
}
;
id = program.structs[x].declarationL[1].specifiers[0].identifier;
star = program.structs[x].declarationL[1].declarators[0].declarators.star;
if (id != null) {
program.structs[x].declarationL[1].specifiers[0].text = program.structs[x].declarationL[1].specifiers[0].identifier
}
if (star != null) {
func.specifiers[0].text = string(checkIdorText(program.structs[x].declarationL[1].specifiers[0])) + " *";
func.specifiers[0].comment = "";
} else {
func.specifiers[0].text = string(checkIdorText(program.structs[x].declarationL[1].specifiers[0]));
}
func.declarators.declarators.identifier = "get" + string(x);
func.compoundS.expression[0].condition.expression.declarators.identifier = "is" + string(x);
func.compoundS.expression[0].consequent.expression[0].expression.paramTypeL[2].text[0].value = "\"\\nget" + string(x) + " call on non-" + string(x) + "\\n\"";
func.compoundS.expression[1].expression.paramTypeL[2].identifier = string(x);
func.compoundS.expression[1].expression.paramTypeL[4].identifier = checkIdorDecl(program.structs[x].declarationL[length(program.structs[x].declarationL)-1].declarators[0].declarators);
func.declarators.paramTypeL[0].specifiers[0].text = program.objects.last;
treeCopy(func);
}
// Function to set up element useful to the programmer
endObject() {
l = {};
objectUnion = `declaration union object { int type; };;
objectUnion = treeCopy(objectUnion);
objectUnion.specifiers[0].declarationL[0].specifiers[0].text = program.objects.enum.declarators[0].identifier;
objectUnion.semicolon.comment = newComment("\n");
obj = select(notToken, program.objects.enum.specifiers[1].enumList);
elt = treeCopy(`declaration struct nil nil;);
for (i in obj) {
len = length(objectUnion.specifiers[0].declarationL);
elt.specifiers[0].name.identifier = elt.declarators[0].identifier = obj[i].name.identifier;
objectUnion.specifiers[0].declarationL[len] = treeCopy(elt);
objectUnion.specifiers[0].declarationL[len].semicolon.comment = newComment(" ");
}
append(l, objectUnion);
isDef = `declaration int is(int type, int obj);;
isDef.declarators[0].paramTypeL[0].specifiers[0].text = program.objects.enum.declarators[0].identifier;
isDef.declarators[0].paramTypeL[2].specifiers[0].text = program.objects.last;
isDef.semicolon.comment = newComment("\n");
append(l, isDef);
func = `fun int isFoo(int obj) { return is(foo, obj); };
func.declarators.paramTypeL[0].specifiers[0].text = program.objects.last;
func.compoundS.rightCurly.comment = newComment("\n");
for (i in obj) {
func.declarators.declarators.identifier = "is" + string(obj[i].name.identifier);
func.compoundS.expression[0].expression.paramTypeL[0].identifier = obj[i].name.identifier;
append(l, treeCopy(func));
}
func = `fun int getType(int ptr) { assert(ptr); return ptr->type; };
func.specifiers[0].text = program.objects.enum.declarators[0].identifier;
func.declarators.paramTypeL[0].specifiers[0].text = program.objects.last;
func.compoundS.rightCurly.comment = newComment("\n");
append(l, treeCopy(func));
func = `fun int is(int type, int obj) { return type == getType(obj); };
func.declarators.paramTypeL[0].specifiers[0].text = program.objects.enum.declarators[0].identifier;
func.declarators.paramTypeL[2].specifiers[0].text = program.objects.last;
func.compoundS.rightCurly.comment = newComment("\n");
append(l, treeCopy(func));
append(l, treeCopy(getObjectMacro()));
append(l, treeCopy(setObjectMacro()));
program.objects = null;
l;
}
nil;
}

Makefile → src/Makefile Visa fil

@ -40,6 +40,7 @@ clean : .FORCE
rm -f $(MAIN) $(MAIN).c
rm -f *~ $(MAIN)-output.out
rm -rf */*.out
rm -rf ccmeta.dSYM
tidy : .FORCE
rm -f *~ $(MAIN)-tree.out

buffer.h → src/buffer.h Visa fil


ccmeta-input.txt → src/ccmeta-input.txt Visa fil


ccmeta.leg → src/ccmeta.leg Visa fil

@ -94,13 +94,13 @@ typedef struct jb_record
jb_record *jbs= NULL;
#define jbRecPush() \
struct jb_record jbrec; \
#define jbRecPush() \
struct jb_record jbrec; \
jbrec.next= jbs; \
jbs= &jbrec
#define jbRecPop() \
assert(jbs == &jbrec); \
#define jbRecPop() \
assert(jbs == &jbrec); \
jbs= jbrec.next
// this is the global scope
@ -902,6 +902,7 @@ oop new_C_enumerator(oop id, oop attributeSpecifier, oop expression) {
return object;
}
//TODO
#define YY_INPUT(buf, result, max_size) \
{ \
int yyc= feof(inputStack->file) ? EOF : getc(inputStack->file); \
@ -1453,9 +1454,7 @@ start = m:metaCatch { yylval= m }
error = EOL* < (!EOL .)* EOL* (!EOL .)* > &{ error(yytext), 1 }
### A.1.3 Identifiers
# 6.4.2.1
# Identifiers rules
idOpt = id | {$$=newNullObject()}
@ -1478,29 +1477,23 @@ IDREST = IDFIRST | [0-9]
digit = [0-9]
### A.1.4 Universal character names
# 6.4.3
# universalCharacterName
universalCharacterName = "\\u" hexQuad
| "\\U" hexQuad hexQuad
hexQuad = hexadecimalDigit hexadecimalDigit hexadecimalDigit hexadecimalDigit
###
### A.1.5 Constants
# 6.4.4
# constant rule
constant = characterConstant
| floatingConstant
| integerConstant
| META_AT m:mvalue
| META_AT m:mvalue
# 6.4.4.1
# integerConstant rule
integerConstant = < ( hexadecimalConstant
| octalConstant
@ -1528,7 +1521,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); } -
@ -1576,9 +1569,7 @@ octalEscapeSequence = '\\' octalDigit octalDigit? octalDigit?
hexadecimalEscapeSequence = '\\x' hexadecimalDigit+
### A.1.6 String literals
# 6.4.5
# stringLiteral rule
stringLiteral = { listBegin(); }
( s:stringLiteralPart { listAppend(s) }
@ -1590,18 +1581,16 @@ stringLiteralPart = < '"' sCharSequence '"' > { $$= new_C_string(y
sCharSequence = ( escapeSequence | !EOL [^\"\\] )* #"
### A.2.1 Expressions
# 6.5.1
# primaryExpression rule
primaryExpression = stringLiteral | constant | id
| META_AT ( META_LCB x:mstmts
| x:mvalue
| x:mvalue
)
| 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
a:LCURLY r:initializerList ( c:COMMA | {c=newNullObject()} ) b:RCURLY { $$= new_C_aggregate(o, l, p, a, r, c, b) }
@ -1620,7 +1609,7 @@ argumentExpressionList = { listBegin() }
)*
)? { $$= listEnd() }
# 6.5.3
# unaryExpression rule
unaryExpression = o:INC x:unaryExpression { $$= new_C_prefix(o, x) }
| o:DEC x:unaryExpression { $$= new_C_prefix(o, x) }
@ -1639,12 +1628,12 @@ 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
( o:multiplicativeOperator r:castExpression { l= new_C_binary(l, o, r) }
@ -1652,7 +1641,7 @@ multiplicativeExpression = l:castExpression
multiplicativeOperator = STAR | DIV | MOD
# 6.5.6
# additiveExpression rule
additiveExpression = l:multiplicativeExpression
( o:additiveOperator r:multiplicativeExpression { l= new_C_binary(l, o, r) }
@ -1660,7 +1649,7 @@ additiveExpression = l:multiplicativeExpression
additiveOperator = PLUS | MINUS
# 6.5.7
# shiftExpression rule
shiftExpression = l:additiveExpression
( o:shiftOperator r:additiveExpression { l= new_C_binary(l, o, r) }
@ -1668,7 +1657,7 @@ shiftExpression = l:additiveExpression
shiftOperator = LSHIFT | RSHIFT
# 6.5.8
# relationalExpression rule
relationalExpression = l:shiftExpression
( o:relationalOperator r:shiftExpression { l= new_C_binary(l, o, r) }
@ -1676,7 +1665,7 @@ relationalExpression = l:shiftExpression
relationalOperator = LT | LTE | GT | GTE
# 6.5.9
# equalityExpression rule
equalityExpression = l:relationalExpression
( o:equalityOperator r:relationalExpression { l= new_C_binary(l, o, r) }
@ -1684,37 +1673,37 @@ 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
( q:QUESTION m:expression c:COLON r:conditionalExpression { $$= new_C_conditional(l, q, m, c, r) }
@ -1722,7 +1711,7 @@ conditionalExpression = l:logicalOrExpression
| { $$= l }
)
# 6.5.16
# assignmentExpressionOpt rule
assignmentExpressionOpt = assignmentExpression | {$$=newNullObject()}
@ -1733,7 +1722,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
( o:COMMA r:assignmentExpression { l= new_C_binary(l, o, r) }
@ -1743,9 +1732,7 @@ expressionOpt = expression | { $$= newNullObject() }
constantExpression = conditionalExpression
### A.2.2 Declarations
# 6.7
# declaration rule
declaration = @{ C_declarationBegin() }
( s:declarationSpecifiers
@ -1777,7 +1764,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() }
| AUTO
@ -1788,14 +1775,14 @@ parameterStorageClassSpecifier = REGISTER
functionStorageClassSpecifier = EXTERN | STATIC
# 6.7.2
# typeSpecifier rule
typeSpecifier = VOID | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | SIGNED | UNSIGNED | BOOL | COMPLEX
| ( BUILTIN_VA_LIST | _FLOAT128 )
| structOrUnionSpecifier
| enumSpecifier
# 6.7.2.1
# structOrUnionSpecifier rule
structOrUnionSpecifier = s:structOrUnion
# An attribute specifier list may appear as part of a struct, union or enum specifier. It may go
@ -1843,7 +1830,7 @@ structDeclarator = ( c:COLON e:constantExpression
( a:attributeSpecifiers { d= new_C_attribution(d, a) }
)? { $$= d }
# 6.7.2.2
# enumSpecifier rule
enumSpecifier = e:ENUM
( i:idOpt l:LCURLY m:enumeratorList r:RCURLY { $$= new_C_enumSpec(e, i, l, m, r) }
@ -1863,17 +1850,17 @@ 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
a:attributeSpecifier d:declarator &{gnu} { $$= new_C_attribution(a, d) }
@ -1943,7 +1930,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()) }
@ -1966,7 +1953,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 = <ID> &{ isTypedefName(yytext) } { $$= new_C_id(yytext) } -
| t:TYPEOF l:LPAREN
@ -1974,11 +1961,10 @@ 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) }
| assignmentExpression
| META_AT m:mvalue
initializerList = { listBegin() }
( d:designation { listAppend(d) }
@ -1999,9 +1985,7 @@ designatorList = { listB
| l:DOT x:id { listAppend(new_C_binary(newNullObject(), l, x)) }
)+ { $$= listEnd() }
### A.2.3 Statements
# 6.8
# statement rule
statement = expressionStatement
| labeledStatement
@ -2010,7 +1994,7 @@ statement = expressionStatement
| iterationStatement
| jumpStatement
# 6.8.1
# labeledStatement rule
labeledStatement = i:id c:COLON
# an attribute specifier list may appear after
@ -2021,7 +2005,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() }
l:LCURLY { listBegin() }
@ -2036,18 +2020,18 @@ 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) }
| d:DO s:statement w:WHILE l:LPAREN x:expression r:RPAREN t:SEMI { $$= new_C_do(d, s, w, l, x, r, t) }
@ -2056,7 +2040,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) }
| c:CONTINUE t:SEMI { $$= new_C_continue(c, t) }
@ -2064,9 +2048,7 @@ 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
# 6.9
# externalDeclaration rule
## translationUnit = externalDeclaration+
@ -2306,15 +2288,15 @@ _FLOAT128 = '_Float128' !IDREST &{gnu} { $$= newToken("_Float128"
# input buffer from moving past it before redirecting input from the imported file
metaCatch = META_AT ( META_IMPORT s:META_STRING ";" { inputStackPush(get(s, String, value)) ; $$= 0 }
| m:mvalue { map_append(outputProgram, m) ; $$= null }
| META_LCB s:mstmts { map_append(outputProgram, s) ; $$= null }
| m:mvalue { $$= m }
| META_LCB s:mstmts { $$= s }
)
mvalue = ( i:META_IDENT { i= newGetVariable(i) } ( a:meta_argumentList { oop k = map_pop(a); i = newCall(i, a, k) } # call a function with argument
| { i = is(Function, eval(globals, i)) == 1 ? newCall(i, makeMap(), null) : i } # without
| { i = is(Function, eval(globals, i)) ? newCall(i, makeMap(), null) : i } # without
)
| META_LPAREN ( i:meta_exp ) META_RPAREN
) { $$= eval(globals, i) }
) { $$= eval(globals, i) }
mstmts = ( s:eval_stmt )* META_RCB { $$= s } # return the last stmt
@ -2533,26 +2515,22 @@ META_FLOAT = < [-+]* [0-9]+ '.' [0-9]* ('e'[-+]*[0-9]+)? > { $$= make
#--------------------------------------------- Meta operator ----------------------------------------------#
MO_OPERATION = META_BACKTICK ( MO_INITIALIZER i:initializer { $$= newUnary(Quasiquote_proto, i) }
| MO_CONSTANT c:constant { $$= newUnary(Quasiquote_proto, c) }
| MO_STATEMENT s:statement { $$= newUnary(Quasiquote_proto, s) }
| MO_INTEGER i:integerConstant { $$= newUnary(Quasiquote_proto, i) }
| MO_DECLARATION d:declaration { $$= newUnary(Quasiquote_proto, d) }
MO_OPERATION = META_BACKTICK ( MO_CONSTANT c:constant { $$= newUnary(Quasiquote_proto, c) }
| MO_STRING s:stringLiteral { $$= newUnary(Quasiquote_proto, s) }
| MO_EXPRESSION e:expression { $$= newUnary(Quasiquote_proto, e) }
| MO_FUN f:functionDefinition { $$= newUnary(Quasiquote_proto, f) }
| MO_DECLARATION d:declaration { $$= newUnary(Quasiquote_proto, d) }
| MO_STATEMENT s:statement { $$= newUnary(Quasiquote_proto, s) }
| MO_ED e:externalDeclaration { $$= newUnary(Quasiquote_proto, e) }
| MO_EXPRESSION e:expression { $$= newUnary(Quasiquote_proto, e) }
)
MO_INITIALIZER = 'initializer' ![(a-zA-Z0-9_] --
MO_CONSTANT = 'constant' ![(a-zA-Z0-9_] --
MO_STATEMENT = 'statement' ![(a-zA-Z0-9_] --
MO_INTEGER = 'integer' ![(a-zA-Z0-9_] --
MO_DECLARATION = 'declaration' ![(a-zA-Z0-9_] --
MO_STRING = 'string' ![(a-zA-Z0-9_] --
MO_EXPRESSION = 'expression' ![(a-zA-Z0-9_] --
MO_FUN = 'fun' ![(a-zA-Z0-9_] --
MO_DECLARATION = 'declaration' ![(a-zA-Z0-9_] --
MO_STATEMENT = 'statement' ![(a-zA-Z0-9_] --
MO_ED = 'ed' ![(a-zA-Z0-9_] --
MO_EXPRESSION = 'expression' ![(a-zA-Z0-9_] --
#--------------------------------------------- Meta rules ----------------------------------------------#
@ -3238,7 +3216,11 @@ oop eval(oop scope, oop ast)
if (keys != null && map_size(keys) > 0) {
oop newArgs = makeMap();
for (int i = 0; i<map_size(args); i++) {
if (map_get(keys, makeInteger(i)) == null) map_append(newArgs, map_get(args, makeInteger(i)));
if (map_get(keys, makeInteger(i)) == null) {
map_append(newArgs, map_get(args, makeInteger(i)));
} else {
map_append(newArgs, null);
}
}
oop paramFunc = get(func, Function, param);
oop idKeys = map_keys(keys);
@ -3699,10 +3681,17 @@ void readEvalPrint(oop scope, char *fileName)
}
oop proto = map_get(yylval, __proto___symbol);
if (proto == null) {
if (is(Map, yylval)) {
for (int i = 0; i < map_size(yylval); i++) {
map_append(outputProgram, treeCopyUnquoting(scope, map_get(yylval, makeInteger(i))));
}
continue;
} // new modification
println(map_keys(yylval));
printf("no prototype associated with ");
println(yylval);
fflush(stdout);
fprintf(stderr, "aborting\n");
fprintf(stderr, "(readEvalPrint - proto == null) aborting\n");
exit(1);
}
// proto_number is the enum version of the proto symbol
@ -3764,6 +3753,22 @@ oop prim_scope(oop scope, oop params)
return fixScope(scope);
}
oop prim_parseFrom(oop scope, oop params)
{
if (map_size(params) != 1) return null;
oop name = get(params, Map, elements)[0].value;
if (!is(String, name)) return null;
char *s = get(name, String, value);
struct _yycontext *yy = yyctx;
if (!strcmp(s, "declaration")) {
oop res = yyparsefrom(yy_declaration) ? __ : null ;
yylval = res; // TODO
return res;
}
printf("%s expected\n", s);
return null;
}
#include <sys/resource.h>
oop prim_microseconds(oop scope, oop params)
@ -3785,6 +3790,7 @@ void outputText(char *text)
void outputNode(oop node)
{
if (!node) return;
switch (getType(node)) {
case Undefined:
@ -4215,6 +4221,9 @@ void outputTree(oop node, int depth)
CASE(stringLiteral)
OUT(text);
break;
CASE(string)
OUT(value);
break;
CASE(char)
OUT(value);
break;
@ -4763,6 +4772,7 @@ void outputTree(oop node, int depth)
/** Unknown node */
default:
printf("I cannot print a node with proto_number %i\n", proto_number);
println(node);
exit(0);
}
#undef PRINT
@ -4803,10 +4813,9 @@ int main(int argc, char **argv)
map_set(globals, intern("treeCopy" ), makeFunction(prim_treeCopy, intern("treeCopy" ), null, null, globals, null));
map_set(globals, intern("import" ), makeFunction(prim_import, intern("import" ), null, null, globals, null));
map_set(globals, intern("microseconds"), makeFunction(prim_microseconds, intern("microseconds"), null, null, globals, null));
map_set(globals, intern("string" ), makeFunction(prim_String , intern("string" ), null, null, globals, null));
map_set(globals, intern("string" ), makeFunction(prim_String, intern("string" ), null, null, globals, null));
map_set(globals, intern("scope" ), makeFunction(prim_scope, intern("scope" ), null, null, globals, null));
map_set(globals, intern("parseFrom" ), makeFunction(prim_parseFrom, intern("parseFrom" ), null, null, globals, null));
#define _DO(NAME) NAME##_symbol=intern(#NAME);
DO_SYMBOLS()

debug.c → src/debug.c Visa fil


dotest → src/dotest Visa fil

@ -1,5 +1,7 @@
#!/bin/sh
make
if test $# -gt 0; then
run="$@"
else
@ -12,28 +14,37 @@ die()
exit 1
}
for i in tests-std/*.c; do
for i in tests/tests-parsimony/*.c; do
echo $i
j="${i%.c}.out"
k="tests/tests-parsimony/tmp.out"
$run $i > $k
cmp $k $j || die $k $j
done
rm tests/tests-parsimony/tmp.out
for i in tests/tests-std/*.c; do
echo $i
j="${i%.c}.out"
$run < $i > $j
cmp $i $j || die $i $j
done
for i in tests-gnu/*.c; do
for i in tests/tests-gnu/*.c; do
echo $i
j="${i%.c}.out"
$run < $i > $j
cmp $i $j || die $i $j
done
for i in tests-err/*.c; do
for i in tests/tests-err/*.c; do
echo $i
j="${i%.c}.out"
$run < $i > $j
cmp -s $i $j || echo failed
done
for i in tests-c/*.c; do
for i in tests/tests-c/*.c; do
echo $i
j="${i%.c}.out"
$run < $i > $j

media/ccmeta.drawio.png → src/images/ccmeta.drawio.png Visa fil


object.c → src/object.c Visa fil

@ -546,6 +546,12 @@ oop map_append(oop map, oop value)
return map_set(map, makeInteger(map_size(map)), value);
}
oop map_appendNonNil(oop map, oop value)
{
if (value != null) map_set(map, makeInteger(map_size(map)), value);
return value;
}
oop map_pop(oop map)
{ assert(map_isArray(map));
size_t size = get(map, Map, size);

parsimonyLibrary/boot.mc → src/parsimonyLibrary/boot.mc Visa fil

@ -1,20 +1,6 @@
@{
println(x) { print(x, "\n"); }
// now in C
// treeCopy(x) {
// l = {};
// k = _keys(x);
// if (k == null) {
// return clone(x);
// } else {
// for (i in k) {
// l[k[i]] = clone(treeCopy(x[k[i]]));
// }
// return clone(l);
// }
// }
//------------ creation C structure ------------//
newId(x, comm) {
@ -55,10 +41,6 @@
} // TO FIX
}
newDeclarators() {}
//--- TO FIX ---//
newEnum(x) { { attributeL: null, expression: null, name: newId(x), __proto__: C_enum }; }
newFunction() {}
@ -114,7 +96,6 @@
append(s1, s2[i]);
}
return s1;
// return treeCopy(s1);
}
// If g then we add a filter on the application of the function f to each element of seq

parsimonyLibrary/dynamicObject.c → src/parsimonyLibrary/dynamicObject.c Visa fil


parsimonyLibrary/dynamicObject.mc → src/parsimonyLibrary/dynamicObjectExtDecl.mc Visa fil

@ -19,8 +19,6 @@ struct Symbol *newSymbol(char *name)
struct Symbol **symbols = 0;
int nSymbols = 0;
struct Symbol *intern(char *name)
{
int lo = 0;
@ -112,10 +110,15 @@ typedef struct __oop *oop;
x;
}
makeln(x, tabs) {
makeln(x, tabs, newLine) {
x.semicolon.comment = newComment("\n");
nbTabs = 0;
nbLn = 1;
if (tabs != null) { nbTabs = tabs; }
if (newLine != null) { nbLn = newLine; }
for (i = 1; i<nbLn; i++) {
x.semicolon.comment.text = x.semicolon.comment.text + "\n";
}
for (i = 0; i<tabs; i++) {
x.semicolon.comment.text = x.semicolon.comment.text + " ";
}
@ -183,7 +186,6 @@ typedef struct __oop *oop;
s.declarators.paramTypeL[0] = treeCopy(param);
}
tmp = {};
// @@ problem for variable changement
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));
program.objects.function = "none";

+ 241
- 0
src/parsimonyLibrary/dynamicObjectParsFrom.mc Visa fil

@ -0,0 +1,241 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Symbol {
char *name;
int class, selector;
};
struct Symbol *newSymbol(char *name)
{
struct Symbol *symbol = malloc(sizeof(*symbol));
symbol->name = strdup(name);
symbol->class = 0;
symbol->selector = 0;
return symbol;
}
struct Symbol **symbols = 0;
int nSymbols = 0;
struct Symbol *intern(char *name)
{
int lo = 0;
int hi = nSymbols - 1;
while (lo <= hi ) {
int mid = (lo+hi)/2;
int cmp = strcmp(name, symbols[mid]->name);
if (cmp > 0) lo = mid + 1;
else if (cmp < 0) hi = mid - 1;
else return symbols[mid];
}
symbols = realloc(symbols, sizeof(*symbols) * ++nSymbols);
memmove(symbols + lo + 1, symbols + lo, sizeof(*symbols)*(nSymbols - lo - 1));
return symbols[lo] = newSymbol(name);
}
typedef void *(*method_t)();
void *method_dnu()
{
printf("method not found\n");
exit(1);
return 0;
}
method_t **methods = 0;
int nClasses = 0;
int nSelectors = 0;
int ensureClass(struct Symbol *symbol)
{
if (symbol->class == 0) {
if (nClasses == 0) nClasses++;
symbol->class = nClasses++;
methods = realloc(methods, sizeof(*methods)*nClasses);
methods[symbol->class] = malloc(sizeof(*methods)*nSelectors);
for (int i = 0; i<nSelectors; ++i)
methods[symbol->class][i] = method_dnu;
}
return symbol->class;
}
int ensureSelector(struct Symbol *symbol)
{
if (symbol->selector == 0) {
if (nSelectors == 0) nSelectors++;
symbol->selector = nSelectors++;
for (int i = 0; i<nClasses; ++i) {
methods[i] = realloc(methods[i], sizeof(**methods)*nSelectors);
methods[i][nSelectors-1] = method_dnu;
}
}
return symbol->selector;
}
int findClass(char *class)
{
return ensureClass(intern(class));
}
int findSelector(char *selector)
{
return ensureSelector(intern(selector));
}
void addMethod(int class, int selector, method_t method)
{
methods[class][selector] = method;
}
#define lookup(C, S) (methods[C][S])
struct Object {
int class;
};
#define send(R, M, ...) ({ struct Object *__ = (struct Object *)(R); lookup(__->class, _selector_##M)(__, ##__VA_ARGS__); })
struct __oop { int class; };
typedef struct __oop *oop;
@import("parsimonyLibrary/boot.mc")
@{
rmSemi(x) {
x.semicolon = null;
x;
}
makeln(x, tabs, newLine) {
x.semicolon.comment = newComment("\n");
nbTabs = 0;
nbLn = 1;
if (tabs != null) { nbTabs = tabs; }
if (newLine != null) { nbLn = newLine; }
for (i = 1; i<nbLn; i++) {
x.semicolon.comment.text = x.semicolon.comment.text + "\n";
}
for (i = 0; i<tabs; i++) {
x.semicolon.comment.text = x.semicolon.comment.text + " ";
}
x;
}
program.objects = {};
program.objects.class = {};
program.objects.methods = {};
program.objects.send = {};
program.objects.send.object = {};
program.objects.send.method = {};
sendLen = -1;
sw = 0;
class()
{
exp = parseFrom("declaration");
program.objects.class[exp.specifiers[0].name.identifier] = {};
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;
}
method(object_name)
{
program.objects.currentClassName = object_name;
program.objects.function = "method";
nil;
}
constructor(object_name) {
program.objects.currentClassName = object_name;
program.objects.function = "constructor";
nil;
}
send(object, method)
{
treeCopy(rmSemi(`declaration send(@@(newText(object)), @@(newText(method)));));
}
everyExternalDeclaration(s)
{
/*********** Class function ************/
if (program.objects.function == "class") {
program.objects.class[program.last.name.identifier] = {};
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.objects.function = "none";
return s;
}
/*********** Method function ************/
if (program.objects.function == "method") {
intern(program.objects.methods, program.last.declarators.declarators.identifier);
for (i in program.objects.class) {
if (string(i) == program.objects.currentClassName) intern(program.objects.class[i], program.last.declarators.declarators.identifier);
}
program.last.declarators.declarators.identifier = program.objects.currentClassName + "_" + string(program.last.declarators.declarators.identifier);
param = rmSemi(`declaration struct __oop *__self;);
if (length(s.declarators.paramTypeL) > 0) {
append(s.declarators.paramTypeL, newComma());
append(s.declarators.paramTypeL, treeCopy(param));
} else {
s.declarators.paramTypeL = {};
s.declarators.paramTypeL[0] = treeCopy(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));
program.objects.function = "none";
return s;
}
/*********** Constructor function ************/
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)));
// take the structure of self->foo
lhs = treeCopy(s.compoundS.expression[0].expression.lhs);
lhs.rhs = newId("class", " ");
// Change foo to Class
rawDeclaration.declarators[0].lhs = lhs;
// prepare the right object to return
append(s.compoundS.expression, rawDeclaration);
append(s.compoundS.expression, makeln(`statement return (struct __oop *) self;));
s.compoundS.expression = fusion(t, s.compoundS.expression);
program.objects.function = "none";
return s;
}
/*********** Main function ************/
if (s.declarators != null && s.declarators.declarators != null && string(s.declarators.declarators.identifier) == "main") {
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)));
}
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)));
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)));
}
}
s.compoundS.expression = fusion(t, s.compoundS.expression);
return s;
}
s;
}
nil;
}

protoNumber.txt → src/protoNumber.txt Visa fil

@ -61,6 +61,7 @@ _DO(Continue)
_DO(Throw)
_DO(Try)
_DO(Quote)
_DO(Quasiquote)
_DO(Comment)
_DO(Token)
_DO(C_declaration)

scope.c → src/scope.c Visa fil


tests-c/00001.c → src/tests/tests-c/00001.c Visa fil


+ 5
- 0
src/tests/tests-c/00001.out Visa fil

@ -0,0 +1,5 @@
int
main()
{
return 0;
}

tests-c/00002.c → src/tests/tests-c/00002.c Visa fil


+ 5
- 0
src/tests/tests-c/00002.out Visa fil

@ -0,0 +1,5 @@
int
main()
{
return 3-3;
}

tests-c/00003.c → src/tests/tests-c/00003.c Visa fil


+ 8
- 0
src/tests/tests-c/00003.out Visa fil

@ -0,0 +1,8 @@
int
main()
{
int x;
x = 4;
return x - 4;
}

tests-c/00004.c → src/tests/tests-c/00004.c Visa fil


+ 12
- 0
src/tests/tests-c/00004.out Visa fil

@ -0,0 +1,12 @@
int
main()
{
int x;
int *p;
x = 4;
p = &x;
*p = 0;
return *p;
}

tests-c/00005.c → src/tests/tests-c/00005.c Visa fil


+ 23
- 0
src/tests/tests-c/00005.out Visa fil

@ -0,0 +1,23 @@
int
main()
{
int x;
int *p;
int **pp;
x = 0;
p = &x;
pp = &p;
if(*p)
return 1;
if(**pp)
return 1;
else
**pp = 1;
if(x)
return 0;
else
return 1;
}

tests-c/00006.c → src/tests/tests-c/00006.c Visa fil


+ 10
- 0
src/tests/tests-c/00006.out Visa fil

@ -0,0 +1,10 @@
int
main()
{
int x;
x = 50;
while (x)
x = x - 1;
return x;
}

tests-c/00007.c → src/tests/tests-c/00007.c Visa fil


+ 15
- 0
src/tests/tests-c/00007.out Visa fil

@ -0,0 +1,15 @@
int
main()
{
int x;
x = 1;
for(x = 10; x; x = x - 1)
;
if(x)
return 1;
x = 10;
for (;x;)
x = x - 1;
return x;
}

tests-c/00008.c → src/tests/tests-c/00008.c Visa fil


+ 11
- 0
src/tests/tests-c/00008.out Visa fil

@ -0,0 +1,11 @@
int
main()
{
int x;
x = 50;
do
x = x - 1;
while(x);
return x;
}

tests-c/00009.c → src/tests/tests-c/00009.c Visa fil


+ 11
- 0
src/tests/tests-c/00009.out Visa fil

@ -0,0 +1,11 @@
int
main()
{
int x;
x = 1;
x = x * 10;
x = x / 2;
x = x % 3;
return x - 2;
}

tests-c/00010.c → src/tests/tests-c/00010.c Visa fil


+ 13
- 0
src/tests/tests-c/00010.out Visa fil

@ -0,0 +1,13 @@
int
main()
{
start:
goto next;
return 1;
success:
return 0;
next:
foo:
goto success;
return 1;
}

tests-c/00011.c → src/tests/tests-c/00011.c Visa fil


+ 8
- 0
src/tests/tests-c/00011.out Visa fil

@ -0,0 +1,8 @@
int
main()
{
int x;
int y;
x = y = 0;
return x;
}

tests-c/00012.c → src/tests/tests-c/00012.c Visa fil


+ 5
- 0
src/tests/tests-c/00012.out Visa fil

@ -0,0 +1,5 @@
int
main()
{
return (2 + 2) * 2 - 8;
}

tests-c/00013.c → src/tests/tests-c/00013.c Visa fil


+ 10
- 0
src/tests/tests-c/00013.out Visa fil

@ -0,0 +1,10 @@
int
main()
{
int x;
int *p;
x = 0;
p = &x;
return p[0];
}

tests-c/00014.c → src/tests/tests-c/00014.c Visa fil


+ 11
- 0
src/tests/tests-c/00014.out Visa fil

@ -0,0 +1,11 @@
int
main()
{
int x;
int *p;
x = 1;
p = &x;
p[0] = 0;
return x;
}

tests-c/00015.c → src/tests/tests-c/00015.c Visa fil


+ 10
- 0
src/tests/tests-c/00015.out Visa fil

@ -0,0 +1,10 @@
int
main()
{
int arr[2];
arr[0] = 1;
arr[1] = 2;
return arr[0] + arr[1] - 3;
}

tests-c/00016.c → src/tests/tests-c/00016.c Visa fil


+ 10
- 0
src/tests/tests-c/00016.out Visa fil

@ -0,0 +1,10 @@
int
main()
{
int arr[2];
int *p;
p = &arr[1];
*p = 0;
return arr[1];
}

tests-c/00017.c → src/tests/tests-c/00017.c Visa fil


+ 9
- 0
src/tests/tests-c/00017.out Visa fil

@ -0,0 +1,9 @@
int
main()
{
struct { int x; int y; } s;
s.x = 3;
s.y = 5;
return s.y - s.x - 2;
}

tests-c/00018.c → src/tests/tests-c/00018.c Visa fil


+ 13
- 0
src/tests/tests-c/00018.out Visa fil

@ -0,0 +1,13 @@
int
main()
{
struct S { int x; int y; } s;
struct S *p;
p = &s;
s.x = 1;
p->y = 2;
return p->y + p->x - 3;
}

tests-c/00019.c → src/tests/tests-c/00019.c Visa fil


+ 10
- 0
src/tests/tests-c/00019.out Visa fil

@ -0,0 +1,10 @@
int
main()
{
struct S { struct S *p; int x; } s;
s.x = 0;
s.p = &s;
return s.p->p->p->p->p->x;
}

tests-c/00020.c → src/tests/tests-c/00020.c Visa fil


+ 10
- 0
src/tests/tests-c/00020.out Visa fil

@ -0,0 +1,10 @@
int
main()
{
int x, *p, **pp;
x = 0;
p = &x;
pp = &p;
return **pp;
}

tests-c/00021.c → src/tests/tests-c/00021.c Visa fil


+ 12
- 0
src/tests/tests-c/00021.out Visa fil

@ -0,0 +1,12 @@
int
foo(int a, int b)
{
return 2 + a - b;
}
int
main()
{
return foo(1, 3);
}

tests-c/00022.c → src/tests/tests-c/00022.c Visa fil


+ 10
- 0
src/tests/tests-c/00022.out Visa fil

@ -0,0 +1,10 @@
typedef int x;
int
main()
{
x v;
v = 0;
return v;
}

tests-c/00023.c → src/tests/tests-c/00023.c Visa fil


+ 9
- 0
src/tests/tests-c/00023.out Visa fil

@ -0,0 +1,9 @@
int x;
int
main()
{
x = 0;
return x;
}

tests-c/00024.c → src/tests/tests-c/00024.c Visa fil


+ 12
- 0
src/tests/tests-c/00024.out Visa fil

@ -0,0 +1,12 @@
typedef struct { int x; int y; } s;
s v;
int
main()
{
v.x = 1;
v.y = 2;
return 3 - v.x - v.y;
}

tests-c/00025.c → src/tests/tests-c/00025.c Visa fil


+ 10
- 0
src/tests/tests-c/00025.out Visa fil

@ -0,0 +1,10 @@
int strlen(char *);
int
main()
{
char *p;
p = "hello";
return strlen(p) - 5;
}

tests-c/00026.c → src/tests/tests-c/00026.c Visa fil


+ 8
- 0
src/tests/tests-c/00026.out Visa fil

@ -0,0 +1,8 @@
int
main()
{
char *p;
p = "hello";
return p[0] - 104;
}

tests-c/00027.c → src/tests/tests-c/00027.c Visa fil


+ 10
- 0
src/tests/tests-c/00027.out Visa fil

@ -0,0 +1,10 @@
int
main()
{
int x;
x = 1;
x = x | 4;
return x - 5;
}

tests-c/00028.c → src/tests/tests-c/00028.c Visa fil


+ 10
- 0
src/tests/tests-c/00028.out Visa fil

@ -0,0 +1,10 @@
int
main()
{
int x;
x = 1;
x = x & 3;
return x - 1;
}

tests-c/00029.c → src/tests/tests-c/00029.c Visa fil


+ 10
- 0
src/tests/tests-c/00029.out Visa fil

@ -0,0 +1,10 @@
int
main()
{
int x;
x = 1;
x = x ^ 3;
return x - 2;
}

tests-c/00030.c → src/tests/tests-c/00030.c Visa fil


+ 24
- 0
src/tests/tests-c/00030.out Visa fil

@ -0,0 +1,24 @@
int
f()
{
return 100;
}
int
main()
{
if (f() > 1000)
return 1;
if (f() >= 1000)
return 1;
if (1000 < f())
return 1;
if (1000 <= f())
return 1;
if (1000 == f())
return 1;
if (100 != f())
return 1;
return 0;
}

tests-c/00031.c → src/tests/tests-c/00031.c Visa fil


+ 48
- 0
src/tests/tests-c/00031.out Visa fil

@ -0,0 +1,48 @@
int
zero()
{
return 0;
}
int
one()
{
return 1;
}
int
main()
{
int x;
int y;
x = zero();
y = ++x;
if (x != 1)
return 1;
if (y != 1)
return 1;
x = one();
y = --x;
if (x != 0)
return 1;
if (y != 0)
return 1;
x = zero();
y = x++;
if (x != 1)
return 1;
if (y != 0)
return 1;
x = one();
y = x--;
if (x != 0)
return 1;
if (y != 1)
return 1;
return 0;
}

tests-c/00032.c → src/tests/tests-c/00032.c Visa fil


+ 30
- 0
src/tests/tests-c/00032.out Visa fil

@ -0,0 +1,30 @@
int
main()
{
int arr[2];
int *p;
arr[0] = 2;
arr[1] = 3;
p = &arr[0];
if(*(p++) != 2)
return 1;
if(*(p++) != 3)
return 2;
p = &arr[1];
if(*(p--) != 3)
return 1;
if(*(p--) != 2)
return 2;
p = &arr[0];
if(*(++p) != 3)
return 1;
p = &arr[1];
if(*(--p) != 2)
return 1;
return 0;
}

tests-c/00033.c → src/tests/tests-c/00033.c Visa fil


+ 45
- 0
src/tests/tests-c/00033.out Visa fil

@ -0,0 +1,45 @@
int g;
int
effect()
{
g = 1;
return 1;
}
int
main()
{
int x;
g = 0;
x = 0;
if(x && effect())
return 1;
if(g)
return 2;
x = 1;
if(x && effect()) {
if(g != 1)
return 3;
} else {
return 4;
}
g = 0;
x = 1;
if(x || effect()) {
if(g)
return 5;
} else {
return 6;
}
x = 0;
if(x || effect()) {
if(g != 1)
return 7;
} else {
return 8;
}
return 0;
}

tests-c/00034.c → src/tests/tests-c/00034.c Visa fil


+ 32
- 0
src/tests/tests-c/00034.out Visa fil

@ -0,0 +1,32 @@
int
main()
{
int x;
x = 0;
while(1)
break;
while(1) {
if (x == 5) {
break;
}
x = x + 1;
continue;
}
for (;;) {
if (x == 10) {
break;
}
x = x + 1;
continue;
}
do {
if (x == 15) {
break;
}
x = x + 1;
continue;
} while(1);
return x - 15;
}

tests-c/00035.c → src/tests/tests-c/00035.c Visa fil


+ 15
- 0
src/tests/tests-c/00035.out Visa fil

@ -0,0 +1,15 @@
int
main()
{
int x;
x = 4;
if(!x != 0)
return 1;
if(!!x != 1)
return 1;
if(-x != 0 - 4)
return 1;
return 0;
}

tests-c/00036.c → src/tests/tests-c/00036.c Visa fil


+ 19
- 0
src/tests/tests-c/00036.out Visa fil

@ -0,0 +1,19 @@
int
main()
{
int x;
x = 0;
x += 2;
x += 2;
if (x != 4)
return 1;
x -= 1;
if (x != 3)
return 2;
x *= 2;
if (x != 6)
return 3;
return 0;
}

tests-c/00037.c → src/tests/tests-c/00037.c Visa fil


+ 17
- 0
src/tests/tests-c/00037.out Visa fil

@ -0,0 +1,17 @@
int
main()
{
int x[2];
int *p;
x[1] = 7;
p = &x[0];
p = p + 1;
if(*p != 7)
return 1;
if(&x[1] - &x[0] != 1)
return 1;
return 0;
}

tests-c/00038.c → src/tests/tests-c/00038.c Visa fil


+ 17
- 0
src/tests/tests-c/00038.out Visa fil

@ -0,0 +1,17 @@
int
main()
{
int x, *p;
if (sizeof(0) < 2)
return 1;
if (sizeof 0 < 2)
return 1;
if (sizeof(char) < 1)
return 1;
if (sizeof(int) - 2 < 0)
return 1;
if (sizeof(&x) != sizeof p)
return 1;
return 0;
}

tests-c/00039.c → src/tests/tests-c/00039.c Visa fil


+ 13
- 0
src/tests/tests-c/00039.out Visa fil

@ -0,0 +1,13 @@
int
main()
{
void *p;
int x;
x = 2;
p = &x;
if(*((int*)p) != 2)
return 1;
return 0;
}

tests-c/00040.c → src/tests/tests-c/00040.c Visa fil


+ 55
- 0
src/tests/tests-c/00040.out Visa fil

@ -0,0 +1,55 @@
#include <stdlib.h>
int N;
int *t;
int
chk(int x, int y)
{
int i;
int r;
for (r=i=0; i<8; i++) {
r = r + t[x + 8*i];
r = r + t[i + 8*y];
if (x+i < 8 & y+i < 8)
r = r + t[x+i + 8*(y+i)];
if (x+i < 8 & y-i >= 0)
r = r + t[x+i + 8*(y-i)];
if (x-i >= 0 & y+i < 8)
r = r + t[x-i + 8*(y+i)];
if (x-i >= 0 & y-i >= 0)
r = r + t[x-i + 8*(y-i)];
}
return r;
}
int
go(int n, int x, int y)
{
if (n == 8) {
N++;
return 0;
}
for (; y<8; y++) {
for (; x<8; x++)
if (chk(x, y) == 0) {
t[x + 8*y]++;
go(n+1, x, y);
t[x + 8*y]--;
}
x = 0;
}
return 0;
}
int
main()
{
t = calloc(64, sizeof(int));
go(0, 0, 0);
if(N != 92)
return 1;
return 0;
}

tests-c/00041.c → src/tests/tests-c/00041.c Visa fil


+ 26
- 0
src/tests/tests-c/00041.out Visa fil

@ -0,0 +1,26 @@
int
main() {
int n;
int t;
int c;
int p;
c = 0;
n = 2;
while (n < 5000) {
t = 2;
p = 1;
while (t*t <= n) {
if (n % t == 0)
p = 0;
t++;
}
n++;
if (p)
c++;
}
if (c != 669)
return 1;
return 0;
}

tests-c/00042.c → src/tests/tests-c/00042.c Visa fil


+ 11
- 0
src/tests/tests-c/00042.out Visa fil

@ -0,0 +1,11 @@
int
main()
{
union { int a; int b; } u;
u.a = 1;
u.b = 3;
if (u.a != 3 || u.b != 3)
return 1;
return 0;
}

Vissa filer visades inte eftersom för många filer har ändrats

Laddar…
Avbryt
Spara