[Swift-commit] cog r3789
swift at ci.uchicago.edu
swift at ci.uchicago.edu
Thu Sep 19 01:45:03 CDT 2013
------------------------------------------------------------------------
r3789 | hategan | 2013-09-19 01:42:15 -0500 (Thu, 19 Sep 2013) | 1 line
fixed weird errors when some parameter values are missing in function invocations
------------------------------------------------------------------------
Index: modules/karajan/src/org/globus/cog/karajan/analyzer/ChannelRef.java
===================================================================
--- modules/karajan/src/org/globus/cog/karajan/analyzer/ChannelRef.java (revision 3788)
+++ modules/karajan/src/org/globus/cog/karajan/analyzer/ChannelRef.java (working copy)
@@ -47,6 +47,12 @@
get(stack).add(value);
}
+ public void check(Stack stack) {
+ // implementations that require restrictions
+ // on the structure of the channel (like the number of items)
+ // should override this
+ }
+
public StaticChannel getValue() {
throw new UnsupportedOperationException();
}
@@ -419,6 +425,15 @@
}
}
+ @Override
+ public void check(Stack stack) {
+ @SuppressWarnings("unchecked")
+ VarArgChannel<T> c = (VarArgChannel<T>) stack.top().get(index);
+ if (c.argSize() < names.size()) {
+ throw new IllegalArgumentException("Missing argument '" + names.get(c.argSize()) + "'");
+ }
+ }
+
public void setNamesP(List<Param> l) {
names = new ArrayList<String>();
for (Param p : l) {
@@ -480,6 +495,15 @@
c.setNames(names);
}
}
+
+ @Override
+ public void check(Stack stack) {
+ @SuppressWarnings("unchecked")
+ FixedArgChannel<T> c = (FixedArgChannel<T>) stack.top().get(index);
+ if (c.size() < names.size()) {
+ throw new IllegalArgumentException("Missing argument '" + names.get(c.size()) + "'");
+ }
+ }
}
public static class InvalidArg extends Dynamic<Object> {
Index: modules/karajan/src/org/globus/cog/karajan/compiled/nodes/SetVarK.java
===================================================================
--- modules/karajan/src/org/globus/cog/karajan/compiled/nodes/SetVarK.java (revision 3788)
+++ modules/karajan/src/org/globus/cog/karajan/compiled/nodes/SetVarK.java (working copy)
@@ -21,7 +21,6 @@
import org.globus.cog.karajan.analyzer.ChannelRef;
import org.globus.cog.karajan.analyzer.CompilationException;
-import org.globus.cog.karajan.analyzer.CompilerSettings;
import org.globus.cog.karajan.analyzer.NamedValue;
import org.globus.cog.karajan.analyzer.Pure;
import org.globus.cog.karajan.analyzer.RecursiveFunctionChannel;
@@ -36,7 +35,7 @@
private ChannelRef.ArgMapping<Object> values;
@Override
- public void run(LWThread thr) throws ExecutionException {
+ public void run(LWThread thr) {
int i = thr.checkSliceAndPopState();
Stack stack = thr.getStack();
try {
@@ -51,8 +50,12 @@
for (; i <= nc; i++) {
runChild(i - 1, thr);
}
+ values.check(stack);
}
}
+ catch (Exception e) {
+ throw new ExecutionException(this, e);
+ }
catch (Yield y) {
y.getState().push(i);
throw y;
@@ -106,9 +109,7 @@
}
values = new ChannelRef.ArgMappingFixed<Object>(startIndex, vars.size(), svalues.getIndex());
- if (CompilerSettings.DEBUG) {
- values.setNamesS(vars);
- }
+ values.setNamesS(vars);
addChild(cn);
return this;
}
Index: modules/karajan/src/org/globus/cog/karajan/compiled/nodes/InternalFunction.java
===================================================================
--- modules/karajan/src/org/globus/cog/karajan/compiled/nodes/InternalFunction.java (revision 3788)
+++ modules/karajan/src/org/globus/cog/karajan/compiled/nodes/InternalFunction.java (working copy)
@@ -49,7 +49,7 @@
protected ChannelRef<Object> _vargs;
protected abstract Signature getSignature();
- private int firstOptionalIndex, lastOptionalIndex;
+ private int firstOptionalIndex = -1, lastOptionalIndex;
protected Param[] params(Object... p) {
Param[] a = new Param[p.length];
@@ -146,8 +146,9 @@
for (; i <= ec; i++) {
runChild(i - 1, thr);
}
+ checkArgs(stack);
}
- catch (IllegalExtraArgumentException e) {
+ catch (IllegalArgumentException e) {
throw new ExecutionException(this, e.getMessage());
}
try {
@@ -179,6 +180,12 @@
initializeOptional(stack);
}
+ protected void checkArgs(final Stack stack) {
+ if (_vargs != null) {
+ _vargs.check(stack);
+ }
+ }
+
protected void initializeOptional(Stack stack) {
if (firstOptionalIndex != -1) {
Arrays.fill(stack.top().getAll(), firstOptionalIndex, lastOptionalIndex, null);
@@ -335,22 +342,18 @@
}
else {
_vargs = makeArgMappingChannel(firstDynamicIndex, dynamicCount, ai.vargs.getIndex());
- if (CompilerSettings.DEBUG) {
- int i1 = ai.positional.size() - dynamicCount;
- int i2 = ai.positional.size();
- ((ChannelRef.ArgMapping<Object>) _vargs).setNamesP(ai.positional.subList(i1, i2));
- }
+ int i1 = ai.positional.size() - dynamicCount;
+ int i2 = ai.positional.size();
+ ((ChannelRef.ArgMapping<Object>) _vargs).setNamesP(ai.positional.subList(i1, i2));
}
setChannelArg(w, Param.VARGS, _vargs);
}
else {
if (!allPosStatic) {
_vargs = makeArgMappingFixedChannel(firstDynamicIndex, dynamicCount, ai.vargs.getIndex());
- if (CompilerSettings.DEBUG) {
- int i1 = ai.positional.size() - dynamicCount;
- int i2 = ai.positional.size();
- ((ChannelRef.ArgMapping<Object>) _vargs).setNamesP(ai.positional.subList(i1, i2));
- }
+ int i1 = ai.positional.size() - dynamicCount;
+ int i2 = ai.positional.size();
+ ((ChannelRef.ArgMapping<Object>) _vargs).setNamesP(ai.positional.subList(i1, i2));
}
else if (ai.vargs != null) {
_vargs = makeInvalidArgChannel(ai.vargs.getIndex());
Index: modules/karajan/src/org/globus/cog/karajan/compiled/nodes/functions/Misc.java
===================================================================
--- modules/karajan/src/org/globus/cog/karajan/compiled/nodes/functions/Misc.java (revision 3788)
+++ modules/karajan/src/org/globus/cog/karajan/compiled/nodes/functions/Misc.java (working copy)
@@ -347,8 +347,6 @@
return params("name");
}
-
-
@Override
protected Node compileBody(WrapperNode w, Scope argScope, Scope scope)
throws CompilationException {
Index: modules/karajan/src/k/rt/VarArgChannel.java
===================================================================
--- modules/karajan/src/k/rt/VarArgChannel.java (revision 3788)
+++ modules/karajan/src/k/rt/VarArgChannel.java (working copy)
@@ -125,6 +125,10 @@
return vargs.size();
}
}
+
+ public int argSize() {
+ return index - startIndex;
+ }
@Override
public T get(int index) {
Index: modules/karajan/src/k/rt/FixedArgChannel.java
===================================================================
--- modules/karajan/src/k/rt/FixedArgChannel.java (revision 3788)
+++ modules/karajan/src/k/rt/FixedArgChannel.java (working copy)
@@ -29,8 +29,21 @@
public void setNames(List<String> names) {
this.names = names;
}
+
+ public boolean isEmpty() {
+ return index > getStartIndex();
+ }
+ private int getStartIndex() {
+ return bounds >> 16;
+ }
+
@Override
+ public int size() {
+ return index - getStartIndex();
+ }
+
+ @Override
public synchronized boolean add(T value) {
if (index > (bounds & 0x0000ffff)) {
throw new IllegalExtraArgumentException(value);
More information about the Swift-commit
mailing list