commit 9eafce19945f858649eaac8eabfee9ec1857c1cd
parent f35cd6c1d15ce31cd5f1d1d578a7a2a4880c2179
Author: thing1 <thing1@seacrossedlovers.xyz>
Date: Mon, 16 Sep 2024 12:06:09 +0100
finished the compiler, moving on to advaced command line tool
Diffstat:
6 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/comp/lucas-standen-NEA/code2/Makefile b/comp/lucas-standen-NEA/code2/Makefile
@@ -1,5 +1,5 @@
CC = cc
-CFLAGS = -O3
+CFLAGS = -O0 -ggdb
all: _zpy _parser _tokenizer _comp _appendsnprintf _util
${CC} zpy.o parser.o tokenizer.o comp.o appendsnprintf.o util.o -o zpy ${CFLAGS}
diff --git a/comp/lucas-standen-NEA/code2/comp.c b/comp/lucas-standen-NEA/code2/comp.c
@@ -4,6 +4,7 @@
#include <stdbool.h>
#include "tokenizer.h"
+#include "util.h"
#include "appendsnprintf.h"
#define MAXOUTLEN 512
@@ -99,6 +100,13 @@ char *getVarName(char *exp){
return out;
}
+char *getVarType(char *exp){
+ char *out = malloc(strlen(exp));
+ char *pos = strchr(exp, ':')+1;
+ memcpy(out, pos, strlen(pos) + 1);
+ return out;
+}
+
char *reversepolishToC(astNode *exp, char *out){
out = appendsnprintf(out, MAXOUTLEN, "%s ", exp->args[0]);
if (exp->func[0] == '=') out = appendsnprintf(out, MAXOUTLEN, "==");
@@ -125,7 +133,7 @@ char *compile(astNode *node){
out = appendsnprintf(out, MAXOUTLEN, "%s %s(", node->args[1], node->args[0]);
int i = 2;
while (node->args[i] != NULL){
- if (i != 2) out = appendsnprintf(out, MAXOUTLEN, ",", node->args[i]);
+ if (i != 2) out = appendsnprintf(out, MAXOUTLEN, ",");
out = vartypeToC(node->args[i], out);
i++;
}
@@ -213,6 +221,17 @@ char *compile(astNode *node){
else if (strcmp(names[27], node->func) == 0){
out = appendsnprintf(out, MAXOUTLEN, "sizeof(%s)", node->args[0]);
}
+ else if (strcmp(names[28], node->func) == 0){
+ out = appendsnprintf(out, MAXOUTLEN, "%s (*%s)", node->args[1], node->args[0]);
+ int i = 2;
+ while (node->args[i] != NULL){
+ if (i != 2) out = appendsnprintf(out, MAXOUTLEN, ",");
+ else out = appendsnprintf(out, MAXOUTLEN, "(");
+ out = appendsnprintf(out, MAXOUTLEN, "%s", getVarType(node->args[i]));
+ i++;
+ }
+ out = appendsnprintf(out, MAXOUTLEN, ")");
+ }
else {
// arithmetic operators and comparitors
diff --git a/comp/lucas-standen-NEA/code2/sample b/comp/lucas-standen-NEA/code2/sample
Binary files differ.
diff --git a/comp/lucas-standen-NEA/code2/sample.zpy b/comp/lucas-standen-NEA/code2/sample.zpy
@@ -1,9 +0,0 @@
-(struct ll)
- (def data:void*)
- (def next:ll*)
-(endstruct)
-
-(defun main int)
- (let node:ll* (alloc (sizeof ll*)))
- (return 0)
-(endfun)
diff --git a/comp/lucas-standen-NEA/code2/util.c b/comp/lucas-standen-NEA/code2/util.c
@@ -1,9 +1,8 @@
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
void die(char *msg){
fprintf(stderr, "zpy: %s\n", msg);
exit(1);
-
}
-
diff --git a/comp/lucas-standen-NEA/code2/zpy b/comp/lucas-standen-NEA/code2/zpy
Binary files differ.