diff --git a/tests/self/assembler.es b/tests/self/assembler.es index c46b909c..9de83e03 100644 --- a/tests/self/assembler.es +++ b/tests/self/assembler.es @@ -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 } diff --git a/tests/self/bytestream.es b/tests/self/bytestream.es index 266fe2e2..2e693441 100644 --- a/tests/self/bytestream.es +++ b/tests/self/bytestream.es @@ -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; @@ -80,7 +79,7 @@ (val >> 16) & 0xFF); } - public function uint30(val:uint) { + function uint30(val:uint) { assert(val < 1073741824); uint32(val); } diff --git a/tests/self/cogen.es b/tests/self/cogen.es index e79c62d0..b05b582f 100644 --- a/tests/self/cogen.es +++ b/tests/self/cogen.es @@ -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)); @@ -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; @@ -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" } + /// } } } @@ -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); @@ -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); diff --git a/tests/self/emitter.es b/tests/self/emitter.es index 3d1443ea..1778a9ec 100644 --- a/tests/self/emitter.es +++ b/tests/self/emitter.es @@ -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) { @@ -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) { @@ -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; @@ -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; @@ -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++ ) diff --git a/tests/self/parse-util.es b/tests/self/parse-util.es index 270e495a..6f35637d 100644 --- a/tests/self/parse-util.es +++ b/tests/self/parse-util.es @@ -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 = []; @@ -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