Package org.openquark.cal.internal.javamodel

Examples of org.openquark.cal.internal.javamodel.JavaTypeName


        case JavaTypeName.ARRAY_TAG:
        {
            JavaTypeName.Reference.Array arrayType = (JavaTypeName.Reference.Array)typeName;
            int nDimensions = arrayType.getNDimensions();
            JavaTypeName elementType = arrayType.getElementType();

            // Get the source for the element type, and append "[]" for each dimension.
            StringBuilder sb = new StringBuilder(getNameForPrimitive(elementType));
            for (int i = 0; i < nDimensions; i++) {
                sb.append("_Array");
View Full Code Here


            JavaStatement caseVarDeclaration = null;
            Expression switchExpression = eswitch.getSwitchExpr();

            // Generate a local variable and assign the evaluated value of the expression
            // we are switching on.
            JavaTypeName typeClassName = isEnumDataType ? JavaTypeNames.RTVALUE : CALToJavaNames.createTypeNameFromType(typeCons, module);
            caseVar = new LocalVariable("$case" + nestedCaseLevel, typeClassName);

            // Add the local variable declaration.
            caseVarDeclaration = new LocalVariableDeclaration(caseVar);
            switchBlock.addStatement(caseVarDeclaration);
View Full Code Here

        }

        // Only do a local variable if the switch expression is not evaluated or we will
        // be extracting member fields from the data constructor resulting from evaluating the switch expression.
        LocalVariable caseVar = null;
        JavaTypeName caseVarType = (isSwitchingOnDC && alt.hasVars()) ? JavaTypeNames.RTCONS : JavaTypeNames.RTVALUE;
        if (!switchExprEvaluated || alt.hasVars()) {
            caseVar = new LocalVariable("$case" + nestedCaseLevel, caseVarType);

            ExpressionContextPair pair = genS_E(eSwitch.getSwitchExpr(), variableContext);
            switchBlock.addStatement(pair.getContextBlock());
            JavaExpression caseExpression = pair.getJavaExpression();

            if (caseVarType.equals(JavaTypeNames.RTCONS)) {
                caseExpression = new CastExpression(JavaTypeNames.RTCONS, caseExpression);
            }

            LocalVariableDeclaration caseVarDeclaration =
                new LocalVariableDeclaration(caseVar, caseExpression);
            switchBlock.addStatement(caseVarDeclaration);
        }

        // Populate the switch statement with case statement groups.

        // Create a new let variable scope to handle the alternate and any let variables it contains.
        variableContext.pushJavaScope();

        Block caseBlock = new Block();

        if (isSwitchingOnDC) {
            caseBlock.addStatement(new LineComment(((DataConstructor)altTag).getName().getQualifiedName()));
        }

        // Get this alternative's variables.  These have to be added to the active list of scope variables
        if (alt.hasVars()) {
            caseBlock.addStatement(new LineComment("Decompose data type to access members."));

            if (caseVar == null) {
                throw new CodeGenerationException ("Null case variable encountered in single alternate switch.");
            }

            // Must be a data constructor tag, since there are field names (see Expression.Switch.SwitchAlt).
            DataConstructor tagDC = (DataConstructor)altTag;

            TypeExpr fieldTypes[] = SCJavaDefn.getFieldTypesForDC(tagDC);

            // Cast the case var to the appropriate type to call getField0, getField1, etc.
            JavaTypeName dcTypeName = CALToJavaNames.createTypeNameFromDC(tagDC, module);
            JavaExpression castExpression = new CastExpression(dcTypeName, caseVar);

            // There is at least one field to be extracted.
            // Declare a local variable that is the casted case var so that we only do the cast once.
            JavaExpression castCaseVar = new LocalVariable("$dcCaseVar" + nestedCaseLevel, dcTypeName);
            LocalVariableDeclaration localVarStmnt = new LocalVariableDeclaration((LocalVariable)castCaseVar, castExpression);
            caseBlock.addStatement (localVarStmnt);

            for (final AltVarIndexPair altVarIndexPair : getAltVarIndexList(alt, tagDC)) {

                String altVar = altVarIndexPair.getAltVar();
                int fieldIndex = altVarIndexPair.getIndex();

                String fieldGetterName = "get" + SCJavaDefn.getJavaFieldNameFromDC(tagDC, fieldIndex);

                // Build in place representation of this variable mapped to its name
                QualifiedName qn = QualifiedName.make(currentModuleName, altVar);
                VarInfo.DCMember vi = variableContext.addDCField(qn, fieldTypes[fieldIndex]);

                boolean fieldIsStrict =
                    !LECCMachineConfiguration.IGNORE_STRICTNESS_ANNOTATIONS && tagDC.isArgStrict(fieldIndex);

                if (fieldIsStrict) {
                    vi.setEvaluated(true);
                }

                if (fieldIsStrict) {
                    if (SCJavaDefn.canTypeBeUnboxed(fieldTypes[fieldIndex])) {
                        JavaTypeName strictType = SCJavaDefn.typeExprToTypeName(fieldTypes[fieldIndex]);
                        JavaExpression unboxedInitializer =
                            new JavaExpression.MethodInvocation.Instance(castCaseVar,
                                                                         fieldGetterName + "_As_" + SCJavaDefn.getNameForPrimitive(strictType),
                                                                         strictType,
                                                                         JavaExpression.MethodInvocation.InvocationType.VIRTUAL);
View Full Code Here

        // This is a fully saturated supercombinator application that can be represented
        // using an special purpose graph node.
        JavaExpression args[] = new JavaExpression[calledArity + 1];
        args[0] = expressionVarToJavaDef(var, Scheme.E_SCHEME, variableContext);
        JavaTypeName argTypes[] = new JavaTypeName[calledArity + 1];
        if (useTypeSpecificAppNode) {
            argTypes[0] = CALToJavaNames.createTypeNameFromSC(var.getName(), module);
        } else {
            argTypes[0] = JavaTypeNames.RTSUPERCOMBINATOR;
        }
        for (int i = 0; i < calledArity; ++i) {
            args[i+1] = ecp[i+1].getJavaExpression();
            if (calledArgStrictness[i] && SCJavaDefn.canTypeBeUnboxed(calledArgTypes[i])) {
                argTypes[i+1] = SCJavaDefn.typeExprToTypeName(calledArgTypes[i]);
            } else {
                argTypes[i+1] = JavaTypeNames.RTVALUE;
            }
        }

        JavaTypeName appNodeType;
        if (useTypeSpecificAppNode) {
            appNodeType = CALToJavaNames.createStrictInnerTypeNameFromSC(var.getName(), module);
        } else {
            appNodeType = getTypeNameForApplicationNode(chain.length-1, true);
        }
View Full Code Here

            return null;
        }


        // Get the JavaTypeName for the partial application node.
        JavaTypeName nodeClassName = JavaTypeName.make("org.openquark.cal.internal.runtime.lecc.RTPartialApp$_"+calledArity+"$_"+(chain.length-1), false);
        int length = chain.length;

        // Compile each of the arguments in the partial application lazily.
        ExpressionContextPair[] ecp = new ExpressionContextPair[chain.length];
        for (int i = 1; i < length; ++i) {
                ecp[i] = genS_C(chain[i], variableContext);
        }

        // Build up the context from the compiled arguments.
        Block newContext = ecp[1].getContextBlock();
        for (int i = 2; i < length; ++i) {
            newContext.addStatement(ecp[i].getContextBlock());
        }

        // Build the statement to create a new partial application node.
        JavaExpression args[] = new JavaExpression[length];
        JavaTypeName argTypes[] = new JavaTypeName[length];
        Arrays.fill(argTypes, JavaTypeNames.RTVALUE);
        args[0] = expressionVarToJavaDef(chain[0].asVar(), Scheme.E_SCHEME, variableContext);
        argTypes[0] = JavaTypeNames.RTSUPERCOMBINATOR;

        for (int i = 1; i < length; ++i) {
View Full Code Here

                }
            }
        }

        for (int i = 0; i < getArity(); ++i) {
            JavaTypeName argType = JavaTypeNames.RTVALUE;
            if (isArgUnboxable(i) && isArgStrict (i)) {
                argType = typeExprToTypeName(argumentTypes[i]);
            }

            if (needTemp[i] == 0) {
View Full Code Here

        JavaExpression constructorArgs[] = new JavaExpression [calledArity + 1];
        constructorArgs[0] = scInstance;
        for (int i = 0; i < args.length; ++i) {
            constructorArgs[i+1] = args[i];
        }
        JavaTypeName constructorArgTypes[] = new JavaTypeName[calledArity + 1];
        Arrays.fill(constructorArgTypes, JavaTypeNames.RTVALUE);
        constructorArgTypes[0] = JavaTypeNames.RTSUPERCOMBINATOR;

        JavaTypeName appNodeType;
        // We want to use a type specific app node if the called function
        // is a tail recursive loop with arity greater than that supported
        // by the predefined lazy app nodes.
        if (mf.isTailRecursive() && calledArity > LECCMachineConfiguration.OPTIMIZED_APP_CHAIN_LENGTH) {
            appNodeType = CALToJavaNames.createLazyInnerTypeNameFromSC(var.getName(), module);
View Full Code Here

                JavaExpression args[] = new JavaExpression[chain.length];
                for (int i = 0; i < chain.length; ++i) {
                    args[i] = ecp[i].getJavaExpression();
                }

                JavaTypeName type;
                switch (nArgs) {
                    case 2:
                        type = JavaTypeNames.RTOAPP2;
                        break;
                    case 3:
                        type = JavaTypeNames.RTOAPP3;
                         break;
                    default:
                        throw new IllegalStateException();
                }

                JavaTypeName constructorArgTypes[] = new JavaTypeName[chain.length];
                Arrays.fill(constructorArgTypes, JavaTypeNames.RTVALUE);
                root = new JavaExpression.ClassInstanceCreationExpression(type, args, constructorArgTypes);
                if (scheme == Scheme.E_SCHEME) {
                    // This is being built in a strict scheme so call evaluate on the RTValue.
                    root = createInvocation (root, EVALUATE, EXECUTION_CONTEXT_VAR);
View Full Code Here

            // First determine what kind of symbol this is
            if (dc != null) {
                // Constructor
                // Emit symbol with factory invocation

                JavaTypeName typeName = CALToJavaNames.createTypeNameFromDC(dc, module);
                JavaExpression dcInstance;
                dcInstance = getReferencedDC(typeName, dc);

                return dcInstance;
            } else {
                MachineFunction mf = module.getFunction(qualName);
                if (mf == null) {
                    throw new CodeGenerationException("Unable to retrieve MachineFunction for " + qualName.getQualifiedName());
                }

                LECCModule.FunctionGroupInfo fgi = module.getFunctionGroupInfo(qualName);
                if (fgi == null) {
                    throw new CodeGenerationException("Unable to retrieve FunctionGroupInfo for " + qualName.getQualifiedName());
                }

                // Function
                JavaTypeName fullClass = CALToJavaNames.createTypeNameFromSC(qualName, module);

                if (mf.getArity() == 0) {
                    // This is a CAF or a zero arity function.
                    // Either way we need to invoke the static factory method
                    // 'make'.
                    if (fgi.getNCAFs() + fgi.getNZeroArityFunctions() <= 1) {
                        return new MethodInvocation.Static (
                                fullClass,
                                "make",
                                new JavaExpression[]{SCJavaDefn.EXECUTION_CONTEXT_VAR},
                                new JavaTypeName[]{JavaTypeNames.RTEXECUTION_CONTEXT},
                                JavaTypeNames.RTFUNCTION);
                    } else {
                        int functionIndex = fgi.getFunctionIndex(qualName.getUnqualifiedName());
                        return new MethodInvocation.Static (
                                fullClass,
                                "make",
                                new JavaExpression[]{LiteralWrapper.make(Integer.valueOf(functionIndex)), SCJavaDefn.EXECUTION_CONTEXT_VAR},
                                new JavaTypeName[]{JavaTypeName.INT, JavaTypeNames.RTEXECUTION_CONTEXT},
                                JavaTypeNames.RTFUNCTION);
                    }
                }


                // If this is a self reference or a reference to a function
                // in the same function group use the '$instance....' member.
                if (fullClass.equals (thisTypeName)) {
                    return new JavaField.Static(fullClass, CALToJavaNames.getInstanceFieldName(qualName, module), thisTypeName);
                }

                // Use the static 'instance' field in the class for the referenced function.
                return new JavaField.Static(fullClass, CALToJavaNames.getInstanceFieldName(qualName, module), fullClass);
View Full Code Here

     */
    private void addExceptionHandler(Class<?> exceptionClass) {
        // Generate a Block corresponding to:
        // throw new RTForeignFunctionException(RTValue.generateForeignFunctionErrorMessage(exception, generatedClassName, supercombinatorName), null, exception);

        JavaTypeName exceptionType = JavaTypeName.make(exceptionClass);
        JavaExpression args[] = new JavaExpression [4];
        JavaTypeName argTypes[] = new JavaTypeName [4];
        args[0] = new LocalVariable("caught_exception" , exceptionType);
        argTypes[0] = JavaTypeName.THROWABLE;
        args[1] = LiteralWrapper.make(CALToJavaNames.createFullClassNameFromSC(getQualifiedName(), module));
        argTypes[1] = JavaTypeName.STRING;
        args[2] = LiteralWrapper.make(currentModuleName.toSourceText());
        argTypes[2] = JavaTypeName.STRING;
        args[3] = LiteralWrapper.make(getFunctionName());
        argTypes[3] = JavaTypeName.STRING;
        MethodInvocation genMessage = new MethodInvocation.Static (JavaTypeNames.RTVALUE,
                                                            "generateForeignFunctionErrorMessage",
                                                            args,
                                                            argTypes,
                                                            argTypes[1]);

        JavaExpression constructorArgs[] = new JavaExpression [2];
        JavaTypeName constructorArgTypes[] = new JavaTypeName [2];
        constructorArgs[0] = genMessage;
        constructorArgTypes[0] = JavaTypeName.STRING;
        constructorArgs[1] = new LocalVariable("caught_exception", exceptionType);
        constructorArgTypes[1] = JavaTypeName.THROWABLE;
        ClassInstanceCreationExpression nc =
View Full Code Here

TOP

Related Classes of org.openquark.cal.internal.javamodel.JavaTypeName

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.