feat(pbs): align typed values and Pad input facade
This commit is contained in:
@@ -93,3 +93,14 @@ installed-runtime qualification remain separate consumer claims.
|
||||
See [typed common Registry and PBX v0](typed-registry-and-pbx-v0.md) for the
|
||||
frontend/backend boundary and [mirror policy](../../../vm-arch/README.md) for
|
||||
explicit verification commands.
|
||||
|
||||
|
||||
## PBS consumer
|
||||
|
||||
The [PBS input and value alignment contract](../../pbs/specs/input-and-existing-type-runtime-alignment.md)
|
||||
requires typed Pad/Button dispatch, direct LowPad endpoints and complete builtin
|
||||
value groups. Frontend numeric literal and builtin-constant operations retain
|
||||
explicit identity and width; common lowering resolves constant groups against
|
||||
`IRVMBuiltinConstantDefinition` and checks the declared result width. PBS does
|
||||
not introduce another catalog. Source execution and the full installed example
|
||||
are separate consumer gates beyond CSV parity.
|
||||
|
||||
@@ -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`.
|
||||
@@ -296,3 +296,7 @@ This document is ready to move beyond temporary status only when:
|
||||
2. diagnostic identity, metadata, and attribution rules are explicit enough for conformance, including locale-agnostic token/template identity,
|
||||
3. the backend-originated failure boundary is explicit enough that PBS-facing diagnostics can be distinguished from internal tool failures,
|
||||
4. and cost/warning expectations are explicit where they are intended to be normative for v1.
|
||||
|
||||
## Existing values and input runtime alignment
|
||||
|
||||
The [PBS input and value alignment contract](../../../compiler/pbs/specs/input-and-existing-type-runtime-alignment.md) governs int/Int32, long/Int64, exact builtin carriers, the Pad/Button/LowPad and Touch API, named-argument evaluation order, migration diagnostics and executable conformance. It supersedes older input-object and untyped executable-lowering descriptions.
|
||||
|
||||
@@ -238,3 +238,7 @@ At frontend `IRBackend` emission time:
|
||||
4. module order in the declaration MUST propagate the explicit dependency order already derived from resolved project/module data, without sorting by `FileId`, textual module name, or synthetic callable name,
|
||||
5. PBS MUST NOT emit module init, project-init wrapper, published frame wrapper, physical entrypoint, or boot guard,
|
||||
6. and common lifecycle assembly remains the owner of derived artifacts, including the published wrapper that becomes the physical entrypoint and owns the final frame return.
|
||||
|
||||
## Existing values and input runtime alignment
|
||||
|
||||
The [PBS input and value alignment contract](../../../compiler/pbs/specs/input-and-existing-type-runtime-alignment.md) governs int/Int32, long/Int64, exact builtin carriers, the Pad/Button/LowPad and Touch API, named-argument evaluation order, migration diagnostics and executable conformance. It supersedes older input-object and untyped executable-lowering descriptions.
|
||||
|
||||
@@ -48,7 +48,7 @@ Rules:
|
||||
- `declare host` declarations are reserved to SDK/toolchain-controlled modules and are not formable in ordinary user-authored PBS source.
|
||||
- `declare builtin type` declarations are reserved to SDK/toolchain-controlled modules and are not formable in ordinary user-authored PBS source.
|
||||
- A host owner name is not an ordinary value expression in v1 core; it is used only as a qualified host-call owner.
|
||||
- The builtin simple types `int`, `float`, `bool`, and `str` are always present in the type namespace.
|
||||
- The builtin simple types `int`, `long`, `float`, `bool`, and `str` are always present in the type namespace.
|
||||
- Builtin simple types are resolved without import or declaration.
|
||||
- User-authored type declarations must not reuse builtin simple type names.
|
||||
|
||||
@@ -874,3 +874,7 @@ At minimum, deterministic static diagnostics are required for:
|
||||
- invalid optional intrinsic member call,
|
||||
- invalid builtin intrinsic member call,
|
||||
- member projection on a missing named output label.
|
||||
|
||||
## Existing values and input runtime alignment
|
||||
|
||||
The [PBS input and value alignment contract](../../../compiler/pbs/specs/input-and-existing-type-runtime-alignment.md) governs int/Int32, long/Int64, exact builtin carriers, the Pad/Button/LowPad and Touch API, named-argument evaluation order, migration diagnostics and executable conformance. It supersedes older input-object and untyped executable-lowering descriptions.
|
||||
|
||||
+9
-5
@@ -263,13 +263,13 @@ Example:
|
||||
```pbs
|
||||
[BuiltinType(name="color", version=1)]
|
||||
declare builtin type Color(
|
||||
pub raw: int,
|
||||
pub raw: long,
|
||||
);
|
||||
|
||||
[BuiltinType(name="pixel", version=1)]
|
||||
declare builtin type Pixel(
|
||||
pub x: int,
|
||||
pub y: int,
|
||||
pub x: long,
|
||||
pub y: long,
|
||||
pub color: Color,
|
||||
);
|
||||
```
|
||||
@@ -277,13 +277,13 @@ declare builtin type Pixel(
|
||||
Canonical semantic layout:
|
||||
|
||||
```text
|
||||
Pixel -> [int, int, Color]
|
||||
Pixel -> [long, long, Color]
|
||||
```
|
||||
|
||||
Canonical flattened slot layout:
|
||||
|
||||
```text
|
||||
Pixel -> [int, int, int]
|
||||
Pixel -> [long, long, long]
|
||||
```
|
||||
|
||||
## 13. Member Categories
|
||||
@@ -560,3 +560,7 @@ The current temporary contract is:
|
||||
7. `BuiltinConst(target, name, version)` exposes VM-owned builtin constants through reserved top-level `declare const` shells.
|
||||
8. Builtin projections, constants, and intrinsic calls must not lower through `SYSC`, `HOSTCALL`, or `SYSCALL`.
|
||||
9. Runtime-facing intrinsic artifacts are distinct from host-binding artifacts.
|
||||
|
||||
## Existing values and input runtime alignment
|
||||
|
||||
The [PBS input and value alignment contract](../../../compiler/pbs/specs/input-and-existing-type-runtime-alignment.md) governs int/Int32, long/Int64, exact builtin carriers, the Pad/Button/LowPad and Touch API, named-argument evaluation order, migration diagnostics and executable conformance. It supersedes older input-object and untyped executable-lowering descriptions.
|
||||
|
||||
@@ -387,3 +387,7 @@ This document is ready to move beyond temporary draft status only when:
|
||||
3. host-call interaction rules are stated without relying on informal prose elsewhere,
|
||||
4. the document can drive runtime conformance tests without decision backfill,
|
||||
5. the remaining TODO items are reduced to editorial integration rather than semantic uncertainty.
|
||||
|
||||
## Existing values and input runtime alignment
|
||||
|
||||
The [PBS input and value alignment contract](../../../compiler/pbs/specs/input-and-existing-type-runtime-alignment.md) governs int/Int32, long/Int64, exact builtin carriers, the Pad/Button/LowPad and Touch API, named-argument evaluation order, migration diagnostics and executable conformance. It supersedes older input-object and untyped executable-lowering descriptions.
|
||||
|
||||
@@ -559,8 +559,8 @@ are also checked. Rebuilding changes pixels/build identity and visibly marks the
|
||||
old capture stale. Images remain in memory; window screenshots are not evidence.
|
||||
|
||||
The fixture uses supported project-source LSP definition/symbol navigation and
|
||||
indexed SDK reads. A probe of the installed SDK's `Input.pad()` definition returns
|
||||
an empty result with the current language service; the gate does not claim SDK
|
||||
indexed SDK reads. The historical probe of the former SDK `Input.pad()` definition returned
|
||||
an empty result (the current facade is Pad/Button and Touch); the gate does not claim SDK
|
||||
symbol navigation where no location is returned. This is a language tooling
|
||||
limitation, not a headless or MCP execution fallback.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user