python-cc 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (393) hide show
  1. python_cc-0.0.2/.github/workflows/workflow.yml +29 -0
  2. python_cc-0.0.2/.gitignore +78 -0
  3. python_cc-0.0.2/.python-version +1 -0
  4. python_cc-0.0.2/LICENSE +25 -0
  5. python_cc-0.0.2/PKG-INFO +182 -0
  6. python_cc-0.0.2/README.md +169 -0
  7. python_cc-0.0.2/c_tests/ackermann.c +10 -0
  8. python_cc-0.0.2/c_tests/basic_arithmetic.c +6 -0
  9. python_cc-0.0.2/c_tests/calculator_project/main.c +17 -0
  10. python_cc-0.0.2/c_tests/calculator_project/ops.c +25 -0
  11. python_cc-0.0.2/c_tests/calculator_project/stack.h +14 -0
  12. python_cc-0.0.2/c_tests/collatz.c +16 -0
  13. python_cc-0.0.2/c_tests/conditional.c +19 -0
  14. python_cc-0.0.2/c_tests/fibonacci.c +9 -0
  15. python_cc-0.0.2/c_tests/game_of_life.c +44 -0
  16. python_cc-0.0.2/c_tests/hanoi.c +17 -0
  17. python_cc-0.0.2/c_tests/mathutil.h +28 -0
  18. python_cc-0.0.2/c_tests/quicksort.c +33 -0
  19. python_cc-0.0.2/c_tests/search.h +18 -0
  20. python_cc-0.0.2/c_tests/sieve.c +20 -0
  21. python_cc-0.0.2/c_tests/sort_project/main.c +13 -0
  22. python_cc-0.0.2/c_tests/sort_project/sort.c +37 -0
  23. python_cc-0.0.2/c_tests/sort_project/sort.h +9 -0
  24. python_cc-0.0.2/c_tests/stack.h +27 -0
  25. python_cc-0.0.2/c_tests/standard_c.c +30 -0
  26. python_cc-0.0.2/c_tests/string_project/main.c +21 -0
  27. python_cc-0.0.2/c_tests/string_project/mystring.c +27 -0
  28. python_cc-0.0.2/c_tests/string_project/mystring.h +8 -0
  29. python_cc-0.0.2/c_tests/struct_layout.c +82 -0
  30. python_cc-0.0.2/c_tests/unsigned_cmp.c +17 -0
  31. python_cc-0.0.2/c_tests/use_mathutil.c +11 -0
  32. python_cc-0.0.2/c_tests/use_search.c +11 -0
  33. python_cc-0.0.2/c_tests/use_stack.c +14 -0
  34. python_cc-0.0.2/c_tests/use_vec.c +11 -0
  35. python_cc-0.0.2/c_tests/vec.h +17 -0
  36. python_cc-0.0.2/clang_study/.gitignore +2 -0
  37. python_cc-0.0.2/clang_study/README.md +3 -0
  38. python_cc-0.0.2/clang_study/and.c +14 -0
  39. python_cc-0.0.2/clang_study/cast.c +6 -0
  40. python_cc-0.0.2/clang_study/if.c +9 -0
  41. python_cc-0.0.2/clang_study/malloc.c +6 -0
  42. python_cc-0.0.2/clang_study/simple_func.c +13 -0
  43. python_cc-0.0.2/clang_study/simple_int.c +5 -0
  44. python_cc-0.0.2/clang_study/simple_pointer.c +6 -0
  45. python_cc-0.0.2/clang_study/simple_printf.c +4 -0
  46. python_cc-0.0.2/clang_study/simple_recurse.c +15 -0
  47. python_cc-0.0.2/clang_study/struct.c +12 -0
  48. python_cc-0.0.2/clang_study/test_arrary.c +18 -0
  49. python_cc-0.0.2/clang_study/test_double_array.c +18 -0
  50. python_cc-0.0.2/clang_study/test_if_else.c +13 -0
  51. python_cc-0.0.2/clang_study/test_int.c +6 -0
  52. python_cc-0.0.2/clang_study/test_puts.c +6 -0
  53. python_cc-0.0.2/pcc/__init__.py +0 -0
  54. python_cc-0.0.2/pcc/__main__.py +3 -0
  55. python_cc-0.0.2/pcc/ast/__init__.py +0 -0
  56. python_cc-0.0.2/pcc/ast/ast.py +179 -0
  57. python_cc-0.0.2/pcc/ast/ast_transforms.py +106 -0
  58. python_cc-0.0.2/pcc/ast/c_ast.py +800 -0
  59. python_cc-0.0.2/pcc/codegen/__init__.py +0 -0
  60. python_cc-0.0.2/pcc/codegen/c_codegen.py +4177 -0
  61. python_cc-0.0.2/pcc/evaluater/__init__.py +0 -0
  62. python_cc-0.0.2/pcc/evaluater/c_evaluator.py +238 -0
  63. python_cc-0.0.2/pcc/generator/__init__.py +0 -0
  64. python_cc-0.0.2/pcc/generator/c_generator.py +399 -0
  65. python_cc-0.0.2/pcc/lex/__init__.py +0 -0
  66. python_cc-0.0.2/pcc/lex/c_lexer.py +495 -0
  67. python_cc-0.0.2/pcc/lex/lexer.py +68 -0
  68. python_cc-0.0.2/pcc/lex/token.py +24 -0
  69. python_cc-0.0.2/pcc/parse/__init__.py +0 -0
  70. python_cc-0.0.2/pcc/parse/c_parser.py +1700 -0
  71. python_cc-0.0.2/pcc/parse/file_parser.py +82 -0
  72. python_cc-0.0.2/pcc/parse/parser.py +300 -0
  73. python_cc-0.0.2/pcc/parse/plyparser.py +56 -0
  74. python_cc-0.0.2/pcc/pcc.py +38 -0
  75. python_cc-0.0.2/pcc/ply/__init__.py +5 -0
  76. python_cc-0.0.2/pcc/ply/cpp.py +908 -0
  77. python_cc-0.0.2/pcc/ply/ctokens.py +133 -0
  78. python_cc-0.0.2/pcc/ply/lex.py +1097 -0
  79. python_cc-0.0.2/pcc/ply/yacc.py +3471 -0
  80. python_cc-0.0.2/pcc/ply/ygen.py +74 -0
  81. python_cc-0.0.2/pcc/preprocessor.py +509 -0
  82. python_cc-0.0.2/pcc/project.py +78 -0
  83. python_cc-0.0.2/pcc/util.py +121 -0
  84. python_cc-0.0.2/projects/lua-5.5.0/.gitignore +15 -0
  85. python_cc-0.0.2/projects/lua-5.5.0/README.md +7 -0
  86. python_cc-0.0.2/projects/lua-5.5.0/all +9 -0
  87. python_cc-0.0.2/projects/lua-5.5.0/lapi.c +1473 -0
  88. python_cc-0.0.2/projects/lua-5.5.0/lapi.h +65 -0
  89. python_cc-0.0.2/projects/lua-5.5.0/lauxlib.c +1202 -0
  90. python_cc-0.0.2/projects/lua-5.5.0/lauxlib.h +271 -0
  91. python_cc-0.0.2/projects/lua-5.5.0/lbaselib.c +559 -0
  92. python_cc-0.0.2/projects/lua-5.5.0/lcode.c +1971 -0
  93. python_cc-0.0.2/projects/lua-5.5.0/lcode.h +105 -0
  94. python_cc-0.0.2/projects/lua-5.5.0/lcorolib.c +225 -0
  95. python_cc-0.0.2/projects/lua-5.5.0/lctype.c +64 -0
  96. python_cc-0.0.2/projects/lua-5.5.0/lctype.h +101 -0
  97. python_cc-0.0.2/projects/lua-5.5.0/ldblib.c +477 -0
  98. python_cc-0.0.2/projects/lua-5.5.0/ldebug.c +979 -0
  99. python_cc-0.0.2/projects/lua-5.5.0/ldebug.h +65 -0
  100. python_cc-0.0.2/projects/lua-5.5.0/ldo.c +1164 -0
  101. python_cc-0.0.2/projects/lua-5.5.0/ldo.h +99 -0
  102. python_cc-0.0.2/projects/lua-5.5.0/ldump.c +307 -0
  103. python_cc-0.0.2/projects/lua-5.5.0/lfunc.c +314 -0
  104. python_cc-0.0.2/projects/lua-5.5.0/lfunc.h +65 -0
  105. python_cc-0.0.2/projects/lua-5.5.0/lgc.c +1804 -0
  106. python_cc-0.0.2/projects/lua-5.5.0/lgc.h +268 -0
  107. python_cc-0.0.2/projects/lua-5.5.0/linit.c +63 -0
  108. python_cc-0.0.2/projects/lua-5.5.0/liolib.c +841 -0
  109. python_cc-0.0.2/projects/lua-5.5.0/ljumptab.h +114 -0
  110. python_cc-0.0.2/projects/lua-5.5.0/llex.c +604 -0
  111. python_cc-0.0.2/projects/lua-5.5.0/llex.h +93 -0
  112. python_cc-0.0.2/projects/lua-5.5.0/llimits.h +357 -0
  113. python_cc-0.0.2/projects/lua-5.5.0/lmathlib.c +765 -0
  114. python_cc-0.0.2/projects/lua-5.5.0/lmem.c +215 -0
  115. python_cc-0.0.2/projects/lua-5.5.0/lmem.h +96 -0
  116. python_cc-0.0.2/projects/lua-5.5.0/loadlib.c +748 -0
  117. python_cc-0.0.2/projects/lua-5.5.0/lobject.c +718 -0
  118. python_cc-0.0.2/projects/lua-5.5.0/lobject.h +864 -0
  119. python_cc-0.0.2/projects/lua-5.5.0/lopcodes.c +140 -0
  120. python_cc-0.0.2/projects/lua-5.5.0/lopcodes.h +439 -0
  121. python_cc-0.0.2/projects/lua-5.5.0/lopnames.h +105 -0
  122. python_cc-0.0.2/projects/lua-5.5.0/loslib.c +432 -0
  123. python_cc-0.0.2/projects/lua-5.5.0/lparser.c +2192 -0
  124. python_cc-0.0.2/projects/lua-5.5.0/lparser.h +196 -0
  125. python_cc-0.0.2/projects/lua-5.5.0/lprefix.h +45 -0
  126. python_cc-0.0.2/projects/lua-5.5.0/lstate.c +420 -0
  127. python_cc-0.0.2/projects/lua-5.5.0/lstate.h +451 -0
  128. python_cc-0.0.2/projects/lua-5.5.0/lstring.c +353 -0
  129. python_cc-0.0.2/projects/lua-5.5.0/lstring.h +73 -0
  130. python_cc-0.0.2/projects/lua-5.5.0/lstrlib.c +1894 -0
  131. python_cc-0.0.2/projects/lua-5.5.0/ltable.c +1355 -0
  132. python_cc-0.0.2/projects/lua-5.5.0/ltable.h +184 -0
  133. python_cc-0.0.2/projects/lua-5.5.0/ltablib.c +426 -0
  134. python_cc-0.0.2/projects/lua-5.5.0/ltests.c +2224 -0
  135. python_cc-0.0.2/projects/lua-5.5.0/ltests.h +166 -0
  136. python_cc-0.0.2/projects/lua-5.5.0/ltm.c +364 -0
  137. python_cc-0.0.2/projects/lua-5.5.0/ltm.h +105 -0
  138. python_cc-0.0.2/projects/lua-5.5.0/lua.c +766 -0
  139. python_cc-0.0.2/projects/lua-5.5.0/lua.h +547 -0
  140. python_cc-0.0.2/projects/lua-5.5.0/luaconf.h +745 -0
  141. python_cc-0.0.2/projects/lua-5.5.0/lualib.h +65 -0
  142. python_cc-0.0.2/projects/lua-5.5.0/lundump.c +424 -0
  143. python_cc-0.0.2/projects/lua-5.5.0/lundump.h +40 -0
  144. python_cc-0.0.2/projects/lua-5.5.0/lutf8lib.c +291 -0
  145. python_cc-0.0.2/projects/lua-5.5.0/lvm.c +1972 -0
  146. python_cc-0.0.2/projects/lua-5.5.0/lvm.h +136 -0
  147. python_cc-0.0.2/projects/lua-5.5.0/lzio.c +89 -0
  148. python_cc-0.0.2/projects/lua-5.5.0/lzio.h +67 -0
  149. python_cc-0.0.2/projects/lua-5.5.0/makefile +219 -0
  150. python_cc-0.0.2/projects/lua-5.5.0/manual/2html +519 -0
  151. python_cc-0.0.2/projects/lua-5.5.0/manual/manual.of +9825 -0
  152. python_cc-0.0.2/projects/lua-5.5.0/onelua.c +136 -0
  153. python_cc-0.0.2/projects/lua-5.5.0/testes/all.lua +289 -0
  154. python_cc-0.0.2/projects/lua-5.5.0/testes/api.lua +1416 -0
  155. python_cc-0.0.2/projects/lua-5.5.0/testes/attrib.lua +547 -0
  156. python_cc-0.0.2/projects/lua-5.5.0/testes/big.lua +82 -0
  157. python_cc-0.0.2/projects/lua-5.5.0/testes/bitwise.lua +363 -0
  158. python_cc-0.0.2/projects/lua-5.5.0/testes/bwcoercion.lua +78 -0
  159. python_cc-0.0.2/projects/lua-5.5.0/testes/calls.lua +577 -0
  160. python_cc-0.0.2/projects/lua-5.5.0/testes/closure.lua +279 -0
  161. python_cc-0.0.2/projects/lua-5.5.0/testes/code.lua +504 -0
  162. python_cc-0.0.2/projects/lua-5.5.0/testes/constructs.lua +406 -0
  163. python_cc-0.0.2/projects/lua-5.5.0/testes/coroutine.lua +1263 -0
  164. python_cc-0.0.2/projects/lua-5.5.0/testes/cstack.lua +197 -0
  165. python_cc-0.0.2/projects/lua-5.5.0/testes/db.lua +1066 -0
  166. python_cc-0.0.2/projects/lua-5.5.0/testes/errors.lua +779 -0
  167. python_cc-0.0.2/projects/lua-5.5.0/testes/events.lua +511 -0
  168. python_cc-0.0.2/projects/lua-5.5.0/testes/files.lua +1004 -0
  169. python_cc-0.0.2/projects/lua-5.5.0/testes/gc.lua +710 -0
  170. python_cc-0.0.2/projects/lua-5.5.0/testes/gengc.lua +196 -0
  171. python_cc-0.0.2/projects/lua-5.5.0/testes/goto.lua +477 -0
  172. python_cc-0.0.2/projects/lua-5.5.0/testes/heavy.lua +175 -0
  173. python_cc-0.0.2/projects/lua-5.5.0/testes/libs/P1/dummy +2 -0
  174. python_cc-0.0.2/projects/lua-5.5.0/testes/libs/lib1.c +44 -0
  175. python_cc-0.0.2/projects/lua-5.5.0/testes/libs/lib11.c +10 -0
  176. python_cc-0.0.2/projects/lua-5.5.0/testes/libs/lib2.c +23 -0
  177. python_cc-0.0.2/projects/lua-5.5.0/testes/libs/lib21.c +10 -0
  178. python_cc-0.0.2/projects/lua-5.5.0/testes/libs/lib22.c +76 -0
  179. python_cc-0.0.2/projects/lua-5.5.0/testes/libs/makefile +27 -0
  180. python_cc-0.0.2/projects/lua-5.5.0/testes/literals.lua +345 -0
  181. python_cc-0.0.2/projects/lua-5.5.0/testes/locals.lua +1227 -0
  182. python_cc-0.0.2/projects/lua-5.5.0/testes/main.lua +579 -0
  183. python_cc-0.0.2/projects/lua-5.5.0/testes/math.lua +1145 -0
  184. python_cc-0.0.2/projects/lua-5.5.0/testes/memerr.lua +290 -0
  185. python_cc-0.0.2/projects/lua-5.5.0/testes/nextvar.lua +957 -0
  186. python_cc-0.0.2/projects/lua-5.5.0/testes/packtests +56 -0
  187. python_cc-0.0.2/projects/lua-5.5.0/testes/pm.lua +442 -0
  188. python_cc-0.0.2/projects/lua-5.5.0/testes/sort.lua +341 -0
  189. python_cc-0.0.2/projects/lua-5.5.0/testes/strings.lua +563 -0
  190. python_cc-0.0.2/projects/lua-5.5.0/testes/tpack.lua +323 -0
  191. python_cc-0.0.2/projects/lua-5.5.0/testes/tracegc.lua +40 -0
  192. python_cc-0.0.2/projects/lua-5.5.0/testes/utf8.lua +280 -0
  193. python_cc-0.0.2/projects/lua-5.5.0/testes/vararg.lua +260 -0
  194. python_cc-0.0.2/projects/lua-5.5.0/testes/verybig.lua +152 -0
  195. python_cc-0.0.2/pyproject.toml +34 -0
  196. python_cc-0.0.2/tests/README.txt +1 -0
  197. python_cc-0.0.2/tests/__init__.py +0 -0
  198. python_cc-0.0.2/tests/c_files/cppd_with_stdio_h.c +5038 -0
  199. python_cc-0.0.2/tests/c_files/empty.h +8 -0
  200. python_cc-0.0.2/tests/c_files/example_c_file.c +12 -0
  201. python_cc-0.0.2/tests/c_files/hdir/9/inc.h +1 -0
  202. python_cc-0.0.2/tests/c_files/memmgr.c +206 -0
  203. python_cc-0.0.2/tests/c_files/memmgr.h +96 -0
  204. python_cc-0.0.2/tests/c_files/memmgr_with_h.c +350 -0
  205. python_cc-0.0.2/tests/c_files/simplemain.c +5 -0
  206. python_cc-0.0.2/tests/c_files/year.c +60 -0
  207. python_cc-0.0.2/tests/test_advanced.py +139 -0
  208. python_cc-0.0.2/tests/test_algorithms.py +141 -0
  209. python_cc-0.0.2/tests/test_and.py +32 -0
  210. python_cc-0.0.2/tests/test_array.py +48 -0
  211. python_cc-0.0.2/tests/test_array_init.py +34 -0
  212. python_cc-0.0.2/tests/test_arrow.py +29 -0
  213. python_cc-0.0.2/tests/test_assign.py +33 -0
  214. python_cc-0.0.2/tests/test_bitwise.py +67 -0
  215. python_cc-0.0.2/tests/test_c_ast.py +104 -0
  216. python_cc-0.0.2/tests/test_c_evluater.py +39 -0
  217. python_cc-0.0.2/tests/test_c_files.py +57 -0
  218. python_cc-0.0.2/tests/test_c_generator.py +251 -0
  219. python_cc-0.0.2/tests/test_c_lexer.py +421 -0
  220. python_cc-0.0.2/tests/test_c_parser.py +1827 -0
  221. python_cc-0.0.2/tests/test_cast.py +31 -0
  222. python_cc-0.0.2/tests/test_cast_int_to_double.py +26 -0
  223. python_cc-0.0.2/tests/test_char.py +44 -0
  224. python_cc-0.0.2/tests/test_comments.py +101 -0
  225. python_cc-0.0.2/tests/test_compound_assign.py +102 -0
  226. python_cc-0.0.2/tests/test_contract.py +20 -0
  227. python_cc-0.0.2/tests/test_div_mod.py +58 -0
  228. python_cc-0.0.2/tests/test_do_while.py +58 -0
  229. python_cc-0.0.2/tests/test_double.py +31 -0
  230. python_cc-0.0.2/tests/test_double_array.py +55 -0
  231. python_cc-0.0.2/tests/test_edge_cases.py +112 -0
  232. python_cc-0.0.2/tests/test_else_if.py +50 -0
  233. python_cc-0.0.2/tests/test_enum.py +45 -0
  234. python_cc-0.0.2/tests/test_expr_list.py +29 -0
  235. python_cc-0.0.2/tests/test_final.py +131 -0
  236. python_cc-0.0.2/tests/test_float_semantics.py +94 -0
  237. python_cc-0.0.2/tests/test_for.py +42 -0
  238. python_cc-0.0.2/tests/test_for_break.py +51 -0
  239. python_cc-0.0.2/tests/test_for_infinite.py +62 -0
  240. python_cc-0.0.2/tests/test_forward_decl.py +40 -0
  241. python_cc-0.0.2/tests/test_func_ptr.py +125 -0
  242. python_cc-0.0.2/tests/test_func_return_ptr.py +37 -0
  243. python_cc-0.0.2/tests/test_general.py +63 -0
  244. python_cc-0.0.2/tests/test_global.py +44 -0
  245. python_cc-0.0.2/tests/test_goto.py +80 -0
  246. python_cc-0.0.2/tests/test_hex_octal.py +47 -0
  247. python_cc-0.0.2/tests/test_if.py +34 -0
  248. python_cc-0.0.2/tests/test_if_else.py +43 -0
  249. python_cc-0.0.2/tests/test_int.py +31 -0
  250. python_cc-0.0.2/tests/test_integration.py +202 -0
  251. python_cc-0.0.2/tests/test_libc.py +154 -0
  252. python_cc-0.0.2/tests/test_libc_extra.py +186 -0
  253. python_cc-0.0.2/tests/test_libc_math.py +122 -0
  254. python_cc-0.0.2/tests/test_llvmliite_array.py +20 -0
  255. python_cc-0.0.2/tests/test_local.py +10 -0
  256. python_cc-0.0.2/tests/test_lua.py +619 -0
  257. python_cc-0.0.2/tests/test_lua_features.py +200 -0
  258. python_cc-0.0.2/tests/test_main_arg.py +31 -0
  259. python_cc-0.0.2/tests/test_main_return_ptr.py +40 -0
  260. python_cc-0.0.2/tests/test_malloc.py +24 -0
  261. python_cc-0.0.2/tests/test_memset_free.py +42 -0
  262. python_cc-0.0.2/tests/test_mixed_types.py +73 -0
  263. python_cc-0.0.2/tests/test_named_struct.py +41 -0
  264. python_cc-0.0.2/tests/test_nest_loop.py +40 -0
  265. python_cc-0.0.2/tests/test_nest_loop1.py +39 -0
  266. python_cc-0.0.2/tests/test_param_array_decay.py +90 -0
  267. python_cc-0.0.2/tests/test_pointer.py +55 -0
  268. python_cc-0.0.2/tests/test_pre_inc_dec.py +80 -0
  269. python_cc-0.0.2/tests/test_preprocessor.py +220 -0
  270. python_cc-0.0.2/tests/test_printf.py +73 -0
  271. python_cc-0.0.2/tests/test_ptr_arith.py +58 -0
  272. python_cc-0.0.2/tests/test_real_programs.py +115 -0
  273. python_cc-0.0.2/tests/test_return_list.py +49 -0
  274. python_cc-0.0.2/tests/test_short_circuit.py +69 -0
  275. python_cc-0.0.2/tests/test_showcase.py +131 -0
  276. python_cc-0.0.2/tests/test_simple_func.py +37 -0
  277. python_cc-0.0.2/tests/test_simple_init_func_assign.py +31 -0
  278. python_cc-0.0.2/tests/test_simple_no_args.py +32 -0
  279. python_cc-0.0.2/tests/test_sizeof.py +114 -0
  280. python_cc-0.0.2/tests/test_static.py +60 -0
  281. python_cc-0.0.2/tests/test_string_escape.py +40 -0
  282. python_cc-0.0.2/tests/test_string_ptr.py +160 -0
  283. python_cc-0.0.2/tests/test_strlen_strcmp.py +43 -0
  284. python_cc-0.0.2/tests/test_struct.py +33 -0
  285. python_cc-0.0.2/tests/test_struct_array_member.py +187 -0
  286. python_cc-0.0.2/tests/test_switch.py +153 -0
  287. python_cc-0.0.2/tests/test_ternary.py +50 -0
  288. python_cc-0.0.2/tests/test_type_convert.py +61 -0
  289. python_cc-0.0.2/tests/test_type_modifiers.py +182 -0
  290. python_cc-0.0.2/tests/test_typedef.py +37 -0
  291. python_cc-0.0.2/tests/test_unary.py +54 -0
  292. python_cc-0.0.2/tests/test_union_const_init.py +116 -0
  293. python_cc-0.0.2/tests/test_union_ptrarray.py +79 -0
  294. python_cc-0.0.2/tests/test_unsigned_loads.py +136 -0
  295. python_cc-0.0.2/tests/test_varargs.py +188 -0
  296. python_cc-0.0.2/tests/test_void.py +45 -0
  297. python_cc-0.0.2/tests/test_while.py +53 -0
  298. python_cc-0.0.2/utils/fake_libc_include/_ansi.h +2 -0
  299. python_cc-0.0.2/utils/fake_libc_include/_fake_defines.h +62 -0
  300. python_cc-0.0.2/utils/fake_libc_include/_fake_typedefs.h +148 -0
  301. python_cc-0.0.2/utils/fake_libc_include/_syslist.h +2 -0
  302. python_cc-0.0.2/utils/fake_libc_include/alloca.h +2 -0
  303. python_cc-0.0.2/utils/fake_libc_include/ar.h +2 -0
  304. python_cc-0.0.2/utils/fake_libc_include/argz.h +2 -0
  305. python_cc-0.0.2/utils/fake_libc_include/arpa/inet.h +2 -0
  306. python_cc-0.0.2/utils/fake_libc_include/assert.h +2 -0
  307. python_cc-0.0.2/utils/fake_libc_include/complex.h +2 -0
  308. python_cc-0.0.2/utils/fake_libc_include/ctype.h +2 -0
  309. python_cc-0.0.2/utils/fake_libc_include/dirent.h +2 -0
  310. python_cc-0.0.2/utils/fake_libc_include/dlfcn.h +22 -0
  311. python_cc-0.0.2/utils/fake_libc_include/endian.h +2 -0
  312. python_cc-0.0.2/utils/fake_libc_include/envz.h +2 -0
  313. python_cc-0.0.2/utils/fake_libc_include/errno.h +2 -0
  314. python_cc-0.0.2/utils/fake_libc_include/fastmath.h +2 -0
  315. python_cc-0.0.2/utils/fake_libc_include/fcntl.h +2 -0
  316. python_cc-0.0.2/utils/fake_libc_include/features.h +2 -0
  317. python_cc-0.0.2/utils/fake_libc_include/fenv.h +2 -0
  318. python_cc-0.0.2/utils/fake_libc_include/float.h +2 -0
  319. python_cc-0.0.2/utils/fake_libc_include/getopt.h +2 -0
  320. python_cc-0.0.2/utils/fake_libc_include/grp.h +2 -0
  321. python_cc-0.0.2/utils/fake_libc_include/iconv.h +2 -0
  322. python_cc-0.0.2/utils/fake_libc_include/ieeefp.h +2 -0
  323. python_cc-0.0.2/utils/fake_libc_include/inttypes.h +2 -0
  324. python_cc-0.0.2/utils/fake_libc_include/iso646.h +2 -0
  325. python_cc-0.0.2/utils/fake_libc_include/langinfo.h +2 -0
  326. python_cc-0.0.2/utils/fake_libc_include/libgen.h +2 -0
  327. python_cc-0.0.2/utils/fake_libc_include/libintl.h +2 -0
  328. python_cc-0.0.2/utils/fake_libc_include/limits.h +2 -0
  329. python_cc-0.0.2/utils/fake_libc_include/linux/version.h +2 -0
  330. python_cc-0.0.2/utils/fake_libc_include/locale.h +2 -0
  331. python_cc-0.0.2/utils/fake_libc_include/malloc.h +2 -0
  332. python_cc-0.0.2/utils/fake_libc_include/math.h +2 -0
  333. python_cc-0.0.2/utils/fake_libc_include/netdb.h +2 -0
  334. python_cc-0.0.2/utils/fake_libc_include/netinet/in.h +2 -0
  335. python_cc-0.0.2/utils/fake_libc_include/netinet/tcp.h +2 -0
  336. python_cc-0.0.2/utils/fake_libc_include/newlib.h +2 -0
  337. python_cc-0.0.2/utils/fake_libc_include/openssl/err.h +2 -0
  338. python_cc-0.0.2/utils/fake_libc_include/openssl/evp.h +2 -0
  339. python_cc-0.0.2/utils/fake_libc_include/openssl/hmac.h +2 -0
  340. python_cc-0.0.2/utils/fake_libc_include/openssl/ssl.h +2 -0
  341. python_cc-0.0.2/utils/fake_libc_include/openssl/x509v3.h +2 -0
  342. python_cc-0.0.2/utils/fake_libc_include/paths.h +2 -0
  343. python_cc-0.0.2/utils/fake_libc_include/process.h +2 -0
  344. python_cc-0.0.2/utils/fake_libc_include/pthread.h +2 -0
  345. python_cc-0.0.2/utils/fake_libc_include/pwd.h +2 -0
  346. python_cc-0.0.2/utils/fake_libc_include/reent.h +2 -0
  347. python_cc-0.0.2/utils/fake_libc_include/regdef.h +2 -0
  348. python_cc-0.0.2/utils/fake_libc_include/regex.h +2 -0
  349. python_cc-0.0.2/utils/fake_libc_include/sched.h +2 -0
  350. python_cc-0.0.2/utils/fake_libc_include/search.h +2 -0
  351. python_cc-0.0.2/utils/fake_libc_include/semaphore.h +2 -0
  352. python_cc-0.0.2/utils/fake_libc_include/setjmp.h +28 -0
  353. python_cc-0.0.2/utils/fake_libc_include/signal.h +16 -0
  354. python_cc-0.0.2/utils/fake_libc_include/stdarg.h +2 -0
  355. python_cc-0.0.2/utils/fake_libc_include/stdbool.h +2 -0
  356. python_cc-0.0.2/utils/fake_libc_include/stddef.h +2 -0
  357. python_cc-0.0.2/utils/fake_libc_include/stdint.h +2 -0
  358. python_cc-0.0.2/utils/fake_libc_include/stdio.h +16 -0
  359. python_cc-0.0.2/utils/fake_libc_include/stdlib.h +2 -0
  360. python_cc-0.0.2/utils/fake_libc_include/string.h +2 -0
  361. python_cc-0.0.2/utils/fake_libc_include/sys/ioctl.h +2 -0
  362. python_cc-0.0.2/utils/fake_libc_include/sys/mman.h +2 -0
  363. python_cc-0.0.2/utils/fake_libc_include/sys/poll.h +2 -0
  364. python_cc-0.0.2/utils/fake_libc_include/sys/resource.h +2 -0
  365. python_cc-0.0.2/utils/fake_libc_include/sys/select.h +2 -0
  366. python_cc-0.0.2/utils/fake_libc_include/sys/socket.h +2 -0
  367. python_cc-0.0.2/utils/fake_libc_include/sys/stat.h +2 -0
  368. python_cc-0.0.2/utils/fake_libc_include/sys/sysctl.h +2 -0
  369. python_cc-0.0.2/utils/fake_libc_include/sys/time.h +2 -0
  370. python_cc-0.0.2/utils/fake_libc_include/sys/types.h +2 -0
  371. python_cc-0.0.2/utils/fake_libc_include/sys/uio.h +2 -0
  372. python_cc-0.0.2/utils/fake_libc_include/sys/un.h +2 -0
  373. python_cc-0.0.2/utils/fake_libc_include/sys/utsname.h +2 -0
  374. python_cc-0.0.2/utils/fake_libc_include/sys/wait.h +12 -0
  375. python_cc-0.0.2/utils/fake_libc_include/syslog.h +2 -0
  376. python_cc-0.0.2/utils/fake_libc_include/tar.h +2 -0
  377. python_cc-0.0.2/utils/fake_libc_include/termios.h +2 -0
  378. python_cc-0.0.2/utils/fake_libc_include/tgmath.h +2 -0
  379. python_cc-0.0.2/utils/fake_libc_include/time.h +33 -0
  380. python_cc-0.0.2/utils/fake_libc_include/unctrl.h +2 -0
  381. python_cc-0.0.2/utils/fake_libc_include/unistd.h +10 -0
  382. python_cc-0.0.2/utils/fake_libc_include/utime.h +2 -0
  383. python_cc-0.0.2/utils/fake_libc_include/utmp.h +2 -0
  384. python_cc-0.0.2/utils/fake_libc_include/wchar.h +2 -0
  385. python_cc-0.0.2/utils/fake_libc_include/wctype.h +2 -0
  386. python_cc-0.0.2/utils/fake_libc_include/zlib.h +2 -0
  387. python_cc-0.0.2/utils/internal/constptr.c +9 -0
  388. python_cc-0.0.2/utils/internal/example_c_file.c +25 -0
  389. python_cc-0.0.2/utils/internal/fake_includes.py +13 -0
  390. python_cc-0.0.2/utils/internal/make_fake_typedefs.py +21 -0
  391. python_cc-0.0.2/utils/internal/memprofiling.py +121 -0
  392. python_cc-0.0.2/utils/internal/zc.c +107 -0
  393. python_cc-0.0.2/utils/internal/zz_parse.py +21 -0
