Local function variables are function pointers.
catseye
12 years ago
41 | 41 | else: |
42 | 42 | raise NotImplementedError(type) |
43 | 43 | |
44 | def c_decl(self, type, name): | |
44 | def c_decl(self, type, name, ptr=False): | |
45 | 45 | if type == Integer(): |
46 | 46 | return 'int %s' % name |
47 | 47 | elif type == String(): |
53 | 53 | elif isinstance(type, Struct): |
54 | 54 | return 'struct %s * %s' % (type.name, name) |
55 | 55 | elif isinstance(type, Function): |
56 | s = self.c_type(type.return_type) + ' %s(' % name | |
56 | s = self.c_type(type.return_type) | |
57 | if ptr: | |
58 | s += ' (*%s)(' % name | |
59 | else: | |
60 | s += ' %s(' % name | |
57 | 61 | s += ', '.join([self.c_type(a) for a in type.arg_types]) |
58 | 62 | s += ')' |
59 | 63 | return s |
164 | 168 | for child in ast.children: |
165 | 169 | self.compile(child) |
166 | 170 | elif ast.tag == 'VarDecl': |
167 | self.out.write('%s;\n' % self.c_decl(ast.type, ast.value)) | |
171 | self.out.write('%s;\n' % self.c_decl(ast.type, ast.value, ptr=True)) | |
168 | 172 | elif ast.tag == 'Block': |
169 | 173 | self.out.write('{\n') |
170 | 174 | for child in ast.children: |