main.c 6.06 KB
Newer Older
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
1
2

#include <stdio.h>
3
#include <string.h>
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
4

5
#include "desc.h"
6
#include "prim.h"
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
7
#include "parse.h"
8
#include "code.h"
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
9
#include "mem.h"
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
10
11
12
13

int main()
{   
	init_mem();
14
	init_desc();
15
	init_prim();
16
	
17
	// char* funstream = "25 F13 example.Start0 0 LI1 29 F4 main0 0 VF13 example.Start";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
18
	// 1
19
	// char* funstream = "20 F9 example.c1 1 VA0 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
20
	// 1
21
	// char* funstream = "20 F9 example.c2 1 VA0 44 F13 example.Start0 0 AF9 example.c2 LI2 LI1 29 F4 main0 0 VF13 example.Start";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
22
	// 1	
23
	// char* funstream = "20 F9 example.c2 2 VA1 44 F13 example.Start0 0 AF9 example.c2 LI2 LI1 29 F4 main0 0 VF13 example.Start";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
24
	// 2
25
	// char* funstream = "20 F9 example.c2 2 VA1 40 F13 example.Start0 0 AF9 example.c1 LI2 29 F4 main0 0 VF13 example.Start";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
26
	// example.c 2
27
	// char* funstream = "20 F9 example.c3 7 VA1 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
28
	// example.c 1	
29
	// char* funstream = "20 F9 example.c3 7 VA1 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
30
	// example.c 1
31
	// char* funstream = "20 F9 example.c3 7 VA1 44 F13 example.Start0 0 AF9 example.c2 LI1 LI2 29 F4 main0 0 VF13 example.Start";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
32
	// example.c 1 2
33
	// char* funstream = "20 F9 example.c3 7 VA1 49 F13 example.Start0 0 AF9 example.c3 LI1 LI33 LI2 29 F4 main0 0 VF13 example.Start";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
34
	// 33
35
	// char* funstream = "33 A2 9 example.A2 2 9 example.B0 0 34 F13 example.Start0 0 VF9 example.B29 F4 main0 0 VF13 example.Start";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
36
37
38
	// example.B
	// char* funstream = "33 A2 9 example.A2 2 9 example.B0 0 40 F13 example.Start0 0 AF9 example.A1 LI5 29 F4 main0 0 VF13 example.Start";
	// example.A 5
39
	// char* funstream = "33 A2 9 example.A2 2 9 example.B0 0 44 F13 example.Start0 0 AF9 example.A2 LI5 LI6 29 F4 main0 0 VF13 example.Start";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
40
	// example.A 5 6
41
	// char* funstream = "40 R10 example._R2 1 9 example.a9 example.b46 F13 example.Start0 0 AF10 example._R2 LI6 LI7 29 F4 main0 0 VF13 example.Start";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
42
	// example._R 6 7
43
	// char* funstream = "26 F9 example.g2 2 AA1 1 VA0 20 F9 example.f2 1 VA0 59 F13 example.Start0 0 AF9 example.g2 AF9 example.f1 LI8 LI9 29 F4 main0 0 VF13 example.Start";
44
	// 9
45
46
	// char* funstream = "26 F9 example.g2 2 AA1 1 VA0 20 F9 example.f2 2 VA1 59 F13 example.Start0 0 AF9 example.g2 AF9 example.f1 LI8 LI9 29 F4 main0 0 VF13 example.Start";
	// 8
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
47
	//char* funstream = "26 F9 example.g2 2 AA1 1 VA0 37 F12 example.f_502 3 AF3 add2 VA1 VA0 63 F13 example.Start0 0 AF9 example.g2 AF12 example.f_501 LI8 LI9 29 F4 main0 0 VF13 example.Start";
48
	// 17
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
49
50
51
52
53
54
55
56
	//char* funstream = "33 A2 9 example.A2 0 9 example.B0 0 49 F13 example.Start0 0 AF9 example.f1 VF9 example.B57 F9 example.f1 1 SVA0 2 C9 example.BLI11 C9 example.ALI22 ";
	// 11	
	// char* funstream = "33 A2 9 example.A2 0 9 example.B0 0 61 F13 example.Start0 0 AF9 example.f1 AF9 example.A2 LI33 LI44 57 F9 example.f1 1 SVA0 2 C9 example.BLI11 C9 example.ALI22 ";
	// 22
	// char* funstream = "33 A2 9 example.A2 0 9 example.B0 0 61 F13 example.Start0 0 AF9 example.f1 AF9 example.A2 LI33 LI44 56 F9 example.f1 1 SVA0 2 C9 example.BLI11 C9 example.AVL0 ";
	// 33
	// char* funstream = "33 A2 9 example.A2 0 9 example.B0 0 61 F13 example.Start0 0 AF9 example.f1 AF9 example.A2 LI33 LI44 56 F9 example.f1 1 SVA0 2 C9 example.BLI11 C9 example.AVL1 ";
	// 44
57
58
	// char* funstream = "160 F13 example.Start0 0 AF11 example.map2 VF11 example.incAF17 _predefined._Cons2 LI1 AF17 _predefined._Cons2 LI2 AF17 _predefined._Cons2 LI3 VF16 _predefined._Nil36 F11 example.inc1 1 AF3 add2 VA0 LI1 148 F11 example.map2 1 SVA0 2 C16 _predefined._NilVF16 _predefined._NilC17 _predefined._ConsAF17 _predefined._Cons2 AA1 1 VL0 AF11 example.map2 VA1 VL1 50 A2 17 _predefined._Cons2 0 16 _predefined._Nil0 0 ";
	// [_predefined._Cons [2] [_predefined._Cons [3] [_predefined._Cons [4] [_predefined._Nil]]]]
59
60
	 char* funstream = "43 F13 example.Start0 0 AF11 example.fib1 LI5 119 F11 example.fib1 1 IAF2 lt2 VA0 LI2 LI1 AF3 add2 AF11 example.fib1 AF3 sub2 VA0 LI1 AF11 example.fib1 AF3 sub2 VA0 LI2 ";
	// fib
61
	
62
63
	// char* funstream = "29 F9 Braun.int1 1 IVA0 LI1 LI0 27 F9 Braun.and2 2 IVA1 VA0 L099 F9 Braun.all2 1 SVA0 2 C9 Flite.NilL1C10 Flite.ConsAF9 Braun.and2 AA1 1 VL0 AF9 Braun.all2 VA1 VL1 98 F16 Braun._c;39;3_203 4 IAF3 eqB2 VA2 L0L0IAF3 eqB2 VA2 L1AF14 Braun.equal_182 VA1 VA0 VF7 nomatch175 F14 Braun.equal_182 3 SVA1 2 C9 Flite.NilSVA0 2 C9 Flite.NilL1C10 Flite.ConsL0C10 Flite.ConsSVA0 2 C9 Flite.NilL0C10 Flite.ConsAF16 Braun._c;39;3_203 AF3 eqI2 VL0 VL2 VL1 VL3 176 F9 Braun.ilv2 3 SVA1 2 C9 Flite.NilVA0 C10 Flite.ConsSVA0 2 C9 Flite.NilAF10 Flite.Cons2 VL0 VL1 C10 Flite.ConsAF10 Flite.Cons2 VL0 AF10 Flite.Cons2 VL2 AF9 Braun.ilv2 VL1 VL3 153 F12 Braun.toList1 1 SVA0 2 C11 Braun.EmptyVF9 Flite.NilC12 Braun.BranchAF10 Flite.Cons2 VL0 AF9 Braun.ilv2 AF12 Braun.toList1 VL1 AF12 Braun.toList1 VL2 40 A2 11 Braun.Empty0 0 12 Braun.Branch3 0 167 F12 Braun.insert2 1 SVA0 2 C11 Braun.EmptyAF12 Braun.Branch3 VA1 VF11 Braun.EmptyVF11 Braun.EmptyC12 Braun.BranchAF12 Braun.Branch3 VA1 AF12 Braun.insert2 VL0 VL2 VL1 119 F14 Braun.fromList1 1 SVA0 2 C9 Flite.NilVF11 Braun.EmptyC10 Flite.ConsAF12 Braun.insert2 VL0 AF14 Braun.fromList1 VL1 90 F13 Braun.prop_171 1 AF14 Braun.equal_182 VA0 AF12 Braun.toList1 AF14 Braun.fromList1 VA0 118 F15 Braun.replicate2 2 IAF3 eqI2 VA1 LI0 VF9 Flite.NilAF10 Flite.Cons2 VA0 AF15 Braun.replicate2 AF3 sub2 VA1 LI1 VA0 44 F11 Braun.<=_162 3 AF3 not1 AF2 lt2 VA0 VA1 35 A2 9 Flite.Nil0 0 10 Flite.Cons2 0 121 F12 Braun.fromTo2 3 IAF11 Braun.<=_162 VA1 VA0 AF10 Flite.Cons2 VA1 AF12 Braun.fromTo2 AF3 add2 VA1 LI1 VA0 VF9 Flite.Nil125 F11 Braun.Start0 0 AF9 Braun.int1 AF9 Braun.all2 VF13 Braun.prop_17AF15 Braun.replicate2 LI6000 AF12 Braun.fromTo2 LI0 LI255 27 F4 main0 0 VF11 Braun.Start";
	//braun
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
64
65
	
	int nrfuns = parse(&funstream, strlen(funstream));		
66
67
68
69
	printf("Number of functions parsed: %d\n", nrfuns);	
		
	// TODO: put it into a special "expression" space, instead of "code"

70
	char *exprstream = "VF13 example.Start";
71
	//char *exprstream = "VF11 Braun.Start";
72
73
	
	Code* expr = parseTerm(&exprstream);	
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
74
	
75
	Thunk* res = exec(expr, stack_top, NULL);
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
76
77
	eval(res);
	print(res, true);
78
	
79
	print_stat();
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
80
}