Skip to content

Commit

Permalink
implementing pull
Browse files Browse the repository at this point in the history
  • Loading branch information
jweinst1 committed May 10, 2018
1 parent c372aac commit 1d22b85
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
7 changes: 7 additions & 0 deletions include/WindBuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
wb = realloc(wb, WindBuf_SIZE(wb)); \
}

// Macro that checks if a size can fit in the buffer, and if it doesn't
// expands buffer by add
#define WindBuf_CHECK(wb, size, add) if((wb->cap - wb->len) < size) { \
wb->cap += add; \
wb = realloc(wb, WindBuf_SIZE(wb)); \
}

// Gets a typed pointer to some area of the buffer.
#define WindBuf_TPTR(wb, index, type) ((type*)(wb->data + index))

Expand Down
2 changes: 2 additions & 0 deletions include/WindLoad.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
static unsigned char WIND_BOOL_T[] = {WindType_Bool, 1};
static unsigned char WIND_BOOL_F[] = {WindType_Bool, 0};

void WindLoad_bool(WindStream* ws, BufKey bkey, int b);

#endif
1 change: 1 addition & 0 deletions include/WindRun.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdio.h>
#include "WindStream.h"
#include "WindExec.h"
#include "WindLoad.h"

// central header that handles running of code

Expand Down
20 changes: 19 additions & 1 deletion src/code/WindRun.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,27 @@ int WindRun_load(WindStream* ws, const char** code)
if((*code)[1] == 'r' && (*code)[2] == 'u' && (*code)[3] == 'e')
{
*code += 4;
// write bool
WindLoad_bool(ws, BufKey_load, 1);
continue;
}
else
{
WindStream_write_err(ws, "Expected argument or value, found 'T%c'", *code[1]);
return 0;
}
break;
case 'F':
if((*code)[1] == 'a' && (*code)[2] == 'l' && (*code)[3] == 's' && (*code)[4] == 'e')
{
*code += 5;
WindLoad_bool(ws, BufKey_load, 0);
continue;
}
else
{
WindStream_write_err(ws, "Expected argument or value, found 'F%c'", *code[1]);
return 0;
}
break;
case 'N':
switch((*code)[1])
Expand Down
10 changes: 10 additions & 0 deletions src/stream/WindLoad.c
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
#include "WindLoad.h"

void WindLoad_bool(WindStream* ws, BufKey bkey, int b)
{
WindBuf* buf = WindStream_get_buf(ws, bkey);
unsigned char* boolp = b ? WIND_BOOL_T : WIND_BOOL_F;
// size of bool buf is same for true and false.
WindBuf_CHECK(buf, sizeof(WIND_BOOL_T), 10);
buf->data[buf->len++] = boolp[0];
buf->data[buf->len++] = boolp[1];
}

0 comments on commit 1d22b85

Please sign in to comment.