diff --git a/sources/zweic/Analyzer.scala b/sources/zweic/Analyzer.scala index 6826852..fb34bf1 100755 --- a/sources/zweic/Analyzer.scala +++ b/sources/zweic/Analyzer.scala @@ -41,7 +41,7 @@ val cs = ClassSymbol(tree.pos, name.name, None); classScope = classScope + name.name -> cs; name.sym = cs; - members.foreach(x => analyzeMember(cs,x)) + members.foreach(x => analyzeMember(cs,x)); } case ClassDef(name, extend, members) => @@ -56,7 +56,7 @@ val cs = ClassSymbol(tree.pos, name.name, classScope.get(extend.get.name)); classScope = classScope + name.name -> cs; name.sym = cs; - members.foreach(x => analyzeMember(cs,x)) + members.foreach(x => analyzeMember(cs,x)); } } @@ -70,16 +70,16 @@ Report.error(tree.pos, "class variable '" + name + "' already defined"); case None => name.sym = FieldSymbol(tree.pos, name.name, analyzeType(typ)); - ownerClass.enterField(name.sym.asInstanceOf[FieldSymbol]); + ownerClass.enterField(name.sym.asInstanceOf[FieldSymbol]); } case MethodDef(name, args, rtype, expr) => var myVarScope = emptyVarScope; - //XXX tree.asInstanceOf[MethodDef].self = Name(ownerClass.name); myVarScope = myVarScope + "this" -> VarSymbol(ownerClass.pos, "this", IClassType(ownerClass)); + var offset = 4; val paramtypes = for ( val f <- args ) yield { //TODO: check that there isn't already a class field with the same name myVarScope.get(f.name.name) match { @@ -88,7 +88,9 @@ case None => () } val at = analyzeType(f.typ); + offset = offset + 4; f.name.sym = VarSymbol(f.pos, f.name.name, at); + f.name.sym.offset = offset; myVarScope = myVarScope + f.name.name -> f.name.sym.asInstanceOf[VarSymbol]; at } diff --git a/sources/zweic/Generator.scala b/sources/zweic/Generator.scala index 94e5492..6cc4107 100644 --- a/sources/zweic/Generator.scala +++ b/sources/zweic/Generator.scala @@ -140,7 +140,8 @@ //code.decFrameSize(4); // fs = params + this //code.emit(SUBI, SP, SP, params.length*4+4); - code.emit(POP, LNK, SP, code.getFrameSize()-params.length); + //TODO FP + code.emit(POP, LNK, SP, code.getFrameSize()-params.length*4); code.decFrameSize(code.getFrameSize()); // fs = 0 code.incFrameSize(oldFrameSize); // fs = oldframesize @@ -299,10 +300,10 @@ case Ident(name) => if ( name.name == "this" ) { - code.emit(LDW, targetReg, SP, code.getFrameSize()/4, name.name + " FS:" + code.getFrameSize()); + code.emit(LDW, targetReg, SP, code.getFrameSize()-4, name.name + " FS:" + code.getFrameSize()); } else { - code.emit(LDW, targetReg, SP, code.getFrameSize()/4-(name.sym.offset), - name.name + "offset"+ name.sym.offset + " FS:" + code.getFrameSize()); + code.emit(LDW, targetReg, SP, code.getFrameSize() - name.sym.offset, //- 4, + name.name + " offset: "+ name.sym.offset + " FS:" + code.getFrameSize()); } case New(name, args) => @@ -396,7 +397,9 @@ code.emit(RET, targetReg); //TODO store return value - code.emit(ADDI, targetReg, RES, 0, "store return value to target reg"); + if (targetReg!=RES) { + code.emit(ADDI, targetReg, RES, 0, "store return value to target reg"); + } code.decFrameSize(args.length*4+4); // fs = oldframesize - params - this @@ -499,46 +502,6 @@ code.emit(BEQ, tmpLeft, targetLabel); } -// case Operators.ADD => -// code.emit(ADD, tmpLeft, tmpLeft, tmpRight); -// if ( when ) { -// code.emit(BNE, tmpLeft, targetLabel); -// } else { -// code.emit(BEQ, tmpLeft, targetLabel); -// } - -// case Operators.SUB => -// code.emit(CMP, tmpLeft, tmpLeft, tmpRight); -// if ( when ) { -// code.emit(BNE, tmpLeft, targetLabel); -// } else { -// code.emit(BEQ, tmpLeft, targetLabel); -// } - -// case Operators.MUL => -// code.emit(MUL, tmpLeft, tmpLeft, tmpRight); -// if ( when ) { -// code.emit(BNE, tmpLeft, targetLabel); -// } else { -// code.emit(BEQ, tmpLeft, targetLabel); -// } - -// case Operators.DIV => -// code.emit(DIV, tmpLeft, tmpLeft, tmpRight); -// if ( when ) { -// code.emit(BNE, tmpLeft, targetLabel); -// } else { -// code.emit(BEQ, tmpLeft, targetLabel); -// } - -// case Operators.MOD => -// code.emit(MOD, tmpLeft, tmpLeft, tmpRight); -// if ( when ) { -// code.emit(BNE, tmpLeft, targetLabel); -// } else { -// code.emit(BEQ, tmpLeft, targetLabel); -// } - case _ => genLoad(tree, tmpLeft); if ( when ) { diff --git a/tests/5/var.zwei b/tests/5/var.zwei index eb97543..6d48e3a 100644 --- a/tests/5/var.zwei +++ b/tests/5/var.zwei @@ -6,7 +6,7 @@ { Int b = 7; b = 8; - printInt(b); + printInt(b); //8 a = 6; }; diff --git a/unittest.py b/unittest.py index ebd131e..2e4cd7a 100644 --- a/unittest.py +++ b/unittest.py @@ -146,7 +146,8 @@ print '.' if errs: print >>sys.stderr, errs - sys.exit(1) + print >>sys.stderr + #sys.exit(1) def check(self, fname, solution): @@ -155,7 +156,8 @@ errs = pipes[2].read() if errs: print >>sys.stderr, errs - sys.exit(2) + print >>sys.stderr + #sys.exit(2) answer = pipes[1].read() if solution == answer: