浏览代码

modification for the class object

develop-theo
Theo Souchon 2 年前
父节点
当前提交
791119d516
共有 8 个文件被更改,包括 35 次插入25 次删除
  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 查看文件

@ -104,7 +104,7 @@ jb_record *jbs= NULL;
// this is the global scope // this is the global scope
oop globals= 0; oop globals= 0;
oop properties= 0;
oop program= 0;
oop prop_enums= 0; oop prop_enums= 0;
#define DO_SYMBOLS() \ #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 } | 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 | META_LPAREN ( i:MO_OPERATION
| i:meta_exp | i:meta_exp
) META_RPAREN { $$= eval(globals, i) }
) META_RPAREN { $$= eval(globals, i) }
mstmts = ( s:eval_stmt )* ( META_NIL META_SEMICOLON META_RCB { $$= null } mstmts = ( s:eval_stmt )* ( META_NIL META_SEMICOLON META_RCB { $$= null }
| META_RCB { $$= s } | META_RCB { $$= s }
@ -4665,10 +4668,10 @@ int main(int argc, char **argv)
DO_PROTOS() DO_PROTOS()
#undef _DO #undef _DO
properties = makeMap();
program = makeMap();
prop_enums = 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); fixScope(globals);

class.mc → fake-static-classes.mc 查看文件

@ -22,13 +22,12 @@
k++; k++;
} }
for (i in class) { for (i in class) {
if (i != keys(class)[0] ) {
if (i != keys(class)[0]) {
out[i] = clone(class[i]); out[i] = clone(class[i]);
} }
} }
return out; return out;
} }
nil; nil;
} }

+ 1
- 0
object.c 查看文件

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

+ 9
- 8
testPars.sh 查看文件

@ -1,28 +1,29 @@
make make
echo "\n" echo "\n"
echo "\n" echo "\n"
./ccmeta tests-parsimony/001.c
./ccmeta tests-parsimony/parsimony-lang/001.c
echo "\n" echo "\n"
echo "\n" echo "\n"
./ccmeta tests-parsimony/002.c
./ccmeta tests-parsimony/parsimony-lang/002.c
echo "\n" echo "\n"
echo "\n" echo "\n"
./ccmeta tests-parsimony/003.c
./ccmeta tests-parsimony/parsimony-lang/003.c
echo "\n" echo "\n"
echo "\n" echo "\n"
./ccmeta tests-parsimony/004.c
./ccmeta tests-parsimony/parsimony-lang/004.c
echo "\n" echo "\n"
echo "\n" echo "\n"
./ccmeta tests-parsimony/005.c
./ccmeta tests-parsimony/parsimony-lang/005.c
echo "\n" echo "\n"
echo "\n" echo "\n"
./ccmeta tests-parsimony/006.c
./ccmeta tests-parsimony/parsimony-lang/006.c
echo "\n" echo "\n"
echo "\n" echo "\n"
./ccmeta tests-parsimony/007.c
./ccmeta tests-parsimony/parsimony-lang/007.c
echo "\n" echo "\n"
echo "\n" echo "\n"
./ccmeta tests-parsimony/map.c
./ccmeta tests-parsimony/parsimony-lang/map.c
echo "\n" echo "\n"
./ccmeta tests-parsimony/projExample.c
echo "\n" echo "\n"
echo "ok !" echo "ok !"

+ 4
- 4
tests-parsimony/parsimony-lang/map.c 查看文件

@ -7,11 +7,11 @@ enum oof { A, B, C };
isEnum(x) { x.__proto__ == C_enum } isEnum(x) { x.__proto__ == C_enum }
notToken(x) { x.__proto__ != Token } notToken(x) { x.__proto__ != Token }
to_C_string(x) {{ __proto__: C_string, value: "\"" + string(x.name.identifier) + "\"" }} 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; nil;
} }

+ 1
- 1
tests-parsimony/projExample.c 查看文件

@ -8,4 +8,4 @@ enum foo { Closed = 0, ReadOnly = 1, WriteOnly = 2 };
nil; 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 查看文件

@ -1,4 +1,4 @@
@(import("class.mc"))
@(import("fake-static-classes.mc"))
@{ @{
//creation of the class //creation of the class
@ -15,7 +15,10 @@
(P.values.w != null) ? print("\nyes\n\n") : print("\nno\n\n"); (P.values.w != null) ? print("\nyes\n\n") : print("\nno\n\n");
// Use of the P class // 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); x.functions.printf(x);
// Create another class from P // Create another class from P
@ -27,7 +30,10 @@
Q.functions.printf = printf; Q.functions.printf = printf;
// Use of the Q class // 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); y.functions.printf(y);
nil; nil;

+ 1
- 1
tests-parsimony/testFile2.c 查看文件

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

正在加载...
取消
保存