Mercurial > lcfOS
comparison python/testc3.py @ 213:003c8a976fff
Merge of semantics and parser again ..
author | Windel Bouwman |
---|---|
date | Fri, 05 Jul 2013 11:18:48 +0200 |
parents | d77cb5962cc5 |
children | c1ccb1cb4cef |
comparison
equal
deleted
inserted
replaced
212:62386bcee1ba | 213:003c8a976fff |
---|---|
54 var int hahaa = 23 * 2; | 54 var int hahaa = 23 * 2; |
55 | 55 |
56 | 56 |
57 """ | 57 """ |
58 | 58 |
59 | |
60 def c3compile(src, diag): | |
61 # Structures: | |
62 builder = c3.Builder(diag) | |
63 ir = builder.build(src) | |
64 # optional optimize here | |
65 x86gen = x86.X86CodeGenSimple(diag) | |
66 ok = len(diag.diags) == 0 | |
67 if not ok: | |
68 return | |
69 print('generating x86 code') | |
70 x86gen.genBin(ir) | |
71 with open('dummydummy.asm', 'w') as f: | |
72 f.write('bits 64\n') | |
73 for a in x86gen.asm: | |
74 print(a) | |
75 f.write(str(a) + '\n') | |
76 | |
77 def do(): | |
78 diag = ppci.DiagnosticsManager() | |
79 c3compile(testsrc, diag) | |
80 | |
81 class testLexer(unittest.TestCase): | 59 class testLexer(unittest.TestCase): |
82 def testUnexpectedCharacter(self): | 60 def testUnexpectedCharacter(self): |
83 snippet = """ var s \u6c34 """ | 61 snippet = """ var s \u6c34 """ |
84 with self.assertRaises(ppci.CompilerError): | 62 with self.assertRaises(ppci.CompilerError): |
85 list(c3.lexer.tokenize(snippet)) | 63 list(c3.lexer.tokenize(snippet)) |
222 """ | 200 """ |
223 ircode = self.builder.build(snippet) | 201 ircode = self.builder.build(snippet) |
224 if not ircode: | 202 if not ircode: |
225 self.diag.printErrors(snippet) | 203 self.diag.printErrors(snippet) |
226 self.assertTrue(ircode) | 204 self.assertTrue(ircode) |
205 | |
206 @unittest.skip | |
207 def testPointerType(self): | |
208 snippet = """ | |
209 package testpointer; | |
210 var int* pa; | |
211 function void t(int a, double b) | |
212 { | |
213 *pa = 22; | |
214 } | |
215 """ | |
216 self.diag.clear() | |
217 ircode = self.builder.build(snippet) | |
218 if not ircode: | |
219 self.diag.printErrors(snippet) | |
220 self.assertTrue(ircode) | |
221 | |
222 @unittest.skip | |
223 def testComplexType(self): | |
224 snippet = """ | |
225 package testpointer; | |
226 type int my_int; | |
227 | |
228 type struct { | |
229 int x, y; | |
230 } point; | |
231 | |
232 type struct { | |
233 int mem1; | |
234 int memb2; | |
235 point P1; | |
236 } my_struct; | |
237 | |
238 type my_struct* my_sptr; | |
239 | |
240 function void t(int a, double b, my_sptr x) | |
241 { | |
242 var my_struct *msp; | |
243 | |
244 msp = x; | |
245 *pa = 22; | |
246 x->memb2 = *pa + a * b; | |
247 | |
248 mxp->P1.x = a * x->P1.y; | |
249 } | |
250 """ | |
251 self.diag.clear() | |
252 ircode = self.builder.build(snippet) | |
253 if not ircode: | |
254 self.diag.printErrors(snippet) | |
255 self.assertTrue(ircode) | |
227 | 256 |
228 def test2(self): | 257 def test2(self): |
229 # testsrc2 is valid code: | 258 # testsrc2 is valid code: |
230 testsrc2 = """ | 259 testsrc2 = """ |
231 package test2; | 260 package test2; |
252 self.diag.clear() | 281 self.diag.clear() |
253 ir = self.builder.build(testsrc2) | 282 ir = self.builder.build(testsrc2) |
254 self.assertTrue(ir) | 283 self.assertTrue(ir) |
255 | 284 |
256 if __name__ == '__main__': | 285 if __name__ == '__main__': |
257 do() | |
258 unittest.main() | 286 unittest.main() |
259 | 287 |
260 | 288 |