summaryrefslogtreecommitdiff
path: root/comp/lucas-standen-NEA/code2
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
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')
-rw-r--r--comp/lucas-standen-NEA/code2/Makefile1
-rw-r--r--comp/lucas-standen-NEA/code2/autodoc/Makefile11
-rwxr-xr-xcomp/lucas-standen-NEA/code2/autodoc/autodocbin19584 -> 0 bytes
-rw-r--r--comp/lucas-standen-NEA/code2/autodoc/autodoc.c73
-rw-r--r--comp/lucas-standen-NEA/code2/comp.c22
-rw-r--r--comp/lucas-standen-NEA/code2/examples/Makefile5
-rwxr-xr-xcomp/lucas-standen-NEA/code2/examples/fib_examplebin0 -> 25496 bytes
-rwxr-xr-xcomp/lucas-standen-NEA/code2/examples/helloworld/mainbin0 -> 24720 bytes
-rw-r--r--comp/lucas-standen-NEA/code2/examples/helloworld/main.zpy3
-rw-r--r--comp/lucas-standen-NEA/code2/examples/helloworld/zpybuild.sh2
-rw-r--r--comp/lucas-standen-NEA/code2/examples/helloworldadv/helloworld.c4
-rw-r--r--comp/lucas-standen-NEA/code2/examples/helloworldadv/helloworld.zpy3
-rwxr-xr-xcomp/lucas-standen-NEA/code2/examples/helloworldadv/mainbin0 -> 19440 bytes
-rw-r--r--comp/lucas-standen-NEA/code2/examples/helloworldadv/main.c4
-rw-r--r--comp/lucas-standen-NEA/code2/examples/helloworldadv/main.zpy3
-rw-r--r--comp/lucas-standen-NEA/code2/examples/helloworldadv/zpybuild.sh4
-rw-r--r--comp/lucas-standen-NEA/code2/examples/raylib_example/dvd.png (renamed from comp/lucas-standen-NEA/code2/examples/dvd.png)bin1247 -> 1247 bytes
-rwxr-xr-xcomp/lucas-standen-NEA/code2/examples/raylib_example/mainbin0 -> 1077360 bytes
-rw-r--r--comp/lucas-standen-NEA/code2/examples/raylib_example/main.zpy (renamed from comp/lucas-standen-NEA/code2/examples/raylib_example.zpy)1
-rw-r--r--comp/lucas-standen-NEA/code2/examples/raylib_example/zpybuild.sh4
-rwxr-xr-xcomp/lucas-standen-NEA/code2/examples/spaceinvadersbin0 -> 1086520 bytes
-rw-r--r--comp/lucas-standen-NEA/code2/examples/spaceinvaders.zpy2
-rwxr-xr-xcomp/lucas-standen-NEA/code2/examples/str_examplebin0 -> 25952 bytes
-rw-r--r--comp/lucas-standen-NEA/code2/examples/syntaxerr.zpy4
-rw-r--r--comp/lucas-standen-NEA/code2/examples/tmp.zpy.c2
-rw-r--r--comp/lucas-standen-NEA/code2/parser.c2
-rwxr-xr-xcomp/lucas-standen-NEA/code2/zpybin0 -> 42592 bytes
-rw-r--r--comp/lucas-standen-NEA/code2/zpypkg/Makefile4
-rwxr-xr-xcomp/lucas-standen-NEA/code2/zpypkg/zpypkg79
29 files changed, 135 insertions, 98 deletions
diff --git a/comp/lucas-standen-NEA/code2/Makefile b/comp/lucas-standen-NEA/code2/Makefile
index 126bed6..4dc4224 100644
--- a/comp/lucas-standen-NEA/code2/Makefile
+++ b/comp/lucas-standen-NEA/code2/Makefile
@@ -16,6 +16,7 @@ install: zpy
cp ./zpy /usr/local/bin/zpy
cd stdlib && make install
+ cd zpypkg && make install
example: zpy
cd examples && make
diff --git a/comp/lucas-standen-NEA/code2/autodoc/Makefile b/comp/lucas-standen-NEA/code2/autodoc/Makefile
deleted file mode 100644
index 76ef5c1..0000000
--- a/comp/lucas-standen-NEA/code2/autodoc/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-autodoc: autodoc.c
- cc autodoc.c -o autodoc -ggdb
-
-install: autodoc
- cp autodoc /usr/local/bin/autodoc
-
-uninstall:
- rm /usr/local/bin/autodoc
-
-clean:
- rm autodoc
diff --git a/comp/lucas-standen-NEA/code2/autodoc/autodoc b/comp/lucas-standen-NEA/code2/autodoc/autodoc
deleted file mode 100755
index 0ef6fad..0000000
--- a/comp/lucas-standen-NEA/code2/autodoc/autodoc
+++ /dev/null
Binary files differ
diff --git a/comp/lucas-standen-NEA/code2/autodoc/autodoc.c b/comp/lucas-standen-NEA/code2/autodoc/autodoc.c
deleted file mode 100644
index d8e7583..0000000
--- a/comp/lucas-standen-NEA/code2/autodoc/autodoc.c
+++ /dev/null
@@ -1,73 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdbool.h>
-
-typedef struct docpair {
- char *doc;
- char *func;
-} docpair;
-
-docpair funcs[2048];
-int count = 0;
-
-//# returns a bool as to weather s2 is contained fully in s1
-bool contains(char *s1, char *s2){
- int j = 0;
- if (strlen(s1) < strlen(s2)) return false;
- for (int i = 0; i < strlen(s1); i++){
- if (s1[i] == s2[j]){
- if (j+1 == strlen(s2)) return true;
- j++;
- }
- }
- return false;
-}
-
-int main(int argc, char **argv){
- FILE *in;
- if (argv[1][0] == '-') in = stdin;
- else in = fopen(argv[1], "r");
-
- char *search = argv[2];
-
- char *line = malloc(512);
- char *tmp = malloc(512);
-
- bool nextIsFunc = false;
-
- while (fgets(line, 512, in) != NULL){
- strcpy(tmp, line);
- tmp[4] = '\0';
- if (strcmp(tmp, "//# ") == 0){
- funcs[count].doc = malloc(strlen(line)+1);
- strcpy(funcs[count].doc, line);
- nextIsFunc = true;
- }
- else if (nextIsFunc == true){
- funcs[count].func = malloc(strlen(line)+1);
- strcpy(funcs[count].func, line);
- nextIsFunc = false;
- count++;
- }
- }
-
- if (search != NULL){
- for (int i = 0; i < 2048; i++){
- if (funcs[i].doc != NULL)
- if (contains(funcs[i].func, search))
- printf("%s \e[1m%s\e[0m\n", funcs[i].doc, funcs[i].func);
- }
- }
- else {
- for (int i = 0; i < 2048; i++){
- if (funcs[i].doc != NULL)
- printf("%s \e[1m%s\e[0m\n", funcs[i].doc, funcs[i].func);
- }
- }
-
- free(line);
- free(tmp);
-
-
-}
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);
diff --git a/comp/lucas-standen-NEA/code2/examples/Makefile b/comp/lucas-standen-NEA/code2/examples/Makefile
index 18a9e64..d3ee327 100644
--- a/comp/lucas-standen-NEA/code2/examples/Makefile
+++ b/comp/lucas-standen-NEA/code2/examples/Makefile
@@ -1,9 +1,8 @@
all:
- zpy raylib_example.zpy -o raylib_example -f -lraylib -f -lm -i raylib.h
zpy spaceinvaders.zpy -o spaceinvaders -f -lraylib -f -lm -i raylib.h
zpy fib_example.zpy -o fib_example -f -ggdb
zpy str_example.zpy -o str_example -f -ggdb
- zpy syntaxerr.zpy -o syntaxerr
+ zpy syntaxerr.zpy -o syntaxerr
clean:
- rm -rf fib_example raylib_example str_example spaceinvaders tmp.zpy.c
+ rm -rf fib_example raylib_example str_example spaceinvaders syntaxerr tmp.zpy.c
diff --git a/comp/lucas-standen-NEA/code2/examples/fib_example b/comp/lucas-standen-NEA/code2/examples/fib_example
new file mode 100755
index 0000000..bdd94ec
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/fib_example
Binary files differ
diff --git a/comp/lucas-standen-NEA/code2/examples/helloworld/main b/comp/lucas-standen-NEA/code2/examples/helloworld/main
new file mode 100755
index 0000000..653d84c
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/helloworld/main
Binary files differ
diff --git a/comp/lucas-standen-NEA/code2/examples/helloworld/main.zpy b/comp/lucas-standen-NEA/code2/examples/helloworld/main.zpy
new file mode 100644
index 0000000..ef0a288
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/helloworld/main.zpy
@@ -0,0 +1,3 @@
+(defun main int)
+ (printstr "hello world\n")
+(endfun)
diff --git a/comp/lucas-standen-NEA/code2/examples/helloworld/zpybuild.sh b/comp/lucas-standen-NEA/code2/examples/helloworld/zpybuild.sh
new file mode 100644
index 0000000..7f675c3
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/helloworld/zpybuild.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+zpy ./main.zpy -o main
diff --git a/comp/lucas-standen-NEA/code2/examples/helloworldadv/helloworld.c b/comp/lucas-standen-NEA/code2/examples/helloworldadv/helloworld.c
new file mode 100644
index 0000000..f1e746f
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/helloworldadv/helloworld.c
@@ -0,0 +1,4 @@
+#include <zpylib.h>
+void helloworld(){
+printstr("hello world\n");
+}
diff --git a/comp/lucas-standen-NEA/code2/examples/helloworldadv/helloworld.zpy b/comp/lucas-standen-NEA/code2/examples/helloworldadv/helloworld.zpy
new file mode 100644
index 0000000..9e3553b
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/helloworldadv/helloworld.zpy
@@ -0,0 +1,3 @@
+(defun helloworld void)
+ (printstr "hello world\n")
+(endfun)
diff --git a/comp/lucas-standen-NEA/code2/examples/helloworldadv/main b/comp/lucas-standen-NEA/code2/examples/helloworldadv/main
new file mode 100755
index 0000000..593fe40
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/helloworldadv/main
Binary files differ
diff --git a/comp/lucas-standen-NEA/code2/examples/helloworldadv/main.c b/comp/lucas-standen-NEA/code2/examples/helloworldadv/main.c
new file mode 100644
index 0000000..a2b6927
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/helloworldadv/main.c
@@ -0,0 +1,4 @@
+#include <zpylib.h>
+int main(){
+helloworld();
+}
diff --git a/comp/lucas-standen-NEA/code2/examples/helloworldadv/main.zpy b/comp/lucas-standen-NEA/code2/examples/helloworldadv/main.zpy
new file mode 100644
index 0000000..05b6155
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/helloworldadv/main.zpy
@@ -0,0 +1,3 @@
+(defun main int)
+ (helloworld)
+(endfun)
diff --git a/comp/lucas-standen-NEA/code2/examples/helloworldadv/zpybuild.sh b/comp/lucas-standen-NEA/code2/examples/helloworldadv/zpybuild.sh
new file mode 100644
index 0000000..26424d7
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/helloworldadv/zpybuild.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+zpy ./main.zpy -c -o main.c
+zpy ./helloworld.zpy -c -o helloworld.c
+cc main.c helloworld.c /usr/local/share/zpylib/zpylib.o -o main -I/usr/local/share/zpylib/include -Wno-implicit-function-declaration
diff --git a/comp/lucas-standen-NEA/code2/examples/dvd.png b/comp/lucas-standen-NEA/code2/examples/raylib_example/dvd.png
index 8e219f7..8e219f7 100644
--- a/comp/lucas-standen-NEA/code2/examples/dvd.png
+++ b/comp/lucas-standen-NEA/code2/examples/raylib_example/dvd.png
Binary files differ
diff --git a/comp/lucas-standen-NEA/code2/examples/raylib_example/main b/comp/lucas-standen-NEA/code2/examples/raylib_example/main
new file mode 100755
index 0000000..b124ebf
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/raylib_example/main
Binary files differ
diff --git a/comp/lucas-standen-NEA/code2/examples/raylib_example.zpy b/comp/lucas-standen-NEA/code2/examples/raylib_example/main.zpy
index 7c6e599..cd6a382 100644
--- a/comp/lucas-standen-NEA/code2/examples/raylib_example.zpy
+++ b/comp/lucas-standen-NEA/code2/examples/raylib_example/main.zpy
@@ -1,3 +1,4 @@
+//# this function is my main loop
(defun main int)
(InitWindow 800 800 "test test")
(SetTargetFPS 60)
diff --git a/comp/lucas-standen-NEA/code2/examples/raylib_example/zpybuild.sh b/comp/lucas-standen-NEA/code2/examples/raylib_example/zpybuild.sh
new file mode 100644
index 0000000..3916f3b
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/raylib_example/zpybuild.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+zpy ./main.zpy -c -o main.c -i raylib.h
+cc main.c /usr/local/share/zpylib/zpylib.o -o main -I/usr/local/share/zpylib/include -Wno-implicit-function-declaration -lraylib -lm
+rm -rf main.c
diff --git a/comp/lucas-standen-NEA/code2/examples/spaceinvaders b/comp/lucas-standen-NEA/code2/examples/spaceinvaders
new file mode 100755
index 0000000..ec88002
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/spaceinvaders
Binary files differ
diff --git a/comp/lucas-standen-NEA/code2/examples/spaceinvaders.zpy b/comp/lucas-standen-NEA/code2/examples/spaceinvaders.zpy
index 698999a..5e51ed3 100644
--- a/comp/lucas-standen-NEA/code2/examples/spaceinvaders.zpy
+++ b/comp/lucas-standen-NEA/code2/examples/spaceinvaders.zpy
@@ -8,6 +8,7 @@
(def exists:bool)
(endstruct)
+//# this checks if 2 entitys are touching
(defun touching bool a:entity* b:entity*)
(def r1:Rectangle)
(def r2:Rectangle)
@@ -24,6 +25,7 @@
(return (CheckCollisionRecs r1 r2))
(endfun)
+//# the main loop of the program
(defun main int)
(InitWindow 800 800 "test test")
(SetTargetFPS 60)
diff --git a/comp/lucas-standen-NEA/code2/examples/str_example b/comp/lucas-standen-NEA/code2/examples/str_example
new file mode 100755
index 0000000..c543ab7
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/str_example
Binary files differ
diff --git a/comp/lucas-standen-NEA/code2/examples/syntaxerr.zpy b/comp/lucas-standen-NEA/code2/examples/syntaxerr.zpy
index c74d53b..87494ed 100644
--- a/comp/lucas-standen-NEA/code2/examples/syntaxerr.zpy
+++ b/comp/lucas-standen-NEA/code2/examples/syntaxerr.zpy
@@ -1,3 +1,5 @@
(defun main int)
- (return)
+ (let x:int)
+ (set x 10)
+ (return 10)
(endfun)
diff --git a/comp/lucas-standen-NEA/code2/examples/tmp.zpy.c b/comp/lucas-standen-NEA/code2/examples/tmp.zpy.c
new file mode 100644
index 0000000..2305f24
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/examples/tmp.zpy.c
@@ -0,0 +1,2 @@
+#include <zpylib.h>
+int main(){
diff --git a/comp/lucas-standen-NEA/code2/parser.c b/comp/lucas-standen-NEA/code2/parser.c
index 62f32fa..a84291b 100644
--- a/comp/lucas-standen-NEA/code2/parser.c
+++ b/comp/lucas-standen-NEA/code2/parser.c
@@ -27,7 +27,7 @@ strings *parse(FILE *f){
char *line = alloca(256);
int count = 0;
while (fgets(line, 256, f) != NULL){
- if (line[0] != '\n'){
+ if (line[0] != '\n' && line[0] != '/'){
while (line[0] == '\t') line++;
line[strlen(line)-1] = '\0';
strs->strs[count] = malloc(256);
diff --git a/comp/lucas-standen-NEA/code2/zpy b/comp/lucas-standen-NEA/code2/zpy
new file mode 100755
index 0000000..0c23ae3
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/zpy
Binary files differ
diff --git a/comp/lucas-standen-NEA/code2/zpypkg/Makefile b/comp/lucas-standen-NEA/code2/zpypkg/Makefile
new file mode 100644
index 0000000..dc86e53
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/zpypkg/Makefile
@@ -0,0 +1,4 @@
+install: zpypkg
+ cp zpypkg /usr/local/bin/zpypkg
+uninstall:
+ rm /usr/local/bin/zpypkg
diff --git a/comp/lucas-standen-NEA/code2/zpypkg/zpypkg b/comp/lucas-standen-NEA/code2/zpypkg/zpypkg
new file mode 100755
index 0000000..95e59c8
--- /dev/null
+++ b/comp/lucas-standen-NEA/code2/zpypkg/zpypkg
@@ -0,0 +1,79 @@
+#!/bin/bash
+
+function init () {
+ if [ ! -e "main.zpy" ]; then
+ touch main.zpy
+
+ echo -e "(defun main int)" >> main.zpy
+ printf "\t(printstr \"hello world\\\n\")\n" >> main.zpy
+ echo -e "(endfun)" >> main.zpy
+
+ echo "#!/bin/sh" > zpybuild.sh
+ echo "zpy ./main.zpy -o main" >> zpybuild.sh
+ else
+ echo "zpypkg already in use!"
+ fi
+}
+
+function advinit () {
+ if [ ! -e "main.zpy" ]; then
+ touch main.zpy
+
+ echo -e "(defun main int)" >> main.zpy
+ printf "\t(printstr \"hello world\\\n\")\n" >> main.zpy
+ echo -e "(endfun)" >> main.zpy
+
+ touch zpybuild.sh
+ echo "#!/bin/sh" > zpybuild.sh
+ echo "zpy ./main.zpy -c -o main.c" >> zpybuild.sh
+ echo "cc main.c /usr/local/share/zpylib/zpylib.o -o main -I/usr/local/share/zpylib/include -Wno-implicit-function-declaration" >> zpybuild.sh
+ echo "rm -rf main.c" >> zpybuild.sh
+
+ else
+ echo "zpypkg already in use!"
+ fi
+}
+
+function build (){
+ sh ./zpybuild.sh
+}
+
+function run (){
+ ./main
+}
+
+function clean (){
+ rm -f ./main
+}
+
+function remove () {
+ if [ -e "main.zpy" ]; then
+ rm main.zpy zpybuild.sh
+ else
+ echo "zpypkg not in use!"
+ fi
+}
+
+case $@ in
+ "init")
+ init
+ ;;
+ "advinit")
+ advinit
+ ;;
+ "build")
+ build
+ ;;
+ "run")
+ build
+ run
+ ;;
+ "clean")
+ clean
+ ;;
+ "remove")
+ remove
+ ;;
+ *)
+ echo "unknown option ${@}"
+esac