Skip to content

Commit

Permalink
implemented reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
jweinst1 committed Jun 13, 2018
1 parent 6bd661e commit 73fa61f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/code/WindRun.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int WindRun_exec(const char** code)
WindExec_filter();
break;
case WindCommand_reduce:
// handle reduce
WindReduce_reduce();
break;
}
WindData_load_reset(); // Resets load buf.
Expand Down
17 changes: 15 additions & 2 deletions src/flow/WindReduce.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,29 @@ int WindReduce_plus(void)

// load first onto comp buffer
activeStart += WindComp_write_typed(activeStart);
if(*comp != WindType_Number)
{
// todo: String will be added
WindState_write_err("Attempted to reduce + on type: '%s'", WindType_get_str(*comp));
return 0;
}
WindData_inactive_reset();
while(activeStart != activeStop)
{
switch(*activeStart)
{
case WindType_Number:
activeStart++;
// todo: macros of these need to be in separate head.
*(double*)(compBody) += *(double*)(activeStart);
activeStart += sizeof(double);
break;
default:
WindState_write_err("Cannot perform reduce (+) with argument type: '%s'", WindType_get_str(*activeStart));
return 0;
}
}
WindData_inactive_write(WindComp_begin(), WindComp_get_len());
WindData_active_switch();
return 1;
}
Expand All @@ -31,8 +45,7 @@ int WindReduce_reduce(void)
switch(*reduceInst)
{
case WindType_Plus:
// calls plus reducer
return 1;
return WindReduce_plus();
default:
WindState_write_err("Cannot run reduce operation with instruction type: '%s'", WindType_get_str(*reduceInst));
return 0;
Expand Down

0 comments on commit 73fa61f

Please sign in to comment.