diff --git a/ccmeta.leg b/ccmeta.leg index 2497bbd..8e5de37 100644 --- a/ccmeta.leg +++ b/ccmeta.leg @@ -2413,7 +2413,7 @@ MO_STRING = 'string' ![(a-zA-Z0-9_] -- #--------------------------------------------- Meta rules ----------------------------------------------# -META_NIL = 'nil' ![a-zA-Z0-9_] -- +META_NIL = 'nil' ![a-zA-Z0-9_] -- #META_FUN = 'fun' ![a-zA-Z0-9_] -- #META_SYNTAX = 'syntax' ![a-zA-Z0-9_] -- META_VAR = 'var' ![a-zA-Z0-9_] -- @@ -3640,6 +3640,8 @@ void outputNode(oop node) case Symbol: outputText(get(node, Symbol, name)); return; + case Function: + return; default: fprintf(stderr, "\noutputNode: unknown node type %i\n", getType(node)); abort(); diff --git a/class.mc b/class.mc new file mode 100644 index 0000000..96a6cd8 --- /dev/null +++ b/class.mc @@ -0,0 +1,35 @@ +@(import("boot.mc")) + +@{ + + classCopy(class) { + {values: clone(class.values), functions: clone(class.functions)}; + } + + initClass(class) { + out = {}; + if (class == null) { + out.values = {}; + out.functions = {}; + } + out; + } + + new(class, param) { + k = 0; + out = initClass(); + for (i in class.values) { + out.values[i] = clone(param[i]); + k++; + } + for (i in class) { + if (i != keys(class)[0] ) { + out[i] = clone(class[i]); + } + } + return out; + } + + + nil; +} \ No newline at end of file diff --git a/tests-parsimony/testFile.c b/tests-parsimony/testFile.c new file mode 100644 index 0000000..e46e91e --- /dev/null +++ b/tests-parsimony/testFile.c @@ -0,0 +1,42 @@ +@(import("class.mc")) + +@{ + //creation of the class + P = initClass(); + P.values.x = "null"; + P.values.y = "null"; + P.values.z = "null"; + P.functions.printf = "null"; + printf(p) { // Can we create a self variable or somthing like that ? + print("Object P : "); + print(p); + print("\n"); + } + P.functions.printf = printf; + + // To know if the parameter is known + print("\n"); + (P.values.x != null) ? print("yes\n") : print("no\n"); + (P.values.w != null) ? print("yes\n") : print("no\n"); + print("\n"); + + // Use of the P class + x = new(P, {x: 2, y: 4, z: 6 }); + x.functions.printf(x); + + // Create another class from P + Q = classCopy(P); + Q.values.q = "null"; + printf(q) { + print("Object Q : "); + print(q); + print("\n"); + } + Q.functions.printf = printf; + + // Use of the Q class + y = new(Q, {x: 1, y: 2, z: 3, q: 42 }); + P.functions.printf(P); + + nil; +} \ No newline at end of file diff --git a/tests-parsimony/testFile2.c b/tests-parsimony/testFile2.c new file mode 100644 index 0000000..e0be8db --- /dev/null +++ b/tests-parsimony/testFile2.c @@ -0,0 +1,47 @@ +@(import("class.mc")) + +@{ + //creation of the object class + Object = initClass(); + Object.type = "object"; + type_t = { type_Nil: 0, type_Int: 1, type_Pair: 2}; + printf(x) { + switch (x.type) { + case type_t.type_Int: { + print(x.values.value); + return; + } + case type_t.type_Pair: { + print("("); + printf(x.values.a); + print(", "); + printf(x.values.d); + print(")"); + return; + } + } + } + Object.functions.printf = printf; + + // from object + Nil = classCopy(Object); + Nil.type = type_t.type_Nil; + Int = classCopy(Object); + Int.values.value = "null"; + Int.type = type_t.type_Int; + Pair = classCopy(Object); + Pair.values.a = "null"; + Pair.values.d = "null"; + Pair.type = type_t.type_Pair; + + // function to simplify the writting of example + newNil(x) { new(Nil, {}); } + newInt(x) { new(Int, {value: x}); } + newPair(x, y) { new(Pair, { a: x, d: y }); } + + // example + l = newPair(newInt(1), newPair(newInt(2), newPair(newInt(3), newNil()))) + l.functions.printf(l); + + nil; +} \ No newline at end of file