Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.DataConstructor


            returnType = JavaTypeName.STRING;
            javaMethod = new JavaMethod(modifiers, returnType, "getUnqualifiedName");
            tagDCClassRep.addMethod(javaMethod);
            SwitchStatement sw = new SwitchStatement (new JavaField.Instance(null, "tag", JavaTypeName.INT));
            for (int i = 0, nDCs = dataConsList.size(); i < nDCs; ++i) {
                DataConstructor dc = dataConsList.get (i);
                sw.addCase(new SwitchStatement.IntCaseGroup(dc.getOrdinal(), new ReturnStatement (LiteralWrapper.make(dc.getName().getUnqualifiedName()))));
            }
            javaMethod.addStatement (sw);
            javaMethod.addStatement(new ReturnStatement(LiteralWrapper.make ("Unknown data constructor")));

            // public final String getQualfiedName() ...
            modifiers = Modifier.PUBLIC | Modifier.FINAL;
            returnType = JavaTypeName.STRING;
            javaMethod = new JavaMethod(modifiers, returnType, "getQualifiedName");
            tagDCClassRep.addMethod(javaMethod);
            sw = new SwitchStatement (new JavaField.Instance(null, "tag", JavaTypeName.INT));
            for (int i = 0, nDCs = dataConsList.size(); i < nDCs; ++i) {
                DataConstructor dc = dataConsList.get (i);
                sw.addCase(new SwitchStatement.IntCaseGroup(dc.getOrdinal(), new ReturnStatement (LiteralWrapper.make(dc.getName().getQualifiedName()))));
            }
            javaMethod.addStatement (sw);
            javaMethod.addStatement(new ReturnStatement(LiteralWrapper.make ("Unknown data constructor")));

            return tagDCClassRep;
View Full Code Here


            //  e.g. RTFunction i_Foo;
            if (sharedValues.getNReferencedDCs() > 0) {
                javaClassRep.addComment(new JavaStatement.MultiLineComment("Data constructor class instances for all referenced data constructors."));
            }
            for (final ReferencedDCInfo rfi : sharedValues.getReferencedDCs()) {
                DataConstructor dc = rfi.getDC();
                JavaField jf = rfi.getJField();
                JavaExpression fieldInitializer;
                if (dc.getArity() > 0) {
                    // Just invoke the regular make invocation to get the singleton SC/DC instance.
                    fieldInitializer =
                        new MethodInvocation.Static(jf.getFieldType(), "make", JavaExpression.EMPTY_JAVA_EXPRESSION_ARRAY, JavaExpression.EMPTY_TYPE_NAME_ARRAY, jf.getFieldType());
                } else {
                    // This is a zero arity data constructor.  We get the singleton instance by accessing
                    // the DataType class factory method if the data type has more than one zero arity DC.
                    TypeConstructor typeCons = dc.getTypeConstructor();
                    if (SCJavaDefn.isTagDC(dc, module)) {
                        JavaTypeName typeClass = CALToJavaNames.createTypeNameFromType(typeCons, module);
                        JavaTypeName tagDCTypeName = CALToJavaNames.createTypeNameForTagDCFromType(typeCons, module);
                        Integer ordinal = Integer.valueOf(dc.getOrdinal());
                        fieldInitializer = new MethodInvocation.Static(typeClass, "getTagDC", LiteralWrapper.make(ordinal), JavaTypeName.INT, tagDCTypeName);
                    } else {
                        // Just invoke the regular make invocation to get the singleton SC/DC instance.
                        fieldInitializer =
                            new MethodInvocation.Static(jf.getFieldType(), "make", JavaExpression.EMPTY_JAVA_EXPRESSION_ARRAY, JavaExpression.EMPTY_TYPE_NAME_ARRAY, jf.getFieldType());
View Full Code Here

            return ERROR_ALREADY_STORED;
        }
       
        // Check if specified value is not already a constructor
       
        DataConstructor constr =
            perspective.getWorkingModuleTypeInfo().getDataConstructor(valueName);       
        if (constr == null) {
            return ERROR_NONE;
        }
       
        QualifiedName typeName = constr.getTypeConstructor().getName();
        if (!typeName.getUnqualifiedName().equals( ((JTextField)gemNameField.getEditor().getEditorComponent()).getText() )) {
           
            String statusMessage = "<html><body>"+
                GeneratorMessages.getString("ETGF_ExistingConstructorFor")+
                typeName.getUnqualifiedName()+
View Full Code Here

     * @return full class name
     */
    static String createFullClassNameFromDC (QualifiedName dcName, LECCModule module) {
        // Determine whether this DC is going to be in a shared class.
        module = (LECCModule)module.findModule(dcName.getModuleName());
        DataConstructor dc = module.getModuleTypeInfo().getDataConstructor(dcName.getUnqualifiedName());
        return createFullClassNameFromDC(dc, module);
    }
View Full Code Here

        if (machineFunction.isDataConstructor()) {
           
            // this is a DataConstructor
            className = CALToJavaNames.createFullClassNameFromDC(
                    entryPointSCName, startModule);
            DataConstructor dc = startModule.getModuleTypeInfo().getDataConstructor(
                    entryPointSCName.getUnqualifiedName());

            if (LECCMachineConfiguration.TREAT_ENUMS_AS_INTS && TypeExpr.isEnumType(dc.getTypeConstructor())) {
                // an enum data cons treated as an int - we should just return the boxed ordinal
                return RTData.CAL_Int.make(dc.getOrdinal());
               
            } else {
                if (className.endsWith("$TagDC")) {
                    if (entryPointSCName.equals(CAL_Prelude.DataConstructors.True)) {
                        return RTData.CAL_Boolean.TRUE;
                    } else if (entryPointSCName
                            .equals(CAL_Prelude.DataConstructors.False)) {
                        return RTData.CAL_Boolean.FALSE;
                    } else {
                        className = className.substring(0, className.length() - 6);
                        startPoint = loader.getTagDCStartPointInstance(className,
                            dc.getOrdinal());
                    }
                } else {
                    startPoint = loader.getStartPointInstance(className, machineFunction, executionContext);
                }
            }
View Full Code Here

                // This can either be a supercombinator or a data declaration
                if (label.getExpressionForm().asPackCons() != null) {
                    // This is a data declaration
                    // Add the associated TypeConstructor to the set for later code generation.
                    DataConstructor dc = label.getExpressionForm().asPackCons().getDataConstructor();
                    TypeConstructor typeCons = dc.getTypeConstructor();
                    typeConsSet.add(typeCons);
                } else {
                    // This is a supercombinator.  Emit the definition if necessary.
                    try {
                        LECCModule.FunctionGroupInfo fgi = module.getFunctionGroupInfo(label);
View Full Code Here

           
            if (!returnType.getExposedTypeName().equals(JavaTypeName.CAL_VALUE)) {
                throw new IllegalStateException("The return type " + returnType.getExposedTypeName() + " is not the expected " + JavaTypeName.CAL_VALUE);
            }
           
            final DataConstructor dc = (DataConstructor)functionalAgent;
            isLiteralResult = true;
            resultExpr = makeRTValueMarshallingExpr(ClassTypeInfo.make(int.class), JavaExpression.LiteralWrapper.make(Integer.valueOf(dc.getOrdinal())));
           
        } else {
            isLiteralResult = false;
            resultExpr =
                makeEvaluateInvocationExpr(
View Full Code Here

        if (actualMachineFunction.isDataConstructor()) {
   
            // this is a DataConstructor
            final String className = CALToJavaNames.createFullClassNameFromDC(entryPointSCName, startModule);
           
            final DataConstructor dc = startModule.getModuleTypeInfo().getDataConstructor(entryPointSCName.getUnqualifiedName());
   
            if (isEnumDataConsRepresentedAsPrimitiveInt(dc)) {
                // an enum data cons treated as an int - we should just return the boxed ordinal
                return makeRTValueMarshallingExpr(ClassTypeInfo.make(int.class), JavaExpression.LiteralWrapper.make(Integer.valueOf(dc.getOrdinal())));
               
            } else {
                if (className.endsWith("$TagDC")) {
                    if (entryPointSCName.equals(CAL_Prelude.DataConstructors.True)) {
                        return new JavaExpression.JavaField.Static(JavaTypeNames.RTDATA_BOOLEAN, "TRUE", JavaTypeNames.RTDATA_BOOLEAN);

                    } else if (entryPointSCName.equals(CAL_Prelude.DataConstructors.False)) {
                        return new JavaExpression.JavaField.Static(JavaTypeNames.RTDATA_BOOLEAN, "FALSE", JavaTypeNames.RTDATA_BOOLEAN);

                    } else {
                        final String outerClassName = className.substring(0, className.length() - 6);
                        return StandaloneJarBuilder.getTagDCStartPointInstanceJavaExpression(outerClassName, dc.getOrdinal());
                    }
                } else {
                    return getStartPointInstanceJavaExpression(className, startModule, actualMachineFunction, executionContextExpr);
                }
            }
View Full Code Here

        } else {

            buffer.append("<tt>");
                      
            for (int i = 0; i < count; i++) {
                DataConstructor dataCons = typeCons.getNthDataConstructor(i);
                NavAddress dataConsUrl = NavAddress.getAddress(dataCons);
                String dataConsLink = getLinkHtml(dataConsUrl, NavAddressHelper.getDisplayText(owner, dataConsUrl, ScopedEntityNamingPolicy.UNQUALIFIED));
                buffer.append("<b>" + dataConsLink + "</b> :: ");
                buffer.append("<i>" + getTypeStringHtml(owner, dataCons.getTypeExpr(), namingPolicy) + "</i>");
                buffer.append("<br>");
            }
           
            // remove trailing <br>
            buffer.delete(buffer.length() - 4, buffer.length());
View Full Code Here

TOP

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

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.