Package org.openquark.cal.internal.javamodel.JavaStatement

Examples of org.openquark.cal.internal.javamodel.JavaStatement.Block


            Expression condExpression = conditionExpressions.getConditionExpression();
            ExpressionContextPair pair;
            pair = generateUnboxedArgument(JavaTypeName.BOOLEAN, condExpression, variableContext);

            Block contextBlock = pair.getContextBlock();
            JavaExpression condJavaExpression = pair.getJavaExpression();
            ExpressionContextPair thenPart = genS_E (conditionExpressions.getThenExpression(), variableContext);
            ExpressionContextPair elsePart = genS_E (conditionExpressions.getElseExpression(), variableContext);

            // Note: both contexts are evaluated..
            contextBlock.addStatement(thenPart.getContextBlock());
            contextBlock.addStatement(elsePart.getContextBlock());

            OperatorExpression ternaryExpression = new OperatorExpression.Ternary(condJavaExpression, new JavaExpression.CastExpression(JavaTypeNames.RTVALUE, thenPart.getJavaExpression()), elsePart.getJavaExpression());
            return new ExpressionContextPair(ternaryExpression, contextBlock);
        }


        // With the changes to the compiler to lift inner cases into their own function
        // we should never encounte a case at this level.
        // Expression is a case/switch?
        if (e.asSwitch() != null) {
            throw new CodeGenerationException ("Encountered a case statement that wasn't at top level in schemeE.");
        }

        // Similarly, we should never encounter a data constructor field selection.
        if (e.asDataConsSelection() != null) {
            return generateDCFieldSelection(e.asDataConsSelection(), Scheme.E_SCHEME, variableContext);
            //throw new CodeGenerationException  ("Encountered a data constructor field selection at an inner level.  schemeE.");
        }

        // R is a let var.
        if (e.asLetNonRec() != null) {
            return generateLetNonRec (e.asLetNonRec(), Scheme.E_SCHEME, null, variableContext);
        }
        if (e.asLetRec() != null) {
            return generateLetRec (e.asLetRec(), Scheme.E_SCHEME, variableContext);
        }

        // R is an application?
        Expression.Appl appl = e.asAppl();
        if (appl != null) {
            ExpressionContextPair ecp = buildApplicationChain (appl, Scheme.E_SCHEME, variableContext);
            if (ecp == null) {

                // This is a general application
                ExpressionContextPair target = genS_C(appl.getE1(), variableContext);
                ExpressionContextPair arg = genS_C(appl.getE2(), variableContext);

                Block newContextBlock = target.getContextBlock();
                newContextBlock.addStatement(arg.getContextBlock());

                MethodInvocation applyMI = createInvocation(target.getJavaExpression(), APPLY, arg.getJavaExpression());
                MethodInvocation evaluateMI = createInvocation(applyMI, EVALUATE, EXECUTION_CONTEXT_VAR);//, ExecutionContextClassName));

                ecp = new ExpressionContextPair(evaluateMI, newContextBlock);
View Full Code Here


     * @param pair the ExpressionContextPair
     * @param context - current variable context.  May be null.
     * @return the resulting java statement
     */
    private JavaStatement generateReturn(ExpressionContextPair pair, VariableContext context) {
        Block contextBlock = pair.getContextBlock();
        JavaExpression javaExpression = pair.getJavaExpression();

        if (javaExpression != null) {
            ReturnStatement ret = new ReturnStatement(javaExpression);

            if (context != null) {
                Set<VarInfo> vars = new HashSet<VarInfo>();
                Map<QualifiedName, VarInfo> scope = context.getCurrentScope();
                for (final Map.Entry<QualifiedName, VarInfo> entry : scope.entrySet()) {
                    vars.add(entry.getValue());
                }
                returnStatementToLocalVars.put(ret, vars);
            }

            contextBlock.addStatement(ret);
        }
        return contextBlock;
    }
View Full Code Here

            } else {
                ecp[i-1] = genS_C(chain[i], variableContext);
            }
        }

        Block newContext;
        if (ecp.length > 0) {
            newContext = ecp[0].getContextBlock();
            for (int i = 1; i < ecp.length; ++i) {
                newContext.addStatement(ecp[i].getContextBlock());
            }
        } else {
            newContext = new Block();
        }

        // This is a fully saturated supercombinator application
        // for which we can generate a direct call instead of building a suspension.
        int calledArity = mf.getArity();
