blob: 7b17c38a8594856c0edba052306a84eb227a2a37 [file] [log] [blame]
Damien429d7192013-10-04 19:53:11 +01001#include <stdint.h>
2#include <stdio.h>
3#include <string.h>
4
5#include "misc.h"
6#include "lexer.h"
7#include "machine.h"
8#include "parse.h"
9#include "compile.h"
10#include "runtime.h"
11
12int main(int argc, char **argv) {
13 qstr_init();
14 rt_init();
15
16 if (argc != 2) {
17 printf("usage: py <file>\n");
18 return 1;
19 }
20 py_lexer_t *lex = py_lexer_from_file(argv[1]);
21 //const char *pysrc = "def f():\n x=x+1\n print(42)\n";
22 //py_lexer_t *lex = py_lexer_from_str_len("<>", pysrc, strlen(pysrc), false);
23 if (lex == NULL) {
24 return 1;
25 }
26
27 if (0) {
28 while (!py_lexer_is_kind(lex, PY_TOKEN_END)) {
29 py_token_show(py_lexer_cur(lex));
30 py_lexer_to_next(lex);
31 }
32 } else {
33 py_parse_node_t pn = py_parse(lex, 0);
34 //printf("----------------\n");
35 //parse_node_show(pn, 0);
36 //printf("----------------\n");
37 py_compile(pn);
38 //printf("----------------\n");
39 }
40
41 py_lexer_free(lex);
42
43 if (1) {
44 // execute it
45 py_obj_t module_fun = rt_make_function_from_id(1);
46 if (module_fun != py_const_none) {
47 py_obj_t ret = rt_call_function_0(module_fun);
48 printf("done! got: ");
49 py_obj_print(ret);
50 printf("\n");
51 }
52 }
53
54 rt_deinit();
55
56 //printf("total bytes = %d\n", m_get_total_bytes_allocated());
57 return 0;
58}