[Swift-commit] r2520 - in trunk: resources src/org/griphyn/vdl/engine tests/language-behaviour

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Mon Feb 9 08:58:48 CST 2009


Author: benc
Date: 2009-02-09 08:58:47 -0600 (Mon, 09 Feb 2009)
New Revision: 2520

Added:
   trunk/tests/language-behaviour/089-nested-proc-call.swift
Modified:
   trunk/resources/Karajan.stg
   trunk/resources/swiftscript.g
   trunk/resources/swiftscript.xsd
   trunk/src/org/griphyn/vdl/engine/Karajan.java
   trunk/src/org/griphyn/vdl/engine/VariableScope.java
Log:
permit procedure calls to be used inside expressions when they return a single value. mostly a patch from hategan with a small change by me.

Modified: trunk/resources/Karajan.stg
===================================================================
--- trunk/resources/Karajan.stg	2009-02-09 14:12:56 UTC (rev 2519)
+++ trunk/resources/Karajan.stg	2009-02-09 14:58:47 UTC (rev 2520)
@@ -294,6 +294,16 @@
    </vdl:setfieldvalue>
 >>
 
+callexpr(call, datatype, callID) ::= <<
+<sequential>
+	<set name="swift#callintermediate">
+		<vdl:new type="$datatype$" dbgname="tmp"/>
+	</set>
+	$call$
+	<variable>swift#callintermediate</variable>
+</sequential>
+>>
+
 array(elements, datatype) ::= <<
 <vdl:createarray>
   <list>

Modified: trunk/resources/swiftscript.g
===================================================================
--- trunk/resources/swiftscript.g	2009-02-09 14:12:56 UTC (rev 2519)
+++ trunk/resources/swiftscript.g	2009-02-09 14:58:47 UTC (rev 2520)
@@ -669,6 +669,30 @@
         RPAREN
     ;
 
+procedureInvocationExpr [StringTemplate code]
+{StringTemplate f=null;}
+    :
+        id:ID {code.setAttribute("func", id.getText());}
+        LPAREN (
+        	f=actualParameter {
+        		code.setAttribute("inputs", f);
+        	}
+       		(
+       			COMMA f=actualParameter {
+        			code.setAttribute("inputs", f);
+            	}
+            )*
+        )?
+        RPAREN
+    ;
+    
+procedureCallExpr returns [StringTemplate code=template("call")]
+{StringTemplate f=null;}
+    :
+        procedureInvocationExpr[code]
+    ;
+
+
 predictProcedurecallDecl : ASSIGN ID LPAREN ;
 
 procedurecallDecl [StringTemplate container, StringTemplate type, StringTemplate decl, StringTemplate var]
@@ -968,13 +992,17 @@
 
 primExpr returns [StringTemplate code=null]
 {StringTemplate id=null, exp=null;}
-    : code=identifier
+    : (predictProcedureCallExpr) => code=procedureCallExpr                     
+    | code=identifier
     | LPAREN exp=orExpr RPAREN { code=template("paren");
         code.setAttribute("exp", exp);}
     | code=constant
     | code=functionInvocation
     ;
 
+predictProcedureCallExpr
+    : ID LPAREN ;
+
 // TODO - redo identifier parsing to fit in with the XML style
 // that this patch introduces
 

Modified: trunk/resources/swiftscript.xsd
===================================================================
--- trunk/resources/swiftscript.xsd	2009-02-09 14:12:56 UTC (rev 2519)
+++ trunk/resources/swiftscript.xsd	2009-02-09 14:58:47 UTC (rev 2520)
@@ -556,6 +556,7 @@
       <xs:element name="array" type="Array" substitutionGroup="abstractExpression"/>
       <xs:element name="range" type="Range" substitutionGroup="abstractExpression"/>
       <xs:element name="function" type="Function" substitutionGroup="abstractExpression"/>
+      <xs:element name="call" type="Call" substitutionGroup="abstractExpression"/>
 
   <xs:complexType name="BinaryOperator">
     <xs:sequence>

Modified: trunk/src/org/griphyn/vdl/engine/Karajan.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/Karajan.java	2009-02-09 14:12:56 UTC (rev 2519)
+++ trunk/src/org/griphyn/vdl/engine/Karajan.java	2009-02-09 14:58:47 UTC (rev 2520)
@@ -8,8 +8,8 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
+
 import javax.xml.namespace.QName;
 
 import org.antlr.stringtemplate.StringTemplate;
@@ -24,34 +24,12 @@
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlOptions;
 import org.apache.xmlbeans.XmlString;
-import org.globus.swift.language.ActualParameter;
-import org.globus.swift.language.ApplicationBinding;
-import org.globus.swift.language.Array;
-import org.globus.swift.language.Assign;
-import org.globus.swift.language.BinaryOperator;
-import org.globus.swift.language.Binding;
-import org.globus.swift.language.Call;
-import org.globus.swift.language.Foreach;
-import org.globus.swift.language.FormalParameter;
-import org.globus.swift.language.Function;
-import org.globus.swift.language.If;
-import org.globus.swift.language.Iterate;
-import org.globus.swift.language.LabelledBinaryOperator;
-import org.globus.swift.language.Procedure;
-import org.globus.swift.language.ProgramDocument;
-import org.globus.swift.language.Range;
-import org.globus.swift.language.Switch;
-import org.globus.swift.language.TypeRow;
-import org.globus.swift.language.TypeStructure;
-import org.globus.swift.language.UnlabelledUnaryOperator;
-import org.globus.swift.language.Variable;
+import org.globus.swift.language.*;
 import org.globus.swift.language.Variable.Mapping;
 import org.globus.swift.language.Variable.Mapping.Param;
 import org.globus.swift.language.If.Else;
 import org.globus.swift.language.If.Then;
-import org.globus.swift.language.Procedure;
 import org.globus.swift.language.ProgramDocument.Program;
-import org.globus.swift.language.StructureMember;
 import org.globus.swift.language.Switch.Case;
 import org.globus.swift.language.Switch.Default;
 import org.globus.swift.language.TypesDocument.Types;
@@ -410,7 +388,7 @@
 			assign((Assign) child, scope);
 		}
 		else if (child instanceof Call) {
-			call((Call) child, scope);
+			call((Call) child, scope, false);
 		}
 		else if (child instanceof Foreach) {
 			foreachStat((Foreach)child, scope);
@@ -432,7 +410,7 @@
 		}
 	}
 
-	public void call(Call call, VariableScope scope) throws CompilationException {
+	public StringTemplate call(Call call, VariableScope scope, boolean inhibitOutput) throws CompilationException {
 		try {
 			StringTemplate callST = template("call");
 			callST.setAttribute("func", call.getProc().getLocalPart());
@@ -593,7 +571,10 @@
 				}
 			}					
 			
-			scope.appendStatement(callST);
+			if (!inhibitOutput) {
+			    scope.appendStatement(callST);
+			}
+			return callST;
 		} catch(CompilationException ce) {
 			throw new CompilationException("Compile error in procedure invocation at "+call.getSrc()+": "+ce.getMessage(),ce);
 		}
@@ -854,6 +835,7 @@
 	static final QName ARRAY_EXPR = new QName(SWIFTSCRIPT_NS, "array");
 	static final QName RANGE_EXPR = new QName(SWIFTSCRIPT_NS, "range");
 	static final QName FUNCTION_EXPR = new QName(SWIFTSCRIPT_NS, "function");
+	static final QName CALL_EXPR = new QName(SWIFTSCRIPT_NS, "call");
 
 	/** converts an XML intermediate form expression into a
 	 *  Karajan expression.
@@ -1102,6 +1084,34 @@
 			} else
 				throw new CompilationException("Function " + name + " is not defined.");
 			return st;
+		} else if (expressionQName.equals(CALL_EXPR)) {
+		    Call c = (Call) expression;
+		    c.addNewOutput(); 
+		    VariableScope subscope = new VariableScope(this, scope);
+		    VariableReferenceDocument ref = VariableReferenceDocument.Factory.newInstance();
+		    ref.setVariableReference("swift#callintermediate");
+		    c.getOutputArray(0).set(ref);
+		    String name = c.getProc().getLocalPart();
+		    ProcedureSignature funcSignature = (ProcedureSignature) proceduresMap.get(name);
+		    
+		    if (funcSignature == null) {
+                throw new CompilationException("Procedure " + name + " is not defined.");
+            }
+		    
+		    if (funcSignature.sizeOfOutputArray() != 1) {
+		        throw new CompilationException("Procedure " + name + " must have exactly one " +
+		        		"return value to be used in an expression.");
+		    }
+		    
+		    StringTemplate call = template("callexpr");
+		    
+		    String type = funcSignature.getOutputArray(0).getType();
+		    subscope.addVariable("swift#callintermediate", type);
+
+		    call.setAttribute("datatype", type);
+		    call.setAttribute("call", call(c, subscope, true));
+		    call.setAttribute("callID", new Integer(callID++));
+		    return call;
 		} else {
 			throw new CompilationException("unknown expression implemented by class "+expression.getClass()+" with node name "+expressionQName +" and with content "+expression);
 		}

Modified: trunk/src/org/griphyn/vdl/engine/VariableScope.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/VariableScope.java	2009-02-09 14:12:56 UTC (rev 2519)
+++ trunk/src/org/griphyn/vdl/engine/VariableScope.java	2009-02-09 14:58:47 UTC (rev 2520)
@@ -186,6 +186,9 @@
 	    rather then walking the template.
 	*/
 	StringTemplate getLocalDeclaration(String name) {
+	    if (bodyTemplate == null) {
+	        return null;
+	    }
 		Object decls = bodyTemplate.getAttribute("declarations");
 		if(decls == null) return null;
 

Added: trunk/tests/language-behaviour/089-nested-proc-call.swift
===================================================================
--- trunk/tests/language-behaviour/089-nested-proc-call.swift	                        (rev 0)
+++ trunk/tests/language-behaviour/089-nested-proc-call.swift	2009-02-09 14:58:47 UTC (rev 2520)
@@ -0,0 +1,21 @@
+type messagefile;
+
+(messagefile t) inner_greeting() { 
+    app {
+        echo "hello" stdout=@filename(t);
+    }
+}
+
+(string s) outer_greeting() {
+  messagefile m <"ssss">;
+  m = inner_greeting();
+  s = readData(m);
+}
+
+
+// messagefile outfile <"089-nested-proc-call.swift">;
+
+// outfile = greeting();
+
+trace(outer_greeting());
+




More information about the Swift-commit mailing list