Skip to content

Commit

Permalink
started divide type, implemented zero div guard for doubles.
Browse files Browse the repository at this point in the history
  • Loading branch information
jweinst1 committed Jun 11, 2018
1 parent f9f0577 commit 3ea4e2b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/WindLoad.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void WindLoad_assign(void);
void WindLoad_plus(void);
void WindLoad_minus(void);
void WindLoad_multiply(void);
void WindLoad_divide(void);
void WindLoad_del(void);
void WindLoad_lt(void);
void WindLoad_gt(void);
Expand Down
1 change: 1 addition & 0 deletions include/WindType.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef enum
WindType_Plus,
WindType_Minus,
WindType_Multiply,
WindType_Divide,
WindType_Lt,
WindType_Gt,
WindType_Del,
Expand Down
6 changes: 5 additions & 1 deletion src/code/WindRun.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ int WindRun_load(const char** code)
*code += 1;
WindLoad_multiply();
continue;
case '/':
*code += 1;
WindLoad_divide();
continue;
case '=':
// assign :symbol
*code += 1;
Expand Down Expand Up @@ -324,7 +328,7 @@ int WindRun_command(const char** code)
goto TRANS_TO_LOAD;
TRANS_TO_LOAD:
if(WindState_has_cmd()) WindState_set_mode(WindMode_load);
else return 1;
return 1;
}

void WindRun_code(const char* code)
Expand Down
2 changes: 2 additions & 0 deletions src/code/WindType.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ static const char* WindType_STR_NOT = "Not";
static const char* WindType_STR_PLUS = "Plus";
static const char* WindType_STR_MINUS = "Minus";
static const char* WindType_STR_MULTIPLY = "Multiply";
static const char* WindType_STR_DIVIDE = "Divide";
static const char* WindType_STR_SEP = "Separator";
static const char* WindType_STR_DEL = "Delete";
static const char* WindType_STR_LT = "LessThan";
Expand All @@ -27,6 +28,7 @@ const char* WindType_get_str(WindType type)
case WindType_Plus: return WindType_STR_PLUS;
case WindType_Minus: return WindType_STR_MINUS;
case WindType_Multiply: return WindType_STR_MULTIPLY;
case WindType_Divide: return WindType_STR_DIVIDE;
case WindType_Del: return WindType_STR_DEL;
case WindType_Sep: return WindType_STR_SEP;
case WindType_Lt: return WindType_STR_LT;
Expand Down
9 changes: 9 additions & 0 deletions src/flow/WindComp.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ unsigned WindComp_write_typed(const unsigned char* item)
case WindType_Plus:
case WindType_Minus:
case WindType_Multiply:
case WindType_Divide:
WindComp_BUF[0] = *item;
WindComp_ITEM_LEN = sizeof(unsigned char);
return WindComp_ITEM_LEN;
Expand All @@ -93,6 +94,14 @@ unsigned WindComp_read(void* dest)
return WindComp_ITEM_LEN;
}

// Guards against dividing by zero, defaults to division by 1
static inline
double _guard_div_zero(double lfs, double rfs)
{
if(rfs == 0) return lfs / 1;
else return lfs / rfs;
}

void WindComp_apply_not(void)
{
WindComp_ITEM_LEN = sizeof(unsigned char) + sizeof(unsigned char);
Expand Down
6 changes: 6 additions & 0 deletions src/flow/WindLoad.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static unsigned char WIND_SEP[] = {WindType_Sep};
static unsigned char WIND_PLUS[] = {WindType_Plus};
static unsigned char WIND_MINUS[] = {WindType_Minus};
static unsigned char WIND_MULTIPLY[] = {WindType_Multiply};
static unsigned char WIND_DIVIDE[] = {WindType_Divide};
static unsigned char WIND_DEL[] = {WindType_Del};
static unsigned char WIND_LT[] = {WindType_Lt};
static unsigned char WIND_GT[] = {WindType_Gt};
Expand Down Expand Up @@ -68,6 +69,11 @@ void WindLoad_multiply(void)
WindData_load_write(WIND_MULTIPLY, sizeof(WIND_MULTIPLY));
}

void WindLoad_divide(void)
{
WindData_load_write(WIND_DIVIDE, sizeof(WIND_DIVIDE));
}

void WindLoad_del(void)
{
WindData_load_write(WIND_DEL, sizeof(WIND_DEL));
Expand Down
4 changes: 4 additions & 0 deletions src/util/IOUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ int IOUtil_print(const unsigned char* start, const unsigned char* end)
start++;
printf("* ");
break;
case WindType_Divide:
start++;
printf("/ ");
break;
case WindType_Lt:
start++;
printf("< ");
Expand Down

0 comments on commit 3ea4e2b

Please sign in to comment.