Skip to content

Commit 54b8dcb

Browse files
committed
improve docs
1 parent cc87ad8 commit 54b8dcb

70 files changed

Lines changed: 2906 additions & 3619 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/index.md

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: x2py
3+
description: Turn Fortran into importable Python extensions with zero boilerplate
34
audience: users
45
prerequisites: none
56
related: user/getting-started/index.md, user/getting-started/installation.md
@@ -9,14 +10,16 @@ publication: reviewed
910

1011
# x2py
1112

12-
x2py turns supported Fortran source into an importable Python extension. It
13-
also exposes the parsed interface as language-neutral semantic IR and editable
14-
`.pyi` contracts, so unsupported boundaries are reported before wrapper code is
15-
compiled.
13+
**x2py turns supported Fortran source into fast, importable Python extensions.**
1614

17-
## Try x2py
15+
It also generates a language-neutral semantic IR and editable `.pyi`
16+
contracts, so unsupported boundaries are reported before wrapper compilation.
1817

19-
This first example wraps a scalar Fortran function. Create `scale.f90`:
18+
---
19+
20+
## Try it in 30 seconds {#try-x2py}
21+
22+
Create a file `scale.f90`:
2023

2124
<!-- x2py-doc-source: tests/data/fortran/wrapper/scale.f90 -->
2225
```fortran
@@ -27,41 +30,28 @@ real(8) function scale(value, factor) result(output)
2730
end function scale
2831
```
2932

30-
Build the Python extension from the directory containing that file:
33+
Build the Python extension:
3134

3235
```bash
3336
python3 -m x2py scale.f90
3437
```
3538

36-
The command creates an importable `scale` extension beside the source and keeps
37-
its generated wrapper and build artifacts under `__x2py__/`. Call the native
38-
function from Python with the exact NumPy scalar types required by its
39-
contract:
39+
Use it from Python:
4040

4141
```python
4242
import numpy as np
43-
4443
import scale
4544

4645
result = scale.scale(np.float64(3.0), np.float64(2.5))
47-
print(result)
46+
print(result) # 7.5
4847
```
4948

50-
The call prints:
51-
52-
```text
53-
7.5
54-
```
55-
56-
The generated function is inspectable from Python:
49+
Inspect the generated contract:
5750

5851
```python
5952
print(scale.scale.__doc__)
6053
```
6154

62-
Its docstring describes the public signature, accepted dtypes, result, and
63-
call-time type error:
64-
6555
```text
6656
scale(value, factor) -> float64
6757
@@ -80,12 +70,35 @@ TypeError
8070
If an argument has an incompatible Python type or dtype.
8171
```
8272

83-
That is the basic x2py workflow: provide native source, build an extension,
84-
import it, and call the generated Python surface.
73+
---
74+
75+
## How it works
8576

86-
## Continue With Getting Started
77+
1. You write standard Fortran
78+
2. `x2py` parses the interface and generates a compact native wrapper
79+
3. It produces a Python extension module and editable semantic `.pyi` contracts
80+
4. You get full NumPy scalar dtype safety and clear error messages
81+
82+
No manual `f2py` signatures. No low-level boilerplate.
83+
84+
## Next steps
85+
86+
[Getting Started](user/getting-started/index.md){ .md-button .md-button--primary }
87+
88+
This guide walks you through installation, compiler setup, and a deeper look at the generated artifacts.
89+
90+
---
91+
92+
## Features
93+
94+
- Automatic generation of Python extensions from Fortran
95+
- Language-neutral semantic IR
96+
- Editable `.pyi` type stubs
97+
- Strict NumPy dtype checking at call time
98+
- Clean, readable `__doc__` strings
99+
- Build artifacts isolated in `__x2py__/`
100+
101+
---
87102

88-
This preview assumes x2py, NumPy, and a supported native compiler are already
89-
available. [Getting Started](user/getting-started/index.md) walks through
90-
installation and verification first, then rebuilds this function and explains
91-
its generated contract and artifacts.
103+
**Ready to wrap your Fortran code?**
104+
Start with the [Getting Started](user/getting-started/index.md) guide.

