tighten up function args for non-linear calls
This commit is contained in:
1 parent
d35769a365
commit
56f8f17aaa
3 files changed
+13
-9
No files matched your search
@@ -2967,7 +2967,7 @@ public class CarpetExpression
|
||||
throw new InternalExpressionException("'schedule' should have at least 2 arguments, delay and call name");
|
||||
long delay = NumericValue.asNumber(lv.get(0).evalValue(c)).getLong();
|
||||
|
||||
FunctionArgument functionArgument = FunctionArgument.findIn(c, this.expr.module, lv, 1, true);
|
||||
FunctionArgument functionArgument = FunctionArgument.findIn(c, this.expr.module, lv, 1, true, true);
|
||||
|
||||
CarpetServer.scriptServer.events.scheduleCall(
|
||||
(CarpetContext) c,
|
||||
|
||||
@@ -440,7 +440,7 @@ public class Expression
|
||||
//lv.remove(lv.size()-1); // aint gonna cut it // maybe it will because of the eager eval changes
|
||||
if (t != Context.SIGNATURE) // just call the function
|
||||
{
|
||||
FunctionArgument functionArgument = FunctionArgument.findIn(c, module, lv, 0, true);
|
||||
FunctionArgument functionArgument = FunctionArgument.findIn(c, module, lv, 0, false, true);
|
||||
FunctionValue fun = functionArgument.function;
|
||||
Value retval = fun.callInContext(expr, c, t, fun.getExpression(), fun.getToken(), functionArgument.args).evalValue(c);
|
||||
return (cc, tt) -> retval; ///!!!! dono might need to store expr and token in statics? (e? t?)
|
||||
@@ -1878,7 +1878,7 @@ public class Expression
|
||||
addLazyFunctionWithDelegation("task", -1, (c, t, expr, tok, lv) -> {
|
||||
if (lv.size() == 0)
|
||||
throw new InternalExpressionException("'task' requires at least function to call as a parameter");
|
||||
FunctionArgument functionArgument = FunctionArgument.findIn(c, module, lv, 0);
|
||||
FunctionArgument functionArgument = FunctionArgument.findIn(c, module, lv, 0, true, false);
|
||||
Value queue = Value.NULL;
|
||||
if (lv.size() > functionArgument.offset) queue = lv.get(functionArgument.offset).evalValue(c);
|
||||
ThreadValue thread = new ThreadValue(queue, functionArgument.function, expr, tok, c, functionArgument.args);
|
||||
|
||||
@@ -22,11 +22,7 @@ public class FunctionArgument extends Argument
|
||||
this.function = function;
|
||||
this.args = args;
|
||||
}
|
||||
public static FunctionArgument findIn(Context c, Module module, List<LazyValue> params, int offset)
|
||||
{
|
||||
return findIn(c, module, params, offset, false);
|
||||
}
|
||||
public static FunctionArgument findIn(Context c, Module module, List<LazyValue> params, int offset, boolean strict)
|
||||
public static FunctionArgument findIn(Context c, Module module, List<LazyValue> params, int offset, boolean prematureEvaluation, boolean strict)
|
||||
{
|
||||
Value functionValue = params.get(offset).evalValue(c);
|
||||
if (!(functionValue instanceof FunctionValue))
|
||||
@@ -40,9 +36,17 @@ public class FunctionArgument extends Argument
|
||||
if (extraargs < 0 || (extraargs > 0 && strict))
|
||||
throw new InternalExpressionException("Function "+fun.getPrettyString()+" requires "+fun.getArguments().size()+" arguments");
|
||||
List<LazyValue> lvargs = new ArrayList<>();
|
||||
if (prematureEvaluation)
|
||||
{
|
||||
for (int i = 0; i < argsize; i++)
|
||||
{
|
||||
lvargs.add(params.get(offset+1+i));
|
||||
Value arg = params.get(offset + 1 + i).evalValue(c);
|
||||
lvargs.add((cc, tt) -> arg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < argsize; i++) lvargs.add(params.get(offset + 1 + i));
|
||||
}
|
||||
return new FunctionArgument(fun, offset+1+argsize, lvargs);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user