Commits

catseye  committed 364f606

Fix bugs in function lifter, C boilerplate: 24 more tests pass.

  • Participants
  • Parent commits a3c0e76

Comments (0)

Files changed (3)

File src/castile/backends/c.py

 
     def compile(self, ast):
         if ast.tag == 'Program':
-            self.out.write(r"""\
+            self.out.write(r"""
 /* AUTOMATICALLY GENERATED -- EDIT AT OWN RISK */
 
 #include <stdio.h>
 """)
             for child in ast.children:
                 self.compile(child)
-            self.out.write("""\
+            self.out.write(r"""
 
 int main(int argc, char **argv)
 {
     int x = castile_main();
     printf("%d\n", x);
-    exit(0);
+    return 0;
 }
 
 """)
             if name == 'main':
                 name = 'castile_main'
             if thing.tag == 'FunLit':
-                self.out.write('%s %s' % (self.c_type(thing.type.return_type), ast.value))
+                self.out.write('%s %s' % (self.c_type(thing.type.return_type), name))
                 self.compile(ast.children[0])
             else:
                 self.out.write('%s = ' % ast.value)

File src/castile/main.py

         if options.compile_to is not None:
             x = FunctionLifter()
             ast = x.lift_functions(ast)
+            if options.show_ast:
+                print ast.pprint(0)
+                print "-----"
             c = getattr(backends, options.compile_to).Compiler(sys.stdout)
             c.compile(ast)
             sys.exit(0)

File src/castile/transformer.py

             # before function defns
             non_fun_defns = []
             non_lifted_defns = []
-            for child in ast.children:
+            for child in children:
                 if child.children:
                     if child.children[0].tag == 'FunLit':
                         non_lifted_defns.append(child)