Package org.openquark.cal.internal.machine.g

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


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

        // Evaluate the 3 arguments.
        NRecordValue recordDict = (NRecordValue) executor.internalEvaluate(arguments[0]);
        NValInt index = (NValInt) executor.internalEvaluate(arguments[1]);
        NRecordValue recordValue = (NRecordValue) executor.internalEvaluate(arguments[2]);
       
        int nFields = recordDict.getNFields();
       
        List<String> fieldNames = recordDict.fieldNames();

        NRecordValue result=new NRecordValue(nFields);
       
        int nParams = recordValue.getNFields();
       
        ArrayList<RecordParamHelper> paramSources = new ArrayList<RecordParamHelper>(nParams);
        for(int i=0; i<nParams; i++) {
            paramSources.add(RecordParamHelper.create(recordValue.getNthValue(i), executor));
        }
        for (int i = 0; i < nFields; ++i) {
           
            Node fieldDict = recordDict.getNthValue(i);           
            Node elem;

            if (index.getIntValue() == -1)
                elem = fieldDict;
            else
                elem = fieldDict.apply(index);
           
            //fill f's arguments using the param sources.
            for(RecordParamHelper param : paramSources) {
                elem = elem.apply(param.getNext(executor));
            }
            String fieldName = fieldNames.get(i);
            result= result.insertRecordField(fieldName, executor.internalEvaluate(elem));
        }
       
        return result;
    }
View Full Code Here


        //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.equals on
        //the values x.f and y.f. 
       
        // Evaluate the three arguments.
        NRecordValue recordDictionary = (NRecordValue) executor.internalEvaluate(arguments[0]);
        NRecordValue x = (NRecordValue) executor.internalEvaluate(arguments[1]);
        NRecordValue y = (NRecordValue) executor.internalEvaluate(arguments[2]);
       
        NValInt classMethodIndex = getIndexOfEqualsClassMethod(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);
           
            //compute "Prelude.equals valueDictionaryThunk xValueThunk yValueThunk"
            //this is just (after inlining Prelude.equals d = d classMethodIndex"
           
            if (!((NValBoolean)executor.internalEvaluate(valueDictionaryThunk.apply(classMethodIndex).apply(xValueThunk).apply(yValueThunk))).getBooleanValue()) {
View Full Code Here

  
    @Override
    public Node doEvaluation (Node[] arguments, Executor executor)
            throws CALExecutorException {
            
        final NRecordValue record = (NRecordValue) executor.internalEvaluate(arguments[0]);
      
        //we need to go through the fields of the record in field-name order
        final List<String> fieldNames = record.fieldNames();       
        final int nFields = fieldNames.size();
               
        for (int i = 0; i < nFields; ++i) {
           
            final String fieldName = fieldNames.get(i);
            final Node fieldValue = record.getValue(fieldName);
            final Node evaluatedFieldValue = executor.internalEvaluate(fieldValue);
            if (fieldValue != evaluatedFieldValue) {
                //remove indirections
                record.putValue(fieldName, evaluatedFieldValue);
            }
        }
       
        return record;      
    }   
View Full Code Here

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

        //insertTextualRecordFieldPrimitive recordValue fieldName fieldValue
        NRecordValue recordValue = (NRecordValue) executor.internalEvaluate(arguments[0]);
        String fieldName = (String)executor.internalEvaluate(arguments[1]).getValue();
        Node fieldValue = arguments[2];

        return recordValue.insertRecordField(fieldName, fieldValue);
    }
