WIP unpacking of parameters.

This commit is contained in:
gnembon committed 2021-04-21 12:21:47 -03:00
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