View Full Code Here

            // Then
            variableContext.pushJavaScope();
            JavaStatement thenPart = genS_R (conditionExpressions.getThenExpression(), variableContext);

            Block thenBlock = variableContext.popJavaScope();
            thenBlock.addStatement(thenPart);

            // Else
            variableContext.pushJavaScope();
            JavaStatement elsePart = genS_R (conditionExpressions.getElseExpression(), variableContext);

            Block elseBlock = variableContext.popJavaScope();
            elseBlock.addStatement(elsePart);

            JavaExpression conditionExpression = pair.getJavaExpression();

            JavaStatement ite = new IfThenElseStatement(conditionExpression, thenBlock, elseBlock);

            Block contextBlock = pair.getContextBlock();
            contextBlock.addStatement(ite);

            // We don't need to call generateReturn() at this point.  Any return statements
            // will have been generated in the sub-parts of the if-then-else.
            return contextBlock;
        }
View Full Code Here

        ExpressionContextPair baseRecordExprContextPair = genS_C(baseRecordExpr, variableContext);

        JavaExpression javaBaseRecordExpr = baseRecordExprContextPair.getJavaExpression();
        //holds the variable declarations introduced in subexpressions of the record update.
        //for example, in the expression {e | field1 := e1, field2 := e2}, these could come from e, e1 or e2.
        Block recordUpdateBlock = new Block();
        recordUpdateBlock.addStatement(baseRecordExprContextPair.getContextBlock());

        Expression.FieldValueData updateFieldsData = recordUpdateExpr.getUpdateFieldsData();
        final int nOrdinalFields = updateFieldsData.getNOrdinalFields();
        final int nTextualFields = updateFieldsData.getNTextualFields();
View Full Code Here

        Expression baseRecordExpr = recordUpdateExpr.getBaseRecordExpr();

        //holds the variable declarations introduced in subexpressions of the record update expression.
        //for example, in the expression {e | field1 := e1, field2 := e2}, these could come from e, e1 or e2.
        Block recordUpdateBlock = new Block();

        JavaExpression invocationTarget;
        {

            ExpressionContextPair baseRecordExprContextPair = genS_E(baseRecordExpr, variableContext);

            JavaExpression javaBaseRecordExpr = baseRecordExprContextPair.getJavaExpression();
            recordUpdateBlock.addStatement(baseRecordExprContextPair.getContextBlock());

            //the compiler ensures that evaluating baseRecordExpr will result in a RTRecordValue.
            invocationTarget = new CastExpression(JavaTypeNames.RTRECORD_VALUE, javaBaseRecordExpr);
        }

        //the expression {e | field1 := e1, field2 := e2, field3 := e3} is encoded as
        //{{{e | field1 := e1} | field2 := e2} | field3 := e3}

        // We want to copy the base record for the first update.  Subsequent updates can just
        // mutate the copy.
        // The copy is created by a call to:
        //    1) updateOrdinalField - if only ordinal fields are being updated
        //    2) updateTextualField - if only textual fields are being updated
        //    3) updateMixedOrdinalField - if both ordinal and textual fields are being updated
        FieldValueData fieldValueData = recordUpdateExpr.getUpdateFieldsData();

        SortedMap<FieldName, Expression> updateFieldValuesMap = recordUpdateExpr.getUpdateFieldValuesMap();
        int fieldN = 0;
        for (final Map.Entry<FieldName, Expression> entry : updateFieldValuesMap.entrySet()) {

            FieldName fieldName = entry.getKey();
            Expression updateExpr = entry.getValue();

            //the actual updated values are not strictly evaluated, so we use the C scheme.
            ExpressionContextPair updateExprContextPair = genS_C(updateExpr, variableContext);
            JavaExpression javaUpdateExpr = updateExprContextPair.getJavaExpression();
            recordUpdateBlock.addStatement(updateExprContextPair.getContextBlock());

            if (fieldName instanceof FieldName.Ordinal) {

                //we need to copy the base record only for the first update. Subsequent updates can just mutate the base.
                String updateMethodName;
View Full Code Here

        Expression baseRecordExpr = recordExtensionExpr.getBaseRecordExpr();

        //holds the variable declarations introduced in subexpressions of the record extension.
        //for example, in the expression {e | field1 = e1, field2 = e2}, these could come from e, e1 or e2.
        Block recordExtensionBlock = new Block();

        JavaExpression invocationTarget;
        if (baseRecordExpr != null) {

            ExpressionContextPair baseRecordExprContextPair = genS_E(baseRecordExpr, variableContext);

            JavaExpression javaBaseRecordExpr = baseRecordExprContextPair.getJavaExpression();
            recordExtensionBlock.addStatement(baseRecordExprContextPair.getContextBlock());

            //the compiler ensures that evaluating baseRecordExpr will result in a RTRecordValue.
            invocationTarget = new CastExpression(JavaTypeNames.RTRECORD_VALUE, javaBaseRecordExpr);
            //invocationType = InvocationType.VIRTUAL;
View Full Code Here

        ExpressionContextPair baseRecordExprContextPair = genS_C(baseRecordExpr, variableContext);

        JavaExpression javaBaseRecordExpr = baseRecordExprContextPair.getJavaExpression();
        //holds the variable declarations introduced in subexpressions of the record extension.
        //for example, in the expression {e | field1 = e1, field2 = e2}, these could come from e, e1 or e2.
        Block recordExtensionBlock = new Block();
        recordExtensionBlock.addStatement(baseRecordExprContextPair.getContextBlock());

        Expression.FieldValueData extensionFieldsData = recordExtensionExpr.getExtensionFieldsData();
        final int nOrdinalFields = extensionFieldsData.getNOrdinalFields();
        final int nTextualFields = extensionFieldsData.getNTextualFields();
View Full Code Here


        ExpressionContextPair recordExprContextPair = genS_E(recordExpr, variableContext);

        JavaExpression javaRecordExpr = recordExprContextPair.getJavaExpression();
        Block recordSelectionBlock = new Block();
        recordSelectionBlock.addStatement(recordExprContextPair.getContextBlock());

        //the compiler ensures that evaluating recordExpr will result in a RTRecordValue.
        javaRecordExpr = new CastExpression(JavaTypeNames.RTRECORD_VALUE, javaRecordExpr);

        MethodInvocation getValueInvocation;
View Full Code Here

         * @throws CodeGenerationException
         */
        public Block popJavaScope () throws CodeGenerationException {
            Map<QualifiedName, VarInfo> varMap = javaScopeStack.pop();

            Block declarationBlock = new Block();
            Block definitionBlock = new Block();

            for (final Map.Entry<QualifiedName, VarInfo> entry : varMap.entrySet()) {
                VarInfo info = entry.getValue();

                String javaName = info.getJavaName();

                if (info instanceof VarInfo.LetRec) {
                    JavaExpression boxedVarDef = ((VarInfo.LetRec)info).getLazyVarDef();
                    if (boxedVarDef == null) {
                        throw new CodeGenerationException ("Missing boxed definition for let variable: " + info.getCALName());
                    }

                    LocalVariable letNameVariable = new LocalVariable(javaName, JavaTypeNames.RTINDIRECTION);

                    // RTValue javaName = new RTIndirection();
                    JavaExpression newIndirection = new ClassInstanceCreationExpression(JavaTypeNames.RTINDIRECTION);
                    LocalVariableDeclaration letDecl = new LocalVariableDeclaration(letNameVariable, newIndirection);
                    declarationBlock.addStatement(letDecl);

                    // Emit let variable definition.
                    // letName.setResult(letDef);
                    MethodInvocation letInvocation = createInvocation(letNameVariable, SETRESULT, boxedVarDef);
                    definitionBlock.addStatement(new ExpressionStatement(letInvocation));
                } else
                if (info instanceof VarInfo.LetNonRec) {
                    // This variable is referenced multiple times.
                    // We need to declare/initialize a local java variable.

View Full Code Here

TOP

Related Classes of org.openquark.cal.internal.javamodel.JavaStatement.Block

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.