Package org.openquark.cal.internal.machine

Examples of org.openquark.cal.internal.machine.CodeGenerationException


            // Retrieve the custom class loader that is stored in the Program object.
            CALClassLoader calLoader = module.getClassLoader();
            if (calLoader == null) {
                // This should never be null.
                throw (new CodeGenerationException ("Null class loader in LECCProgram."));
            }

            // Mark labels as adjuncts, and whether they will have code generated.
            for (final MachineFunction machineFunction : module.getFunctions()) {
View Full Code Here


            // Retrieve the custom class loader that is stored in the Program object.
            CALClassLoader calLoader = module.getClassLoader();
            if (calLoader == null) {
                // This should never be null.
                throw (new CodeGenerationException ("Null class loader in LECCProgram."));
            }


            // Create a new Set to hold the TypeConstructor instances associated with this module
            Set<TypeConstructor> typeConsSet = new HashSet<TypeConstructor>();
View Full Code Here

            for (int i = 0, nInnerClasses = classRep.getNInnerClasses(); i < nInnerClasses; ++i) {
                JavaClassRep innerClassRep = classRep.getInnerClass(i);
                writeClassWithInnerClasses(innerClassRep, logger);
            }       
        } catch (JavaGenerationException e) {
            throw new CodeGenerationException(e.getLocalizedMessage(), e);
        }
    }
View Full Code Here

                debugGeneratedBytecode(classRep.getClassName(), bytecode);
            }
           
            return bytecode;
        } catch (JavaGenerationException e) {
            throw new CodeGenerationException(e.getLocalizedMessage(), e);
        }
    }
