| 48 | } |
| 49 | |
| 50 | static Record ApplyConsume(OpBase *opBase) { |
| 51 | Apply *op = (Apply *)opBase; |
| 52 | |
| 53 | while(true) { |
| 54 | if(op->r == NULL) { |
| 55 | // retrieve a Record from the bound branch |
| 56 | op->r = OpBase_Consume(op->bound_branch); |
| 57 | if(op->r == NULL) { |
| 58 | return NULL; // Bound branch and this op are depleted. |
| 59 | } |
| 60 | |
| 61 | // collect record for future freeing |
| 62 | array_append(op->records, op->r); |
| 63 | |
| 64 | // Successfully pulled a new Record, propagate to the top of the RHS branch. |
| 65 | if(op->op_arg) { |
| 66 | Argument_AddRecord(op->op_arg, OpBase_CloneRecord(op->r)); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // pull a Record from the RHS branch |
| 71 | Record rhs_record = OpBase_Consume(op->rhs_branch); |
| 72 | |
| 73 | if(rhs_record == NULL) { |
| 74 | // RHS branch depleted for the current bound Record |
| 75 | // free it and loop back to retrieve a new one |
| 76 | op->r = NULL; |
| 77 | // reset the RHS branch |
| 78 | OpBase_PropagateReset(op->rhs_branch); |
| 79 | continue; |
| 80 | } |
| 81 | |
| 82 | // clone the bound Record and merge the RHS Record into it |
| 83 | Record r = OpBase_CloneRecord(op->r); |
| 84 | Record_Merge(r, rhs_record); |
| 85 | // delete the RHS record, as it has been merged into r |
| 86 | OpBase_DeleteRecord(rhs_record); |
| 87 | |
| 88 | return r; |
| 89 | } |
| 90 | |
| 91 | return NULL; |
| 92 | } |
| 93 | |
| 94 | static OpResult ApplyReset(OpBase *opBase) { |
| 95 | Apply *op = (Apply *)opBase; |
nothing calls this directly
no test coverage detected