Skip to content

Commit

Permalink
implemented power ** type for map
Browse files Browse the repository at this point in the history
  • Loading branch information
jweinst1 committed Jun 17, 2018
1 parent b81b9af commit b6be781
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 10 deletions.
13 changes: 12 additions & 1 deletion include/LangInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@
#define LangInfo_REPL_INS "The Wind Programming Language REPL\nTo exit, simply enter 'exit'.\n"

#define LangInfo_HELP "The Wind Programming Language Help Guide\n \
map command: \n \
The map command transforms data through a flow of operations. \n \
It can be used with operations like +, - and more. \n \
__example__: push 5 5 -> map + 3 | * 3 -> out \n \
[ 24 24 ]\n \
push command: \n \
The push command appends data to the end of the active data. \n \
__example__: push 5 6 7 -> out \n \
[ 5 6 7 ]\n \
out command: \n \
The out command prints the entire active data to stdout. \n \
clr command: \n \
The clr command resets the active data.\n"
The clr command resets the active data.\n"

#endif
6 changes: 5 additions & 1 deletion include/WindComp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#define WindComp_MULTIPLY_NUM(val1, val2) *(double*)(val1) *= *(double*)(val2)

#define WindComp_POW_NUM(val1, val2) *(double*)(val1) = pow(*(double*)(val1),*(double*)(val2))

#define WindComp_LT_NUM(val1, val2) *(double*)(val1) < *(double*)(val2)

#define WindComp_GT_NUM(val1, val2) *(double*)(val1) > *(double*)(val2)
Expand Down Expand Up @@ -56,7 +58,9 @@ unsigned WindComp_apply_plus(unsigned char* args, const unsigned char* argsEnd);

unsigned WindComp_apply_minus(unsigned char* args, const unsigned char* argsEnd);

unsigned WindComp_apply_multiply(unsigned char* args, const unsigned char* argsEnd);
// Applies multiplication to the number in the comp buffer.
// Also can do the power operation.
unsigned WindComp_apply_multiply(unsigned char* args, const unsigned char* argsEnd, int powOp);

unsigned WindComp_apply_divide(unsigned char* args, const unsigned char* argsEnd);

Expand Down
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_pow(void);
void WindLoad_divide(void);
void WindLoad_del(void);
void WindLoad_lt(void);
Expand Down
1 change: 1 addition & 0 deletions include/WindType.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef enum
WindType_Minus,
WindType_Multiply,
WindType_Divide,
WindType_Pow,
WindType_Lt,
WindType_Gt,
WindType_Del,
Expand Down
15 changes: 12 additions & 3 deletions src/code/WindRun.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,18 @@ int WindRun_load(const char** code)
WindLoad_plus();
continue;
case '*':
*code += 1;
WindLoad_multiply();
continue;
if((*code)[1] == '*')
{
*code += 2;
WindLoad_pow();
continue;
}
else
{
*code += 1;
WindLoad_multiply();
continue;
}
case '/':
*code += 1;
WindLoad_divide();
Expand Down
2 changes: 2 additions & 0 deletions src/code/WindType.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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_POW = "Power";
static const char* WindType_STR_DIVIDE = "Divide";
static const char* WindType_STR_SEP = "Separator";
static const char* WindType_STR_DEL = "Delete";
Expand All @@ -30,6 +31,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_Pow: return WindType_STR_POW;
case WindType_Divide: return WindType_STR_DIVIDE;
case WindType_Del: return WindType_STR_DEL;
case WindType_Sep: return WindType_STR_SEP;
Expand Down
14 changes: 11 additions & 3 deletions src/flow/WindComp.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ unsigned WindComp_write_typed(const unsigned char* item)
case WindType_Plus:
case WindType_Minus:
case WindType_Multiply:
case WindType_Pow:
case WindType_Divide:
WindComp_BUF[0] = *item;
WindComp_ITEM_LEN = sizeof(unsigned char);
Expand Down Expand Up @@ -198,7 +199,7 @@ unsigned WindComp_apply_minus(unsigned char* args, const unsigned char* argsEnd)
return mover - args;
}