View Full Code Here

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

        // Evaluate the 3 arguments.
        NRecordValue recordDict = (NRecordValue) executor.internalEvaluate(arguments[0]);
        NValInt index = (NValInt) executor.internalEvaluate(arguments[1]);
        NRecordValue recordValue = (NRecordValue) executor.internalEvaluate(arguments[2]);
       
        int nFields = recordDict.getNFields();
       
        List<Node> result = new ArrayList<Node>(nFields);
       
        int nParams = recordValue.getNFields();
        ArrayList<RecordParamHelper> paramSources = new ArrayList<RecordParamHelper>(nParams);
        for(int i=0; i<nParams; i++) {
            paramSources.add(RecordParamHelper.create(recordValue.getNthValue(i), executor));
        }
        for (int i = 0; i < nFields; ++i) {
           
            Node fieldDict = recordDict.getNthValue(i);           
View Full Code Here

        //the value x.f. 
       
        checkShowRecordImplementation (executor);
       
        // Evaluat the two arguments.
        NRecordValue recordDictionary = (NRecordValue) executor.internalEvaluate(arguments[0]);
        NRecordValue x = (NRecordValue) executor.internalEvaluate(arguments[1]);
       
        List<String> fieldNames = recordDictionary.fieldNames();       
        int nFields = fieldNames.size();
       
        //tuple records (with 2 or more fields) are displayed using the parentheses notation where field-names are omitted.
        boolean isTuple = fieldNames.size() >= 2;
        for (int i = 1; isTuple && i <= fieldNames.size(); ++i) {
            String fieldName = fieldNames.get(i-1);
            if (!fieldName.equals("#"+i)) {
                isTuple = false;
            }
        }
       
        StringBuilder showResult = new StringBuilder();
        if (isTuple) {
            showResult.append ("(");
           
            for (int i = 0; i < nFields; ++i) {
                if (i > 0) {
                    showResult.append (", ");
                }
               
                //compute "Debug.show valueDictionaryThunk xValueThunk"
                //this is just (after inlining Debug.show d = d)
                //valueDictionaryThunk xValueThunk
               
                String fieldName = fieldNames.get(i);
                Node valueDictionaryThunk = recordDictionary.getValue(fieldName);
                Node xValueThunk = x.getValue(fieldName);
                Node ap = valueDictionaryThunk.apply (xValueThunk);
               
                String apResult = (String)(executor.internalEvaluate(ap).getValue());
               
                showResult.append(apResult);
            }
           
            showResult.append(")");
           
        } else {
            showResult.append ("{");
           
            for (int i = 0; i < nFields; ++i) {
                if (i > 0) {
                    showResult.append (", ");
                }
               
                String fieldName = fieldNames.get(i);
                showResult.append(fieldName).append(" = ");
               
                //compute "Debug.show valueDictionaryThunk xValueThunk"
                //this is just (after inlining Debug.show d = d)
                //valueDictionaryThunk xValueThunk
                Node valueDictionaryThunk = recordDictionary.getValue(fieldName);
                Node xValueThunk = x.getValue(fieldName);
                Node ap = new NAp(valueDictionaryThunk, xValueThunk);
               
                String apResult = (String)(executor.internalEvaluate(ap).getValue());
               
                showResult.append(apResult);
View Full Code Here

        //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.notEquals on
        //the values x.f and y.f. 
       
        // Evaluate the three arguments.
        NRecordValue recordDictionary = (NRecordValue) executor.internalEvaluate(arguments[0]);
        NRecordValue x = (NRecordValue) executor.internalEvaluate(arguments[1]);
        NRecordValue y = (NRecordValue) executor.internalEvaluate(arguments[2]);
       
        NValInt classMethodIndex = getIndexOfNotEqualsClassMethod(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);
           
            //compute "Prelude.equals valueDictionaryThunk xValueThunk yValueThunk"
            //this is just (after inlining Prelude.equals d = d classMethodIndex)
            //valueDictionaryThunk classMethodIndex xValueThunk yValueThunk
           
View Full Code Here

            throws CALExecutorException {

        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]);
        List<?> inputList = (List<?>)((NValObject)executor.internalEvaluate(arguments[1])).getValue();
        //we use an iterator since inputList may be a non-random access list such as a java.util.LinkedList.
        Iterator<?> inputListIterator = inputList.iterator();
       
        List<String> fieldNames = recordDictionary.fieldNames();       
        int nFields = fieldNames.size();       
       
        //check that the number of fields in the inputList is the same as the number of fields in the record.
        //without this check it is possible that inputList 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 != inputList.size()) {
            throw new IllegalArgumentException("A Java list of size " + inputList.size() + " cannot be input to a record with " + nFields + " fields.");
        }
       
        // Create a record value.
        NRecordValue newRecord = new NRecordValue (nFields);
       
        // The order of iteration over the fields is unimportant in this case, since there is no
        // evaluation being done.  We're just pushing suspensions into the NRecordValue node.
        for (int i = 0; i < nFields; ++i) {
            String fieldName = fieldNames.get(i);
            newRecord.putValue (fieldName, recordDictionary.getValue(fieldName).apply (new NValObject(inputListIterator.next())));
        }
       
        return newRecord;
    }
View Full Code Here

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

        //appendRecordPrimitive leftRecord rightRecord
        NRecordValue leftRecord = (NRecordValue) executor.internalEvaluate(arguments[0]);
        NRecordValue rightRecord = (NRecordValue) executor.internalEvaluate(arguments[1]);

        return leftRecord.appendRecord(rightRecord);
    }
View Full Code Here

TOP

Related Classes of org.openquark.cal.internal.machine.g.NRecordValue

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.