@@ -0,0 +1,29 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ pypi-publish:
9
+ name: Upload release to PyPI
10
+ runs-on: ubuntu-latest
11
+ environment: pypi
12
+ permissions:
13
+ id-token: write
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - name: Set up Python
18
+ uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.12"
21
+
22
+ - name: Install build dependencies
23
+ run: pip install build
24
+
25
+ - name: Build package
26
+ run: python -m build
27
+
28
+ - name: Publish to PyPI
29
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,78 @@
1
+ *.out
2
+ *.s
3
+ # Byte-compiled / optimized / DLL files
4
+ .pytest_cache/
5
+ parser.out
6
+ #
7
+ #
8
+ *.bc
9
+ __pycache__/
10
+ *.py[cod]
11
+
12
+ # C extensions
13
+ *.so
14
+
15
+ # Distribution / packaging
16
+ .Python
17
+ env/
18
+ build/
19
+ develop-eggs/
20
+ dist/
21
+ downloads/
22
+ eggs/
23
+ lib/
24
+ lib64/
25
+ parts/
26
+ sdist/
27
+ var/
28
+ *.egg-info/
29
+ .installed.cfg
30
+ *.egg
31
+ .idea/
32
+ # PyInstaller
33
+ # Usually these files are written by a python script from a template
34
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
35
+ *.manifest
36
+ *.spec
37
+
38
+ # Installer logs
39
+ pip-log.txt
40
+ pip-delete-this-directory.txt
41
+
42
+ # Unit test / coverage reports
43
+ htmlcov/
44
+ .tox/
45
+ .coverage
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+
50
+ # Translations
51
+ *.mo
52
+ *.pot
53
+
54
+ # Django stuff:
55
+ *.log
56
+
57
+ # Sphinx documentation
58
+ docs/_build/
59
+
60
+ # PyBuilder
61
+ target/
62
+ lextab.py
63
+ *.bcode
64
+ *.ir
65
+ yacctab.py
66
+ *.gch
67
+
68
+ # uv / venv
69
+ .venv/
70
+ uv.lock
71
+
72
+ # Temp files
73
+ temp.*
74
+
75
+
76
+
77
+ redis
78
+ nginx
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,25 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org>
25
+
@@ -0,0 +1,182 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-cc
3
+ Version: 0.0.2
4
+ Summary: Pcc is a c compiler built on python and llvm.
5
+ Project-URL: Homepage, http://pypi.python.org/pypi/pcc/
6
+ License-Expression: BSD-3-Clause
7
+ License-File: LICENSE
8
+ Keywords: c,compiler,llvm,ply
9
+ Requires-Python: >=3.10
10
+ Requires-Dist: click
11
+ Requires-Dist: llvmlite==0.46.0
12
+ Description-Content-Type: text/markdown
13
+
14
+ Pcc
15
+ ====================
16
+
17
+ What is this?
18
+ --------------------
19
+ Pcc is a C compiler based on ply + pycparser + llvmlite + llvm.
20
+ We can run C programs like Python: `pcc test.c` to run C code.
21
+ Pcc was inspired by: https://github.com/eliben/pykaleidoscope.
22
+
23
+ Notice
24
+ --------------------
25
+ 1. Some code skeleton comes from pykaleidoscope.
26
+ 2. ply and pycparser are embedded into this project for debug use.
27
+
28
+ Development
29
+ --------------------
30
+
31
+ Requires Python 3.13+ and [uv](https://docs.astral.sh/uv/).
32
+
33
+ ```bash
34
+ uv sync # install dependencies
35
+ uv run pytest # run all 400+ tests (~10s parallel)
36
+ ```
37
+
38
+ Run pcc
39
+ --------------------
40
+
41
+ ```bash
42
+ # Single file
43
+ uv run pcc hello.c
44
+
45
+ # Multi-file project (auto-collects all .c files, resolves .h includes)
46
+ uv run pcc myproject/
47
+
48
+ # Dump LLVM IR
49
+ uv run pcc --llvmdump test.c
50
+ ```
51
+
52
+ Multi-file projects: put `.c` and `.h` files in a directory, one `.c` must contain `main()`. Pcc auto-discovers all `.c` files, merges them, and compiles.
53
+
54
+ Lua Compilation Goal
55
+ --------------------
56
+
57
+ The target is to compile and run [Lua 5.5.0](https://github.com/lua/lua) using pcc.
58
+
59
+ ```
60
+ projects/lua-5.5.0/ - Lua 5.5.0 source code + Makefile
61
+ projects/lua-5.5.0/testes/ - Lua test suite
62
+ ```
63
+
64
+ ### Test Structure
65
+
66
+ Tests in `tests/test_lua.py` compare three builds:
67
+
68
+ | Build | Method |
69
+ |-------|--------|
70
+ | **pcc** | `onelua.c` → pcc preprocess/parse/codegen → LLVM IR → cc compile+link |
71
+ | **native** | `onelua.c` → `cc -O0` single-file compile |
72
+ | **makefile** | `make` with project Makefile (separate compilation of each .c, static lib + link) |
73
+
74
+ ```bash
75
+ # Run all Lua tests (slow marker, ~5 min with 4 workers)
76
+ uv run pytest tests/test_lua.py -m slow -v -n 4
77
+
78
+ # Individual file compilation through pcc pipeline
79
+ uv run pytest tests/test_lua.py::test_lua_source_compile -v
80
+ # pcc vs native (same onelua.c, test pcc as C compiler)
81
+ uv run pytest tests/test_lua.py::test_pcc_runtime_matches_native -v
82
+ # pcc vs Makefile-built lua (official reference)
83
+ uv run pytest tests/test_lua.py::test_pcc_runtime_matches_makefile -v
84
+ # Lua test suite with Makefile-built binary (baseline)
85
+ uv run pytest tests/test_lua.py::test_makefile_lua_test_suite -v```
86
+
87
+ Note: `heavy.lua` is excluded from automated tests (runs ~2 min+, may timeout). Run manually:
88
+ ```bash
89
+ # Build Makefile lua, then run heavy.lua directly
90
+ cd projects/lua-5.5.0 && make CC=cc CWARNS= MYCFLAGS="-std=c99 -DLUA_USE_MACOSX" MYLDFLAGS= MYLIBS=
91
+ ./lua testes/heavy.lua
92
+ ```
93
+
94
+ Add C test cases
95
+ --------------------
96
+
97
+ ```bash
98
+ # Single file: add to c_tests/ with expected return value
99
+ echo '// EXPECT: 42
100
+ int main(){ return 42; }' > c_tests/mytest.c
101
+
102
+ # Multi-file project: create a directory with main.c
103
+ mkdir c_tests/myproject
104
+ # ... add .c and .h files, main.c must have: // EXPECT: N
105
+
106
+ # Run all C file tests
107
+ uv run pytest tests/test_c_files.py -v
108
+ ```
109
+
110
+ Preprocessor
111
+ --------------------
112
+
113
+ ```c
114
+ #include <stdio.h> // system headers: 133 libc functions auto-declared
115
+ #include "mylib.h" // user headers: read and inline file content
116
+ #define MAX_SIZE 100 // object-like macro
117
+ #define MAX(a,b) ((a)>(b)?(a):(b)) // function-like macro
118
+ #define DEBUG // flag for conditional compilation
119
+ #ifdef / #ifndef / #if / #elif / #else / #endif // conditional compilation
120
+ #if defined(X) && (VERSION >= 3) // expression evaluation with defined()
121
+ #undef NAME // undefine macro
122
+ ```
123
+
124
+ Built-in macros: `NULL`, `EOF`, `EXIT_SUCCESS`, `EXIT_FAILURE`, `RAND_MAX`, `INT_MAX`, `INT_MIN`, `LLONG_MAX`, `CHAR_BIT`, `true`, `false`, `__STDC__`
125
+
126
+ Built-in typedefs: `size_t`, `ssize_t`, `ptrdiff_t`, `va_list`, `FILE`, `time_t`, `clock_t`, `pid_t`
127
+
128
+ Supported C Features
129
+ --------------------
130
+
131
+ ### Types
132
+ `int`, `double`, `float`, `char`, `void`, `unsigned`/`signed`/`long`/`short` (all combinations),
133
+ `size_t`, `int8_t`..`uint64_t`,
134
+ pointers (multi-level), arrays (multi-dim),
135
+ structs (named, anonymous, nested, with array/pointer/function-pointer members, pointer-to-struct),
136
+ unions, enums (with constant expressions), typedef (scalar, struct, pointer, function pointer),
137
+ `static` local variables, `const`/`volatile` qualifiers
138
+
139
+ ### Operators
140
+ - Arithmetic: `+` `-` `*` `/` `%`
141
+ - Bitwise: `&` `|` `^` `<<` `>>`
142
+ - Comparison: `<` `>` `<=` `>=` `==` `!=` (including pointer comparison)
143
+ - Logical: `&&` `||` (short-circuit evaluation)
144
+ - Unary: `-x` `+x` `!x` `~x` `sizeof` `&x` `*p`
145
+ - Increment/Decrement: `++x` `x++` `--x` `x--` (int and pointer, including struct members)
146
+ - Assignment: `=` `+=` `-=` `*=` `/=` `%=` `<<=` `>>=` `&=` `|=` `^=` (including pointer `+=`/`-=`)
147
+ - Ternary: `a ? b : c`
148
+ - Pointer: `p + n`, `p - n`, `p - q`, `p++`, `p[i]`
149
+ - Struct access: `.` and `->` (including nested `a.b.c` and `s->fn(args)`)
150
+ - Chained: `a = b = c = 5`
151
+
152
+ ### Control Flow
153
+ `if` / `else` / `else if`, `while`, `do-while`, `for` (all variants including `for(;;)`),
154
+ `switch` / `case` / `default`, `goto` / `label`, `break`, `continue`, `return`
155
+
156
+ ### Functions
157
+ Definitions, forward declarations, mutual recursion, void functions, variadic (`...`),
158
+ pointer/array arguments, `static` local variables, function pointers (declaration, assignment,
159
+ calling, as parameters, in structs, typedef'd), callback patterns
160
+
161
+ ### Libc Functions (133 total, auto-declared on first use)
162
+
163
+ | Header | Functions |
164
+ |--------|-----------|
165
+ | stdio.h | printf, fprintf, sprintf, snprintf, puts, putchar, getchar, fopen, fclose, fread, fwrite, fseek, ftell, fgets, fputs, scanf, sscanf, ... |
166
+ | stdlib.h | malloc, calloc, realloc, free, abs, labs, atoi, atol, atof, strtol, strtod, rand, srand, exit, abort, qsort, bsearch, getenv, system, ... |
167
+ | string.h | strlen, strcmp, strncmp, strcpy, strncpy, strcat, strncat, strchr, strrchr, strstr, memset, memcpy, memmove, memcmp, memchr, strtok, ... |
168
+ | ctype.h | isalpha, isdigit, isalnum, isspace, isupper, islower, isprint, ispunct, isxdigit, toupper, tolower, ... |
169
+ | math.h | sin, cos, tan, asin, acos, atan, atan2, exp, log, log2, log10, pow, sqrt, cbrt, hypot, ceil, floor, round, trunc, fmod, fabs, ... |
170
+ | time.h | time, clock, difftime |
171
+ | unistd.h | sleep, usleep, read, write, open, close, getpid, getppid |
172
+ | setjmp.h | setjmp, longjmp |
173
+ | signal.h | signal, raise |
174
+
175
+ ### Literals
176
+ Decimal, hex (`0xFF`), octal (`077`), char (`'a'`, `'\n'`), string (`"hello\n"`), double (`3.14`)
177
+
178
+ ### Other
179
+ C comments (`/* */`, `//`), array initializer lists (1D and multi-dim),
180
+ string escape sequences (`\n \t \\ \0 \r`), implicit type promotion (int/char/double/pointer),
181
+ array-to-pointer decay, `NULL` pointer support, opaque/forward-declared structs,
182
+ two-pass codegen (types first, functions second)
@@ -0,0 +1,169 @@
1
+ Pcc
2
+ ====================
3
+
4
+ What is this?
5
+ --------------------
6
+ Pcc is a C compiler based on ply + pycparser + llvmlite + llvm.
7
+ We can run C programs like Python: `pcc test.c` to run C code.
8
+ Pcc was inspired by: https://github.com/eliben/pykaleidoscope.
9
+
10
+ Notice
11
+ --------------------
12
+ 1. Some code skeleton comes from pykaleidoscope.
13
+ 2. ply and pycparser are embedded into this project for debug use.
14
+
15
+ Development
16
+ --------------------
17
+
18
+ Requires Python 3.13+ and [uv](https://docs.astral.sh/uv/).
19
+
20
+ ```bash
21
+ uv sync # install dependencies
22
+ uv run pytest # run all 400+ tests (~10s parallel)
23
+ ```
24
+
25
+ Run pcc
26
+ --------------------
27
+
28
+ ```bash
29
+ # Single file
30
+ uv run pcc hello.c
31
+
32
+ # Multi-file project (auto-collects all .c files, resolves .h includes)
33
+ uv run pcc myproject/
34
+
35
+ # Dump LLVM IR
36
+ uv run pcc --llvmdump test.c
37
+ ```
38
+
39
+ Multi-file projects: put `.c` and `.h` files in a directory, one `.c` must contain `main()`. Pcc auto-discovers all `.c` files, merges them, and compiles.
40
+
41
+ Lua Compilation Goal
42
+ --------------------
43
+
44
+ The target is to compile and run [Lua 5.5.0](https://github.com/lua/lua) using pcc.
45
+
46
+ ```
47
+ projects/lua-5.5.0/ - Lua 5.5.0 source code + Makefile
48
+ projects/lua-5.5.0/testes/ - Lua test suite
49
+ ```
50
+
51
+ ### Test Structure
52
+
53
+ Tests in `tests/test_lua.py` compare three builds:
54
+
55
+ | Build | Method |
56
+ |-------|--------|
57
+ | **pcc** | `onelua.c` → pcc preprocess/parse/codegen → LLVM IR → cc compile+link |
58
+ | **native** | `onelua.c` → `cc -O0` single-file compile |
59
+ | **makefile** | `make` with project Makefile (separate compilation of each .c, static lib + link) |
60
+
61
+ ```bash
62
+ # Run all Lua tests (slow marker, ~5 min with 4 workers)
63
+ uv run pytest tests/test_lua.py -m slow -v -n 4
64
+
65
+ # Individual file compilation through pcc pipeline
66
+ uv run pytest tests/test_lua.py::test_lua_source_compile -v
67
+ # pcc vs native (same onelua.c, test pcc as C compiler)
68
+ uv run pytest tests/test_lua.py::test_pcc_runtime_matches_native -v
69
+ # pcc vs Makefile-built lua (official reference)
70
+ uv run pytest tests/test_lua.py::test_pcc_runtime_matches_makefile -v
71
+ # Lua test suite with Makefile-built binary (baseline)
72
+ uv run pytest tests/test_lua.py::test_makefile_lua_test_suite -v```
73
+
74
+ Note: `heavy.lua` is excluded from automated tests (runs ~2 min+, may timeout). Run manually:
75
+ ```bash
76
+ # Build Makefile lua, then run heavy.lua directly
77
+ cd projects/lua-5.5.0 && make CC=cc CWARNS= MYCFLAGS="-std=c99 -DLUA_USE_MACOSX" MYLDFLAGS= MYLIBS=
78
+ ./lua testes/heavy.lua
79
+ ```
80
+
81
+ Add C test cases
82
+ --------------------
83
+
84
+ ```bash
85
+ # Single file: add to c_tests/ with expected return value
86
+ echo '// EXPECT: 42
87
+ int main(){ return 42; }' > c_tests/mytest.c
88
+
89
+ # Multi-file project: create a directory with main.c
90
+ mkdir c_tests/myproject
91
+ # ... add .c and .h files, main.c must have: // EXPECT: N
92
+
93
+ # Run all C file tests
94
+ uv run pytest tests/test_c_files.py -v
95
+ ```
96
+
97
+ Preprocessor
98
+ --------------------
99
+
100
+ ```c
101
+ #include <stdio.h> // system headers: 133 libc functions auto-declared
102
+ #include "mylib.h" // user headers: read and inline file content
103
+ #define MAX_SIZE 100 // object-like macro
104
+ #define MAX(a,b) ((a)>(b)?(a):(b)) // function-like macro
105
+ #define DEBUG // flag for conditional compilation
106
+ #ifdef / #ifndef / #if / #elif / #else / #endif // conditional compilation
107
+ #if defined(X) && (VERSION >= 3) // expression evaluation with defined()
108
+ #undef NAME // undefine macro
109
+ ```
110
+
111
+ Built-in macros: `NULL`, `EOF`, `EXIT_SUCCESS`, `EXIT_FAILURE`, `RAND_MAX`, `INT_MAX`, `INT_MIN`, `LLONG_MAX`, `CHAR_BIT`, `true`, `false`, `__STDC__`
112
+
113
+ Built-in typedefs: `size_t`, `ssize_t`, `ptrdiff_t`, `va_list`, `FILE`, `time_t`, `clock_t`, `pid_t`
114
+
115
+ Supported C Features
116
+ --------------------
117
+
118
+ ### Types
119
+ `int`, `double`, `float`, `char`, `void`, `unsigned`/`signed`/`long`/`short` (all combinations),
120
+ `size_t`, `int8_t`..`uint64_t`,
121
+ pointers (multi-level), arrays (multi-dim),
122
+ structs (named, anonymous, nested, with array/pointer/function-pointer members, pointer-to-struct),
123
+ unions, enums (with constant expressions), typedef (scalar, struct, pointer, function pointer),
124
+ `static` local variables, `const`/`volatile` qualifiers
125
+
126
+ ### Operators
127
+ - Arithmetic: `+` `-` `*` `/` `%`
128
+ - Bitwise: `&` `|` `^` `<<` `>>`
129
+ - Comparison: `<` `>` `<=` `>=` `==` `!=` (including pointer comparison)
130
+ - Logical: `&&` `||` (short-circuit evaluation)
131
+ - Unary: `-x` `+x` `!x` `~x` `sizeof` `&x` `*p`
132
+ - Increment/Decrement: `++x` `x++` `--x` `x--` (int and pointer, including struct members)
133
+ - Assignment: `=` `+=` `-=` `*=` `/=` `%=` `<<=` `>>=` `&=` `|=` `^=` (including pointer `+=`/`-=`)
134
+ - Ternary: `a ? b : c`
135
+ - Pointer: `p + n`, `p - n`, `p - q`, `p++`, `p[i]`
136
+ - Struct access: `.` and `->` (including nested `a.b.c` and `s->fn(args)`)
137
+ - Chained: `a = b = c = 5`
138
+
139
+ ### Control Flow
140
+ `if` / `else` / `else if`, `while`, `do-while`, `for` (all variants including `for(;;)`),
141
+ `switch` / `case` / `default`, `goto` / `label`, `break`, `continue`, `return`
142
+
143
+ ### Functions
144
+ Definitions, forward declarations, mutual recursion, void functions, variadic (`...`),
145
+ pointer/array arguments, `static` local variables, function pointers (declaration, assignment,
146
+ calling, as parameters, in structs, typedef'd), callback patterns
147
+
148
+ ### Libc Functions (133 total, auto-declared on first use)
149
+
150
+ | Header | Functions |
151
+ |--------|-----------|
152
+ | stdio.h | printf, fprintf, sprintf, snprintf, puts, putchar, getchar, fopen, fclose, fread, fwrite, fseek, ftell, fgets, fputs, scanf, sscanf, ... |
153
+ | stdlib.h | malloc, calloc, realloc, free, abs, labs, atoi, atol, atof, strtol, strtod, rand, srand, exit, abort, qsort, bsearch, getenv, system, ... |
154
+ | string.h | strlen, strcmp, strncmp, strcpy, strncpy, strcat, strncat, strchr, strrchr, strstr, memset, memcpy, memmove, memcmp, memchr, strtok, ... |
155
+ | ctype.h | isalpha, isdigit, isalnum, isspace, isupper, islower, isprint, ispunct, isxdigit, toupper, tolower, ... |
156
+ | math.h | sin, cos, tan, asin, acos, atan, atan2, exp, log, log2, log10, pow, sqrt, cbrt, hypot, ceil, floor, round, trunc, fmod, fabs, ... |
157
+ | time.h | time, clock, difftime |
158
+ | unistd.h | sleep, usleep, read, write, open, close, getpid, getppid |
159
+ | setjmp.h | setjmp, longjmp |
160
+ | signal.h | signal, raise |
161
+
162
+ ### Literals
163
+ Decimal, hex (`0xFF`), octal (`077`), char (`'a'`, `'\n'`), string (`"hello\n"`), double (`3.14`)
164
+
165
+ ### Other
166
+ C comments (`/* */`, `//`), array initializer lists (1D and multi-dim),
167
+ string escape sequences (`\n \t \\ \0 \r`), implicit type promotion (int/char/double/pointer),
168
+ array-to-pointer decay, `NULL` pointer support, opaque/forward-declared structs,
169
+ two-pass codegen (types first, functions second)
@@ -0,0 +1,10 @@
1
+ // EXPECT: 61
2
+ int ack(int m, int n) {
3
+ if (m == 0) return n + 1;
4
+ if (n == 0) return ack(m - 1, 1);
5
+ return ack(m - 1, ack(m, n - 1));
6
+ }
7
+
8
+ int main() {
9
+ return ack(3, 3);
10
+ }
@@ -0,0 +1,6 @@
1
+ // EXPECT: 42
2
+ int main() {
3
+ int a = 10;
4
+ int b = 32;
5
+ return a + b;
6
+ }
@@ -0,0 +1,17 @@
1
+ // EXPECT: 14
2
+ #include "stack.h"
3
+
4
+ void op_add();
5
+ void op_sub();
6
+ void op_mul();
7
+ void op_div();
8
+
9
+ int main() {
10
+ // Calculate: (3 + 4) * 2 = 14
11
+ push(3);
12
+ push(4);
13
+ op_add(); // stack: [7]
14
+ push(2);
15
+ op_mul(); // stack: [14]
16
+ return pop(); // 14
17
+ }
@@ -0,0 +1,25 @@
1
+ #include "stack.h"
2
+
3
+ void op_add() {
4
+ int b = pop();
5
+ int a = pop();
6
+ push(a + b);
7
+ }
8
+
9
+ void op_sub() {
10
+ int b = pop();
11
+ int a = pop();
12
+ push(a - b);
13
+ }
14
+
15
+ void op_mul() {
16
+ int b = pop();
17
+ int a = pop();
18
+ push(a * b);
19
+ }
20
+
21
+ void op_div() {
22
+ int b = pop();
23
+ int a = pop();
24
+ push(a / b);
25
+ }
@@ -0,0 +1,14 @@
1
+ #ifndef STACK_H
2
+ #define STACK_H
3
+
4
+ #define STACK_SIZE 64
5
+
6
+ int _stack[STACK_SIZE];
7
+ int _sp = -1;
8
+
9
+ void push(int val) { _sp++; _stack[_sp] = val; }
10
+ int pop() { int v = _stack[_sp]; _sp--; return v; }
11
+ int peek() { return _stack[_sp]; }
12
+ int empty() { return _sp < 0; }
13
+
14
+ #endif
@@ -0,0 +1,16 @@
1
+ // EXPECT: 111
2
+ int collatz_steps(int n) {
3
+ int steps = 0;
4
+ while (n != 1) {
5
+ if (n % 2 == 0)
6
+ n = n / 2;
7
+ else
8
+ n = 3 * n + 1;
9
+ steps++;
10
+ }
11
+ return steps;
12
+ }
13
+
14
+ int main() {
15
+ return collatz_steps(27);
16
+ }
@@ -0,0 +1,19 @@
1
+ // EXPECT: 42
2
+ #define USE_FAST_PATH
3
+
4
+ #ifdef USE_FAST_PATH
5
+ int compute(int x) {
6
+ return x * 2;
7
+ }
8
+ #else
9
+ int compute(int x) {
10
+ int i;
11
+ int result = 0;
12
+ for (i = 0; i < 2; i++) result += x;
13
+ return result;
14
+ }
15
+ #endif
16
+
17
+ int main() {
18
+ return compute(21);
19
+ }
@@ -0,0 +1,9 @@
1
+ // EXPECT: 55
2
+ int fib(int n) {
3
+ if (n <= 1) return n;
4
+ return fib(n - 1) + fib(n - 2);
5
+ }
6
+
7
+ int main() {
8
+ return fib(10);
9
+ }
@@ -0,0 +1,44 @@
1
+ // EXPECT: 3
2
+ // Conway's Game of Life: blinker oscillator
3
+ int get(int *g, int r, int c, int n) {
4
+ if (r < 0 || r >= n || c < 0 || c >= n) return 0;
5
+ return g[r * n + c];
6
+ }
7
+
8
+ int neighbors(int *g, int r, int c, int n) {
9
+ int s = 0;
10
+ int dr;
11
+ int dc;
12
+ for (dr = -1; dr <= 1; dr++)
13
+ for (dc = -1; dc <= 1; dc++)
14
+ if (dr != 0 || dc != 0)
15
+ s += get(g, r + dr, c + dc, n);
16
+ return s;
17
+ }
18
+
19
+ int main() {
20
+ int g[25] = {
21
+ 0,0,0,0,0,
22
+ 0,0,1,0,0,
23
+ 0,0,1,0,0,
24
+ 0,0,1,0,0,
25
+ 0,0,0,0,0
26
+ };
27
+ int next[25];
28
+ int r;
29
+ int c;
30
+ int n = 5;
31
+ for (r = 0; r < n; r++) {
32
+ for (c = 0; c < n; c++) {
33
+ int nb = neighbors(g, r, c, n);
34
+ int alive = g[r * n + c];
35
+ if (alive && (nb == 2 || nb == 3))
36
+ next[r * n + c] = 1;
37
+ else if (!alive && nb == 3)
38
+ next[r * n + c] = 1;
39
+ else
40
+ next[r * n + c] = 0;
41
+ }
42
+ }
43
+ return next[2*5+1] + next[2*5+2] + next[2*5+3];
44
+ }
@@ -0,0 +1,17 @@
1
+ // EXPECT: 31
2
+ int moves = 0;
3
+
4
+ void hanoi(int n, int from, int to, int aux) {
5
+ if (n == 1) {
6
+ moves++;
7
+ return;
8
+ }
9
+ hanoi(n - 1, from, aux, to);
10
+ moves++;
11
+ hanoi(n - 1, aux, to, from);
12
+ }
13
+
14
+ int main() {
15
+ hanoi(5, 1, 3, 2);
16
+ return moves;
17
+ }