Package org.openquark.cal.internal.javamodel

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


        for (int i = 2; i < length; ++i) {
            newContext.addStatement(ecp[i].getContextBlock());
        }

        // Build the statement to create a new partial application node.
        JavaExpression args[] = new JavaExpression[length];
        JavaTypeName argTypes[] = new JavaTypeName[length];
        Arrays.fill(argTypes, JavaTypeNames.RTVALUE);
        args[0] = expressionVarToJavaDef(chain[0].asVar(), Scheme.E_SCHEME, variableContext);
        argTypes[0] = JavaTypeNames.RTSUPERCOMBINATOR;

        for (int i = 1; i < length; ++i) {
            args[i] = ecp[i].getJavaExpression();
        }

        JavaExpression cci =
            new ClassInstanceCreationExpression(nodeClassName, args, argTypes);

        return new ExpressionContextPair(cci, newContext);
    }
View Full Code Here


        Block newContext = ecp[0].getContextBlock();
        for (int i = 1; i < chain.length; ++i) {
            newContext.addStatement(ecp[i].getContextBlock());
        }

        JavaExpression root = ecp[0].getJavaExpression();

        if (codeGenerationStats != null) {
            if (var.getForeignFunctionInfo() != null) {
                codeGenerationStats.incrementDirectForeignCalls();
            } else {
                codeGenerationStats.incrementDirectSCCalls();
            }
        }

        // Optimize Prelude.not to use the '!' java operator.
        if (var.getName().equals(CAL_Prelude.Functions.not)) {
            JavaExpression not = new JavaExpression.OperatorExpression.Unary(JavaOperator.LOGICAL_NEGATE, ecp[1].getJavaExpression());
            return new ExpressionContextPair (not, newContext);
        }

        // This is a fully saturated supercombinator application
        // for which we can generate a direct call instead of building a suspension.
        JavaExpression args[] = new JavaExpression[calledArity + 1];
        for (int i = 0; i < calledArity; ++i) {
            args[i] = ecp[i + 1].getJavaExpression();
        }
        args[calledArity] = EXECUTION_CONTEXT_VAR;
View Full Code Here

            }
        }

        // This is a fully saturated supercombinator application that can be represented
        // using an special purpose graph node.
        JavaExpression args[] = new JavaExpression[calledArity];
        for (int i = 0; i < calledArity; ++i) {
            args[i] = ecp[i + 1].getJavaExpression();
        }

        JavaExpression scInstance = expressionVarToJavaDef(var, Scheme.C_SCHEME, variableContext);

        JavaExpression constructorArgs[] = new JavaExpression [calledArity + 1];
        constructorArgs[0] = scInstance;
        for (int i = 0; i < args.length; ++i) {
            constructorArgs[i+1] = args[i];
        }
        JavaTypeName constructorArgTypes[] = new JavaTypeName[calledArity + 1];
View Full Code Here

            System.arraycopy(je, 1, args, 0, args.length -1);
            args[args.length-1] = SCJavaDefn.EXECUTION_CONTEXT_VAR;
            JavaTypeName[] argTypes = new JavaTypeName[chain.length];
            Arrays.fill(argTypes, JavaTypeNames.RTVALUE);
            argTypes[argTypes.length-1] = JavaTypeNames.RTEXECUTION_CONTEXT;
            JavaExpression root = je[0];
            MethodInvocation fL = new MethodInvocation.Instance(root, "f" + (chain.length-1) + "L", args, argTypes, JavaTypeNames.RTVALUE, MethodInvocation.InvocationType.VIRTUAL);
            MethodInvocation eval = SCJavaDefn.createInvocation(fL, SCJavaDefn.EVALUATE, EXECUTION_CONTEXT_VAR);
            return new ExpressionContextPair(eval, newContext);
        }

        // Now we want to build the application chain. (As efficiently as possible).
        int nApplicationArguments = chain.length - 1;
        int argIndex = 1;
        JavaExpression root = je[0];
        while (nApplicationArguments > 0) {
            if (nApplicationArguments >= 4) {
                JavaExpression[] args = new JavaExpression[4];
                JavaTypeName[] argTypes = new JavaTypeName[4];
                Arrays.fill (argTypes, JavaTypeNames.RTVALUE);
View Full Code Here

        } else {
            pair = generateUnboxedArgument(null, e, variableContext);
        }

        Block block = pair.getContextBlock();
        JavaExpression firstArg = pair.getJavaExpression();
        block.addStatement(new ExpressionStatement(forceSafeForStatement(firstArg)));

        return block;
    }
View Full Code Here

        } else {
            fsRootECP = genS_C(fsRoot, variableContext);
        }

        Block b = fsRootECP.getContextBlock();
        JavaExpression rootExpression = fsRootECP.getJavaExpression();

        JavaExpression extraArgs[] = new JavaExpression[diff];
        for (int i = calledArity + 1; i < appChain.length; ++i) {
            ExpressionContextPair argECP = genS_C(appChain[i], variableContext);
            b.addStatement(argECP.getContextBlock());
            extraArgs[i-calledArity-1] = argECP.getJavaExpression();
        }