unsigned WindComp_apply_multiply(unsigned char* args, const unsigned char* argsEnd)
unsigned WindComp_apply_multiply(unsigned char* args, const unsigned char* argsEnd, int powOp)
{
if(WindComp_BUF[0] != WindType_Number)
{
Expand All @@ -212,7 +213,8 @@ unsigned WindComp_apply_multiply(unsigned char* args, const unsigned char* argsE
{
case WindType_Number:
mover++;
WindComp_MULTIPLY_NUM(WindComp_BODY, mover);
if(powOp) WindComp_POW_NUM(WindComp_BODY, mover);
else WindComp_MULTIPLY_NUM(WindComp_BODY, mover);
mover += sizeof(double);
break;
case WindType_Bool:
Expand Down Expand Up @@ -369,7 +371,13 @@ int WindComp_map(unsigned char* ins, const unsigned char* insEnd)
break;
case WindType_Multiply:
ins++;
moveChecker = WindComp_apply_multiply(ins, insEnd);
moveChecker = WindComp_apply_multiply(ins, insEnd, 0);
if(moveChecker) ins += moveChecker;
else return 0;
break;
case WindType_Pow:
ins++;
moveChecker = WindComp_apply_multiply(ins, insEnd, 1);
if(moveChecker) ins += moveChecker;
else return 0;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/flow/WindExec.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int WindExec_save(void)
WindState_write_err("File path '%s' cannot be written to.", savePath);
return 0;
}
printf("saved @ %s\n", savePath);
printf("Saved at: %s\n", savePath);
return 1;
}

Expand Down
6 changes: 6 additions & 0 deletions src/flow/WindLoad.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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_POW[] = {WindType_Pow};
static unsigned char WIND_DIVIDE[] = {WindType_Divide};
static unsigned char WIND_DEL[] = {WindType_Del};
static unsigned char WIND_LT[] = {WindType_Lt};
Expand Down Expand Up @@ -73,6 +74,11 @@ void WindLoad_multiply(void)
WindData_load_write(WIND_MULTIPLY, sizeof(WIND_MULTIPLY));
}

void WindLoad_pow(void)
{
WindData_load_write(WIND_POW, sizeof(WIND_POW));
}

void WindLoad_divide(void)
{
WindData_load_write(WIND_DIVIDE, sizeof(WIND_DIVIDE));
Expand Down
2 changes: 2 additions & 0 deletions src/util/DataUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ unsigned long DataUtil_copy(unsigned char* dest,
case WindType_Plus:
case WindType_Minus:
case WindType_Multiply:
case WindType_Pow:
case WindType_Divide:
*dest++ = *src++;
break;
Expand Down Expand Up @@ -64,6 +65,7 @@ int DataUtil_validate(const unsigned char* start, const unsigned char* end)
case WindType_Plus:
case WindType_Minus:
case WindType_Multiply:
case WindType_Pow:
case WindType_Divide:
start++;
break;
Expand Down
6 changes: 5 additions & 1 deletion src/util/IOUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ int IOUtil_print(const unsigned char* start, const unsigned char* end)
start++;
printf("* ");
break;
case WindType_Pow:
start++;
printf("** ");
break;
case WindType_Divide:
start++;
printf("/ ");
Expand Down Expand Up @@ -174,7 +178,7 @@ int IOUtil_load(const char* path)
fclose(loadFile);
exit(1);
}
fread(WindData_active_start(), sizeof(unsigned char), WindData_active_len(), loadFile);
fread(WindData_active_start(), sizeof(unsigned char), fSize, loadFile);
WindData_active_adv(fSize);
if(!DataUtil_validate(WindData_active_start(), WindData_active_ptr()))
{
Expand Down

0 comments on commit b6be781

Please sign in to comment.