Package org.openquark.cal.internal.javamodel.JavaExpression

Examples of org.openquark.cal.internal.javamodel.JavaExpression.JavaField


            //    }
            //}

            JavaMethod method = new JavaMethod (Modifier.PUBLIC | Modifier.FINAL, JavaTypeName.STRING, "debug_getNodeEndText");

            JavaField resultField = new JavaField.Instance(null, "result", JavaTypeNames.RTVALUE);
            JavaExpression conditionExpr =
                new JavaExpression.OperatorExpression.Binary(
                    JavaOperator.NOT_EQUALS_OBJECT,
                    resultField,
                    LiteralWrapper.NULL)
View Full Code Here


            {
                //    if (result != null) {
                //        return super.debug_getChildPrefixText(childN);
                //    }

                JavaField resultField = new JavaField.Instance(null, "result", JavaTypeNames.RTVALUE);
                JavaExpression conditionExpr =
                    new OperatorExpression.Binary(
                        JavaOperator.NOT_EQUALS_OBJECT,
                        resultField,
                        LiteralWrapper.NULL)
View Full Code Here

            javaMethod.addThrows(JavaTypeName.CAL_EXECUTOR_EXCEPTION);

            // If we are doing a sanity check on let variable behaviour we
            // want to check/set the flag associated with this method.
            if (LECCMachineConfiguration.SANITY_CHECK_LET_VARS) {
                JavaField flag = new JavaField.Instance(null, CALToJavaNames.cleanSCName(javaDefn.getFunctionName()) + "_flag_", JavaTypeName.BOOLEAN);
                JavaExpression exception =
                    new JavaExpression.ClassInstanceCreationExpression(
                            JavaTypeName.NULL_POINTER_EXCEPTION,
                            LiteralWrapper.make("Double evaluation of " + javaDefn.getModuleName() + "." + CALToJavaNames.cleanSCName(javaDefn.getFunctionName()) + " in " + functions.getFunctionGroupName()),
                            JavaTypeName.STRING);
View Full Code Here

            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());
                    }
                }

                JavaFieldDeclaration dcDeclaration =
                    new JavaFieldDeclaration(
                            referencedDCModifiers,
                            jf.getFieldType(),
                            jf.getFieldName(),
                            fieldInitializer);
                javaClassRep.addFieldDeclaration(dcDeclaration);
            }

            if (functions.includesCAFs()) {
View Full Code Here

                if (!mf.isCAF()) {
                    continue;
                }
                String mapPrefix = functions.getFNamePrefix(mf.getName());

                JavaField instanceField = new JavaField.Static(className, mapPrefix+"$instancesMap", JavaTypeName.MAP);
                MethodInvocation remove = new MethodInvocation.Instance (instanceField,
                                                             "remove",
                                                             new JavaExpression[]{SCJavaDefn.EXECUTION_CONTEXT_VAR},
                                                             new JavaTypeName[]{JavaTypeName.OBJECT},
                                                             JavaTypeName.OBJECT,
View Full Code Here

            // A zero arity function is different from a CAF in that we don't cache the 'instance'.
            // Regular functions we just return the singleton supercombinator instance.

            if (functions.getNCAFs() + functions.getNZeroArityFunctions() <= 1) {
                for (final MachineFunction mf : functions.getTopLevelCALFunctions()) {
                    JavaField instanceField = new JavaField.Static(className, CALToJavaNames.getInstanceFieldName(mf.getQualifiedName(), module), className);

                    if (mf.isCAF()) {
                        Block b = new Block();
                        // This is a CAF (constant applicative form) we want to use the cached instance associated
                        // with the execution context, if it exists.
                        // If it doesn't exist we will create an instance and add it to the cache.

                        String instanceMapFieldName = functions.getFNamePrefix(mf.getName()) + "$instancesMap";
                        JavaField instanceMapField =
                            new JavaField.Static(className, instanceMapFieldName, JavaTypeName.MAP);

                        // RTFunction newInstance = (RTFunction)$instancesMap.get($ec);
                        JavaExpression.LocalVariable newInstanceVar =
                            new JavaExpression.LocalVariable("newInstance", returnType);
                        JavaExpression initializer = new JavaExpression.CastExpression(
                                returnType,
                                new MethodInvocation.Instance(
                                        instanceMapField,
                                        "get",
                                        SCJavaDefn.EXECUTION_CONTEXT_VAR,
                                        JavaTypeName.OBJECT,
                                        JavaTypeName.OBJECT,
                                        MethodInvocation.InvocationType.INTERFACE));
                        JavaStatement decl = new JavaStatement.LocalVariableDeclaration(newInstanceVar, initializer);
                        b.addStatement(decl);

                        // If no instance exists for the execution context create one and cache it.

                        // newInstance == null
                        JavaExpression comparison = new JavaExpression.OperatorExpression.Binary(JavaOperator.EQUALS_OBJECT, newInstanceVar, JavaExpression.LiteralWrapper.NULL);

                        // newInstance = new RTFullApp.General_0($instance);
                        // $instancesMap.put($ec, newInstance);
                        JavaStatement.Block then = new JavaStatement.Block();
                        then.addStatement(new ExpressionStatement(new JavaExpression.Assignment(newInstanceVar, new JavaExpression.ClassInstanceCreationExpression(_0TypeName, instanceField, JavaTypeNames.RTSUPERCOMBINATOR))));
                        JavaExpression cacheValue = new MethodInvocation.Instance(
                                instanceMapField,
                                "put",
                                new JavaExpression[] {
                                        SCJavaDefn.EXECUTION_CONTEXT_VAR,
                                        newInstanceVar },
                                new JavaTypeName[] {
                                        JavaTypeName.OBJECT,
                                        JavaTypeName.OBJECT },
                                JavaTypeName.OBJECT,
                                MethodInvocation.InvocationType.INTERFACE);
                        then.addStatement(new ExpressionStatement(cacheValue));

                        // Put the whole if expression together.
                        JavaStatement ifthen = new JavaStatement.IfThenElseStatement(comparison, then);
                        b.addStatement(ifthen);
                        b.addStatement(new ReturnStatement(newInstanceVar));

                        javaMethod.addStatement(b);
                        break;
                    } else if (mf.getArity() == 0) {

                        Block b = new Block();

                        // This is an unsafe method.  i.e. a non-CAF function of arity zero.  Since the
                        // function can have side effects we need to create a new instance of the class
                        // each time so that a previously evaluated value doesn't get re-used in place
                        // of actually executing the function.
                        JavaExpression.LocalVariable newInstanceVar = new JavaExpression.LocalVariable("newInstance", returnType);
                        JavaExpression initializer = new ClassInstanceCreationExpression(_0TypeName, instanceField, JavaTypeNames.RTSUPERCOMBINATOR);
                        JavaStatement decl = new JavaStatement.LocalVariableDeclaration(newInstanceVar, initializer);
                        b.addStatement(decl);
                        b.addStatement(new ReturnStatement(newInstanceVar));

                        javaMethod.addStatement(b);
                        break;
                    }
                }

            } else {
                SwitchStatement switchStatement =
                    new SwitchStatement(new MethodVariable("scIndex"));

                for (final MachineFunction mf : functions.getTopLevelCALFunctions()) {
                    JavaField instanceField = new JavaField.Static(className, CALToJavaNames.getInstanceFieldName(mf.getQualifiedName(), module), className);
                    int functionIndex = functions.getFunctionIndex(mf.getName());
                    if (mf.isCAF()) {

                        Block b = new Block();
                        // This is a CAF (constant applicative form) we want to use the cached instance associated
                        // with the execution context, if it exists.
                        // If it doesn't exist we will create an instance and add it to the cache.

                        String instanceMapFieldName = functions.getFNamePrefix(mf.getName()) + "$instancesMap";
                        JavaField instanceMapField =
                            new JavaField.Static(className, instanceMapFieldName, JavaTypeName.MAP);


                        // RTFunction newInstance = (RTFunction)$instancesMap.get($ec);
                        JavaExpression.LocalVariable newInstanceVar = new JavaExpression.LocalVariable("newInstance", returnType);
View Full Code Here

                javaClassRep.addConstructor(javaConstructor);

                // Now fill in the constructor body.

                // assign the tag field.
                JavaField tagField = new JavaField.Instance(null, SCDefinitionBuilder.functionTagFieldName, JavaTypeName.INT);
                MethodVariable tagArgument = new MethodVariable("scIndex");
                JavaExpression.Assignment tagAssign = new JavaExpression.Assignment(tagField, tagArgument);
                javaConstructor.addStatement(new ExpressionStatement(tagAssign));

                // asign the arity.
View Full Code Here

            JavaMethod javaMethod = new JavaMethod(modifiers, JavaTypeName.INT, "getArity");
            javaClassRep.addMethod(javaMethod);

            // Add the body
            if (functions.getNFunctions() > 1) {
                JavaField arityField = new JavaField.Instance(null, "arity", JavaTypeName.INT);
                javaMethod.addStatement(new ReturnStatement(arityField));
            } else {
                int arity = functions.getTopLevelCALFunctions().iterator().next().getArity();
                javaMethod.addStatement(new ReturnStatement(LiteralWrapper.make(Integer.valueOf(arity))));
            }
View Full Code Here

            JavaClassRep strictAppClassRep = new JavaClassRep(strictAppTypeName, superClassTypeName, classModifiers, interfaces);

            //add the function field, which is a reference to the function singleton.
            JavaFieldDeclaration functionFieldDec = new JavaFieldDeclaration (Modifier.PRIVATE | Modifier.FINAL, className, "function", null);
            strictAppClassRep.addFieldDeclaration(functionFieldDec);
            JavaField functionField = new JavaField.Instance (null, "function", className);

            // This class has a member field for each argument to the SC.
            JavaField[] functionArgumentMemberFields = new JavaField [mf.getArity()];
            for (int i = 0; i < mf.getArity(); ++i) {
                JavaFieldDeclaration fieldDec;
                JavaField field;
                String fieldName = CALToJavaNames.fixupVarName(mf.getParameterNames()[i]);
                if (mf.getParameterStrictness()[i] && SCJavaDefn.canTypeBeUnboxed(mf.getParameterTypes()[i])) {
                    fieldDec = new JavaFieldDeclaration (Modifier.PRIVATE, SCJavaDefn.typeExprToTypeName(mf.getParameterTypes()[i]), fieldName, null);
                    field = new JavaField.Instance (null, fieldName, SCJavaDefn.typeExprToTypeName(mf.getParameterTypes()[i]));
                } else {
View Full Code Here

            //         function.f4S(
            //             RTValue.lastRef(arg1, arg1 = null), ...));
            // }
            // return result;

            final JavaField resultField = new JavaField.Instance(null, "result", JavaTypeNames.RTVALUE);

            OperatorExpression condition = new OperatorExpression.Binary (JavaOperator.EQUALS_OBJECT, resultField, LiteralWrapper.NULL);
            Block then = new Block();

            JavaExpression args[] = new JavaExpression[mf.getArity() + 1];
View Full Code Here

TOP

Related Classes of org.openquark.cal.internal.javamodel.JavaExpression.JavaField

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.