Browse Source

modification for the class object

develop-theo
Theo Souchon 2 years ago
parent
commit
791119d516
8 changed files with 35 additions and 25 deletions
  1. +9
    -6
      ccmeta.leg
  2. +1
    -2
      fake-static-classes.mc
  3. +1
    -0
      object.c
  4. +9
    -8
      testPars.sh
  5. +4
    -4
      tests-parsimony/parsimony-lang/map.c
  6. +1
    -1
      tests-parsimony/projExample.c
  7. +9
    -3
      tests-parsimony/testFile.c
  8. +1
    -1
      tests-parsimony/testFile2.c

+ 9
- 6
ccmeta.leg View File

@ -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);

class.mc → fake-static-classes.mc View File

@ -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;
}

+ 1
- 0
object.c View File

@ -89,6 +89,7 @@ struct Undefined {
type_t type;
};
struct Integer {
type_t type;
int_t _value;

+ 9
- 8
testPars.sh View File

@ -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 !"

+ 4
- 4
tests-parsimony/parsimony-lang/map.c View File

@ -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;
}

+ 1
- 1
tests-parsimony/projExample.c View File

@ -8,4 +8,4 @@ enum foo { Closed = 0, ReadOnly = 1, WriteOnly = 2 };
nil;
}
static char *stateNames[] = { @(map(idToString, properties.enums.foo.enumList, notToken)) };
static char *stateNames[] = { @(map(idToString, program.enums.foo.enumList, notToken)) };

+ 9
- 3
tests-parsimony/testFile.c View File

@ -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;

+ 1
- 1
tests-parsimony/testFile2.c View File

@ -1,4 +1,4 @@
@(import("class.mc"))
@(import("fake-static-classes.mc"))
@{
//creation of the object class

Loading…
Cancel
Save