can compile again

master
Clyne 5 years ago
parent a93654c1de
commit 2f506168a1

@ -18,14 +18,14 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# #
CFLAGS = -ggdb -fsigned-char -fno-builtin -Wall -Wextra -Werror -pedantic CFLAGS = -ggdb -Wall -Wextra -pedantic #-Werror
CFILES = $(wildcard *.c) CFILES = $(wildcard *.c)
all: all:
@echo $(CFILES) @echo $(CFILES)
@gcc -m32 $(CFLAGS) $(CFILES) -o shell @g++ $(CFLAGS) $(CFILES) -o shell
arm: arm:
@arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 $(CFLAGS) -c *.c @g++ $(CFLAGS) -c *.c
@arm-none-eabi-ar r libinterp.a *.o @ar r libinterp.a *.o
@rm *.o @rm *.o

@ -34,20 +34,21 @@
#include "builtins.h" #include "builtins.h"
#include <memory.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define IF_SIG (uint32_t)-1 #define IF_SIG (size_t)-1
#define WHILE_SIG (uint32_t)-2 #define WHILE_SIG (size_t)-2
#define ELSE_SIG (uint32_t)-3 #define ELSE_SIG (size_t)-3
#define FUNC_SIG (uint32_t)-4 #define FUNC_SIG (size_t)-4
variable bopen = { variable bopen = {
0, CFUNC, 0, 0, {.p = (uint32_t)bracket_open} 0, CFUNC, 0, 0, {.p = (size_t)bracket_open}
}; };
variable bclose = { variable bclose = {
0, CFUNC, 0, 0, {.p = (uint32_t)bracket_close} 0, CFUNC, 0, 0, {.p = (size_t)bracket_close}
}; };
int bn_if(instance *it); int bn_if(instance *it);
@ -102,7 +103,7 @@ int bracket_close(instance *it)
int bn_if(instance *it) int bn_if(instance *it)
{ {
variable *cond = (variable *)ipop(it); variable *cond = (variable *)ipop(it);
uint32_t result = cond->value.p; size_t result = cond->value.p;
ipush(it, result); ipush(it, result);
ipush(it, IF_SIG); ipush(it, IF_SIG);
@ -114,10 +115,10 @@ int bn_if(instance *it)
return 0; return 0;
} }
static uint32_t if_cond = 0; static size_t if_cond = 0;
int bn_else(instance *it) int bn_else(instance *it)
{ {
uint32_t cond = if_cond; size_t cond = if_cond;
if (cond != 0) if (cond != 0)
it->sindent = SKIP | it->indent; it->sindent = SKIP | it->indent;
ipush(it, ELSE_SIG); ipush(it, ELSE_SIG);
@ -135,12 +136,12 @@ int bn_else(instance *it)
*/ */
int bn_end(instance *it) int bn_end(instance *it)
{ {
uint32_t sig = ipop(it); size_t sig = ipop(it);
if (sig == IF_SIG) { if (sig == IF_SIG) {
if_cond = ipop(it); if_cond = ipop(it);
} else if (sig == WHILE_SIG) { } else if (sig == WHILE_SIG) {
uint32_t lnidx = ipop(it); size_t lnidx = ipop(it);
if (lnidx != (uint32_t)-1) if (lnidx != (size_t)-1)
it->lnidx = lnidx - 1; it->lnidx = lnidx - 1;
} else if (sig == CALL_SIG) { } else if (sig == CALL_SIG) {
it->lnidx = ipop(it); it->lnidx = ipop(it);
@ -152,11 +153,11 @@ int bn_end(instance *it)
int bn_while(instance *it) int bn_while(instance *it)
{ {
variable *cond = (variable *)ipop(it); variable *cond = (variable *)ipop(it);
uint32_t result = cond->value.p; size_t result = cond->value.p;
if (result == 0) { if (result == 0) {
it->sindent = SKIP | it->indent; it->sindent = SKIP | it->indent;
ipush(it, (uint32_t)-1); ipush(it, (size_t)-1);
} else { } else {
ipush(it, it->lnidx); ipush(it, it->lnidx);
} }
@ -182,7 +183,7 @@ int bn_solve(instance *it)
variable *s = igetarg(it, 0); variable *s = igetarg(it, 0);
variable **ops = iparse(it, (const char *)s->value.p); variable **ops = iparse(it, (const char *)s->value.p);
if (ops == 0) { if (ops == 0) {
ipush(it, (uint32_t)make_varf(0, 0.0f)); ipush(it, (size_t)make_varf(0, 0.0f));
// return zero, don't let bad solves break the script // return zero, don't let bad solves break the script
return 0; return 0;
} }
@ -190,7 +191,7 @@ int bn_solve(instance *it)
variable *a = isolve(it, ops, 0); variable *a = isolve(it, ops, 0);
free(ops); free(ops);
ipush(it, (uint32_t)a); ipush(it, (size_t)a);
return 0; return 0;
} }
@ -198,12 +199,12 @@ int bn_array(instance *it)
{ {
variable *a = igetarg(it, 0); variable *a = igetarg(it, 0);
int size = igetarg(it, 1)->value.f; int size = igetarg(it, 1)->value.f;
uint32_t i0 = a->value.p; size_t i0 = a->value.p;
variable *array = calloc(size, sizeof(variable)); variable *array = (variable *)calloc(size, sizeof(variable));
array[0].type = a->type; array[0].type = a->type;
array[0].value.p = i0; array[0].value.p = i0;
a->array = size; a->array = size;
a->value.p = (uint32_t)array; a->value.p = (size_t)array;
return 0; return 0;
} }
@ -215,7 +216,7 @@ int bn_size(instance *it)
f = strlen((char *)a->value.p); f = strlen((char *)a->value.p);
else else
f = a->array; f = a->array;
ipush(it, (uint32_t)make_varf(0, f)); ipush(it, (size_t)make_varf(0, f));
return 0; return 0;
} }
@ -229,23 +230,23 @@ int bn_append(instance *it)
if (b->type == NUMBER) { if (b->type == NUMBER) {
int len = strlen((char *)a->value.p); int len = strlen((char *)a->value.p);
char *newstr = malloc(len + 2); char *newstr = (char *)malloc(len + 2);
memcpy(newstr, (char *)a->value.p, len); memcpy(newstr, (char *)a->value.p, len);
newstr[len] = b->value.f; newstr[len] = b->value.f;
newstr[len + 1] = '\0'; newstr[len + 1] = '\0';
free((void *)a->value.p); free((void *)a->value.p);
a->value.p = (uint32_t)newstr; a->value.p = (size_t)newstr;
} else if (b->type == STRING) { } else if (b->type == STRING) {
int len1 = strlen((char *)a->value.p); int len1 = strlen((char *)a->value.p);
int len2 = strlen((char *)b->value.p); int len2 = strlen((char *)b->value.p);
char *newstr = malloc(len1 + len2); char *newstr = (char *)malloc(len1 + len2);
memcpy(newstr, (char *)a->value.p, len1); memcpy(newstr, (char *)a->value.p, len1);
memcpy(newstr + len1, (char *)b->value.p, len2); memcpy(newstr + len1, (char *)b->value.p, len2);
newstr[len1 + len2] = '\0'; newstr[len1 + len2] = '\0';
free((void *)a->value.p); free((void *)a->value.p);
a->value.p = (uint32_t)newstr; a->value.p = (size_t)newstr;
} }
ipush(it, (uint32_t)a); ipush(it, (size_t)a);
return 0; return 0;
} }

@ -24,8 +24,8 @@
#include "parser.h" #include "parser.h"
#define SKIP_SIG (uint32_t)-5 #define SKIP_SIG (size_t)-5
#define CALL_SIG (uint32_t)-6 #define CALL_SIG (size_t)-6
// open bracket 'operator', for use in a compiled line // open bracket 'operator', for use in a compiled line
extern variable bopen; extern variable bopen;

12
ops.c

@ -36,7 +36,7 @@
#include <stdlib.h> #include <stdlib.h>
#define OP_DEF(o) int op_##o(variable **r, variable *a, variable *b) #define OP_DEF(o) int op_##o(variable **r, variable *a, variable *b)
#define OP_VAR(o) {0, OPERATOR, 0, 0, {.p = (uint32_t)op_##o}} #define OP_VAR(o) {0, OPERATOR, 0, 0, {.p = (size_t)op_##o}}
#define OP_NONE {0, OPERATOR, 0, 0, {.p = 0x0BADCAFE}} #define OP_NONE {0, OPERATOR, 0, 0, {.p = 0x0BADCAFE}}
OP_DEF(idx); OP_DEF(idx);
@ -87,7 +87,7 @@ const char *opnames[] = {
variable *igetop(const char *name, int *retlen) variable *igetop(const char *name, int *retlen)
{ {
for (uint32_t i = 0; i < OPS_COUNT; i++) { for (size_t i = 0; i < OPS_COUNT; i++) {
if (opnames[i] == 0) if (opnames[i] == 0)
continue; continue;
int len = strlen(opnames[i]); int len = strlen(opnames[i]);
@ -130,9 +130,9 @@ OP_DEF(idx)
int idx = b->value.f; int idx = b->value.f;
if (idx >= a->array) { if (idx >= a->array) {
variable *newarray = calloc(idx + 1, sizeof(variable)); variable *newarray = (variable *)calloc(idx + 1, sizeof(variable));
void *old = (void *)a->value.p; void *old = (void *)a->value.p;
a->value.p = (uint32_t)memcpy(newarray, (variable *)a->value.p, a->value.p = (size_t)memcpy(newarray, (variable *)a->value.p,
a->array * sizeof(variable)); a->array * sizeof(variable));
free(old); free(old);
a->array = idx + 1; a->array = idx + 1;
@ -285,9 +285,9 @@ OP_DEF(set)
} else if (b->type == STRING) { } else if (b->type == STRING) {
a->type = STRING; a->type = STRING;
free((void *)a->value.p); free((void *)a->value.p);
a->value.p = (uint32_t)strclone((char *)b->value.p); a->value.p = (size_t)strclone((char *)b->value.p);
(*r)->type = STRING; (*r)->type = STRING;
(*r)->value.p = (uint32_t)strclone((char *)a->value.p); (*r)->value.p = (size_t)strclone((char *)a->value.p);
} else { } else {
return seterror(EBADPARAM); return seterror(EBADPARAM);
} }

@ -28,6 +28,7 @@
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
/** /**
* Limitations for an instance. TODO make dynamic (no limits). * Limitations for an instance. TODO make dynamic (no limits).
@ -61,7 +62,7 @@ instance *inewinstance(void)
instance *it = (instance *)malloc(sizeof(instance)); instance *it = (instance *)malloc(sizeof(instance));
it->vars = (variable *)calloc(MAX_VARS, sizeof(variable)); it->vars = (variable *)calloc(MAX_VARS, sizeof(variable));
it->names = (char **)calloc(MAX_VARS, sizeof(char *)); it->names = (char **)calloc(MAX_VARS, sizeof(char *));
it->stack = (uint32_t *)malloc(MAX_STACK * sizeof(uint32_t)); it->stack = (size_t *)malloc(MAX_STACK * sizeof(size_t));
it->stidx = 0; it->stidx = 0;
it->lines = (variable ***)calloc(MAX_LINES, sizeof(variable **)); it->lines = (variable ***)calloc(MAX_LINES, sizeof(variable **));
it->lnidx = 0; it->lnidx = 0;
@ -78,7 +79,7 @@ void idelinstance(instance *it)
{ {
itryfree(it->ret); itryfree(it->ret);
for (uint32_t i = 0; i < MAX_LINES; i++) { for (size_t i = 0; i < MAX_LINES; i++) {
if (it->lines[i] == 0) if (it->lines[i] == 0)
continue; continue;
@ -87,7 +88,7 @@ void idelinstance(instance *it)
} }
free(it->lines); free(it->lines);
for (uint32_t i = 0; i < MAX_VARS; i++) { for (size_t i = 0; i < MAX_VARS; i++) {
if (it->vars[i].type == STRING || it->vars[i].array > 0) if (it->vars[i].type == STRING || it->vars[i].array > 0)
free((void *)it->vars[i].value.p); free((void *)it->vars[i].value.p);
free(it->names[i]); free(it->names[i]);
@ -104,7 +105,7 @@ void idelline(variable **ops)
for (int j = 0; j < 32; j++) { for (int j = 0; j < 32; j++) {
variable *v = ops[j]; variable *v = ops[j];
if (v != 0) { if (v != 0) {
if (((uint32_t)v & OP_MAGIC) == OP_MAGIC) if (((size_t)v & OP_MAGIC) == OP_MAGIC)
continue; continue;
if (v->type == FUNC || v->type == CFUNC) if (v->type == FUNC || v->type == CFUNC)
@ -120,22 +121,22 @@ void idelline(variable **ops)
// stack operations // stack operations
// //
void ipush(instance *it, uint32_t v) void ipush(instance *it, size_t v)
{ {
it->stack[it->stidx++] = v; it->stack[it->stidx++] = v;
} }
uint32_t ipop(instance *it) size_t ipop(instance *it)
{ {
return it->stack[--it->stidx]; return it->stack[--it->stidx];
} }
void ipopm(instance *it, uint32_t count) void ipopm(instance *it, size_t count)
{ {
it->stidx -= count; it->stidx -= count;
} }
variable *igetarg(instance *it, uint32_t n) variable *igetarg(instance *it, size_t n)
{ {
return (variable *)it->stack[it->stidx - n - 1]; return (variable *)it->stack[it->stidx - n - 1];
} }
@ -147,7 +148,7 @@ variable *igetarg(instance *it, uint32_t n)
variable *igetvar(instance *it, const char *name) variable *igetvar(instance *it, const char *name)
{ {
if (isalpha(name[0])) { if (isalpha(name[0])) {
for (uint32_t i = 0; i < MAX_VARS; i++) { for (size_t i = 0; i < MAX_VARS; i++) {
if (it->names[i] == 0) { if (it->names[i] == 0) {
it->names[i] = strclone(name); it->names[i] = strclone(name);
// default to 0 float // default to 0 float
@ -165,7 +166,7 @@ void inew_cfunc(instance *it, const char *name, func_t func)
{ {
variable *v = igetvar(it, name); variable *v = igetvar(it, name);
v->type = CFUNC; v->type = CFUNC;
v->value.p = (uint32_t)func; v->value.p = (size_t)func;
} }
void inew_number(instance *it, const char *name, float f) void inew_number(instance *it, const char *name, float f)
@ -179,7 +180,7 @@ void inew_string(instance *it, const char *name, const char *s)
{ {
variable *v = igetvar(it, name); variable *v = igetvar(it, name);
v->type = STRING; v->type = STRING;
v->value.p = (uint32_t)strclone(s); v->value.p = (size_t)strclone(s);
} }
int iaddline(instance *it, const char *s) int iaddline(instance *it, const char *s)
@ -207,7 +208,7 @@ loop:
for (int i = 0; i < 32; i++) { for (int i = 0; i < 32; i++) {
variable *v = it->lines[it->lnidx][i]; variable *v = it->lines[it->lnidx][i];
if (v != 0) { if (v != 0) {
if (((uint32_t)v & OP_MAGIC) == OP_MAGIC) { if (((size_t)v & OP_MAGIC) == OP_MAGIC) {
copy[i] = v; copy[i] = v;
continue; continue;
} }
@ -235,7 +236,7 @@ loop:
free((void *)ret->value.p); free((void *)ret->value.p);
ret->type = it->ret->type; ret->type = it->ret->type;
if (ret->type == STRING) if (ret->type == STRING)
ret->value.p = (uint32_t)strclone((char *)it->ret->value.p); ret->value.p = (size_t)strclone((char *)it->ret->value.p);
else else
ret->value.p = it->ret->value.p; ret->value.p = it->ret->value.p;
itryfree(it->ret); itryfree(it->ret);
@ -251,17 +252,17 @@ loop:
return 0; return 0;
} }
variable *isolve_(instance *it, variable **ops, uint32_t count); variable *isolve_(instance *it, variable **ops, size_t count);
variable *isolve(instance *it, variable **ops, uint32_t count) variable *isolve(instance *it, variable **ops, size_t count)
{ {
if (count == 0) if (count == 0)
for (count = 0; ops[count] != 0; count++); for (count = 0; ops[count] != 0; count++);
for (uint32_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
if (((uint32_t)ops[i] & OP_MAGIC) == OP_MAGIC) { if (((size_t)ops[i] & OP_MAGIC) == OP_MAGIC) {
uint32_t count_ = (uint32_t)ops[i] & 0xFF; size_t count_ = (size_t)ops[i] & 0xFF;
ops[i] = isolve(it, ops + i + 1, count_); ops[i] = isolve(it, ops + i + 1, count_);
for (uint32_t j = 1; j <= count_; j++) for (size_t j = 1; j <= count_; j++)
ops[i + j] = 0; ops[i + j] = 0;
} }
} }
@ -269,15 +270,15 @@ variable *isolve(instance *it, variable **ops, uint32_t count)
return isolve_(it, ops, count); return isolve_(it, ops, count);
} }
variable *isolve_(instance *it, variable **ops, uint32_t count) variable *isolve_(instance *it, variable **ops, size_t count)
{ {
// first, look for functions // first, look for functions
for (uint32_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
if (ops[i] == 0) if (ops[i] == 0)
continue; continue;
if (ops[i]->type == CFUNC || ops[i]->type == FUNC) { if (ops[i]->type == CFUNC || ops[i]->type == FUNC) {
uint32_t nargs = (uint32_t)ops[i + 1] - 1; size_t nargs = (size_t)ops[i + 1] - 1;
uint32_t start = i; size_t start = i;
i++; i++;
if (nargs > 0) if (nargs > 0)
i++; i++;
@ -285,7 +286,7 @@ variable *isolve_(instance *it, variable **ops, uint32_t count)
for (j = nargs; j > 0 && i < count; i++) { for (j = nargs; j > 0 && i < count; i++) {
if (ops[i] != 0) { if (ops[i] != 0) {
if (ops[start]->type == CFUNC) { if (ops[start]->type == CFUNC) {
it->stack[it->stidx + j - 1] = (uint32_t)ops[i]; it->stack[it->stidx + j - 1] = (size_t)ops[i];
} else { } else {
char namebuf[6]; char namebuf[6];
snprintf(namebuf, 6, "arg%u", snprintf(namebuf, 6, "arg%u",
@ -306,7 +307,7 @@ variable *isolve_(instance *it, variable **ops, uint32_t count)
func_t func = (func_t)ops[start]->value.p; func_t func = (func_t)ops[start]->value.p;
it->stidx += nargs; it->stidx += nargs;
uint32_t sidx = it->stidx; size_t sidx = it->stidx;
int ret = 0; int ret = 0;
if (!(it->sindent & SKIP) || (func == bracket_open || if (!(it->sindent & SKIP) || (func == bracket_open ||
func == bracket_close)) func == bracket_close))
@ -326,7 +327,7 @@ variable *isolve_(instance *it, variable **ops, uint32_t count)
} }
ops[start + 1] = 0; ops[start + 1] = 0;
for (uint32_t j = start + 2; j < i; j++) { for (size_t j = start + 2; j < i; j++) {
itryfree(ops[j]); itryfree(ops[j]);
ops[j] = 0; ops[j] = 0;
} }
@ -334,23 +335,23 @@ variable *isolve_(instance *it, variable **ops, uint32_t count)
} }
// next, operators // next, operators
for (uint32_t j = 0; j < OPS_COUNT; j += 2) { for (size_t j = 0; j < OPS_COUNT; j += 2) {
for (uint32_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
if (ops[i] == 0) if (ops[i] == 0)
continue; continue;
if (ops[i]->type == OPERATOR) { if (ops[i]->type == OPERATOR) {
if (ops[i]->value.p != (uint32_t)opvars[j].value.p) { if (ops[i]->value.p != (size_t)opvars[j].value.p) {
if (ops[i]->value.p != (uint32_t)opvars[j + 1].value.p) if (ops[i]->value.p != (size_t)opvars[j + 1].value.p)
continue; continue;
} }
opfunc_t func = (opfunc_t)ops[i]->value.p; opfunc_t func = (opfunc_t)ops[i]->value.p;
uint32_t aidx = i - 1; size_t aidx = i - 1;
while (ops[aidx] == 0 && aidx != 0) while (ops[aidx] == 0 && aidx != 0)
aidx--; aidx--;
if (ops[aidx] == 0) if (ops[aidx] == 0)
return 0; return 0;
uint32_t bidx = i + 1; size_t bidx = i + 1;
while (ops[bidx] == 0 && ++bidx < count); while (ops[bidx] == 0 && ++bidx < count);
if (bidx >= count) if (bidx >= count)
return 0; return 0;
@ -373,7 +374,7 @@ variable *isolve_(instance *it, variable **ops, uint32_t count)
// implicit multiply // implicit multiply
/*if (ops[0] != 0 && ops[0]->type == NUMBER) { /*if (ops[0] != 0 && ops[0]->type == NUMBER) {
for (uint32_t i = 1; i < count; i++) { for (size_t i = 1; i < count; i++) {
if (ops[i] != 0 && ops[i]->type == NUMBER) if (ops[i] != 0 && ops[i]->type == NUMBER)
ops[0]->value.f *= ops[i]->value.f; ops[0]->value.f *= ops[i]->value.f;
} }
@ -385,7 +386,7 @@ variable *isolve_(instance *it, variable **ops, uint32_t count)
variable **iparse(instance *it, const char *s) variable **iparse(instance *it, const char *s)
{ {
variable **ops = 0; variable **ops = 0;
uint32_t ooffset = 0; size_t ooffset = 0;
int32_t boffset = 1; int32_t boffset = 1;
size_t offset = 0; size_t offset = 0;
uint8_t prevNum = 0; uint8_t prevNum = 0;
@ -414,23 +415,23 @@ variable **iparse(instance *it, const char *s)
while (isblank(s[end])) while (isblank(s[end]))
end++; end++;
if (s[end] == '(') { if (s[end] == '(') {
uint32_t argidx = ooffset; size_t argidx = ooffset;
uint32_t argcount = 1; size_t argcount = 1;
ooffset++; ooffset++;
end++; end++;
uint32_t last = end; size_t last = end;
for (int c = 0; c >= 0; end++) { for (int c = 0; c >= 0; end++) {
if (s[end] == '(') if (s[end] == '(')
c++; c++;
if (c == 0 && last != end && (s[end] == ',' || s[end] == ')' || s[end] == '\0')) { if (c == 0 && last != end && (s[end] == ',' || s[end] == ')' || s[end] == '\0')) {
argcount++; argcount++;
char *arg = strnclone(s + last, end - last); char *arg = strnclone(s + last, end - last);
uint32_t parenidx = ooffset; size_t parenidx = ooffset;
ooffset++; ooffset++;
variable **moreops = iparse(it, arg); variable **moreops = iparse(it, arg);
uint32_t count = 0; size_t count = 0;
if (moreops != 0) { if (moreops != 0) {
for (uint32_t i = 0; moreops[i] != 0; count++, i++) for (size_t i = 0; moreops[i] != 0; count++, i++)
ops[ooffset++] = moreops[i]; ops[ooffset++] = moreops[i];
free(moreops); free(moreops);
} }
@ -478,12 +479,12 @@ variable **iparse(instance *it, const char *s)
} }
i++; i++;
char *word = strnclone(s + offset + 1, i - offset - 2); char *word = strnclone(s + offset + 1, i - offset - 2);
uint32_t parenidx = ooffset; size_t parenidx = ooffset;
ooffset++; ooffset++;
variable **moreops = iparse(it, word); variable **moreops = iparse(it, word);
uint32_t count = 0; size_t count = 0;
if (moreops != 0) { if (moreops != 0) {
for (uint32_t i = 0; moreops[i] != 0; count++, i++) for (size_t i = 0; moreops[i] != 0; count++, i++)
ops[ooffset++] = moreops[i]; ops[ooffset++] = moreops[i];
free(moreops); free(moreops);
} }
@ -492,8 +493,8 @@ variable **iparse(instance *it, const char *s)
offset = i; offset = i;
prevNum += 2; prevNum += 2;
} else if (s[offset] == '[') { } else if (s[offset] == '[') {
/*uint32_t i = offset + 1; /*size_t i = offset + 1;
uint32_t j = i; size_t j = i;
while (s[offset] != ']') { while (s[offset] != ']') {
if (s[offset] == ';') { if (s[offset] == ';') {

@ -32,10 +32,10 @@
typedef struct { typedef struct {
variable *vars; /**< An array of defined variables */ variable *vars; /**< An array of defined variables */
char **names; /**< An array of names for the variables */ char **names; /**< An array of names for the variables */
uint32_t *stack; /**< The instance's stack */ size_t *stack; /**< The instance's stack */
uint32_t stidx; /**< The instance's position in the stack */ size_t stidx; /**< The instance's position in the stack */
variable ***lines; /**< Compiled data for each line of script */ variable ***lines; /**< Compiled data for each line of script */
uint32_t lnidx; /**< Position in script/line being run */ size_t lnidx; /**< Position in script/line being run */
variable *ret; /**< Pointer to the last returned variable */ variable *ret; /**< Pointer to the last returned variable */
uint8_t indent; /**< Current indent/scope of the instance */ uint8_t indent; /**< Current indent/scope of the instance */
uint8_t sindent; /**< Indent of scope to skip, for false conditionals */ uint8_t sindent; /**< Indent of scope to skip, for false conditionals */
@ -99,14 +99,14 @@ void inew_number(instance *it, const char *name, float f);
* @param it the current instance * @param it the current instance
* @return the popped value * @return the popped value
*/ */
uint32_t ipop(instance *it); size_t ipop(instance *it);
/** /**
* Pushes a word to the instance's stack. * Pushes a word to the instance's stack.
* @param it the current instance * @param it the current instance
* @param v the word to push * @param v the word to push
*/ */
void ipush(instance *it, uint32_t v); void ipush(instance *it, size_t v);
/** /**
* Gets the nth argument passed to the current C function. * Gets the nth argument passed to the current C function.
@ -115,7 +115,7 @@ void ipush(instance *it, uint32_t v);
* @param n the index of the argument, zero-based * @param n the index of the argument, zero-based
* @return the argument's variable * @return the argument's variable
*/ */
variable *igetarg(instance *it, uint32_t n); variable *igetarg(instance *it, size_t n);
/** /**
* Parses the given line, returning compiled data to run. * Parses the given line, returning compiled data to run.
@ -134,6 +134,6 @@ variable **iparse(instance *it, const char *s);
* @param count the size of the ops array, zero if unknown * @param count the size of the ops array, zero if unknown
* @return the variable returned by the line, null if none * @return the variable returned by the line, null if none
*/ */
variable *isolve(instance *it, variable **ops, uint32_t count); variable *isolve(instance *it, variable **ops, size_t count);
#endif // PARSER_H_ #endif // PARSER_H_

@ -46,7 +46,7 @@ int gets(instance *it)
*strchr(line, '\n') = '\0'; *strchr(line, '\n') = '\0';
variable *v = make_vars(0, line); variable *v = make_vars(0, line);
free(line); free(line);
ipush(it, (uint32_t)v); ipush(it, (size_t)v);
return 0; return 0;
} }

@ -21,6 +21,7 @@
#include "string.h" #include "string.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
char *strnclone(const char *s, size_t c) char *strnclone(const char *s, size_t c)
{ {
@ -36,7 +37,7 @@ char *strclone(const char *s)
char *fixstring(const char *s) char *fixstring(const char *s)
{ {
char *n = malloc(strlen(s) + 1 - 2); char *n = (char *)malloc(strlen(s) + 1 - 2);
int j = 0; int j = 0;
for (int i = 1; s[i] != '\"'; i++, j++) { for (int i = 1; s[i] != '\"'; i++, j++) {
if (s[i] == '\\') { if (s[i] == '\\') {

@ -21,12 +21,9 @@
#ifndef STRING_H_ #ifndef STRING_H_
#define STRING_H_ #define STRING_H_
#include <stddef.h>
#include <string.h> #include <string.h>
#ifndef size_t
typedef unsigned int size_t;
#endif
/** /**
* Clones a string of a given size into a malloc'd buffer. * Clones a string of a given size into a malloc'd buffer.
* @param s the string to clone * @param s the string to clone

@ -43,7 +43,7 @@ variable *make_vars(variable *v, const char *s)
v->tmp = 1; v->tmp = 1;
} }
v->type = STRING; v->type = STRING;
v->value.p = (uint32_t)strclone(s); v->value.p = (size_t)strclone(s);
return v; return v;
} }
@ -53,7 +53,7 @@ variable *varclone(variable *n)
v->tmp = 1; v->tmp = 1;
v->type = n->type; v->type = n->type;
if (n->type == STRING) if (n->type == STRING)
v->value.p = (uint32_t)strclone((char *)n->value.p); v->value.p = (size_t)strclone((char *)n->value.p);
else else
v->value.p = n->value.p; v->value.p = n->value.p;
return v; return v;

@ -23,6 +23,7 @@
#define VARIABLE_H_ #define VARIABLE_H_
#include <stdint.h> #include <stdint.h>
#include <stddef.h>
/** /**
* Data for a script variable. * Data for a script variable.
@ -31,10 +32,10 @@ typedef struct {
uint8_t tmp :1; /**< If zero, variable cannot be free'd */ uint8_t tmp :1; /**< If zero, variable cannot be free'd */
uint8_t type :3; /**< The variable's type */ uint8_t type :3; /**< The variable's type */
uint8_t unused :4; /**< Unused... */ uint8_t unused :4; /**< Unused... */
uint8_t array; /**< ">0?" -> array w/ this size */ uint8_t array; /**< Variable is array if >0, this defines array size */
union { union {
float f; float f;
uint32_t p; size_t p;
} value; /**< The variable's value, either float or a pointer */ } value; /**< The variable's value, either float or a pointer */
} variable; } variable;
@ -80,3 +81,4 @@ variable *make_num(const char *text);
variable *varclone(variable *n); variable *varclone(variable *n);
#endif // VARIABLE_H_ #endif // VARIABLE_H_

Loading…
Cancel
Save