Skip to content

Commit

Permalink
work around cogen issue in cogen in esc
Browse files Browse the repository at this point in the history
--HG--
branch : com.mozilla.es4.smlnj
extra : convert_revision : d8d8b12003cf310684cddfd150d406bbe54863fd
  • Loading branch information
jeffdyer committed Sep 4, 2007
1 parent b02f000 commit e1a5e4c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 95 deletions.
3 changes: 2 additions & 1 deletion tests/self/assembler.es
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ namespace Asm;
const listify = true;
const indent = " ";

function AVM2Assembler(constants, numberOfFormals) {
function AVM2Assembler(constants, numberOfFormals, initScopeDepth) {
this.constants = constants;
this.nextTemp = numberOfFormals+1; // local 0 is always "this"
this.current_scope_depth = initScopeDepth;
}

public function get maxStack() { return max_stack_depth }
Expand Down
5 changes: 2 additions & 3 deletions tests/self/bytestream.es
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
* All data are dumped in litte-endian format.
*/


public final class ABCByteStream
class ABCByteStream
{
public function get length() {
return bytes.length;
Expand Down Expand Up @@ -80,7 +79,7 @@
(val >> 16) & 0xFF);
}

public function uint30(val:uint) {
function uint30(val:uint) {
assert(val < 1073741824);
uint32(val);
}
Expand Down
40 changes: 25 additions & 15 deletions tests/self/cogen.es
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,18 @@ namespace Gen;
let [fxname, fx] = fixtures[i];
let name = emitter.fixtureNameToName(fxname);

switch type (fx) {
case (vf:ValFixture) {
/// switch type (fx) {
/// case (fx:ValFixture) {
if (fx is ValFixture) {
if( !hasTrait(target.traits, name, TRAIT_Slot) )
target.addTrait(new ABCSlotTrait(name, 0, false, 0, emitter.typeFromTypeExpr(vf.type)));
target.addTrait(new ABCSlotTrait(name, 0, false, 0, emitter.typeFromTypeExpr(fx.type)));
// FIXME when we have more general support for type annos
}
case (mf:MethodFixture) {
methidx = cgFunc(ctx, mf.func);
/// case (fx:MethodFixture) {
else if (fx is MethodFixture) {
print ("ctx.stk.tag ",ctx.stk.tag);
var initScopeDepth = ctx.stk.tag=="instance"?2:0;
methidx = cgFunc(ctx, fx.func, initScopeDepth);
switch type (target) {
case (m:Method) {
target.addTrait(new ABCSlotTrait(name, 0, false, 0, 0));
Expand All @@ -142,7 +146,7 @@ namespace Gen;
case (x:*) {
// target.addTrait(new ABCOtherTrait(name, 0, TRAIT_Method, 0, methidx));
trait_kind = TRAIT_Method;
switch type(mf.func.name.kind) {
switch type(fx.func.name.kind) {
case (g:Get) {
print("Getter, target: " + target);
trait_kind = TRAIT_Getter;
Expand All @@ -157,18 +161,24 @@ namespace Gen;
}
}
}
case (cf:ClassFixture) {
clsidx = cgClass(ctx, cf.cls);
/// case (fx:ClassFixture) {
else if (fx is ClassFixture) {
clsidx = cgClass(ctx, fx.cls);
target.addTrait(new ABCOtherTrait(name, 0, TRAIT_Class, 0, clsidx));
}
case (nf:NamespaceFixture) {
target.addTrait(new ABCSlotTrait(name, 0, true, 0, emitter.qname({ns:new PublicNamespace(""), id:"Namespace"}), emitter.namespace(nf.ns), CONSTANT_Namespace));
/// case (fx:NamespaceFixture) {
else if (fx is NamespaceFixture) {
target.addTrait(new ABCSlotTrait(name, 0, true, 0, emitter.qname({ns:new PublicNamespace(""), id:"Namespace"}), emitter.namespace(fx.ns), CONSTANT_Namespace));
}
case (tf:TypeFixture) {
/// case (fx:TypeFixture) {
else if (fx is TypeFixture) {
print ("warning: ignoring type fixture");
}
case (x:*) { throw "Internal error: unhandled fixture type" }
/// case (fx:*) {
else {
throw "Internal error: unhandled fixture type"
}
/// }
}
}

Expand Down Expand Up @@ -261,7 +271,7 @@ namespace Gen;
*/
function cgCtor(ctx, c, instanceInits) {
let formals_type = extractFormalTypes(ctx, c.func);
let method = new Method(ctx.script.e, formals_type, "$construct", false);
let method = new Method(ctx.script.e, formals_type, 2, "$construct", false);
let asm = method.asm;
let defaults = extractDefaultValues(ctx, c.func);
Expand Down Expand Up @@ -341,9 +351,9 @@ namespace Gen;
* Generate code for the function
* Return the function index
*/
function cgFunc({emitter:emitter, script:script}, f:FUNC) {
function cgFunc({emitter:emitter, script:script}, f:FUNC, initScopeDepth) {
let formals_type = extractFormalTypes({emitter:emitter, script:script}, f);
let method = script.newFunction(formals_type);
let method = script.newFunction(formals_type,initScopeDepth);
let asm = method.asm;
let defaults = extractDefaultValues({emitter:emitter, script:script}, f);
Expand Down
18 changes: 10 additions & 8 deletions tests/self/emitter.es
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ namespace Emit;

function Script(e:ABCEmitter) {
this.e = e;
this.init = new Method(e,[]);
this.init = new Method(e,[], 0);
}

public function newClass(name, basename) {
Expand All @@ -346,8 +346,8 @@ namespace Emit;

/* All functions are in some sense global because the
methodinfo and methodbody are both global. */
public function newFunction(formals) {
return new Method(e, formals);
public function newFunction(formals,initScopeDepth) {
return new Method(e, formals, initScopeDepth);
}

public function addException(e) {
Expand Down Expand Up @@ -392,13 +392,13 @@ namespace Emit;

public function getCInit() {
if(cinit == null )
cinit = new Method(s.e, [], "$cinit");
cinit = new Method(s.e, [], 0, "$cinit");
return cinit;
}

/*
public function newIInit(formals, name=null) {
var iinit = new Method(s.e, formals, name);
var iinit = new Method(s.e, formals, 2, name);
iinit.I_getlocal(0);
iinit.I_constructsuper(0);
return iinit;
Expand Down Expand Up @@ -467,11 +467,12 @@ namespace Emit;
public class Method // extends AVM2Assembler
{
public var e, formals, name, asm, traits = [], finalized=false, defaults = null, exceptions=[];

function Method(e:ABCEmitter, formals:Array, name=null, standardPrologue=true) {
asm = new AVM2Assembler(e.constants, formals.length);
var initScopeDepth;
function Method(e:ABCEmitter, formals:Array, initScopeDepth, name=null, standardPrologue=true) {
asm = new AVM2Assembler(e.constants, formals.length, initScopeDepth);
//super(e.constants, formals.length);
this.formals = formals;
this.initScopeDepth = initScopeDepth
this.e = e;
this.name = name;

Expand Down Expand Up @@ -508,6 +509,7 @@ namespace Emit;
var body = new ABCMethodBodyInfo(meth);
body.setMaxStack(asm.maxStack);
body.setLocalCount(asm.maxLocal);
body.setInitScopeDepth(this.initScopeDepth);
body.setMaxScopeDepth(asm.maxScope);
body.setCode(asm);
for ( var i=0 ; i < traits.length ; i++ )
Expand Down
7 changes: 4 additions & 3 deletions tests/self/parse-util.es
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ public namespace Parse;
}
}
//case (p: (ArrayPattern, ObjectPattern)) {
case (x: *) {
case (p: *) {
let tn = new Ast::TempName (n);
var fxtrs = [];
let exprs = [];
Expand All @@ -727,17 +727,18 @@ public namespace Parse;
if (sub is FieldPattern) {
var typ = new Ast::FieldTypeRef (t,sub.ident);
var exp = new Ast::ObjectRef (new Ast::GetTemp (n), sub.ident);
var sub = sub.ptrn;
var ptn = sub.ptrn;
}
/// case (pat: *) {
else {
var typ = new Ast::ElementTypeRef (t,i);
var exp = new Ast::ObjectRef (new Ast::GetTemp (n), new Ast::Identifier (i,[[Ast::noNS]]));
// FIXME what is the ns of a temp and how do we refer it
var ptn = sub;
}
/// }

let [fx,ex] = desugarSubPattern (sub,typ,exp,n+1);
let [fx,ex] = desugarSubPattern (ptn,typ,exp,n+1);
for (let j=0; j<fx.length; ++j) fxtrs.push(fx[j]);
exprs.push(ex);
}
Expand Down
68 changes: 4 additions & 64 deletions tests/self/t.es
Original file line number Diff line number Diff line change
@@ -1,65 +1,5 @@
desugarSubPattern (null,null,null,0);
class A {
function m() { print('hi') }
}

function desugarSubPattern (p: PATTERN, t: Ast::TYPE_EXPR, e: Ast::EXPR, n: int)
: [Ast::FIXTURES, Ast::EXPR]
{
switch type (p) : PATTERN {
case (p:IdentifierPattern) {
let nm = new Ast::PropName ({ns:ns,id:p.ident});
let fx = new Ast::ValFixture (t,ro);
var fxtrs = [[nm,fx]];
if (e !== null) {
var inits = [[nm,e]];
}
else {
var inits = [];
}
var expr = new Ast::InitExpr (it, new Ast::Head ([],[]), inits);
}
case (p:SimplePattern) {
if (e === null) throw "simple pattern without initializer";
var fxtrs = [];
if (it != null) { // we have an init target so must be an init
var ie = identExprFromExpr (p.expr);
var nm = cx.resolveIdentExpr (ie,it);
var expr = new Ast::InitExpr (it, new Ast::Head ([],[]), [[nm,e]]);
}
else {
var expr = new Ast::SetExpr (op,p.expr,e);
}
}
//case (p: (ArrayPattern, ObjectPattern)) {
case (x: *) {
let tn = new Ast::TempName (n);
var fxtrs = [];
let exprs = [];
let ptrns = p.ptrns;
for (let i=0; i<ptrns.length; ++i) {
let sub = ptrns[i];
switch type (sub) {
case (pat: FieldPattern) {
var typ = new Ast::FieldTypeRef (t,sub.ident);
var exp = new Ast::ObjectRef (new Ast::GetTemp (n), sub.ident);
var pat = sub.ptrn;
}
case (pat: *) {
var typ = new Ast::ElementTypeRef (t,i);
var exp = new Ast::ObjectRef (new Ast::GetTemp (n), new Ast::Identifier (i,[[Ast::noNS]]));
// FIXME what is the ns of a temp and how do we refer it
var pat = sub;
}
case (x: *) {
throw "internal error: desugarPattern " + p;
}
}

let [fx,ex] = desugarSubPattern (pat,typ,exp,n+1);
for (let j=0; j<fx.length; ++j) fxtrs.push(fx[j]);
exprs.push(ex);
}
let head = new Ast::Head ([[tn,new Ast::ValFixture (Ast::anyType,false)]],[new Ast::InitExpr (Ast::letInit,new Ast::Head([],[]),[[tn,e]])]);
var expr = new Ast::LetExpr (head, new Ast::ListExpr (exprs));
}
}
return [fxtrs,expr];
}
new A().m()
2 changes: 1 addition & 1 deletion tests/self/util.es
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Util
//package util
{
use default namespace Util
use default namespace Util;
//import bytestream.*;


Expand Down

0 comments on commit e1a5e4c

Please sign in to comment.