Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.FieldName


                hashCodeFieldDecl.setJavaDoc(new JavaDocComment("Lazily initialized, cached hashCode."));
               
                dcClass.addFieldDeclaration(hashCodeFieldDecl);

                for (int i = 0, n = dc.getArity(); i < n; ++i) {
                    FieldName fieldName = dc.getNthFieldName(i);
                    if (typeConstructorInfo.commonFieldNames.contains(fieldName)) {
                        continue;
                    }
                   
                    JavaTypeName type = (JavaTypeName)dci.fieldTypeNames.get(fieldName);
View Full Code Here


            }

            // Now push the values for the bound fields onto the stack.
            for (final Map.Entry<FieldName, String> entry : fieldBindingVarMap.entrySet()) {

                FieldName fieldName = entry.getKey();
                String bindingVarName = entry.getValue();

                //ignore anonymous pattern variables. These are guaranteed not to be used
                //by the result expression, and so don't need to be extracted from the condition record.
                if (!bindingVarName.equals(Expression.RecordCase.WILDCARD_VAR)) {

                    QualifiedName qn = QualifiedName.make(currentMachineFunction.getQualifiedName().getModuleName(), bindingVarName);
                    newEnv.put(qn, Integer.valueOf(++d));

                    gp.code (new Instruction.I_Push (recordPos));
                    gp.code (new Instruction.I_RecordSelection (fieldName.getCalSourceForm()));
                    recordPos++;
                }
            }

            //encode the result expression in the context of the extended variable scope.
