WIP unpacking of parameters.
This commit is contained in:
1 parent
72a3d74a97
commit
a65d16c9ba
11 files changed
+106
-30
No files matched your search
@@ -6,12 +6,14 @@ import carpet.script.LazyValue;
|
||||
import carpet.script.argument.FunctionArgument;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.exception.ReturnStatement;
|
||||
import carpet.script.value.AbstractListValue;
|
||||
import carpet.script.value.FunctionSignatureValue;
|
||||
import carpet.script.value.FunctionValue;
|
||||
import carpet.script.value.FunctionAnnotationValue;
|
||||
import carpet.script.value.ListValue;
|
||||
import carpet.script.value.StringValue;
|
||||
import carpet.script.value.Value;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -90,9 +92,20 @@ public class Functions {
|
||||
|
||||
expression.addLazyUnaryOperator("...", Operators.precedence.get("def->..."), false, (c, t, lv) ->
|
||||
{
|
||||
if (t != Context.LOCALIZATION)
|
||||
throw new InternalExpressionException("That functionality has not been implemented yet.");
|
||||
return (cc, tt) -> new FunctionAnnotationValue(lv.evalValue(c), 1);
|
||||
if (t == Context.LOCALIZATION)
|
||||
return (cc, tt) -> new FunctionAnnotationValue(lv.evalValue(c), 1);
|
||||
if (t == Context.CALLARGS)
|
||||
{
|
||||
Value params = lv.evalValue(c, Context.NONE);
|
||||
if (params instanceof ListValue)
|
||||
return (cc, tt) -> params;
|
||||
if (!(params instanceof AbstractListValue))
|
||||
throw new InternalExpressionException("Unable to unpack a non-list");
|
||||
Value unpacked = ListValue.wrap(ImmutableList.copyOf(((AbstractListValue) params).iterator()));
|
||||
return (cc, tt) -> unpacked;
|
||||
}
|
||||
throw new InternalExpressionException("That functionality has not been implemented yet.");
|
||||
|
||||
});
|
||||
|
||||
//assigns const procedure to the lhs, returning its previous value
|
||||
|
||||
@@ -19,7 +19,7 @@ public class Threading
|
||||
if (lv.size() == 0)
|
||||
throw new InternalExpressionException("'task' requires at least function to call as a parameter");
|
||||
FunctionArgument<LazyValue> functionArgument = FunctionArgument.findIn(c, expression.module, lv, 0, false, true);
|
||||
ThreadValue thread = new ThreadValue(Value.NULL, functionArgument.function, expr, tok, c, FunctionValue.resolveArgs(functionArgument.args, c, t));
|
||||
ThreadValue thread = new ThreadValue(Value.NULL, functionArgument.function, expr, tok, c, functionArgument.unpackArgs(c));
|
||||
Thread.yield();
|
||||
return (cc, tt) -> thread;
|
||||
});
|
||||
@@ -30,7 +30,7 @@ public class Threading
|
||||
throw new InternalExpressionException("'task' requires at least function to call as a parameter");
|
||||
Value queue = lv.get(0).evalValue(c);
|
||||
FunctionArgument<LazyValue> functionArgument = FunctionArgument.findIn(c, expression.module, lv, 1, false, true);
|
||||
ThreadValue thread = new ThreadValue(queue, functionArgument.function, expr, tok, c, FunctionValue.resolveArgs(functionArgument.args, c, t));
|
||||
ThreadValue thread = new ThreadValue(queue, functionArgument.function, expr, tok, c, functionArgument.unpackArgs(c));
|
||||
Thread.yield();
|
||||
return (cc, tt) -> thread;
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user