remane
This commit is contained in:
1 parent
77fbb3af75
commit
5edbbe3fe2
1 file changed
+19
-19
@@ -150,11 +150,11 @@ public class FunctionValue extends Value implements Fluff.ILazyFunction
|
|||||||
return varArgs != null;
|
return varArgs != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LazyValue callInContext(Context c, Integer type, List<Value> args)
|
public LazyValue callInContext(Context c, Integer type, List<Value> params)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return execute(c, type, expression, token, args);
|
return execute(c, type, expression, token, params);
|
||||||
}
|
}
|
||||||
catch (ExpressionException exc)
|
catch (ExpressionException exc)
|
||||||
{
|
{
|
||||||
@@ -183,40 +183,40 @@ public class FunctionValue extends Value implements Fluff.ILazyFunction
|
|||||||
throw new InternalExpressionException("Function " + getPrettyString() + " requires " + actual + " arguments");
|
throw new InternalExpressionException("Function " + getPrettyString() + " requires " + actual + " arguments");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Value> unpackArgs(List<LazyValue> lzargs, Context c)
|
public static List<Value> unpackArgs(List<LazyValue> lazyParams, Context c)
|
||||||
{
|
{
|
||||||
// TODO we shoudn't need that if all fuctions are not lazy really
|
// TODO we shoudn't need that if all fuctions are not lazy really
|
||||||
List<Value> args = new ArrayList<>();
|
List<Value> params = new ArrayList<>();
|
||||||
for (LazyValue lv : lzargs)
|
for (LazyValue lv : lazyParams)
|
||||||
{
|
{
|
||||||
Value arg = lv.evalValue(c, Context.NONE);
|
Value param = lv.evalValue(c, Context.NONE);
|
||||||
if (arg instanceof FunctionUnpackedArgumentsValue)
|
if (param instanceof FunctionUnpackedArgumentsValue)
|
||||||
{
|
{
|
||||||
CarpetSettings.LOG.error("How did we get here?");
|
CarpetSettings.LOG.error("How did we get here?");
|
||||||
args.addAll(((ListValue) arg).getItems());
|
params.addAll(((ListValue) param).getItems());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
args.add(arg);
|
params.add(param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return args;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LazyValue lazyEval(Context c, Integer type, Expression e, Tokenizer.Token t, List<LazyValue> lazyParams) {
|
public LazyValue lazyEval(Context c, Integer type, Expression e, Tokenizer.Token t, List<LazyValue> lazyParams) {
|
||||||
List<Value> resolvedArgs = unpackArgs(lazyParams, c);
|
List<Value> resolvedParams = unpackArgs(lazyParams, c);
|
||||||
return execute(c, type, e, t, resolvedArgs);
|
return execute(c, type, e, t, resolvedParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LazyValue execute(Context c, Integer type, Expression e, Tokenizer.Token t, List<Value> resolvedArgs)
|
public LazyValue execute(Context c, Integer type, Expression e, Tokenizer.Token t, List<Value> params)
|
||||||
{
|
{
|
||||||
assertArgsOk(resolvedArgs, (fixedArgs) ->{
|
assertArgsOk(params, (fixedArgs) ->{
|
||||||
if (fixedArgs) // wrong number of args for fixed args
|
if (fixedArgs) // wrong number of args for fixed args
|
||||||
{
|
{
|
||||||
throw new ExpressionException(c, e, t,
|
throw new ExpressionException(c, e, t,
|
||||||
"Incorrect number of arguments for function "+name+
|
"Incorrect number of arguments for function "+name+
|
||||||
". Should be "+args.size()+", not "+resolvedArgs.size()+" like "+args
|
". Should be "+args.size()+", not "+params.size()+" like "+args
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else // too few args for varargs
|
else // too few args for varargs
|
||||||
@@ -225,7 +225,7 @@ public class FunctionValue extends Value implements Fluff.ILazyFunction
|
|||||||
argList.add("... "+varArgs);
|
argList.add("... "+varArgs);
|
||||||
throw new ExpressionException(c, e, t,
|
throw new ExpressionException(c, e, t,
|
||||||
"Incorrect number of arguments for function "+name+
|
"Incorrect number of arguments for function "+name+
|
||||||
". Should be at least "+args.size()+", not "+resolvedArgs.size()+" like "+argList
|
". Should be at least "+args.size()+", not "+params.size()+" like "+argList
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -235,15 +235,15 @@ public class FunctionValue extends Value implements Fluff.ILazyFunction
|
|||||||
for (int i=0; i<args.size(); i++)
|
for (int i=0; i<args.size(); i++)
|
||||||
{
|
{
|
||||||
String arg = args.get(i);
|
String arg = args.get(i);
|
||||||
Value val = resolvedArgs.get(i).reboundedTo(arg); // todo check if we need to copy that
|
Value val = params.get(i).reboundedTo(arg); // todo check if we need to copy that
|
||||||
newFrame.setVariable(arg, (cc, tt) -> val);
|
newFrame.setVariable(arg, (cc, tt) -> val);
|
||||||
}
|
}
|
||||||
if (varArgs != null)
|
if (varArgs != null)
|
||||||
{
|
{
|
||||||
List<Value> extraParams = new ArrayList<>();
|
List<Value> extraParams = new ArrayList<>();
|
||||||
for (int i = args.size(), mx = resolvedArgs.size(); i < mx; i++)
|
for (int i = args.size(), mx = params.size(); i < mx; i++)
|
||||||
{
|
{
|
||||||
extraParams.add(resolvedArgs.get(i).reboundedTo(null)); // copy by value I guess
|
extraParams.add(params.get(i).reboundedTo(null)); // copy by value I guess
|
||||||
}
|
}
|
||||||
Value rest = ListValue.wrap(extraParams).bindTo(varArgs); // didn't we just copied that?
|
Value rest = ListValue.wrap(extraParams).bindTo(varArgs); // didn't we just copied that?
|
||||||
newFrame.setVariable(varArgs, (cc, tt) -> rest);
|
newFrame.setVariable(varArgs, (cc, tt) -> rest);
|
||||||
|
|||||||
Reference in new issue
Block a user