View Full Code Here

            // Create a new record that is a copy of the base record.
            gp.code(new Instruction.I_ExtendRecord());          

            // Put the field values into the new record instance.
            for (final Map.Entry<FieldName, Expression> entry : updateFieldValuesMap.entrySet()) {              
                FieldName fieldName = entry.getKey();
                Expression valueExpr = entry.getValue();
                gp.code (schemeC (valueExpr, p, d+1));
                gp.code (new Instruction.I_PutRecordField(fieldName.getCalSourceForm()));
            }

            return gp;
        }         

        // Is e a record extension
        Expression.RecordExtension recordExtensionExpr = e.asRecordExtension();
        if (recordExtensionExpr != null) {
            if (CODEGEN_DIAG) {
                MACHINE_LOGGER.log(Level.FINE, "    Record extension:");
            }

            Expression baseRecordExpr = recordExtensionExpr.getBaseRecordExpr();

            //FieldName -> Expression
            Map<FieldName, Expression> extensionFieldsMap = recordExtensionExpr.getExtensionFieldsMap();

            if (baseRecordExpr == null) {
                // No base record so create a new one.
                gp.code(new Instruction.I_CreateRecord(extensionFieldsMap.size()));      
            } else {
                // Strictly evaluate the base record.
                gp.code(schemeE (baseRecordExpr, p, d));

                // Create a new record that is a copy of the base record.
                gp.code(new Instruction.I_ExtendRecord());
            }

            // Put the field values into the new record instance.
            for (final Map.Entry<FieldName, Expression> entry : extensionFieldsMap.entrySet()) {             
                FieldName fieldName = entry.getKey();
                Expression valueExpr = entry.getValue();
                gp.code (schemeC (valueExpr, p, d+1));
                gp.code (new Instruction.I_PutRecordField(fieldName.getCalSourceForm()));
            }

            return gp;
       
View Full Code Here

            // Add field values.  In the case of extending an existing record these are
            // added to the record extension node as if they were further arguments in
            // the application chain for the virtual function.
            for (final Map.Entry<FieldName, Expression> entry : updateFieldValuesMap.entrySet()) {            
                FieldName fieldName = entry.getKey();
                Expression valueExpr = entry.getValue();
                gp.code (schemeC (valueExpr, p, d+1));
                gp.code (new Instruction.I_PutRecordField(fieldName.getCalSourceForm()));
            }

            return gp;           
        }

        // Is e a record extension
        // e is a record extension
        Expression.RecordExtension recordExtensionExpr = e.asRecordExtension();
        if (recordExtensionExpr != null) {
            if (CODEGEN_DIAG) {
                MACHINE_LOGGER.log(Level.FINE, "    Record extension:");
            }

            Expression baseRecordExpr = recordExtensionExpr.getBaseRecordExpr();

            //FieldName -> Expression
            Map<FieldName, Expression> extensionFieldsMap = recordExtensionExpr.getExtensionFieldsMap();

            if (baseRecordExpr == null) {
                // No base record so we create a new one.
                gp.code(new Instruction.I_CreateRecord(extensionFieldsMap.size()));      
            } else {
                // Lazy evaluation of the base record.
                gp.code(schemeC (baseRecordExpr, p, d));

                // Create an application of the virtual extension function to the base record.
                gp.code(new Instruction.I_LazyRecordExtension());
            }

            // Add field values.  In the case of extending an existing record these are
            // added to the record extension node as if they were further arguments in
            // the application chain for the virtual function.
            for (final Map.Entry<FieldName, Expression> entry : extensionFieldsMap.entrySet()) {                
                FieldName fieldName = entry.getKey();
                Expression valueExpr = entry.getValue();
                gp.code (schemeC (valueExpr, p, d+1));
                gp.code (new Instruction.I_PutRecordField(fieldName.getCalSourceForm()));
            }

            return gp;
       
View Full Code Here

                }
            } else {
                // Must be matching.
                Map<FieldName, String> fieldNameToVarNameMap = ((Expression.Switch.SwitchAlt.Matching)alt).getFieldNameToVarNameMap();
                for (final Map.Entry<FieldName, String> entry : fieldNameToVarNameMap.entrySet()) {                  
                    FieldName fieldName = entry.getKey();
                    String varName = entry.getValue();

                    int fieldIndex = dataCons.getFieldIndex(fieldName);
                    vars[fieldIndex] = varName;
                }
View Full Code Here

        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;
                if (fieldN == 0) {
                    // If there are only ordinal field updates we call updateOrdinalField to generate
                    // the record copy.  Otherwise we call updateMixedOrdinalField, so that it is
                    // safe to modify the textual fields of the copy.
                    if (fieldValueData.getNTextualFields() == 0) {
                        updateMethodName = "updateOrdinalField";
                    } else {
                        updateMethodName = "updateMixedOrdinalField";
                    }
                } else {
                    updateMethodName = "mutateOrdinalField";
                }

                int ordinal = ((FieldName.Ordinal)fieldName).getOrdinal();
                invocationTarget =
                   new MethodInvocation.Instance(
                       invocationTarget,
                       updateMethodName,
                       new JavaExpression[] {
                           LiteralWrapper.make(Integer.valueOf(ordinal)),
                           javaUpdateExpr},
                       new JavaTypeName[] {JavaTypeName.INT, JavaTypeNames.RTVALUE},
                       JavaTypeNames.RTRECORD_VALUE,
                       InvocationType.VIRTUAL);

            } else if (fieldName instanceof FieldName.Textual) {

                //we need to copy the base record only for the first update. Subsequent updates can just mutate the base.
                String updateMethodName;
                if (fieldN == 0) {
                    updateMethodName = "updateTextualField";
                } else {
                    updateMethodName = "mutateTextualField";
                }

                String textualFieldName = fieldName.getCalSourceForm();
                invocationTarget =
                   new MethodInvocation.Instance(
                       invocationTarget,
                       updateMethodName,
                       new JavaExpression[] {
View Full Code Here

        //((RTRecordValue) (codeForRecordExpr.evaluate($ec))).getOrdinalFieldValue(ordinal)
        //for textual fields
        //((RTRecordValue) (codeForRecordExpr.evaluate($ec))).getTextualFieldValue(textualFieldName)

        Expression recordExpr = recordSelectionExpr.getRecordExpr();
        FieldName fieldName = recordSelectionExpr.getFieldName();


        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;
        if (fieldName instanceof FieldName.Textual) {
            getValueInvocation = new MethodInvocation.Instance(javaRecordExpr, "getTextualFieldValue",
                LiteralWrapper.make(fieldName.getCalSourceForm()), JavaTypeName.STRING,
                JavaTypeNames.RTVALUE, InvocationType.VIRTUAL);
        } else {
            int ordinal = ((FieldName.Ordinal)fieldName).getOrdinal();
            getValueInvocation = new MethodInvocation.Instance(javaRecordExpr, "getOrdinalFieldValue",
                LiteralWrapper.make(Integer.valueOf(ordinal)), JavaTypeName.INT,
View Full Code Here

        // WHNF.
        if (canIgnoreLaziness(recordExpr, variableContext)) {
            return generateStrictRecordSelection(recordSelectionExpr, false, variableContext);
        }

        FieldName fieldName = recordSelectionExpr.getFieldName();

        ExpressionContextPair recordExprContextPair = genS_C(recordExpr, variableContext);

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

        JavaExpression createLazyRecordSelection;
        if (fieldName instanceof FieldName.Textual) {

            createLazyRecordSelection = new ClassInstanceCreationExpression(JavaTypeNames.RTRECORD_SELECTION_TEXTUAL_FIELD,
                new JavaExpression[] {javaRecordExpr, LiteralWrapper.make(fieldName.getCalSourceForm())},
                new JavaTypeName[] {JavaTypeNames.RTVALUE, JavaTypeName.STRING});

        } else {

            int ordinal = ((FieldName.Ordinal)fieldName).getOrdinal();
View Full Code Here

            recordCaseBlock.addStatement(extractBaseRecordDeclaration);
        }

        for (final Map.Entry<FieldName, String> entry : fieldBindingVarMap.entrySet()) {

            FieldName fieldName = entry.getKey();
            String bindingVarName = entry.getValue();

            //ignore anonymous pattern variables. These are guaranteed not to be used
            //by the result expression, and so don't need to be extracted from the condition record.
            if (!bindingVarName.equals(Expression.RecordCase.WILDCARD_VAR)) {

                QualifiedName qn = QualifiedName.make(currentModuleName, bindingVarName);
                VarInfo.RecordField varInfo = variableContext.addRecordField(qn, null);
                String javaBindingVarName = varInfo.getJavaName();
                LocalName lazyRef = new LocalName(varInfo.getJavaName(), JavaTypeNames.RTVALUE);
                varInfo.updateLazyReference(lazyRef);
                varInfo.updateStrictReference(SCJavaDefn.createInvocation(lazyRef, SCJavaDefn.EVALUATE, SCJavaDefn.EXECUTION_CONTEXT_VAR));

                LocalVariable bindingVar = new LocalVariable(javaBindingVarName, JavaTypeNames.RTVALUE);

                JavaExpression javaExtractValueExpr;
                if (fieldName instanceof FieldName.Textual) {
                    //javaBindingVarName = $recordCase.getTextualFieldValue(fieldName);
                    javaExtractValueExpr = new MethodInvocation.Instance(conditionVar, "getTextualFieldValue",
                        LiteralWrapper.make(fieldName.getCalSourceForm()), JavaTypeName.STRING,
                        JavaTypeNames.RTVALUE, InvocationType.VIRTUAL);
                } else {
                    int ordinal = ((FieldName.Ordinal)fieldName).getOrdinal();
                    javaExtractValueExpr = new MethodInvocation.Instance(conditionVar, "getOrdinalFieldValue",
                        LiteralWrapper.make(Integer.valueOf(ordinal)), JavaTypeName.INT,
View Full Code Here

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

TOP

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

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.