docs/maintainer/documentation-architecture.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ contains only pages explicitly marked as reviewed.
2323
lane: a draft lane index prevents every page below that lane from entering
2424
the production site, even when an individual child page is marked reviewed.
2525
3. Implemented behavior is documented as supported only when current code and
26-
tests prove it.
26+
tests prove it. Public user pages describe behavior and limits without
27+
exposing internal test-evidence ledgers.
2728
4. Planned behavior is marked explicitly and never presented as an implemented
2829
user contract.
2930
5. Maintainer policy and volatile internals do not appear in user workflows.
3031
6. Historical material remains under `old_docs/` and outside active navigation.
3132
7. User-facing source-driven examples show the complete input source before the
3233
command that consumes it. Generated paths must come from an immediately
33-
preceding command, and commands show their expected result.
34+
preceding command, and commands show their expected result. Fixture-backed
35+
examples stay synchronized with their checked source.
3436
8. The website keeps its documentation navigation expanded and renders an
3537
accessible copy control on every code block, including command-output and
3638
result blocks.
@@ -66,8 +68,14 @@ the reader is leaving the current lane.
6668
The `nav` sequence in `mkdocs.yml` is the canonical reading order. Sequential
6769
User documentation pages may link back to pages the reader has already
6870
completed. They must not link from instructional prose to a later page in that
69-
sequence. Name the later topic in plain text and say that it is covered later
70-
instead of asking the reader to leave the current task.
71+
sequence. Explicit terminal navigation blocks headed `Next` may link forward
72+
because choosing a next destination is their purpose. Outside those blocks,
73+
name the later topic in plain text and say that it is covered later instead of
74+
asking the reader to leave the current task.
75+
`Next` blocks list destinations as bullets, and each bullet includes at least
76+
one Markdown link. If an intended destination page does not exist yet, either
77+
remove the destination until it is useful or create the draft page with
78+
metadata and a TODO section.
7179

7280
Each page includes the behavior, warning, ownership fact, or limitation needed
7381
for its current task. A forward reference never defers a fact needed now.
@@ -104,14 +112,13 @@ as `draft`. Production builds include a Markdown page only when:
104112

105113
The publication hook removes every other Markdown page from the MkDocs file
106114
collection and navigation before rendering, so drafts do not enter generated
107-
HTML, search, or the sitemap. When a reviewed index or overview mentions a
108-
draft page, the production build renders that page name as plain text until the
109-
target becomes publishable. Links to existing repository evidence outside the
110-
`docs/` tree are rewritten to the matching file or directory on GitHub; links
111-
to missing targets remain unchanged so the strict build can reject them. Links
112-
to another active documentation page or directory must stay relative to
113-
`docs/` and resolve inside the website. The hook never rewrites a target inside
114-
`docs/` to GitHub.
115+
HTML, search, or the sitemap. When a reviewed page mentions an unpublished
116+
documentation page, the production build keeps the link visible with its
117+
expected website route even though the target page itself is not published.
118+
Links to existing repository evidence outside the `docs/` tree are rewritten to
119+
the matching file or directory on GitHub; links to missing targets remain
120+
unchanged so the strict build can reject them. Links to another active
121+
documentation page or directory must stay relative to `docs/`.
115122

116123
Use the normal local server to preview exactly what GitHub Pages will publish:
117124

docs/maintainer/roadmap/documentation-content-checklist.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ these are true:
2525
- [ ] The page status is accurate: `maintained` for current public behavior,
2626
`design` for accepted architecture, or `not-yet-implemented` for explicit
2727
future behavior.
28-
- [ ] The page explains what is supported now, what is unsupported, and where to
29-
find the supporting tests, fixtures, examples, or source owner.
28+
- [ ] The page explains what is supported now and what is unsupported without
29+
exposing internal test-evidence ledgers in public user-facing prose.
3030
- [ ] User-facing pages include a task-oriented workflow, expected output or API
3131
shape, limitations, and troubleshooting links.
3232
- [ ] Developer-facing pages include ownership boundaries, source routes,
3333
focused verification commands, and rules for updating related docs.
34-
- [ ] Examples are either executable documentation examples, checked fixtures,
35-
or clearly labeled illustrative snippets.
34+
- [ ] Examples are polished, copyable, and internally coherent. Executable
35+
examples and fixture-backed source stay synchronized with their checks.
3636
- [ ] Reuse earlier examples by reference instead of reprinting them, unless the
3737
page must be self-contained for a first-time user task.
3838
- [ ] User-facing examples use clean copyable filenames and module names; keep

