Examples of NRecordValue


Examples of org.openquark.cal.internal.machine.g.NRecordValue

    @Override
    public Node doEvaluation (Node[] arguments, Executor executor)
            throws CALExecutorException {
      
        // Evaluate the 3 arguments.
        NRecordValue recordDictionary = (NRecordValue) executor.internalEvaluate(arguments[0]);
        Node genParams = executor.internalEvaluate(arguments[1]);
        Node independent = executor.internalEvaluate(arguments[2]);
       
        NValInt arbitraryMethodIndex = getIndexOfGenerateClassMethod(executor);
      
        List<String> fieldNames = recordDictionary.fieldNames();
        final int nFields = fieldNames.size();

        NRecordValue result=new NRecordValue(nFields);

        /*
         * Loops through all fields in the record dictionary and
         * invokes the arbitrary class method to
         * construct each record field
         */
        for (int i = 0; i < nFields; ++i) {
            genParams=executor.internalEvaluate(independent.apply( new NValInt(i)).apply(genParams));
           
            String fieldName = fieldNames.get(i);
            Node valueDictionaryThunk = recordDictionary.getValue(fieldName);
           
            result= result.insertRecordField(fieldName,
                executor.internalEvaluate(valueDictionaryThunk.apply(arbitraryMethodIndex).apply(genParams)));
        }
       
        return result;
    }
View Full Code Here

Examples of org.openquark.cal.internal.machine.g.NRecordValue

    @Override
    public Node doEvaluation (Node[] arguments, Executor executor)
            throws CALExecutorException {

        //recordFieldValuePrimitive recordValue fieldIndex
        NRecordValue recordValue = (NRecordValue) executor.internalEvaluate(arguments[0]);
        NValInt fieldIndex = (NValInt) executor.internalEvaluate(arguments[1]);
       
        return recordValue.getNthValue(fieldIndex.getIntValue());
    }   
View Full Code Here

