diff options
Diffstat (limited to 'firmware/main.c')
-rw-r--r-- | firmware/main.c | 116 |
1 files changed, 51 insertions, 65 deletions
diff --git a/firmware/main.c b/firmware/main.c index d03b3e2..11f249f 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -1,89 +1,75 @@ #include <xc.h> +#include <stdlib.h> +#include <math.h> +#include <stdio.h> +#include <string.h> + #include "init.h" #include "t6963c/t6963c.h" #include "t6963c/terminal.h" +#include "fuspel/interpreter/lex.h" +#include "fuspel/interpreter/parse.h" +#include "fuspel/interpreter/eval.h" +#include "fuspel/interpreter/print.h" +#include "fuspel/interpreter/mem.h" + static Terminal* term; -//unsigned char* string = "me@pic:~$ ls -//me@pic:~$ mkdir docs -//me@pic:~$ cd docs/ -//me@pic:~/docs$ ls -//me@pic:~/docs$ touch doc.txt -//me@pic:~/docs$ ls -//doc.txt -//me@pic:~/docs$ cat doc.txt -//me@pic:~/docs$ echo hello > doc.txt -//me@pic:~/docs$ cat doc.txt -//hello -//me@pic:~/docs$ cd .. -//me@pic:~$ tree -fFi -//. -//./docs/ -//./docs/doc.txt -// -//1 directory, 1 file -//me@pic:~$ rm -r docs/ -//"; -const static char* string = - "[me@pic ~] ls\n" - "[me@pic ~] mkdir docs\n" - "[me@pic ~] cd docs/\n" - "[me@pic docs] ls\n" - "[me@pic docs] touch doc.txt\n" - "[me@pic docs] ls\n" - "doc.txt\n" - "[me@pic docs] cat doc.txt\n" - "[me@pic docs] echo hello > doc.txt\n" - "[me@pic docs] cat doc.txt\n" - "hello\n" - "[me@pic docs] cd ..\n" - "[me@pic ~] tree -fFi\n" - ".\n" - "./docs/\n" - "./docs/doc.txt\n" - "\n" - "1 directory, 1 file\n" - "[me@pic ~] rm -r docs/\n"; +int __attribute__((__weak__, __section__(".libc"))) write( + int handle, void *buff, unsigned int len) { + terminal.append_n(term, (char*) buff, len); + return len; +} void init_terminal(void) { term = terminal.construct(t6963c_rows * t6963c_columns); term->update = t6963c_update_terminal; } -void loop_string(void) { - unsigned short i, j; - unsigned char state = 0; // 0 = quick, 1 = slow - for (i = 0; string[i]; i++) { - if (!terminal.appendChar(term, string[i])) { - terminal.free(term); - t6963c_clear(); - t6963c_set_address(5,5); - t6963c_writeString("ERROR"); - while (1); - } - if (string[i] == ']') { - state = 1; - terminal.appendChar(term, string[++i]); - __delay_ms(800); - } else if (string[i] == '\n') { - state = 0; - } - if (state) { - __delay_ms(80); - } - } -} +static char* program = + "mul a b = code mul a b;" + "sub a b = code sub a b;" + "prod = foldr mul 1;" + "faclist 0 = [];" + "faclist n = [n:faclist (sub 1 n)];" + "foldr op r [] = r;" + "foldr op r [a:x] = op a (foldr op r x);" + "main = prod (faclist 5);"; int main(void) { init(); init_terminal(); - while (1) { - loop_string(); + token_list* tokens; + fuspel* pgm; + expression* result; + + tokens = lex(NULL, program); + pgm = parse(tokens); + free_token_list(tokens); + free(tokens); + + print_fuspel(pgm); + printf("\n\n"); + + result = eval_main(pgm); + if (result) { + print_expression(result); + printf("\n"); + + free_expression(result); + free(result); + } else { + printf("Evaluation failed...\n\n"); } + free_fuspel(pgm); + free(pgm); + + while (1) Idle(); + return 0; } |