annotate python/testc3.py @ 217:8b2e5f3cd579

Removed some stale python source files
author Windel Bouwman
date Fri, 05 Jul 2013 14:13:59 +0200
parents c1ccb1cb4cef
children 3f6c30a5d234
rev   line source
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
1 import c3
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
2 import time, ppci, x86, ir
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
3 import unittest
148
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
4
162
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 160
diff changeset
5 testsrc = """package test;
148
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
6
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
7 /*
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
8 demo of the source that is correct :)
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
9 */
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
10 var int c, d;
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 162
diff changeset
11 var double e;
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 162
diff changeset
12 var int f;
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 162
diff changeset
13
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
14 const int A = 1337;
149
74241ca312cc Fixes on parser and semantics
Windel Bouwman
parents: 148
diff changeset
15
74241ca312cc Fixes on parser and semantics
Windel Bouwman
parents: 148
diff changeset
16 function void test1()
148
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
17 {
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
18 var int bdd;
148
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
19 var int a = 10;
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
20 bdd = 20;
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 152
diff changeset
21 var int buf;
148
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
22 var int i;
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
23 i = 2;
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 152
diff changeset
24 var int zero = i - 2;
148
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
25 if (i > 1)
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
26 {
157
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
27 buf = b + 22 * i - 13 + (55 * 2 *9-2) / 44 - 1;
148
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
28 }
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 152
diff changeset
29 else
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 152
diff changeset
30 {
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 152
diff changeset
31 ;;;
157
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
32 }
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 152
diff changeset
33
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 152
diff changeset
34 t2(2, 3);
148
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
35 }
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
36
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
37 function int t2(int a, int b)
148
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
38 {
157
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
39 if (a > 0)
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
40 {
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
41 a = 2 + t2(a - 1, 10);
157
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
42 }
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
43
148
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
44 return a + b;
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
45 }
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
46
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
47 var int a, b;
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
48
166
da0087b82fbe Improved type checking
Windel Bouwman
parents: 165
diff changeset
49 function int t3(int aap, int blah)
da0087b82fbe Improved type checking
Windel Bouwman
parents: 165
diff changeset
50 {
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
51 if (a > blah and blah < 45 + 33 or 33 > aap or 6 > 2 and true)
166
da0087b82fbe Improved type checking
Windel Bouwman
parents: 165
diff changeset
52 {
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
53 a = 2 + t2(a - 1, 0);
166
da0087b82fbe Improved type checking
Windel Bouwman
parents: 165
diff changeset
54 }
da0087b82fbe Improved type checking
Windel Bouwman
parents: 165
diff changeset
55
da0087b82fbe Improved type checking
Windel Bouwman
parents: 165
diff changeset
56 return a + b;
da0087b82fbe Improved type checking
Windel Bouwman
parents: 165
diff changeset
57 }
da0087b82fbe Improved type checking
Windel Bouwman
parents: 165
diff changeset
58
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 152
diff changeset
59 var int hahaa = 23 * 2;
150
4ae0e02599de Added type check start and analyze phase
Windel Bouwman
parents: 149
diff changeset
60
149
74241ca312cc Fixes on parser and semantics
Windel Bouwman
parents: 148
diff changeset
61
148
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
62 """
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
63
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
64 class testLexer(unittest.TestCase):
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
65 def testUnexpectedCharacter(self):
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
66 snippet = """ var s \u6c34 """
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
67 with self.assertRaises(ppci.CompilerError):
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
68 list(c3.lexer.tokenize(snippet))
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
69
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
70 def testBlockComment(self):
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
71 snippet = """
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
72 /* Demo */
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
73 var int x = 0;
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
74 """
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
75 toks = ['var', 'ID', 'ID', '=', 'NUMBER', ';', 'END']
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
76 self.assertSequenceEqual([tok.typ for tok in c3.lexer.tokenize(snippet)], toks)
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
77
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
78 def testBlockCommentMultiLine(self):
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
79 snippet = """
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
80 /* Demo
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
81 bla1
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
82 bla2
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
83 */
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
84 var int x = 0;
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
85 """
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
86 toks = ['var', 'ID', 'ID', '=', 'NUMBER', ';', 'END']
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
87 self.assertSequenceEqual([tok.typ for tok in c3.lexer.tokenize(snippet)], toks)
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
88
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 194
diff changeset
89 class testBuilder(unittest.TestCase):
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
90 def setUp(self):
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
91 self.diag = ppci.DiagnosticsManager()
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
92 self.builder = c3.Builder(self.diag)
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
93 self.diag.clear()
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
94
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
95 def testSrc(self):
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
96 self.expectOK(testsrc)
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
97
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
98 def expectErrors(self, snippet, rows):
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
99 """ Helper to test for expected errors on rows """
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
100 ircode = self.builder.build(snippet)
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
101 actualErrors = [err.row for err in self.diag.diags]
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
102 if rows != actualErrors:
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
103 self.diag.printErrors(snippet)
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
104 self.assertSequenceEqual(rows, actualErrors)
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
105 self.assertFalse(ircode)
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
106
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
107 def expectOK(self, snippet):
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
108 ircode = self.builder.build(snippet)
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
109 if not ircode:
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
110 self.diag.printErrors(snippet)
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
111 self.assertTrue(ircode)
217
8b2e5f3cd579 Removed some stale python source files
Windel Bouwman
parents: 215
diff changeset
112 return ircode
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
113
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
114 def testFunctArgs(self):
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
115 snippet = """
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
116 package testargs;
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
117 function void t2(int a, double b)
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
118 {
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
119 t2(2, 2);
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
120 t2(2);
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
121 t2(1, 1.2);
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
122 }
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
123 """
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
124 self.expectErrors(snippet, [5, 6])
148
e5263f74b287 Added c3 language frontend initial parser
Windel Bouwman
parents:
diff changeset
125
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
126 def testExpressions(self):
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
127 snippet = """
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
128 package test;
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
129 function void t(int a, double b)
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
130 {
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
131 var int a2;
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
132 var bool c;
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
133
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
134 a2 = b * a;
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
135 c = a;
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
136 c = b > 1;
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
137 }
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
138 """
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
139 self.expectErrors(snippet, [8, 9, 10])
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
140
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
141 def testEmpty(self):
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
142 snippet = """
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
143 package A
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
144 """
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
145 self.expectErrors(snippet, [3])
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
146
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
147 def testEmpty2(self):
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
148 snippet = ""
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
149 self.expectErrors(snippet, [1])
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
150
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
151 def testRedefine(self):
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
152 snippet = """
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
153 package test;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
154 var int a;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
155 var int b;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
156 var int a;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
157 """
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
158 self.expectErrors(snippet, [5])
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
159
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
160 def testWhile(self):
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
161 snippet = """
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
162 package tstwhile;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
163 var int a;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
164 function void t()
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
165 {
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
166 var int i = 0;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
167 while (i < 1054)
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
168 {
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
169 i = i + 3;
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 182
diff changeset
170 a = a + i;
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
171 }
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
172
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
173 while(true)
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
174 {
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
175 }
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
176
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
177 while(false)
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
178 {
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
179 }
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
180 }
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
181 """
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
182 self.expectOK(snippet)
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
183
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
184 def testIf(self):
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
185 snippet = """
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
186 package tstIFF;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
187 function void t(int b)
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
188 {
180
25a0753da4cf Re-organized files
Windel Bouwman
parents: 170
diff changeset
189 var int a;
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
190 a = 2;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
191 if (a > b)
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
192 {
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
193 if (a > 1337)
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
194 {
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
195 b = 2;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
196 }
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
197 }
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
198 else
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
199 {
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
200 b = 1;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
201 }
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
202
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
203 return b;
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
204 }
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
205 """
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
206 self.expectOK(snippet)
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
207
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
208 @unittest.skip
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
209 def testPointerType(self):
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
210 snippet = """
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
211 package testpointer;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
212 var int* pa;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
213 function void t(int a, double b)
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
214 {
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
215 *pa = 22;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
216 }
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
217 """
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
218 self.expectOK(snippet)
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
219
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
220 @unittest.skip
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
221 def testComplexType(self):
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
222 snippet = """
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
223 package testpointer;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
224 type int my_int;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
225
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
226 type struct {
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
227 int x, y;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
228 } point;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
229
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
230 type struct {
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
231 int mem1;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
232 int memb2;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
233 point P1;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
234 } my_struct;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
235
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
236 type my_struct* my_sptr;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
237
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
238 function void t(int a, double b, my_sptr x)
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
239 {
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
240 var my_struct *msp;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
241
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
242 msp = x;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
243 *pa = 22;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
244 x->memb2 = *pa + a * b;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
245
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
246 mxp->P1.x = a * x->P1.y;
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
247 }
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 205
diff changeset
248 """
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
249 self.expectOK(snippet)
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
250
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
251 def test2(self):
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
252 # testsrc2 is valid code:
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 213
diff changeset
253 snippet = """
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
254 package test2;
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
255
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
256 function void tst()
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
257 {
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
258 var int a, b;
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
259 a = 2 * 33 - 12;
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
260 b = a * 2 + 13;
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
261 a = b + a;
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
262 if (a > b and b == 3)
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
263 {
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
264 var int x = a;
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
265 x = b * 2 - a;
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
266 a = x*x;
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
267 }
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
268 else
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
269 {
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
270 a = b + a;
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
271 }
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
272 }
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
273
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
274 """
217
8b2e5f3cd579 Removed some stale python source files
Windel Bouwman
parents: 215
diff changeset
275 ircode = self.expectOK(snippet)
8b2e5f3cd579 Removed some stale python source files
Windel Bouwman
parents: 215
diff changeset
276 self.assertEqual(1, len(ircode.Functions))
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
277
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
278 if __name__ == '__main__':
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
279 unittest.main()
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
280
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
281