annotate test/testc3.py @ 393:6ae782a085e0

Added init program
author Windel Bouwman
date Sat, 17 May 2014 21:17:40 +0200
parents 2ec730e45ea1
children fb3c1f029b30
rev   line source
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
1 import unittest
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
2 import logging
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
3 import io
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 313
diff changeset
4 from ppci.c3 import Builder, Lexer
86b02c98a717 Moved target directory
Windel Bouwman
parents: 313
diff changeset
5 from ppci.target import SimpleTarget
86b02c98a717 Moved target directory
Windel Bouwman
parents: 313
diff changeset
6 import ppci
148
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
7
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
8
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
9 class testLexer(unittest.TestCase):
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
10 def setUp(self):
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
11 diag = ppci.DiagnosticsManager()
300
Windel Bouwman
parents: 295
diff changeset
12 self.l = Lexer(diag)
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
13
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
14 def testUnexpectedCharacter(self):
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
15 snippet = io.StringIO(""" var s \u6c34 """)
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
16 with self.assertRaises(ppci.CompilerError):
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
17 list(self.l.tokenize(snippet))
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
18
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
19 def check(self, snippet, toks):
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
20 toks2 = list(tok.typ for tok in self.l.tokenize(io.StringIO(snippet)))
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
21 self.assertSequenceEqual(toks, toks2)
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
22
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
23 def testBlockComment(self):
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
24 snippet = """
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
25 /* Demo */
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
26 var int x = 0;
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
27 """
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
28 toks = ['var', 'ID', 'ID', '=', 'NUMBER', ';', 'END']
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
29 self.check(snippet, toks)
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
30
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
31 def testBlockCommentMultiLine(self):
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
32 snippet = """
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
33 /* Demo
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
34 bla1
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
35 bla2
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
36 */
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
37 var int x = 0;
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
38 """
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
39 toks = ['var', 'ID', 'ID', '=', 'NUMBER', ';', 'END']
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
40 self.check(snippet, toks)
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
41
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
42
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
43 class testBuilder(unittest.TestCase):
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
44 def setUp(self):
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
45 self.diag = ppci.DiagnosticsManager()
301
6753763d3bec merge codegen into ppci package
Windel Bouwman
parents: 300
diff changeset
46 self.builder = Builder(self.diag, SimpleTarget())
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
47 self.diag.clear()
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
48 # Add a null logging handler to disable warning log messages:
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
49 nh = logging.NullHandler()
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
50 logging.getLogger().addHandler(nh)
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
51
306
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
52 def makeFileList(self, snippet):
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
53 """ Try to make a list with opened files """
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
54 if type(snippet) is list:
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
55 l2 = []
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
56 for s in snippet:
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
57 if type(s) is str:
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
58 l2.append(io.StringIO(s))
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
59 else:
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
60 l2.append(s)
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
61 return l2
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
62 else:
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
63 return [io.StringIO(snippet)]
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
64
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
65 def expectErrors(self, snippet, rows):
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
66 """ Helper to test for expected errors on rows """
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
67 list(self.builder.build([io.StringIO(snippet)]))
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
68 actualErrors = [err.row for err in self.diag.diags]
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
69 if rows != actualErrors:
306
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
70 self.diag.printErrors()
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
71 self.assertSequenceEqual(rows, actualErrors)
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
72 # self.assertFalse(all(ircode))
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
73
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
74 def expectOK(self, snippet):
306
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
75 """ Expect a snippet to be OK """
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
76 ircode = list(self.builder.build(self.makeFileList(snippet)))
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
77 if len(self.diag.diags) > 0:
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
78 self.diag.printErrors()
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
79 self.assertTrue(all(ircode))
306
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
80 self.assertEqual(0, len(self.diag.diags))
217
8b2e5f3cd579 Removed some stale python source files
Windel Bouwman
parents: 215
diff changeset
81 return ircode
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
82
251
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 249
diff changeset
83 def testPackage(self):
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
84 p1 = """module p1;
251
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 249
diff changeset
85 type int A;
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 249
diff changeset
86 """
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
87 p2 = """module p2;
251
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 249
diff changeset
88 import p1;
306
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
89 var p1.A b;
251
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 249
diff changeset
90 """
306
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
91 self.expectOK([p1, p2])
251
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 249
diff changeset
92
288
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
93 def testPackageMutual(self):
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
94 p1 = """module p1;
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
95 import p2;
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
96 type int A;
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
97 var p2.B b;
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
98 """
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
99 p2 = """module p2;
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
100 import p1;
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
101 var p1.A a;
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
102 """
306
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
103 self.expectOK([p1, p2])
288
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
104
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
105 def testConstant(self):
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
106 snip = """module C;
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
107 const int a = 2;
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
108 """
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
109 self.expectOK(snip)
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
110
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
111 @unittest.skip('Not checked yet')
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
112 def testConstantMutual(self):
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
113 snip = """module C;
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
114 const int a = b + 1;
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
115 const int b = a + 1;
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
116 function void f()
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
117 {
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
118 return b;
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
119 }
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
120 """
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
121 self.expectOK(snip)
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 311
diff changeset
122
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
123 def testPackageNotExists(self):
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
124 p1 = """module p1;
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
125 import p23;
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
126 """
306
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
127 self.expectErrors(p1, [0])
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
128
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
129 def testFunctArgs(self):
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
130 snippet = """
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
131 module testargs;
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
132 function void t2(int a, double b)
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
133 {
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
134 t2(2, 2);
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
135 t2(2);
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
136 t2(1, 1.2);
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
137 }
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
138 """
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
139 self.expectErrors(snippet, [5, 6])
148
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
140
303
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
141 def testReturn(self):
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
142 snippet = """
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
143 module testreturn;
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
144 function void t()
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
145 {
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
146 return;
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
147 }
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
148 """
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
149 self.expectOK(snippet)
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
150
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
151 def testReturn2(self):
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
152 snippet = """
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
153 module testreturn;
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
154 function int t()
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
155 {
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
156 return 2;
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
157 }
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
158 """
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
159 self.expectOK(snippet)
be7f60545368 Final fixups
Windel Bouwman
parents: 301
diff changeset
160
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
161 def testExpressions(self):
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
162 snippet = """
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
163 module test;
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
164 function void t(int a, double b)
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
165 {
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
166 var int a2;
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
167 var bool c;
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
168
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
169 a2 = b * a;
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
170 c = a;
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
171 }
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
172 """
307
e609d5296ee9 Massive rewrite of codegenerator
Windel Bouwman
parents: 306
diff changeset
173 self.expectErrors(snippet, [8, 9])
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
174
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
175 def testExpression1(self):
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
176 snippet = """
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
177 module testexpr1;
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
178 function void t()
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
179 {
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
180 var int a, b, c;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
181 a = 1;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
182 b = a * 2 + a * a;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
183 c = b * a - 3;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
184 }
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
185 """
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
186 self.expectOK(snippet)
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
187
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
188 def testEmpty(self):
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
189 snippet = """
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
190 module A
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
191 """
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
192 self.expectErrors(snippet, [3])
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
193
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
194 def testEmpty2(self):
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
195 snippet = ""
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
196 self.expectErrors(snippet, [1])
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
197
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
198 def testRedefine(self):
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
199 snippet = """
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
200 module test;
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
201 var int a;
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
202 var int b;
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
203 var int a;
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
204 """
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
205 self.expectErrors(snippet, [5])
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
206
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
207 def testWhile(self):
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
208 snippet = """
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
209 module tstwhile;
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
210 function void t()
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
211 {
306
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
212 var int i;
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 303
diff changeset
213 i = 0;
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
214 while (i < 1054)
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
215 {
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
216 i = i + 3;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
217 }
307
e609d5296ee9 Massive rewrite of codegenerator
Windel Bouwman
parents: 306
diff changeset
218 }
e609d5296ee9 Massive rewrite of codegenerator
Windel Bouwman
parents: 306
diff changeset
219 """
e609d5296ee9 Massive rewrite of codegenerator
Windel Bouwman
parents: 306
diff changeset
220 self.expectOK(snippet)
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
221
307
e609d5296ee9 Massive rewrite of codegenerator
Windel Bouwman
parents: 306
diff changeset
222 def testWhile2(self):
e609d5296ee9 Massive rewrite of codegenerator
Windel Bouwman
parents: 306
diff changeset
223 snippet = """
e609d5296ee9 Massive rewrite of codegenerator
Windel Bouwman
parents: 306
diff changeset
224 module tstwhile;
e609d5296ee9 Massive rewrite of codegenerator
Windel Bouwman
parents: 306
diff changeset
225 function void t()
e609d5296ee9 Massive rewrite of codegenerator
Windel Bouwman
parents: 306
diff changeset
226 {
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
227 while(true)
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
228 {
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
229 }
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
230
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
231 while(false)
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
232 {
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
233 }
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
234 }
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
235 """
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
236 self.expectOK(snippet)
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
237
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
238 def testIf(self):
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
239 snippet = """
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
240 module tstIFF;
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
241 function void t(int b)
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
242 {
180
25a0753da4cf Re-organized files
Windel Bouwman
parents: 170
diff changeset
243 var int a;
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
244 a = 2;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
245 if (a > b)
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
246 {
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
247 if (a > 1337)
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
248 {
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
249 b = 2;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
250 }
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
251 }
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
252 else
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
253 {
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
254 b = 1;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
255 }
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
256
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
257 return b;
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 284
diff changeset
258 }
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
259 """
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
260 self.expectOK(snippet)
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
261
308
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
262 def testAndCondition(self):
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
263 snippet = """
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
264 module tst;
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
265 function void t() {
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
266 if (4 > 3 and 1 < 10) {
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
267 }
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
268 }
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
269 """
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
270 self.expectOK(snippet)
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
271
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
272 def testOrCondition(self):
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
273 snippet = """
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
274 module tst;
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
275 function void t() {
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
276 if (3 > 4 or 3 < 10) {
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
277 }
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
278 }
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
279 """
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
280 self.expectOK(snippet)
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
281
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
282 def testNonBoolCondition(self):
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
283 snippet = """
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
284 module tst;
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
285 function void t() {
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 308
diff changeset
286 if (3+3) {
308
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
287 }
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
288 }
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
289 """
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
290 self.expectErrors(snippet, [4])
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
291
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
292 def testTypeDef(self):
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
293 snippet = """
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
294 module testtypedef;
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
295 type int my_int;
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
296 function void t()
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
297 {
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
298 var my_int a;
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
299 var int b;
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
300 a = 2;
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
301 b = a + 2;
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
302 }
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
303 """
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
304 self.expectOK(snippet)
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
305
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
306 def testLocalVariable(self):
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
307 snippet = """
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
308 module testlocalvar;
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
309 function void t()
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
310 {
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
311 var int a, b;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
312 a = 2;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
313 b = a + 2;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
314 }
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
315 """
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 252
diff changeset
316 self.expectOK(snippet)
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
317
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 243
diff changeset
318 def testUnknownType(self):
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
319 snippet = """module testlocalvar;
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 243
diff changeset
320 function void t()
e41e4109addd Added current position arrow
Windel Bouwman
parents: 243
diff changeset
321 {
e41e4109addd Added current position arrow
Windel Bouwman
parents: 243
diff changeset
322 var int2 a;
e41e4109addd Added current position arrow
Windel Bouwman
parents: 243
diff changeset
323 }
e41e4109addd Added current position arrow
Windel Bouwman
parents: 243
diff changeset
324 """
e41e4109addd Added current position arrow
Windel Bouwman
parents: 243
diff changeset
325 self.expectErrors(snippet, [4])
e41e4109addd Added current position arrow
Windel Bouwman
parents: 243
diff changeset
326
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
327 def testStruct1(self):
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
328 snippet = """
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
329 module teststruct1;
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
330 function void t()
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
331 {
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
332 var struct {int x, y;} a;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
333 a.x = 2;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
334 a.y = a.x + 2;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
335 }
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
336 """
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 252
diff changeset
337 self.expectOK(snippet)
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
338
308
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
339 def testStruct2(self):
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
340 """ Select struct member from non struct type """
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
341 snippet = """
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
342 module teststruct1;
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
343 function void t() {
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
344 var int a;
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
345 a.z = 2;
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
346 }
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
347 """
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
348 self.expectErrors(snippet, [5])
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
349
354
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
350 def testArray(self):
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
351 snippet = """
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
352 module testarray;
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
353 function void t()
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
354 {
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
355 var int[100] x;
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
356 var int a, b;
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
357 a = 2;
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
358 b = x[a*2+9 - a] * x[22+12];
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
359 x[1] = x[2];
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
360 }
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
361 """
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
362 self.expectOK(snippet)
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
363
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
364 def testArrayFail(self):
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
365 snippet = """
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
366 module testarray;
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
367 function void t()
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
368 {
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
369 var bool c;
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
370 c = false;
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
371 var int[100] x;
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
372 x[1] = x[c];
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
373 }
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
374 """
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
375 self.expectErrors(snippet, [8])
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
376
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
377 def testArrayFail2(self):
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
378 snippet = """
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
379 module testarray;
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
380 function void t()
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
381 {
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
382 var int c;
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
383 var int x;
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
384 c = x[2];
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
385 }
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
386 """
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
387 self.expectErrors(snippet, [7])
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 353
diff changeset
388
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
389 @unittest.skip('TODO')
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
390 def testArrayFail3(self):
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
391 snippet = """
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
392 module testarray;
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
393 function void t()
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
394 {
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
395 var int c[20];
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
396 }
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
397 """
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
398 self.expectErrors(snippet, [7])
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
399
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
400 def testStructCall(self):
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
401 snippet = """
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
402 module teststruct1;
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
403 function void t()
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
404 {
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
405 var struct {int x, y;} a;
307
e609d5296ee9 Massive rewrite of codegenerator
Windel Bouwman
parents: 306
diff changeset
406 a.x(9);
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
407 }
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
408 """
308
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
409 self.expectErrors(snippet, [6])
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
410
353
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
411 def testString(self):
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
412 snippet = """
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
413 module teststring;
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
414 function void t()
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
415 {
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
416 var string a;
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
417 a = "Hello world";
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
418 print(a);
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
419 print("Moi");
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
420 }
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
421
353
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
422 function void print(string a)
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
423 {
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
424 }
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
425 """
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
426 self.expectOK(snippet)
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
427
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
428 def testSizeof1(self):
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
429 snippet = """
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
430 module testsizeof;
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
431
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
432 function void t()
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
433 {
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
434 var int a;
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
435 a = sizeof(int*);
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
436 }
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
437 """
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
438 self.expectOK(snippet)
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
439
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
440 def testSizeof2(self):
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
441 snippet = """
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
442 module testsizeof2;
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
443
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
444 function void t()
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
445 {
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
446 sizeof(int*) = 2;
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
447 }
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
448 """
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
449 self.expectErrors(snippet, [6])
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
450
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
451 @unittest.skip('TODO: Too hard')
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
452 def testWrongVarUse(self):
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
453 snippet = """
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
454 module testsizeof;
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
455
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
456 function void t()
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
457 {
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
458 int a = 1;
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
459 }
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
460 """
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
461 self.expectOK(snippet)
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
462
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
463 def testPointerType1(self):
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
464 snippet = """
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
465 module testpointer1;
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
466 var int* pa;
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
467 function void t()
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
468 {
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
469 var int a;
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
470 pa = &a;
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
471 *pa = 22;
308
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
472 a = *pa + *pa * 8;
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
473 }
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
474 """
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
475 self.expectOK(snippet)
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
476
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
477 def testPointerType(self):
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
478 snippet = """
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
479 module testpointer;
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
480 var int* pa, pb;
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
481 function void t(int a, double b)
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
482 {
280
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 272
diff changeset
483 var int a2;
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 272
diff changeset
484 a2 = a; // parameters cannot be escaped for now..
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 272
diff changeset
485 pa = &a2;
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
486 pb = pa;
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
487 *pa = 22;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
488 }
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
489 """
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
490 self.expectOK(snippet)
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
491
221
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
492 def testPointerTypeInCorrect(self):
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
493 snippet = """
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
494 module testpointerincorrect;
221
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
495 var int* pa;
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
496 function void t(int a, double b)
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
497 {
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
498 pa = 2; // type conflict
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
499 pa = &a;
307
e609d5296ee9 Massive rewrite of codegenerator
Windel Bouwman
parents: 306
diff changeset
500 pa = &2; // No valid lvalue
221
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
501 &a = pa; // No valid lvalue
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
502 **pa = 22; // Cannot deref int
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
503 }
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
504 """
307
e609d5296ee9 Massive rewrite of codegenerator
Windel Bouwman
parents: 306
diff changeset
505 self.expectErrors(snippet, [6, 8, 9, 10])
221
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
506
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
507 def testPointerTypeIr(self):
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
508 snippet = """
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
509 module testptr_ir;
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
510 function void t()
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
511 {
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
512 var int* a;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
513 a = cast<int*>(40);
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
514 *a = 2;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
515 }
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
516 """
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 252
diff changeset
517 self.expectOK(snippet)
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
518
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
519 def testPointerTypeIr2(self):
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
520 snippet = """
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
521 module testptr_ir;
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
522 type struct {int x,y;}* gpio;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
523 function void t()
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
524 {
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
525 var gpio a;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
526 a = cast<gpio>(40);
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
527 a->x = 2;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
528 a->y = a->x - 14;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
529 }
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
530 """
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 252
diff changeset
531 self.expectOK(snippet)
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
532
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
533 def testPointerArithmatic(self):
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
534 snippet = """
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
535 module testpointerarithmatic;
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
536 function void t()
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
537 {
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
538 var int* pa;
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
539 *(pa+2) = 2;
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
540 }
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
541 """
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
542 self.expectOK(snippet)
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
543
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
544 def testWrongCast(self):
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
545 snippet = """
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
546 module testptr_ir;
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
547 type struct {int x,y;}* gpio;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
548 function void t()
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
549 {
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
550 var gpio a;
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
551 *cast<gpio>(*a);
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
552 }
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
553 """
308
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 307
diff changeset
554 self.expectErrors(snippet, [7])
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
555
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
556 def testLinkedList(self):
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
557 """
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
558 Test if a struct can contain a field with a pointer to itself
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
559 """
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
560 snippet = """
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
561 module testlinkedlist;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
562
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
563 type struct {
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
564 int x;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
565 list_t* next;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
566 } list_t;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
567
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
568 function void t()
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
569 {
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
570 var list_t* a;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
571 a = a->next;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
572 }
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
573 """
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
574 self.expectOK(snippet)
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
575
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
576 def testInfiniteStruct(self):
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
577 """
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
578 Test if a struct can contain a field with itself as type?
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
579 This should not be possible!
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
580 """
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
581 snippet = """
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
582 module testnestedstruct;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
583
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
584 type struct {
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
585 int x;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
586 list_t inner;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
587 } list_t;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
588
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
589 """
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
590 self.expectErrors(snippet, [0])
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
591
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
592 def testMutualStructs(self):
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
593 """
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
594 Test if two structs can contain each other!
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
595 This should not be possible!
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
596 """
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
597 snippet = """
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
598 module testnestedstruct;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
599
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
600 type struct {
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
601 int x;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
602 B other;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
603 } A;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
604
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
605 type struct {
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
606 int x;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
607 A other;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
608 } B;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
609
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
610 """
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
611 self.expectErrors(snippet, [0])
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 355
diff changeset
612
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
613 def testComplexType(self):
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
614 snippet = """
284
05184b95fa16 Moved tests to seperate folder
Windel Bouwman
parents: 280
diff changeset
615 module testpointer;
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
616 type int my_int;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
617
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
618 type struct {
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
619 int x, y;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
620 } point;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
621
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
622 type struct {
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
623 int mem1;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
624 int memb2;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
625 point P1;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
626 } my_struct;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
627
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
628 type my_struct* my_sptr;
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
629 var int* pa;
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
630
227
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 225
diff changeset
631 function void t(int a, int b, my_sptr x)
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
632 {
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
633 var my_struct *msp;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
634
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
635 var my_struct u, v;
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
636 var point *pt;
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
637
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
638 pt = &msp->P1;
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
639 msp = x;
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
640 *pa = 22 + u.mem1 * v.memb2 - u.P1.x;
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
641 x->memb2 = *pa + a * b;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
642
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 221
diff changeset
643 msp->P1.x = a * x->P1.y;
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
644 }
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
645 """
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
646 self.expectOK(snippet)
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
647
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
648
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
649 if __name__ == '__main__':
243
ef683881c64e Remove various files
Windel Bouwman
parents: 231
diff changeset
650 unittest.main()