From: <ta...@us...> - 2010-08-13 22:09:41
|
Revision: 15536 http://x10.svn.sourceforge.net/x10/?rev=15536&view=rev Author: tardieu Date: 2010-08-13 22:09:34 +0000 (Fri, 13 Aug 2010) Log Message: ----------- work in progress toward supporting ref capture in asyncs Modified Paths: -------------- trunk/x10.compiler/src/x10cpp/visit/Emitter.java trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java Added Paths: ----------- trunk/x10.runtime/src-x10/x10/compiler/Ref.x10 Modified: trunk/x10.compiler/src/x10cpp/visit/Emitter.java =================================================================== --- trunk/x10.compiler/src/x10cpp/visit/Emitter.java 2010-08-13 21:11:23 UTC (rev 15535) +++ trunk/x10.compiler/src/x10cpp/visit/Emitter.java 2010-08-13 22:09:34 UTC (rev 15536) @@ -920,16 +920,16 @@ return; } - public void printDeclarationList(CodeWriter w, X10CPPContext_c c, ArrayList<VarInstance<?>> vars) { - printDeclarationList(w, c, vars, true, false); + public void printDeclarationList(CodeWriter w, X10CPPContext_c c, ArrayList<VarInstance<?>> vars, List<VarInstance> refs) { + printDeclarationList(w, c, vars, true, false, refs); } - void printDeclarationList(CodeWriter w, X10CPPContext_c c, ArrayList<VarInstance<?>> vars, boolean saved_this_mechanism, boolean writable) { + void printDeclarationList(CodeWriter w, X10CPPContext_c c, ArrayList<VarInstance<?>> vars, boolean saved_this_mechanism, boolean writable, List<VarInstance> refs) { for (int i = 0; i < vars.size(); i++) { VarInstance<?> var = vars.get(i); Type t = var.type(); String type = translateType(t, true); - if (writable && !var.name().toString().equals(THIS)) // this is a temporary ref + if ((writable && !var.name().toString().equals(THIS)) || refs.contains(var)) // this is a temporary ref type = type + "&"; // FIXME: Hack to get writable args in finally closures String name = var.name().toString(); if (saved_this_mechanism && name.equals(THIS)) { Modified: trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java 2010-08-13 21:11:23 UTC (rev 15535) +++ trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java 2010-08-13 22:09:34 UTC (rev 15536) @@ -212,6 +212,7 @@ import x10.types.X10Flags; import x10.types.X10MethodDef; import x10.types.X10MethodInstance; +import x10.types.X10ParsedClassType_c; import x10.types.X10TypeMixin; import x10.types.X10TypeSystem; import x10.types.X10TypeSystem_c; @@ -4067,7 +4068,16 @@ inc.newline(); inc.forceNewline(); inc.write("// captured environment"); inc.newline(); - emitter.printDeclarationList(inc, c, c.variables); + List<Type> ats = closureDef.annotationsNamed(QName.make("x10.compiler.Ref")); + List<VarInstance> refs = new ArrayList<VarInstance>(); + for (Type at : ats) { + Expr exp = ((X10ParsedClassType_c) at).propertyInitializer(0); + if (exp instanceof X10Local_c) { + refs.add(((X10Local_c) exp).varInstance()); + } + } + + emitter.printDeclarationList(inc, c, c.variables, refs); inc.forceNewline(); inc.write("x10aux::serialization_id_t "+SERIALIZE_ID_METHOD+"() {"); Added: trunk/x10.runtime/src-x10/x10/compiler/Ref.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/compiler/Ref.x10 (rev 0) +++ trunk/x10.runtime/src-x10/x10/compiler/Ref.x10 2010-08-13 22:09:34 UTC (rev 15536) @@ -0,0 +1,20 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +package x10.compiler; + +import x10.lang.annotations.StatementAnnotation; + +/** + * @Ref(v) may be used to annotate an async to specify that variable v should be captured by reference. */ +public interface Ref[T](id:T) + extends StatementAnnotation { +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |