Skip to content

Commit

Permalink
Bug fixes in frame closing.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbebenita committed Jul 25, 2012
1 parent 989235c commit 192faac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/compiler.js
Expand Up @@ -386,15 +386,12 @@
};

TypeAliasDirective.prototype.scan = function (o) {
var scope;
var scope = new Frame(o.scope, "Struct " + this.original.id.name);;
var thisTy = new PointerType(o.types[this.original.id.name]);
if (this.original instanceof T.StructType) {
var fields = this.original.fields;
for (var i = 0; i < fields.length; i++) {
if (fields[i] instanceof FunctionDeclaration) {
if (!scope) {
scope = new Frame(o.scope, "Struct " + this.original.id.name);
}
o = extend(o, { thisTy: thisTy });
o.scope = scope;
fields[i].scan(o);
Expand Down Expand Up @@ -620,6 +617,7 @@

assert(this.body instanceof BlockStatement);
this.body.body = compileList(this.body.body, o);
this.frame.close();

return cast(this, this.decltype.reflect(o));
};
Expand Down Expand Up @@ -1263,7 +1261,7 @@

Program.prototype.lower = function (o) {
o = extend(o);
o.scope = this.frame;
o.scope = o.frame = this.frame;

this.body = lowerList(this.body, o);
var prologue = createPrologue(this, o);
Expand All @@ -1277,7 +1275,8 @@
FunctionDeclaration.prototype.lower = function (o) {
var memcheckName;
o = extend(o);
o.scope = this.frame;
o.scope = o.frame = this.frame;


if (o.memcheck) {
if (this.id && this.id.name) {
Expand All @@ -1300,7 +1299,6 @@
var prologue = createPrologue(this, o);
var epilogue = createEpilogue(this, o);
this.body.body = prologue.concat(this.body.body).concat(epilogue);
this.frame.close();

return this;
};
Expand Down Expand Up @@ -1343,7 +1341,7 @@
Identifier.prototype.lowerNode = function (o) {
var variable = this.variable;
if (variable && variable.isStackAllocated) {
return variable.getStackAccess(o.scope, this.loc);
return variable.getStackAccess(o.frame, this.loc);
}
};

Expand Down
18 changes: 18 additions & 0 deletions src/tests/structs-0.ljs
Expand Up @@ -10,6 +10,11 @@ struct Point {
function toString() {
return "{x: " + this->x + ", y: " + this->y + "}";
}
function distanceTo(Point * other) {
let Line l (this->x, this->y, other->x, other->y);
console.info(l.toString());
return l.getLength();
}
}

struct Line {
Expand Down Expand Up @@ -45,3 +50,16 @@ console.info(l1.toString());

console.info(l1.a.toString());
console.info(l1.b.toString());

for (let int i = 0; i < 10; i++) {
let Point * k = new Point(1, 2);
console.info(k->toString());
console.info(k);
}

for (let int i = 0; i < 10; i++) {
let Point a (i, 1), b (1, i);
console.info(a.toString() + " @" + &a);
console.info(b.toString() + " @" + &b);
console.info(a.distanceTo(&b));
}

0 comments on commit 192faac

Please sign in to comment.