From c95443c5201f0beb75590088d53c4b212bc97797 Mon Sep 17 00:00:00 2001 From: Theo Souchon Date: Fri, 18 Nov 2022 16:42:45 +0900 Subject: [PATCH] new example of simplification --- boot.mc | 4 ---- ccmeta.leg | 3 ++- tests-parsimony/{ => parsimony-lang}/001.c | 0 tests-parsimony/{ => parsimony-lang}/002.c | 0 tests-parsimony/{ => parsimony-lang}/003.c | 14 ++++++++++++- tests-parsimony/{ => parsimony-lang}/004.c | 0 tests-parsimony/{ => parsimony-lang}/005.c | 4 ++-- tests-parsimony/{ => parsimony-lang}/006.c | 4 ++-- tests-parsimony/{ => parsimony-lang}/007.c | 2 +- tests-parsimony/{ => parsimony-lang}/map.c | 23 ---------------------- tests-parsimony/projExample.c | 2 +- 11 files changed, 21 insertions(+), 35 deletions(-) rename tests-parsimony/{ => parsimony-lang}/001.c (100%) rename tests-parsimony/{ => parsimony-lang}/002.c (100%) rename tests-parsimony/{ => parsimony-lang}/003.c (63%) rename tests-parsimony/{ => parsimony-lang}/004.c (100%) rename tests-parsimony/{ => parsimony-lang}/005.c (88%) rename tests-parsimony/{ => parsimony-lang}/006.c (91%) rename tests-parsimony/{ => parsimony-lang}/007.c (92%) rename tests-parsimony/{ => parsimony-lang}/map.c (67%) diff --git a/boot.mc b/boot.mc index 8ea4b70..ab62dac 100644 --- a/boot.mc +++ b/boot.mc @@ -1,8 +1,4 @@ @{ - createList() { - return {}; - } - append(s, e) { s[length(s)] = e; } diff --git a/ccmeta.leg b/ccmeta.leg index a6521e1..2497bbd 100644 --- a/ccmeta.leg +++ b/ccmeta.leg @@ -1368,6 +1368,7 @@ integerConstant = < ( hexadecimalConstant | decimalConstant ) integerSuffix? > { $$= new_C_int(yytext); } - + | META_AT mvalue decimalConstant = [1-9][0-9]* @@ -2177,7 +2178,7 @@ mstmts = ( s:eval_stmt )* ( META_NIL META_SEMICOLON META_RCB { $$= null | META_RCB { $$= s } ) -eval_stmt = s:meta_stmt { $$= eval(globals, s) } +eval_stmt = s:meta_stmt { $$= eval(globals, s) } meta_stmt = s:meta_block { $$= s } | META_SEMICOLON { $$= null } diff --git a/tests-parsimony/001.c b/tests-parsimony/parsimony-lang/001.c similarity index 100% rename from tests-parsimony/001.c rename to tests-parsimony/parsimony-lang/001.c diff --git a/tests-parsimony/002.c b/tests-parsimony/parsimony-lang/002.c similarity index 100% rename from tests-parsimony/002.c rename to tests-parsimony/parsimony-lang/002.c diff --git a/tests-parsimony/003.c b/tests-parsimony/parsimony-lang/003.c similarity index 63% rename from tests-parsimony/003.c rename to tests-parsimony/parsimony-lang/003.c index 8542601..7c3a04a 100644 --- a/tests-parsimony/003.c +++ b/tests-parsimony/parsimony-lang/003.c @@ -11,7 +11,19 @@ int main() { @{ - l = createList(); + l = {}; + append(l, forLoop); + if (useForLoop) { + append(l, forLoop); + } else { + append(l, whileLoop); + } + l; + }; + @{ + l = {}; + useForLoop = 0; + append(l, forLoop); if (useForLoop) { append(l, forLoop); } else { diff --git a/tests-parsimony/004.c b/tests-parsimony/parsimony-lang/004.c similarity index 100% rename from tests-parsimony/004.c rename to tests-parsimony/parsimony-lang/004.c diff --git a/tests-parsimony/005.c b/tests-parsimony/parsimony-lang/005.c similarity index 88% rename from tests-parsimony/005.c rename to tests-parsimony/parsimony-lang/005.c index df2a1cb..72c3ae4 100644 --- a/tests-parsimony/005.c +++ b/tests-parsimony/parsimony-lang/005.c @@ -1,7 +1,7 @@ @{import("boot.mc");} @{ - l = createList(); + l = {}; append(l, `declaration int a = 5;); append(l, `declaration int b = 2;); l; @@ -9,7 +9,7 @@ int main() { @{ - l = createList(); + l = {}; a = (`declaration int a = 2;); append(l, `declaration int c = 5;); b = 5; diff --git a/tests-parsimony/006.c b/tests-parsimony/parsimony-lang/006.c similarity index 91% rename from tests-parsimony/006.c rename to tests-parsimony/parsimony-lang/006.c index 7e30eca..e308e40 100644 --- a/tests-parsimony/006.c +++ b/tests-parsimony/parsimony-lang/006.c @@ -1,7 +1,7 @@ @{import("boot.mc");} @{ - l = createList(); + l = {}; append(l, `declaration int a = 5;); a = (`declaration int a = 5;); append(l, `declaration int a = 5;); @@ -19,7 +19,7 @@ int main() { @a; int b = 0; @{ - l = createList(); + l = {}; append(l, `declaration int c = 0;); x = (`declaration int d = 5;); append(l, x); diff --git a/tests-parsimony/007.c b/tests-parsimony/parsimony-lang/007.c similarity index 92% rename from tests-parsimony/007.c rename to tests-parsimony/parsimony-lang/007.c index f4fbc56..78024f1 100644 --- a/tests-parsimony/007.c +++ b/tests-parsimony/parsimony-lang/007.c @@ -1,7 +1,7 @@ @{import("boot.mc");} @{ - l = createList(); + l = {}; append(l, `declaration int a = 0;); a = (`declaration int b = 0;); append(l, a); diff --git a/tests-parsimony/map.c b/tests-parsimony/parsimony-lang/map.c similarity index 67% rename from tests-parsimony/map.c rename to tests-parsimony/parsimony-lang/map.c index de84ce0..71a5fff 100644 --- a/tests-parsimony/map.c +++ b/tests-parsimony/parsimony-lang/map.c @@ -1,28 +1,5 @@ @{import("boot.mc");} -@{ - toChar(foo) { - "\"type :"+foo+"\""; - } - p2(foo) { - foo * foo; - } - c = ["earth", "sky", "water"]; - isSky(x) { x == "sky" } - c = reject(isSky, c); - nil; -} - -@{ - print(map(p2, [100, 2, 3])); - nil; -} - -@{ - print(map(toChar, c)); - nil; -} - enum foo { A, B, C }; enum oof { A, B, C }; diff --git a/tests-parsimony/projExample.c b/tests-parsimony/projExample.c index 10bfc1d..8ed58f7 100644 --- a/tests-parsimony/projExample.c +++ b/tests-parsimony/projExample.c @@ -8,4 +8,4 @@ enum foo { Closed = 0, ReadOnly = 1, WriteOnly = 2 }; nil; } -static char ∗stateNames[] = { @(map(idToString, properties.enums.foo.enumList, notToken)) }; \ No newline at end of file +static char *stateNames[] = { @(map(idToString, properties.enums.foo.enumList, notToken)) }; \ No newline at end of file