summaryrefslogtreecommitdiff
path: root/comp/lucas-standen-NEA/code2/comp.c
diff options
context:
space:
mode:
authorthing1 <thing1@seacrossedlovers.xyz>2024-10-15 10:19:30 +0100
committerthing1 <thing1@seacrossedlovers.xyz>2024-10-15 10:19:30 +0100
commitfaef2d81c224b715c5e429d04c59ba50fb772d9e (patch)
tree2f75197a884ded3486c14e09908cb23bd24b968c /comp/lucas-standen-NEA/code2/comp.c
parent3564e513623bb3fc4d528d3d29df9aa91dae1396 (diff)
added a stupid amount of work to zpy, and started the document work in latex
rather than groff
Diffstat (limited to 'comp/lucas-standen-NEA/code2/comp.c')
-rw-r--r--comp/lucas-standen-NEA/code2/comp.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/comp/lucas-standen-NEA/code2/comp.c b/comp/lucas-standen-NEA/code2/comp.c
index d49148e..a2440e2 100644
--- a/comp/lucas-standen-NEA/code2/comp.c
+++ b/comp/lucas-standen-NEA/code2/comp.c
@@ -33,6 +33,14 @@ void errorhandle(int type){
exit(1);
}
+//# this function will check if the value given is null, if it is, it will cause a sig segv and set the error msg
+void checkNULL(void *value, char *msg){
+ if (value == NULL) {
+ errmsg = msg;
+ kill(pid, SIGSEGV);
+ }
+}
+
char *names[] = {
"defun", // takes a func name, func return type, and args // 0
"endfun", // takes no args // 1
@@ -91,6 +99,8 @@ char *vartypeToC(char *str, char *out){
}
name[i] = '\0';
i++;
+
+ if (i > strlen(str)) checkNULL(NULL, "expected var type, got nothing");
for (; i < strlen(str); i++){
if (str[i] == ':'){
@@ -114,6 +124,7 @@ char *getVarName(char *exp){
char *out = malloc(strlen(exp));
memcpy(out, exp, strlen(exp));
char *pos = strchr(out, ':');
+ if (pos == NULL) checkNULL(NULL, "expected var type, got nothing");
pos[0] = '\0';
return out;
}
@@ -122,7 +133,8 @@ char *getVarName(char *exp){
char *getVarType(char *exp){
char *out = malloc(strlen(exp));
char *pos = strchr(exp, ':')+1;
- memcpy(out, pos, strlen(pos) + 1);
+ if (pos == NULL) checkNULL(NULL, "expected var type, got nothing");
+ memcpy(out, pos, strlen(pos) + 1);
return out;
}
//# this will convert mathmatical expressions, to the c style of maths
@@ -145,14 +157,6 @@ astNode *processChildren(astNode *node){
return node;
}
-//# this function will check if the value given is null, if it is, it will cause a sig segv and set the error msg
-void checkNULL(void *value, char *msg){
- if (value == NULL) {
- errmsg = msg;
- kill(pid, SIGSEGV);
- }
-}
-
//# this function will do the bulk of converting from zpy into c code
char *compile(astNode *node){
char *out = calloc(0, MAXOUTLEN);