feat(pbs): align typed values and Pad input facade
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
# PBS input and existing value runtime alignment
|
||||
|
||||
Status: normative. Owner: `compiler/pbs`. Common ABI authority:
|
||||
[typed Registry/PBX](../../general/specs/typed-registry-and-pbx-v0.md) and
|
||||
[runtime catalogs](../../general/specs/runtime-catalog-support.md).
|
||||
|
||||
## Source types and exact carriers
|
||||
|
||||
| PBS source | Runtime identity | Ordered slots |
|
||||
| --- | --- | --- |
|
||||
| `int` | Int32 | Int32 |
|
||||
| `long` | Int64 | Int64 |
|
||||
| `float` | Float | Float (binary64) |
|
||||
| `bool` | Bool | Bool |
|
||||
| `str` | String | String |
|
||||
| builtin `color` shell | color | Int64 constrained to RGBA8888 |
|
||||
| builtin `vec2` shell | vec2 | Float x, Float y |
|
||||
| builtin `pixel` shell | pixel | Int64 x, Int64 y, Int64 color |
|
||||
|
||||
The canonical builtin metadata determines a shell's identity; its source name
|
||||
is not an ABI lookup rule. Equal widths do not permit substitution. Function
|
||||
metadata MUST declare ordered parameter and result identities. Slot counts are
|
||||
checked caches derived from those identities. Calls, locals and returns MUST
|
||||
preserve entire value groups. A vec2 is one logical value with two slots;
|
||||
a named output tuple is a fixed sequence of logical results, not a heap object.
|
||||
|
||||
`int` and `long` are distinct. Integer literals default to `int`; explicit
|
||||
`long` contexts (annotations, parameters and results) validate literals in the
|
||||
Int64 range and materialize them with that carrier. Out-of-range literals MUST
|
||||
be diagnosed, never replaced by zero. A typed variable does not change type
|
||||
because it appears in another expected context. Mixed int/long operations
|
||||
require an explicit conversion. Existing `as` syntax expresses conversion:
|
||||
|
||||
```pbs
|
||||
let frames: long = 2147483648;
|
||||
let offset: int = 10;
|
||||
let wide = offset as long;
|
||||
let narrow = frames as int;
|
||||
```
|
||||
|
||||
The final conversion faults if its value is outside Int32 range. Numeric
|
||||
conversions use published math/mathf conversion intrinsics, without adding
|
||||
math service facades. Int32/Int64 arithmetic preserves runtime wrapping;
|
||||
Float overflow and range-invalid conversions preserve runtime faults.
|
||||
Defaults are owned by the runtime storage contract: numeric zero, Float +0,
|
||||
Bool false, nullable String null, transparent color, zero vec2 and zero pixel.
|
||||
This does not introduce implicit source-variable initialization: VM locals
|
||||
start null and PBS definite-assignment rules still apply. NaN/infinity are not
|
||||
valid guest numeric defaults.
|
||||
|
||||
## Public input API
|
||||
|
||||
Import `Pad`, `Button` and `Touch` from `@sdk:input`. Button is a closed nominal
|
||||
PBS enum with cases Up, Down, Left, Right, A, B, X, Y, L, R, Start and Select.
|
||||
It identifies a button; it does not contain input state or perform a query.
|
||||
Locals and typed function parameters may carry Button values, including values
|
||||
selected during execution. Strings, integer indices and unrelated enums are
|
||||
not valid Button arguments.
|
||||
|
||||
| Public operation | Result |
|
||||
| --- | --- |
|
||||
| `Pad.pressed(button: Button)` | bool |
|
||||
| `Pad.released(button: Button)` | bool |
|
||||
| `Pad.down(button: Button)` | bool |
|
||||
| `Pad.hold(button: Button)` | long, held logical frames |
|
||||
| `Touch.pressed()`, `Touch.released()`, `Touch.down()` | bool |
|
||||
| `Touch.hold()` | long, held logical frames |
|
||||
| `Touch.x()`, `Touch.y()` | long |
|
||||
|
||||
```pbs
|
||||
import { Pad, Button, Touch } from @sdk:input;
|
||||
|
||||
fn jump(button: Button) -> bool {
|
||||
return Pad.pressed(button);
|
||||
}
|
||||
|
||||
fn held() -> long {
|
||||
let jump_button = Button.A;
|
||||
return Pad.hold(jump_button);
|
||||
}
|
||||
```
|
||||
|
||||
Pad dispatches to `LowPad.<button>_<query>()`, for example
|
||||
`LowPad.a_pressed()`. All 48 combinations map to the published direct endpoint.
|
||||
Each call MUST evaluate its selector once and execute exactly one chosen
|
||||
query. It MUST NOT read unselected buttons, speculate input faults or collect
|
||||
all button states. Constant specialization is optional; dynamic dispatch must
|
||||
work without optimization.
|
||||
|
||||
All 54 VM queries take zero arguments and no receiver. Button never crosses
|
||||
the intrinsic boundary as a selector. Touch x/y use current IDs 0x2134/0x2135
|
||||
and Int64 results. No new device, button-state object, snapshot or multi-pad
|
||||
contract is introduced. Known input without an available platform faults with
|
||||
TRAP_UNAVAILABLE; it never fabricates false or zero. Unknown and retired IDs
|
||||
are invalid even in unreachable code.
|
||||
|
||||
## Migration and diagnostics
|
||||
|
||||
The old Input root and intermediate InputPad/InputTouch/InputButton objects
|
||||
are removed. Replace `Input.pad().a().pressed()` with
|
||||
`Pad.pressed(Button.A)` and `Input.touch().x()` with `Touch.x()`.
|
||||
`let button = Input.pad().a();` is invalid; `let button = Button.A;` is valid.
|
||||
Migration diagnostics must point to the replacement surface. Hover, completion,
|
||||
exports and examples must advertise the same API and exact return types.
|
||||
When a consumer requires int coordinates, explicitly narrow a Touch result
|
||||
with `as int`; do not silently change the query's ABI.
|
||||
|
||||
## Lowering and observable order
|
||||
|
||||
PBS owns source enum dispatch and typed metadata. Common code owns catalog
|
||||
resolution, PBX validation and emission. The frontend MUST NOT maintain a
|
||||
second intrinsic or constant catalog. SDK executable methods admit the existing
|
||||
switch expression with value arms, apply and explicit numeric conversions
|
||||
needed by this facade; other unsupported SDK constructs remain diagnosed.
|
||||
|
||||
For named application such as `f apply (y: effect_y(), x: effect_x())`, evaluate
|
||||
Y then X exactly once, store complete groups in temporary locals, and reload
|
||||
in x,y parameter order. Reordering expressions instead of values is invalid.
|
||||
|
||||
Builtin constants are groups resolved by the shared constant catalog.
|
||||
`vec2.zero` materializes two Float slots; no intrinsic endpoint is invented.
|
||||
Colors may use a published constant or an independently published intrinsic.
|
||||
Function metadata must cover SDK wrappers such as Gfx.clear. Validation must
|
||||
not infer missing identities from widths or omit the full installed example.
|
||||
Preserve the existing lifecycle assembly and physical boot FunctionId zero.
|
||||
|
||||
## Conformance
|
||||
|
||||
The PBS source-to-production-PBX corpus and production runtime harness must
|
||||
cover all 54 input queries with controlled input and exactly-one-query checks,
|
||||
known-unavailable behavior, typed selectors, int/long boundaries and explicit
|
||||
conversions, Float/String/Bool, color/vec2/pixel groups, multiple returns and
|
||||
named-argument effects. Keep common registry wrong-carrier, retired-ID and stale
|
||||
signature tests active. Record runtime hash, Studio revision, platform and
|
||||
configuration. A catalog-only pass does not replace successful PBS execution
|
||||
or `:prometeu-app:installedKnowledgeTest`.
|
||||
Reference in New Issue
Block a user