View Full Code Here

     * @throws CodeGenerationException
     */
    static JavaExpression getPrimOpDefinition(int code, JavaExpression[] args) throws CodeGenerationException {
        switch (code) {
            case PrimOps.PRIMOP_NOP:
                throw new CodeGenerationException ("Attempt to generate code for PRIMOP_NOP.");

            case PrimOps.PRIMOP_OR:
                return new OperatorExpression.Binary(JavaOperator.CONDITIONAL_OR, args);

            case PrimOps.PRIMOP_AND:
                return new OperatorExpression.Binary(JavaOperator.CONDITIONAL_AND, args);

            case PrimOps.PRIMOP_EQUALS_INT:
                return new OperatorExpression.Binary(JavaOperator.EQUALS_INT, args);

            case PrimOps.PRIMOP_NOT_EQUALS_INT:
                return new OperatorExpression.Binary(JavaOperator.NOT_EQUALS_INT, args);

            case PrimOps.PRIMOP_GREATER_THAN_INT:
                return new OperatorExpression.Binary(JavaOperator.GREATER_THAN_INT, args);

            case PrimOps.PRIMOP_GREATER_THAN_EQUALS_INT:
                return new OperatorExpression.Binary(JavaOperator.GREATER_THAN_EQUALS_INT, args);

            case PrimOps.PRIMOP_LESS_THAN_INT:
                return new OperatorExpression.Binary(JavaOperator.LESS_THAN_INT, args);

            case PrimOps.PRIMOP_LESS_THAN_EQUALS_INT:
                return new OperatorExpression.Binary(JavaOperator.LESS_THAN_EQUALS_INT, args);

            case PrimOps.PRIMOP_ADD_INT:
                return new OperatorExpression.Binary(JavaOperator.ADD_INT, args);

            case PrimOps.PRIMOP_SUBTRACT_INT:
                return new OperatorExpression.Binary(JavaOperator.SUBTRACT_INT, args);

            case PrimOps.PRIMOP_MULTIPLY_INT:
                return new OperatorExpression.Binary(JavaOperator.MULTIPLY_INT, args);
           
            case PrimOps.PRIMOP_DIVIDE_INT:
                return new OperatorExpression.Binary(JavaOperator.DIVIDE_INT, args);           

            case PrimOps.PRIMOP_ADD_DOUBLE:
                return new OperatorExpression.Binary(JavaOperator.ADD_DOUBLE, args);

            case PrimOps.PRIMOP_SUBTRACT_DOUBLE:
                return new OperatorExpression.Binary(JavaOperator.SUBTRACT_DOUBLE, args);

            case PrimOps.PRIMOP_MULTIPLY_DOUBLE:
                return new OperatorExpression.Binary(JavaOperator.MULTIPLY_DOUBLE, args);

            case PrimOps.PRIMOP_DIVIDE_DOUBLE:
                return new OperatorExpression.Binary(JavaOperator.DIVIDE_DOUBLE, args);

            case PrimOps.PRIMOP_EQUALS_DOUBLE:
                return new OperatorExpression.Binary(JavaOperator.EQUALS_DOUBLE, args);

            case PrimOps.PRIMOP_NOT_EQUALS_DOUBLE:
                return new OperatorExpression.Binary(JavaOperator.NOT_EQUALS_DOUBLE, args);

            case PrimOps.PRIMOP_GREATER_THAN_DOUBLE:
                return new OperatorExpression.Binary(JavaOperator.GREATER_THAN_DOUBLE, args);

            case PrimOps.PRIMOP_GREATER_THAN_EQUALS_DOUBLE:
                return new OperatorExpression.Binary(JavaOperator.GREATER_THAN_EQUALS_DOUBLE, args);

            case PrimOps.PRIMOP_LESS_THAN_DOUBLE:
                return new OperatorExpression.Binary(JavaOperator.LESS_THAN_DOUBLE, args);

            case PrimOps.PRIMOP_LESS_THAN_EQUALS_DOUBLE:
                return new OperatorExpression.Binary(JavaOperator.LESS_THAN_EQUALS_DOUBLE, args);
           
            case PrimOps.PRIMOP_ADD_FLOAT:
                return new OperatorExpression.Binary(JavaOperator.ADD_FLOAT, args);

            case PrimOps.PRIMOP_SUBTRACT_FLOAT:
                return new OperatorExpression.Binary(JavaOperator.SUBTRACT_FLOAT, args);

            case PrimOps.PRIMOP_MULTIPLY_FLOAT:
                return new OperatorExpression.Binary(JavaOperator.MULTIPLY_FLOAT, args);

            case PrimOps.PRIMOP_DIVIDE_FLOAT:
                return new OperatorExpression.Binary(JavaOperator.DIVIDE_FLOAT, args);

            case PrimOps.PRIMOP_EQUALS_FLOAT:
                return new OperatorExpression.Binary(JavaOperator.EQUALS_FLOAT, args);

            case PrimOps.PRIMOP_NOT_EQUALS_FLOAT:
                return new OperatorExpression.Binary(JavaOperator.NOT_EQUALS_FLOAT, args);

            case PrimOps.PRIMOP_GREATER_THAN_FLOAT:
                return new OperatorExpression.Binary(JavaOperator.GREATER_THAN_FLOAT, args);

            case PrimOps.PRIMOP_GREATER_THAN_EQUALS_FLOAT:
                return new OperatorExpression.Binary(JavaOperator.GREATER_THAN_EQUALS_FLOAT, args);

            case PrimOps.PRIMOP_LESS_THAN_FLOAT:
                return new OperatorExpression.Binary(JavaOperator.LESS_THAN_FLOAT, args);

            case PrimOps.PRIMOP_LESS_THAN_EQUALS_FLOAT:
                return new OperatorExpression.Binary(JavaOperator.LESS_THAN_EQUALS_FLOAT, args);
           
            case PrimOps.PRIMOP_ADD_LONG:
                return new OperatorExpression.Binary(JavaOperator.ADD_LONG, args);

            case PrimOps.PRIMOP_SUBTRACT_LONG:
                return new OperatorExpression.Binary(JavaOperator.SUBTRACT_LONG, args);

            case PrimOps.PRIMOP_MULTIPLY_LONG:
                return new OperatorExpression.Binary(JavaOperator.MULTIPLY_LONG, args);

            case PrimOps.PRIMOP_DIVIDE_LONG:
                return new OperatorExpression.Binary(JavaOperator.DIVIDE_LONG, args);

            case PrimOps.PRIMOP_EQUALS_LONG:
                return new OperatorExpression.Binary(JavaOperator.EQUALS_LONG, args);

            case PrimOps.PRIMOP_NOT_EQUALS_LONG:
                return new OperatorExpression.Binary(JavaOperator.NOT_EQUALS_LONG, args);

            case PrimOps.PRIMOP_GREATER_THAN_LONG:
                return new OperatorExpression.Binary(JavaOperator.GREATER_THAN_LONG, args);

            case PrimOps.PRIMOP_GREATER_THAN_EQUALS_LONG:
                return new OperatorExpression.Binary(JavaOperator.GREATER_THAN_EQUALS_LONG, args);

            case PrimOps.PRIMOP_LESS_THAN_LONG:
                return new OperatorExpression.Binary(JavaOperator.LESS_THAN_LONG, args);

            case PrimOps.PRIMOP_LESS_THAN_EQUALS_LONG:
                return new OperatorExpression.Binary(JavaOperator.LESS_THAN_EQUALS_LONG, args);

            case PrimOps.PRIMOP_EQUALS_SHORT:
                return new OperatorExpression.Binary(JavaOperator.EQUALS_SHORT, args);

            case PrimOps.PRIMOP_NOT_EQUALS_SHORT:
                return new OperatorExpression.Binary(JavaOperator.NOT_EQUALS_SHORT, args);

            case PrimOps.PRIMOP_GREATER_THAN_SHORT:
                return new OperatorExpression.Binary(JavaOperator.GREATER_THAN_SHORT, args);

            case PrimOps.PRIMOP_GREATER_THAN_EQUALS_SHORT:
                return new OperatorExpression.Binary(JavaOperator.GREATER_THAN_EQUALS_SHORT, args);

            case PrimOps.PRIMOP_LESS_THAN_SHORT:
                return new OperatorExpression.Binary(JavaOperator.LESS_THAN_SHORT, args);

            case PrimOps.PRIMOP_LESS_THAN_EQUALS_SHORT:
                return new OperatorExpression.Binary(JavaOperator.LESS_THAN_EQUALS_SHORT, args);

            case PrimOps.PRIMOP_EQUALS_BYTE:
                return new OperatorExpression.Binary(JavaOperator.EQUALS_BYTE, args);

            case PrimOps.PRIMOP_NOT_EQUALS_BYTE:
                return new OperatorExpression.Binary(JavaOperator.NOT_EQUALS_BYTE, args);

            case PrimOps.PRIMOP_GREATER_THAN_BYTE:
                return new OperatorExpression.Binary(JavaOperator.GREATER_THAN_BYTE, args);

            case PrimOps.PRIMOP_GREATER_THAN_EQUALS_BYTE:
                return new OperatorExpression.Binary(JavaOperator.GREATER_THAN_EQUALS_BYTE, args);

            case PrimOps.PRIMOP_LESS_THAN_BYTE:
                return new OperatorExpression.Binary(JavaOperator.LESS_THAN_BYTE, args);

            case PrimOps.PRIMOP_LESS_THAN_EQUALS_BYTE:
                return new OperatorExpression.Binary(JavaOperator.LESS_THAN_EQUALS_BYTE, args);
          

            case PrimOps.PRIMOP_EQUALS_CHAR:
                return new OperatorExpression.Binary(JavaOperator.EQUALS_CHAR, args);

            case PrimOps.PRIMOP_NOT_EQUALS_CHAR:
                return new OperatorExpression.Binary(JavaOperator.NOT_EQUALS_CHAR, args);

            case PrimOps.PRIMOP_GREATER_THAN_CHAR:
                return new OperatorExpression.Binary(JavaOperator.GREATER_THAN_CHAR, args);

            case PrimOps.PRIMOP_GREATER_THAN_EQUALS_CHAR:
                return new OperatorExpression.Binary(JavaOperator.GREATER_THAN_EQUALS_CHAR, args);

            case PrimOps.PRIMOP_LESS_THAN_CHAR:
                return new OperatorExpression.Binary(JavaOperator.LESS_THAN_CHAR, args);

            case PrimOps.PRIMOP_LESS_THAN_EQUALS_CHAR:
                return new OperatorExpression.Binary(JavaOperator.LESS_THAN_EQUALS_CHAR, args);
   
            case PrimOps.PRIMOP_NEGATE_INT:
                return new OperatorExpression.Unary(JavaOperator.NEGATE_INT, args[0]);
               
            case PrimOps.PRIMOP_REMAINDER_INT:
                return new OperatorExpression.Binary(JavaOperator.REM_INT, args);               

            case PrimOps.PRIMOP_NEGATE_DOUBLE:
                return new OperatorExpression.Unary(JavaOperator.NEGATE_DOUBLE, args[0]);
               
            case PrimOps.PRIMOP_REMAINDER_DOUBLE:
                return new OperatorExpression.Binary(JavaOperator.REM_DOUBLE, args);                  
           
            case PrimOps.PRIMOP_NEGATE_FLOAT:
                return new OperatorExpression.Unary(JavaOperator.NEGATE_FLOAT, args[0]);
               
            case PrimOps.PRIMOP_REMAINDER_FLOAT:
                return new OperatorExpression.Binary(JavaOperator.REM_FLOAT, args);                      
           
            case PrimOps.PRIMOP_NEGATE_LONG:
                return new OperatorExpression.Unary(JavaOperator.NEGATE_LONG, args[0]);
               
            case PrimOps.PRIMOP_REMAINDER_LONG:
                return new OperatorExpression.Binary(JavaOperator.REM_LONG, args);                           

            case PrimOps.PRIMOP_FIELD_NAMES:
            {               
                //((RTRecordValue)args[0]).fieldNames()
                return new MethodInvocation.Instance(new CastExpression(JavaTypeNames.RTRECORD_VALUE, args[0]),
                    "fieldNames", JavaTypeName.LIST, InvocationType.VIRTUAL);                             
            }
           
            case PrimOps.PRIMOP_FIELD_VALUES:
            {               
                //((RTRecordValue)args[0]).fieldValues()
                return new MethodInvocation.Instance(new CastExpression(JavaTypeNames.RTRECORD_VALUE, args[0]),
                    "fieldValues", JavaTypeName.LIST, InvocationType.VIRTUAL);                             
            }           
           
            case PrimOps.PRIMOP_HAS_FIELD:
           
                //((RTRecordValue)args[0]).hasField(args[1])           
                return new MethodInvocation.Instance(new CastExpression(JavaTypeNames.RTRECORD_VALUE, args[0]), "hasField",
                    args[1], JavaTypeName.STRING, JavaTypeName.BOOLEAN, InvocationType.VIRTUAL);
            }
           
            case PrimOps.PRIMOP_RECORD_FIELD_INDEX:
           
                //((RTRecordValue)args[0]).indexOfField(args[1])           
                return new MethodInvocation.Instance(
                        new CastExpression(JavaTypeNames.RTRECORD_VALUE, args[0]),
                        "indexOfField", args[1], JavaTypeName.STRING, JavaTypeName.INT, InvocationType.VIRTUAL);
            }
           
            case PrimOps.PRIMOP_CAL_VALUE_TO_OBJECT:
            {
                return new JavaExpression.MethodInvocation.Static (JavaTypeNames.RTDATA_OPAQUE,
                                                                   "make",
                                                                   args[0],
                                                                   JavaTypeName.OBJECT,
                                                                   JavaTypeNames.RTDATA_OPAQUE);
            }
           
            case PrimOps.PRIMOP_OBJECT_TO_CAL_VALUE:
            {
                //note that the call to evaluate is necessary because the code generator makes some assumptions that all PrimOps produce
                //a value in weak-head normal form.
                //((RTValue) args[0]).evaluate($ec);
                return SCJavaDefn.createInvocation(new JavaExpression.CastExpression(JavaTypeNames.RTVALUE, args[0]), SCJavaDefn.EVALUATE, SCJavaDefn.EXECUTION_CONTEXT_VAR);
            }
           
            case PrimOps.PRIMOP_MAKE_ITERATOR:
            {               
                //new RTCalListIterator(args[0], args[1], $ec)              
                JavaExpression[] arguments = new JavaExpression[] {args[0], args[1], new MethodVariable(SCJavaDefn.EXECUTION_CONTEXT_NAME)};
                JavaTypeName[] argTypes = new JavaTypeName[] {JavaTypeNames.RTVALUE, JavaTypeNames.RTVALUE, JavaTypeNames.RTEXECUTION_CONTEXT};              
                return new JavaExpression.ClassInstanceCreationExpression(JavaTypeNames.RTCAL_LIST_ITERATOR, arguments, argTypes);
            }           
           
            case PrimOps.PRIMOP_MAKE_COMPARATOR:
            {               
                //new RTComparator(args[0], $ec)              
                JavaExpression[] arguments = new JavaExpression[] {args[0], new MethodVariable(SCJavaDefn.EXECUTION_CONTEXT_NAME)};
                JavaTypeName[] argTypes = new JavaTypeName[] {JavaTypeNames.RTVALUE, JavaTypeNames.RTEXECUTION_CONTEXT};              
                return new JavaExpression.ClassInstanceCreationExpression(JavaTypeNames.RTCOMPARATOR, arguments, argTypes);
            }
           
            case PrimOps.PRIMOP_MAKE_EQUIVALENCE_RELATION:
            {
                //new RTEquivalenceRelation(args[0], $ec)               
                JavaExpression[] arguments = new JavaExpression[] {args[0], new MethodVariable(SCJavaDefn.EXECUTION_CONTEXT_NAME)};
                JavaTypeName[] argTypes = new JavaTypeName[] {JavaTypeNames.RTVALUE, JavaTypeNames.RTEXECUTION_CONTEXT};              
                return new JavaExpression.ClassInstanceCreationExpression(JavaTypeNames.RTEQUIVALENCE_RELATION, arguments, argTypes);                               
            }
           
            case PrimOps.PRIMOP_MAKE_CAL_FUNCTION:
            {               
                //new RTCalFunction(args[0], $ec)              
                JavaExpression[] arguments = new JavaExpression[] {args[0], new MethodVariable(SCJavaDefn.EXECUTION_CONTEXT_NAME)};
                JavaTypeName[] argTypes = new JavaTypeName[] {JavaTypeNames.RTVALUE, JavaTypeNames.RTEXECUTION_CONTEXT};              
                return new JavaExpression.ClassInstanceCreationExpression(JavaTypeNames.RTCAL_FUNCTION, arguments, argTypes);
            }           
           
            case PrimOps.PRIMOP_BITWISE_AND_INT: {
                return new OperatorExpression.Binary (JavaOperator.BITWISE_AND_INT, args);
            }
           
            case PrimOps.PRIMOP_BITWISE_OR_INT: {
                return new OperatorExpression.Binary (JavaOperator.BITWISE_OR_INT, args);
            }
           
            case PrimOps.PRIMOP_BITWISE_XOR_INT: {
                return new OperatorExpression.Binary (JavaOperator.BITWISE_XOR_INT, args);
            }
           
            case PrimOps.PRIMOP_COMPLEMENT_INT: {
                return new OperatorExpression.Unary (JavaOperator.COMPLEMENT_INT, args[0]);
            }
           
            case PrimOps.PRIMOP_SHIFTL_INT: {
                return new OperatorExpression.Binary (JavaOperator.SHIFTL_INT, args);
            }
           
            case PrimOps.PRIMOP_SHIFTR_INT: {
                return new OperatorExpression.Binary (JavaOperator.SHIFTR_INT, args);
            }
           
            case PrimOps.PRIMOP_SHIFTR_UNSIGNED_INT: {
                return new OperatorExpression.Binary (JavaOperator.SHIFTR_UNSIGNED_INT, args);
            }

            case PrimOps.PRIMOP_BITWISE_AND_LONG: {
                return new OperatorExpression.Binary (JavaOperator.BITWISE_AND_LONG, args);
            }
           
            case PrimOps.PRIMOP_BITWISE_OR_LONG: {
                return new OperatorExpression.Binary (JavaOperator.BITWISE_OR_LONG, args);
            }
           
            case PrimOps.PRIMOP_BITWISE_XOR_LONG: {
                return new OperatorExpression.Binary (JavaOperator.BITWISE_XOR_LONG, args);
            }
           
            case PrimOps.PRIMOP_COMPLEMENT_LONG: {
                return new OperatorExpression.Unary (JavaOperator.COMPLEMENT_LONG, args[0]);
            }
           
            case PrimOps.PRIMOP_SHIFTL_LONG: {
                return new OperatorExpression.Binary (JavaOperator.SHIFTL_LONG, args);
            }
           
            case PrimOps.PRIMOP_SHIFTR_LONG: {
                return new OperatorExpression.Binary (JavaOperator.SHIFTR_LONG, args);
            }
           
            case PrimOps.PRIMOP_SHIFTR_UNSIGNED_LONG: {
                return new OperatorExpression.Binary (JavaOperator.SHIFTR_UNSIGNED_LONG, args);
            }
           
            case PrimOps.PRIMOP_EXECUTION_CONTEXT:
           
                //reference to the "$ec" execution context variable
                return SCJavaDefn.EXECUTION_CONTEXT_VAR;
            }           
           
            // This is now handled higher up since more context information is needed
            // in order to add the source position to the error message.
            //
            default:
            {
                throw new CodeGenerationException("Unrecognized PrimOp: " + code + ".");
            }
        }
       
    }
