Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.TypeExpr


        if (scheme == Scheme.UNBOX_INTERNAL_SCHEME && !canTypeBeUnboxed(mf.getResultType())) {
            return null;
        }

        boolean calledArgStrictness[] = mf.getParameterStrictness();
        TypeExpr calledArgTypes[] = mf.getParameterTypes();

        // First generate the java expressions for the argument CAL expressions.
        ExpressionContextPair[] ecp = new ExpressionContextPair[chain.length-1];
        for (int i = 1; i < chain.length; ++i) {
            if (calledArgStrictness[i-1]) {
View Full Code Here


        // value.
        // Assuming of course that the expected unboxed type is compatible with
        // the type of the field.
        DataConstructor dc = dcs.getDataConstructor();
        TypeExpr[] fieldTypes = SCJavaDefn.getFieldTypesForDC(dc);
        TypeExpr fieldType = fieldTypes[dcs.getFieldIndex()];

        if (unboxedType == null) {
            // The type of the unboxed value is irrelevent so set it to be the same type as the field.
            if (dc.isArgStrict(dcs.getFieldIndex())) {
                unboxedType = SCJavaDefn.typeExprToTypeName(fieldType);
View Full Code Here

        for (int i = 0, n = typeCons.getNDataConstructors(); i < n; ++i) {
            DataConstructor dc = typeCons.getNthDataConstructor(i);
            TypeExpr[] fieldTypes = SCJavaDefn.getFieldTypesForDC(dc);
            for (int j = 0, k = fieldTypes.length; j < k; ++j) {
                TypeExpr fieldType = fieldTypes[j];
                TypeConsApp fieldTc = fieldType.rootTypeConsApp();
                if (fieldTc != null &&
                    (typeConsApp.sameType(fieldTc) || fieldTc.getRoot().equals(typeCons))) {
                    return true;
                }
            }
View Full Code Here

     */
    @Override
    protected List<ValueNode> getValueList() {

        // Add values to the list.
        TypeExpr typeExpr = getValueNode().getTypeExpr();
        QualifiedName typeConstructorName = ((TypeConsApp)typeExpr).getName();
        DataConstructor[] dcList = valueEditorManager.getPerspective().getDataConstructorsForType(typeConstructorName);

        List<ValueNode> valueList = new ArrayList<ValueNode>();
        for (final DataConstructor dataConstructor : dcList) {
View Full Code Here

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

                        // Get this alternative's variables.  These have to be added to the active list of scope variables
                        TypeExpr fieldTypes[] = SCJavaDefn.getFieldTypesForDC(firstDC);
                        for (final AltVarIndexPair altVarIndexPair : getAltVarIndexList(alt, firstDC)) {

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

                            QualifiedName qn = QualifiedName.make(currentModuleName, altVar);
                            VarInfo.DCMember vi = variableContext.addDCField(qn, fieldTypes[fieldIndex]);

                            boolean fieldIsStrict =
                                !LECCMachineConfiguration.IGNORE_STRICTNESS_ANNOTATIONS;

                            for (final DataConstructor tagDC : group) {
                                fieldIsStrict = fieldIsStrict && tagDC.isArgStrict(fieldIndex);
                            }

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

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

                            // Generate the code defining the variable.
                            if (fieldIsStrict) {
                                if (SCJavaDefn.canTypeBeUnboxed(fieldTypes[fieldIndex])) {
                                    // This is a strict field of a primitive type so has both a boxed and unboxed form.
                                    JavaExpression unboxedInitializer =
                                        new JavaExpression.MethodInvocation.Instance(caseVar,
                                                                                     fieldGetterName + "_As_" + SCJavaDefn.getNameForPrimitive(fieldTypes[fieldIndex]),
                                                                                     SCJavaDefn.typeExprToTypeName(fieldTypes[fieldIndex]),
                                                                                     JavaExpression.MethodInvocation.InvocationType.VIRTUAL);

                                    vi.updateUnboxedVarDef(unboxedInitializer);
                                    JavaExpression localVar = new LocalVariable(vi.getJavaName()+"$U", vi.getUnboxedType());
                                    vi.updateUnboxedReference(localVar);
                                    JavaExpression boxedDef = SCJavaDefn.boxExpression(vi.getUnboxedType(), localVar);
                                    vi.updateStrictReference(boxedDef);
                                    vi.updateLazyReference(boxedDef);
                                } else {
                                    // RTValue altVarName = ((DCClass)caseVar).getFieldn();
                                    JavaExpression initializer = new JavaExpression.MethodInvocation.Instance(caseVar, fieldGetterName, JavaTypeNames.RTVALUE, JavaExpression.MethodInvocation.InvocationType.VIRTUAL);
                                    vi.updateStrictVarDef (initializer);
                                    JavaExpression localVar = new LocalVariable(vi.getJavaName(), JavaTypeNames.RTVALUE);
                                    vi.updateStrictReference(localVar);
                                    vi.updateLazyReference(localVar);
                                }
                            } else {
                                // RTValue altVarName = ((DCClass)caseVar).getFieldn();
                                JavaExpression initializer = new JavaExpression.MethodInvocation.Instance(caseVar, fieldGetterName, JavaTypeNames.RTVALUE, JavaExpression.MethodInvocation.InvocationType.VIRTUAL);
                                vi.updateLazyVarDef (initializer);
                                JavaExpression localVar = new LocalVariable(vi.getJavaName(), JavaTypeNames.RTVALUE);
                                vi.updateLazyReference(localVar);

                                JavaExpression evaluatedVar = SCJavaDefn.createInvocation(localVar, SCJavaDefn.EVALUATE, SCJavaDefn.EXECUTION_CONTEXT_VAR);
                                vi.updateStrictReference(evaluatedVar);
                                if (SCJavaDefn.canTypeBeUnboxed(fieldTypes[fieldIndex])) {
                                    vi.updateUnboxedReference(SCJavaDefn.unboxValue(vi.getUnboxedType(), evaluatedVar));
                                }
                            }
                        }

                        // Compile the actual body of the alternate.
                        JavaStatement altStatement = genS_R(alt.getAltExpr(), variableContext);
                        caseBlock.addStatement(variableContext.popJavaScope());
                        caseBlock.addStatement(altStatement);

                        switchStatement.addCase(new SwitchStatement.IntCaseGroup(caseLabels, caseBlock));
                    }
                } else {
                    // Matching notation for switch alternate.
                    Map<FieldName, String> fieldNameToVarNameMap = ((SwitchAlt.Matching)alt).getFieldNameToVarNameMap();

                    Block caseBlock = new Block();

                    int[] caseLabels = new int[altTags.size()];
                    int index = 0;
                    DataConstructor firstDC = null;
                    // Must be a data constructor tag, since there are field names (see Expression.Switch.SwitchAlt).
                    for (final Object altTag : altTags) {
                        DataConstructor tagDC = (DataConstructor)altTag;
                        if (firstDC == null) {
                            firstDC = tagDC;
                        } else if (tagDC.getOrdinal() < firstDC.getOrdinal()) {
                            firstDC = tagDC;
                        }
                        caseBlock.addStatement(new LineComment(tagDC.getName().getQualifiedName()));
                        caseLabels[index] = tagDC.getOrdinal();
                        index++;
                    }

                    caseBlock.addStatement(new LineComment("Decompose data type to access members."));

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

                    for (int iField = 0; iField < firstDC.getArity(); ++iField) {
                        FieldName fn = firstDC.getNthFieldName(iField);
                        String altVar = fieldNameToVarNameMap.get(fn);
                        if (altVar == null) {
                            continue;
                        }

                        QualifiedName qn = QualifiedName.make(currentModuleName, altVar);
                        TypeExpr fieldType = SCJavaDefn.getFieldTypeForDC(firstDC, fn);

                        VarInfo.DCMember vi = variableContext.addDCField(qn, fieldType);

                        boolean fieldIsStrict = !LECCMachineConfiguration.IGNORE_STRICTNESS_ANNOTATIONS;
                        for (final Object altTag : altTags) {
View Full Code Here

            }

            // 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);
View Full Code Here

            // all arguments are primitive/foreign or an enum data type.
            // This way we know that holding the roots of the arguments can safely be held on the
            // java call stack since none of them can grow and be consumed in an unbounded fashion
            // by the loop in the tail recursive function.
            for (int i = 0, n = calledArgTypes.length; i < n && safeToCallOnJavaStack; ++i) {
                TypeExpr argType = calledArgTypes[i];
                safeToCallOnJavaStack = argType != null &&
                                            (SCJavaDefn.canTypeBeUnboxed(argType) ||
                                             SCJavaDefn.isEnumDataType(argType) ||
                                             !SCJavaDefn.isSelfReferentialDataType(argType));
            }
View Full Code Here

     * @param dc
     * @return an array of TypeExpr
     */
    static TypeExpr[] getFieldTypesForDC (DataConstructor dc) {
        TypeExpr[] fieldTypes = new TypeExpr[dc.getArity()];
        TypeExpr dcType = dc.getTypeExpr();
        TypeExpr[] tft = dcType.getTypePieces(dc.getArity());
        System.arraycopy(tft, 0, fieldTypes, 0, fieldTypes.length);

        return fieldTypes;
    }
View Full Code Here

     * @param fieldName
     * @return the type of the field
     */
    static private TypeExpr getFieldTypeForDC (DataConstructor dc, FieldName fieldName) {
        TypeExpr[] fieldTypes = new TypeExpr[dc.getArity()];
        TypeExpr dcType = dc.getTypeExpr();
        TypeExpr[] tft = dcType.getTypePieces(dc.getArity());
        System.arraycopy(tft, 0, fieldTypes, 0, fieldTypes.length);

        return fieldTypes[dc.getFieldIndex(fieldName)];
    }
View Full Code Here

    /**
     * Adds an item to the list.
     */
    @Override
    public void addRow() {
        TypeExpr typeExpr = listValueNode.getTypeExpr();
      
        TypeExpr elementTypeExpr = ((TypeConsApp) typeExpr).getArg(0);
        ValueNode elementVN = valueEditorManager.getValueNodeBuilderHelper().getValueNodeForTypeExpr(elementTypeExpr);
        listValueNode.add(elementVN);
       
        // The following two lines were commented out in Ken's change.  Why?
        int indexNewRow = listValueNode.getNElements() - 1;
View Full Code Here

TOP

Related Classes of org.openquark.cal.compiler.TypeExpr

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.