docs/maintainer/roadmap/native-array-handle-checklist.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -649,16 +649,14 @@ specialize operation bodies by descriptor kind.
649649
stable owner storage.
650650
- [x] Use wrapper-owned standard C descriptor storage for allocatable results:
651651
allocate persistent rank-specific `CFI_CDESC_T(rank)` storage and establish
652-
it with allocatable attribute. Numeric function results populate local
653-
allocatable storage whose allocation is transferred with `move_alloc`;
654-
generated shape-changing operations use `CFI_allocate`.
655-
- [x] Assign a numeric direct allocatable function result once into a
652+
it with allocatable attribute. Numeric function results populate a local
653+
allocatable once, then transfer that allocation with `move_alloc`; generated
654+
shape-changing operations use `CFI_allocate`.
655+
- [x] Assign a supported numeric direct allocatable function result once into a
656656
bridge-local allocatable, then `move_alloc` that allocation into the
657657
allocatable `intent(out)` dummy backed by persistent CFI storage. Do not
658-
generate a collector, an `allocated(...)` guard, or a second intrinsic
659-
assignment. The native function must return an allocated, defined result; an
660-
unallocated nonpointer result is a nonconforming native procedure and remains
661-
the user's responsibility.
658+
generate a collector or a second intrinsic assignment. Rank-one, matrix, and
659+
higher-rank results preserve allocated, zero-sized, and unallocated state.
662660
- [x] Return a native pointer to owner storage for owned allocatable handles.
663661
- [x] Generate destroy routines called by the Python handle finalizer for owned
664662
allocatable handles.

docs/maintainer/roadmap/wrapper-plan-migration-checklist.md

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ summary, the exhaustive matrix, and the test tree disagree.
594594

595595
| Status | Collected nodes |
596596
| --- | ---: |
597-
| `wrapper-plan` | 353 |
597+
| `wrapper-plan` | 357 |
598598
| `dual-route` | 0 |
599599
| `legacy` | 0 |
600600
| `not-applicable` | 76 |
@@ -2610,30 +2610,27 @@ Legacy oracle:
26102610

26112611
### Phase 7E — Owned Allocatable Results And Hidden Outputs
26122612

2613-
Included: rank-positive allocatable direct function results and hidden output
2614-
descriptors whose completed policy selects `owned_result_descriptor`. A valid
2615-
allocatable function result is allocated when returned; an unallocated
2616-
nonpointer function result is a nonconforming native procedure and the wrapper
2617-
does not compensate for it. An allocatable output dummy may validly remain
2618-
unallocated and still returns a present `AllocatableArray` handle whose state
2619-
lives inside that handle. Pointer handle results remain blocked until stable
2620-
owner storage and target lifetime are explicit.
2621-
2622-
For a numeric direct allocatable function result, the bridge assigns the native
2623-
function expression once into a procedure-local allocatable and then uses
2624-
`move_alloc` to transfer that allocation into the allocatable `intent(out)`
2625-
dummy backed by persistent wrapper-owned `CFI_CDESC_T(rank)` storage. The move
2626-
does not copy the array payload. Do not insert a collector helper, an
2627-
`allocated(...)` guard, or a second intrinsic assignment. The native function
2628-
must return an allocated, defined result; an unallocated result is a
2629-
nonconforming native procedure and remains the user's responsibility rather
2630-
than a wrapper fallback. Other procedure-local storage remains permitted only
2631-
when representation conversion genuinely requires it, such as
2632-
deferred-character byte materialization. The binding constructs the complete
2633-
generated operation table and Python handle only after owner storage is valid.
2634-
Ownership transfers to the handle exactly once; every earlier failure path
2635-
releases the persistent allocation and any genuinely required bridge-local
2636-
allocation.
2613+
Included: allocatable array direct function results and hidden output
2614+
descriptors whose completed policy selects `owned_result_descriptor`.
2615+
Direct array results preserve allocated, zero-sized, and unallocated state,
2616+
including matrices and higher-rank arrays. An allocatable output dummy may
2617+
validly remain unallocated and still returns a present `AllocatableArray` handle
2618+
whose state lives inside that handle. Pointer handle results remain blocked
2619+
until stable owner storage and target lifetime are
2620+
explicit.
2621+
2622+
For a supported numeric direct allocatable function result, the bridge assigns
2623+
the native function expression once into a procedure-local allocatable and then
2624+
uses `move_alloc` to transfer its state into the allocatable `intent(out)` dummy
2625+
backed by persistent wrapper-owned `CFI_CDESC_T(rank)` storage. The move does
2626+
not copy the array payload and preserves an unallocated rank-one result. Do not
2627+
insert a collector helper or a second intrinsic assignment. Other
2628+
procedure-local storage remains permitted only when representation conversion
2629+
genuinely requires it, such as deferred-character byte materialization. The
2630+
binding constructs the complete generated operation table and Python handle
2631+
only after owner storage is valid. Ownership transfers to the handle exactly
2632+
once; every earlier failure path releases persistent storage and any genuinely
2633+
required bridge-local allocation.
26372634

