summaryrefslogtreecommitdiff
path: root/comp
diff options
context:
space:
mode:
Diffstat (limited to 'comp')
-rw-r--r--comp/lucas-standen-NEA/code2/Makefile2
-rw-r--r--comp/lucas-standen-NEA/code2/comp.c21
-rwxr-xr-xcomp/lucas-standen-NEA/code2/samplebin15512 -> 0 bytes
-rw-r--r--comp/lucas-standen-NEA/code2/sample.zpy9
-rw-r--r--comp/lucas-standen-NEA/code2/util.c3
-rwxr-xr-xcomp/lucas-standen-NEA/code2/zpybin21288 -> 34448 bytes
6 files changed, 22 insertions, 13 deletions
diff --git a/comp/lucas-standen-NEA/code2/Makefile b/comp/lucas-standen-NEA/code2/Makefile
index bcfe9f5..1ed8b29 100644
--- 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
index bdca47f..6d96994 100644
--- 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
deleted file mode 100755
index 7516796..0000000
--- a/comp/lucas-standen-NEA/code2/sample
+++ /dev/null
Binary files differ
diff --git a/comp/lucas-standen-NEA/code2/sample.zpy b/comp/lucas-standen-NEA/code2/sample.zpy
index 57b954f..e69de29 100644
--- 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
index 5cda33e..a1e8f15 100644
--- 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
index 4191bbf..9b43b1d 100755
--- a/comp/lucas-standen-NEA/code2/zpy
+++ b/comp/lucas-standen-NEA/code2/zpy
Binary files differ