Examples of org.openquark.cal.internal.machine.g.NRecordValue

    @Override
    public Node doEvaluation (Node[] arguments, Executor executor)
            throws CALExecutorException {

        //recordFieldType recordDictionary recordValue
        NRecordValue recordDictionary = (NRecordValue) executor.internalEvaluate(arguments[0]);
       
        // Note that we have evaluated the record dictionary but NOT
        // the record value itself.
       
        return new NValObject(recordDictionary);
View Full Code Here

Examples of org.openquark.cal.internal.machine.g.NRecordValue

    public Node doEvaluation (Node[] arguments, Executor executor)
            throws CALExecutorException {

       
        // Evaluate the 3 arguments.
        NRecordValue recordDictionary = (NRecordValue) executor.internalEvaluate(arguments[0]);
        NRecordValue inputRecord = (NRecordValue) executor.internalEvaluate(arguments[1]);
        Node generator = executor.internalEvaluate(arguments[2]);
       
        NValInt coarbitraryMethodIndex = getIndexOfCoArbitraryClassMethod(executor);
      
        List<String> fieldNames = recordDictionary.fieldNames();
        final int nFields = fieldNames.size();

        Node result=generator;

        /*
         * loop through each element in the record and apply the coarbitrary
         * method to vary the input generator so that the resulting generator will be
         * depenedant on each of the fields in the input record.
         */
        for (int i = 0; i < nFields; ++i) {
           
            String fieldName = fieldNames.get(i);
            Node valueDictionaryThunk = recordDictionary.getValue(fieldName);
            Node value = inputRecord.getValue(fieldName);
           
            result=executor.internalEvaluate(valueDictionaryThunk.apply(coarbitraryMethodIndex).apply(value).apply(result));
        }
       
        return result;
View Full Code Here

Examples of org.openquark.cal.internal.machine.g.NRecordValue

        //the value x.f. 
       
        checkImplementation(executor);
       
        // The two arguments in evaluated form will be on top of the stack, in reverse order.
        NRecordValue recordDictionary = (NRecordValue) executor.internalEvaluate(arguments[0]);
        NRecordValue x = (NRecordValue) executor.internalEvaluate(arguments[1]);
       
        List<String> fieldNames = recordDictionary.fieldNames();       
        int nFields = fieldNames.size();
       
        RecordValue resultMap = RecordValueImpl.make();
        for (int i = 0; i < nFields; ++i) {
           
            String fieldName = fieldNames.get(i);
            Node valueDictionaryThunk = recordDictionary.getValue(fieldName);
            Node xValueThunk = x.getValue(fieldName);           
           
            //compute "Prelude.output valueDictionaryThunk xValueThunk"
            //this is just (after inlining Prelude.output d = d"
            //valueDictionaryThunk xValueThunk
           
View Full Code Here

Examples of org.openquark.cal.internal.machine.g.NRecordValue

        //the value x.f. 
       
        checkImplementation(executor);
       
        // The two arguments in evaluated form will be on top of the stack, in reverse order.
        NRecordValue recordDictionary = (NRecordValue) executor.internalEvaluate(arguments[0]);
        NRecordValue x = (NRecordValue) executor.internalEvaluate(arguments[1]);
       
        List<String> fieldNames = recordDictionary.fieldNames();       
        int nFields = fieldNames.size();
       
        List<Object> resultList = new ArrayList<Object>(nFields);
        for (int i = 0; i < nFields; ++i) {
           
            String fieldName = fieldNames.get(i);
            Node valueDictionaryThunk = recordDictionary.getValue(fieldName);
            Node xValueThunk = x.getValue(fieldName);           
           
            //compute "Prelude.output valueDictionaryThunk xValueThunk"
            //this is just (after inlining Prelude.output d = d"
            //valueDictionaryThunk xValueThunk
           
View Full Code Here

Examples of org.openquark.cal.internal.machine.g.NRecordValue

        //we iterate in FieldName order over the field names so that the function is well-defined in the presence of side effects.
        //If f is a field, then recordDictionary.f is the dictionary for use when calling the class method Prelude.compare on
        //the values x.f and y.f. 
       
        // The three arguments in evaluated form will be on top of the stack, in reverse order.
        NRecordValue recordDictionary = (NRecordValue) executor.internalEvaluate(arguments[0]);
        NRecordValue x = (NRecordValue) executor.internalEvaluate(arguments[1]);
        NRecordValue y = (NRecordValue) executor.internalEvaluate(arguments[2]);
       
        // Get the index of the compare class method in the Ord type class.
        Node classMethodIndex = getIndexOfCompareClassMethod(executor);
       
        List<String> fieldNames = recordDictionary.fieldNames();
        final int nFields = fieldNames.size();
       
        for (int i = 0; i < nFields; ++i) {
           
            String fieldName = fieldNames.get(i);
            Node valueDictionaryThunk = recordDictionary.getValue(fieldName);
            Node xValueThunk = x.getValue(fieldName);
            Node yValueThunk = y.getValue(fieldName);
           
            Node ap = valueDictionaryThunk.apply(classMethodIndex).apply(xValueThunk).apply(yValueThunk);
           
            int compareResult = executor.internalEvaluate(ap).getOrdinalValue ();
           
View Full Code Here

Examples of org.openquark.cal.internal.machine.g.NRecordValue

    @Override
    public Node doEvaluation (Node[] arguments, Executor executor)
            throws CALExecutorException {

        //extendRecordOrdinalPrimitive recordValue fieldName fieldValue
        NRecordValue recordValue = (NRecordValue) executor.internalEvaluate(arguments[0]);
        int fieldOrdinal = ((NValInt)executor.internalEvaluate(arguments[1])).getIntValue();
        String fieldName = "#" + fieldOrdinal;
        Node fieldValue = arguments[2];
       
        return recordValue.insertRecordField(fieldName, fieldValue);
    }
View Full Code Here

Examples of org.openquark.cal.internal.machine.g.NRecordValue

    @Override
    public Node doEvaluation (Node[] arguments, Executor executor)
            throws CALExecutorException {

        //recordFieldType recordDictionary recordValue fieldIndex
        NRecordValue recordDictionary = (NRecordValue) executor.internalEvaluate(arguments[0]);
        NValInt fieldIndex = (NValInt) executor.internalEvaluate(arguments[2]);
       
        // Note that we have evaluated the record dictionary and the field index, but NOT
        // the record value itself.
       
        return recordDictionary.getNthValue(fieldIndex.getIntValue()).apply(boolean_false);
    }
View Full Code Here

Examples of org.openquark.cal.internal.machine.g.NRecordValue

            throws CALExecutorException {

        checkInputRecordImplementation(executor);
       
        // The two arguments in evaluated form will be on top of the stack, in reverse order.
        final NRecordValue recordDictionary = (NRecordValue) executor.internalEvaluate(arguments[0]);
                             
        //inputMap, but with the keys sorted in FieldName order.
        final SortedMap<?, ?> fieldNameSortedInputMap;
        {
            final Map<?, ?> inputMap = (Map<?, ?>)((NValObject)executor.internalEvaluate(arguments[1])).getValue();      
               
            //In the case when inputMap is in fact a SortedMap that is using the comparator on the keys, then we can just use it directly.
            //We still need to verify that the keys are in fact FieldNames, but that will be done later. 
            //Otherwise we need to copy the map to get a proper iteration order.           
            if (inputMap instanceof SortedMap && ((SortedMap<?, ?>)inputMap).comparator() == null) {           
                fieldNameSortedInputMap = (SortedMap<?, ?>)inputMap;           
            } else {
                fieldNameSortedInputMap = new TreeMap<Object, Object>(inputMap);
            }
        }
       
        final List<String> fieldNames = recordDictionary.fieldNames();       
        final int nFields = fieldNames.size();       
       
        //check that the number of fields in the input map is the same as the number of fields in the record.
        //without this check it is possible that input map could have more elements than the size of the record and still succeed.
        //This would still "work" but this check is useful to alert clients to potential bugs in their code.
        if (nFields != fieldNameSortedInputMap.size()) {
            throw new IllegalArgumentException("A Java list of size " + fieldNameSortedInputMap.size() + " cannot be input to a record with " + nFields + " fields.");
        }
       
                                      
        final Iterator<?> iterator = fieldNameSortedInputMap.entrySet().iterator();
       
        // Create a record value.
        final NRecordValue newRecord = new NRecordValue (nFields);
       
        // The order of iteration over the fields is only import to check that fieldnames from the input map and from the record dictionary
        //(i.e. the CAL type) are the same. Evaluation is not being done.  We're just pushing suspensions into the NRecordValue node.
        for (int i = 0; i < nFields; ++i) {
            final Map.Entry<?, ?> entry = (Map.Entry<?, ?>)iterator.next();
            final String fieldNameFromInputMap = ((FieldName)entry.getKey()).getCalSourceForm();                             
            final String fieldName = fieldNames.get(i);
            if (!fieldNameFromInputMap.equals(fieldName)) {
                throw new IllegalArgumentException("The field names of the input map and target record must match exactly.");
            }           
            newRecord.putValue (fieldName, recordDictionary.getValue(fieldName).apply (new NValObject(entry.getValue())));
        }
       
        return newRecord;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.