View Full Code Here

     * @throws CodeGenerationException
     */
    static JavaTypeName getTypeNameForPrimOp (int primOp) throws CodeGenerationException {
        switch (primOp) {
            case PrimOps.PRIMOP_NOP:
                throw new CodeGenerationException ("attempt to get type for primop_nop.");
   
            case PrimOps.PRIMOP_OR:
            case PrimOps.PRIMOP_AND:
            case PrimOps.PRIMOP_EQUALS_INT:
            case PrimOps.PRIMOP_NOT_EQUALS_INT:
            case PrimOps.PRIMOP_GREATER_THAN_INT:
            case PrimOps.PRIMOP_GREATER_THAN_EQUALS_INT:
            case PrimOps.PRIMOP_LESS_THAN_INT:
            case PrimOps.PRIMOP_LESS_THAN_EQUALS_INT:
            case PrimOps.PRIMOP_EQUALS_DOUBLE:
            case PrimOps.PRIMOP_NOT_EQUALS_DOUBLE:
            case PrimOps.PRIMOP_GREATER_THAN_DOUBLE:
            case PrimOps.PRIMOP_GREATER_THAN_EQUALS_DOUBLE:
            case PrimOps.PRIMOP_LESS_THAN_DOUBLE:
            case PrimOps.PRIMOP_LESS_THAN_EQUALS_DOUBLE:
            case PrimOps.PRIMOP_EQUALS_LONG:
            case PrimOps.PRIMOP_NOT_EQUALS_LONG:
            case PrimOps.PRIMOP_GREATER_THAN_LONG:
            case PrimOps.PRIMOP_GREATER_THAN_EQUALS_LONG:
            case PrimOps.PRIMOP_LESS_THAN_LONG:
            case PrimOps.PRIMOP_LESS_THAN_EQUALS_LONG:
            case PrimOps.PRIMOP_EQUALS_CHAR:
            case PrimOps.PRIMOP_NOT_EQUALS_CHAR:
            case PrimOps.PRIMOP_GREATER_THAN_CHAR:
            case PrimOps.PRIMOP_GREATER_THAN_EQUALS_CHAR:
            case PrimOps.PRIMOP_LESS_THAN_CHAR:
            case PrimOps.PRIMOP_LESS_THAN_EQUALS_CHAR:
            case PrimOps.PRIMOP_EQUALS_SHORT:
            case PrimOps.PRIMOP_NOT_EQUALS_SHORT:
            case PrimOps.PRIMOP_GREATER_THAN_SHORT:
            case PrimOps.PRIMOP_GREATER_THAN_EQUALS_SHORT:
            case PrimOps.PRIMOP_LESS_THAN_SHORT:
            case PrimOps.PRIMOP_LESS_THAN_EQUALS_SHORT:
            case PrimOps.PRIMOP_EQUALS_FLOAT:
            case PrimOps.PRIMOP_NOT_EQUALS_FLOAT:
            case PrimOps.PRIMOP_GREATER_THAN_FLOAT:
            case PrimOps.PRIMOP_GREATER_THAN_EQUALS_FLOAT:
            case PrimOps.PRIMOP_LESS_THAN_FLOAT:
            case PrimOps.PRIMOP_LESS_THAN_EQUALS_FLOAT:
            case PrimOps.PRIMOP_EQUALS_BYTE:
            case PrimOps.PRIMOP_NOT_EQUALS_BYTE:
            case PrimOps.PRIMOP_GREATER_THAN_BYTE:
            case PrimOps.PRIMOP_GREATER_THAN_EQUALS_BYTE:
            case PrimOps.PRIMOP_LESS_THAN_BYTE:
            case PrimOps.PRIMOP_LESS_THAN_EQUALS_BYTE:
            case PrimOps.PRIMOP_HAS_FIELD:
                return JavaTypeName.BOOLEAN;
           
            case PrimOps.PRIMOP_ADD_INT:
            case PrimOps.PRIMOP_SUBTRACT_INT:
            case PrimOps.PRIMOP_MULTIPLY_INT:
            case PrimOps.PRIMOP_DIVIDE_INT:           
            case PrimOps.PRIMOP_NEGATE_INT:
            case PrimOps.PRIMOP_REMAINDER_INT:           
            case PrimOps.PRIMOP_BITWISE_AND_INT:
            case PrimOps.PRIMOP_BITWISE_OR_INT:
            case PrimOps.PRIMOP_BITWISE_XOR_INT:
            case PrimOps.PRIMOP_COMPLEMENT_INT:
            case PrimOps.PRIMOP_SHIFTL_INT:
            case PrimOps.PRIMOP_SHIFTR_INT:
            case PrimOps.PRIMOP_SHIFTR_UNSIGNED_INT:
            case PrimOps.PRIMOP_RECORD_FIELD_INDEX:
                return JavaTypeName.INT;
           
            case PrimOps.PRIMOP_ADD_DOUBLE:
            case PrimOps.PRIMOP_SUBTRACT_DOUBLE:
            case PrimOps.PRIMOP_MULTIPLY_DOUBLE:
            case PrimOps.PRIMOP_DIVIDE_DOUBLE:
            case PrimOps.PRIMOP_NEGATE_DOUBLE:
            case PrimOps.PRIMOP_REMAINDER_DOUBLE:          
                return JavaTypeName.DOUBLE;
           
            case PrimOps.PRIMOP_ADD_LONG:
            case PrimOps.PRIMOP_SUBTRACT_LONG:
            case PrimOps.PRIMOP_MULTIPLY_LONG:
            case PrimOps.PRIMOP_DIVIDE_LONG:
            case PrimOps.PRIMOP_NEGATE_LONG:
            case PrimOps.PRIMOP_REMAINDER_LONG:           
            case PrimOps.PRIMOP_BITWISE_AND_LONG:
            case PrimOps.PRIMOP_BITWISE_OR_LONG:
            case PrimOps.PRIMOP_BITWISE_XOR_LONG:
            case PrimOps.PRIMOP_COMPLEMENT_LONG:
            case PrimOps.PRIMOP_SHIFTL_LONG:
            case PrimOps.PRIMOP_SHIFTR_LONG:
            case PrimOps.PRIMOP_SHIFTR_UNSIGNED_LONG:
                return JavaTypeName.LONG;
           
            case PrimOps.PRIMOP_ADD_FLOAT:
            case PrimOps.PRIMOP_SUBTRACT_FLOAT:
            case PrimOps.PRIMOP_MULTIPLY_FLOAT:
            case PrimOps.PRIMOP_DIVIDE_FLOAT:
            case PrimOps.PRIMOP_NEGATE_FLOAT:
            case PrimOps.PRIMOP_REMAINDER_FLOAT:          
                return JavaTypeName.FLOAT;
           
            case PrimOps.PRIMOP_FIELD_NAMES:
            case PrimOps.PRIMOP_FIELD_VALUES:
                return JavaTypeName.LIST;
           
            case PrimOps.PRIMOP_OBJECT_TO_CAL_VALUE:
                return JavaTypeName.CAL_VALUE;
               
            case PrimOps.PRIMOP_CAL_VALUE_TO_OBJECT:
                return JavaTypeName.OBJECT;
               
            case PrimOps.PRIMOP_MAKE_ITERATOR:
                return JavaTypeName.ITERATOR;
           
            case PrimOps.PRIMOP_MAKE_COMPARATOR:
                return JavaTypeName.COMPARATOR;
           
            case PrimOps.PRIMOP_MAKE_EQUIVALENCE_RELATION:
                return JavaTypeName.EQUIVALENCE_RELATION;
               
            case PrimOps.PRIMOP_MAKE_CAL_FUNCTION:
                return JavaTypeName.CAL_FUNCTION;               
               
            case PrimOps.PRIMOP_EXECUTION_CONTEXT:
                return JavaTypeNames.RTEXECUTION_CONTEXT;
           
            case PrimOps.PRIMOP_FOREIGN_FUNCTION:
                //more information is needed to determine the return type of a foreign function...
                return null;
           
            default:
            {
                throw new CodeGenerationException("Unrecognized primitive op code " + primOp);
            }
        }             
    }
