From 791119d516fa27fe56f32f16f0231f5e3c651b49 Mon Sep 17 00:00:00 2001 From: Theo Souchon Date: Thu, 24 Nov 2022 18:04:23 +0900 Subject: [PATCH] modification for the class object --- ccmeta.leg | 15 +++++++++------ class.mc => fake-static-classes.mc | 3 +-- object.c | 1 + testPars.sh | 17 +++++++++-------- tests-parsimony/parsimony-lang/map.c | 8 ++++---- tests-parsimony/projExample.c | 2 +- tests-parsimony/testFile.c | 12 +++++++++--- tests-parsimony/testFile2.c | 2 +- 8 files changed, 35 insertions(+), 25 deletions(-) rename class.mc => fake-static-classes.mc (93%) diff --git a/ccmeta.leg b/ccmeta.leg index 8e5de37..c869455 100644 --- a/ccmeta.leg +++ b/ccmeta.leg @@ -104,7 +104,7 @@ jb_record *jbs= NULL; // this is the global scope oop globals= 0; -oop properties= 0; +oop program= 0; oop prop_enums= 0; #define DO_SYMBOLS() \ @@ -2169,10 +2169,13 @@ metaCatch = META_AT ( META_IMPORT s:META_STRING ";" { inputStack | META_LCB s:mstmts { map_append(outputProgram, s); $$= null } ) -mvalue = i:META_IDENT { $$= eval(globals, newGetVariable(i)) } +mvalue = i:META_IDENT { i= newGetVariable(i) } + ( a:meta_argumentList { i = (null != getSyntax(1, i)) ? apply(globals, globals, getSyntax(1, i), a, i) : newCall(i, a) } )? + { $$= eval(globals, i)} | META_LPAREN ( i:MO_OPERATION | i:meta_exp - ) META_RPAREN { $$= eval(globals, i) } + ) META_RPAREN { $$= eval(globals, i) } + mstmts = ( s:eval_stmt )* ( META_NIL META_SEMICOLON META_RCB { $$= null } | META_RCB { $$= s } @@ -4665,10 +4668,10 @@ int main(int argc, char **argv) DO_PROTOS() #undef _DO - properties = makeMap(); + program = makeMap(); prop_enums = makeMap(); - map_set(properties, intern("enums"), prop_enums); - map_set(globals, intern("properties"), properties); + map_set(program, intern("enums"), prop_enums); + map_set(globals, intern("program"), program); fixScope(globals); diff --git a/class.mc b/fake-static-classes.mc similarity index 93% rename from class.mc rename to fake-static-classes.mc index 00107c4..2b6ff01 100644 --- a/class.mc +++ b/fake-static-classes.mc @@ -22,13 +22,12 @@ k++; } for (i in class) { - if (i != keys(class)[0] ) { + if (i != keys(class)[0]) { out[i] = clone(class[i]); } } return out; } - nil; } \ No newline at end of file diff --git a/object.c b/object.c index 7bd448c..f61a928 100644 --- a/object.c +++ b/object.c @@ -89,6 +89,7 @@ struct Undefined { type_t type; }; + struct Integer { type_t type; int_t _value; diff --git a/testPars.sh b/testPars.sh index d48ab90..4b94d0e 100755 --- a/testPars.sh +++ b/testPars.sh @@ -1,28 +1,29 @@ make echo "\n" echo "\n" -./ccmeta tests-parsimony/001.c +./ccmeta tests-parsimony/parsimony-lang/001.c echo "\n" echo "\n" -./ccmeta tests-parsimony/002.c +./ccmeta tests-parsimony/parsimony-lang/002.c echo "\n" echo "\n" -./ccmeta tests-parsimony/003.c +./ccmeta tests-parsimony/parsimony-lang/003.c echo "\n" echo "\n" -./ccmeta tests-parsimony/004.c +./ccmeta tests-parsimony/parsimony-lang/004.c echo "\n" echo "\n" -./ccmeta tests-parsimony/005.c +./ccmeta tests-parsimony/parsimony-lang/005.c echo "\n" echo "\n" -./ccmeta tests-parsimony/006.c +./ccmeta tests-parsimony/parsimony-lang/006.c echo "\n" echo "\n" -./ccmeta tests-parsimony/007.c +./ccmeta tests-parsimony/parsimony-lang/007.c echo "\n" echo "\n" -./ccmeta tests-parsimony/map.c +./ccmeta tests-parsimony/parsimony-lang/map.c echo "\n" +./ccmeta tests-parsimony/projExample.c echo "\n" echo "ok !" \ No newline at end of file diff --git a/tests-parsimony/parsimony-lang/map.c b/tests-parsimony/parsimony-lang/map.c index 71a5fff..e294a52 100644 --- a/tests-parsimony/parsimony-lang/map.c +++ b/tests-parsimony/parsimony-lang/map.c @@ -7,11 +7,11 @@ enum oof { A, B, C }; isEnum(x) { x.__proto__ == C_enum } notToken(x) { x.__proto__ != Token } to_C_string(x) {{ __proto__: C_string, value: "\"" + string(x.name.identifier) + "\"" }} - // to_C_string(properties.enums.foo.enumList[?].name.identifier); + // to_C_string(program.enums.foo.enumList[?].name.identifier); - a = map(to_C_string, select(isEnum, properties.enums.foo.enumList)); - b = map(to_C_string, properties.enums.foo.enumList, notToken); - c = map(to_C_string, properties.enums.foo.enumList, isEnum); + a = map(to_C_string, select(isEnum, program.enums.foo.enumList)); + b = map(to_C_string, program.enums.foo.enumList, notToken); + c = map(to_C_string, program.enums.foo.enumList, isEnum); nil; } diff --git a/tests-parsimony/projExample.c b/tests-parsimony/projExample.c index 8ed58f7..372eb18 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, program.enums.foo.enumList, notToken)) }; \ No newline at end of file diff --git a/tests-parsimony/testFile.c b/tests-parsimony/testFile.c index 9145c0a..9af8bf0 100644 --- a/tests-parsimony/testFile.c +++ b/tests-parsimony/testFile.c @@ -1,4 +1,4 @@ -@(import("class.mc")) +@(import("fake-static-classes.mc")) @{ //creation of the class @@ -15,7 +15,10 @@ (P.values.w != null) ? print("\nyes\n\n") : print("\nno\n\n"); // Use of the P class - x = new(P, { x: 2, y: 4, z: 6 }); + // x = new(P, { x: 2, y: 4, z: 6 }); + // or + newP(a, b) { new(P, { x: a, y: b }) } + x = newP(2, 4); x.functions.printf(x); // Create another class from P @@ -27,7 +30,10 @@ Q.functions.printf = printf; // Use of the Q class - y = new(Q, { x: 1, y: 2, z: 3 }); + // y = new(Q, { x: 1, y: 2, z: 3 }); + // or + newQ(a, b, c) { new(Q, { x: a, y: b, z: c }) } + y = newQ(1, 2, 3); y.functions.printf(y); nil; diff --git a/tests-parsimony/testFile2.c b/tests-parsimony/testFile2.c index 068f5fd..a0e5880 100644 --- a/tests-parsimony/testFile2.c +++ b/tests-parsimony/testFile2.c @@ -1,4 +1,4 @@ -@(import("class.mc")) +@(import("fake-static-classes.mc")) @{ //creation of the object class