About
Compy is a very small transpiler that takes Python-looking code and turns it into plain C.
It produces readable output, adds no runtime, and supports dropping real C code with
__inline_c__ and __inline_c_global__ blocks.
What it understands
def name(args):→int name(args) {if cond:/else:return valueprint(expr)→printf(…)with basic type guessingfprint_str("text ${x}")/fprint_int()/fprint_flt()- Short type names:
int,flt,str,bool,char,double include stdio.horinclude "file.h"- Indent-based blocks (automatically adds/closes braces)
- Raw C inside
__inline_c__ {…}blocks - Global raw C with
__inline_c_global__ {…}
Compy stdlib (included when you use it)
pow_int(base, exp)sqrt_flt(x)abs_int(x)len_str(s)concat(a, b)→ new allocated stringsubstr(s, start, len)→ new allocated stringseed_rand()/rand_int(min,max)/rand_flt(min,max)input_str(buf, maxlen, prompt)input_int(prompt)/input_flt(prompt)write_file(path, content)read_file(path)→ allocated string or NULL
Quick usage
- Write code in
.cmpyfile - Run:
./compy yourfile.cmpy - Compile generated file:
gcc out.c -O3 -o program - Run:
./program
Output always goes to out.c in current directory.
Compiler itself is tiny (~400 LOC).