This commit is contained in:
gnembon committed 2021-04-23 01:20:42 -03:00
1 parent edca3fb131
commit bed9e2c60a
6 files changed
+56 -21

No files matched your search

+9 -9
View File
@@ -188,7 +188,7 @@ public class Expression
public void addLazyFunctionWithDelegation(String name, int numpar,
QuinnFunction<Context, Integer, Expression, Tokenizer.Token, List<LazyValue>, LazyValue> lazyfun)
{
functions.put(name, new AbstractLazyFunction(numpar)
functions.put(name, new AbstractLazyFunction(numpar, name)
{
@Override
public LazyValue lazyEval(Context c, Integer type, Expression e, Tokenizer.Token t, List<LazyValue> lv)
@@ -208,7 +208,7 @@ public class Expression
public void addFunctionWithDelegation(String name, int numpar,
QuinnFunction<Context, Integer, Expression, Tokenizer.Token, List<Value>, Value> fun)
{
functions.put(name, new AbstractLazyFunction(numpar)
functions.put(name, new AbstractLazyFunction(numpar, name)
{
@Override
public LazyValue lazyEval(Context c, Integer type, Expression e, Tokenizer.Token t, List<LazyValue> lv)
@@ -286,7 +286,7 @@ public class Expression
public void addUnaryOperator(String surface, boolean leftAssoc, Function<Value, Value> fun)
{
operators.put(surface+"u", new AbstractUnaryOperator(Operators.precedence.get("unary+-!"), leftAssoc)
operators.put(surface+"u", new AbstractUnaryOperator(Operators.precedence.get("unary+-!..."), leftAssoc)
{
@Override
public Value evalUnary(Value v1)
@@ -312,7 +312,7 @@ public class Expression
public void addUnaryFunction(String name, Function<Value, Value> fun)
{
functions.put(name, new AbstractFunction(1)
functions.put(name, new AbstractFunction(1, name)
{
@Override
public Value eval(List<Value> parameters)
@@ -324,7 +324,7 @@ public class Expression
public void addBinaryFunction(String name, BiFunction<Value, Value, Value> fun)
{
functions.put(name, new AbstractFunction(2)
functions.put(name, new AbstractFunction(2, name)
{
@Override
public Value eval(List<Value> parameters)
@@ -339,7 +339,7 @@ public class Expression
public void addFunction(String name, Function<List<Value>, Value> fun)
{
functions.put(name, new AbstractFunction(-1)
functions.put(name, new AbstractFunction(-1, name)
{
@Override
public Value eval(List<Value> parameters)
@@ -370,7 +370,7 @@ public class Expression
public void addLazyFunction(String name, int num_params, TriFunction<Context, Integer, List<LazyValue>, LazyValue> fun)
{
functions.put(name, new AbstractLazyFunction(num_params)
functions.put(name, new AbstractLazyFunction(num_params, name)
{
@Override
public LazyValue lazyEval(Context c, Integer i, Expression e, Tokenizer.Token t, List<LazyValue> lazyParams)
@@ -389,7 +389,7 @@ public class Expression
public void addContextFunction(String name, int num_params, TriFunction<Context, Integer, List<Value>, Value> fun)
{
functions.put(name, new AbstractLazyFunction(num_params)
functions.put(name, new AbstractLazyFunction(num_params, name)
{
@Override
public LazyValue lazyEval(Context c, Integer i, Expression e, Tokenizer.Token t, List<LazyValue> lazyParams)
@@ -409,7 +409,7 @@ public class Expression
public void addTypedContextFunction(String name, int num_params, int reqType, TriFunction<Context, Integer, List<Value>, Value> fun)
{
functions.put(name, new AbstractLazyFunction(num_params)
functions.put(name, new AbstractLazyFunction(num_params, name)
{
@Override
public LazyValue lazyEval(Context c, Integer i, Expression e, Tokenizer.Token t, List<LazyValue> lazyParams)
+4 -5
View File
@@ -64,9 +64,10 @@ public abstract class Fluff
protected String name;
int numParams;
AbstractLazyFunction(int numParams)
AbstractLazyFunction(int numParams, String name)
{
this.numParams = numParams;
this.name = name;
}
@@ -115,12 +116,10 @@ public abstract class Fluff
public abstract static class AbstractFunction extends AbstractLazyFunction implements IFunction
{
AbstractFunction(int numParams) {
super(numParams);
AbstractFunction(int numParams, String name) {
super(numParams, name);
}
@Override
public LazyValue lazyEval(Context cc, Integer type, Expression e, Tokenizer.Token t, final List<LazyValue> lazyParams)
{
@@ -93,7 +93,7 @@ public class Functions {
});
// lazy because of typed evaluation of the argument
expression.addLazyUnaryOperator("...", Operators.precedence.get("def->..."), false, (c, t, lv) ->
expression.addLazyUnaryOperator("...", Operators.precedence.get("unary+-!..."), false, (c, t, lv) ->
{
if (t == Context.LOCALIZATION)
return (cc, tt) -> new FunctionAnnotationValue(lv.evalValue(c), FunctionAnnotationValue.Type.VARARG);
@@ -116,7 +116,7 @@ public class Functions {
//assigns const procedure to the lhs, returning its previous value
// must be lazy due to RHS being an expression to save to execute
expression.addLazyBinaryOperatorWithDelegation("->", Operators.precedence.get("def->..."), false, (c, type, e, t, lv1, lv2) ->
expression.addLazyBinaryOperatorWithDelegation("->", Operators.precedence.get("def->"), false, (c, type, e, t, lv1, lv2) ->
{
if (type == Context.MAPDEF)
{
@@ -20,7 +20,7 @@ import java.util.Map;
public class Operators {
public static final Map<String, Integer> precedence = new HashMap<String,Integer>() {{
put("attribute~:", 80);
put("unary+-!", 60);
put("unary+-!...", 60);
put("exponent^", 40);
put("multiplication*/%", 30);
put("addition+-", 20);
@@ -29,7 +29,7 @@ public class Operators {
put("and&&", 5);
put("or||", 4);
put("assign=<>", 3);
put("def->...", 2);
put("def->", 2);
put("nextop;", 1);
}};
@@ -216,7 +216,9 @@ public class Operators {
expression.addUnaryOperator("+", false, NumericValue::asNumber);
// could be non-lazy, but who cares - its a small one.
expression.addLazyUnaryOperator("!", precedence.get("unary+-!"), false, (c, t, lv)-> lv.evalValue(c, Context.BOOLEAN).getBoolean() ? (cc, tt)-> Value.FALSE : (cc, tt) -> Value.TRUE); // might need context boolean
expression.addLazyUnaryOperator("!", precedence.get("unary+-!..."), false, (c, t, lv) ->
lv.evalValue(c, Context.BOOLEAN).getBoolean() ? (cc, tt)-> Value.FALSE : (cc, tt) -> Value.TRUE
); // might need context boolean
}
}
@@ -7,4 +7,17 @@ public class FunctionUnpackedArgumentsValue extends ListValue
public FunctionUnpackedArgumentsValue(List<Value> list) {
super(list);
}
@Override
public Value clone()
{
return new FunctionUnpackedArgumentsValue(items);
}
@Override
public Value deepcopy()
{
ListValue copy = (ListValue)super.deepcopy();
return new FunctionUnpackedArgumentsValue(copy.items);
}
}