python c model skeleton added

This commit is contained in:
Nicolas 2025-10-03 22:49:07 +02:00
parent 3476fc8980
commit 672a67837f
8 changed files with 39 additions and 5 deletions

View File

@ -9,5 +9,5 @@ gcc -c src/copapy/stencils.c -O2 -o src/copapy/obj/stencils_x86_64_O2.o
gcc -c src/copapy/stencils.c -O3 -o src/copapy/obj/stencils_x86_64_O3.o
mkdir bin -p
gcc -Wall -Wextra -Wconversion -Wsign-conversion -Wshadow -Wstrict-overflow -Werror -g src/runner/runmem2.c -o bin/runmem2
gcc -Wall -Wextra -Wconversion -Wsign-conversion -Wshadow -Wstrict-overflow -Werror -g src/coparun/coparun.c src/coparun/runmem.c -o bin/coparun
#x86_64-w64-mingw32-gcc -Wall -Wextra -Wconversion -Wsign-conversion -Wshadow -Wstrict-overflow -Werror src/runner/runmem2.c -Wall -O3 -o bin/runmem2.exe

View File

@ -28,7 +28,10 @@ build-backend = "setuptools.build_meta"
where = ["src"]
[tool.setuptools.package-data]
copapy = ["*.c", "*.o"]
copapy = ["*.o"]
[tool.setuptools.ext_modules]
coparun = { sources = ["src/coparun/coparun_module.c"] }
[project.optional-dependencies]
dev = [

0
src/coparun/coparun.c Normal file
View File

View File

@ -0,0 +1,31 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>
// A simple C function exposed to Python
static PyObject* my_function(PyObject* self, PyObject* args) {
int a, b;
if (!PyArg_ParseTuple(args, "ii", &a, &b)) {
return NULL; // Error if arguments aren't two integers
}
return PyLong_FromLong(a + b); // Return sum as Python integer
}
// Method definitions
static PyMethodDef MyMethods[] = {
{"add", my_function, METH_VARARGS, "Adds two numbers"},
{NULL, NULL, 0, NULL} // Sentinel
};
// Module definition
static struct PyModuleDef my_module = {
PyModuleDef_HEAD_INIT,
"my_module", // Module name
NULL, // Documentation
-1, // Size of per-interpreter state (-1 for global)
MyMethods
};
// Module initialization function
PyMODINIT_FUNC PyInit_my_module(void) {
return PyModule_Create(&my_module);
}

0
src/coparun/runmem.h Normal file
View File

View File

@ -5,5 +5,5 @@ python tests/test_compile.py
echo "Run..."
echo "-----------------------------------"
mkdir bin -p
gcc -Wall -Wextra -Wconversion -Wsign-conversion -Wshadow -Wstrict-overflow -Werror -g src/runner/runmem2.c -o bin/runmem2
./bin/runmem2 test.copapy
gcc -Wall -Wextra -Wconversion -Wsign-conversion -Wshadow -Wstrict-overflow -Werror -g src/coparun/runmem.c src/coparun/coparun.c -o bin/coparun
./bin/coparun test.copapy

View File

@ -72,7 +72,7 @@ def test_compile():
il.to_file('test.copapy')
result = run_command(['./bin/runmem2', 'test.copapy'])
result = run_command(['./bin/coparun', 'test.copapy'])
print('* Output from runner:')
print(result)