diff --git a/class.mc b/class.mc index 96a6cd8..00107c4 100644 --- a/class.mc +++ b/class.mc @@ -2,15 +2,14 @@ @{ - classCopy(class) { - {values: clone(class.values), functions: clone(class.functions)}; - } - initClass(class) { out = {}; if (class == null) { out.values = {}; out.functions = {}; + } else { + out = {values: clone(class.values), functions: clone(class.functions)}; + } out; } diff --git a/tests-parsimony/testFile.c b/tests-parsimony/testFile.c index c6c6c05..9145c0a 100644 --- a/tests-parsimony/testFile.c +++ b/tests-parsimony/testFile.c @@ -2,40 +2,32 @@ @{ //creation of the class - P = initClass(); - P.values.x = "null"; - P.values.y = "null"; - P.values.z = "null"; - P.functions.printf = "null"; + P = initClass(); + P.values.x = "null"; + P.values.y = "null"; printf(p) { // Can we create a self variable or somthing like that ? - print("Object P : "); - print(p); - print("\n"); + print("P(", p.values.x, ", ", p.values.y, ")\n"); } - P.functions.printf = printf; + 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"); + (P.values.x != null) ? print("\nyes") : print("\nno"); + (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, w: 9}); + 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"; + Q = initClass(P); + Q.values.z = "null"; printf(q) { - print("Object Q : "); - print(q); - print("\n"); + print("Q(", q.values.x, ", ", q.values.y, ", ", q.values.z, ")\n"); } Q.functions.printf = printf; // Use of the Q class - y = new(Q, {x: 1, y: 2, z: 3, q: 42 }); + y = new(Q, { x: 1, y: 2, z: 3 }); y.functions.printf(y); nil; diff --git a/tests-parsimony/testFile2.c b/tests-parsimony/testFile2.c index e0be8db..068f5fd 100644 --- a/tests-parsimony/testFile2.c +++ b/tests-parsimony/testFile2.c @@ -2,11 +2,15 @@ @{ //creation of the object class - Object = initClass(); + Object = initClass(); Object.type = "object"; - type_t = { type_Nil: 0, type_Int: 1, type_Pair: 2}; + type_t = { type_Nil: 0, type_Int: 1, type_Pair: 2}; printf(x) { switch (x.type) { + case type_t.type_Nil: { + print("Nil"); + return; + } case type_t.type_Int: { print(x.values.value); return; @@ -14,7 +18,7 @@ case type_t.type_Pair: { print("("); printf(x.values.a); - print(", "); + print(" . "); printf(x.values.d); print(")"); return; @@ -24,24 +28,30 @@ 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; + // Nil + Nil = initClass(Object); + Nil.type = type_t.type_Nil; + // Int + Int = initClass(Object); + Int.values.value = "null"; + Int.type = type_t.type_Int; + // Pair + Pair = initClass(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}); } + 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 = newPair(newInt(1), newPair(newInt(2), newPair(newInt(3), newNil()))); l.functions.printf(l); + print("\n"); + s = newInt(1); + s.functions.printf(s); nil; } \ No newline at end of file