Skip to content

Commit 191bca9

Browse files
zrr1999Copilot
andcommitted
✨ feat(platform): add startup contract module
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6223c44 commit 191bca9

4 files changed

Lines changed: 38 additions & 3 deletions

File tree

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ This repository currently keeps `examples/` limited to files that PR CI validate
5050
basic-cli/
5151
├── spore.toml # Platform manifest
5252
├── src/
53-
│ ├── host.sp # Default platform entry point
53+
│ ├── host.sp # Compatibility runtime entry point
54+
│ ├── platform_contract.sp
5455
│ └── basic_cli/ # Spore API modules, checked and built in CI
5556
│ ├── stdout.sp # Standard output operations
5657
│ ├── stdin.sp # Standard input operations
@@ -65,10 +66,24 @@ basic-cli/
6566
└── examples/ # Canonical examples that format/check/build in CI
6667
```
6768

69+
## Contract Surface (MVP)
70+
71+
The current Platform contract MVP is intentionally split across two artifacts:
72+
73+
1. `spore.toml` `[platform]` metadata names the contract module, the startup contract symbol, the adapter function, and the handled capabilities.
74+
2. `src/platform_contract.sp` owns the startup contract itself:
75+
- a hole-backed `main` function carries the authoritative startup signature
76+
- `main_for_host` is the Platform-owned adapter that receives the application startup function
77+
78+
Applications targeting `basic-cli` must implement the same startup function name/signature in their entry module. When the compiler starts reading Platform contracts from packages, `spec` items attached to the Platform contract and the application implementation will both have to hold.
79+
80+
`src/host.sp` remains as a compatibility copy of the adapter while the compiler still hardcodes platform startup behavior.
81+
6882
## Tutorial Contract
6983

7084
- `examples/` is for truthful, CI-validated examples only.
7185
- `src/basic_cli/` is the API surface for the platform modules themselves.
86+
- `src/platform_contract.sp` is the package-owned startup contract surface.
7287
- Only add `tests/` when the repo has real Spore-side regression coverage worth running with `spore test`.
7388

7489
If you want to add a new tutorial/example, treat this as the bar:

spore.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ version = "0.1.0"
44
type = "platform"
55
spore-version = ">=0.1.0"
66

7+
[platform]
8+
contract-module = "platform_contract"
9+
startup-contract = "main"
10+
adapter-function = "main_for_host"
11+
handles = ["Console", "FileRead", "FileWrite", "Env", "Spawn"]
12+
713
[capabilities]
814
allow = ["Compute"]
915

src/host.sp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/// Platform startup adapter.
2-
/// This is where the platform sets up effect handlers before calling the application startup function.
1+
/// Compatibility startup adapter.
2+
/// Keep this entry in sync with `platform_contract.sp` until the compiler reads
3+
/// `[platform].contract-module` directly.
34
pub fn main_for_host(app_main: () -> ()) -> () {
45
app_main()
56
return

src/platform_contract.sp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// Platform contract module for `basic-cli`.
2+
/// Applications targeting this Platform must implement the same `main`
3+
/// signature in their entry module. Any `spec` items attached here will stack
4+
/// with the application's own `main` spec and both must hold.
5+
pub fn main() -> () {
6+
?platform_startup_contract
7+
}
8+
9+
/// Platform-owned startup adapter.
10+
pub fn main_for_host(app_main: () -> ()) -> () {
11+
app_main()
12+
return
13+
}

0 commit comments

Comments
 (0)