/
NewCompile.py
executable file
·59 lines (47 loc) · 1.3 KB
/
NewCompile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
58
59
import sys
import compiler
from compiler.ast import *
from Flatten import flatten
from explicate import entry
from selectInstructions import compile
from heapify import heap
from Closure import close
from uniquify import uniquify
#import parser
WHITE = "\x1B[0m"
RED = "\x1B[31m"
MAGENTA = "\x1B[35m"
YELLOW = "\x1B[33m"
GREEN = "\x1B[32m"
CYAN = "\x1B[36m"
BLUE = "\x1B[0;34m"
PURPLE = "\x1B[0;35m"
def ColorPrint(expr,color):
print color+str(expr)+WHITE
def main():
# try:
# argv1_str = str(sys.argv[1])
# except:
# print("Why you no give me argv 1 >:(")
# print("Example call to pyyc:")
# print("./pyyc tests/test1.py")
# sys.exit()
#New flow ast -> flat(ast) -> heapify(ast) -> -> explicate(ast) -> compile(ast)
#Get standard AST from file
#ast = compiler.parseFile(argv1_str)
name = sys.argv[1]
ast = compiler.parseFile(name)
flat = flatten(ast)
print ast
ColorPrint(flat, MAGENTA)
#heap = heapify(flat)
#compile(flat, "test.py")
heapAST = heap(flat)
ColorPrint(heapAST, CYAN)
(closed, closureMap) = close(heapAST)
ColorPrint(closed, YELLOW)
(explicit, stackFrame) = entry(closed)
#print stackFrame
ColorPrint(explicit, GREEN)
compileAST = compile(explicit, name, stackFrame, closureMap)
main()