risky optimizations.
This commit is contained in:
1 parent
989bc1ec2b
commit
07dce7bc2e
5 files changed
+19
-20
No files matched your search
@@ -658,18 +658,18 @@ public class Expression
|
||||
case UNARY_OPERATOR:
|
||||
{
|
||||
final LazyValue value = stack.pop();
|
||||
LazyValue result = (c, t) -> operators.get(token.surface).lazyEval(c, t, this, token, value, null).evalValue(c);
|
||||
LazyValue result = (c, t) -> operators.get(token.surface).lazyEval(c, t, this, token, value, null).evalValue(c, t);
|
||||
stack.push(result);
|
||||
break;
|
||||
}
|
||||
case OPERATOR:
|
||||
final LazyValue v1 = stack.pop();
|
||||
final LazyValue v2 = stack.pop();
|
||||
LazyValue result = (c,t) -> operators.get(token.surface).lazyEval(c, t,this, token, v2, v1).evalValue(c);
|
||||
LazyValue result = (c,t) -> operators.get(token.surface).lazyEval(c, t,this, token, v2, v1).evalValue(c, t);
|
||||
stack.push(result);
|
||||
break;
|
||||
case VARIABLE:
|
||||
stack.push((c, t) -> getOrSetAnyVariable(c, token.surface).evalValue(c));
|
||||
stack.push((c, t) -> getOrSetAnyVariable(c, token.surface).evalValue(c, t));
|
||||
break;
|
||||
case FUNCTION:
|
||||
String name = token.surface;
|
||||
@@ -700,7 +700,7 @@ public class Expression
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
stack.push((c, t) -> f.lazyEval(c, t, this, token, p).evalValue(c));
|
||||
stack.push((c, t) -> f.lazyEval(c, t, this, token, p).evalValue(c, t));
|
||||
break;
|
||||
case OPEN_PAREN:
|
||||
stack.push(LazyValue.PARAMS_START);
|
||||
|
||||
@@ -149,7 +149,7 @@ public abstract class Fluff
|
||||
{
|
||||
try
|
||||
{
|
||||
return (c, type_ignored) -> AbstractOperator.this.eval(v1.evalValue(c), v2.evalValue(c));
|
||||
return (c, type_ignored) -> AbstractOperator.this.eval(v1.evalValue(c, type), v2.evalValue(c, type));
|
||||
}
|
||||
catch (RuntimeException exc)
|
||||
{
|
||||
|
||||
@@ -45,11 +45,10 @@ public class Functions {
|
||||
{
|
||||
FunctionArgument<LazyValue> functionArgument = FunctionArgument.findIn(c, expression.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?)
|
||||
return fun.callInContext(c, t, functionArgument.args);
|
||||
}
|
||||
// gimme signature
|
||||
String name = lv.get(0).evalValue(c).getString();
|
||||
String name = lv.get(0).evalValue(c, Context.NONE).getString();
|
||||
List<String> args = new ArrayList<>();
|
||||
List<String> globals = new ArrayList<>();
|
||||
String varArgs = null;
|
||||
|
||||
@@ -70,7 +70,7 @@ public class Loops {
|
||||
// expr receives bounded variable '_' indicating iteration
|
||||
expression.addLazyFunction("loop", 2, (c, t, lv) ->
|
||||
{
|
||||
long limit = NumericValue.asNumber(lv.get(0).evalValue(c)).getLong();
|
||||
long limit = NumericValue.asNumber(lv.get(0).evalValue(c, Context.NONE)).getLong();
|
||||
Value lastOne = Value.NULL;
|
||||
LazyValue expr = lv.get(1);
|
||||
//scoping
|
||||
@@ -99,7 +99,7 @@ public class Loops {
|
||||
// receives bounded variable '_' with the expression
|
||||
expression.addLazyFunction("map", 2, (c, t, lv) ->
|
||||
{
|
||||
Value rval= lv.get(0).evalValue(c);
|
||||
Value rval= lv.get(0).evalValue(c, Context.NONE);
|
||||
if (!(rval instanceof AbstractListValue))
|
||||
throw new InternalExpressionException("First argument of 'map' function should be a list or iterator");
|
||||
Iterator<Value> iterator = ((AbstractListValue) rval).iterator();
|
||||
@@ -144,7 +144,7 @@ public class Loops {
|
||||
// produces list of values for which the expression is true
|
||||
expression.addLazyFunction("filter", 2, (c, t, lv) ->
|
||||
{
|
||||
Value rval= lv.get(0).evalValue(c);
|
||||
Value rval= lv.get(0).evalValue(c, Context.NONE);
|
||||
if (!(rval instanceof AbstractListValue))
|
||||
throw new InternalExpressionException("First argument of 'filter' function should be a list or iterator");
|
||||
Iterator<Value> iterator = ((AbstractListValue) rval).iterator();
|
||||
@@ -191,7 +191,7 @@ public class Loops {
|
||||
expression.addLazyFunction("first", 2, (c, t, lv) ->
|
||||
{
|
||||
|
||||
Value rval= lv.get(0).evalValue(c);
|
||||
Value rval= lv.get(0).evalValue(c, Context.NONE);
|
||||
if (!(rval instanceof AbstractListValue))
|
||||
throw new InternalExpressionException("First argument of 'first' function should be a list or iterator");
|
||||
Iterator<Value> iterator = ((AbstractListValue) rval).iterator();
|
||||
@@ -242,7 +242,7 @@ public class Loops {
|
||||
// returns true if expr is true for all items
|
||||
expression.addLazyFunction("all", 2, (c, t, lv) ->
|
||||
{
|
||||
Value rval= lv.get(0).evalValue(c);
|
||||
Value rval= lv.get(0).evalValue(c, Context.NONE);
|
||||
if (!(rval instanceof AbstractListValue))
|
||||
throw new InternalExpressionException("First argument of 'all' function should be a list or iterator");
|
||||
Iterator<Value> iterator = ((AbstractListValue) rval).iterator();
|
||||
@@ -306,7 +306,7 @@ public class Loops {
|
||||
// can be substituted for first and all, but first is more efficient and all doesn't require knowing list size
|
||||
expression.addLazyFunction("for", 2, (c, t, lv) ->
|
||||
{
|
||||
Value rval= lv.get(0).evalValue(c);
|
||||
Value rval= lv.get(0).evalValue(c, Context.NONE);
|
||||
if (!(rval instanceof AbstractListValue))
|
||||
throw new InternalExpressionException("First argument of 'for' function should be a list or iterator");
|
||||
Iterator<Value> iterator = ((AbstractListValue) rval).iterator();
|
||||
@@ -358,8 +358,8 @@ public class Loops {
|
||||
{
|
||||
LazyValue expr = lv.get(1);
|
||||
|
||||
Value acc = lv.get(2).evalValue(c);
|
||||
Value rval= lv.get(0).evalValue(c);
|
||||
Value acc = lv.get(2).evalValue(c, Context.NONE);
|
||||
Value rval= lv.get(0).evalValue(c, Context.NONE);
|
||||
if (!(rval instanceof AbstractListValue))
|
||||
throw new InternalExpressionException("First argument of 'reduce' should be a list or iterator");
|
||||
Iterator<Value> iterator = ((AbstractListValue) rval).iterator();
|
||||
|
||||
@@ -150,11 +150,11 @@ public class FunctionValue extends Value implements Fluff.ILazyFunction
|
||||
return varArgs != null;
|
||||
}
|
||||
|
||||
public LazyValue callInContext(Expression callingExpression, Context c, Integer type, Expression e, Tokenizer.Token t, List<LazyValue> lazyParams)
|
||||
public LazyValue callInContext(Context c, Integer type, List<LazyValue> lazyParams)
|
||||
{
|
||||
try
|
||||
{
|
||||
return lazyEval(c, type, e, t, lazyParams);
|
||||
return lazyEval(c, type, expression, token, lazyParams);
|
||||
}
|
||||
catch (ExpressionException exc)
|
||||
{
|
||||
@@ -164,12 +164,12 @@ public class FunctionValue extends Value implements Fluff.ILazyFunction
|
||||
catch (InternalExpressionException exc)
|
||||
{
|
||||
exc.stack.add(this);
|
||||
throw new ExpressionException(c, e, t, exc.getMessage(), exc.stack);
|
||||
throw new ExpressionException(c, expression, token, exc.getMessage(), exc.stack);
|
||||
}
|
||||
|
||||
catch (ArithmeticException exc)
|
||||
{
|
||||
throw new ExpressionException(c, e, t, "Your math is wrong, "+exc.getMessage(), Collections.singletonList(this));
|
||||
throw new ExpressionException(c, expression, token, "Your math is wrong, "+exc.getMessage(), Collections.singletonList(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user