cshape 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cshape-0.1.0/LICENSE +21 -0
- cshape-0.1.0/PKG-INFO +88 -0
- cshape-0.1.0/README.md +70 -0
- cshape-0.1.0/cshape.egg-info/PKG-INFO +88 -0
- cshape-0.1.0/cshape.egg-info/SOURCES.txt +9 -0
- cshape-0.1.0/cshape.egg-info/dependency_links.txt +1 -0
- cshape-0.1.0/cshape.egg-info/top_level.txt +1 -0
- cshape-0.1.0/cshape.py +1608 -0
- cshape-0.1.0/pyproject.toml +24 -0
- cshape-0.1.0/setup.cfg +4 -0
- cshape-0.1.0/tests/test_smoke.py +41 -0
cshape-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alex Balan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
cshape-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cshape
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A dependency-free C AST + printer: build a tree in Python, get C11 source back
|
|
5
|
+
Author-email: Alex Balan <outsiders.b@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: c,codegen,code-generation,ast,transpiler,compiler
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: C
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
13
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# cshape
|
|
20
|
+
|
|
21
|
+
A dependency-free C AST + printer for Python: build a tree and get C11
|
|
22
|
+
source back. No parsing, no dependencies beyond the standard library —
|
|
23
|
+
just `CType*` / `CValue*` / `CStmt*` nodes and a `render()` function that
|
|
24
|
+
turns them into text.
|
|
25
|
+
|
|
26
|
+
Originally the C backend's printer for the Modest compiler, split out
|
|
27
|
+
because it doesn't know anything about Modest — it only knows about C.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
pip install cshape
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Example
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from cshape import *
|
|
39
|
+
|
|
40
|
+
func = CStmtDefFunc(
|
|
41
|
+
id_str="add",
|
|
42
|
+
type=CTypeFunc(
|
|
43
|
+
params=[CField(id_str="a", type=CTypeNamed("int")),
|
|
44
|
+
CField(id_str="b", type=CTypeNamed("int"))],
|
|
45
|
+
to=CTypeNamed("int"),
|
|
46
|
+
),
|
|
47
|
+
block=CStmtBlock([
|
|
48
|
+
CStmtReturn(CValueAdd(CValueNamed("a"), CValueNamed("b"))),
|
|
49
|
+
]),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
print(render(func).strip())
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```c
|
|
56
|
+
int add(int a, int b) {
|
|
57
|
+
return a + b;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
(`render()` returns the node's own leading blank lines too — `CStmtDefFunc`
|
|
62
|
+
starts with a blank line by default, so `.strip()` if you're printing a
|
|
63
|
+
single node standalone rather than concatenating several.)
|
|
64
|
+
|
|
65
|
+
## What it covers
|
|
66
|
+
|
|
67
|
+
- Types: named types, pointers, arrays, function types, structs/unions, enums
|
|
68
|
+
- Values: the full C11 expression grammar with correct operator precedence
|
|
69
|
+
and parenthesization (including the extra parens GCC/Clang warn about for
|
|
70
|
+
mixed bitwise/shift expressions)
|
|
71
|
+
- Statements: blocks, if/while, return, break/continue, inline asm, raw
|
|
72
|
+
inserts
|
|
73
|
+
- Preprocessor: `#define`, `#undef`, `#include`, `#if`/`#elif`/`#else`/`#endif`
|
|
74
|
+
regions
|
|
75
|
+
- Two brace styles (`legacy` — K&R-ish, `modern` — Allman-ish), configurable
|
|
76
|
+
via `render(node, style=...)`
|
|
77
|
+
- A `.mark` field on every node: set it to any string and it shows up as a
|
|
78
|
+
`/*mark*/` comment right before that node in the output — useful for
|
|
79
|
+
tracing which part of your own compiler/generator produced which bit of C
|
|
80
|
+
|
|
81
|
+
## What it doesn't do
|
|
82
|
+
|
|
83
|
+
No parsing, no semantic analysis, no type checking. It's a printer, not a
|
|
84
|
+
compiler frontend — you build the tree, it hands you back text.
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
MIT
|
cshape-0.1.0/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# cshape
|
|
2
|
+
|
|
3
|
+
A dependency-free C AST + printer for Python: build a tree and get C11
|
|
4
|
+
source back. No parsing, no dependencies beyond the standard library —
|
|
5
|
+
just `CType*` / `CValue*` / `CStmt*` nodes and a `render()` function that
|
|
6
|
+
turns them into text.
|
|
7
|
+
|
|
8
|
+
Originally the C backend's printer for the Modest compiler, split out
|
|
9
|
+
because it doesn't know anything about Modest — it only knows about C.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pip install cshape
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Example
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from cshape import *
|
|
21
|
+
|
|
22
|
+
func = CStmtDefFunc(
|
|
23
|
+
id_str="add",
|
|
24
|
+
type=CTypeFunc(
|
|
25
|
+
params=[CField(id_str="a", type=CTypeNamed("int")),
|
|
26
|
+
CField(id_str="b", type=CTypeNamed("int"))],
|
|
27
|
+
to=CTypeNamed("int"),
|
|
28
|
+
),
|
|
29
|
+
block=CStmtBlock([
|
|
30
|
+
CStmtReturn(CValueAdd(CValueNamed("a"), CValueNamed("b"))),
|
|
31
|
+
]),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
print(render(func).strip())
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```c
|
|
38
|
+
int add(int a, int b) {
|
|
39
|
+
return a + b;
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
(`render()` returns the node's own leading blank lines too — `CStmtDefFunc`
|
|
44
|
+
starts with a blank line by default, so `.strip()` if you're printing a
|
|
45
|
+
single node standalone rather than concatenating several.)
|
|
46
|
+
|
|
47
|
+
## What it covers
|
|
48
|
+
|
|
49
|
+
- Types: named types, pointers, arrays, function types, structs/unions, enums
|
|
50
|
+
- Values: the full C11 expression grammar with correct operator precedence
|
|
51
|
+
and parenthesization (including the extra parens GCC/Clang warn about for
|
|
52
|
+
mixed bitwise/shift expressions)
|
|
53
|
+
- Statements: blocks, if/while, return, break/continue, inline asm, raw
|
|
54
|
+
inserts
|
|
55
|
+
- Preprocessor: `#define`, `#undef`, `#include`, `#if`/`#elif`/`#else`/`#endif`
|
|
56
|
+
regions
|
|
57
|
+
- Two brace styles (`legacy` — K&R-ish, `modern` — Allman-ish), configurable
|
|
58
|
+
via `render(node, style=...)`
|
|
59
|
+
- A `.mark` field on every node: set it to any string and it shows up as a
|
|
60
|
+
`/*mark*/` comment right before that node in the output — useful for
|
|
61
|
+
tracing which part of your own compiler/generator produced which bit of C
|
|
62
|
+
|
|
63
|
+
## What it doesn't do
|
|
64
|
+
|
|
65
|
+
No parsing, no semantic analysis, no type checking. It's a printer, not a
|
|
66
|
+
compiler frontend — you build the tree, it hands you back text.
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
MIT
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cshape
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A dependency-free C AST + printer: build a tree in Python, get C11 source back
|
|
5
|
+
Author-email: Alex Balan <outsiders.b@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: c,codegen,code-generation,ast,transpiler,compiler
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: C
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
13
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# cshape
|
|
20
|
+
|
|
21
|
+
A dependency-free C AST + printer for Python: build a tree and get C11
|
|
22
|
+
source back. No parsing, no dependencies beyond the standard library —
|
|
23
|
+
just `CType*` / `CValue*` / `CStmt*` nodes and a `render()` function that
|
|
24
|
+
turns them into text.
|
|
25
|
+
|
|
26
|
+
Originally the C backend's printer for the Modest compiler, split out
|
|
27
|
+
because it doesn't know anything about Modest — it only knows about C.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
pip install cshape
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Example
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from cshape import *
|
|
39
|
+
|
|
40
|
+
func = CStmtDefFunc(
|
|
41
|
+
id_str="add",
|
|
42
|
+
type=CTypeFunc(
|
|
43
|
+
params=[CField(id_str="a", type=CTypeNamed("int")),
|
|
44
|
+
CField(id_str="b", type=CTypeNamed("int"))],
|
|
45
|
+
to=CTypeNamed("int"),
|
|
46
|
+
),
|
|
47
|
+
block=CStmtBlock([
|
|
48
|
+
CStmtReturn(CValueAdd(CValueNamed("a"), CValueNamed("b"))),
|
|
49
|
+
]),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
print(render(func).strip())
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```c
|
|
56
|
+
int add(int a, int b) {
|
|
57
|
+
return a + b;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
(`render()` returns the node's own leading blank lines too — `CStmtDefFunc`
|
|
62
|
+
starts with a blank line by default, so `.strip()` if you're printing a
|
|
63
|
+
single node standalone rather than concatenating several.)
|
|
64
|
+
|
|
65
|
+
## What it covers
|
|
66
|
+
|
|
67
|
+
- Types: named types, pointers, arrays, function types, structs/unions, enums
|
|
68
|
+
- Values: the full C11 expression grammar with correct operator precedence
|
|
69
|
+
and parenthesization (including the extra parens GCC/Clang warn about for
|
|
70
|
+
mixed bitwise/shift expressions)
|
|
71
|
+
- Statements: blocks, if/while, return, break/continue, inline asm, raw
|
|
72
|
+
inserts
|
|
73
|
+
- Preprocessor: `#define`, `#undef`, `#include`, `#if`/`#elif`/`#else`/`#endif`
|
|
74
|
+
regions
|
|
75
|
+
- Two brace styles (`legacy` — K&R-ish, `modern` — Allman-ish), configurable
|
|
76
|
+
via `render(node, style=...)`
|
|
77
|
+
- A `.mark` field on every node: set it to any string and it shows up as a
|
|
78
|
+
`/*mark*/` comment right before that node in the output — useful for
|
|
79
|
+
tracing which part of your own compiler/generator produced which bit of C
|
|
80
|
+
|
|
81
|
+
## What it doesn't do
|
|
82
|
+
|
|
83
|
+
No parsing, no semantic analysis, no type checking. It's a printer, not a
|
|
84
|
+
compiler frontend — you build the tree, it hands you back text.
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cshape
|