main.c 1.35 KB
Newer Older
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
1
#include <stdio.h>
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
2
#include <stdlib.h>
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
3
#include <stdbool.h>
4
#include <string.h>
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
5

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
6
7
#include "getline.h"

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

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
15
16
int main ( int argc, char *argv[] )
{
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
17
18
19
    init_mem();
    init_desc();
    init_prim();
20

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
21
22
23
24
25
26
27
28
29
30
31
    char* input = "..\\tests\\Braun.bsapl";
    
    if ( argc == 2 )
    {
        input = argv[1];
    }

    FILE* file = fopen(input, "r");
    char* line = NULL;
    size_t bufsize = 0;
    size_t len = 0;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
32

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    if ( file == 0 )
    {
        printf( "Could not open file\n" );
    }
    else 
    {	
        len = getline(&line, &bufsize, file);
        if(len == -1)
        {
            printf( "No Input\n" );
        }
			
        fclose( file );
        if(len == -1) exit(-1);
    }
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
48

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
49
#ifdef DEBUG
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
50
51
    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
52
#endif
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
53
    
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
54
55
56
    int nrfuns = parse(&line, len);

#ifdef DEBUG
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
57
    printf("Number of functions parsed: %d\n", nrfuns);
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
58
#endif
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
59
60

    // TODO: put it into a special "expression" space, instead of "code"
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
61
    char *exprstream = "VF4 main";
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
62
63

    Code* expr = parseTerm(&exprstream);
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
64
    
65
    Thunk* res = exec(expr, stack_top_a, NULL, true);
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
66
67
68
    eval(res);
    print(res, true);

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
69
#ifdef DEBUG
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
70
    print_stat();
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
71
#endif
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
72
}