Skip to content

dan-german/cpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpy

cpy is a minimal, naive C to Apple Silicon ARM64 compiler.

Example

from cpy import compile

code = """
int main() {
    return 2 * 3;
}
"""
print(compile(code))

Output (ARM64 Assembly)

.global _main
.align 2

_main:
    str lr, [sp, #-32]!
    mov w8, #2
    str w8, [sp, #4]
    mov w8, #3
    str w8, [sp, #8]
    ldr w8, [sp, #4]
    ldr w9, [sp, #8]
    mul w8, w8, w9
    str w8, [sp, #12]
    ldr w0, [sp, #12]
    ldr lr, [sp]
    add sp, sp, #32
    ret

Running the Compiled Code

If you're on an Apple Silicon Mac, you can run the generated assembly using:

from test.test_e2e import debug

print(debug(code))  # Outputs: 6

Features

✅ Functions
if/else statements
while statements
✅ Compound statements
✅ Declaration, scope & reference validation
✅ Integer arithmetic
✅ Tests for each step, including end-to-end program execution.
🔜 More soon!

About

C to Apple ARM64 compiler written in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages