[Swift-commit] r7959 - trunk/src/org/griphyn/vdl/karajan/lib

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Fri Jul 4 01:44:18 CDT 2014


Author: hategan
Date: 2014-07-04 01:44:17 -0500 (Fri, 04 Jul 2014)
New Revision: 7959

Modified:
   trunk/src/org/griphyn/vdl/karajan/lib/GetFieldConst.java
   trunk/src/org/griphyn/vdl/karajan/lib/New.java
Log:
some more compile-time optimizations

Modified: trunk/src/org/griphyn/vdl/karajan/lib/GetFieldConst.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/GetFieldConst.java	2014-07-04 06:42:52 UTC (rev 7958)
+++ trunk/src/org/griphyn/vdl/karajan/lib/GetFieldConst.java	2014-07-04 06:44:17 UTC (rev 7959)
@@ -24,23 +24,39 @@
 import k.rt.Stack;
 
 import org.globus.cog.karajan.analyzer.ArgRef;
-import org.globus.cog.karajan.analyzer.Param;
-import org.globus.cog.karajan.compiled.nodes.functions.AbstractSingleValuedFunction;
+import org.globus.cog.karajan.analyzer.CompilationException;
+import org.globus.cog.karajan.analyzer.Scope;
+import org.globus.cog.karajan.analyzer.Signature;
+import org.globus.cog.karajan.compiled.nodes.Node;
+import org.globus.cog.karajan.compiled.nodes.functions.AbstractFunction;
+import org.globus.cog.karajan.parser.WrapperNode;
 import org.griphyn.vdl.type.Field;
 import org.griphyn.vdl.type.NoSuchTypeException;
 import org.griphyn.vdl.type.Types;
 
-public class GetFieldConst extends AbstractSingleValuedFunction {
+public class GetFieldConst extends AbstractFunction {
     private ArgRef<String> name;
     private ArgRef<String> type;
 
+    @Override
+    protected Signature getSignature() {
+        return new Signature(params("name", "type"));
+    }
     
     @Override
-    protected Param[] getParams() {
-        return params("name", "type");
+    protected Node compileBody(WrapperNode w, Scope argScope, Scope scope) throws CompilationException {
+        String name = this.name.getValue();
+        String type = this.type.getValue();
+        try {
+            staticReturn(scope, Field.Factory.getImmutableField(name, Types.getType(type)));
+        }
+        catch (NoSuchTypeException e) {
+            throw new ExecutionException("No such type: " + name, e);
+        }
+        
+        return null;
     }
 
-
     @Override
 	public Object function(Stack stack) {
         String name = this.name.getValue(stack);

Modified: trunk/src/org/griphyn/vdl/karajan/lib/New.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/New.java	2014-07-04 06:42:52 UTC (rev 7958)
+++ trunk/src/org/griphyn/vdl/karajan/lib/New.java	2014-07-04 06:44:17 UTC (rev 7959)
@@ -22,7 +22,6 @@
 
 import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 
 import k.rt.Context;
 import k.rt.ExecutionException;
@@ -39,6 +38,7 @@
 import org.globus.cog.karajan.parser.WrapperNode;
 import org.griphyn.vdl.mapping.DSHandle;
 import org.griphyn.vdl.mapping.DuplicateMappingChecker;
+import org.griphyn.vdl.mapping.GenericMappingParamSet;
 import org.griphyn.vdl.mapping.InvalidMapperException;
 import org.griphyn.vdl.mapping.Mapper;
 import org.griphyn.vdl.mapping.MapperFactory;
@@ -50,9 +50,6 @@
 import org.griphyn.vdl.mapping.nodes.RootClosedArrayDataNode;
 import org.griphyn.vdl.mapping.nodes.RootClosedPrimitiveDataNode;
 import org.griphyn.vdl.mapping.nodes.RootFutureArrayDataNode;
-import org.griphyn.vdl.mapping.nodes.RootFutureMappedSingleDataNode;
-import org.griphyn.vdl.mapping.nodes.RootFuturePrimitiveDataNode;
-import org.griphyn.vdl.mapping.nodes.RootFutureStructDataNode;
 import org.griphyn.vdl.type.Field;
 import org.griphyn.vdl.type.NoSuchTypeException;
 import org.griphyn.vdl.type.Type;
@@ -63,15 +60,17 @@
 	
 	private static final Mapper NULL_MAPPER = new NullMapper();
 	
+	private static DuplicateMappingChecker staticDMC = new DuplicateMappingChecker(null);
+	
 	private ArgRef<Field> field;
-	private ArgRef<Map<String, Object>> mapping;
+	private ArgRef<GenericMappingParamSet> mapping;
 	private ArgRef<Object> value;
 	private ArgRef<Number> waitCount;
 	private ArgRef<Boolean> input;
 	private ArgRef<Integer> _defline;
 	
 	private VarRef<Context> context;
-	private VarRef<String> cwd;
+	private VarRef<String> cwd; 
 	
 	@Override
 	protected Signature getSignature() {
@@ -103,7 +102,7 @@
     public Object function(Stack stack) {
 		Field field = this.field.getValue(stack);
 		Object value = this.value.getValue(stack);
-        Map<String, Object> mapping = this.mapping.getValue(stack);
+        GenericMappingParamSet mapping = this.mapping.getValue(stack);
 		Number waitCount = this.waitCount.getValue(stack);
 		boolean input = this.input.getValue(stack);
 		Integer line = this._defline.getValue(stack);
@@ -117,14 +116,12 @@
 		String dbgname = (String) field.getId();
 		
 		if (type.hasMappedComponents()) {
-		    String desc = (String) mapping.remove("swift#descriptor");
 		    try {
-                mapper = MapperFactory.getMapper(desc);
+                mapper = MapperFactory.getMapper(mapping.getDescriptor());
             }
             catch (InvalidMapperException e) {
-                throw new ExecutionException(this, "Invalid mapper '" + desc + "'");
+                throw new ExecutionException(this, "Invalid mapper '" + mapping.getDescriptor() + "'");
             }
-		    mapping.remove("descriptor");
 		    mapper.setParameters(mapping);
 		    mapper.setBaseDir(cwd.getValue(stack));
 		}




More information about the Swift-commit mailing list