git @ Cat's Eye Technologies Castile / bf58b63
Local function variables are function pointers. catseye 12 years ago
1 changed file(s) with 7 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
4141 else:
4242 raise NotImplementedError(type)
4343
44 def c_decl(self, type, name):
44 def c_decl(self, type, name, ptr=False):
4545 if type == Integer():
4646 return 'int %s' % name
4747 elif type == String():
5353 elif isinstance(type, Struct):
5454 return 'struct %s * %s' % (type.name, name)
5555 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
5761 s += ', '.join([self.c_type(a) for a in type.arg_types])
5862 s += ')'
5963 return s
164168 for child in ast.children:
165169 self.compile(child)
166170 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))
168172 elif ast.tag == 'Block':
169173 self.out.write('{\n')
170174 for child in ast.children: