Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.TypeExpr


    public String[][] getArgNamesAndTypes(String qualifiedFunctionName) {
        try {          
            MachineFunction mf = program.getCodeLabel(QualifiedName.makeFromCompoundName(qualifiedFunctionName));
            if (mf != null && mf.getArity() > 0) {
                String argNames[] = mf.getParameterNames();
                TypeExpr argTypes[] = mf.getParameterTypes();
                String argTypeStrings[] = new String[argTypes.length];
                for (int i = 0; i < argTypeStrings.length; ++i) {
                    if (argTypes[i] == null) {
                        argTypeStrings[i] = "internal type";
                    } else {
View Full Code Here


        // Get supercombinator defined at the current target and its name
        ModuleTypeInfo currentModuleTypeInfo = getWorkspaceManager().getWorkspace().getMetaModule(getTargetModule()).getTypeInfo();
        AdjunctSource scDef = target.getTargetDef(null, currentModuleTypeInfo);

        CompilerMessageLogger logger = new MessageLogger ();
        TypeExpr targetTypeExpr = getTypeChecker().checkFunction(scDef, targetModule, logger);
       
        if (targetTypeExpr == null) {
            VALUENODE_LOGGER.log(Level.SEVERE, "Error determining gem execution type.  Text: \n" + scDef);
            throw new ProgramCompileException(CompilerMessage.Severity.ERROR, logger.getFirstError());
        }

        // Determine the overall output TypeExpr of the target.
        int numArgs = inputPolicies.length;
        TypeExpr[] targetTypePieces = targetTypeExpr.getTypePieces(numArgs);
                                           
        TypeExpr outputTypeExpr;
        try {
                              
            TypeExpr[] specializedTargetTypePieces =
                TypeExpr.patternMatchPieces(argTypes, targetTypePieces, currentModuleTypeInfo);
            outputTypeExpr = specializedTargetTypePieces[numArgs];  
                                   
        } catch (TypeException e) {
            // What to do?  You really don't want to be throwing an uncaught exception here.
            VALUENODE_LOGGER.log(Level.WARNING, "Error determining gem execution output type.");
            e.printStackTrace();
            outputTypeExpr = targetTypePieces[numArgs];
        }
       
        TypeExpr declaredType = outputTypeExpr;
        for (int i = numArgs - 1; i >= 0 ; i--) {
            declaredType = TypeExpr.makeFunType(argTypes[i], declaredType);
        }

        // Update the scDef with the type declaration.
        scDef = target.getTargetDef(declaredType, currentModuleTypeInfo);

        outputValueNode = valueNodeBuilderHelper.getValueNodeForTypeExpr(outputTypeExpr);
        if (outputValueNode == null) {
            // Unable to create an output value node for type: {declaredType}
            throw new ProgramCompileException(CompilerMessage.Severity.ERROR,
                    new CompilerMessage(new MessageKind.Error.UnableToCreateOutputValueNode(declaredType.toString())));
        }
       
        OutputPolicy outputPolicy = null;
        outputPolicy = outputValueNode.getOutputPolicy();
        if (outputPolicy == null) {
            // Unable to retrieve an output policy for type: {declaredType}
            throw new ProgramCompileException(CompilerMessage.Severity.ERROR,
                    new CompilerMessage(new MessageKind.Error.UnableToRetrieveAnOutputPolicy(declaredType.toString())));
        }

        if (getShowConsoleInfo()) {
            System.out.println("Executing:\n" + scDef);
        }
View Full Code Here

        List<ValueNode> newChildrenList = new ArrayList<ValueNode>(childrenCount);

        for (int i = 0; i < childrenCount; i++) {

            ValueNode childVN = childrenList.get(i);
            TypeExpr elementTypeExpr = TypeExpr.getComponentTypeExpr(newTypeExpr, i, dataConstructor);
            newChildrenList.add(childVN.copyValueNode(elementTypeExpr));
        }

        DataConstructorValueNode dvn =  new DataConstructorValueNode(newChildrenList, getDataConstructor(), newTypeExpr);
        dvn.setOutputJavaValue(outputValue);
View Full Code Here

   
            // Go thru the component ValueNodes and transmute them.
            for (int i = 0, componentCount = componentList.size(); i < componentCount; i++) {

                ValueNode componentVN = componentList.get(i);
                TypeExpr componentTypeExpr = TypeExpr.getComponentTypeExpr(newTypeExpr, i, dataConstructor);
                newComponentList.add(componentVN.transmuteValueNode(valueNodeBuilderHelper, valueNodeTransformer, componentTypeExpr));
            }

            ValueNode newValueNode = valueNodeBuilderHelper.buildValueNode(newComponentList, dataConstructor, newTypeExpr);
            return newValueNode;
View Full Code Here

     * @param value - the java value
     */
    @Override
    public void setOutputJavaValue(Object value) {
       
        TypeExpr typeExpr = getTypeExpr();
       
        // We only restrict the value that can be set if it is one of the small number of types we know about.
        if (typeExpr.hasRootTypeConstructor(CAL_Prelude.TypeConstructors.Maybe) ||
            typeExpr.hasRootTypeConstructor(CAL_Prelude.TypeConstructors.Either) ||
            typeExpr.hasRootTypeConstructor(CAL_Prelude.TypeConstructors.Ordering) ||
            typeExpr.hasRootTypeConstructor(CAL_Prelude.TypeConstructors.Unit)) {
           
            if (value instanceof AlgebraicValue ||
                value instanceof MaybeValue ||
                value instanceof EitherValue ||
                value instanceof UnitValue ||
View Full Code Here

                        // Construct child value nodes for the arguments.
                        ValueNode[] childValueNodes = new ValueNode[arity];
                   
                        for (int i = 0 ; i < arity; i++) {
                       
                            TypeExpr argType = TypeExpr.getComponentTypeExpr(typeExpr, i, dataConstructor);
   
                            childValueNodes[i] = getValueNodeBuilderHelper().getValueNodeForTypeExpr(argType)
                       
                            if (childValueNodes[i] == null) {
                           
View Full Code Here

     * @return SourceModel.Expr
     */
    @Override
    public SourceModel.Expr getCALSourceModel() {

        TypeExpr typeExpr = getTypeExpr();

        if (typeExpr.isNonParametricType(CAL_Prelude.TypeConstructors.Boolean)) {
                       
            return SourceModel.Expr.makeBooleanValue(getBooleanValue().booleanValue());
          
        } else if (typeExpr.isNonParametricType(CAL_Prelude.TypeConstructors.Char)) {
           
            return SourceModel.Expr.Literal.Char.make(getValue().toString().charAt(0));          
           
        } else if (typeExpr.isNonParametricType(CAL_Prelude.TypeConstructors.Byte)) {
           
            return SourceModel.Expr.makeByteValue(((Byte)getValue()).byteValue());
           
        } else if (typeExpr.isNonParametricType(CAL_Prelude.TypeConstructors.Short)) {
           
            return SourceModel.Expr.makeShortValue(((Short)getValue()).shortValue());
                                       
        } else if (typeExpr.isNonParametricType(CAL_Prelude.TypeConstructors.Int)) {

            // TEMP: For now, we need to do this to ensure that the value is being interpreted as an Int and not Num.
            return SourceModel.Expr.makeIntValue(((Integer)getValue()).intValue());
           
        } else if (typeExpr.isNonParametricType(CAL_Prelude.TypeConstructors.Long)) {
           
            // TEMP: For now, we need to do this to ensure that the value is being interpreted as an Long and not Num.           
            return SourceModel.Expr.makeLongValue(((Long)getValue()).longValue());
           
        } else if (typeExpr.isNonParametricType(CAL_Prelude.TypeConstructors.Float)) {
           
            return SourceModel.Expr.makeFloatValue(((Float)getValue()).floatValue());
                              
        } else if (typeExpr.isNonParametricType(CAL_Prelude.TypeConstructors.Double)) {
      
            return SourceModel.Expr.makeDoubleValue(getDoubleValue().doubleValue());
              
        } else if (typeExpr.isNonParametricType(CAL_Prelude.TypeConstructors.String)) {
           
            return SourceModel.Expr.makeStringValue(getValue().toString())
                     
        } else if (typeExpr.isNonParametricType(CAL_Prelude.TypeConstructors.Integer)) {
           
            return SourceModel.Expr.makeIntegerValue((BigInteger)getValue());
           
        } else if (typeExpr.isNonParametricType(CAL_Prelude.TypeConstructors.Decimal)) {
            return CAL_Prelude.Functions.stringToDecimal(getValue().toString());
           
        } else {
           
            throw new IllegalStateException("invalid type for a literal value");
View Full Code Here

    @Override
    public String getTextValue() {

        String textValue = null;
       
        TypeExpr typeExpr = getTypeExpr();
      
        if (typeExpr.isNonParametricType(CAL_Prelude.TypeConstructors.Boolean)) {
            textValue = getBooleanValue().booleanValue() ? "True" : "False";
                      
        } else if (typeExpr.isNonParametricType(CAL_Prelude.TypeConstructors.String)) {
            // Will need to get rid of the carriage returns (since they will not be nicely displayed).
            textValue = getStringValue().replace('\n', ListOfCharValueNode.CHAR_RETURN_REPLACE);
             
        } else {         
View Full Code Here

         *
         * @param dc
         * @return QualifiedName of the make function, null if none found.
         */
        private QualifiedName findMakeDCName (DataConstructor dc) {
            TypeExpr dcTypeExpr = dc.getTypeExpr();
            String probableFunctionName = "make" + dc.getName().getUnqualifiedName();

            for (int i = 0; i < module.getNFunctions(); ++i) {
                Function function = module.getNthFunction(i);
                if (function.getName().getUnqualifiedName().equals(probableFunctionName)) {
                    if (dcTypeExpr.sameType(function.getTypeExpr())) {
                        return QualifiedName.make(module.getModuleName(), probableFunctionName);
                    }
                }
            }
           
View Full Code Here

                SourceModel.Expr argValue = Expr.SelectDataConsField.make(dcVar, dataConsSourceModelName, SourceModel.Name.Field.make(fn));
               
                // If the type of the dc field matches the type of the constructor argument
                // we can simply use the field accessor.  Otherwise we need to apply output to
                // resulting value.
                TypeExpr fieldTypeExpr = dcFieldTypeExprs[i];
                updateInputableImports(fieldTypeExpr);
                String dcFieldTypeConsName = "";
                TypeConsApp typeConsApp = fieldTypeExpr.rootTypeConsApp();
                if (typeConsApp != null) {
                    TypeConstructor tc = typeConsApp.getRoot();
                    dcFieldTypeConsName = tc.getName().toString();
                }
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.