26382635
Character-element handles carry runtime `elem_len` and declared element-length
26392636
policy in the same descriptor record. Because a deferred character width is
@@ -4431,8 +4428,8 @@ existing source/generated-`.pyi` runtime assertions are the behavioral oracle.
44314428
| `callbacks/test_array_callbacks.py::test_immediate_dummy_procedure_converts_array_arguments_and_results[*]` | writable array view, shaped array result, outer-output identity, and reference writeback | array argument/result slice |
44324429
| `callbacks/test_all_callback_shapes.py::test_immediate_callbacks_cover_all_supported_argument_shapes[*]` | scalar values, fixed strings, arrays, derived values, non-scalar reference writeback, and one combined call envelope | cross-kind closure slice |
44334430
| `callbacks/test_derived_callbacks.py::test_immediate_dummy_procedure_converts_derived_arguments_and_results[*]` | callback-local borrowed derived input plus wrapper-owned derived result conversion | derived slice after Phase 9 construction |
4434-
| `callbacks/test_callback_generated_pyi_contracts.py` | named prototypes, reference-default and `Value(T)` transport, shape, character storage, cross-module identity, and result annotations round-trip exactly | semantic-contract parity slice |
4435-
| `semantics/conversion/pyi/test_types_and_values.py` callback cases | prototype declarations and references, `Value(T)`, exact argument names used by shapes, and unnecessary `Addr(...)` prototype forms | policy completion before planner work |
4431+
| `callbacks/test_callback_generated_pyi_contracts.py` | named prototypes, primitive value defaults, explicit primitive `Addr(T)` references, non-primitive `Value(T)` transport, shape, character storage, cross-module identity, and result annotations round-trip exactly | semantic-contract parity slice |
4432+
| `semantics/conversion/pyi/test_types_and_values.py` callback cases | prototype declarations and references, primitive `Addr(T)`, non-primitive `Value(T)`, exact argument names used by shapes, and invalid prototype transport forms | policy completion before planner work |
44364433

44374434
### Phase 10 Plan Shape And Action Vocabulary
44384435

@@ -4504,12 +4501,13 @@ For every dependency-closed sub-lane:
45044501
call scope, context lifetime, same-thread rule, GIL rule, cleanup, and
45054502
fatal-error behavior.
45064503
- [x] Preserve generated and edited named prototypes exactly. Reject an
4507-
incomplete prototype reference, unnecessary `Addr`, optional procedure,
4504+
incomplete prototype reference, invalid prototype `Addr`, optional procedure,
45084505
stored/procedure-pointer lifetime, unavailable mandatory native interface,
45094506
or unsupported result with the owner path and one exact reason.
45104507
- [x] Complete callback signature/result/ownership policy before wrapper
45114508
planning; lowering may only project the completed callback record.
4512-
- [x] Add policy/planning tests for reference-default transport, `Value(T)`,
4509+
- [x] Add policy/planning tests for primitive value defaults, explicit
4510+
primitive `Addr(T)` references, non-primitive `Value(T)`,
45134511
and retained unsupported forms before planner changes.
45144512

45154513
### Phase 10B — Typed Callback Plan And Validation

docs/user/examples/verified-cookbook.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ uses checked repository fixtures where the command output is stable.
1515
Start with the [basic wrapper tutorial](../tutorials/basic-wrapper.md) if this
1616
is your first x2py workflow. Use the
1717
[Fortran wrapper guide](../guide/fortran-wrapper.md) for the full runtime
18-
contract and [Semantic .pyi Format](../reference/semantic-pyi-format.md) for
19-
editable wrapper contracts.
18+
contract. The Semantic .pyi Format reference gives the complete editable
19+
wrapper contract syntax.
2020

2121
## Choose A Recipe
2222

@@ -65,6 +65,6 @@ X2PY_C_DOCS_END -->
6565

6666
- [Basic wrapper tutorial](../tutorials/basic-wrapper.md)
6767
- [Fortran wrapper guide](../guide/fortran-wrapper.md)
68-
- [Semantic .pyi Format](../reference/semantic-pyi-format.md)
69-
- [Semantic IR Reference](../reference/semantic-ir.md)
70-
- [Diagnostic Codes](../reference/diagnostic-codes.md)
68+
- Semantic .pyi Format
69+
- Semantic IR Reference
70+
- Diagnostic Codes

0 commit comments

Comments
 (0)