]> git.bts.cx Git - sun.git/blob - runtime/src/sun/compiler/compiler.c
do not evaluate variables until they are used
[sun.git] / runtime / src / sun / compiler / compiler.c
1 #include <sun/compiler/compiler_internal.h>
2
3 #include <stdio.h>
4
5 #include "sun_parser.h" // This needs to be first.
6 #include "sun_lexer.h"
7
8 #include <sun/compiler/vm_generator.h>
9 #include <sun/tree/node.h>
10 #include <sun/tree/tree.h>
11 #include <sun/vm/vm.h>
12
13 extern int yyparse(SLTNode **moduleOut, yyscan_t *scanner);
14
15 SVMModule *slcCompileSource(const SLCCompileConfiguration *configuration) {
16 yyscan_t sc;
17 int res;
18 SLCLexerExtra extra;
19
20 extra.readCallback = configuration->sourceReadCallback;
21 extra.readCallbackParameter = configuration->sourceUserParam;
22
23 yylex_init_extra(&extra, &sc);
24 SLTNode *module = NULL;
25 int parse_return = yyparse(&module, sc);
26 yylex_destroy(sc);
27
28 switch (parse_return) {
29 case 0:
30 return slcGenerateVMInstructions(module);
31
32 case 1:
33 printf("Error\n");
34 return NULL;
35
36 case 2:
37 printf("Out of memory\n");
38 return NULL;
39
40 default:
41 printf("Unknown error...\n");
42 return NULL;
43 }
44 }