diff options
author | Camil Staps | 2016-08-26 16:51:17 +0200 |
---|---|---|
committer | Camil Staps | 2016-08-26 16:51:17 +0200 |
commit | 687f1b3c2911090682ad02dff0e18688b8735e57 (patch) | |
tree | d7d4a4c8f445412f00bbbb3def094aab34e7cb8b | |
parent | LCD working; simple test (diff) |
Added fuspel
-rw-r--r-- | .gitmodules | 3 | ||||
-rw-r--r-- | firmware/Makefile | 24 | ||||
m--------- | firmware/fuspel | 0 | ||||
-rw-r--r-- | firmware/main.c | 116 | ||||
m--------- | firmware/t6963c | 0 |
5 files changed, 69 insertions, 74 deletions
diff --git a/.gitmodules b/.gitmodules index c9f056f..b532b3e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "firmware/t6963c"] path = firmware/t6963c url = https://github.com/camilstaps/T6963C_PIC +[submodule "firmware/fuspel"] + path = firmware/fuspel + url = https://github.com/camilstaps/fuspel.git diff --git a/firmware/Makefile b/firmware/Makefile index 5aec099..d1493ea 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -8,12 +8,11 @@ CFLAGS:=\ -Wall\ -I$(IDIR)\ -mcpu=$(MCU)\ - -g\ -msmart-io=1\ -Wl,--script=p$(MCU).gld\ -Wl,--gc-sections\ -Wl,--stack=16\ - -Wl,--heap=2048\ + -Wl,--heap=16384\ -Wl,--local-stack\ -Wl,--check-sections\ -Wl,--data-init\ @@ -35,7 +34,15 @@ _DEPS:=\ init.h\ t6963c_specific.h\ t6963c/t6963c.h\ - t6963c/terminal.h + t6963c/terminal.h\ + fuspel/interpreter/code.h\ + fuspel/interpreter/eval.h\ + fuspel/interpreter/lex.h\ + fuspel/interpreter/log.h\ + fuspel/interpreter/mem.h\ + fuspel/interpreter/parse.h\ + fuspel/interpreter/print.h\ + fuspel/interpreter/syntax.h DEPS:=$(patsubst %,$(IDIR)/%,$(_DEPS)) _OBJ:=main.o $(subst .h,.o,$(_DEPS)) @@ -47,7 +54,7 @@ ASM:=$(patsubst %,$(ODIR)/%,$(_ASM)) .PHONY: all all_hex all_assembly clean all: all_hex - + all_hex: $(HEX) all_assembly: $(ASM) @@ -56,17 +63,16 @@ $(ODIR)/%.hex: $(ODIR)/%.out $(BIN2HEX) $< $(ODIR)/%.out: $(OBJ) - $(CC) $(CFLAGS)\ - -Wl,-Map -Wl,$(ODIR)/$(notdir $(basename $@)).map\ - -o $@ $^ + $(CC) -o $@ $^ $(CFLAGS)\ + -Wl,-Map -Wl,$(ODIR)/$(notdir $(basename $@)).map $(ODIR)/%.o: %.c $(DEPS) mkdir -p $(dir $@) - $(CC) $(CFLAGS) -c -o $@ $< + $(CC) -c -o $@ $< $(CFLAGS) $(ODIR)/%.s: %.c mkdir -p $(dir $@) - $(CC) $(CFLAGS) -S -o $@ $< + $(CC) -S -o $@ $< $(CFLAGS) clean: $(RM) -r $(ODIR) diff --git a/firmware/fuspel b/firmware/fuspel new file mode 160000 +Subproject c2807cad6ee36339d1af3e103946d48a3f8cc3b 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; } diff --git a/firmware/t6963c b/firmware/t6963c -Subproject b228b23ce92f390d717c80d3e8331dc15727094 +Subproject cc4261465117854e832f45a32c2b63b01b0465d |