View Full Code Here

    }
   
    static final JavaTypeName getTypeNameForPrimOpArgument (int op, int argNum) throws CodeGenerationException {
        switch (op) {
        case PrimOps.PRIMOP_NOP:
            throw new CodeGenerationException ("Attemp to get argument type for PRIMOP_NOP");
       
        case PrimOps.PRIMOP_OR:
        case PrimOps.PRIMOP_AND:
            return JavaTypeName.BOOLEAN;

        case PrimOps.PRIMOP_EQUALS_INT:
        case PrimOps.PRIMOP_NOT_EQUALS_INT:
        case PrimOps.PRIMOP_GREATER_THAN_INT:
        case PrimOps.PRIMOP_GREATER_THAN_EQUALS_INT:
        case PrimOps.PRIMOP_LESS_THAN_INT:
        case PrimOps.PRIMOP_LESS_THAN_EQUALS_INT:
        case PrimOps.PRIMOP_ADD_INT:
        case PrimOps.PRIMOP_SUBTRACT_INT:
        case PrimOps.PRIMOP_MULTIPLY_INT:
        case PrimOps.PRIMOP_DIVIDE_INT:
        case PrimOps.PRIMOP_NEGATE_INT:
        case PrimOps.PRIMOP_REMAINDER_INT:              
        case PrimOps.PRIMOP_BITWISE_AND_INT:
        case PrimOps.PRIMOP_BITWISE_OR_INT:
        case PrimOps.PRIMOP_BITWISE_XOR_INT:
        case PrimOps.PRIMOP_COMPLEMENT_INT:
        case PrimOps.PRIMOP_SHIFTL_INT:
        case PrimOps.PRIMOP_SHIFTR_INT:
        case PrimOps.PRIMOP_SHIFTR_UNSIGNED_INT:
            return JavaTypeName.INT;
       
        case PrimOps.PRIMOP_EQUALS_LONG:
        case PrimOps.PRIMOP_NOT_EQUALS_LONG:
        case PrimOps.PRIMOP_GREATER_THAN_LONG:
        case PrimOps.PRIMOP_GREATER_THAN_EQUALS_LONG:
        case PrimOps.PRIMOP_LESS_THAN_LONG:
        case PrimOps.PRIMOP_LESS_THAN_EQUALS_LONG:
        case PrimOps.PRIMOP_ADD_LONG:
        case PrimOps.PRIMOP_SUBTRACT_LONG:
        case PrimOps.PRIMOP_MULTIPLY_LONG:
        case PrimOps.PRIMOP_DIVIDE_LONG:
        case PrimOps.PRIMOP_NEGATE_LONG:
        case PrimOps.PRIMOP_REMAINDER_LONG:                   
        case PrimOps.PRIMOP_BITWISE_AND_LONG:
        case PrimOps.PRIMOP_BITWISE_OR_LONG:
        case PrimOps.PRIMOP_BITWISE_XOR_LONG:
        case PrimOps.PRIMOP_COMPLEMENT_LONG:
        case PrimOps.PRIMOP_SHIFTL_LONG:
        case PrimOps.PRIMOP_SHIFTR_LONG:
        case PrimOps.PRIMOP_SHIFTR_UNSIGNED_LONG:
            return JavaTypeName.LONG;

        case PrimOps.PRIMOP_EQUALS_SHORT:
        case PrimOps.PRIMOP_NOT_EQUALS_SHORT:
        case PrimOps.PRIMOP_GREATER_THAN_SHORT:
        case PrimOps.PRIMOP_GREATER_THAN_EQUALS_SHORT:
        case PrimOps.PRIMOP_LESS_THAN_SHORT:
        case PrimOps.PRIMOP_LESS_THAN_EQUALS_SHORT:
            return JavaTypeName.SHORT;

        case PrimOps.PRIMOP_EQUALS_BYTE:
        case PrimOps.PRIMOP_NOT_EQUALS_BYTE:
        case PrimOps.PRIMOP_GREATER_THAN_BYTE:
        case PrimOps.PRIMOP_GREATER_THAN_EQUALS_BYTE:
        case PrimOps.PRIMOP_LESS_THAN_BYTE:
        case PrimOps.PRIMOP_LESS_THAN_EQUALS_BYTE:
            return JavaTypeName.BYTE;

        case PrimOps.PRIMOP_EQUALS_FLOAT:
        case PrimOps.PRIMOP_NOT_EQUALS_FLOAT:
        case PrimOps.PRIMOP_GREATER_THAN_FLOAT:
        case PrimOps.PRIMOP_GREATER_THAN_EQUALS_FLOAT:
        case PrimOps.PRIMOP_LESS_THAN_FLOAT:
        case PrimOps.PRIMOP_LESS_THAN_EQUALS_FLOAT:
        case PrimOps.PRIMOP_ADD_FLOAT:
        case PrimOps.PRIMOP_SUBTRACT_FLOAT:
        case PrimOps.PRIMOP_MULTIPLY_FLOAT:
        case PrimOps.PRIMOP_DIVIDE_FLOAT:
        case PrimOps.PRIMOP_NEGATE_FLOAT:
        case PrimOps.PRIMOP_REMAINDER_FLOAT:                    
            return JavaTypeName.FLOAT;

        case PrimOps.PRIMOP_EQUALS_DOUBLE:
        case PrimOps.PRIMOP_NOT_EQUALS_DOUBLE:
        case PrimOps.PRIMOP_GREATER_THAN_DOUBLE:
        case PrimOps.PRIMOP_GREATER_THAN_EQUALS_DOUBLE:
        case PrimOps.PRIMOP_LESS_THAN_DOUBLE:
        case PrimOps.PRIMOP_LESS_THAN_EQUALS_DOUBLE:
        case PrimOps.PRIMOP_ADD_DOUBLE:
        case PrimOps.PRIMOP_SUBTRACT_DOUBLE:
        case PrimOps.PRIMOP_MULTIPLY_DOUBLE:
        case PrimOps.PRIMOP_DIVIDE_DOUBLE:
        case PrimOps.PRIMOP_NEGATE_DOUBLE:
        case PrimOps.PRIMOP_REMAINDER_DOUBLE:                    
            return JavaTypeName.DOUBLE;

        case PrimOps.PRIMOP_EQUALS_CHAR:
        case PrimOps.PRIMOP_NOT_EQUALS_CHAR:
        case PrimOps.PRIMOP_GREATER_THAN_CHAR:
        case PrimOps.PRIMOP_GREATER_THAN_EQUALS_CHAR:
        case PrimOps.PRIMOP_LESS_THAN_CHAR:
        case PrimOps.PRIMOP_LESS_THAN_EQUALS_CHAR:
            return JavaTypeName.CHAR;
       
        case PrimOps.PRIMOP_FIELD_NAMES:
        case PrimOps.PRIMOP_FIELD_VALUES:
            return JavaTypeNames.RTVALUE;
           
        case PrimOps.PRIMOP_HAS_FIELD:
        case PrimOps.PRIMOP_RECORD_FIELD_INDEX:
        {
            if (argNum == 0) {
                return JavaTypeNames.RTVALUE;
            } else {
                return JavaTypeName.STRING;
            }
        }

        case PrimOps.PRIMOP_OBJECT_TO_CAL_VALUE:
            return JavaTypeName.OBJECT;
       
        case PrimOps.PRIMOP_CAL_VALUE_TO_OBJECT:
            return JavaTypeNames.RTVALUE;
           
        case PrimOps.PRIMOP_MAKE_ITERATOR:
        case PrimOps.PRIMOP_MAKE_COMPARATOR:
        case PrimOps.PRIMOP_MAKE_EQUIVALENCE_RELATION:
        case PrimOps.PRIMOP_MAKE_CAL_FUNCTION:
            return JavaTypeNames.RTVALUE;   
           
        case PrimOps.PRIMOP_EXECUTION_CONTEXT:
            throw new CodeGenerationException("PRIMOP_EXECUTION_CONTEXT has no arguments.");

        case PrimOps.PRIMOP_FOREIGN_FUNCTION:
            // can't determine the arg type here.
            return null;           
           
        default:
            throw new CodeGenerationException("Unrecognized primop " + op + " in PrimOp.getTypeNameForPrimOpArgument.");       
    }      
       
    }
