CONVERSION REFERENCE

Functions and module variables

Use annotated functions and add every source file needed by their imports. Module variables are supported when their values can be determined during conversion.

Variables outside functions

BASE: int = 4
EARLIER = BASE
BASE += 3
PREFIX = "hé" + "llo"

def score(text: str) -> int:
    total = BASE + EARLIER
    if text.startswith(PREFIX):
        total += len(text)
    return total

Module assignments are processed in source order: EARLIER is 4, and the function sees the final BASE value of 7. Supported values are int, float, bool, and str, including earlier constants, numeric constant expressions, and the constant string operations.

These values become constants in the C output. They are not writable shared global state. A module assignment cannot call your functions, read a file, or depend on an external Python environment. global and nonlocal writes are unsupported. Declare a module value before referring to it, and avoid names already used by functions, imports, or scalar built-ins.

Include all required files

The workspace converts its open modules together. Through the Python API, supply the source files in a SourceBundle. PyCForge does not search installed packages or read imported files automatically.

Calling your functions

def combine(left: int, *, right: int) -> int:
    return left + right

def use(value: int) -> int:
    return combine(value, right=2)

You can pass positional arguments, explicit keyword arguments, and required keyword-only arguments. Arguments must match the declared parameter types. Expressions are evaluated once in source order.

Supply every required argument. Default values, *args, **kwargs, argument unpacking, function-valued variables, recursive calls, and arbitrary object methods are unsupported. The string methods documented in String operations are supported separately.

Importing functions from another included file

# math_tools.py — module name: math_tools
def double(value: int) -> int:
    return value * 2

# main.py — module name: main
from math_tools import double

def run(value: int) -> int:
    return double(value)

Add both files before converting. Use from module_name import function_name; an unambiguous as alias is also supported. Plain import module, relative imports, star imports, imports inside functions, and circular imports are unsupported. Importing module constants or record classes is not supported in this version.

Saving the result

The files produce one combined C output. Changing any included file makes the previous output stale. Convert the complete set again before saving.