Selaa lähdekoodia

Simplification of dynamicObject.mc

develop-theo
Theo Souchon 2 vuotta sitten
vanhempi
commit
39dda7f39e
4 muutettua tiedostoa jossa 22 lisäystä ja 29 poistoa
  1. +0
    -1
      ccmeta.leg
  2. +7
    -1
      parsimonyLibrary/boot.mc
  3. +13
    -25
      parsimonyLibrary/dynamicObject.mc
  4. +2
    -2
      tests-parsimony/realObject.c

+ 0
- 1
ccmeta.leg Näytä tiedosto

@ -2945,7 +2945,6 @@ oop apply(oop scope, oop this, oop func, oop args, oop ast)
siglongjmp(jbs->jb, j_throw);
}
}
// oop tmpresult = treeCopyUnquoting(get(func, Function, body), localScope); // eval inside the quasiquote thing
oop result= eval(localScope, get(func, Function, body));
untrace(ast);
delScope(localScope);

+ 7
- 1
parsimonyLibrary/boot.mc Näytä tiedosto

@ -17,7 +17,13 @@
//------------ creation C structure ------------//
newId(x) { { identifier: x, __proto__: C_id }; }
newId(x, comm) {
if (comm == null) {
{ identifier: x, __proto__: C_id };
} else {
{ identifier: x, comment: { text : comm, __proto__: Comment }, __proto__: C_id };
}
}
newText(x) { { value: x, __proto__: C_string }; }

+ 13
- 25
parsimonyLibrary/dynamicObject.mc Näytä tiedosto

@ -184,51 +184,39 @@ typedef struct __oop *oop;
}
tmp = {};
// @@ problem for variable changement
tmp[0] = makeln(`declaration struct @@(newId(string(program.objects.currentClassName))) *self = (struct @@(newId(string(program.objects.currentClassName))) *) __self;, 1);
tmp[0] = makeln(`declaration struct @@(newId(string(program.objects.currentClassName), " ")) *self = (struct @@(newId(string(program.objects.currentClassName))) *) __self;, 1);
s.compoundS.expression = treeCopy(fusion(tmp, s.compoundS.expression));
program.objects.function = "none";
return s;
}
/*********** Constructor function ************/
if (program.objects.function == "constructor") {
structDeclaration = makeln(`declaration struct @@(newId(string(program.objects.currentClassName))) *self = calloc(1, sizeof *self);, 1);
rawDeclaration = makeln(`declaration class = findClass(@@(newText("\"" + string(program.objects.currentClassName) + "\"")));, 1);
returnSTMT = makeln(`statement return (struct __oop *) self;);
t = {};
append(t, treeCopy(structDeclaration));
append(t, treeCopy(makeln(`declaration struct @@(newId(string(program.objects.currentClassName), " ")) *self = calloc(1, sizeof *self);, 1)));
// take the structure of self->foo
lhs = treeCopy(s.compoundS.expression[0].expression.lhs);
lhs.rhs = rawDeclaration.declarators[0].lhs;
lhs.rhs = newId("class", " ");
// Change foo to Class
rawDeclaration.declarators[0].lhs = lhs;
// prepare the right object to return
append(s.compoundS.expression, rawDeclaration);
append(s.compoundS.expression, returnSTMT);
append(s.compoundS.expression, makeln(`statement return (struct __oop *) self;));
s.compoundS.expression = fusion(t, s.compoundS.expression);
program.objects.function = "none";
return s;
}
/*********** Main function ************/
if (s.declarators != null && s.declarators.declarators != null && string(s.declarators.declarators.identifier) == "main") {
rawSelector = makeln(`declaration int _selector_ = findSelector("foo");, 1);
rawClass = makeln(`declaration int _class_ = findClass("foo");, 1);
t = {};
for (i in program.objects.methods) {
rawSelector.declarators[0].lhs.identifier = "_selector_" + string(program.objects.methods[i]);
rawSelector.declarators[0].rhs.paramTypeL[0].text[0].value = "\"" + string(program.objects.methods[i]) + "\"";
append(t, treeCopy(rawSelector));
}
classKeys = keys(program.objects.class);
for (i in classKeys) {
rawClass.declarators[0].lhs.identifier = "_class_" + string(classKeys[i]);
rawClass.declarators[0].rhs.paramTypeL[0].text[0].value = "\"" + string(classKeys[i]) + "\"";
append(t, treeCopy(rawClass));
}
rawAddMethod = makeln(`declaration addMethod(_class_, _selector_, foo);, 1);
for (i in program.objects.class) {
className = string(i); // can't work other way
append(t, treeCopy(makeln(`declaration int @@(newId("_class_" + className)) = findClass(@@(newId("\"" + className + "\"")));, 1)));
for (k in program.objects.class[i]) {
newObject = treeCopy(rawAddMethod);
newObject.declarators[0].paramTypeL[0].identifier = string(rawAddMethod.declarators[0].paramTypeL[0].identifier) + string(i);
newObject.declarators[0].paramTypeL[2].identifier = string(rawAddMethod.declarators[0].paramTypeL[2].identifier) + string(program.objects.class[i][k]);
newObject.declarators[0].paramTypeL[4].identifier = "(method_t) " + string(i) + "_" + string(program.objects.class[i][k]);
append(t, treeCopy(newObject));
linkedMethod = string(program.objects.class[i][k]);
append(t, treeCopy(makeln(`declaration int @@(newId("_selector_" + linkedMethod)) = findSelector(@@(newId("\"" + linkedMethod + "\"")));, 1)));
castMethod = "(method_t) " + string(i) + "_" + string(program.objects.class[i][k]);
append(t, treeCopy(makeln(`declaration addMethod(@@(newId("_class_" + className)), @@(newId("_selector_" + linkedMethod)), @@(newId(castMethod)));, 1)));
}
}
s.compoundS.expression = fusion(t, s.compoundS.expression);

+ 2
- 2
tests-parsimony/realObject.c Näytä tiedosto

@ -10,13 +10,13 @@
self->y = y;
}
@method("Point") double magnitude(int x)
@method("Point") double magnitude()
{
printf("point method : %f\n", sqrt(self->x * self->x * self->y * self->y));
return sqrt(self->x * self->x * self->y * self->y);
}
@method("Point") double getX(int y)
@method("Point") double getX()
{
printf("point method : %f\n", self->x);
return self->x;

Ladataan…
Peruuta
Tallenna