[Nice-commit] Nice/src/bossa/syntax Node.java,1.64,1.65 funexp.nice,1.3,1.4 methodImplementation.nic
Brought to you by:
bonniot
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); } |