Mercurial > python-compiler.rs
annotate src/main.rs @ 18:51ef651266b1
Fix expr_contexts.
Do not always use Load, get the real context from the node.
author | Bastien Orivel <eijebong@bananium.fr> |
---|---|
date | Fri, 03 Jun 2016 00:10:41 +0200 |
parents | 38b0d63697b1 |
children | 25b202005d1d |
rev | line source |
---|---|
0 | 1 extern crate cpython; |
2 | |
3 mod python_tb; | |
4 mod python_parse; | |
5 mod python_dump; | |
6 mod python_ast; | |
7 mod ast_convert; | |
8 mod ast_dump; | |
13
38b0d63697b1
Import the full AST grammar from CPython 3.5.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
9
diff
changeset
|
9 //mod ast_scope; |
0 | 10 //mod ast_rewrite; |
9
fa7e285f88e7
Add a scoping pass, associating each module/statement with a block.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
11 //mod ast_type; |
0 | 12 |
13 use std::fs::File; | |
14 use std::io::Read; | |
15 | |
16 fn main() { | |
17 let filename = match std::env::args().nth(1) { | |
18 Some(filename) => filename, | |
19 None => { | |
20 // TODO: use stderr instead. | |
21 println!("USAGE: {} <filename> [filename…]", std::env::args().nth(0).unwrap()); | |
22 std::process::exit(1); | |
23 } | |
24 }; | |
25 | |
26 let code = { | |
27 let mut file = match File::open(&filename) { | |
28 Ok(file) => file, | |
29 Err(err) => { | |
30 // TODO: use stderr instead. | |
31 println!("Error while opening file “{}”: {}", filename, err); | |
32 std::process::exit(2); | |
33 } | |
34 }; | |
35 let mut code = String::new(); | |
36 file.read_to_string(&mut code).unwrap(); | |
37 code | |
38 }; | |
39 | |
40 let module = match python_parse::parse_ast(code) { | |
41 Ok(module) => module, | |
42 Err(err) => { | |
43 // TODO: use stderr instead. | |
44 println!("Error while parsing file “{}”:", filename); | |
45 python_tb::traceback(err); | |
46 std::process::exit(3); | |
47 } | |
48 }; | |
49 | |
50 //python_dump::dump_module(&module); | |
51 let module_ast = ast_convert::convert_ast("__main__".to_string(), &module); | |
52 ast_dump::dump_ast(&module_ast); | |
13
38b0d63697b1
Import the full AST grammar from CPython 3.5.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
9
diff
changeset
|
53 //let scoped_ast = ast_scope::scope_ast(vec!(module_ast)); |
38b0d63697b1
Import the full AST grammar from CPython 3.5.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
9
diff
changeset
|
54 //println!("{:#?}", scoped_ast); |
38b0d63697b1
Import the full AST grammar from CPython 3.5.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
9
diff
changeset
|
55 //let new_scoped_ast = ast_scope::check_scoping(scoped_ast); |
38b0d63697b1
Import the full AST grammar from CPython 3.5.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
9
diff
changeset
|
56 //println!("{:#?}", new_scoped_ast); |
0 | 57 //ast_rewrite::rewrite_ast(module_ast); |
9
fa7e285f88e7
Add a scoping pass, associating each module/statement with a block.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
58 //ast_type::type_ast(scoped_ast); |
0 | 59 } |