PetWay progress: a step towards PetLang: revised calling conventions

2025-07-02

Initially PetWay was designed to facilitate programming in C, but the ultimate goal is to make it a runtime for PetLang. This milestone is a step towards calling conventions required for threaded code.

Changes

Interfacing with C

Some functions still return PwValue: pw_clone and variadic functions.

Variadic functions are extremely convenient for expressing maps and arrays in C, but functions no longer return PwResult. As a workaround, pwva macro was added. It exploits GNU extension statement expression and returns either result or status, depending on function's return value. If an error occurs when some variadic argument is pushed on stack, it is impossible to handle such an error during function call. These errors are handled by variadic function that checks arguments. Arguments are always passed by value and variadic function is responsible for destroying them upon return.

pw_get and pw_map_get are confusing because the result is the first argument for the former and is the last argument for the latter.

What helps to avoid common mistakes

What caused segfaults

Future work

Finish Pet Preprocessor's initial task: facilitate definition of per-function arguments and result structures.

Rewrite parts of PetWay in PetLang. Freeze current codebase for bootstrapping.

Revise CharPtr. Merge with String? I.e. use str_static along with str_embedded? Think through UTF-8 type.

Think through objectives concept as an alternative to tracebacks.

Think through variadic arguments and results concept in PetLang.

Think through concept of multiple exit points. That's like promises that have two callbacks: resolve and reject.