nice-commit Mailing List for The Nice Programming Language (Page 25)
Brought to you by:
bonniot
You can subscribe to this list here.
2003 |
Jan
|
Feb
(60) |
Mar
(125) |
Apr
(183) |
May
(140) |
Jun
(227) |
Jul
(141) |
Aug
(181) |
Sep
(75) |
Oct
(89) |
Nov
(187) |
Dec
(162) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(69) |
Feb
(197) |
Mar
(98) |
Apr
(26) |
May
(10) |
Jun
(85) |
Jul
(88) |
Aug
(79) |
Sep
(80) |
Oct
(81) |
Nov
(53) |
Dec
(109) |
2005 |
Jan
(68) |
Feb
(77) |
Mar
(232) |
Apr
(79) |
May
(37) |
Jun
(37) |
Jul
(3) |
Aug
(18) |
Sep
|
Oct
|
Nov
|
Dec
|
2006 |
Jan
(10) |
Feb
|
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(1) |
Dec
(9) |
2007 |
Jan
(2) |
Feb
(8) |
Mar
(2) |
Apr
(5) |
May
|
Jun
|
Jul
|
Aug
(4) |
Sep
|
Oct
|
Nov
(17) |
Dec
(6) |
2008 |
Jan
|
Feb
(3) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Arjan B. <ar...@us...> - 2005-01-01 14:38:13
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13867/F:/nice/src/bossa/syntax Modified Files: customConstructor.nice userOperator.nice Added Files: contract.nice Removed Files: Contract.java Log Message: Converted Contract. --- Contract.java DELETED --- Index: customConstructor.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/customConstructor.nice,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** customConstructor.nice 1 Jan 2005 13:10:55 -0000 1.7 --- customConstructor.nice 1 Jan 2005 14:38:03 -0000 1.8 *************** *** 144,148 **** { return new CustomConstructor(new LocatedString("<init>", className.location()), ! cst, getCCReturnType(className, cst), params, contract: Contract.noContract, className: className, body: body); --- 144,148 ---- { return new CustomConstructor(new LocatedString("<init>", className.location()), ! cst, getCCReturnType(className, cst), params, contract: noContract, className: className, body: body); Index: userOperator.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/userOperator.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** userOperator.nice 1 Jan 2005 13:10:55 -0000 1.1 --- userOperator.nice 1 Jan 2005 14:38:03 -0000 1.2 *************** *** 114,118 **** from bytecode. */ ! if (contract != Contract.noContract) this.typecheck(); } --- 114,118 ---- from bytecode. */ ! if (contract != noContract) this.typecheck(); } --- NEW FILE: contract.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package bossa.syntax; import bossa.util.*; /** The contract of a method. */ public class Contract { private List<Expression> pre = new LinkedList(); private List<Expression> post = new LinkedList(); private StringBuffer requireRepr = new StringBuffer("requires "); private StringBuffer ensureRepr = new StringBuffer("ensures "); private ?MonoSymbol result = null; public void addElement(Expression condition, ?Expression name, boolean precond) { let sym = createIdentExp(new LocatedString("alwaysAssert", condition.location())); Expression call; String repr; if (name == null) { call = createCallExp(sym, condition); repr = condition.toString() + ","; } else { call = createCallExp(sym, condition, name); repr = condition.toString() + ":" + name.toString() + ","; } if (precond) { pre.add(call); requireRepr.append(repr); } else { post.add(call); ensureRepr.append(repr); } } void resolve(VarScope scope, TypeScope typeScope, mlsub.typing.Monotype resultType, Location location) { pre = pre.map(Expression e => analyse(e, scope, typeScope)); if (post.isEmpty()) return; if (! nice.tools.typing.Types.isVoid(resultType)) result = new ResultMonoSymbol(new LocatedString("result", location), resultType); try { if (result != null) scope.addSymbol(result); post = post.map(Expression e => analyse(e, scope, typeScope)); } finally { if (result != null) scope.removeSymbol(result); } } void typecheck() { for (pe : pre) typecheck(pe); for (pe : post) typecheck(pe); } public gnu.expr.Expression compile(gnu.expr.Expression body) { return new gnu.expr.CheckContract(Expression.compile(pre.toArray()), Expression.compile(post.toArray()), body); } toString() { StringBuffer res = new StringBuffer(); if (! pre.isEmpty()) res.append(requireRepr.toString()); if (! post.isEmpty()) res.append(ensureRepr.toString()); return res.toString(); } } let Contract noContract = new NoContract(); class NoContract extends Contract { resolve(scope, typeScope, resultType, location) {} typecheck() {} compile(body) = body; toString() = ""; } class ResultMonoSymbol extends MonoSymbol { isAssignable() = false; compile() = gnu.expr.CheckContract.result; } |
From: Arjan B. <ar...@us...> - 2005-01-01 13:11:06
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31972/F:/nice/src/bossa/syntax Modified Files: customConstructor.nice defaultMethod.nice niceMethod.nice Added Files: userOperator.nice Removed Files: UserOperator.java Log Message: Converted UserOperator. Index: niceMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceMethod.nice,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** niceMethod.nice 31 Dec 2004 20:23:32 -0000 1.5 --- niceMethod.nice 1 Jan 2005 13:10:55 -0000 1.6 *************** *** 31,35 **** } ! isMain() { return name.toString().equals("main") && arity==1 && --- 31,35 ---- } ! public boolean isMain() { return name.toString().equals("main") && arity==1 && *************** *** 185,189 **** computeCode() = getDispatchMethod(this, module); ! getLambda() = nice.tools.code.Gen.dereference(this.getCode()); compile() {} --- 185,189 ---- computeCode() = getDispatchMethod(this, module); ! public gnu.expr.LambdaExp getLambda() = nice.tools.code.Gen.dereference(this.getCode()); compile() {} *************** *** 203,207 **** Contract contract, boolean isOverride) { ! let res = new NiceMethod(name, constraint, returnType, parameters, contract, isOverride: isOverride, returnTypeLocation: returnType.location()); return res; --- 203,207 ---- Contract contract, boolean isOverride) { ! let res = new NiceMethod(name, constraint, returnType, parameters, contract: contract, isOverride: isOverride, returnTypeLocation: returnType.location()); return res; --- NEW FILE: userOperator.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package bossa.syntax; import bossa.util.*; /** An operator whose semantics is defined by the user (i.e. not built-in). A contract can be attached to a user operator. */ public abstract class UserOperator extends MethodDeclaration { private Contract contract; private boolean resolved = false; private MonoSymbol[?] symbols = null; public Contract getContract() = contract; public MonoSymbol[?] getSymbols() = symbols; doResolve() { if (resolved) return; resolved = true; // the type must be found before this.removeChild(this.getSymbol()); this.getSymbol().doResolve(); symbols = parameters.getMonoSymbols(); if (symbols != null) { mlsub.typing.Monotype[] paramTypes = this.getArgTypes(); for (int i = 0; i < notNull(symbols).length; i++) { if (nice.tools.typing.Types.isVoid(paramTypes[i])) throw bossa.util.User.error(notNull(symbols)[i].syntacticType, "A parameter cannot have a void type"); if (notNull(symbols)[i].name != null) { notNull(symbols)[i].type = paramTypes[i]; notNull(scope).addSymbol(notNull(symbols)[i]); } } } else symbols = new MonoSymbol[0]; VarScope scope = notNull(this.scope); TypeScope typeScope = notNull(this.typeScope); super; // The contract must be resolved after the formal parameters since they // can refer to them. contract.resolve(scope, typeScope, this.getReturnType(), this.location()); } resolve() { super; // Adding the constraint in the type scope. It can be useful for // the default values of the formal parameters // (e.g. an anonymous function refering to a type parameter). let cst = this.getType().getConstraint(); if (mlsub.typing.Constraint.hasBinders(cst)) try { notNull(typeScope).addSymbols(notNull(cst).binders()); } catch (TypeScope.DuplicateName ex) { User.error(this, "Double declaration of the same type parameter"); } } innerTypecheck() { /* The body must be type-checked in a rigid context This is not done in MethodDeclaration, because it is not usefull for all subclasses. XXX: Note that this is a waste if this is a method declaration and there is no contract. The performance loss should be mesured, to see if optimisation is necessary. */ mlsub.typing.Typing.implies(); contract.typecheck(); // Set bytecode types for type variables. mlsub.typing.FunType ft = cast(this.getType().getMonotype()); nice.tools.code.Types.setBytecodeType(ft.domain()); nice.tools.code.Types.setBytecodeType(ft.codomain()); } typecheckCompiled() { /* We only need typechecking if there is a contract, to resolve overloading. We will probably be able to remove this if contracts cen be reloaded from bytecode. */ if (contract != Contract.noContract) this.typecheck(); } toString() = super + contract; } --- UserOperator.java DELETED --- Index: customConstructor.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/customConstructor.nice,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** customConstructor.nice 20 Dec 2004 17:16:48 -0000 1.6 --- customConstructor.nice 1 Jan 2005 13:10:55 -0000 1.7 *************** *** 61,65 **** { resolveCCThis(body, this, notNull(classe)); ! body = analyseMethodBody(body, notNull(thisScope), notNull(thisTypeScope), this.getSymbols(), false); } --- 61,65 ---- { resolveCCThis(body, this, notNull(classe)); ! body = analyseMethodBody(body, notNull(thisScope), notNull(thisTypeScope), notNull(this.getSymbols()), false); } *************** *** 144,148 **** { return new CustomConstructor(new LocatedString("<init>", className.location()), ! cst, getCCReturnType(className, cst), params, Contract.noContract, className: className, body: body); --- 144,148 ---- { return new CustomConstructor(new LocatedString("<init>", className.location()), ! cst, getCCReturnType(className, cst), params, contract: Contract.noContract, className: className, body: body); Index: defaultMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/defaultMethod.nice,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** defaultMethod.nice 19 Dec 2004 19:58:28 -0000 1.3 --- defaultMethod.nice 1 Jan 2005 13:10:55 -0000 1.4 *************** *** 131,135 **** createPattern(param.getName() || new LocatedString("_", name.location())))); res.declaration = new MethodWithDefault(name, constraint, returnType, ! parameters, contract, isOverride: isOverride, implementation: res); res.addChild(res.declaration); return res; --- 131,135 ---- createPattern(param.getName() || new LocatedString("_", name.location())))); res.declaration = new MethodWithDefault(name, constraint, returnType, ! parameters, contract: contract, isOverride: isOverride, implementation: res); res.addChild(res.declaration); return res; |
From: Arjan B. <ar...@us...> - 2004-12-31 20:23:42
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19198/F:/nice/src/bossa/syntax Modified Files: Module.java niceMethod.nice Log Message: Make the Module interface not depend on NiceMethod. Index: niceMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceMethod.nice,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** niceMethod.nice 29 Dec 2004 23:10:48 -0000 1.4 --- niceMethod.nice 31 Dec 2004 20:23:32 -0000 1.5 *************** *** 183,187 **** getFullName() = module.getName() + '.' + name + ':' + this.getType(); ! computeCode() = module.getDispatchMethod(this); getLambda() = nice.tools.code.Gen.dereference(this.getCode()); --- 183,187 ---- getFullName() = module.getName() + '.' + name + ':' + this.getType(); ! computeCode() = getDispatchMethod(this, module); getLambda() = nice.tools.code.Gen.dereference(this.getCode()); *************** *** 313,314 **** --- 313,380 ---- (name, constraint, returnType, params, body, contract, isOverride); } + + public gnu.expr.Expression getDispatchMethod(NiceMethod def, Module module) + { + String name = def.getName().toString(); + gnu.expr.LambdaExp res; + gnu.bytecode.Type[] argTypes; + gnu.bytecode.Type retType; + + /* + If this package is not recompiled, + we fetch the bytecode type information + from the previous dispatch class. + Benefits: we get the most precise bytecode type for methods, + as computed during the initial compilation. + This would not be the case if we recomputed it, + as the precise types are found during typechecking. + */ + ?gnu.bytecode.Method meth = module.lookupDispatchClassMethod(name, "id", def.getFullName()); + if (meth != null) // Reuse existing dispatch method header + { + // The dispatch code will have to be regenerated anyway + meth.eraseCode(); + + argTypes = notNull(meth.arg_types); + retType = notNull(meth.return_type); + // Make sure we use the same bytecode name, since compiled code + // can rely on it. + name = meth.getName(); + } + else // Get type information from the nice declaration + { + argTypes = def.javaArgTypes(); + retType = def.javaReturnType(); + } + + // Try to compile the dispatch method as a member method if possible. + ?NiceClass receiver; + if (argTypes.length == 0) + receiver = null; + else + { + receiver = NiceClass.get(def.getArgTypes()[0]); + + // JVM interfaces cannot contain code. + if (receiver != null && receiver.isInterface()) + receiver = null; + + // Special treatment for serialization at the moment. + if (def.getArity() == 2 && + (name.equals("writeObject")||name.equals("readObject"))) + receiver = null; + } + + res = nice.tools.code.Gen.createMethod + (name, argTypes, retType, def.getSymbols(), true, receiver != null); + res.parameterCopies = def.formalParameters().getParameterCopies(); + + // add unique information to disambiguate which method this represents + res.addBytecodeAttribute + (new gnu.bytecode.MiscAttr("id", def.getFullName().getBytes())); + + if (receiver != null) + return receiver.addJavaMethod(res); + else + return module.addMethod(res, false); + } Index: Module.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Module.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Module.java 19 Dec 2004 19:58:28 -0000 1.21 --- Module.java 31 Dec 2004 20:23:31 -0000 1.22 *************** *** 32,36 **** gnu.bytecode.ClassType createClass(String name); void addGlobalVar(gnu.expr.Declaration declaration, boolean constant); ! gnu.expr.Expression getDispatchMethod(UserOperator/*NiceMethod*/ def); gnu.expr.ReferenceExp addMethod(gnu.expr.LambdaExp method, boolean packageMethod); --- 32,36 ---- gnu.bytecode.ClassType createClass(String name); void addGlobalVar(gnu.expr.Declaration declaration, boolean constant); ! gnu.bytecode.Method lookupDispatchClassMethod(String name, String attribute, String value); gnu.expr.ReferenceExp addMethod(gnu.expr.LambdaExp method, boolean packageMethod); |
From: Arjan B. <ar...@us...> - 2004-12-31 20:23:41
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19198/F:/nice/src/bossa/modules Modified Files: Package.java Log Message: Make the Module interface not depend on NiceMethod. Index: Package.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Package.java,v retrieving revision 1.132 retrieving revision 1.133 diff -C2 -d -r1.132 -r1.133 *** Package.java 29 Dec 2004 23:10:46 -0000 1.132 --- Package.java 31 Dec 2004 20:23:31 -0000 1.133 *************** *** 745,748 **** --- 745,753 ---- } + public Method lookupDispatchClassMethod(String name, String attribute, String value) + { + return lookupClassMethod(source.getDispatch(), name, attribute, value); + } + /** @return the bytecode method with this (unique) name *************** *** 774,844 **** return null; } - - public gnu.expr.Expression getDispatchMethod(UserOperator/*NiceMethod*/ def) - { - String name = def.getName().toString(); - LambdaExp res; - Type[] argTypes; - Type retType; - - /* - If this package is not recompiled, - we fetch the bytecode type information - from the previous dispatch class. - Benefits: we get the most precise bytecode type for methods, - as computed during the initial compilation. - This would not be the case if we recomputed it, - as the precise types are found during typechecking. - */ - Method meth = lookupClassMethod(source.getDispatch(), name, - "id", def.getFullName()); - if (meth != null) // Reuse existing dispatch method header - { - // The dispatch code will have to be regenerated anyway - meth.eraseCode(); - - argTypes = meth.arg_types; - retType = meth.return_type; - // Make sure we use the same bytecode name, since compiled code - // can rely on it. - name = meth.getName(); - } - else // Get type information from the nice declaration - { - argTypes = def.javaArgTypes(); - retType = def.javaReturnType(); - } - - // Try to compile the dispatch method as a member method if possible. - NiceClass receiver; - if (argTypes.length == 0) - receiver = null; - else - { - receiver = NiceClass.get(def.getArgTypes()[0]); - - // JVM interfaces cannot contain code. - if (receiver != null && receiver.isInterface()) - receiver = null; - - // Special treatment for serialization at the moment. - if (def.getArity() == 2 && - (name.equals("writeObject")||name.equals("readObject"))) - receiver = null; - } - - res = nice.tools.code.Gen.createMethod - (name, argTypes, retType, def.getSymbols(), true, receiver != null); - res.parameterCopies = def.formalParameters().getParameterCopies(); - - // add unique information to disambiguate which method this represents - res.addBytecodeAttribute - (new MiscAttr("id", def.getFullName().getBytes())); - - if (receiver != null) - return receiver.addJavaMethod(res); - else - return addMethod(res, false); - } /** Add a method to this package and return an expression to refer it. */ --- 779,782 ---- |
From: Arjan B. <ar...@us...> - 2004-12-31 18:40:59
|
Update of /cvsroot/nice/Nice/src/nice/tools/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31454/F:/nice/src/nice/tools/typing Modified Files: PrimitiveType.java Log Message: Converted ConstantExp. Index: PrimitiveType.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/typing/PrimitiveType.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PrimitiveType.java 1 Dec 2004 02:43:53 -0000 1.2 --- PrimitiveType.java 31 Dec 2004 18:40:44 -0000 1.3 *************** *** 37,40 **** --- 37,41 ---- charTC = tc; charType = Types.sureMonotype(new MonotypeConstructor(tc, null)); + charPolytype = new Polytype(charType); return SpecialTypes.charType; } *************** *** 84,87 **** --- 85,89 ---- doubleTC = tc; doubleType = Types.sureMonotype(new MonotypeConstructor(tc, null)); + doublePolytype = new Polytype(doubleType); return SpecialTypes.doubleType; } *************** *** 91,94 **** --- 93,97 ---- floatTC = tc; floatType = Types.sureMonotype(new MonotypeConstructor(tc, null)); + floatPolytype = new Polytype(floatType); return SpecialTypes.floatType; } *************** *** 144,148 **** public static mlsub.typing.Monotype byteType, charType, intType, longType, boolType, shortType, doubleType, floatType, voidType; ! public static Polytype voidPolytype, boolPolytype, bytePolytype, shortPolytype, intPolytype, longPolytype; private static Polytype objectPolytype; --- 147,151 ---- public static mlsub.typing.Monotype byteType, charType, intType, longType, boolType, shortType, doubleType, floatType, voidType; ! public static Polytype voidPolytype, boolPolytype, charPolytype ,bytePolytype, shortPolytype, intPolytype, longPolytype, doublePolytype, floatPolytype; private static Polytype objectPolytype; |
From: Arjan B. <ar...@us...> - 2004-12-31 18:40:58
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31454/F:/nice/src/bossa/parser Modified Files: Parser.jj Log Message: Converted ConstantExp. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.291 retrieving revision 1.292 diff -C2 -d -r1.291 -r1.292 *** Parser.jj 20 Dec 2004 17:16:45 -0000 1.291 --- Parser.jj 31 Dec 2004 18:40:43 -0000 1.292 *************** *** 1289,1293 **** val=patternLiteral() [ "(" additional=typeIdent() ")" ] ! { return bossa.syntax.dispatch.createPattern(val, additional);} | "@" tc=typeIdent() --- 1289,1293 ---- val=patternLiteral() [ "(" additional=typeIdent() ")" ] ! { return val.createPattern(additional);} | "@" tc=typeIdent() *************** *** 1614,1618 **** { representation=integerLiteral() ! { return ConstantExp.makeNumber(representation); } } --- 1614,1618 ---- { representation=integerLiteral() ! { return bossa.syntax.dispatch.createIntegerConstantExp(representation); } } *************** *** 1623,1627 **** { representation.prepend("-"); ! return ConstantExp.makeNumber(representation); } } --- 1623,1627 ---- { representation.prepend("-"); ! return bossa.syntax.dispatch.createIntegerConstantExp(representation); } } *************** *** 1631,1635 **** { representation=floatingLiteral() ! { return ConstantExp.makeFloating(representation); } } --- 1631,1635 ---- { representation=floatingLiteral() ! { return bossa.syntax.dispatch.createFloatConstantExp(representation); } } *************** *** 2082,2086 **** { if (e1 == null) ! e1 = ConstantExp.makeNumber(new LocatedString("0", makeLocation(t))); if (e2 == null) --- 2082,2086 ---- { if (e1 == null) ! e1 = bossa.syntax.dispatch.createIntegerConstantExp(new LocatedString("0", makeLocation(t))); if (e2 == null) *************** *** 2153,2160 **** | ( t="+" | t="-" ) res=PrimaryExpression() ! { if (res instanceof ConstantExp && ((ConstantExp)res).isNumber()) { if (t.kind == MINUS) ! res=((ConstantExp)res).makeNegative(); } else --- 2153,2160 ---- | ( t="+" | t="-" ) res=PrimaryExpression() ! { if (res instanceof NumberConstantExp) { if (t.kind == MINUS) ! res = ((NumberConstantExp)res).makeNegative(); } else |
From: Arjan B. <ar...@us...> - 2004-12-31 18:40:56
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang/inline In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31454/F:/nice/stdlib/nice/lang/inline Modified Files: CompOp.java Log Message: Converted ConstantExp. Index: CompOp.java =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/inline/CompOp.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CompOp.java 25 Feb 2004 11:23:27 -0000 1.6 --- CompOp.java 31 Dec 2004 18:40:44 -0000 1.7 *************** *** 140,143 **** --- 140,144 ---- public void checkSpecialRequirements(bossa.syntax.Expression[] arguments) { + /* TODO: make this work again bossa.syntax.ConstantExp literalexp = null; bossa.syntax.Expression otherexp = null; *************** *** 162,166 **** bossa.util.User.warning(otherexp, "Comparing a value with a constant outside the range of that value"); } ! } // Interpretation --- 163,168 ---- bossa.util.User.warning(otherexp, "Comparing a value with a constant outside the range of that value"); } ! */ ! } // Interpretation |
From: Arjan B. <ar...@us...> - 2004-12-31 18:40:56
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31454/F:/nice/src/bossa/syntax Modified Files: analyse.nice constant.nice enum.nice pattern.nice Removed Files: ConstantExp.java Log Message: Converted ConstantExp. Index: constant.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/constant.nice,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** constant.nice 14 Dec 2004 20:18:05 -0000 1.5 --- constant.nice 31 Dec 2004 18:40:45 -0000 1.6 *************** *** 11,14 **** --- 11,272 ---- /**************************************************************************/ + package bossa.syntax; + + import bossa.util.*; + + /** + Constant expressions (values) of basic types. + + */ + public abstract class ConstantExp extends Expression + { + public final ?Object value; + private String representation; + public ?mlsub.typing.TypeConstructor tc = null; + + ?LocatedString className = null; + + /* + ConstantExp() + { + } + + ConstantExp(Polytype type, TypeConstructor tc, Object value, String representation, + Location location) + { + this.type = type; + this.tc = tc; + this.value = value; + this.representation = representation; + setLocation(location); + } + + ConstantExp(TypeConstructor tc, Object value, String representation, + Location location) + { + this(new mlsub.typing.Polytype(Monotype.sure(new mlsub.typing.MonotypeConstructor(tc,null))), + tc, value, representation, location); + } + + ConstantExp(TypeConstructor tc, String representation, Location location) + { + this(tc, null, representation, location); + } + + public ConstantExp(Object value) + { + this.value = value; + this.representation = value.toString(); + } + */ + + computeType() + { + // The type is known at creation. + } + + toString() = representation; + + equals(ConstantExp other) = this.value.equals(other.value); + + } + + public abstract class NumberConstantExp extends ConstantExp + { + override Number value; + + public ConstantExp makeNegative() + { + LocatedString newRepres = new LocatedString("-"+representation, this.location()); + + if (value instanceof Float || value instanceof Double) + return createFloatConstantExp(newRepres); + + return createIntegerConstantExp(newRepres); + } + + compile() + { + return new gnu.expr.QuoteExp(value, nice.tools.code.Types.javaType(type)); + } + } + + public class IntegerConstantExp extends NumberConstantExp + { + public long longValue() + { + let Number val = cast(value); + return val.longValue(); + } + + isZero() + { + let Number val = cast(value); + return val.intValue() == 0; + } + + } + + public class FloatConstantExp extends NumberConstantExp + { + + } + + public class SymbolConstantExp extends ConstantExp + { + override VarSymbol value; + + compile() + { + let VarSymbol val = cast(value); + return val.compile(); + } + } + + ConstantExp createSymbolConstantExp(?mlsub.typing.TypeConstructor tc, VarSymbol sym, String repres, Location loc) + { + let res = new SymbolConstantExp(tc: tc, value: sym, representation: repres); + res.setLocation(loc); + return res; + } + + public ConstantExp createIntegerConstantExp(LocatedString representation) + { + String rep = representation.toString(); + + int lastCharIndex = rep.length() - 1; + char last = rep.charAt(lastCharIndex); + boolean isLong = last == 'l' || last == 'L'; + if (isLong) + rep = rep.substring(0, lastCharIndex); + + try { + long value = parseInteger(removeUnderscores(rep)); + + mlsub.typing.Polytype type; + mlsub.typing.TypeConstructor tc; + Number object; + + if (Byte.MIN_VALUE <= value <= Byte.MAX_VALUE && !isLong) + { + type = notNull(nice.tools.typing.PrimitiveType.bytePolytype); + tc = notNull(nice.tools.typing.PrimitiveType.byteTC); + object = new Byte(byte(value)); + } + else if (Short.MIN_VALUE <= value <= Short.MAX_VALUE && !isLong) + { + type = notNull(nice.tools.typing.PrimitiveType.shortPolytype); + tc = notNull(nice.tools.typing.PrimitiveType.shortTC); + object = new Short(short(value)); + } + else if (Integer.MIN_VALUE <= value <= Integer.MAX_VALUE && !isLong) + { + type = notNull(nice.tools.typing.PrimitiveType.intPolytype); + tc = notNull(nice.tools.typing.PrimitiveType.intTC); + object = value; + } + else + { + type = notNull(nice.tools.typing.PrimitiveType.longPolytype); + tc = notNull(nice.tools.typing.PrimitiveType.longTC); + object = value; + } + + let res = new IntegerConstantExp(tc: tc, value: object, + representation: ""+value+(isLong ? "L" : "")); + res.type = type; + res.setLocation(representation.location()); + return res; + } + catch(NumberFormatException e) { + e.printStackTrace(); + throw User.error(representation, rep + " is not a valid number"); + } + } + + ConstantExp createIntConstantExp(int value, Location loc) + { + let res = new IntegerConstantExp(tc: nice.tools.typing.PrimitiveType.intTC, + value: value, representation: value.toString()); + res.type = nice.tools.typing.PrimitiveType.intPolytype; + res.setLocation(loc); + return res; + } + + ConstantExp createLongConstantExp(long value) + { + return new IntegerConstantExp(tc: nice.tools.typing.PrimitiveType.longTC, + value: value, representation: value.toString()); + } + + + private long parseInteger(String rep) + { + int radix = 10; + int index = 0; + boolean negative = false; + + // Leading minus + if (rep.startsWith("-")) { + negative = true; + index++; + } + + // Radix specifier + if (rep.startsWith("0x", index) || rep.startsWith("0X", index)) + { + index += 2; + radix = 16; + } + else if (rep.startsWith("#", index)) + { + index++; + radix = 16; + } + else if (rep.startsWith("0", index) && rep.length() > 1 + index) + { + index++; + radix = 8; + } + + if (rep.startsWith("-", index)) + throw new NumberFormatException("Negative sign in wrong position"); + + long result = new java.math.BigInteger(rep.substring(index), radix).longValue(); + + if (negative) + result = -result; + + return result; + } + + private String removeUnderscores(String s) + { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i<s.length(); i++) + if (s.charAt(i) != '_') + sb.append(s.charAt(i)); + + return sb.toString(); + } + + public ConstantExp createFloatConstantExp(LocatedString representation) + { + String repres = removeUnderscores(representation.toString()); + if (repres.endsWith("F") || repres.endsWith("f")) + { + float value = Float.parseFloat(repres); + let res = new FloatConstantExp(tc: nice.tools.typing.PrimitiveType.floatTC, value: value, representation:value+"f"); + res.type = nice.tools.typing.PrimitiveType.floatPolytype; + res.setLocation(representation.location()); + return res; + } + + double value = Double.parseDouble(repres); + let res = new FloatConstantExp(tc: nice.tools.typing.PrimitiveType.doubleTC, value: value, representation: value+""); + res.type = nice.tools.typing.PrimitiveType.doublePolytype; + res.setLocation(representation.location()); + return res; + } /** *************** *** 40,44 **** ConstantExp createNullExp(bossa.util.Location loc) { ! let res = new NullExp(); res.setLocation(loc); return res; --- 298,302 ---- ConstantExp createNullExp(bossa.util.Location loc) { ! let res = new NullExp(value: null, representation: "null"); res.setLocation(loc); return res; *************** *** 57,72 **** public ConstantExp createBooleanConstant(boolean value, Location location) { ! return new BooleanConstantExp(nice.tools.typing.PrimitiveType.boolTC, ! value, value ? "true" : "false", location, compiledValue: notNull(value ? gnu.expr.QuoteExp.trueExp : gnu.expr.QuoteExp.falseExp)); } class CharConstantExp extends ConstantExp { ! longValue() { Character val = cast(this.value); return int(val.charValue()); } } --- 315,338 ---- public ConstantExp createBooleanConstant(boolean value, Location location) { ! let res = new BooleanConstantExp(tc: nice.tools.typing.PrimitiveType.boolTC, ! value: value, representation: value ? "true" : "false", compiledValue: notNull(value ? gnu.expr.QuoteExp.trueExp : gnu.expr.QuoteExp.falseExp)); + res.type = nice.tools.typing.PrimitiveType.boolPolytype; + res.setLocation(location); + return res; } class CharConstantExp extends ConstantExp { ! public long longValue() { Character val = cast(this.value); return int(val.charValue()); } + + compile() + { + return new gnu.expr.QuoteExp(value, nice.tools.code.Types.javaType(type)); + } } *************** *** 77,82 **** User.error(value, "Invalid character constant: " + value); ! return new CharConstantExp(nice.tools.typing.PrimitiveType.charTC, ! s[0], "'" + s + "'", value.location()); } --- 343,356 ---- User.error(value, "Invalid character constant: " + value); ! return createCharConstant(s[0], notNull(value.location())); ! } ! ! public ConstantExp createCharConstant(char value, Location loc) ! { ! let res = new CharConstantExp(tc: nice.tools.typing.PrimitiveType.charTC, ! value: value, representation: "'" + value + "'"); ! res.type = nice.tools.typing.PrimitiveType.charPolytype; ! res.setLocation(loc); ! return res; } *************** *** 87,96 **** public class VoidConstantExp extends ConstantExp { { this.className = voidName; - this.value = gnu.mapping.Values.empty; } ! toString() = "{}"; } --- 361,374 ---- public class VoidConstantExp extends ConstantExp { + override value = gnu.mapping.Values.empty; + override representation = "{}"; { this.className = voidName; } ! compile() ! { ! return new gnu.expr.QuoteExp(value, nice.tools.code.Types.javaType(type)); ! } } *************** *** 105,109 **** final String escapedValue; ! toString() = "\""+escapedValue+"\""; } --- 383,390 ---- final String escapedValue; ! compile() ! { ! return new gnu.expr.QuoteExp(value, nice.tools.code.Types.javaType(type)); ! } } *************** *** 118,124 **** value = escapeEOL(value); ! let res = new StringConstantExp(escapedValue: value); ! res.value = unescapeLiteral(value); ! res.className = stringClassName; return res; } --- 399,403 ---- value = escapeEOL(value); ! let res = new StringConstantExp(value: unescapeLiteral(value), escapedValue: value, representation: "\""+value+"\"" , className: stringClassName); return res; } *************** *** 209,222 **** } ! void setRepresentedType(mlsub.typing.Polytype type, ?gnu.bytecode.Type bytecodeType) { ! this.value = bytecodeType; ! this.representedType = type.getMonotype(); ! this.type = new mlsub.typing.Polytype (type.getConstraint(), Monotype.sure(new mlsub.typing.MonotypeConstructor (nice.tools.typing.PrimitiveType.classTC, [type.getMonotype()]))); } --- 488,504 ---- } ! TypeConstantExp setRepresentedType(mlsub.typing.Polytype type, ?gnu.bytecode.Type bytecodeType) { ! let res = new TypeConstantExp(value: bytecodeType, representation: this.representation); ! res.isExpression = this.isExpression; ! res.isLiteral = this.isLiteral; ! res.representedType = type.getMonotype(); ! res.type = new mlsub.typing.Polytype (type.getConstraint(), Monotype.sure(new mlsub.typing.MonotypeConstructor (nice.tools.typing.PrimitiveType.classTC, [type.getMonotype()]))); + return res; } *************** *** 224,228 **** { if (isLiteral) ! return super; gnu.bytecode.Type type = cast(value); --- 506,510 ---- { if (isLiteral) ! return new gnu.expr.QuoteExp(value, nice.tools.code.Types.javaType(type)); gnu.bytecode.Type type = cast(value); *************** *** 248,252 **** public TypeConstantExp createTypeConstantExp(LocatedString name) { ! return new TypeConstantExp(null, null, name, name.toString(), name.location()); } --- 530,536 ---- public TypeConstantExp createTypeConstantExp(LocatedString name) { ! let res = new TypeConstantExp(value: name, representation: name.toString()); ! res.setLocation(name.location()); ! return res; } *************** *** 271,276 **** if (type instanceof gnu.bytecode.ClassType) { ! TypeConstantExp res = new TypeConstantExp(name); ! res.setRepresentedType(universalPolytype(tc, true), type); res.setLocation(root == null ? name.location() : root.location()); return res; --- 555,559 ---- if (type instanceof gnu.bytecode.ClassType) { ! TypeConstantExp res = new TypeConstantExp(value: name, representation: name.toString()).setRepresentedType(universalPolytype(tc, true), type); res.setLocation(root == null ? name.location() : root.location()); return res; Index: enum.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/enum.nice,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** enum.nice 18 Dec 2004 19:41:01 -0000 1.9 --- enum.nice 31 Dec 2004 18:40:45 -0000 1.10 *************** *** 178,183 **** args.add(new Arguments.Argument(createStringConstantExp(name.toString()), new LocatedString("name",name.location))); ! args.add(new Arguments.Argument(new ConstantExp(nice.tools.typing.PrimitiveType.intTC, ordinal, ! ordinal.toString(), name.location()), new LocatedString("ordinal", name.location))); for (int i = 0; i < fields.size(); i++) --- 178,182 ---- args.add(new Arguments.Argument(createStringConstantExp(name.toString()), new LocatedString("name",name.location))); ! args.add(new Arguments.Argument(createIntConstantExp(ordinal, notNull(name.location())), new LocatedString("ordinal", name.location))); for (int i = 0; i < fields.size(); i++) Index: pattern.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/pattern.nice,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** pattern.nice 30 Dec 2004 18:49:01 -0000 1.14 --- pattern.nice 31 Dec 2004 18:40:45 -0000 1.15 *************** *** 295,304 **** additional: additional, loc: value.location(), atValue: value); ! if (value.tc == nice.tools.typing.PrimitiveType.boolTC) return new BoolPattern(tc: value.tc, additional: additional, loc: value.location(), atValue: value); ! if (value.tc == nice.tools.typing.PrimitiveType.charTC) return new CharPattern(tc: value.tc, additional: additional, loc: value.location(), atValue: value); return new IntPattern(tc: value.tc, additional: additional, loc: value.location(), atValue: value); } --- 295,305 ---- additional: additional, loc: value.location(), atValue: value); ! if (value instanceof BooleanConstantExp) return new BoolPattern(tc: value.tc, additional: additional, loc: value.location(), atValue: value); ! if (value instanceof CharConstantExp) return new CharPattern(tc: value.tc, additional: additional, loc: value.location(), atValue: value); + assert value instanceof IntegerConstantExp; return new IntPattern(tc: value.tc, additional: additional, loc: value.location(), atValue: value); } *************** *** 392,395 **** --- 393,398 ---- public class CharPattern extends ValuePattern { + override CharConstantExp atValue; + setDomainTC(domaintc) { *************** *** 404,407 **** --- 407,412 ---- public class IntPattern extends ValuePattern { + override IntegerConstantExp atValue; + setDomainTC(domaintc) { *************** *** 447,459 **** hi = val+1; ! while(values.any(ConstantExp ce => (ce.value instanceof Number) && (ce.longValue == lo))) lo--; ! values.add(new ConstantExp(new Long(lo))); ! while(values.any(ConstantExp ce => (ce.value instanceof Number) && (ce.longValue == hi))) hi++; ! values.add(new ConstantExp(new Long(hi))); } --- 452,464 ---- hi = val+1; ! while(values.any(ConstantExp ce => (ce instanceof IntegerConstantExp) && (ce.longValue() == lo))) lo--; ! values.add(createLongConstantExp(lo)); ! while(values.any(ConstantExp ce => (ce instanceof IntegerConstantExp) && (ce.longValue() == hi))) hi++; ! values.add(createLongConstantExp(hi)); } *************** *** 474,478 **** let EnumSymbol esym = cast(atValue.value); for (sym : esym.getDefinition().symbols) ! values.add(new ConstantExp(null, tc, sym, sym.name.toString(), this.location)); } --- 479,483 ---- let EnumSymbol esym = cast(atValue.value); for (sym : esym.getDefinition().symbols) ! values.add(createSymbolConstantExp(notNull(tc), sym, sym.name.toString(), this.location)); } *************** *** 498,513 **** matches(EnumPattern p, tag) = (tag != null) && mlsub.typing.Typing.testRigidLeq(tag, p.tc); matchesValue(VariablePattern p, ConstantExp val) = true; - matchesValue(NullPattern p, ConstantExp val) = false; - matchesValue(NotNullPattern p, ConstantExp val) = false; - matchesValue(TypePattern p, ConstantExp val) = false; matchesValue(ValuePattern p, ConstantExp val) = p.atValue.equals(val); ! matchesValue(IntPattern p, ConstantExp val) { ! return (val.value instanceof Number) && p.atValue.longValue() == val.longValue(); } ! matchesValue(IntComparePattern p, ConstantExp val) { ! return val.value instanceof Number && matches(p.kind, val.longValue(), p.atValue.longValue()); } --- 503,516 ---- matches(EnumPattern p, tag) = (tag != null) && mlsub.typing.Typing.testRigidLeq(tag, p.tc); + matchesValue(Pattern p, ConstantExp val) = false; matchesValue(VariablePattern p, ConstantExp val) = true; matchesValue(ValuePattern p, ConstantExp val) = p.atValue.equals(val); ! matchesValue(IntPattern p, IntegerConstantExp val) { ! return p.atValue.longValue() == val.longValue(); } ! matchesValue(IntComparePattern p, IntegerConstantExp val) { ! return matches(p.kind, val.longValue(), p.atValue.longValue()); } *************** *** 738,743 **** NewExp val = cast(symbol.getValue()); return new EnumPattern(name: pattern.name, tc: val.tc, loc: pattern.location(), atValue: ! new ConstantExp(null, pattern.tc, symbol, ! notNull(pattern.name).toString(), pattern.location())); } --- 741,745 ---- NewExp val = cast(symbol.getValue()); return new EnumPattern(name: pattern.name, tc: val.tc, loc: pattern.location(), atValue: ! createSymbolConstantExp(pattern.tc, symbol, notNull(pattern.name).toString(), pattern.location())); } *************** *** 759,765 **** else if (symbol.getValue() instanceof NewExp) { ! NewExp val = cast(symbol.getValue()); return new ReferencePattern(name: pattern.name, tc: val.tc, loc: pattern.location(), atValue: ! new ConstantExp(null, pattern.tc, symbol, notNull(pattern.name).toString(), pattern.location())); } --- 761,767 ---- else if (symbol.getValue() instanceof NewExp) { ! NewExp val = cast(symbol.getValue()); return new ReferencePattern(name: pattern.name, tc: val.tc, loc: pattern.location(), atValue: ! createSymbolConstantExp(pattern.tc, symbol, notNull(pattern.name).toString(), pattern.location())); } *************** *** 826,837 **** { if (name[0] == '\'') ! return createPattern(new CharConstantExp(nice.tools.typing.PrimitiveType.charTC, ! name[1], name, loc)); if (name[0] == '-') ! return createPattern(ConstantExp.makeNumber(new LocatedString(name))); if (name[0] == '+') ! return createPattern(ConstantExp.makeNumber(new LocatedString(name.substring(1)))); if (name[0] == '\"') --- 828,838 ---- { if (name[0] == '\'') ! return createPattern(createCharConstant(name[1], loc)); if (name[0] == '-') ! return createPattern(createIntegerConstantExp(new LocatedString(name))); if (name[0] == '+') ! return createPattern(createIntegerConstantExp(new LocatedString(name.substring(1)))); if (name[0] == '\"') *************** *** 842,846 **** { let prefix = name.substring(0, (name[1] == '=') ? 2 : 1); ! return createPattern(prefix, null, ConstantExp.makeNumber( new LocatedString(name.substring(prefix.length()))), null, loc); } --- 843,847 ---- { let prefix = name.substring(0, (name[1] == '=') ? 2 : 1); ! return createPattern(prefix, null, createIntegerConstantExp( new LocatedString(name.substring(prefix.length()))), null, loc); } --- ConstantExp.java DELETED --- Index: analyse.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/analyse.nice,v retrieving revision 1.120 retrieving revision 1.121 diff -C2 -d -r1.120 -r1.121 *** analyse.nice 25 Dec 2004 23:26:20 -0000 1.120 --- analyse.nice 31 Dec 2004 18:40:45 -0000 1.121 *************** *** 676,682 **** (name.toString(), name.location()); ! e.setRepresentedType(type, bytecodeType); ! ! return e; } --- 676,680 ---- (name.toString(), name.location()); ! return e.setRepresentedType(type, bytecodeType); } |
From: Arjan B. <ar...@us...> - 2004-12-30 20:58:48
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12091/F:/nice/src/bossa/syntax Modified Files: Node.java funexp.nice methodImplementation.nice typecheck.nice Removed Files: Function.java Log Message: Converted Function. Index: Node.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Node.java,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** Node.java 20 Dec 2004 20:25:53 -0000 1.64 --- Node.java 30 Dec 2004 20:58:37 -0000 1.65 *************** *** 291,297 **** // The current function should be saved in nodes that need it // during execution of their typecheck method. ! static Function currentFunction; ! static Function getCurrentFunction() { return currentFunction; } ! static void setCurrentFunction(Function f) { currentFunction = f; } /** The this parameter of the current function, or null. */ --- 291,297 ---- // The current function should be saved in nodes that need it // during execution of their typecheck method. ! static /*Function*/Object currentFunction; ! static /*Function*/Object getCurrentFunction() { return currentFunction; } ! static void setCurrentFunction(/*Function*/Object f) { currentFunction = f; } /** The this parameter of the current function, or null. */ Index: methodImplementation.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/methodImplementation.nice,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** methodImplementation.nice 30 Dec 2004 18:49:01 -0000 1.4 --- methodImplementation.nice 30 Dec 2004 20:58:37 -0000 1.5 *************** *** 141,145 **** } catch (mlsub.typing.TypingEx e) { ! throw new Function.WrongReturnType(e, notNull(declaration).getReturnType()); } } --- 141,145 ---- } catch (mlsub.typing.TypingEx e) { ! throw new WrongReturnType(typingException: e, expectedReturnType: notNull(declaration).getReturnType()); } } --- Function.java DELETED --- Index: funexp.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/funexp.nice,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** funexp.nice 1 Dec 2004 02:00:32 -0000 1.3 --- funexp.nice 30 Dec 2004 20:58:37 -0000 1.4 *************** *** 16,19 **** --- 16,38 ---- /** + A function is either a method body or a lambda expression. + + */ + interface Function + { + /** + The expected return type of this function. + Can be null if it is not known (e.g. the type is inferred). + */ + ?mlsub.typing.Monotype getExpectedType(); + + /** + Called with each type returned from the function. + Can be used for either type checking or type inference. + */ + void checkReturnedType(mlsub.typing.Polytype returned); + } + + /** A functional abstraction expression. */ *************** *** 47,51 **** if (! notNull(_inferredReturnType).trySimplify()) ! throw new Function.IncompatibleReturnType(old); } --- 66,70 ---- if (! notNull(_inferredReturnType).trySimplify()) ! throw new IncompatibleReturnType(previouslyInferredType: old); } *************** *** 140,141 **** --- 159,173 ---- return res; } + + abstract class ReturnTypeError extends Exception {} + + class WrongReturnType extends ReturnTypeError + { + mlsub.typing.TypingEx typingException; + mlsub.typing.Monotype expectedReturnType; + } + + class IncompatibleReturnType extends ReturnTypeError + { + mlsub.typing.Polytype previouslyInferredType; + } Index: typecheck.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v retrieving revision 1.118 retrieving revision 1.119 diff -C2 -d -r1.118 -r1.119 *** typecheck.nice 1 Dec 2004 02:00:32 -0000 1.118 --- typecheck.nice 30 Dec 2004 20:58:37 -0000 1.119 *************** *** 248,252 **** typecheck(FunExp e) { ! ?Function saved = Node.getCurrentFunction(); Node.setCurrentFunction(e); --- 248,252 ---- typecheck(FunExp e) { ! /* ?Function*/ ?Object saved = Node.getCurrentFunction(); Node.setCurrentFunction(e); *************** *** 885,889 **** typecheck(ReturnStmt r) { ! ?Function function = Node.currentFunction; if (function == null) throw bossa.util.User.error(r, "This return is not inside a function"); --- 885,889 ---- typecheck(ReturnStmt r) { ! ?Function function = cast(Node.currentFunction); if (function == null) throw bossa.util.User.error(r, "This return is not inside a function"); *************** *** 907,916 **** function.checkReturnedType(r.returnType()); } ! catch(Function.WrongReturnType e){ if (notNullError(notNull(e.typingException), r, String.valueOf(r.value))) wrongReturnType(r, r.returnType().toString(), valueOf(e.expectedReturnType), notNull(e.typingException)); } ! catch(Function.IncompatibleReturnType e){ throw bossa.util.User.error(r, "The returned value is incompatible with the return type: " + e.previouslyInferredType); } --- 907,916 ---- function.checkReturnedType(r.returnType()); } ! catch(WrongReturnType e){ if (notNullError(notNull(e.typingException), r, String.valueOf(r.value))) wrongReturnType(r, r.returnType().toString(), valueOf(e.expectedReturnType), notNull(e.typingException)); } ! catch(IncompatibleReturnType e){ throw bossa.util.User.error(r, "The returned value is incompatible with the return type: " + e.previouslyInferredType); } *************** *** 919,923 **** typecheck(VoidReturnStmt r) { ! ?Function function = Node.currentFunction; if (function == null) throw bossa.util.User.error(r, "This return is not inside a function"); --- 919,923 ---- typecheck(VoidReturnStmt r) { ! ?Function function = cast(Node.currentFunction); if (function == null) throw bossa.util.User.error(r, "This return is not inside a function"); *************** *** 929,937 **** function.checkReturnedType(r.returnType()); } ! catch(Function.WrongReturnType e){ wrongReturnType(r, r.returnType().toString(), valueOf(e.expectedReturnType), notNull(e.typingException)); } ! catch(Function.IncompatibleReturnType e){ throw bossa.util.User.error(r, "The returned value is incompatible with the return type: " + e.previouslyInferredType); } --- 929,937 ---- function.checkReturnedType(r.returnType()); } ! catch(WrongReturnType e){ wrongReturnType(r, r.returnType().toString(), valueOf(e.expectedReturnType), notNull(e.typingException)); } ! catch(IncompatibleReturnType e){ throw bossa.util.User.error(r, "The returned value is incompatible with the return type: " + e.previouslyInferredType); } |
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19437/F:/nice/src/bossa/syntax Modified Files: alternative.nice compilation.nice dispatch.java.bootstrap methodImplementation.nice methodbody.nice pattern.nice tools.nice Removed Files: Pattern.java Log Message: Converted Pattern. Index: methodbody.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/methodbody.nice,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** methodbody.nice 20 Dec 2004 16:05:18 -0000 1.6 --- methodbody.nice 30 Dec 2004 18:49:01 -0000 1.7 *************** *** 71,76 **** return null; ! ?mlsub.typing.TypeConstructor[] additionalTags = cast(Pattern.getAdditionalTC(formals)); ! boolean hasAdditionalTags = additionalTags.any( ? TypeConstructor tc => tc != null); // Try to remember what caused the error when no symbol could be found. --- 71,76 ---- return null; ! ?mlsub.typing.TypeConstructor[] additionalTags = formals.mapToArray(Pattern p => p.tc2); ! boolean hasAdditionalTags = additionalTags.any(?TypeConstructor tc => tc != null); // Try to remember what caused the error when no symbol could be found. *************** *** 251,255 **** //Resolution of the body is delayed to enable overloading ! Pattern.resolve(notNull(typeScope), Node.getGlobalScope(), formals); symbols = notNull(scope).lookup(name); --- 251,255 ---- //Resolution of the body is delayed to enable overloading ! resolvePatterns(notNull(typeScope), Node.getGlobalScope(), formals); symbols = notNull(scope).lookup(name); *************** *** 258,262 **** void lateBuildScope() { ! Pattern.resolveValues(formals); let s = this.findSymbol(notNull(symbols)); --- 258,262 ---- void lateBuildScope() { ! resolvePatternValues(formals); let s = this.findSymbol(notNull(symbols)); *************** *** 384,388 **** // The arguments are specialized by the patterns try { ! Pattern.in(monotypes, formals); } catch(TypingEx e){ throw User.error(name,"The patterns are not correct", e); --- 384,388 ---- // The arguments are specialized by the patterns try { ! monotypes.inPattern(formals); } catch(TypingEx e){ throw User.error(name,"The patterns are not correct", e); --- Pattern.java DELETED --- Index: methodImplementation.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/methodImplementation.nice,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** methodImplementation.nice 29 Dec 2004 23:10:48 -0000 1.3 --- methodImplementation.nice 30 Dec 2004 18:49:01 -0000 1.4 *************** *** 189,193 **** notNull(compiledMethod).addBytecodeAttribute (new gnu.bytecode.MiscAttr("patterns", ! Pattern.bytecodeRepresentation(formals).getBytes())); } --- 189,193 ---- notNull(compiledMethod).addBytecodeAttribute (new gnu.bytecode.MiscAttr("patterns", ! bytecodeRepresentation(formals).getBytes())); } Index: pattern.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/pattern.nice,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** pattern.nice 20 Dec 2004 16:05:18 -0000 1.13 --- pattern.nice 30 Dec 2004 18:49:01 -0000 1.14 *************** *** 15,21 **** import bossa.util.*; public Pattern createPattern(LocatedString name) { ! return new VariablePattern(name, name.location); } --- 15,249 ---- import bossa.util.*; + /** + Represents the information about one argument of a method body. + + @see MethodBodyDefinition + */ + public abstract class Pattern implements Located + { + ?LocatedString name = null; + ?TypeIdent typeConstructor= null; + private ?TypeIdent additional = null; + ?mlsub.typing.TypeConstructor tc = null; + ?mlsub.typing.TypeConstructor tc2 = null; + ?mlsub.typing.Interface itf2 = null; + + // The class constraint verified by this pattern. + private ?mlsub.typing.Constraint constraint = null; + // The type of the class matched, if it is constrained. + private ?mlsub.typing.Monotype patternType = null; + + private Location loc; + + public ?mlsub.typing.TypeConstructor getTC() = tc; + + ?mlsub.typing.TypeConstructor getRuntimeTC() = null; + + void resolveTC(TypeScope scope) + { + if (typeConstructor != null) + { + TypeSymbol sym = notNull(typeConstructor).resolveToTypeSymbol(scope); + + if (sym instanceof mlsub.typing.TypeConstructor) + tc = sym; + else + throw User.error(this, notNull(typeConstructor) + + " is not a declared class or interface"); + + if (this.exactlyAtType() && !instantiableTC(notNull(tc))) + User.error + (notNull(typeConstructor).location(), + "Pattern #" + notNull(typeConstructor) + + " cannot be matched because interfaces and abstract classes do not have direct instances."); + + typeConstructor = null; + } + if (additional != null) + { + TypeSymbol sym = notNull(additional).resolveToTypeSymbol(scope); + + if (sym instanceof mlsub.typing.TypeConstructor) + tc2 = sym; + else if (sym instanceof mlsub.typing.Interface) + itf2 = sym; + else + User.error(additional, + notNull(additional) + " should be a class or an interface"); + + additional = null; + } + + // Class constraints + if (tc == null) + return; + + let def = getTypeDefinition(notNull(tc)); + if (def == null) + return; + + let classType = def.getConstrainedType(); + if (classType != null) + { + constraint = classType.getConstraint(); + patternType = classType.getMonotype(); + } + } + + /** + Asserts that m is below this pattern. + */ + private void leq(mlsub.typing.Monotype m) + { + nice.tools.typing.Types.setMarkedKind(m); + m = m.equivalent(); + if (!(m instanceof mlsub.typing.MonotypeConstructor)) + throw Internal.error("Nullness check"); + + mlsub.typing.MonotypeConstructor mc = m; + + if (this.atNull()) + mlsub.typing.Typing.leq(nice.tools.typing.PrimitiveType.maybeTC, mc.getTC()); + + if (tc == null) + return; + + // the argument is not null + mlsub.typing.Typing.leq(mc.getTC(), nice.tools.typing.PrimitiveType.sureTC); + mlsub.typing.Monotype type = nice.tools.typing.Types.rawType(mc); + + if (constraint != null) + { + notNull(constraint).enter(); + mlsub.typing.Typing.leq(type, patternType); + if (this.exactlyAtType()) + { + mlsub.typing.Typing.leq(patternType, type); + mlsub.typing.MonotypeConstructor inner = cast(type.equivalent()); + inner.getTC().setMinimal(); + } + } + else + { + mlsub.typing.Typing.leq(type, tc); + if (this.exactlyAtType()) + { + mlsub.typing.Typing.leq(tc, type); + mlsub.typing.MonotypeConstructor inner = cast(type.equivalent()); + inner.getTC().setMinimal(); + } + } + } + + void inDomain(mlsub.typing.Monotype type) + { + nice.tools.typing.Types.setMarkedKind(type); + + if (this.atNull()) + mlsub.typing.Typing.leq(nice.tools.typing.PrimitiveType.maybeTC, type.head()); + + mlsub.typing.Monotype rawType = nice.tools.typing.Types.rawType(type); + + if (constraint != null) + { + notNull(constraint).enter(); + mlsub.typing.Typing.leq(patternType, rawType); + } + else + { + mlsub.typing.Typing.leq(tc, rawType); + } + + if (tc2 != null) + mlsub.typing.Typing.leq(tc2, rawType); + else if (itf2 != null) + mlsub.typing.Typing.assertImp(rawType.head(), itf2, false); + } + + public boolean matches(mlsub.typing.TypeConstructor tag); + + public boolean matchesValue(ConstantExp val); + + public Pattern setDomainEq(boolean equal) + { + return this; + } + + public void setDomainTC(?mlsub.typing.TypeConstructor domaintc) {} + + public void addValues(List<ConstantExp> values) {} + + public ?LocatedString getName() = name; + + location() = loc; + + /** + * Returns a string used to recognize this pattern in the bytecode. + * for the different patterns the following signatures are used: + * any : `@_` + * null : `@NULL` + * type : `@` + type where `.` in type are replaced by `$` + * exactly at type : `#` + type idem + * integer literal : `@-` / `@+` + int_literal + * char literal : `@'c'` where c is an unescaped char + * string literal : `@"string"` where string is an escaped string + * reference : `@` + globalconstantname + * int comparison : `@>` / `@>=` / `@<` / `@<=` + int_literal + * + * This is usefull to distinguish alternatives of a method. + */ + public String bytecodeRepresentation(); + + /** + Returns code that tests if the parameter is matched. + + @param dispatchMade indicates that dispatch has already occured. It is + still necessary to check for exact matching if applicable. + */ + public gnu.expr.Expression matchTest(gnu.expr.Expression parameter, boolean dispatchMade); + + public boolean atAny() = false; + public boolean atNull() = false; + boolean exactlyAtType() = false; + public boolean atValue() = false; + public boolean atTypeMatchingValue() = false; + } + + void resolvePatterns(TypeScope tscope, VarScope vscope, Pattern[] patterns) + { + for (int i = 0; i < patterns.length; i++) + patterns[i].resolveTC(tscope); + } + + void resolvePatternValues(Pattern[] patterns) + { + for (int i = 0; i < patterns.length; i++) + patterns[i] = resolveGlobalConstants(patterns[i]); + } + + /** + Assert that the monotypes belong the the patterns. + */ + void inPattern(mlsub.typing.Monotype[] monotypes, Pattern[] patterns) + { + for (int i = 0; i < monotypes.length; i++) + patterns[i].leq(monotypes[i]); + } + + + public String bytecodeRepresentation(Pattern[] patterns) + { + StringBuffer res = new StringBuffer(); + for (int i = 0; i < patterns.length; i++) + res.append(patterns[i].bytecodeRepresentation()); + + return res.toString(); + } + + public class UnknownPattern extends RuntimeException {} + public Pattern createPattern(LocatedString name) { ! return new VariablePattern(name: name, loc: notNull(name.location())); } *************** *** 23,29 **** { if (ti.toString().equals("Object")) ! return new NotNullPattern(name, nice.tools.typing.PrimitiveType.sureTC, name.location); ! return new TypePattern(name, ti, null, name.location(), exactlyAt: false); } --- 251,257 ---- { if (ti.toString().equals("Object")) ! return new NotNullPattern(name: name, tc: nice.tools.typing.PrimitiveType.sureTC, loc: notNull(name.location)); ! return new TypePattern(name: name, typeConstructor: ti, loc: notNull(name.location()), exactlyAt: false); } *************** *** 31,35 **** public Pattern createPattern(?LocatedString name, ?mlsub.typing.TypeConstructor tc, boolean sure) { // TODO: don't generate NotNullPatterns if the overriden domain is sure. ! let loc = (name != null) ? name.location() : Location.nowhere(); if (nice.tools.typing.Types.isPrimitive(tc)) --- 259,263 ---- public Pattern createPattern(?LocatedString name, ?mlsub.typing.TypeConstructor tc, boolean sure) { // TODO: don't generate NotNullPatterns if the overriden domain is sure. ! let loc = (name != null) ? notNull(name.location()) : Location.nowhere(); if (nice.tools.typing.Types.isPrimitive(tc)) *************** *** 37,46 **** if (sure && tc == null) ! return new NotNullPattern(name, nice.tools.typing.PrimitiveType.sureTC, loc); if (tc == null) ! return new VariablePattern(name, loc); ! return new TypePattern(name, tc, loc, exactlyAt: false); } --- 265,274 ---- if (sure && tc == null) ! return new NotNullPattern(name: name, tc: nice.tools.typing.PrimitiveType.sureTC, loc: loc); if (tc == null) ! return new VariablePattern(name: name, loc: loc); ! return new TypePattern(name: name, tc: tc, loc: loc, exactlyAt: false); } *************** *** 48,54 **** { if (ti.toString().equals("Object")) ! return new NotNullPattern(name, nice.tools.typing.PrimitiveType.sureTC, ti.location); ! return new TypePattern(name, ti, additional, ti.location(), exactlyAt: exactly, runtimeTC: runtimeTC); } --- 276,282 ---- { if (ti.toString().equals("Object")) ! return new NotNullPattern(name: name, tc: nice.tools.typing.PrimitiveType.sureTC, loc: ti.location); ! return new TypePattern(name: name, typeConstructor: ti, additional: additional, loc: ti.location(), exactlyAt: exactly, runtimeTC: runtimeTC); } *************** *** 61,77 **** { if (value instanceof NullExp) ! return new NullPattern(value.tc, additional, value.location()); if (value instanceof StringConstantExp) ! return new StringPattern(null, new TypeIdent(name: new LocatedString("java.lang.String", value.location())), ! additional, value.location(), atValue: value); if (value.tc == nice.tools.typing.PrimitiveType.boolTC) ! return new BoolPattern(value.tc, additional, value.location(), atValue: value); if (value.tc == nice.tools.typing.PrimitiveType.charTC) ! return new CharPattern(value.tc, additional, value.location(), atValue: value); ! return new IntPattern(value.tc, additional, value.location(), atValue: value); } --- 289,305 ---- { if (value instanceof NullExp) ! return new NullPattern(tc: value.tc, additional: additional, loc: value.location()); if (value instanceof StringConstantExp) ! return new StringPattern(typeConstructor: new TypeIdent(name: new LocatedString("java.lang.String", value.location())), ! additional: additional, loc: value.location(), atValue: value); if (value.tc == nice.tools.typing.PrimitiveType.boolTC) ! return new BoolPattern(tc: value.tc, additional: additional, loc: value.location(), atValue: value); if (value.tc == nice.tools.typing.PrimitiveType.charTC) ! return new CharPattern(tc: value.tc, additional: additional, loc: value.location(), atValue: value); ! return new IntPattern(tc: value.tc, additional: additional, loc: value.location(), atValue: value); } *************** *** 89,98 **** let tc = (value != null) ? value.tc : null; ! return new IntComparePattern(name, tc, loc, atValue: cast(value), kind: k, refName: refName); } Pattern createPattern(mlsub.typing.TypeConstructor tc) { ! return new TypePattern(null, tc, null, exactlyAt: false); } --- 317,326 ---- let tc = (value != null) ? value.tc : null; ! return new IntComparePattern(name: name, tc: tc, loc: loc, atValue: cast(value), kind: k, refName: refName); } Pattern createPattern(mlsub.typing.TypeConstructor tc) { ! return new TypePattern(tc: tc, loc: Location.nowhere(), exactlyAt: false); } *************** *** 122,126 **** // only set it to atAny if it's a @type pattern if (equal && !exactlyAt) ! return new VariablePattern(name, this.location); // don't allow integer primitive types in @type and #type patterns --- 350,354 ---- // only set it to atAny if it's a @type pattern if (equal && !exactlyAt) ! return new VariablePattern(name: name, loc: this.location); // don't allow integer primitive types in @type and #type patterns *************** *** 509,515 **** { NewExp val = cast(symbol.getValue()); ! return new EnumPattern(pattern.name, val.tc, pattern.location, atValue: new ConstantExp(null, pattern.tc, symbol, ! notNull(pattern.name).toString(), pattern.location)); } --- 737,743 ---- { NewExp val = cast(symbol.getValue()); ! return new EnumPattern(name: pattern.name, tc: val.tc, loc: pattern.location(), atValue: new ConstantExp(null, pattern.tc, symbol, ! notNull(pattern.name).toString(), pattern.location())); } *************** *** 532,538 **** { NewExp val = cast(symbol.getValue()); ! return new ReferencePattern(pattern.name, val.tc, pattern.location, atValue: new ConstantExp(null, pattern.tc, symbol, ! notNull(pattern.name).toString(), pattern.location)); } else --- 760,766 ---- { NewExp val = cast(symbol.getValue()); ! return new ReferencePattern(name: pattern.name, tc: val.tc, loc: pattern.location(), atValue: new ConstantExp(null, pattern.tc, symbol, ! notNull(pattern.name).toString(), pattern.location())); } else *************** *** 619,623 **** if (name[0] == '=') ! return resolveGlobalConstants(new VariablePattern(new LocatedString(name.substring(1)), loc)); } --- 847,851 ---- if (name[0] == '=') ! return resolveGlobalConstants(new VariablePattern(name: new LocatedString(name.substring(1)), loc: loc)); } *************** *** 626,630 **** if (name.equals("NONNULL")) ! return new NotNullPattern(null, nice.tools.typing.PrimitiveType.sureTC, loc); if (name.equals("NULL")) --- 854,858 ---- if (name.equals("NONNULL")) ! return new NotNullPattern(tc: nice.tools.typing.PrimitiveType.sureTC, loc: loc); if (name.equals("NULL")) *************** *** 639,645 **** // This can happen if the class exists only in a later version // of the JDK. ! throw new Pattern.Unknown(); let mlsub.typing.TypeConstructor tc = cast(sym); ! return new TypePattern(null, tc, Location.nowhere(), exactlyAt:exact); } --- 867,873 ---- // This can happen if the class exists only in a later version // of the JDK. ! throw new UnknownPattern(); let mlsub.typing.TypeConstructor tc = cast(sym); ! return new TypePattern(tc: tc, loc: Location.nowhere(), exactlyAt: exact); } Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.85 retrieving revision 1.86 diff -C2 -d -r1.85 -r1.86 *** tools.nice 29 Dec 2004 23:10:48 -0000 1.85 --- tools.nice 30 Dec 2004 18:49:01 -0000 1.86 *************** *** 213,220 **** <T> String map(String, String, String, T[]) = native String bossa.util.Util.map(String, String, String, Object[]); <T> String map(String, String, String, ?Collection<T>) = native String bossa.util.Util.map(String, String, String, Collection); - void addValues(Pattern, List<ConstantExp>) = native void Pattern.addValues(List); - ?mlsub.typing.TypeConstructor getRuntimeTC(Pattern) = native mlsub.typing.TypeConstructor Pattern.getRuntimeTC(); - boolean matchesValue(Pattern, ConstantExp) = native boolean Pattern.matchesValue(ConstantExp); - ?LocatedString getName(Pattern) = native LocatedString Pattern.getName(); ?mlsub.typing.lowlevel.Kind getKind(mlsub.typing.lowlevel.Element) = native mlsub.typing.lowlevel.Kind mlsub.typing.lowlevel.Element.getKind(); ?gnu.expr.Declaration getDeclaration(Expression) = native gnu.expr.Declaration Expression.getDeclaration(); --- 213,216 ---- Index: compilation.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/compilation.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** compilation.nice 29 Dec 2004 23:10:48 -0000 1.2 --- compilation.nice 30 Dec 2004 18:49:01 -0000 1.3 *************** *** 141,147 **** private NiceClass declaringClass(JavaMethod m, Alternative alt) { ! mlsub.typing.TypeConstructor firstArgument = alt.getPatterns()[0].getTC(); ! let def = getTypeDefinition(firstArgument); ! if (def != null && def.getImplementation() instanceof NiceClass) --- 141,146 ---- private NiceClass declaringClass(JavaMethod m, Alternative alt) { ! ?mlsub.typing.TypeConstructor firstArgument = alt.getPatterns()[0].getTC(); ! let def = firstArgument==null ? null : getTypeDefinition(firstArgument); if (def != null && def.getImplementation() instanceof NiceClass) Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** dispatch.java.bootstrap 29 Dec 2004 23:10:48 -0000 1.47 --- dispatch.java.bootstrap 30 Dec 2004 18:49:01 -0000 1.48 *************** *** 60,78 **** { return null; } - static Pattern resolveGlobalConstants(Pattern pattern) - { return null; } - - public static Pattern readPattern(String rep, int[] pos) - { return null; } - - public static Pattern createPattern(LocatedString name, mlsub.typing.TypeConstructor tc, boolean sure) - { return null; } - - public static boolean leq(Pattern a, Pattern b) - { return false; } - - public static boolean disjoint(Pattern a, Pattern b) - { return false; } - static Expression analyse(Expression e, VarScope v, TypeScope t) { return null; } --- 60,63 ---- Index: alternative.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/alternative.nice,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** alternative.nice 29 Dec 2004 23:10:48 -0000 1.4 --- alternative.nice 30 Dec 2004 18:49:01 -0000 1.5 *************** *** 421,425 **** (fullName, MethodDeclaration.methodListSeparator)); } ! catch(Pattern.Unknown ex) { // This can happen if the class exists only in a later version // of the JDK. We just ignore this alternative. --- 421,425 ---- (fullName, MethodDeclaration.methodListSeparator)); } ! catch(UnknownPattern ex) { // This can happen if the class exists only in a later version // of the JDK. We just ignore this alternative. |
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23166/F:/nice/src/bossa/syntax Modified Files: alternative.nice compilation.nice dispatch.java.bootstrap dispatchTest.nice methodImplementation.nice niceMethod.nice super.nice tools.nice Log Message: Converted Alternative. Index: super.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/super.nice,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** super.nice 19 Dec 2004 22:37:32 -0000 1.5 --- super.nice 29 Dec 2004 23:10:48 -0000 1.6 *************** *** 13,17 **** package bossa.syntax; - import bossa.link.*; import bossa.util.*; --- 13,16 ---- *************** *** 50,57 **** minimumAlt = null; else ! minimumAlt = new Alternative("", notNull(tc).map(mlsub.typing.TypeConstructor tc => createPattern(tc)).toArray()); // Look for the first alternative more general than the current one. ! for (alt : Alternative.sortedAlternatives(decl)) { if (alt == current) --- 49,56 ---- minimumAlt = null; else ! minimumAlt = new Alternative(methodName: "", patterns: notNull(tc).map(mlsub.typing.TypeConstructor tc => createPattern(tc)).toArray()); // Look for the first alternative more general than the current one. ! for (alt : sortedAlternatives(decl)) { if (alt == current) *************** *** 59,69 **** if (minimumAlt != null) ! if (! Alternative.leq(alt, minimumAlt)) continue; ! if (Alternative.leq(current, alt)) ! if (superAlt == null || Alternative.leq(alt, superAlt)) superAlt = alt; ! else if (Alternative.leq(superAlt, alt)) {} // superAlt is a more direct parent than alt, so ignore alt. else --- 58,68 ---- if (minimumAlt != null) ! if (! leq(alt, minimumAlt)) continue; ! if (leq(current, alt)) ! if (superAlt == null || leq(alt, superAlt)) superAlt = alt; ! else if (leq(superAlt, alt)) {} // superAlt is a more direct parent than alt, so ignore alt. else Index: niceMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceMethod.nice,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** niceMethod.nice 29 Dec 2004 16:31:02 -0000 1.3 --- niceMethod.nice 29 Dec 2004 23:10:48 -0000 1.4 *************** *** 129,133 **** // Therefore, all its implementations also belong to this. ! bossa.link.Alternative.addAll(d, this); } --- 129,133 ---- // Therefore, all its implementations also belong to this. ! addAllAlternatives(d, this); } Index: methodImplementation.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/methodImplementation.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** methodImplementation.nice 19 Dec 2004 13:35:48 -0000 1.2 --- methodImplementation.nice 29 Dec 2004 23:10:48 -0000 1.3 *************** *** 39,43 **** MonoSymbol[?] parameters = null; ! private ?bossa.link.Alternative alternative = null; ?gnu.expr.ReferenceExp ref = null; --- 39,43 ---- MonoSymbol[?] parameters = null; ! private ?Alternative alternative = null; ?gnu.expr.ReferenceExp ref = null; *************** *** 131,135 **** } ! bossa.link.Alternative getAlternative() = notNull(alternative); getExpectedType() = notNull(declaration).getReturnType(); --- 131,135 ---- } ! Alternative getAlternative() = notNull(alternative); getExpectedType() = notNull(declaration).getReturnType(); Index: dispatchTest.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatchTest.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dispatchTest.nice 29 Dec 2004 20:22:27 -0000 1.2 --- dispatchTest.nice 29 Dec 2004 23:10:48 -0000 1.3 *************** *** 13,24 **** package bossa.syntax; - import bossa.link.*; import bossa.util.*; List<mlsub.typing.TypeConstructor[]> enumerate(?mlsub.typing.Constraint, mlsub.typing.lowlevel.Element[], boolean[]) = native List mlsub.typing.Enumeration.enumerate(mlsub.typing.Constraint, mlsub.typing.lowlevel.Element[], boolean[]); - boolean matchesValuePart(Alternative, ?ConstantExp[], boolean[]) = native void Alternative.matchesValuePart(ConstantExp[], boolean[]); - - /** Methods performing the coverage and non-ambiguity test. --- 13,20 ---- *************** *** 68,72 **** private void testNiceMethod(NiceMethod m, bossa.modules.Package module) { ! Stack<Alternative> sortedAlternatives = Alternative.sortedAlternatives(m); if (! trivialTestOK(sortedAlternatives)) --- 64,68 ---- private void testNiceMethod(NiceMethod m, bossa.modules.Package module) { ! Stack<Alternative> sortedAlternatives = sortedAlternatives(m); if (! trivialTestOK(sortedAlternatives)) *************** *** 82,86 **** private void testJavaMethod(JavaMethod m, bossa.modules.Package module) { ! Stack<Alternative> sortedAlternatives = Alternative.sortedAlternatives(m); if (! trivialTestJava(m, sortedAlternatives)) --- 78,82 ---- private void testJavaMethod(JavaMethod m, bossa.modules.Package module) { ! Stack<Alternative> sortedAlternatives = sortedAlternatives(m); if (! trivialTestJava(m, sortedAlternatives)) *************** *** 140,151 **** Alternative altB = alternatives[k]; ! if (Alternative.leq(altB, altA)) User.error(method, "ambiguity because of equivalent patterns in:\n" + altA.printLocated() + "\nand\n" + altB.printLocated()); ! if (! (Alternative.leq(altA, altB) || Alternative.disjoint(altA, altB))) { ! let glb = Alternative.greatestLowerBound(altA, altB); if (glb == null) return false; --- 136,147 ---- Alternative altB = alternatives[k]; ! if (leq(altB, altA)) User.error(method, "ambiguity because of equivalent patterns in:\n" + altA.printLocated() + "\nand\n" + altB.printLocated()); ! if (! (leq(altA, altB) || disjoint(altA, altB))) { ! let glb = greatestLowerBound(altA, altB); if (glb == null) return false; *************** *** 153,157 **** boolean glbMatch = false; for (int j = i-1; j >= 0; j--) ! if (Alternative.leq(glb, alternatives[j])) { glbMatch = true; --- 149,153 ---- boolean glbMatch = false; for (int j = i-1; j >= 0; j--) ! if (leq(glb, alternatives[j])) { glbMatch = true; *************** *** 279,283 **** if (first == null) first = a; ! else if (!Alternative.less(first, a) && !a.containsTypeMatchingValue()) { failed = true; --- 275,279 ---- if (first == null) first = a; ! else if (!less(first, a) && !a.containsTypeMatchingValue()) { failed = true; *************** *** 336,340 **** if (first == null) first = a; ! else if (!Alternative.less(first, a)) { failed = true; --- 332,336 ---- if (first == null) first = a; ! else if (!less(first, a)) { failed = true; Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.84 retrieving revision 1.85 diff -C2 -d -r1.84 -r1.85 *** tools.nice 23 Dec 2004 12:49:00 -0000 1.84 --- tools.nice 29 Dec 2004 23:10:48 -0000 1.85 *************** *** 213,217 **** <T> String map(String, String, String, T[]) = native String bossa.util.Util.map(String, String, String, Object[]); <T> String map(String, String, String, ?Collection<T>) = native String bossa.util.Util.map(String, String, String, Collection); - Stack<bossa.link.Alternative> sortedAlternatives(MethodDeclaration) = native Stack bossa.link.Alternative.sortedAlternatives(MethodDeclaration); void addValues(Pattern, List<ConstantExp>) = native void Pattern.addValues(List); ?mlsub.typing.TypeConstructor getRuntimeTC(Pattern) = native mlsub.typing.TypeConstructor Pattern.getRuntimeTC(); --- 213,216 ---- Index: compilation.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/compilation.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** compilation.nice 29 Dec 2004 20:22:27 -0000 1.1 --- compilation.nice 29 Dec 2004 23:10:48 -0000 1.2 *************** *** 14,19 **** package bossa.syntax; - import bossa.link.*; - /** Compilation of the dispatch functions. --- 14,17 ---- Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** dispatch.java.bootstrap 29 Dec 2004 16:31:02 -0000 1.46 --- dispatch.java.bootstrap 29 Dec 2004 23:10:48 -0000 1.47 *************** *** 13,16 **** --- 13,18 ---- public class dispatch { + public static void resetAlternatives() {} + public static void testCoverage(bossa.modules.Package module) {} *************** *** 19,25 **** public static void readImportedAlternative(gnu.bytecode.ClassType c, gnu.bytecode.Method method, bossa.util.Location location) {} - public static bossa.link.Alternative createJavaAlternative(bossa.syntax.MethodDeclaration method) - { return null; } - static TypeScope createGlobalTypeScope() { return null; } --- 21,24 ---- Index: alternative.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/alternative.nice,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** alternative.nice 21 Dec 2004 01:31:14 -0000 1.3 --- alternative.nice 29 Dec 2004 23:10:48 -0000 1.4 *************** *** 17,20 **** --- 17,307 ---- /** + Represents a method alternative in the link. + + It can be build either from information in a Nice source, + or read from a compiled bytecode file. + + */ + public class Alternative implements Located + { + /** + The full name uniquely identifies the method by including the + complete type. + */ + String methodName; + public Pattern[] patterns; + + /** Marks the state of this node in the graph traversal. */ + private int mark = 0; + + /** + * Tests the matching of tags against a method alternative. + */ + public boolean matches(TypeConstructor[] tags) + { + for(int i = 0; i < patterns.length; i++) + if (!patterns[i].matches(tags[i])) + return false; + + return true; + } + + public boolean matchesTypePart(TypeConstructor[] tags, boolean[] isValue) + { + for(int i = 0; i < patterns.length; i++) + if (!isValue[i] && !patterns[i].matches(tags[i])) + return false; + + return true; + } + + public boolean matchesValuePart(?ConstantExp[] values, boolean[] isValue) + { + for(int i = 0; i < patterns.length; i++) + if (isValue[i] && !patterns[i].matchesValue(notNull(values[i]))) + return false; + + return true; + } + + public boolean containsTypeMatchingValue() + { + for(int i = 0; i < patterns.length; i++) + if (patterns[i].atTypeMatchingValue()) + return true; + + return false; + } + + public boolean allAtAny() + { + for (int i = 0; i<patterns.length; i++) + if (! patterns[i].atAny()) + return false; + + return true; + } + + /** + * @return the expression that represents the method body. + */ + public gnu.expr.Expression methodExp() + { + throw Internal.error("methodExp called in " + this.getClass()); + } + + /** + @return the expression that tests if this alternative matches + the tuple <code>parameters</code>. + */ + public gnu.expr.Expression matchTest(gnu.expr.Expression[] parameters, boolean skipFirst) + { + if (parameters.length != patterns.length) + Internal.error("Incorrect parameters "+ + Util.map("",", ","",parameters)+ + " for " + this); + + gnu.expr.Expression result = gnu.expr.QuoteExp.trueExp; + + for (int index = 0; index < parameters.length; index++) + result = nice.tools.code.Gen.shortCircuitAnd + (result, + patterns[index].matchTest(parameters[index], index == 0 && skipFirst)); + + return result; + } + + toString() = methodName + Util.map("(", ", ", ")", patterns); + + public String printLocated() = this.toString(); + + public Pattern[] getPatterns() = patterns; + + location() = Location.nowhere(); + + public void add(String fullName) + { + ?List<Alternative> l = alternativesMap.get(fullName); + if (l == null) + { + // XXX change to LinkedList + l = new ArrayList(); + alternativesMap.put(fullName,notNull(l)); + } + // Dispatch.sort(final List alternatives) assumes that new alternatives + // are added at the end + notNull(l).add(this); + } + + public void add(String[] fullNames) + { + for (int i = 0; i < fullNames.length; i++) + this.add(fullNames[i]); + } + + Alternative addDefaultPatterns(MethodDeclaration def) + { + mlsub.typing.Monotype[?] parameters = nice.tools.typing.Types.parameters(def.getType()); + Pattern[?] newPatterns = null; + + for (int i = 0; i < patterns.length; i++) + if (patterns[i].getTC() == null) + { + if (newPatterns == null) + { + newPatterns = cast(new Pattern[patterns.length]); + System.arraycopy(patterns, 0, notNull(newPatterns), 0, i); + } + notNull(newPatterns)[i] = createPattern + (patterns[i].getName(), + nice.tools.typing.Types.concreteConstructor(notNull(parameters)[i]), + nice.tools.typing.Types.isSure(notNull(parameters)[i])); + } + + if (newPatterns == null) + return this; + else + return new GeneralizedAlternative(methodName: methodName, patterns: newPatterns, parent: this); + } + + } + + // ??? + private class GeneralizedAlternative extends Alternative + { + Alternative parent; + + methodExp() = parent.methodExp(); + } + + var HashMap<String, List<Alternative>> alternativesMap = new HashMap(); + + public void resetAlternatives() + { + alternativesMap = new HashMap(); + } + + public void addAllAlternatives(MethodDeclaration from, MethodDeclaration to) + { + String fullName = to.getFullName(); + + if (from.isJavaMethod()) + createJavaAlternative(from).add(fullName); + + ?List<Alternative> list = alternativesMap.get(from.getFullName()); + + if (list == null) + return; + + for (a : list) + a.addDefaultPatterns(from).add(fullName); + } + + public Stack<Alternative> sortedAlternatives(MethodDeclaration m) + { + ?List<Alternative> list = alternativesMap.get(m.getFullName()); + + if (list == null) + // It's not an error for a method to have no alternative + // as long as its domain is empty. + // this will be checked later + return new Stack(); + + return sortAlts(list); + } + + var int currentVisitedMark = 0; + + /** + Computes a topological sorting of the list of alternatives. + + Uses a postfix travsersal of the graph. + */ + private Stack<Alternative> sortAlts(List<Alternative> alternatives) + { + Stack<Alternative> sortedAlternatives = new Stack(); + + if (alternatives.size() == 0) + return sortedAlternatives; + + // We used a different mark for each sort. + // Useful since an alternative can belong to several methods because of + // overriding, and SuperExp also lists alternatives. + int visited = ++currentVisitedMark; + + for (a : alternatives) + if (a.mark != visited) + visitAlt(a, alternatives, sortedAlternatives, visited); + + return sortedAlternatives; + } + + private void visitAlt(Alternative a, List<Alternative> alternatives, + Stack<Alternative> sortedAlternatives, int visited) + { + a.mark = visited; + + for (daughter : alternatives) + if (daughter.mark != visited && leq(daughter,a)) + visitAlt(daughter, alternatives, sortedAlternatives, visited); + + sortedAlternatives.push(a); + } + + /** + * Returns true iff 'a' is more precise than 'b'. + */ + public boolean leq(Alternative a, Alternative b) + { + for (int i = 0; i<a.patterns.length; i++) + if (! leq(a.patterns[i], b.patterns[i])) + return false; + + return true; + } + + /** + * Returns true iff 'a' is strictly more precise than 'b'. + */ + public boolean less(Alternative a, Alternative b) + { + boolean strictly = false; + + for (int i = 0; i < a.patterns.length; i++) + if (! leq(a.patterns[i], b.patterns[i])) + return false; + else if (! leq(b.patterns[i], a.patterns[i])) + strictly = true; + + return strictly; + } + + public boolean disjoint(Alternative a, Alternative b) + { + for (int i = 0; i<a.patterns.length; i++) + if (disjoint(a.patterns[i], b.patterns[i])) + return true; + + return false; + } + + public ?Alternative greatestLowerBound(Alternative a, Alternative b) + { + Pattern[] pats = cast(new Pattern[a.patterns.length]); + for (int i = 0; i < a.patterns.length; i++) + { + if (leq(a.patterns[i], b.patterns[i])) + pats[i] = a.patterns[i]; + else if (leq(b.patterns[i], a.patterns[i])) + pats[i] = b.patterns[i]; + else + return null; + } + + return new Alternative(methodName: a.methodName, patterns: pats); + } + + + /** An alternative present in the source code. *************** *** 33,38 **** public Alternative createSourceAlternative(MethodImplementation implementation) { ! let res = new SourceAlternative(implementation.getDeclaration().getName().toString(), ! implementation.getPatterns(), implementation: implementation); res.add(implementation.getDeclaration().getFullName()); --- 320,325 ---- public Alternative createSourceAlternative(MethodImplementation implementation) { ! let res = new SourceAlternative(methodName: implementation.getDeclaration().getName().toString(), ! patterns: implementation.getPatterns(), implementation: implementation); res.add(implementation.getDeclaration().getFullName()); *************** *** 66,70 **** nice.tools.typing.Types.isSure(param))); ! return new JavaAlternative(method.getName().toString(), patterns, method: method); } --- 353,357 ---- nice.tools.typing.Types.isSure(param))); ! return new JavaAlternative(methodName: method.getName().toString(), patterns: patterns, method: method); } *************** *** 111,115 **** ?Pattern p; ! while ((p = bossa.syntax.dispatch.readPattern(rep, at)) != null) { if (p.getTC() == nice.tools.typing.PrimitiveType.arrayTC) --- 398,402 ---- ?Pattern p; ! while ((p = readPattern(rep, at)) != null) { if (p.getTC() == nice.tools.typing.PrimitiveType.arrayTC) *************** *** 127,131 **** } ! let alt = new ImportedAlternative(method.getName(), patterns.toArray(), code: new gnu.expr.QuoteExp(new gnu.expr.PrimProcedure(method)), loc: location); --- 414,418 ---- } ! let alt = new ImportedAlternative(methodName: method.getName(), patterns: patterns.toArray(), code: new gnu.expr.QuoteExp(new gnu.expr.PrimProcedure(method)), loc: location); |
From: Arjan B. <ar...@us...> - 2004-12-29 23:10:56
|
Update of /cvsroot/nice/Nice/src/bossa/link In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23166/F:/nice/src/bossa/link Removed Files: Alternative.java Log Message: Converted Alternative. --- Alternative.java DELETED --- |
From: Arjan B. <ar...@us...> - 2004-12-29 23:10:56
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23166/F:/nice/src/bossa/modules Modified Files: Package.java Log Message: Converted Alternative. Index: Package.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Package.java,v retrieving revision 1.131 retrieving revision 1.132 diff -C2 -d -r1.131 -r1.132 *** Package.java 29 Dec 2004 16:31:01 -0000 1.131 --- Package.java 29 Dec 2004 23:10:46 -0000 1.132 *************** *** 288,292 **** nice.tools.code.Types.reset(); nice.tools.code.SpecialTypes.init(); ! bossa.link.Alternative.reset(); bossa.syntax.dispatch.resetDispatchTest(); bossa.syntax.dispatch.resetTypeDefinitionMappings(); --- 288,292 ---- nice.tools.code.Types.reset(); nice.tools.code.SpecialTypes.init(); ! bossa.syntax.dispatch.resetAlternatives(); bossa.syntax.dispatch.resetDispatchTest(); bossa.syntax.dispatch.resetTypeDefinitionMappings(); |
From: Arjan B. <ar...@us...> - 2004-12-29 20:22:39
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20139/F:/nice/src/bossa/syntax Modified Files: NiceUtils.java dispatchTest.nice Added Files: compilation.nice Log Message: Converted Compilation. --- NEW FILE: compilation.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2001 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ // TODO: this class belongs in bossa.link package bossa.syntax; import bossa.link.*; /** Compilation of the dispatch functions. */ let gnu.bytecode.Method newError = notNull(gnu.bytecode.ClassType. make("java.lang.Error")).getDeclaredMethod("<init>", [cast(gnu.bytecode.Type.string_type)]); public void compileNiceMethod(NiceMethod m, Stack<Alternative> sortedAlternatives, bossa.modules.Package module) { gnu.expr.LambdaExp lexp = m.getLambda(); // parameters of the alternative function are the same in each case, // so we compute them just once int arity = m.getArity(); gnu.expr.Expression[] params = cast(new gnu.expr.Expression[arity]); int rank = 0; if (lexp.isClassMethod()) params[rank++] = new gnu.expr.ThisExp(lexp.outerClass()); for(gnu.expr.Declaration param = lexp.firstDecl(); rank < arity; param = param.nextDecl()) params[rank++] = new gnu.expr.ReferenceExp(param); gnu.expr.Expression body = dispatchNiceMethod (sortedAlternatives.iterator(), m.javaReturnType(), m.javaReturnType().isVoid(), params); if (m.isMain()) body = beautifyUncaughtExceptions(body); nice.tools.code.Gen.setMethodBody(lexp, m.getContract().compile(body)); } private gnu.expr.Expression dispatchNiceMethod(Iterator<Alternative> sortedAlternatives, gnu.bytecode.Type returnType, boolean voidReturn, gnu.expr.Expression[] params) { if (!sortedAlternatives.hasNext()) // We produce code that should never be reached at run-time. return new gnu.expr.ApplyExp(NiceUtils.getThrowInstance(), [new gnu.expr.ApplyExp(new gnu.expr.InstantiateProc(newError), [new gnu.expr.QuoteExp("Message not understood")])]); Alternative alt = sortedAlternatives.next(); gnu.expr.Expression matchCase = new gnu.expr.ApplyExp(alt.methodExp(), params); if (voidReturn) matchCase = new gnu.expr.BeginExp(matchCase, nice.tools.code.Gen.returnVoid()); else matchCase = nice.tools.code.Gen.returnValue(matchCase); boolean optimize = true; if (optimize && !sortedAlternatives.hasNext()) return matchCase; else return gnu.expr.SimpleIfExp.make(alt.matchTest(params, false), matchCase, dispatchNiceMethod(sortedAlternatives, returnType, voidReturn, params)); } private gnu.expr.Expression beautifyUncaughtExceptions(gnu.expr.Expression body) { gnu.expr.TryExp res = new gnu.expr.TryExp(body, null); gnu.expr.CatchClause c = new gnu.expr.CatchClause("uncaughtException", gnu.bytecode.Type.throwable_type); res.setCatchClauses(c); gnu.bytecode.Method print = gnu.bytecode.ClassType.make("nice.lang.dispatch"). addMethod("printStackTraceWithSourceInfo", gnu.bytecode.Access.PUBLIC | gnu.bytecode.Access.STATIC, [cast(gnu.bytecode.Type.throwable_type)], gnu.bytecode.Type.void_type); c.setBody(new gnu.expr.ApplyExp(new gnu.expr.PrimProcedure(print), [new gnu.expr.ReferenceExp(c.getDeclaration())])); return res; } public void compileJavaMethod(JavaMethod m, Stack<Alternative> sortedAlternatives, bossa.modules.Package module) { int arity = m.getArity(); while (sortedAlternatives.size() > 0) { // We pick a class, and compile all implementations whose // first argument is at that class. Iterator<Alternative> i = sortedAlternatives.iterator(); Alternative a = i.next(); NiceClass c = declaringClass(m, a); i.remove(); List<Alternative> l = new LinkedList(); l.add(a); while (i.hasNext()) { a = i.next(); if (declaringClass(m, a) == c) { l.add(a); i.remove(); } } gnu.expr.Expression[] params = cast(new gnu.expr.Expression[arity]); gnu.expr.LambdaExp lambda = nice.tools.code.Gen.createMemberMethod (m.getName().toString(), c.getClassExp().getType(), m.javaArgTypes(), m.javaReturnType(), params); c.addJavaMethod(lambda); gnu.expr.Expression body = dispatchJavaMethod (l.iterator(), m.javaReturnType(), m.javaReturnType().isVoid(), params, cast(c.getClassExp().getType()), m); nice.tools.code.Gen.setMethodBody(lambda, body); } } private NiceClass declaringClass(JavaMethod m, Alternative alt) { mlsub.typing.TypeConstructor firstArgument = alt.getPatterns()[0].getTC(); let def = getTypeDefinition(firstArgument); if (def != null && def.getImplementation() instanceof NiceClass) return cast(def.getImplementation()); // Explain that this cannot be done. String msg = m + " is a native method.\n"; if (firstArgument == null) msg += "It cannot be implemented without dispatch on the first argument"; else msg += "It cannot be overriden because the first argument " + firstArgument + " is not a class defined in Nice"; throw User.error(alt, msg); } private gnu.expr.Expression dispatchJavaMethod(Iterator<Alternative> sortedAlternatives, gnu.bytecode.Type returnType, boolean voidReturn, gnu.expr.Expression[] params, gnu.bytecode.ClassType c, JavaMethod m) { if (!sortedAlternatives.hasNext()) { // Call super. gnu.bytecode.ClassType superClass = notNull(c.getSuperclass()); ?gnu.bytecode.Method superMethod = superClass.getMethod (m.getName().toString(), m.javaArgTypes(), true); if (superMethod != null) return new gnu.expr.ApplyExp (new gnu.expr.QuoteExp(gnu.expr.PrimProcedure.specialCall(superMethod)), params); // We produce code that should never be reached at run-time. return new gnu.expr.ApplyExp(NiceUtils.getThrowInstance(), [new gnu.expr.ApplyExp(new gnu.expr.InstantiateProc(newError), [new gnu.expr.QuoteExp("Message not understood")])]); } Alternative alt = sortedAlternatives.next(); gnu.expr.Expression matchCase = new gnu.expr.ApplyExp(alt.methodExp(), params); if (voidReturn) matchCase = new gnu.expr.BeginExp(matchCase, nice.tools.code.Gen.returnVoid()); else matchCase = nice.tools.code.Gen.returnValue(matchCase); return gnu.expr.SimpleIfExp.make (alt.matchTest(params, /* skip first */ true), matchCase, dispatchJavaMethod(sortedAlternatives, returnType, voidReturn, params, c, m)); } Index: NiceUtils.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceUtils.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NiceUtils.java 16 Dec 2004 00:30:29 -0000 1.3 --- NiceUtils.java 29 Dec 2004 20:22:27 -0000 1.4 *************** *** 25,28 **** --- 25,34 ---- } + public static gnu.mapping.Procedure getThrowInstance() + { + return nice.lang.inline.Throw.instance; + } + + static ClassLoader inlineLoader; Index: dispatchTest.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatchTest.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dispatchTest.nice 29 Dec 2004 16:31:02 -0000 1.1 --- dispatchTest.nice 29 Dec 2004 20:22:27 -0000 1.2 *************** *** 77,84 **** bossa.util.Debug.println("Generating dispatch function for "+m); ! Compilation.compile(m, sortedAlternatives, module); } ! private void testJavaMethod(MethodDeclaration/*JavaMethod*/ m, bossa.modules.Package module) { Stack<Alternative> sortedAlternatives = Alternative.sortedAlternatives(m); --- 77,84 ---- bossa.util.Debug.println("Generating dispatch function for "+m); ! compileNiceMethod(m, sortedAlternatives, module); } ! private void testJavaMethod(JavaMethod m, bossa.modules.Package module) { Stack<Alternative> sortedAlternatives = Alternative.sortedAlternatives(m); *************** *** 90,94 **** bossa.util.Debug.println("Generating dispatch function for " + m); ! Compilation.compile(m, sortedAlternatives, module); } --- 90,94 ---- bossa.util.Debug.println("Generating dispatch function for " + m); ! compileJavaMethod(m, sortedAlternatives, module); } |
From: Arjan B. <ar...@us...> - 2004-12-29 20:22:37
|
Update of /cvsroot/nice/Nice/src/bossa/link In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20139/F:/nice/src/bossa/link Modified Files: Alternative.java Removed Files: Compilation.java Log Message: Converted Compilation. --- Compilation.java DELETED --- Index: Alternative.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Alternative.java,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** Alternative.java 29 Dec 2004 16:31:01 -0000 1.61 --- Alternative.java 29 Dec 2004 20:22:26 -0000 1.62 *************** *** 173,177 **** the tuple <code>parameters</code>. */ ! Expression matchTest(Expression[] parameters, boolean skipFirst) { if (parameters.length != patterns.length) --- 173,177 ---- the tuple <code>parameters</code>. */ ! public Expression matchTest(Expression[] parameters, boolean skipFirst) { if (parameters.length != patterns.length) |
From: Arjan B. <ar...@us...> - 2004-12-29 16:31:17
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10834/F:/nice/src/bossa/syntax Modified Files: dispatch.java.bootstrap javaMethod.nice niceMethod.nice retypedMethod.nice Added Files: dispatchTest.nice Log Message: Converted DispatchTest. Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** dispatch.java.bootstrap 21 Dec 2004 01:31:14 -0000 1.45 --- dispatch.java.bootstrap 29 Dec 2004 16:31:02 -0000 1.46 *************** *** 13,16 **** --- 13,20 ---- public class dispatch { + public static void testCoverage(bossa.modules.Package module) {} + + public static void resetDispatchTest() {} + public static void readImportedAlternative(gnu.bytecode.ClassType c, gnu.bytecode.Method method, bossa.util.Location location) {} Index: retypedMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/retypedMethod.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** retypedMethod.nice 20 Dec 2004 16:05:18 -0000 1.2 --- retypedMethod.nice 29 Dec 2004 16:31:02 -0000 1.3 *************** *** 175,179 **** this.ignoredRetyping = true; ! bossa.link.DispatchTest.unregister(this); } --- 175,179 ---- this.ignoredRetyping = true; ! unregisterDispatchTest(this); } *************** *** 282,285 **** { Node.getGlobalScope().removeSymbol(m.getSymbol()); ! bossa.link.DispatchTest.unregister(m); } --- 282,285 ---- { Node.getGlobalScope().removeSymbol(m.getSymbol()); ! unregisterDispatchTest(m); } Index: niceMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceMethod.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** niceMethod.nice 20 Dec 2004 17:16:48 -0000 1.2 --- niceMethod.nice 29 Dec 2004 16:31:02 -0000 1.3 *************** *** 28,32 **** { ! bossa.link.DispatchTest.register(this); } --- 28,32 ---- { ! registerDispatchTest(this); } Index: javaMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/javaMethod.nice,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** javaMethod.nice 24 Dec 2004 12:06:10 -0000 1.3 --- javaMethod.nice 29 Dec 2004 16:31:02 -0000 1.4 *************** *** 67,71 **** return; ! bossa.link.DispatchTest.register(this); this.registered = true; } --- 67,71 ---- return; ! registerDispatchTest(this); this.registered = true; } --- NEW FILE: dispatchTest.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package bossa.syntax; import bossa.link.*; import bossa.util.*; List<mlsub.typing.TypeConstructor[]> enumerate(?mlsub.typing.Constraint, mlsub.typing.lowlevel.Element[], boolean[]) = native List mlsub.typing.Enumeration.enumerate(mlsub.typing.Constraint, mlsub.typing.lowlevel.Element[], boolean[]); boolean matchesValuePart(Alternative, ?ConstantExp[], boolean[]) = native void Alternative.matchesValuePart(ConstantExp[], boolean[]); /** Methods performing the coverage and non-ambiguity test. */ public void registerDispatchTest(NiceMethod m) { dispatchTestMethods.add(m); } public void registerDispatchTest(JavaMethod m) { dispatchTestJavaMethods.add(m); } public void unregisterDispatchTest(MethodDeclaration m) { dispatchTestJavaMethods.remove(m); } private var List<NiceMethod> dispatchTestMethods = new ArrayList(); private var List<JavaMethod> dispatchTestJavaMethods = new ArrayList(); public void resetDispatchTest() { dispatchTestMethods = new ArrayList(); dispatchTestJavaMethods = new ArrayList(); } private var nice.tools.util.Chronometer dispatchTestChrono = nice.tools.util.Chronometer.make("Dispatch tests"); public void testCoverage(bossa.modules.Package module) { dispatchTestChrono.start(); try { for (method : dispatchTestMethods) testNiceMethod(method, module); for (method : dispatchTestJavaMethods) testJavaMethod(method, module); } finally { dispatchTestChrono.stop(); } } private void testNiceMethod(NiceMethod m, bossa.modules.Package module) { Stack<Alternative> sortedAlternatives = Alternative.sortedAlternatives(m); if (! trivialTestOK(sortedAlternatives)) if (! shortTestOk(m, sortedAlternatives)) testMethod(m, sortedAlternatives, false); if(bossa.util.Debug.codeGeneration) bossa.util.Debug.println("Generating dispatch function for "+m); Compilation.compile(m, sortedAlternatives, module); } private void testJavaMethod(MethodDeclaration/*JavaMethod*/ m, bossa.modules.Package module) { Stack<Alternative> sortedAlternatives = Alternative.sortedAlternatives(m); if (! trivialTestJava(m, sortedAlternatives)) testMethod(m, sortedAlternatives, true); if(bossa.util.Debug.codeGeneration) bossa.util.Debug.println("Generating dispatch function for " + m); Compilation.compile(m, sortedAlternatives, module); } private boolean trivialTestOK(Stack<Alternative> alternatives) { // return true iff // there is only one alternative and it does not constrain its arguments if(alternatives.size()!=1) return false; return alternatives.peek().allAtAny(); } private boolean trivialTestJava(MethodDeclaration m, Stack<Alternative> alternatives) { gnu.bytecode.Method reflectMethod = m.getReflectMethod(); // Static methods and constructors cannot be overriden, so there is // no problem. if (reflectMethod.getStaticFlag() || reflectMethod.isConstructor()) return true; if (! reflectMethod.isAbstract()) // The only risk with a non abstract method is that it might be // ambiguous. // We know this won't happen in two cases: // 1) if there is only one argument (single // inheritance, since the root must be a class), // 2) if there are less than two implementations. return m.getArity() == 1 || alternatives.size() < 2; // This method will need testing. return false; } private boolean shortTestOk(NiceMethod method, Stack<Alternative> alternatives) { if (alternatives.size() < 2) return false; //check for default implementation if (! alternatives.peek().allAtAny()) return false; for (int i = 0; i < alternatives.size(); i++) for (int k = i+1; k < alternatives.size(); k++) { Alternative altA = alternatives[i]; Alternative altB = alternatives[k]; if (Alternative.leq(altB, altA)) User.error(method, "ambiguity because of equivalent patterns in:\n" + altA.printLocated() + "\nand\n" + altB.printLocated()); if (! (Alternative.leq(altA, altB) || Alternative.disjoint(altA, altB))) { let glb = Alternative.greatestLowerBound(altA, altB); if (glb == null) return false; boolean glbMatch = false; for (int j = i-1; j >= 0; j--) if (Alternative.leq(glb, alternatives[j])) { glbMatch = true; break; } if (! glbMatch) return false; } } return true; } private boolean[] findUsedPositions(int len, Stack<Alternative> alternatives) { // We want all solutions for both the nullness marker and the tag, // if that position is used. boolean[] res = new boolean[len * 2]; for (a : alternatives) { if (len != notNull(a.patterns).length) Internal.error("Expected number of patterns is " + len + ".\nThe incorrect alternative: " + a); for (int i = 0; i < len; i++) if (! notNull(a.patterns)[i].atAny()) res[2*i] = res[2*i + 1] = true; } return res; } private void testMethod(MethodDeclaration method, Stack<Alternative> sortedAlternatives, boolean isJavaMethod) { if (bossa.util.Debug.linkTests) { bossa.util.Debug.println("\nLink test for "+method); for (alt : sortedAlternatives) bossa.util.Debug.println("Alternative: "+alt.toString()); } boolean[] used = findUsedPositions(method.getArity(), sortedAlternatives); let type = method.getType(); if (type == null) throw Internal.error(method + " is not in a proper state."); List<mlsub.typing.TypeConstructor[]> multitags = enumerateTags(type, used); boolean[] isValue = new boolean[method.getArity()]; List<?ConstantExp[]> values = generateValues(sortedAlternatives, isValue); boolean hasValues = values.size() > 0; List<String> errors = new ArrayList(3); int nb_errors = 0; for (tags : multitags) { // For java methods, we are only concerned with cases // where the first argument is a Nice class. ?gnu.bytecode.ClassType firstArg = null; if (isJavaMethod) { firstArg = classTypeOfNiceClass(tags[0]); if (firstArg == null) continue; } if (testTypes(method, tags, sortedAlternatives, firstArg, errors)) { if (++nb_errors > 3) break; } else if (hasValues && testValues(method, tags, values, isValue, sortedAlternatives, errors)) if (++nb_errors > 0) break; } if (nb_errors > 0) User.error(method, "The implementation test failed for method " + method.toString() + ":\n" + Util.map("", "\n", "", errors)); } private ?gnu.bytecode.ClassType classTypeOfNiceClass(mlsub.typing.TypeConstructor tc) { let def = getTypeDefinition(tc); if (def == null || ! (def.getImplementation() instanceof NiceClass)) return null; let NiceClass nc = cast(def.getImplementation()); return nc.getClassExp().getClassType(); } /** Tests that the 'tags' tuple has a best-match in alternatives @param method the method being tested @param tags a tuple of TypeConstructors @param alternatives a list of Alternatives @return true if the test failed */ private boolean testTypes(MethodDeclaration method, mlsub.typing.TypeConstructor[] tags, Stack<Alternative> sortedAlternatives, ?gnu.bytecode.ClassType firstArg, List<String> errors) { boolean failed = false; if (bossa.util.Debug.linkTests) bossa.util.Debug.println(Util.map("Multitag: ",", ","",tags)); // Tests that a match exists, and that the first match is a "best-match" ?Alternative first = null; for (a : sortedAlternatives) { if (a.matches(tags)) if (first == null) first = a; else if (!Alternative.less(first, a) && !a.containsTypeMatchingValue()) { failed = true; errors.add("ambiguity for parameters of type " + tagsToString(tags)+ "\nboth\n" + first.printLocated() + "\nand\n" + a.printLocated() + "\nmatch."); break; } } if (first == null) { if (firstArg != null) { let superImplementation = getImplementationAbove(method, firstArg); if (superImplementation != null && superImplementation.isAbstract() == false) // It's OK, this case is covered by a Java implementation. return false; } failed = true; if (sortedAlternatives.size()==0) User.error (method, "Method " + method + " is declared but never implemented:\n" + "no alternative matches " + tagsToString(tags)); else errors.add("no alternative matches " + tagsToString(tags)); } return failed; } /** Special version of above that tests tags with all combinations of integer values. */ private boolean testValues (MethodDeclaration method, mlsub.typing.TypeConstructor[] tags, List<?ConstantExp[]> valueCombis, boolean[] isValue, Stack<Alternative> sortedAlternatives, List<String> errors) { boolean failed = false; List<Alternative> sortedTypeMatches = new ArrayList(); for (a : sortedAlternatives) if (a.matchesTypePart(tags, isValue)) sortedTypeMatches.add(a); for (values : valueCombis) { ?Alternative first = null; outer: for (a : sortedTypeMatches) { if (a.matchesValuePart(values, isValue)) if (first == null) first = a; else if (!Alternative.less(first, a)) { failed = true; errors.add("ambiguity for parameters of type/value " + tagsToString(tags, values, isValue)+ "\nboth\n" + first.printLocated() + "\nand\n" + a.printLocated() + "\nmatch."); break outer; } } if (first==null) { failed = true; errors.add("no alternative matches "+ tagsToString(tags, values, isValue)); bossa.util.Debug.println(sortedAlternatives.toString() + "\n" + tagsToString(tags, values, isValue)); break; } } return failed; } private String tagsToString(mlsub.typing.TypeConstructor[] tags) { let res = new StringBuffer(); res.append('('); for (int i = 0, n = 0; i < tags.length; i++) { res.append(tags[n++]); if (i + 1 < tags.length) res.append(", "); } return res.append(')').toString(); } private String tagsToString(mlsub.typing.TypeConstructor[] tags, ?ConstantExp[] values, boolean[] isValue) { let res = new StringBuffer(); res.append('('); for (int i = 0, n = 0; i < tags.length; i++) { if (isValue[n]) res.append(values[n++]); else res.append(tags[n++]); if (i + 1 < tags.length) res.append(", "); } return res.append(')').toString(); } /** Enumerate all the tuples of tags in the domain of a polytype. @return a List of TypeConstructor[] an element of an array is set to: null if it cannot be matched (e.g. a function type) PrimtiveType.nullTC if it can be matched by @null **/ private List<mlsub.typing.TypeConstructor[]> enumerateTags(mlsub.typing.Polytype type, boolean[] used) { mlsub.typing.Monotype[] domains = type.domain(); ?mlsub.typing.Constraint cst = type.getConstraint(); int len = used.length; mlsub.typing.lowlevel.Element[] types = cast(new mlsub.typing.lowlevel.Element[len]); for (int i = domains.length; --i >= 0;) { mlsub.typing.Monotype arg = domains[i]; mlsub.typing.TypeConstructor marker; mlsub.typing.Monotype raw; // We deconstruct 'arg' as 'marker<raw>' // This is easy and more efficent if arg is already a constructed type if (arg instanceof mlsub.typing.MonotypeConstructor) { marker = arg.getTC(); raw = nice.tools.typing.Types.rawType(arg); } else { marker = new mlsub.typing.TypeConstructor(notNull(nice.tools.typing.PrimitiveType.maybeTC).variance); mlsub.typing.MonotypeVar mvar = new mlsub.typing.MonotypeVar("dispatchType"); raw = mvar; mlsub.typing.Monotype t = mlsub.typing.MonotypeConstructor.apply(marker, raw); cst = mlsub.typing.Constraint.and(cst, marker, mvar, new mlsub.typing.MonotypeLeqCst(t, arg), new mlsub.typing.MonotypeLeqCst(arg, t)); } types[--len] = raw; types[--len] = marker; } if (len != 0) throw new Error(); List<mlsub.typing.TypeConstructor[]> res = mlsub.typing.Enumeration.enumerate(cst, types, used); return mergeNullCases(res, domains.length); } /** Merges all null<*> into null. @param tuples a list of tuples. Each tuple has 2 * length elements, alternatively a nullness marker TC and a normal TC */ private List<mlsub.typing.TypeConstructor[]> mergeNullCases(List<mlsub.typing.TypeConstructor[]> tuples, int length) { LinkedList<mlsub.typing.TypeConstructor[]> res = new LinkedList(); Set<mlsub.typing.TypeConstructor[]> tupleSet = new TreeSet(tagComp); for (tuple : tuples) { mlsub.typing.TypeConstructor[] tags = flattenTags(tuple, length); //add only non duplicate tags if (tupleSet.add(tags)) res.add(tags); } return res; } private let Comparator<mlsub.typing.TypeConstructor[]> tagComp = new TagComparator(); private class TagComparator<-T> implements Comparator<T> { compare(o1, o2) { mlsub.typing.TypeConstructor[] tc1 = cast(o1); mlsub.typing.TypeConstructor[] tc2 = cast(o2); for(int i = 0; i<tc1.length; i++) { if (tc1[i] == null) { if (tc2[i] == null) return 0; return -1; } if (tc2[i] == null) return 1; int a = tc1[i].getId(); int b = tc2[i].getId(); if (a<b) return -1; if (a>b) return 1; } return 0; } equals(obj) { return false; } } /** Translates (nullTC, *) into nullTC and (sureTC, tc) into tc @param tags a list of tuples. Each tuple has 2 * length elements, alternatively a nullness marker TC and a normal TC */ private mlsub.typing.TypeConstructor[] flattenTags(mlsub.typing.TypeConstructor[] tags, int length) { mlsub.typing.TypeConstructor[] res = cast(new mlsub.typing.TypeConstructor[length]); for (int i = length; --i >= 0 ;) if (tags[2 * i] == nice.tools.typing.PrimitiveType.nullTC) res[i] = notNull(nice.tools.typing.PrimitiveType.nullTC); else res[i] = tags[2 * i + 1]; return res; } /** Generate all combinations of values from the alternatives * @return List<ConstantExp> */ private List<?ConstantExp[]> generateValues(List<Alternative> alternatives, boolean[] isValue) { List<?ConstantExp[]> values = new ArrayList(); if (alternatives.size() < 1) return values; int len = isValue.length; for (int pos = 0; pos < len; pos++) { List<ConstantExp> valuesAtPos = new ArrayList(); for (a : alternatives) { Pattern pat = a.getPatterns()[pos]; if (pat.atValue()) { isValue[pos] = true; pat.addValues(valuesAtPos); } } //remove duplicates /* for (int i = 0; i < valuesAtPos.size(); i++) for (int j = i+1; j < valuesAtPos.size(); j++) if (valuesAtPos.get(i).equals(valuesAtPos.get(j))) valuesAtPos.remove(j--); */ int valueCount = valuesAtPos.size(); if (valueCount > 0) { List<?ConstantExp[]> res = new ArrayList(); if (values.size() == 0) for (int i = 0; i < valueCount; i++) { ?ConstantExp[] arr2 = new ConstantExp[len]; arr2[pos] = valuesAtPos[i]; res.add(arr2); } else for (arr : values) for (int i = 0; i < valueCount; i++) { ?ConstantExp[] arr2 = new ConstantExp[len]; System.arraycopy(arr,0,arr2,0,len); arr2[pos] = valuesAtPos[i]; res.add(arr2); } values = res; } } return values; } |
From: Arjan B. <ar...@us...> - 2004-12-29 16:31:16
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10834/F:/nice/src/bossa/modules Modified Files: Package.java Log Message: Converted DispatchTest. Index: Package.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Package.java,v retrieving revision 1.130 retrieving revision 1.131 diff -C2 -d -r1.130 -r1.131 *** Package.java 21 Dec 2004 01:31:13 -0000 1.130 --- Package.java 29 Dec 2004 16:31:01 -0000 1.131 *************** *** 289,293 **** nice.tools.code.SpecialTypes.init(); bossa.link.Alternative.reset(); ! bossa.link.DispatchTest.reset(); bossa.syntax.dispatch.resetTypeDefinitionMappings(); bossa.syntax.dispatch.resetConstructorsMap(); --- 289,293 ---- nice.tools.code.SpecialTypes.init(); bossa.link.Alternative.reset(); ! bossa.syntax.dispatch.resetDispatchTest(); bossa.syntax.dispatch.resetTypeDefinitionMappings(); bossa.syntax.dispatch.resetConstructorsMap(); *************** *** 340,344 **** { compilation.progress(this, "linking"); ! bossa.link.DispatchTest.test(this); finishCompilation(); --- 340,344 ---- { compilation.progress(this, "linking"); ! bossa.syntax.dispatch.testCoverage(this); finishCompilation(); |
From: Arjan B. <ar...@us...> - 2004-12-29 16:31:15
|
Update of /cvsroot/nice/Nice/src/bossa/link In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10834/F:/nice/src/bossa/link Modified Files: Alternative.java Compilation.java Removed Files: DispatchTest.java Log Message: Converted DispatchTest. Index: Alternative.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Alternative.java,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** Alternative.java 21 Dec 2004 01:31:13 -0000 1.60 --- Alternative.java 29 Dec 2004 16:31:01 -0000 1.61 *************** *** 83,87 **** } ! static boolean disjoint(Alternative a, Alternative b) { for(int i = 0; i<a.patterns.length; i++) --- 83,87 ---- } ! public static boolean disjoint(Alternative a, Alternative b) { for(int i = 0; i<a.patterns.length; i++) *************** *** 92,96 **** } ! static Alternative greatestLowerBound(Alternative a, Alternative b) { Pattern[] pats = new Pattern[a.patterns.length]; --- 92,96 ---- } ! public static Alternative greatestLowerBound(Alternative a, Alternative b) { Pattern[] pats = new Pattern[a.patterns.length]; *************** *** 111,115 **** * Tests the matching of tags against a method alternative. */ ! boolean matches(TypeConstructor[] tags) { for(int i = 0; i < patterns.length; i++) --- 111,115 ---- * Tests the matching of tags against a method alternative. */ ! public boolean matches(TypeConstructor[] tags) { for(int i = 0; i < patterns.length; i++) *************** *** 120,124 **** } ! boolean matchesTypePart(TypeConstructor[] tags, boolean[] isValue) { for(int i = 0; i < patterns.length; i++) --- 120,124 ---- } ! public boolean matchesTypePart(TypeConstructor[] tags, boolean[] isValue) { for(int i = 0; i < patterns.length; i++) *************** *** 129,133 **** } ! boolean matchesValuePart(ConstantExp[] values, boolean[] isValue) { for(int i = 0; i < patterns.length; i++) --- 129,133 ---- } ! public boolean matchesValuePart(ConstantExp[] values, boolean[] isValue) { for(int i = 0; i < patterns.length; i++) *************** *** 138,142 **** } ! boolean containsTypeMatchingValue() { for(int i = 0; i < patterns.length; i++) --- 138,142 ---- } ! public boolean containsTypeMatchingValue() { for(int i = 0; i < patterns.length; i++) *************** *** 147,151 **** } ! boolean allAtAny() { for (int i = 0; i<patterns.length; i++) --- 147,151 ---- } ! public boolean allAtAny() { for (int i = 0; i<patterns.length; i++) *************** *** 195,199 **** } ! String printLocated() { return toString(); --- 195,199 ---- } ! public String printLocated() { return toString(); *************** *** 201,205 **** String methodName; ! Pattern[] patterns; public Pattern[] getPatterns() { return patterns; } --- 201,205 ---- String methodName; ! public Pattern[] patterns; public Pattern[] getPatterns() { return patterns; } --- DispatchTest.java DELETED --- Index: Compilation.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Compilation.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Compilation.java 19 Dec 2004 22:37:17 -0000 1.20 --- Compilation.java 29 Dec 2004 16:31:02 -0000 1.21 *************** *** 35,39 **** public final class Compilation { ! static void compile(UserOperator/*NiceMethod*/ m, Stack sortedAlternatives, bossa.modules.Package module) --- 35,39 ---- public final class Compilation { ! public static void compile(UserOperator/*NiceMethod*/ m, Stack sortedAlternatives, bossa.modules.Package module) *************** *** 132,136 **** ****************************************************************/ ! static void compile(MethodDeclaration /* JavaMethod */ m, Stack sortedAlternatives, bossa.modules.Package module) --- 132,136 ---- ****************************************************************/ ! public static void compile(MethodDeclaration /* JavaMethod */ m, Stack sortedAlternatives, bossa.modules.Package module) |
From: Arjan B. <ar...@us...> - 2004-12-28 17:00:55
|
Update of /cvsroot/nice/Nice/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21559/Nice/web Modified Files: language.html Log Message: Make examples in the tutorial compile again. Index: language.html =================================================================== RCS file: /cvsroot/nice/Nice/web/language.html,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** language.html 10 Sep 2004 13:10:26 -0000 1.23 --- language.html 28 Dec 2004 17:00:44 -0000 1.24 *************** *** 186,190 **** <br> <PRE> ! <<FONT COLOR="#b7860b">Any T</FONT>> <FONT COLOR="#b7860b">boolean</FONT> <FONT COLOR="#cd0000">equals</FONT>(<FONT COLOR="#b7860b">T</FONT>, <FONT COLOR="#b7860b">T</FONT>); </PRE> <p> --- 186,190 ---- <br> <PRE> ! <<FONT COLOR="#b7860b">T</FONT>> <FONT COLOR="#b7860b">boolean</FONT> <FONT COLOR="#cd0000">equals</FONT>(<FONT COLOR="#b7860b">T</FONT>, <FONT COLOR="#b7860b">T</FONT>); </PRE> <p> *************** *** 204,208 **** and unconstrained types. So it would be possible to define <tt>equals</tt> to have the same typing behaviour it has in Java: ! <br><PRE><<FONT COLOR="#b7860b">Any T</FONT>, <FONT COLOR="#b7860b">Any U</FONT>> <FONT COLOR="#b7860b">boolean</FONT> <FONT COLOR="#cd0000">equals</FONT>(<FONT COLOR="#b7860b">T</FONT>, <FONT COLOR="#b7860b">U</FONT>);</PRE> <h2>Precise types</h2> --- 204,208 ---- and unconstrained types. So it would be possible to define <tt>equals</tt> to have the same typing behaviour it has in Java: ! <br><PRE><<FONT COLOR="#b7860b">T</FONT>, <FONT COLOR="#b7860b">U</FONT>> <FONT COLOR="#b7860b">boolean</FONT> <FONT COLOR="#cd0000">equals</FONT>(<FONT COLOR="#b7860b">T</FONT>, <FONT COLOR="#b7860b">U</FONT>);</PRE> <h2>Precise types</h2> *************** *** 324,328 **** <td> <blockquote> ! <pre><<font color="#B7860B">Any</font> T> T <font color="#CD0000">clone</font>(T); <font color="#CD0000">void main</font>(String[] args) --- 324,328 ---- <td> <blockquote> ! <pre><T> T <font color="#CD0000">clone</font>(T); <font color="#CD0000">void main</font>(String[] args) |
From: Arjan B. <ar...@us...> - 2004-12-28 16:48:58
|
Update of /cvsroot/nice/Nice/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19183/Nice/web Modified Files: manual.xml Log Message: Make examples in the manual compile again. Index: manual.xml =================================================================== RCS file: /cvsroot/nice/Nice/web/manual.xml,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** manual.xml 17 Sep 2004 13:50:15 -0000 1.43 --- manual.xml 28 Dec 2004 16:48:49 -0000 1.44 *************** *** 830,834 **** } ! greet(BOB p) { println("Hi Bob!"); --- 830,834 ---- } ! greet(BOB) { println("Hi Bob!"); *************** *** 2017,2021 **** <para> <literal> ! <![CDATA[<Collection C, Any T> C<T> filter(C<T>, T->boolean);]]> </literal> </para> --- 2017,2021 ---- <para> <literal> ! <![CDATA[<Collection C, T> C<T> filter(C<T>, T->boolean);]]> </literal> </para> *************** *** 2028,2032 **** <para> <literal> ! <![CDATA[<Any T, Any U | U <: T> U[] fill(T[] array, int->U value)]]> </literal> </para> --- 2028,2032 ---- <para> <literal> ! <![CDATA[<T, U | U <: T> U[] fill(T[] array, int->U value)]]> </literal> </para> |
From: Arjan B. <ar...@us...> - 2004-12-28 16:05:43
|
Update of /cvsroot/nice/Nice/testsuite/compiler/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7984/F:/nice/testsuite/compiler/classes Modified Files: specialization.testsuite Log Message: Removed bugmarker of fixed bug. Index: specialization.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/classes/specialization.testsuite,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** specialization.testsuite 26 Dec 2004 06:21:17 -0000 1.7 --- specialization.testsuite 28 Dec 2004 16:05:26 -0000 1.8 *************** *** 73,77 **** } ! /// PASS bug // bug #1090888 /// Toplevel --- 73,77 ---- } ! /// PASS // bug #1090888 /// Toplevel |
From: Daniel B. <bo...@us...> - 2004-12-26 06:21:26
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20732/src/bossa/syntax Modified Files: niceclass.nice Log Message: Correctly handle native parent constructors retyped with type parameters (fixes bug #1090888). Index: niceclass.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceclass.nice,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** niceclass.nice 20 Dec 2004 16:05:18 -0000 1.9 --- niceclass.nice 26 Dec 2004 06:21:17 -0000 1.10 *************** *** 550,555 **** FormalParameters values = new FormalParameters(params.toArray()); notNull(constructorMethod)[i] = new DefaultConstructor ! (new LocatedString("<init>",definition.location()), values, cst, Monotype.resolve(definition.getLocalScope(), values.types()), Monotype.sure(new mlsub.typing.MonotypeConstructor(definition.getTC(), definition.getTypeParameters())), --- 550,565 ---- FormalParameters values = new FormalParameters(params.toArray()); + mlsub.typing.Constraint specificCst = cst; + // If the parent is a native method, it might have been retyped + // with a complex constraint. In that case we need to combine + // the two constraints. + // There might be simpler code to do this, and we could avoid + // duplicating the type variables. + if (parent instanceof JavaMethod && ! parent.getType().isMonomorphic()) + specificCst = identifyTypeParameters(cst, parent, typeParameters); + notNull(constructorMethod)[i] = new DefaultConstructor ! (new LocatedString("<init>",definition.location()), values, ! specificCst, Monotype.resolve(definition.getLocalScope(), values.types()), Monotype.sure(new mlsub.typing.MonotypeConstructor(definition.getTC(), definition.getTypeParameters())), *************** *** 677,680 **** --- 687,722 ---- } + /** + Return a constraint that includes cst, the method's type constraint, + further constraining type parameters to be the same as the type parameters + of the return type of the method. + */ + mlsub.typing.Constraint identifyTypeParameters + (mlsub.typing.Constraint cst, + MethodDeclaration method, + mlsub.typing.Monotype[] typeParameters) + { + mlsub.typing.MonotypeConstructor result = + cast(nice.tools.typing.Types.rawType(method.getType().codomain())); + let methodTP = result.getTP(); + + let cst2 = method.getType().getConstraint(); + mlsub.typing.Constraint and = mlsub.typing.Constraint.and(cst, cst2); + + let atoms = and.atoms(); + let n = atoms == null ? 0 : atoms.length; + let allAtoms = new mlsub.typing.AtomicConstraint[n + typeParameters.length * 2]; + if (n > 0) + System.arraycopy(atoms, 0, allAtoms, 2 * typeParameters.length, n); + + for(int i = 0; i < typeParameters.length; i++) + { + allAtoms[2*i] = new mlsub.typing.MonotypeLeqCst(typeParameters[i], methodTP[i]); + allAtoms[2*i+1] = new mlsub.typing.MonotypeLeqCst(methodTP[i], typeParameters[i]); + } + + return new mlsub.typing.Constraint(and.binders(), cast(allAtoms)); + } + let gnu.bytecode.Method cloneMethod = notNull(gnu.bytecode.Type.pointer_type).getDeclaredMethod("clone", 0); |
From: Daniel B. <bo...@us...> - 2004-12-26 06:21:26
|
Update of /cvsroot/nice/Nice/testsuite/compiler/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20732/testsuite/compiler/classes Modified Files: specialization.testsuite Log Message: Correctly handle native parent constructors retyped with type parameters (fixes bug #1090888). Index: specialization.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/classes/specialization.testsuite,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** specialization.testsuite 17 Dec 2004 20:45:06 -0000 1.6 --- specialization.testsuite 26 Dec 2004 06:21:17 -0000 1.7 *************** *** 72,73 **** --- 72,82 ---- void foo() {} } + + /// PASS bug + // bug #1090888 + /// Toplevel + class Env extends HashMap<String, String> {} + + void _test_makeEnv() { + Env env = new Env(new HashMap()); + } |
From: Daniel B. <bo...@us...> - 2004-12-26 06:21:25
|
Update of /cvsroot/nice/Nice/testsuite/compiler/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20732/testsuite/compiler/native Modified Files: constructors.testsuite Log Message: Correctly handle native parent constructors retyped with type parameters (fixes bug #1090888). Index: constructors.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/native/constructors.testsuite,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** constructors.testsuite 15 Jan 2004 21:39:19 -0000 1.3 --- constructors.testsuite 26 Dec 2004 06:21:16 -0000 1.4 *************** *** 56,57 **** --- 56,64 ---- class A extends Thread { ?Runnable dummy = null; } + + /// PASS + // bug #1090888 + HashMap<String,String> m = new HashMap(); + MyMap<String,String> env = new MyMap(m); + /// Toplevel + class MyMap<A,B> extends HashMap<A,B> {} |
From: Daniel B. <bo...@us...> - 2004-12-25 23:26:30
|
Update of /cvsroot/nice/Nice/testsuite/compiler/classes/constructors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22430/testsuite/compiler/classes/constructors Modified Files: custom.testsuite Log Message: Ignore anonymous symbols instead of failing (occured at least with custom constructors). Index: custom.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/classes/constructors/custom.testsuite,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** custom.testsuite 25 Nov 2004 12:35:48 -0000 1.15 --- custom.testsuite 25 Dec 2004 23:26:19 -0000 1.16 *************** *** 145,146 **** --- 145,151 ---- } new X() = this(str: "abc"); + + /// PASS + /// Toplevel + class A {} + new A(int) { this(); } |