diff options
author | thing1 <thing1@seacrossedlovers.xyz> | 2024-10-01 08:55:32 +0100 |
---|---|---|
committer | thing1 <thing1@seacrossedlovers.xyz> | 2024-10-01 08:55:32 +0100 |
commit | ef8cf00bbf9f74eb3b6aabc1d99f5358e81741c7 (patch) | |
tree | 3479ca1b82573426151cb270c63a588af737d3c0 | |
parent | dc7732b6f073d5450657d94c815ca445a1a08fbd (diff) |
added some cool examples to zpy and got electronics working
17 files changed, 251 insertions, 15 deletions
diff --git a/comp/lucas-standen-NEA/code2/Makefile b/comp/lucas-standen-NEA/code2/Makefile index 9db83ac..b5a1aed 100644 --- a/comp/lucas-standen-NEA/code2/Makefile +++ b/comp/lucas-standen-NEA/code2/Makefile @@ -1,7 +1,7 @@ CC = cc CFLAGS = -O0 -ggdb -all: +zpy: ${CC} *.c -c ${CFLAGS} ${CC} *.o -o zpy ${CFLAGS} cd stdlib && make @@ -10,15 +10,16 @@ clean: cd stdlib && make clean cd examples && make clean -install: all +install: zpy mkdir -p /usr/local/share/zpylib mkdir -p /usr/local/share/zpylib/include cp ./zpy /usr/local/bin/zpy cd stdlib && make install -example: all +example: zpy cd examples && make uninstall: rm /usr/local/bin/zpy + rm -rf /usr/local/share/zpylib diff --git a/comp/lucas-standen-NEA/code2/comp.c b/comp/lucas-standen-NEA/code2/comp.c index f06631b..7d97cdc 100644 --- a/comp/lucas-standen-NEA/code2/comp.c +++ b/comp/lucas-standen-NEA/code2/comp.c @@ -203,7 +203,7 @@ char *compile(astNode *node){ out = appendsnprintf(out, MAXOUTLEN, "return %s;\n", node->args[0]); } else if (strcmp(names[23], node->func) == 0){ - out = appendsnprintf(out, MAXOUTLEN, "calloc(0, %s)", node->args[0]); + out = appendsnprintf(out, MAXOUTLEN, "malloc(%s)", node->args[0]); neededmemptr = true; } else if (strcmp(names[24], node->func) == 0){ diff --git a/comp/lucas-standen-NEA/code2/examples/Makefile b/comp/lucas-standen-NEA/code2/examples/Makefile index 13178a5..cbdcda1 100644 --- a/comp/lucas-standen-NEA/code2/examples/Makefile +++ b/comp/lucas-standen-NEA/code2/examples/Makefile @@ -1,6 +1,7 @@ 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 clean: - rm -rf fib_example raylib_example str_example + rm -rf fib_example raylib_example str_example spaceinvaders diff --git a/comp/lucas-standen-NEA/code2/examples/fib_example b/comp/lucas-standen-NEA/code2/examples/fib_example Binary files differindex e7d4958..bdd94ec 100755 --- a/comp/lucas-standen-NEA/code2/examples/fib_example +++ b/comp/lucas-standen-NEA/code2/examples/fib_example diff --git a/comp/lucas-standen-NEA/code2/examples/raylib_example b/comp/lucas-standen-NEA/code2/examples/raylib_example Binary files differindex 74d52ed..08ea8fd 100755 --- a/comp/lucas-standen-NEA/code2/examples/raylib_example +++ b/comp/lucas-standen-NEA/code2/examples/raylib_example diff --git a/comp/lucas-standen-NEA/code2/examples/raylib_example.zpy b/comp/lucas-standen-NEA/code2/examples/raylib_example.zpy index 90ef8b8..7c6e599 100644 --- a/comp/lucas-standen-NEA/code2/examples/raylib_example.zpy +++ b/comp/lucas-standen-NEA/code2/examples/raylib_example.zpy @@ -1,15 +1,15 @@ (defun main int) - (InitWindow 800 800 "test_test") - (SetTargetFPS 30) + (InitWindow 800 800 "test test") + (SetTargetFPS 60) (let img:Image (LoadImage "dvd.png")) (let tex:Texture (LoadTextureFromImage img)) (UnloadImage img) - (let x:int (randint 1 9)) - (let y:int (randint 1 9)) - (let xd:int (randint 1 5)) - (let yd:int (randint 1 5)) + (let x:int (randint 4 9)) + (let y:int (randint 4 9)) + (let xd:int (randint 3 5)) + (let yd:int (randint 3 5)) (for i:int 0 (= (WindowShouldClose) 0) 0) (BeginDrawing) diff --git a/comp/lucas-standen-NEA/code2/examples/spaceinvaders b/comp/lucas-standen-NEA/code2/examples/spaceinvaders Binary files differnew file mode 100755 index 0000000..ec88002 --- /dev/null +++ b/comp/lucas-standen-NEA/code2/examples/spaceinvaders diff --git a/comp/lucas-standen-NEA/code2/examples/spaceinvaders.zpy b/comp/lucas-standen-NEA/code2/examples/spaceinvaders.zpy new file mode 100644 index 0000000..698999a --- /dev/null +++ b/comp/lucas-standen-NEA/code2/examples/spaceinvaders.zpy @@ -0,0 +1,161 @@ +(struct entity) + (def x:int) + (def y:int) + (def width:int) + (def height:int) + (def ofx:int) + (def ofy:int) + (def exists:bool) +(endstruct) + +(defun touching bool a:entity* b:entity*) + (def r1:Rectangle) + (def r2:Rectangle) + + (set r1.x a->x) + (set r1.y a->y) + (set r1.width a->width) + (set r1.height a->height) + + (set r2.x b->x) + (set r2.y b->y) + (set r2.width b->width) + (set r2.height b->height) + (return (CheckCollisionRecs r1 r2)) +(endfun) + +(defun main int) + (InitWindow 800 800 "test test") + (SetTargetFPS 60) + + (let p:entity* (alloc (sizeof entity))) + (set p->x 400) + (set p->y 700) + (set p->width 50) + (set p->height 30) + (set p->ofx 25) + (set p->ofy 15) + + (let b:entity* (alloc (sizeof entity))) + (set b->x 400) + (set b->y 700) + (set b->width 10) + (set b->height 6) + (set b->ofx 5) + (set b->ofy 3) + (set b->exists false) + + (let b2:entity* (alloc (sizeof entity))) + (set b2->x 400) + (set b2->y 700) + (set b2->width 10) + (set b2->height 6) + (set b2->ofx 5) + (set b2->ofy 3) + (set b2->exists false) + + (let e:entity* (alloc (sizeof entity))) + (set e->x 400) + (set e->y 100) + (set e->width 60) + (set e->height 30) + (set e->ofx 30) + (set e->ofy 15) + (set e->exists true) + + (let ehp:int 5) + (let edx:int 1) + + (let reload:int 0) + + (for i:int 0 (= (WindowShouldClose) 0) 0) +(if (= ehp 0)) +(exit 0) +(elif (= e->y 700)) +(exit 1) +(endif) + (if (!= reload 0) + (set reload (- reload 1)) + (endif) + + (BeginDrawing) + (ClearBackground BLACK) + (DrawRectangle (- p->x p->ofx) (+ p->y p->ofy) p->width p->height GREEN) + (if (= b->exists true)) + (DrawRectangle (- b->x b->ofx) (+ b->y b->ofy) b->width b->height BLUE) + (endif) + (if (= b2->exists true)) + (DrawRectangle (- b2->x b2->ofx) (+ b2->y b2->ofy) b2->width b2->height PURPLE) + (endif) + (if (= e->exists true)) + (DrawRectangle (- e->x e->ofx) (+ e->y e->ofy) e->width e->height RED) + (endif) + (EndDrawing) + + (if (IsKeyDown KEY_LEFT)) + (set p->x (- p->x 6)) + (elif (IsKeyDown KEY_RIGHT)) + (set p->x (+ p->x 6)) + (endif) + + (if (IsKeyPressed KEY_SPACE)) + (if (= reload 0)) + (if (!= b->exists true)) + (set b->exists true) + (else) + (set b2->exists true) + (endif) + (set reload 30) + (endif) + (endif) + + (if (= b->exists true)) + (set b->y (- b->y 10)) + (if (< b->y 0)) + (set b->y 700) + (set b->exists false) + (endif) + (else) + (set b->x p->x) + (endif) + + (if (touching b e)) + (set b->y 700) + (set b->exists false) + (set ehp (- ehp 1) + (if (<= ehp 0)) + (set e->exists false) + (endif) + (endif) + + (if (= b2->exists true)) + (set b2->y (- b2->y 10)) + (if (< b2->y 0)) + (set b2->y 700) + (set b2->exists false) + (endif) + (else) + (set b2->x p->x) + (endif) + + (if (touching b2 e)) + (set b2->y 700) + (set b2->exists false) + (set ehp (- ehp 1) + (if (<= ehp 0)) + (set e->exists false) + (endif) + (endif) + + (set e->x (+ (* 4 edx) e->x) + (if (= e->x 800)) + (set edx (* edx -1) + (set e->y (+ e->y 10)) + (elif (= e->x 0)) + (set edx (* edx -1) + (set e->y (+ e->y 10)) + (endif) + + (endfor) + (CloseWindow) +(endfun) diff --git a/comp/lucas-standen-NEA/code2/examples/str_example b/comp/lucas-standen-NEA/code2/examples/str_example Binary files differindex 8f86844..c543ab7 100755 --- a/comp/lucas-standen-NEA/code2/examples/str_example +++ b/comp/lucas-standen-NEA/code2/examples/str_example diff --git a/comp/lucas-standen-NEA/code2/examples/str_example.zpy b/comp/lucas-standen-NEA/code2/examples/str_example.zpy index 7311660..bffc3f0 100644 --- a/comp/lucas-standen-NEA/code2/examples/str_example.zpy +++ b/comp/lucas-standen-NEA/code2/examples/str_example.zpy @@ -1,6 +1,14 @@ (defun main int) - (let str:string* (String "hello")) - (printchar str->_str[0]) + (let str:string* (String "hello_world")) + (printstr str->_str) + (printchar '\n') + + (let strs:string** (str->split str '_')) + + (printstr strs[0]->_str) + (printchar '\n') + (printstr strs[1]->_str) + (printchar '\n') + (str->free str) - (printstr "<first_letter\n") (endfun) diff --git a/comp/lucas-standen-NEA/code2/stdlib/String/String.c b/comp/lucas-standen-NEA/code2/stdlib/String/String.c index 2814a1c..6f11119 100644 --- a/comp/lucas-standen-NEA/code2/stdlib/String/String.c +++ b/comp/lucas-standen-NEA/code2/stdlib/String/String.c @@ -11,6 +11,16 @@ void __stringfree(string *self){ free(self); } +void __stringprint(string *self){ + printf("%s\n", self->_str); +} + +void __stringinput(string *self, size_t len){ + char *tmp = calloc(0, len); + fgets(tmp, len, stdin); + self->fromcstring(self, tmp); +} + void __stringappendchar(string *self, char c){ self->_len++; self->_str = realloc(self->_str, self->_len); @@ -132,6 +142,8 @@ string *String(char *cstring){ // returns an allocated String from a C string in str->fromcstring = &__stringfromcstring; str->tocstring = &__stringtocstring; str->split = &__stringsplit; + str->print = &__stringprint; + str->input = &__stringinput; return str; } diff --git a/comp/lucas-standen-NEA/code2/stdlib/String/String.h b/comp/lucas-standen-NEA/code2/stdlib/String/String.h index 865defe..b1d07f6 100644 --- a/comp/lucas-standen-NEA/code2/stdlib/String/String.h +++ b/comp/lucas-standen-NEA/code2/stdlib/String/String.h @@ -13,6 +13,8 @@ typedef struct string { void (*fromcstring)(string *, char *); char *(*tocstring)(string *); string **(*split)(string *, char); + void (*print)(string *); + void (*input)(string *, size_t); } string; string *String(char *cstring); @@ -25,3 +27,6 @@ int __stringcmp(string *str1, string *str2); void __stringfromcstring(string *self, char *cstring); char *__stringtocstring(string *self); string **__stringsplit(string *self, char delim); +void *print(string *self); +void *input(string *self, size_t len); + diff --git a/comp/lucas-standen-NEA/code2/tokenizer.c b/comp/lucas-standen-NEA/code2/tokenizer.c index 7e8cae1..c756c0c 100644 --- a/comp/lucas-standen-NEA/code2/tokenizer.c +++ b/comp/lucas-standen-NEA/code2/tokenizer.c @@ -63,7 +63,20 @@ top: head->children[argCount] = tokenize(chunk); argCount++; }else { - i += readuntil(&line[i], ' ', chunk); // reads func name or arg + if (line[i] == '"'){ + i += readuntil(&line[i+1], '"', chunk); // reads a comptime string + i++; + char *tmp = malloc(strlen(chunk)+2); + tmp[0] = '"'; + tmp[1] = '\0'; + strcat(tmp, chunk); + strcat(tmp, "\""); + chunk = tmp; + + } + else { + i += readuntil(&line[i], ' ', chunk); // reads func name or arg + } if (head->func == NULL){ head->func = chunk; } else{ diff --git a/comp/lucas-standen-NEA/code2/zpy b/comp/lucas-standen-NEA/code2/zpy Binary files differindex 107d933..d153a2f 100755 --- a/comp/lucas-standen-NEA/code2/zpy +++ b/comp/lucas-standen-NEA/code2/zpy diff --git a/comp/work/36/revision b/comp/work/36/revision new file mode 100644 index 0000000..7aeebd9 --- /dev/null +++ b/comp/work/36/revision @@ -0,0 +1,18 @@ +1) hardware is the physical device that code runs on +software is the code itself, it tells the hardware what to do +2) core software that is needed for other software to run +3) software that the user uses to do things +4) to manage memory and allow for multitasking, as well as +abstracting the hardware from the user +5) to give each process the memory it needs and not allow +one process to read anothers memory +6) a driver that the operating sytstem uses to talk to a peice of hardware +7) a high level language abstracts away low level concepts, whereas a low level languge doesnt +8) a system designed for one use case +9) a low level langugue is better as it is faster and has a smaller footprint +10) i do this enough i cant be asked to describe it +11) see Q.10 +12) many wires next to eachother that move data around quickly +13) it loses all state when power is lost +14) memory can only be read not written too +15) diff --git a/electronics/asm/Makefile b/electronics/asm/Makefile new file mode 100644 index 0000000..095d4e9 --- /dev/null +++ b/electronics/asm/Makefile @@ -0,0 +1,4 @@ +test: test.asm + wjecasm -c/dev/ttyUSB0 test.asm +clean: + rm -rf *.err diff --git a/electronics/asm/test.asm b/electronics/asm/test.asm new file mode 100644 index 0000000..057bc1f --- /dev/null +++ b/electronics/asm/test.asm @@ -0,0 +1,13 @@ +start: +init: + clrf PORTA ; make sure port A output latches are low + clrf PORTB ; make sure port B output latches are low + bsf STATUS,RP0 ; select memory bank 1 + movlw b'11111111' ; set port A data direction to inputs + movwf TRISA + movlw b'00000000' ; set port B data direction to outputs + movwf TRISB + bcf STATUS,RP0 ; select memory bank 0 + goto main +main: + END ; ends the program |