main.c 6.41 KB
Newer Older
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
1
#include <stdio.h>
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
2
#include <stdbool.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

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
11
12
13
14
int main() {
    init_mem();
    init_desc();
    init_prim();
15

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
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
    // char* funstream = "25 F13 example.Start0 0 LI1 29 F4 main0 0 VF13 example.Start";
    // 1
    // char* funstream = "20 F9 example.c1 1 VA0 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
    // 1
    // 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";
    // 1	
    // 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";
    // 2
    // char* funstream = "20 F9 example.c2 2 VA1 40 F13 example.Start0 0 AF9 example.c1 LI2 29 F4 main0 0 VF13 example.Start";
    // example.c 2
    // char* funstream = "20 F9 example.c3 7 VA1 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
    // example.c 1	
    // char* funstream = "20 F9 example.c3 7 VA1 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
    // example.c 1
    // 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";
    // example.c 1 2
    // 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";
    // 33
    // 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";
    // 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
    // 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";
    // example.A 5 6
    // 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";
    // example._R 6 7
    // 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";
    // 9
    // 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
    //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";
    // 17
    //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
    // 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]]]]
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
58
    // char* funstream = "44 F13 example.Start0 0 AF11 example.fib1 LI36 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 ";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
59
60
    // fib

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
61
    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";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
62
63
    //braun

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
64
65
66
    printf("sizeof(int): %d, sizeof(long): %d, sizeof(void*): %d, sizeof(Thunk): %d\n\n", 
            sizeof(int), sizeof(long), sizeof(void*), sizeof(Thunk));
    
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
67
68
69
70
71
    int nrfuns = parse(&funstream, strlen(funstream));
    printf("Number of functions parsed: %d\n", nrfuns);

    // TODO: put it into a special "expression" space, instead of "code"

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
72
73
    //char *exprstream = "VF13 example.Start";
    char *exprstream = "VF11 Braun.Start";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
74
75

    Code* expr = parseTerm(&exprstream);
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
76
    
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
77
78
79
80
81
    Thunk* res = exec(expr, stack_top, NULL, true);
    eval(res);
    print(res, true);

    print_stat();
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
82
}