blob: 11f249fd79895bb69b3b3d9eabb65082a951f9a8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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;
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;
}
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();
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;
}
|