Przeglądaj źródła

Simplification

develop-theo
Theo Souchon 2 lat temu
rodzic
commit
cc35616769
3 zmienionych plików z 40 dodań i 39 usunięć
  1. +3
    -4
      class.mc
  2. +12
    -20
      tests-parsimony/testFile.c
  3. +25
    -15
      tests-parsimony/testFile2.c

+ 3
- 4
class.mc Wyświetl plik

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

+ 12
- 20
tests-parsimony/testFile.c Wyświetl plik

@ -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 class="p">, 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;

+ 25
- 15
tests-parsimony/testFile2.c Wyświetl plik

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

Ładowanie…
Anuluj
Zapisz