View Full Code Here

                    filesToCompile.add(sourceFile);
                    //System.out.println ("adding to compile: " + sourceFile.getName());
                    fileChange = true;
                }
            } catch (JavaGenerationException e) {
                throw new CodeGenerationException(e.getLocalizedMessage(), e);
            }
        } else {
            if (!resourceRepository.exists(classFile)) {
                filesToCompile.add(sourceFile);
                //System.out.println ("adding to compile: " + sourceFile.getName());
View Full Code Here

                    //System.out.println ("adding to compile: " + sourceFile.getName());
                    filesToCompile.add(sourceFile);
                    fileChange = true;
                }
            } catch (JavaGenerationException e) {
                throw new CodeGenerationException(e.getLocalizedMessage(), e);
            }
        } else {
            if (!resourceRepository.exists(classFile)) {
                //System.out.println ("adding to compile: " + sourceFile.getName());
                filesToCompile.add(sourceFile);
View Full Code Here

    /** {@inheritDoc} */
    @Override
    void wrap() throws CodeGenerationException {

        if (compileMethod == null) {
            throw new CodeGenerationException ("Error compiling generated source code: Unable to locate or access class com.sun.tools.javac.Main.  Generating Java source requires an installed JDK.  Please ensure that tools.jar is on the classpath.");
        }
       
        if (filesToCompile.isEmpty()) {
            return;
        }

      
        try {
            // Let any status listeners know that we're starting the compilation of java sources for this module.
            informStatusListeners(StatusListener.SM_START_COMPILING_GENERATED_SOURCE, module.getName());
           
            // Set up the classpath for compiling this module.
            String fileNames[] = new String [filesToCompile.size()];
            {
                int index = 0;
                for (final ProgramResourceLocator.File fileToCompile : filesToCompile) {
                   
                    File file = resourceRepository.getFile(fileToCompile);
                    if (file == null) {
                        // the fileToCompile refers to a resource that is not backed by the file system (e.g. in a Car)
                        // We do not support Java source generation for modules whose source comes from Car files.
                        throw new CodeGenerationException ("Error compiling generated source code: The location of the source file " + fileToCompile + " does not have a corresponding java.io.File representation (e.g. the module comes from a Car).");
                    }
                   
                    fileNames[index] = file.getPath();
                    index++;
                }
            }
           
            String currentPath = System.getProperty("java.class.path", ".");
            String pathSeparator = System.getProperty ("path.separator", ";");
            String rootPackagePathSegment = LECCMachineConfiguration.ROOT_PACKAGE.replace('.', File.separatorChar);
           
            Set<String> pathAdditions = new HashSet<String>();
            for (final ModuleName moduleName : dependeeModuleNames) {
                // Get module, add its base folder directory to the classpath.
                ProgramResourceLocator.Folder moduleResourceFolder = new ProgramResourceLocator.Folder(moduleName, ResourcePath.EMPTY_PATH);
                File moduleDir = resourceRepository.getFile(moduleResourceFolder);
                if (moduleDir == null) {
                    // the fileToCompile refers to a resource that is not backed by the file system (e.g. in a Car)
                    // We do not support Java source generation for modules whose source comes from Car files.
                    throw new CodeGenerationException ("Error compiling generated source code: The location of the module directory " + moduleResourceFolder + " does not have a corresponding java.io.File representation (e.g. the module comes from a Car).");
                }
               
                String path = moduleDir.getAbsolutePath();
                int index = path.indexOf(rootPackagePathSegment);
                if (index >= 0) {
                    path = path.substring(0, index);
                }
                pathAdditions.add(path);
            }

            for (final String pathAddition : pathAdditions) {
                currentPath += pathSeparator + pathAddition;
            }
           
            // Set up the classpath arguments for the call to 'compile'.
            String args[] = new String [fileNames.length + 6];
            args[0] = "-target";
            args[1] = "1.5";
            args[2] = "-source";
            args[3] = "1.5";
            args[4] = "-classpath";
            args[5] = currentPath;
            System.arraycopy(fileNames, 0, args, 6, fileNames.length);
           
            // Set up a PrintWriter that will write any status messages from the compiler into a string buffer.
            FixedSizeStringWriter sw = new FixedSizeStringWriter(1000);
            PrintWriter pw = new  PrintWriter(sw);
           
            // Invoke the compiler.
            Object compileResult = compileMethod.invoke(null, new Object[]{args, pw});
           
            // Close/flush the PrintWriter.
            pw.close();
           
            // Extract the integer return code from the object result of 'invoke'.
            int returnCode = ((Integer)compileResult).intValue();
           
            if (returnCode != 0) {
                if (DELETE_GENERATED_SOURCES_ON_COMPILATION_ERROR) {
                    // We need to clean out the generated source target directory.  Otherwise we can get into a state where
                    // we assume that an existing java source and the corresponding class file are synchronized when they're
                    // actually not.
                    try {
                        resourceRepository.delete(moduleFolder);
                        // TODO: actually handle this.
                    } catch (IOException ioe) {
                        // There was a problem deleting one or more files.
                        // This used to be just ignored.
                        System.err.println("Problem deleting one or more files: " + ioe);
                    }
                }
               
                // Construct an error message that includes any messages from the javac compiler.
                throw new CodeGenerationException ("Error compiling generated source for module " + module.getName() + ".\n" + sw.toString());
            }

            if (DEBUG_GENERATED_BYTECODE) {
                debugGeneratedBytecode();
            }

        } catch (IllegalAccessException e) {
            throw new CodeGenerationException ("Error compiling generated source code: IllegalAccessException thrown trying to access com.sun.tools.javac.Main.compile.");
        } catch (InvocationTargetException e) {
            throw new CodeGenerationException ("Error compiling generated source code: InvocationTargetException thrown trying to access com.sun.tools.javac.Main.compile. " + e.getLocalizedMessage());
        } finally {
            // Inform any status listeners that compilation of java source for this module is ended.
            informStatusListeners(StatusListener.SM_END_COMPILING_GENERATED_SOURCE, module.getName());
        }
    }
View Full Code Here

TOP

Related Classes of org.openquark.cal.internal.machine.CodeGenerationException

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.