View Full Code Here

                Block newContext = ecp[0].getContextBlock();
                for (int i = 1; i < chain.length; ++i) {
                    newContext.addStatement(ecp[i].getContextBlock());
                }

                JavaExpression root = ecp[0].getJavaExpression();

                JavaExpression args[] = new JavaExpression[chain.length];
                for (int i = 0; i < chain.length; ++i) {
                    args[i] = ecp[i].getJavaExpression();
                }

                JavaTypeName type;
View Full Code Here

                                        ForeignFunctionInfo foreignFunctionInfo,
                                        Scheme scheme,
                                        VariableContext variableContext) throws CodeGenerationException {
        if (variableContext.isLocalVariable(qualName)) {
            if (scheme == Scheme.E_SCHEME) {
                JavaExpression strictRef = variableContext.getStrictReference(qualName);
                if (strictRef != null) {
                    return strictRef;
                }
            } else {
                JavaExpression lazyRef = variableContext.getLazyReference(qualName);
                if (lazyRef != null) {
                    return lazyRef;
                }
            }

            throw new CodeGenerationException ("Unable to obtain reference to local variable " + qualName);
        } else {
            // This is not a local symbol (i.e. it is a supercombinator, foreign function, or constructor)
            // Kernel may claim the symbol if its defined in the Prelude module
            // First determine what kind of symbol this is
            if (dc != null) {
                // Constructor
                // Emit symbol with factory invocation

                JavaTypeName typeName = CALToJavaNames.createTypeNameFromDC(dc, module);
                JavaExpression dcInstance;
                dcInstance = getReferencedDC(typeName, dc);

                return dcInstance;
            } else {
                MachineFunction mf = module.getFunction(qualName);
View Full Code Here

    private void addExceptionHandler(Class<?> exceptionClass) {
        // Generate a Block corresponding to:
        // throw new RTForeignFunctionException(RTValue.generateForeignFunctionErrorMessage(exception, generatedClassName, supercombinatorName), null, exception);

        JavaTypeName exceptionType = JavaTypeName.make(exceptionClass);
        JavaExpression args[] = new JavaExpression [4];
        JavaTypeName argTypes[] = new JavaTypeName [4];
        args[0] = new LocalVariable("caught_exception" , exceptionType);
        argTypes[0] = JavaTypeName.THROWABLE;
        args[1] = LiteralWrapper.make(CALToJavaNames.createFullClassNameFromSC(getQualifiedName(), module));
        argTypes[1] = JavaTypeName.STRING;
        args[2] = LiteralWrapper.make(currentModuleName.toSourceText());
        argTypes[2] = JavaTypeName.STRING;
        args[3] = LiteralWrapper.make(getFunctionName());
        argTypes[3] = JavaTypeName.STRING;
        MethodInvocation genMessage = new MethodInvocation.Static (JavaTypeNames.RTVALUE,
                                                            "generateForeignFunctionErrorMessage",
                                                            args,
                                                            argTypes,
                                                            argTypes[1]);

        JavaExpression constructorArgs[] = new JavaExpression [2];
        JavaTypeName constructorArgTypes[] = new JavaTypeName [2];
        constructorArgs[0] = genMessage;
        constructorArgTypes[0] = JavaTypeName.STRING;
        constructorArgs[1] = new LocalVariable("caught_exception", exceptionType);
        constructorArgTypes[1] = JavaTypeName.THROWABLE;
View Full Code Here

            //}

            //notice that for non-RTValue fields, we need to box

            //$ec.isBreakpointEnabled($functionNameField)
            JavaExpression isDebuggingNeededCheck = new MethodInvocation.Instance(SCJavaDefn.EXECUTION_CONTEXT_VAR, "isDebugProcessingNeeded", LiteralWrapper.make(dc.getName().getQualifiedName()), JavaTypeName.STRING, JavaTypeName.BOOLEAN, MethodInvocation.InvocationType.VIRTUAL);
            JavaStatement.Block debuggingNeededThenBlock = new Block();
            JavaStatement isDebuggingNeededIfStatement =
                new JavaStatement.IfThenElseStatement(isDebuggingNeededCheck, debuggingNeededThenBlock);

            final int arity = dc.getArity();

            //new RTValue[]{CAL_Int.make(take$nElements$1), take$list$2}
            JavaExpression[] argValues = new JavaExpression[arity];
            for (int i = 0; i < arity; ++i) {

                String javaArgName = argNames[i];
                JavaTypeName javaArgType = argTypes[i];

                JavaExpression javaArgValue = new LocalName(javaArgName, javaArgType);
                if (!javaArgType.equals(JavaTypeNames.RTVALUE)) {
                    javaArgValue = SCJavaDefn.boxExpression(javaArgType, javaArgValue);
                }

                argValues[i] = javaArgValue;
            }
            JavaExpression argValueArrayCreation = new JavaExpression.ArrayCreationExpression(JavaTypeNames.RTVALUE, argValues);

            //$ec.debugProcessing("Prelude.take",
            //            new RTValue[]{CAL_Int.make(take$nElements$1), take$list$2}));
            JavaExpression suspend =
                new MethodInvocation.Instance(
                    SCJavaDefn.EXECUTION_CONTEXT_VAR, "debugProcessing",
                    new JavaExpression[] {
                            LiteralWrapper.make(dc.getName().getQualifiedName()),
                            argValueArrayCreation },
View Full Code Here

TOP

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

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.