comparison python/testc3.py @ 152:b73bc14a3aa3

Light coupling ide and c3 frontend
author Windel Bouwman
date Sat, 02 Mar 2013 09:56:12 +0100
parents afc8c0207984
children b28a11c01dbe
comparison
equal deleted inserted replaced
151:afc8c0207984 152:b73bc14a3aa3
1 import c3 1 import c3, time, ppci
2 from ppci.errors import printError, Diagnostics
3 import time
4 2
5 testsrc = """ 3 testsrc = """
6 package test; 4 package test;
7 5
8 var u32 c, d; 6 var u32 c, d;
48 for s in ast.scope: 46 for s in ast.scope:
49 printAst(s, indent + ' ') 47 printAst(s, indent + ' ')
50 for c in ast.getChildren(): 48 for c in ast.getChildren():
51 printAst(c, indent + ' ') 49 printAst(c, indent + ' ')
52 50
53 def c3compile(src): 51 def c3compile(src, diag):
54 print('[0] source:') 52 print('[0] source:')
55 print(src) 53 print(src)
56 print('[1] parsing') 54 print('[1] parsing')
57 diag = Diagnostics()
58 sema = c3.Semantics(diag) 55 sema = c3.Semantics(diag)
59 p = c3.Parser(sema, diag) 56 p = c3.Parser(sema, diag)
60 tc = c3.TypeChecker(diag) 57 tc = c3.TypeChecker(diag)
61 al = c3.Analyzer(diag) 58 al = c3.Analyzer(diag)
62 cg = c3.CodeGenerator() 59 cg = c3.CodeGenerator()
70 print('checktime: {0} [s]'.format(t3 - t2)) 67 print('checktime: {0} [s]'.format(t3 - t2))
71 print('{0} errors'.format(len(diag.diags))) 68 print('{0} errors'.format(len(diag.diags)))
72 69
73 for d in diag.diags: 70 for d in diag.diags:
74 print('ERROR:') 71 print('ERROR:')
75 printError(testsrc, d) 72 ppci.printError(testsrc, d)
76 print('[2] ast:') 73 print('[2] ast:')
77 printAst(sema.mod) 74 printAst(sema.mod)
78 75
79 ok = len(diag.diags) == 0 76 ok = len(diag.diags) == 0
80 if ok: 77 if ok:
81 cg.gencode(sema.mod) 78 cg.gencode(sema.mod)
82 else: 79 else:
83 print('Not generating code') 80 print('Not generating code')
84 81
85 def do(): 82 def do():
86 c3compile(testsrc) 83 diag = ppci.DiagnosticsManager()
84 c3compile(testsrc, diag)
87 85
88 do() 86 do()
89 87