QUICK REFERENCE

Conversion checklist

Use this sequence to prepare Python, convert it, and verify the generated C in your own build environment.

Prepare the Python

  1. Start with functions whose expected results you know.
  2. Choose a mode using Supported conversions, and follow its examples.
  3. For typed conversion, annotate parameters/results and keep variable types consistent. Supply all imported source modules.
  4. For runtime conversion, use explicitly supplied modules and the admitted string, container, class, function, and comprehension forms. Use annotations where a checked type boundary is useful.
  5. Assign every local and field before reading it. Include cases where branches or loops do not execute.

Convert and inspect

  1. Select Typed or Runtime in the Transpile menu, then click the Transpile button.
  2. Read diagnostics and correct rejected source forms. Review warnings on successful output.
  3. Convert again after edits. Save C only when it matches the intended source and settings.
  4. Review the generated function declarations and the selected mode's C caller requirements.

Build with a C11 toolchain

Use the dedicated PCFC11 Compile dialog, or Transpile → Other C Compilers… for GCC/MinGW-w64, Clang, MSVC or Clang-cl. The commands below show the equivalent external GCC workflow.

PyCForge emits source. Use a C application or test harness to call the generated functions. To compile a typed output to an object file with GCC:

gcc -std=c11 -Wall -Wextra -c output.c -o output.o

For runtime output with a Python main() callable without arguments, enable its optional entry wrapper:

gcc -std=c11 -DPYCF_RUNTIME_MAIN output.c -o program -lm

Follow typed string ownership and file status handling for typed output, or context lifetime and runtime errors for runtime output. Review compiler messages before running the program.

Complete typed C caller

Convert the add example to example.c. Save the following as caller.c in the same directory. Including the generated C makes its exact declarations available to this small standalone caller.

#include <inttypes.h>
#include <stdio.h>
#include "example.c"

int main(void)
{
    printf("%" PRId64 "\n", add(2, 3));
    return 0;
}

With a compatible GCC toolchain, build only the caller; do not also pass example.c, because it is already included:

gcc -std=c11 -Wall -Wextra caller.c -o caller

Run ./caller on Linux/macOS, or .\caller.exe in Windows PowerShell. It prints 5. For a larger C project, use matching declarations in a header and compile generated C as a separate translation unit.

Compare results with Python

Lazy iterator imports

The SDK's Delimited records starter provides these same public kernels under the independent recordio namespace. Change package, namespace and export names through the authoring workflow.

Delimited records

Declare *import csv in Runtime mode. The bounded CSV package supplies reader(iterable, /, *, delimiter=',', quotechar='"', skipinitialspace=False, strict=False) and writer(file, /, *, delimiter=',', quotechar='"', lineterminator='\r\n'). A slash marks positional-only input; parameters after the star are keyword-only. Readers yield new lists of strings and expose read-only line_num. Writers expose writerow(row, /), returning characters written, and writerows(rows, /), returning None.

*import csv

def main():
    rows = csv.reader(['name,value\n', '"north,west",12\n'])
    print(next(rows), rows.line_num)
    print(next(rows), rows.line_num)
    with open("records.csv", "w", encoding="utf-8", newline="") as output:
        writer = csv.writer(output, lineterminator="\n")
        writer.writerow(["name", "value"])
        writer.writerows([["north,west", 12], ["south", 15]])
    return 0

The example prints the header at line 1 and the quoted station name at line 2, then writes three rows. Use UTF-8 text files with newline="". Reader input items represent physical lines; quoted fields can span lines. Delimiter and quotechar must be distinct single ASCII characters other than NUL, CR or LF. Quoting is minimal with doubled quotes; writer line endings are CRLF or LF.

Fields admit strings, int64, finite float64, bool and None (an empty field). A field is limited to 131072 Unicode scalars, a row to 16384 fields and input/output record text to 1 MiB of UTF-8; Runtime work and allocation budgets also apply. Format errors raise ValueError with line and column; wrong input types raise TypeError. This profile does not export csv.Error. line_num counts consumed items, including non-string items, which differs from CPython's error behavior.

Readers and writers retain their source/file and share state through aliases. They never close the caller's file; keep use inside its with block. Malformed partial rows are discarded without rewinding input. Formatting finishes before each row is written; earlier rows and partial I/O on device failure are not rolled back. Dialect registries, escape/quoting modes, DictReader/DictWriter, Sniffer, bytes, callbacks and custom conversion hooks are outside this profile. Import Help contains the full contract.

The SDK's Lazy record pipelines starter exposes reusable chain, islice and pairwise operations under an independent namespace. The bundled itertools package uses these same contracts. Iterators retain their inputs and share their position through aliases. Exhaustion releases retained references; caller-owned files remain open until their own close or with-block exit.

*import itertools as it
def main():
    readings = it.chain([10, 12], [15, 21])
    for before, after in it.pairwise(it.islice(readings, 1, None)):
        print(after - before)
    return 0

This prints 3 and 6 on separate lines. chain accepts zero to eight positional inputs; islice accepts its two-, three- or four-argument form; pairwise accepts one input. Keywords, argument expansion, custom iteration hooks, generators and other itertools members are unsupported. Consult Import Help for input types, error recovery and work limits. Keep file-backed pipelines inside the file's with block.

Use independently authored formulas

The SDK's Author-defined measurement formulas starter supports new scalar logic through expression and ordered binding fields. Registered formulas can be called with their advertised positional/named/default arguments in Runtime programs and supplied modules. The initial profile accepts finite numbers and returns float64 or bool; it does not define new objects, iterators or binary buffers.

Each formula declares a bounded expression using arithmetic, comparisons, Boolean conditions and abs/sqrt/min/max primitives. An intermediate such as corrected = value - offset can be used in corrected * gain. Conditional expressions evaluate only their selected branch. Consult the package's Import Help for its exact formula and the engine-owned numerical, error and work limits.

SDK conversion verification does not run C or establish expected output. Compile and exercise the complete application in PyCForge, including errors and boundary values. A changed formula requires fresh conversion evidence and native qualification for its claimed behavior.

Retain a reproducible example

Keep the Python source, selected mode, settings, package version, generated C, test inputs, and expected results together. For a problem report, reduce the source to the smallest example that reproduces it and include the exact diagnostic or compiler message.