@Override public void exitMetagenCall(MetagenParser.MetagenCallContext ctx) { FunctionCall topFunctionCall = calls.pop(); if (calls.empty()) { flows.peek().getLastExpression().setCall(topFunctionCall); } else { calls.peek().addFunctionArg(topFunctionCall); } callContexts.pop(); }
@Override public void enterMetagenFlow(MetagenParser.MetagenFlowContext ctx) { logger.debug("parsing metagen flow."); flowContexts.push(ctx); flows.push(new MetagenFlow()); calls.clear(); }
@Override public void enterExpression(LambdasParser.ExpressionContext ctx) { expressionContexts.push(ctx); flows.peek().addExpression(new Expression()); //logger.debug("parsing metagen expression."); }
public static LongUnaryOperator forSpec(String spec) { LambdasDSL.ParseResult parseResult = LambdasDSL.parse(spec); if (parseResult.throwable!=null) { throw new RuntimeException(parseResult.throwable); } MetagenFlow flow = parseResult.flow; if (flow.getExpressions().size()>1) { throw new RuntimeException("Unable to parse flows in " + IntegerDistributions.class); } FunctionCall call = flow.getLastExpression().getCall(); Class<?> inType = Optional.ofNullable(call.getInputType()).map(ValueType::valueOfClassName).map(ValueType::getValueClass).orElse(null); Class<?> outType = Optional.ofNullable(call.getOutputType()).map(ValueType::valueOfClassName).map(ValueType::getValueClass).orElse(null); inType = (inType==null ? long.class : inType); outType = (outType==null ? long.class : outType); List<ResolvedFunction> resolvedFunctions = new IntegerDistributions().resolveFunctions( outType, inType, call.getFunctionName(), call.getArguments() ); if (resolvedFunctions.size()>1) { throw new RuntimeException("Found " + resolvedFunctions.size() + " implementations, be more specific with" + "input or output qualifiers as in int -> or -> long"); } return (LongUnaryOperator) resolvedFunctions.get(0).getFunctionObject(); }
public static LongToDoubleFunction forSpec(String spec) { LambdasDSL.ParseResult parseResult = LambdasDSL.parse(spec); if (parseResult.throwable!=null) { throw new RuntimeException(parseResult.throwable); } MetagenFlow flow = parseResult.flow; if (flow.getExpressions().size()>1) { throw new RuntimeException("Unable to parse flows in " + IntegerDistributions.class); } FunctionCall call = flow.getLastExpression().getCall(); Class<?> inType = Optional.ofNullable(call.getInputType()).map(ValueType::valueOfClassName).map(ValueType::getValueClass).orElse(null); Class<?> outType = Optional.ofNullable(call.getOutputType()).map(ValueType::valueOfClassName).map(ValueType::getValueClass).orElse(null); if (inType!=null && inType!=long.class) { throw new RuntimeException("This only supports long for input."); } if (outType!=null && outType!=double.class) { throw new RuntimeException("This only supports double fo routput."); } inType = (inType==null ? long.class : inType); outType = (outType==null ? int.class : outType); List<ResolvedFunction> resolvedFunctions = new RealDistributions().resolveFunctions( outType, inType, call.getFunctionName(), call.getArguments() ); if (resolvedFunctions.size()>1) { throw new RuntimeException("Found " + resolvedFunctions.size() + " implementations, be more specific with" + "input or output qualifiers as in int -> or -> long"); } return ((LongToDoubleFunction) resolvedFunctions.get(0).getFunctionObject()); }
@Override public void exitMetagenCall(LambdasParser.MetagenCallContext ctx) { FunctionCall topFunctionCall = calls.pop(); if (calls.empty()) { flows.peek().getLastExpression().setCall(topFunctionCall); } else { calls.peek().addFunctionArg(topFunctionCall); } callContexts.pop(); }
@Override public void enterMetagenFlow(LambdasParser.MetagenFlowContext ctx) { logger.debug("parsing metagen flow..."); flowContexts.push(ctx); flows.push(new MetagenFlow()); calls.clear(); if (ctx.COMPOSE()!=null) { logger.warn("The 'compose' keyword is no longer needed in lambda construction. It will be deprecated in the future."); } }
@Override public void enterExpression(MetagenParser.ExpressionContext ctx) { expressionContexts.push(ctx); flows.peek().addExpression(new Expression()); //logger.debug("parsing metagen expression."); }
@Override public void exitLvalue(MetagenParser.LvalueContext ctx) { flows.peek().getLastExpression().setAssignment(new Assignment(ctx.ID().getSymbol().getText())); }
@Override public void exitLvalue(LambdasParser.LvalueContext ctx) { flows.peek().getLastExpression().setAssignment(new Assignment(ctx.ID().getSymbol().getText())); }