refactor: organize host modules and document architecture with UML
Verify Tessera GUI / verify (push) Failing after 2m2s
Verify Tessera GUI / verify (push) Failing after 2m2s
This commit is contained in:
+84
-264
@@ -1,266 +1,86 @@
|
||||
# Tessera source
|
||||
# Tessera 源码导航
|
||||
|
||||
| Module | Responsibility |
|
||||
整体设计和当前进展从 [架构导览](../docs/architecture/README.md) 开始;本轮每个文件的迁移对应见 [逐文件清单](../docs/architecture/file-map.md)。
|
||||
|
||||
`main.rs` 只负责组合启动,并保留 crate 私有模块路径别名。五组目录仍在同一个 binary crate 中,不是严格单向分层。
|
||||
|
||||
| 目录 | 责任 |
|
||||
| --- | --- |
|
||||
| main.rs | Native window event loop, namespace state and API startup |
|
||||
| api.rs | Code CRUD, live Console/reset and compatibility evaluation endpoints, worker-owned session, request observation, coalesced native viewport/background-task updates, epoch checks, stale source/destination tab-drop rejection and diagnostics |
|
||||
| activity.rs | Bounded in-memory HTTP exchanges with marked previews and allowlisted request headers |
|
||||
| endor_host.rs | Aster compilation, fresh PUT candidates retained after successful publication, shared Console/program VM, asynchronous completion/fault boundaries, bounded execution, compiled source/call-graph effect query and rebinding coverage, root cleanup and AST developer tree for function/class/member assignment nodes |
|
||||
| endor_script.rs | Batch complete inputs for Aster's Interactive parser/compiler, retain Module entry, and rebase Aster spans to the original snapshot |
|
||||
| ui_bridge.rs | Inheritable native nominal constructors with source fields, shared type method tables and bound receiver dispatch, configured unified Function classification and source/field/override checks with deferred typed public/native constructor signatures and split option/field preflight plus shared native arity intervals plus resolved types/unions/effects on methods, tab registry, stable-slot insertion, source-dispatched tab reorder/drop and callback registration checks, Page lifecycle/navigation, Event returns/effect bounds, intrinsic handler recognition and immutable frame extraction |
|
||||
| binding.rs | Target-owned managed property bindings, weak Subscription tokens, zero-argument callback preflight, read-only compute and borrowed dependency/output caches |
|
||||
| block.rs | Aster-managed Block/Cell/data graph, stable child slots, content-owned field storage, shared assignment, cycle validation and explicit text bindings |
|
||||
| snapshot.rs | Property and visual-method identity dependencies across shared field-storage paths, typed method attribute validity and protocol function payload-version dependencies, reverse parent links and cached immutable visual derivation |
|
||||
| mount.rs | Typed per-occurrence methods and nominal Bounds results, managed contexts, weak reverse links, ordered mount/unmount hooks, geometry and focus queries |
|
||||
| events.rs | Bounded native input transport with kind-specific tab-drop/desktop-position metadata to the owning VM |
|
||||
| event_dispatch.rs | Typed Event factory and managed Event/Subscription methods, weak Subscription tokens, Block-owned connections and occurrence-specific capture/target/bubble through a budgeted VM driver |
|
||||
| protocols.rs | Register typed Visual/EventTarget/Children (including insert)/Presentable managed trait requirements, using canonical signatures and explicit native type declarations |
|
||||
| presentation.rs | Per-window layout, Mount/focus/tab state and read dependencies; VM changes fan out before any view consumes work |
|
||||
| io_tasks.rs | Lazy bounded file-provider pool, plain-data mailbox and cancellation leases without managed roots |
|
||||
| tasks.rs | Typed Task/ui.after/ui.readText/ui.fetchText/result/error methods, managed owner scopes and callbacks, weak timer index, request-key replacement, lifecycle cancellation and budgeted worker delivery |
|
||||
| tabs.rs | Immutable tab chrome, shared draw/hit geometry, overflow navigation, drag gaps/anchors/insertion markers and opaque published Page identities |
|
||||
| window.rs | Typed native Window queries/effects, construction/close, context ownership, ordered Page roots, read-only guards, Page reordering, physical desktop placement and coalesced GUI projections |
|
||||
| vm_sequence.rs | Shared validated call-sequence builder and EXTENDED_ARG-aware same-frame repetition for layout, event and lifecycle work |
|
||||
| source_layout.rs | Read-only source layout, repeated constraint/geometry solving with cycle detection, per-Mount measurement caches with subcall dependencies and actual scroll-viewport cross-axis constraints, viewport constraints, typed/slot validation, concrete intrinsic recognition and occurrence geometry |
|
||||
| source_hit.rs | Read-only source/native pointer target selectors, reverse paint order, strict Bool results and matching press/release targets |
|
||||
| source_paint.rs | Read-only source paint dispatch with concrete intrinsic recognition, shared VM budget, paired text-wrap bounds and checked command conversion and versioned object dependencies |
|
||||
| native_visual.rs | Managed native visual protocol queries with resolved type/read-only signatures, occurrence validation, concrete implementation/operation identity, arranged-viewport child constraints, value conversion and bounded results |
|
||||
| object_list.rs | Typed factory envelopes, read-only indexed access and traced results shared by Mount queries and visual protocol results |
|
||||
| layout.rs | Shared native geometry/paint functions, iterative measurement/arrangement, stable occurrence IDs, measurement cache, solve-pass counters, geometry budgets and width-sensitive native text measurement |
|
||||
| document.rs | Published source/AST/UI snapshot, revisions, invalidation, frame validation, single-line fault banner (full cause retained in Frame), validated optional text-wrap bounds and display commands |
|
||||
| app.rs | Window events, logical viewport publication, redraw, native multi-window tab dragging and system widget pointer/keyboard/IME routing |
|
||||
| clipboard.rs | UTF-8 macOS clipboard adapter independent of Finder locale, with strict decoding and surfaced errors |
|
||||
| system_ui/ | Host-only management widget library: stable IDs, interaction, theme and reusable control drawing |
|
||||
| scroll.rs | Per-Mount offsets, nested scrollIntoView, shared geometry/clip projection and wheel ancestor selection |
|
||||
| scene.rs | Page, tab-drop marker and developer-tools display-list composition |
|
||||
| developer_tools.rs | Unified Console prompt/output stream, caret/IME mapping, full Sources, Network inspector, theme, scrolling, overlay splitters and focus |
|
||||
| sources.rs | Disconnected cloud workspace and provider boundary for listing/opening complete source files |
|
||||
| display_list.rs | Rendering primitives, bounded wrapped text and color representation |
|
||||
| geometry.rs | Native points and rectangles |
|
||||
| software_renderer.rs | Software rasterization, per-text bounds and nested rectangular clipping for independently scrolling panes |
|
||||
| text.rs | Shared system font discovery, shaping, real measurements, antialiased glyphs and bounded caches keyed by wrap width |
|
||||
| README.md | Module map |
|
||||
|
||||
Aster is an independent source submodule pinned to the published managed type/native-call implementation. Language parsing, AST definitions,
|
||||
compilation, bytecode and VM execution come from its libraries. Tessera implements
|
||||
only host UI behavior and layout. No CLI, HTTP server or Docker process is needed
|
||||
to execute Endor in the application.
|
||||
|
||||
A complete-PUT candidate owns the desktop and UI service roots, with dynamic
|
||||
Block allocation through scoped NativeContext. Block -> Cell -> data and all
|
||||
child/history/forwarding references are managed VM edges. Native functions declare
|
||||
their captured owner edges. The bridge holds only weak diagnostic references to
|
||||
allocated Blocks; the tab registry owns open Pages. Closing a tab releases that
|
||||
edge, without destroying a still-referenced Page. Console retains the actual VM;
|
||||
a successful complete PUT also retains its candidate as the active program, accessible from Console and native input. Failed PUT preserves the previous heap. Cleanup releases
|
||||
globals/service roots, collects cycles and requires an empty VM. Window frames
|
||||
contain only immutable native data.
|
||||
|
||||
Tests in api/tests.rs execute real HTTP CRUD, persistent Console/reset/PUT isolation and a controlled queued-PUT/DELETE race
|
||||
without opening a window. Tests in endor_host/tests.rs cover lifecycle, direct script and
|
||||
module entry, page methods, stable-slot insertion and tab drop/override/stale-target behavior, multiline inputs, original source ranges, malformed input,
|
||||
owner/task cancellation, hidden-object delivery, stale request and callback failure, entry checks, source function/declared-field annotation checks, constructor side-effect prevention, native callback signature/pre-registration validation, shared field forwarding/function identity and REPL class redefinition, budgets, failure preservation, live object identity, explicit rendering,
|
||||
compile-before-execute behavior and stale-result invalidation. They
|
||||
run only in remote CI. Font tests in text.rs and software_renderer.rs cover real
|
||||
advances, multiline height, fractional scaling, CJK fallback, grapheme-safe fitting,
|
||||
antialiasing and transparency. A process-wide mutex keeps font discovery, shaping
|
||||
and glyph caches shared between the worker's layout and window redraw. The
|
||||
256-string/512-KiB source cache and 4096-glyph/32-MiB image cache are discarded
|
||||
when their budgets are exceeded. See the [project guide](../README.md) for public behavior.
|
||||
|
||||
The expression endpoint deliberately uses Aster's Expression entry in a fresh VM;
|
||||
it has no host UI, no history replay and no published document. API observation
|
||||
notifies the window for accepted and completed requests, including failures. The
|
||||
worker still owns source compilation and snapshot publication. Console sends real
|
||||
loopback HTTP requests on a separate client thread and reports transport failures
|
||||
through the native event loop. CloudSourceProvider is an optional host-side adapter,
|
||||
not a cloud service. A future network adapter should deliver cached/asynchronous
|
||||
results to the workspace rather than block the native event loop during I/O.
|
||||
|
||||
The [System UI library](system_ui/README.md) owns management control appearance and
|
||||
interaction. It imports no Endor runtime or guest UI bridge; developer tools supply
|
||||
typed actions and keep all execution/source behavior outside the widget layer.
|
||||
|
||||
Console sessions use `endor_host::ReplSession` on the same worker thread. Real VM
|
||||
globals, live Blocks and `_` survive between inputs. Parse/compile precede execution;
|
||||
only a successful input commits a pending mount or publishes changes to an existing mount.
|
||||
Runtime-failed input can retain earlier completed bindings, but cannot publish its
|
||||
pending render. Session budgets cover cumulative source/AST and live Block counts.
|
||||
page.unmount releases current content; unreachable object cycles are reclaimed between inputs.
|
||||
Explicit reset drops the VM. Successful PUT replaces it with the fresh program; failed PUT restores the displayed program’s event epoch. Code DELETE invalidates the context. Source snapshots carry annotated AST ranges for the
|
||||
actual Console transcript; source history is never rerun to reconstruct memory.
|
||||
The Aster pin includes independent Assignment syntax and generic opt-in assign_from support.
|
||||
Live reference tests cover alias updates, nested mounts, cycle rejection, detached branch release and unmount/remount.
|
||||
|
||||
Stopped runtimes have a separate host-only secondary-window teardown path. It detaches
|
||||
Mounts and releases window/Page roots without executing source lifecycle callbacks,
|
||||
and does not resume the failed VM. Preserved old-generation pictures can be closed
|
||||
without borrowing a new Console VM's same-number resource. Secondary viewport inputs
|
||||
are filtered by their published runtime generation. Native window/surface failures
|
||||
are returned to the host diagnostics rather than panicking the event loop; main
|
||||
window initialization errors propagate to process exit. The stopped-window and
|
||||
cross-generation regression sources are compiled, not locally executed.
|
||||
|
||||
Native visual scalar parameters live in the Block's managed property storage.
|
||||
Snapshot extraction validates and reads those fields, and records exact property
|
||||
invalidation keys. Payload kind values remain constructor defaults; drawing uses
|
||||
the property projection. Binding refresh traverses the weak visual registry and
|
||||
deduplicates forwarded content, including hidden objects. It records object-level
|
||||
read versions and borrowed output values for equality without adding GC roots;
|
||||
cache updates do not mutate the connection's business version. Target content
|
||||
traces the compute function. Subscription tokens are weak and also support bindings.
|
||||
All binding work settles before published frames; compute failure stops the VM.
|
||||
|
||||
The host registers Trait definitions through Aster's checked nominal capability
|
||||
API. Source subclasses validate inherited method arity before class publication.
|
||||
Presentable dispatch uses a generated validated bytecode continuation inside the
|
||||
current call budget, passes the current managed Window, and validates a real
|
||||
Block result before opening it. Native base visual methods and runtime result
|
||||
checks remain the rendering boundary. Matching present names without an explicit
|
||||
implementation keep the summary fallback and do not execute guest methods.
|
||||
|
||||
ScrollBlock keeps viewport dimensions in the managed Block properties and keeps
|
||||
scroll offsets on Mounts. Layout measures content without a finite viewport bound;
|
||||
a post-layout projection clamps offsets, translates descendants and intersects
|
||||
ancestor clips before committing Mount geometry. It rebuilds native commands and
|
||||
per-command clips; source painting preserves the same clip table. Input, focus
|
||||
outlines and public hit queries consume this projection. Wheel transport carries
|
||||
finite signed deltas, validates the frame/window/session, and invokes the actual
|
||||
Mount.scrollBy method without changing guest focus. Mount requests mark a
|
||||
per-window projection refresh; snapshots/caches never own business objects.
|
||||
|
||||
Tab drops validate source and destination window/session/layout plus the actual VM Page order before callbacks. The bridge invokes managed Page methods, respecting source overrides that decline or redirect a window move. Reordering within a window retains Mounts; moving windows retains Page identity and replaces Mounts. Native drag feedback is host state, with no additional managed roots. Desktop placement is an asynchronous physical outer-origin request, protected by the existing session/commit boundary. Regression sources cover the HTTP event allowlist, stale frame reuse, stable insertion, source overrides and signed positions; these were compiled, not locally executed.
|
||||
|
||||
NativeCallable implementations publish positional metadata, including internal layout/paint/hit/event continuations. The VM validates it before entering Rust. Event delivery uses the same source/native/bound arity query; binding and Task registration reject incompatible or unknown metadata before changing ownership. Native parameter/return types and effects remain checked by existing host boundaries rather than this count-only metadata.
|
||||
|
||||
Native TextBlock measurement and painting now share width-sensitive shaping. Column/Button cross-axis constraints feed both the native fast path and source base calls; direct base measurement also uses its supplied viewport. RenderCommand text has optional wrap_bounds, converted to a clipped WrappedText primitive. Source PaintCommand uses paired wrapWidth/wrapHeight and legacy text remains unwrapped when both are absent. Source-arranged dimensions now participate in repeated constraint solving; general flex allocation, resumable work and axis-specific ScrollBlock wrapping remain future work.
|
||||
|
||||
Layout convergence uses exact finite snapshots of constraints/sizes/bounds and source-selected limits. The same immutable driver loops within one shared VM budget, clears all provisional measurement geometry between passes and rejects nonconsecutive repeated states. Aster ReadAccess distinguishes annotation validation from normal reads; the bridge skips only validation-only Mount reads after independently validating the live Mount/owner context. Actual Mount reads remain volatile; all other recorded dependencies are retained.
|
||||
|
||||
ScrollBlock.axis is stored in its managed properties and projected into the visual snapshot. Axis-aware child constraints use constructor/clamped size for initial measurement and actual occurrence bounds after arrangement. Scroll projection clamps disabled offsets/limits; the same geometry feeds paint and input.
|
||||
|
||||
Container mainAlign projects from managed properties into UiNode and its shallow equality. Native arrangement receives the actual allocated Size, computes positive remaining main-axis space and keeps child sizes unchanged.
|
||||
|
||||
Block.flex is a nonnegative managed weight, default 0. In native containers, fixed children retain measured main-axis sizes; positive weights share the remaining allocated space after padding/gaps with zero basis. This does not request extra parent size. Actual allocated child bounds feed back into measurement before publication. Source arrangement overrides remain authoritative. The additional flexBasis, flexMin, flexMax and flexShrink attributes control bounded allocation and opt-in shrinking along the parent main axis; see the policy below.
|
||||
|
||||
Trees with positive flex weights use the settling driver even when all layout methods are native. This remeasures wrapping and ancestor geometry before publishing. Fast-path eligibility checks actual intrinsic implementations, rather than comparing against a mutable Block method table.
|
||||
|
||||
|
||||
Flex main-axis policy: flexBasis is "auto" by default (zero basis when flex > 0, otherwise the first measured size of this occurrence in the current solve); a number supplies an explicit basis. flexMin defaults to 0, flexMax to 1000000, and flexShrink to 0. All numbers are finite/nonnegative and at most 1000000; flexMin must not exceed flexMax. The parent clamps bases to min/max, distributes positive space by flex, and redistributes space left after a maximum is reached. Deficits shrink by flexShrink times the original basis, freezing at minima. A fixed child can opt into shrink without growth. Unresolvable minimum overflow is preserved, and remaining positive space follows mainAlign. The policy applies to width in a Row and height in Column-like containers; these are not independent width/height bounds. Source arrange overrides remain authoritative. Preferred sizes are derived per occurrence and reset for each new solve, never shared through Block state. See examples/flex-constraints.endor. Layout continuation remains unfinished.
|
||||
|
||||
|
||||
When an occurrence's cross-axis constraint changes during settling, its preferred main-axis size is invalidated and remeasured. Any obsolete native flex allocation on that axis is removed for the replacement measurement, so narrowing a nested Column can increase wrapped text height. Source arrange allocations remain explicit. Preferred-size presence and values participate in convergence/cycle detection.
|
||||
|
||||
|
||||
The source layout driver now uses Aster's resumable read-only call API with a soft quantum of 256 instructions. Pauses retain the same VM frames, operand/local roots, return contracts and read tracking; total instruction/frame limits still apply across slices. ui.stats().layoutSlices counts slices in the most recent solve (native fast path: 1). The worker currently resumes Pending immediately after yielding its OS time slice. Parking the solve across worker turns, scheduling other work and handling newer inputs before completion are not implemented yet. Native callbacks are not preempted. Only the completed settled frame is published.
|
||||
|
||||
|
||||
source_layout::start now returns either Complete(Draft) or Pending(Work). The host-owned Work retains the unpublished frame, derived runtime/cache snapshots, convergence plan and prepare root without borrowing caller frame/cache variables. Work::resume consumes the saved job and advances the same VM continuation; Work::cancel closes that continuation and releases the prepare root without merging a draft. A second start is rejected while any read-only execution is active. Every pending Work must be resumed or explicitly cancelled with its owning VM; dropping it is not cancellation. Synchronous ReplSession operations drain the same saved refresh state. Mount preparation/lifecycle cancellation and parking jobs in the execution worker remain unfinished.
|
||||
|
||||
|
||||
UiBridge::begin_layout_frame/resume_layout_frame now expose PendingLayout around the source job. This bridge-level continuation also owns its target window, page snapshot, tab projection, viewport restoration and retained lifecycle hook root. Only the Complete branch projects scroll/focus, captures dependency versions, merges derived caches, commits Mount geometry and runs deferred hooks. Resume restores the saved window context, and failure releases hook roots. ReplSession uses this protocol through its saved refresh state. Viewport refresh supports cross-worker-turn scheduling and prepared-Mount rollback; callers must not drop a pending bridge layout as a substitute for cancellation.
|
||||
|
||||
|
||||
ReplSession now owns a resumable RefreshWork containing window traversal, pending bridge layout, unpublished per-window documents and the cumulative refresh work budget. poll_refresh advances one refresh stage or VM quantum; only a complete stable pass replaces the session's full document map. Synchronous callers drain the same state machine. Failure stops the domain, releases any pending bridge work and preserves the externally published picture. refreshYields counts cooperative refresh returns, not wall-clock time. Only still-pending Mount preparation is rolled back; completed callbacks remain committed.
|
||||
|
||||
|
||||
Viewport refresh now advances through ReplSession's saved refresh state on worker idle turns. A turn advances one traversal stage or a 256-instruction layout quantum; ready layout/paint or coroutine work checks the request queue without a timed wait and yields to other ready OS threads between turns. An accepted pending input/candidate also yields without adding a fixed millisecond delay per VM quantum; control, epoch and viewport checks still run on every turn. When only external completion/timers are pending, the normal idle wait remains 100 ms. Tasks/window commands and document publication wait for complete refresh. ui.stats().refreshYields reports cooperative idle returns. Mutating requests wait across worker turns for the existing job, so they cannot run inside its read-only scope. Mutating requests are serialized; newer viewport targets coalesce by cancelling unpublished layout. Initial source execution remains atomic; its layout can park across worker turns. Explicit REPL/event refresh can park across worker turns. Idle tasks deliver at most one callback per turn and park subsequent layout; callbacks and individual native nodes remain atomic. Large intrinsic trees use the sliced driver; small intrinsic trees keep the fast path.
|
||||
|
||||
|
||||
Runtime mutation entry points reject direct calls while refresh work is pending, before executing source or changing metadata; task polling defers. The API worker drains the saved refresh before accepting those mutations, keeping the runtime usable. Incremental refresh keeps the prior complete document map until a stable pass, including across window traversal boundaries where no VM read-only frame is currently active.
|
||||
|
||||
|
||||
Mount preparation now has an explicit checkpoint that roots the previous dictionary, Mount payloads and metadata values. It can restore geometry/relations/registry after cancelling an unpublished layout, or release its roots after completion. Task cancellation moves from speculative preparation to immediately before the actual onUnmount callback, so cancelling preparation does not destroy the old occurrence's tasks.
|
||||
|
||||
|
||||
Pending bridge layouts now retain a Mount checkpoint. cancel_layout_frame closes the VM continuation, restores the old Mount payloads/links/dictionary and marks the presentation dirty for a new solve; discarded lifecycle hooks do not run. Successful finalization releases checkpoint roots after callbacks. This restores speculative Mount preparation, not arbitrary application writes or already completed lifecycle callbacks.
|
||||
|
||||
|
||||
New viewport targets now coalesce pending refresh work. The runtime cancels only an unfinished bridge layout, restores its Mount checkpoint, preserves completed per-window drafts/callback effects and restarts traversal with the latest viewport map. refreshRestarts counts target replacements; layoutCancels counts replacements that actually closed a pending VM layout. Unchanged targets resume the same job. A new external target resets its convergence budget; internal settling does not. Ordinary source/event mutations still serialize behind refresh rather than roll back application effects.
|
||||
|
||||
|
||||
Cancellation checkpoints own explicit VM roots until restored or released. Initial presentations may have no mount dictionary; cancellation restores that absence too. Saved metadata values retain object-valued attributes. A pending refresh can restart while keeping already completed window drafts; no onMount/onUnmount callback is replayed merely because the viewport target changed. Mount-owned tasks are cancelled immediately before an actual onUnmount callback, never during abandoned preparation.
|
||||
|
||||
|
||||
source_layout uses the same resumable node driver for trees over 64 occurrences even when measure/arrange are intrinsic. Small intrinsic trees retain LayoutRuntime::frame. The larger path keeps LayoutRuntime measurement caches and yields between node calls; structural extraction, bytecode preparation, a single node, settling and paint remain atomic.
|
||||
|
||||
|
||||
Worker idle polls use ReplSession::poll_tasks_incremental with the current viewport map. Scheduler::poll accepts a checked 1..=64 work limit, counting both delivery and ineligible-task cancellation; idle uses one, synchronous compatibility uses 64. Once delivery begins layout, further tasks and window-command projection wait until the saved refresh completes. The viewport stamp allows cancellation of task-induced pending layout without repeating callback effects.
|
||||
|
||||
|
||||
REPL and event mutations now have incremental refresh entry points. They execute source/callbacks once, retain scalar response metadata, then park layout with the current viewport target. While pending, mutation, command extraction and garbage collection wait; layout can be retargeted by a newer native size. Synchronous helpers remain for host regression coverage. Discarding a ReplSession explicitly cancels any still-pending bridge layout before the Candidate releases service/global roots. This does not preempt source/callback execution, structural preparation or paint.
|
||||
|
||||
|
||||
The API worker now owns a pending HTTP request plus its scalar result while REPL/event layout is parked. It advances the layout with current native viewport targets and responds only after the stable full-window publication and command extraction. Later mutation requests remain queued; GET /code can observe the last complete publication. A newer accepted PUT invalidates queued inputs but lets the already-running owner settle before candidate construction, so failed replacement can preserve its consistent heap. DELETE revokes that owner and prevents late publication. This queue ordering does not roll back already-executed source effects.
|
||||
|
||||
|
||||
Complete-source candidates now separate one-time compilation/source execution from initial layout. load_incremental owns the isolated VM while its first layout is pending; the current live VM stays separate. Cancellation uses the same Mount checkpoint/continuation cleanup as later refresh. Synchronous load helpers remain for host regression coverage. This does not slice parsing, compilation, mutating source execution, structural preparation or final command projection.
|
||||
|
||||
|
||||
The API keeps the old runtime alongside a pending PUT candidate. Newer submissions cancel only the obsolete candidate; failures restore the published runtime's submission owner. Background epoch checks distinguish accepted replacements from DELETE revocation, so queued/superseded candidates do not destroy the previous live heap. Candidate resumption reads only the primary shell viewport, avoiding reuse of an old secondary window's dimensions for a new VM's resource with the same numeric ID. Success publishes the complete candidate document and commands together, then replaces the old runtime.
|
||||
|
||||
|
||||
Source paint now uses a resumable read-only VM call with the same 256-instruction quantum and a cumulative 1,000,000-instruction budget. The pending job owns the unpublished frame, visual snapshot, decoded command buffer and prepare root. The refresh worker resumes paint before advancing to another window and publishes only the full stable window set. New viewport targets cancel unfinished paint, discard partial commands and force that window to refresh. Already completed layout/Mount geometry and lifecycle callbacks remain committed; cancelling paint does not replay or undo them. Failure/discard explicitly closes the read-only continuation and releases its roots. paintSlices reports the most recently completed paint solve (1 when the solve completes within its first quantum); paintCancels counts viewport replacements that closed pending paint. Layout checkpoint rollback remains limited to unfinished layout preparation. Native callback bodies, driver preparation, command decoding/projection and rasterization remain atomic.
|
||||
|
||||
|
||||
Layout and paint drivers now prepare one occurrence at a time. Their fixed-size outer bytecode repeats on the same VM frame; a short-lived helper retains only the current call, its bounds/arguments and collector. The helper is released before the next occurrence. Layout keeps bottom-up measure, top-down arrange and the same settling loop. Paint advances even intrinsic method classification through VM quanta. The weak occurrence list and native scratch/output data remain proportional to the actual tree, but preparation no longer allocates managed callables/Bounds for the whole tree before the first slice. All helpers share the original read-only scope and cumulative instruction/frame limits. Weak-list copying, structural extraction, settling and final projection remain bounded atomic native work.
|
||||
|
||||
|
||||
Presentation dependency diagnostics record a counter and the last invalidated object kind/identity and version transition. ui.stats exposes dependencyInvalidations and lastInvalidDependency without retaining the dependency or rendering its data. windowDependencyDiagnostics includes nonempty reasons from every window, prefixed by window identity. Snapshot replacement also records its last invalidating object/property or change-journal overflow, so cache invalidation can be distinguished from source layout/paint dependencies. These help distinguish expected input invalidation from repeated background refresh.
|
||||
|
||||
|
||||
ui.readText(owner,key,path[,callback]) returns an owner-scoped Task and reads a regular UTF-8 file off the VM thread. Paths use native filesystem syntax; absolute paths are recommended. The optional callback takes zero arguments and must return Unit; it runs only on successful read and can use task.result(). Without a callback, poll status then read result from code. result() is available while a success callback is running or after completion (timers return Unit); error() returns an empty String or the provider/callback error. A provider failure marks the task failed and skips its callback without stopping the VM; a source callback failure still stops the shared domain. Owner/key replacement, explicit cancellation, close/reset/VM discard and GC drop the provider lease, remove queued completion and reject late delivery. In-progress OS reads may finish, but cannot deliver after cancellation. Only the owning VM worker updates managed results and rechecks owner/key identity. No VM handles enter provider threads beyond opaque weak identities.
|
||||
|
||||
The lazy shared pool has four threads and a 64-job queue. Each runtime permits 16 outstanding I/O requests (one temporary replacement reservation), and each read is capped at 1 MiB by metadata plus actual streaming length; non-regular files, non-UTF-8 data and over-limit content fail rather than truncate. These limits do not constitute a full filesystem sandbox. The provider returns text in the same managed Task, not a second application-state store. Task await is supported through ui.spawn; see the await contract below. See examples/async-file.endor; from REPL call reader.read("/absolute/path.txt") to update its actual TextBlock, even when that object is hidden but retained.
|
||||
|
||||
|
||||
ui.fetchText(owner,key,url[,callback]) performs an asynchronous HTTP(S) GET using the same Task, owner/key replacement and success-only callback protocol as readText. Example: fetcher.fetch("http://127.0.0.1:4737/agent") after loading examples/async-network.endor. The example retains the complete result in fetcher.response and displays completion status; it does not put arbitrary network content into a TextBlock, whose own 16 KiB limit is independent of the provider limit. Only 2xx responses produce a UTF-8 result; HTTP failures, invalid UTF-8, oversize bodies and transport errors set status() to failed with error(). It verifies HTTPS certificates, follows at most five HTTP(S) redirects, has a 10-second connect and 30-second total transfer timeout (starting when a worker takes the request), and bounds decoded text to 1 MiB without truncation. URLs are limited to 8192 bytes and must not contain credentials or control characters. This GET API does not accept request bodies, custom headers or authentication.
|
||||
|
||||
The current transport uses a separate system curl process per request (/usr/bin/curl on Unix, curl.exe on Windows); missing or incompatible curl fails the Task. User curlrc and URL globbing are disabled; URL data is passed through escaped stdin configuration rather than command arguments. TLS and normal system proxy behavior remain enabled. Cancellation kills an active HTTP process immediately and the provider worker reaps it; the VM thread never waits for the process. All file and HTTP requests share the per-runtime 16-task limit and global four-worker/64-job queue. In-progress file reads remain cooperatively cancelled at delivery. Network access is not a security sandbox, and this is a text GET provider rather than a general HTTP client. Task await is supported through ui.spawn; see below.
|
||||
|
||||
|
||||
ui.spawn(owner,key,function) creates an owner-scoped cooperative Task for a zero-argument function; its returned value is retained as the Task result. Each owning VM poll resumes at most a 256-instruction quantum per selected Task, rotates runnable tasks fairly, and retains source frames in an Aster-managed coroutine edge. Calls and writes may interleave between quanta; prior writes are not rolled back on cancellation or error. Pending/running Task replacement, owner closure, GC and reset release parked frames through the same managed graph. Native calls remain atomic and all quanta share the 128-frame/100000-instruction callback limit; a native entry may run during preparation. result() is unavailable until spawn completes. A source error still stops the shared runtime. See examples/cooperative-tasks.endor. Endor await expressions now suspend these calls on a Task without replaying the operand. See the await contract below.
|
||||
|
||||
|
||||
Inside a function run by ui.spawn, `value = await task` waits for any timer/file/network/spawn Task and resumes at the same expression with its retained result. A source function may return a Number, String, managed Object or Unit; normal source annotations still apply. Task.result() and await share the result. `ui.sleep(owner,key,milliseconds)` creates a callback-free timer Task returning Unit. Plain calls/REPL can await an already completed Task; a pending await requires a coroutine and fails explicitly rather than blocking. There is no new async function declaration: ui.spawn explicitly schedules an ordinary Endor function. See examples/await-file.endor.
|
||||
|
||||
A waiting coroutine retains its evaluated operand and frames as managed edges; waiting performs no VM execution or active polling. Source side effects and IO initiation before await are not replayed. When the dependency completes, the owning VM worker resumes the waiter through the existing fair quantum scheduler. Cancelling/replacing/closing the waiter releases its frames and operand; it does not automatically cancel an independently owned or shared dependency. Dependency cancellation propagates cancellation to its waiters without running the remainder. An unhandled dependency failure becomes a source await error (with the original provider message), fails the waiter and follows the existing shared-runtime fault rule; provider failure alone still only fails its own Task. Self-await and cyclic Task waits fail explicitly. Read-only layout/paint cannot await. Waiting state is reported as running, while active() remains true; result() is unavailable until completion. These APIs do not introduce try/finally or change the existing exception model.
|
||||
|
||||
|
||||
While a native tab drag is held over an overflow arrow area, the strip waits 350ms then reveals one hidden tab every 120ms, including in a compatible destination window. The preview scroll does not activate Pages or change business state. Drawing, hit testing and insertion gaps share the same transient visible range; release uses its full-order insertion index. Leaving the strip stops the timer; release, Escape, a new press or runtime generation change restores the normal active-tab-centered strip. A resize or changing tab count clamps the range. Native drag/mixed-DPI behavior still requires platform validation; application-exit cleanup is described below.
|
||||
|
||||
CI regression fixtures use the published frame's session identity for input,
|
||||
current Endor statement boundaries/type names and the retained runtime's actual
|
||||
layout/paint pipeline. Failed first Console rendering discards unpublished Page
|
||||
registrations through host-only cleanup, preventing the next successful query
|
||||
from silently opening a previously failed pending render. Earlier ordinary
|
||||
bindings remain live; explicit page.render can subsequently publish the Page.
|
||||
|
||||
|
||||
Application exit now uses a private VM-worker control channel, independent of HTTP queue capacity. Main native close and a managed primary Window.close request asynchronous cleanup; duplicate requests coalesce and mutation requests are rejected with 503 while exiting. An unpublished candidate/input refresh is cancelled without replay. The current VM cancels all Task entries, closes managed windows, detaches occurrences child-before-parent per window, and invokes normal onUnmount hooks once. It does not run layout/paint during shutdown. All windows are closed before hooks run; new windows and tasks are forbidden. A stopped/faulted VM detaches without source hooks; reset/discarded pictures cannot revive an old VM. A hook error aborts remaining source hooks, releases prepared hook roots, drops the VM and reports failure before native exit. Completed shutdown is acknowledged to the GUI, which then ends the event loop. An OS exit bypassing CloseRequested uses a five-second bounded final fallback; non-cooperative native calls remain atomic and force-kill/crash cannot guarantee notifications. Native stderr records the window/mount/task-entry counts and whether source hooks were enabled, or the cleanup error. See examples/exit-lifecycle.endor. Cross-platform exit/drag validation remains broader follow-up work.
|
||||
|
||||
|
||||
Foreground REPL/events now retain a BeforeInput request while an existing idle layout/paint refresh advances one stage/quantum per worker turn. They execute their source only after that refresh settles, so mutations never enter its read-only scope. New task callbacks are not delivered ahead of this accepted input. Shutdown can cancel the waiting request with 503, and superseded submissions still return 409. Reset cancels/discards the old VM instead of synchronously draining its unpublished refresh. Source parsing/compilation and ordinary synchronous source/native calls remain atomic boundaries; this change removes the worker's synchronous pre-input refresh drain.
|
||||
|
||||
|
||||
Source layout/paint now validate name-level read observations from Aster: each globals/builtins lookup records its text key and observed presence/value, while dictionary kind checks remain separate. Updating the REPL result `_` or another unread global no longer invalidates these frames solely because the whole globals dictionary version changed. Reading `_` still observes its value; adding a previously missing global correctly invalidates a builtin fallback. Ordinary native dictionary iteration/content reads retain whole-object version dependencies. Measurement cache hits replay their recorded observations into the outer solve; they do not drop dependencies merely because source execution was skipped. Cache observations contain borrowed handles (including object-valued names), add no GC roots, and never write comparison snapshots back into language objects. Invalid-name diagnostics report only identity/key, not captured values. General Block binding and other legacy readers keep their existing conservative object dependencies. See examples/global-dependencies.endor.
|
||||
|
||||
Source layout/paint and measurement caches exclude every presentation's private desktop identity, including the primary desktop captured by shared native visual methods. Per-window bookkeeping must not invalidate another window's source output. This exclusion does not cover managed Window objects, viewport input records, type definitions or business objects; their observed changes remain dependencies.
|
||||
|
||||
The gc-lifecycle example and endor_host regression combine a mounted Page/Block cycle, source measure/paint dependencies and an owner-scoped coroutine suspended on sleep. Closing the tab preserves a referenced Block's workflow; releasing the external Page/Task holders lets normal collection reclaim the cycle before the wait completes. Regression assertions check both the same-program object baseline and weak identities.
|
||||
|
||||
The API worker logs the submission identity once when a newly accepted input enters BeforeInput waiting. It omits source and runtime values, and resume quanta do not repeat it. This distinguishes cancellation of an accepted pre-input wait from cancellation of an unpublished candidate or a request still in the transport queue.
|
||||
|
||||
Property binding caches now consume synchronous precise ReadSet dependencies, replay validation through ObjectStore and exclude the same private presentation desktops as source layout/paint. Cached output equality still repairs a direct overwrite even when its compute dependencies are unchanged. ui.stats().bindingEvaluations counts computations in completed binding refreshes for this VM, including initial/hidden bindings, so unrelated REPL inputs can be checked without adding effects to read-only source compute functions.
|
||||
|
||||
|
||||
Window workspace modules:
|
||||
- `tabs.rs`: common tab/close/+ geometry, overflow and shared hover/active capsules.
|
||||
- `tabs/motion.rs`: 200 ms eased geometry shared by painting and pointer hits.
|
||||
- `ui_bridge/start_page.endor`: the functional default Page, layout, callbacks and examples in Endor.
|
||||
- `ui_bridge/developer_pages.rs`: loads the private start-page module and delegates new-tab creation to its managed factory.
|
||||
- `ui_bridge/developer_pages.rs`: managed tool/start Pages, identity-preserving reopen and focus.
|
||||
- `developer_tools/{console,sources,network,settings}.rs`: separate page views.
|
||||
- `developer_tools/painter.rs`: reusable pane painting and response formatting.
|
||||
- `developer_tools/selection.rs`: independent read-only source selection.
|
||||
- `endor_host/tests.rs` and `api/tests.rs`: existing regression sources, moved with corrected include paths.
|
||||
| `shell/` | 原生工作区、窗口输入、标签、开发工具和独立宿主管理控件 |
|
||||
| `runtime/` | 本机 API、串行 VM 执行、事件和异步任务 |
|
||||
| `model/` | 托管对象、绑定、Mount、窗口语义、依赖与发布值 |
|
||||
| `render/` | 几何、布局、source/native 视觉协议、绘制、命中、字体和软件渲染 |
|
||||
| `bridge/` | Endor 类型/方法与宿主能力及展示刷新之间的连接 |
|
||||
|
||||
## shell
|
||||
|
||||
| 模块 | 职责 |
|
||||
| --- | --- |
|
||||
| [activity](shell/activity.rs) | 有界 HTTP 活动记录与允许的头部预览 |
|
||||
| [app](shell/app.rs) | GUI 事件循环、窗口/viewport、输入与 chrome 调度 |
|
||||
| [clipboard](shell/clipboard.rs) | 原生 UTF-8 剪贴板适配 |
|
||||
| [developer_tools](shell/developer_tools.rs) | 四个工具 Page 的状态、焦点与管理交互协调 |
|
||||
| [native_chrome](shell/native_chrome.rs) | macOS 原生按钮对齐和工具栏双击系统动作 |
|
||||
| [sources](shell/sources.rs) | 默认断开的云文件 provider 接口及工作区 |
|
||||
| [system_ui](shell/system_ui/mod.rs) | 独立宿主管理控件、交互和主题 |
|
||||
| [tabs](shell/tabs.rs) | 共享标签绘制/命中、密集布局、滚动、拖放及动画 |
|
||||
|
||||
## runtime
|
||||
|
||||
| 模块 | 职责 |
|
||||
| --- | --- |
|
||||
| [api](runtime/api.rs) | HTTP 请求路由、队列、请求观察和响应;worker/指南拆为子模块 |
|
||||
| [endor_host](runtime/endor_host.rs) | 候选/活跃 VM、编译执行、增量刷新、清理和诊断 |
|
||||
| [endor_script](runtime/endor_script.rs) | 组织 Aster Script/Module 输入及原始源码范围 |
|
||||
| [events](runtime/events.rs) | 原生输入的有界 loopback 传输 |
|
||||
| [event_dispatch](runtime/event_dispatch.rs) | 托管事件、订阅和 capture/target/bubble 分发 |
|
||||
| [io_tasks](runtime/io_tasks.rs) | 有界文件/HTTP provider、纯数据完成消息和取消 |
|
||||
| [tasks](runtime/tasks.rs) | 托管 Task、owner/key 取消和协作任务调度 |
|
||||
| [vm_sequence](runtime/vm_sequence.rs) | 共享 VM 调用序列及同帧迭代驱动 |
|
||||
|
||||
## model
|
||||
|
||||
| 模块 | 职责 |
|
||||
| --- | --- |
|
||||
| [binding](model/binding.rs) | 属性依赖、只读计算与托管绑定 |
|
||||
| [block](model/block.rs) | Block/Cell/Data 语义、稳定子 slot 和共享赋值 |
|
||||
| [document](model/document.rs) | NamespaceState、RenderDocument、Frame、发布校验与原生命令 |
|
||||
| [mount](model/mount.rs) | 每次展示出现的托管上下文、生命周期及弱索引 |
|
||||
| [object_list](model/object_list.rs) | 托管结果集合的类型封装与只读访问 |
|
||||
| [presentation](model/presentation.rs) | 逐窗口布局、Mount、缓存、读依赖和失效状态 |
|
||||
| [protocols](model/protocols.rs) | Visual/EventTarget/Children/Presentable 能力契约安装 |
|
||||
| [snapshot](model/snapshot.rs) | 变化依赖和不可变视觉提取缓存 |
|
||||
| [window](model/window.rs) | 托管 Window、Page registry、命令及生命周期 |
|
||||
|
||||
## render
|
||||
|
||||
| 模块 | 职责 |
|
||||
| --- | --- |
|
||||
| [display_list](render/display_list.rs) | 原生绘制原语和颜色 |
|
||||
| [geometry](render/geometry.rs) | 点和矩形值 |
|
||||
| [layout](render/layout.rs) | 原生测量、排列、出现几何及预算 |
|
||||
| [native_visual](render/native_visual.rs) | 托管原生视觉协议、值转换和签名检查 |
|
||||
| [scene](render/scene.rs) | 页面、标签、插入标记和开发工具画面合成 |
|
||||
| [scroll](render/scroll.rs) | 逐 Mount 偏移、嵌套滚动和剪裁投影 |
|
||||
| [software_renderer](render/software_renderer.rs) | 软件光栅化、抗锯齿覆盖和嵌套剪裁 |
|
||||
| [source_hit](render/source_hit.rs) | 源/原生命中协议与匹配目标 |
|
||||
| [source_layout](render/source_layout.rs) | 源 measure/arrange、约束、挂起工作和测量缓存 |
|
||||
| [source_paint](render/source_paint.rs) | 源 paint 调用、受限命令转换和依赖 |
|
||||
| [text](render/text.rs) | 系统字体、shaping、字形和测量缓存 |
|
||||
|
||||
## bridge
|
||||
|
||||
| 模块 | 职责 |
|
||||
| --- | --- |
|
||||
| [ui_bridge](bridge/ui_bridge.rs) | Endor 宿主类型、窗口展示会话、布局/绘制发布协调 |
|
||||
|
||||
## 主要入口和运行约束
|
||||
|
||||
- HTTP 路由:`runtime/api.rs`;worker:`runtime/api/worker.rs`;在线指南:`runtime/api/guide.rs`。
|
||||
- Bridge 安装:`bridge/ui_bridge/bootstrap.rs`;Block 调用:`calls.rs`;签名:`signatures.rs`;不可变树:`tree.rs`。
|
||||
- 默认页:`bridge/ui_bridge/start_page.endor`;Console/Sources/Network/Settings:`shell/developer_tools/`。
|
||||
- 现有 API 和宿主测试:`runtime/api/tests.rs`、`runtime/endor_host/tests.rs`;其他模块中也保留原单元测试。
|
||||
|
||||
VM 和托管根只由执行 worker 操作。原生窗口收到已发布值,不收到 ObjectRef。完整 PUT 成功才接替活跃程序;Console 保留实际 VM;失败和清理语义见架构文档。
|
||||
|
||||
本机遵循既有检查约定:格式、离线 Clippy、原生 release 构建和人工运行检查;不执行 cargo test、自动 smoke 脚本或 Docker。已有远程检查脚本保留原位置,此次不运行或追逐 CI。
|
||||
|
||||
-1802
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
// Module ownership follows the directory; crate-root aliases keep internal call sites stable.
|
||||
pub(crate) mod ui_bridge;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,397 @@
|
||||
//! Allocate and connect the managed desktop, type tables and host globals.
|
||||
use super::*;
|
||||
|
||||
pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
let desktop = vm.new_object()?;
|
||||
roots.push(desktop);
|
||||
vm.set_attr(desktop, "viewport", Value::Nil)?;
|
||||
let tabs = vm.new_dict()?;
|
||||
roots.push(tabs);
|
||||
vm.set_attr(desktop, "tabs", Value::Object(tabs))?;
|
||||
let ui = vm.new_object()?;
|
||||
roots.push(ui);
|
||||
let session = Arc::new(Mutex::new(Session {
|
||||
nodes: Vec::new(),
|
||||
presentations: std::collections::BTreeMap::from([(
|
||||
crate::window::MAIN_WINDOW,
|
||||
crate::presentation::Presentation::new(desktop, tabs),
|
||||
)]),
|
||||
current: crate::window::MAIN_WINDOW,
|
||||
master: desktop,
|
||||
next_window: crate::window::MAIN_WINDOW,
|
||||
next_mount: 0,
|
||||
retired_commands: Vec::new(),
|
||||
refresh_yields: 0,
|
||||
refresh_restarts: 0,
|
||||
layout_cancels: 0,
|
||||
paint_cancels: 0,
|
||||
paint_slices: 0,
|
||||
binding_evaluations: 0,
|
||||
exiting: false,
|
||||
}));
|
||||
let mut public_functions = Vec::new();
|
||||
let mut factories = Vec::new();
|
||||
for (name, operation) in [
|
||||
("implement", Operation::Implement),
|
||||
("implements", Operation::Implements),
|
||||
("supports", Operation::Supports),
|
||||
("isInstance", Operation::IsInstance),
|
||||
("isSubtype", Operation::IsSubtype),
|
||||
("open", Operation::OpenValue),
|
||||
("text", Operation::Text),
|
||||
("rect", Operation::Rect),
|
||||
("spacer", Operation::Spacer),
|
||||
("row", Operation::Row),
|
||||
("column", Operation::Column),
|
||||
("button", Operation::Button),
|
||||
("page", Operation::Page),
|
||||
("present", Operation::Present),
|
||||
("state", Operation::State),
|
||||
("textOf", Operation::TextOf),
|
||||
("stats", Operation::Stats),
|
||||
("viewport", Operation::Viewport),
|
||||
("window", Operation::Window),
|
||||
] {
|
||||
let function = vm.allocate(ContextNativeFunction::new(
|
||||
name,
|
||||
Function {
|
||||
signature: None,
|
||||
operation,
|
||||
owner: None,
|
||||
session: session.clone(),
|
||||
requested_type: None,
|
||||
},
|
||||
vec![desktop],
|
||||
))?;
|
||||
roots.push(function);
|
||||
vm.set_attr(ui, name, Value::Object(function))?;
|
||||
public_functions.push((name, function, operation));
|
||||
}
|
||||
let root_types = vm.bootstrap_types()?;
|
||||
roots.extend([root_types.object, root_types.type_type]);
|
||||
vm.set_attr(ui, "Object", Value::Object(root_types.object))?;
|
||||
vm.set_attr(ui, "Type", Value::Object(root_types.type_type))?;
|
||||
let mut definitions = vec![
|
||||
("Object", root_types.object),
|
||||
("Type", root_types.type_type),
|
||||
];
|
||||
for (name, base_name, constructor_name) in [
|
||||
("Trait", "Object", None),
|
||||
("Function", "Object", None),
|
||||
("Block", "Object", None),
|
||||
("ContainerBlock", "Block", None),
|
||||
("TextBlock", "Block", Some("text")),
|
||||
("RectBlock", "Block", Some("rect")),
|
||||
("Spacer", "Block", Some("spacer")),
|
||||
("ScrollBlock", "ContainerBlock", Some("scroll")),
|
||||
("Row", "ContainerBlock", Some("row")),
|
||||
("Column", "ContainerBlock", Some("column")),
|
||||
("Button", "ContainerBlock", Some("button")),
|
||||
("Page", "ContainerBlock", Some("page")),
|
||||
("Window", "Object", Some("window-create")),
|
||||
("Mount", "Object", None),
|
||||
("Event", "Object", Some("event")),
|
||||
("Subscription", "Object", None),
|
||||
("Task", "Object", None),
|
||||
("ObjectList", "Object", Some("object-list")),
|
||||
] {
|
||||
let base = object(Some(&vm.get_attr(ui, base_name)?))?;
|
||||
let constructor = match constructor_name {
|
||||
Some("object-list") => {
|
||||
let factory = vm.allocate(ContextNativeFunction::new(
|
||||
"object-list",
|
||||
crate::object_list::Constructor {
|
||||
desktop,
|
||||
signature: None,
|
||||
},
|
||||
vec![desktop],
|
||||
))?;
|
||||
roots.push(factory);
|
||||
let function_type = object(Some(&vm.get_attr(ui, "Function")?))?;
|
||||
vm.attach_type(factory, function_type)?;
|
||||
TypeConstructor::NativeTyped(factory)
|
||||
}
|
||||
Some("event") => {
|
||||
let factory = vm.allocate(ContextNativeFunction::new(
|
||||
"event",
|
||||
crate::event_dispatch::Constructor { signature: None },
|
||||
vec![],
|
||||
))?;
|
||||
roots.push(factory);
|
||||
let function_type = object(Some(&vm.get_attr(ui, "Function")?))?;
|
||||
vm.attach_type(factory, function_type)?;
|
||||
TypeConstructor::NativeTyped(factory)
|
||||
}
|
||||
Some(constructor_name) => {
|
||||
let operation = match constructor_name {
|
||||
"text" => Operation::Text,
|
||||
"rect" => Operation::Rect,
|
||||
"spacer" => Operation::Spacer,
|
||||
"scroll" => Operation::Scroll,
|
||||
"row" => Operation::Row,
|
||||
"column" => Operation::Column,
|
||||
"button" => Operation::Button,
|
||||
"page" => Operation::Page,
|
||||
"window-create" => Operation::NewWindow,
|
||||
_ => return Err(invalid("unknown native type allocator").into()),
|
||||
};
|
||||
let factory = vm.allocate(ContextNativeFunction::new(
|
||||
constructor_name,
|
||||
NativeFactory {
|
||||
signature: None,
|
||||
options: None,
|
||||
operation,
|
||||
session: session.clone(),
|
||||
},
|
||||
vec![desktop],
|
||||
))?;
|
||||
roots.push(factory);
|
||||
let function_type = object(Some(&vm.get_attr(ui, "Function")?))?;
|
||||
vm.attach_type(factory, function_type)?;
|
||||
TypeConstructor::NativeTyped(factory)
|
||||
}
|
||||
None => TypeConstructor::Abstract,
|
||||
};
|
||||
if let (Some(tag), TypeConstructor::NativeTyped(factory)) = (constructor_name, constructor)
|
||||
{
|
||||
factories.push((tag, factory));
|
||||
}
|
||||
let definition = vm.new_type(name, base, constructor)?;
|
||||
roots.push(definition);
|
||||
vm.set_attr(ui, name, Value::Object(definition))?;
|
||||
definitions.push((name, definition));
|
||||
}
|
||||
for (name, fields) in [
|
||||
(
|
||||
"Constraints",
|
||||
vec!["minWidth", "minHeight", "maxWidth", "maxHeight"],
|
||||
),
|
||||
("MeasureResult", vec!["width", "height"]),
|
||||
("Bounds", vec!["x", "y", "width", "height"]),
|
||||
("Point", vec!["x", "y"]),
|
||||
("Arrangement", vec!["children"]),
|
||||
("DisplayList", vec!["commands"]),
|
||||
("PaintCommand", vec![]),
|
||||
] {
|
||||
let fields = fields
|
||||
.into_iter()
|
||||
.map(|name| endor_core::ClassField {
|
||||
name: name.into(),
|
||||
type_name: if matches!(name, "children" | "commands") {
|
||||
"Object"
|
||||
} else {
|
||||
"Number"
|
||||
}
|
||||
.into(),
|
||||
})
|
||||
.collect();
|
||||
let definition = vm.new_class(
|
||||
name,
|
||||
root_types.object,
|
||||
fields,
|
||||
std::collections::BTreeMap::new(),
|
||||
)?;
|
||||
roots.push(definition);
|
||||
vm.set_attr(ui, name, Value::Object(definition))?;
|
||||
definitions.push((name, definition));
|
||||
}
|
||||
// The desktop owns the registry through ordinary traced attributes. The
|
||||
// Rust session only borrows handles and adds no hidden lifetime roots.
|
||||
let types = vm.new_dict()?;
|
||||
roots.push(types);
|
||||
for (name, definition) in definitions {
|
||||
vm.dict_set(types, Value::Text(name.into()), Value::Object(definition))?;
|
||||
}
|
||||
vm.set_attr(desktop, "types", Value::Object(types))?;
|
||||
vm.attach_type(desktop, root_types.object)?;
|
||||
vm.attach_type(ui, root_types.object)?;
|
||||
let function_type = object(Some(&vm.get_attr(ui, "Function")?))?;
|
||||
vm.set_function_type(function_type)?;
|
||||
vm.set_source_type_checks(true)?;
|
||||
for (name, function, operation) in public_functions {
|
||||
vm.replace_payload(
|
||||
function,
|
||||
ContextNativeFunction::new(
|
||||
name,
|
||||
Function {
|
||||
signature: Some(operation_signature(vm.object_store(), desktop, operation)?),
|
||||
operation,
|
||||
owner: None,
|
||||
session: session.clone(),
|
||||
requested_type: None,
|
||||
},
|
||||
vec![desktop],
|
||||
),
|
||||
)?;
|
||||
}
|
||||
for (name, function) in factories {
|
||||
let operation = match name {
|
||||
"text" => Some(Operation::Text),
|
||||
"rect" => Some(Operation::Rect),
|
||||
"spacer" => Some(Operation::Spacer),
|
||||
"scroll" => Some(Operation::Scroll),
|
||||
"row" => Some(Operation::Row),
|
||||
"column" => Some(Operation::Column),
|
||||
"button" => Some(Operation::Button),
|
||||
"page" => Some(Operation::Page),
|
||||
"window-create" => Some(Operation::NewWindow),
|
||||
"event" | "object-list" => None,
|
||||
_ => return Err(invalid("unknown deferred factory").into()),
|
||||
};
|
||||
if let Some(operation) = operation {
|
||||
let options = operation_signature(vm.object_store(), desktop, operation)?;
|
||||
let envelope = CallSignature {
|
||||
arity: endor_core::CallArity::range(options.arity.required + 1, usize::MAX),
|
||||
parameters: vec![AnnotationType::Type.into()],
|
||||
variadic: Some(AnnotationType::Any.into()),
|
||||
returns: options.returns.clone(),
|
||||
effect: options.effect,
|
||||
};
|
||||
let mut captures = vec![desktop];
|
||||
captures.extend(options.references());
|
||||
vm.replace_payload(
|
||||
function,
|
||||
ContextNativeFunction::new(
|
||||
name,
|
||||
NativeFactory {
|
||||
signature: Some(envelope),
|
||||
options: Some(options),
|
||||
operation,
|
||||
session: session.clone(),
|
||||
},
|
||||
captures,
|
||||
),
|
||||
)?;
|
||||
} else {
|
||||
let kind = if name == "event" {
|
||||
"Event"
|
||||
} else {
|
||||
"ObjectList"
|
||||
};
|
||||
let signature = CallSignature {
|
||||
arity: endor_core::CallArity::range(
|
||||
if name == "event" { 2 } else { 1 },
|
||||
usize::MAX,
|
||||
),
|
||||
parameters: if name == "event" {
|
||||
vec![AnnotationType::Type.into(), AnnotationType::String.into()]
|
||||
} else {
|
||||
vec![AnnotationType::Type.into()]
|
||||
},
|
||||
variadic: Some(AnnotationType::Any.into()),
|
||||
returns: AnnotationType::Nominal(desktop_type(vm.object_store(), kind, desktop)?)
|
||||
.into(),
|
||||
effect: CallEffect::ReadOnly,
|
||||
};
|
||||
if name == "event" {
|
||||
vm.replace_payload(
|
||||
function,
|
||||
ContextNativeFunction::new(
|
||||
name,
|
||||
crate::event_dispatch::Constructor {
|
||||
signature: Some(signature),
|
||||
},
|
||||
vec![],
|
||||
),
|
||||
)?;
|
||||
} else {
|
||||
vm.replace_payload(
|
||||
function,
|
||||
ContextNativeFunction::new(
|
||||
name,
|
||||
crate::object_list::Constructor {
|
||||
desktop,
|
||||
signature: Some(signature),
|
||||
},
|
||||
vec![desktop],
|
||||
),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
for name in [
|
||||
"open",
|
||||
"text",
|
||||
"rect",
|
||||
"spacer",
|
||||
"row",
|
||||
"column",
|
||||
"button",
|
||||
"page",
|
||||
"present",
|
||||
"state",
|
||||
"textOf",
|
||||
"stats",
|
||||
"viewport",
|
||||
"window",
|
||||
"isInstance",
|
||||
"isSubtype",
|
||||
"implement",
|
||||
"implements",
|
||||
"supports",
|
||||
] {
|
||||
let function = object(Some(&vm.get_attr(ui, name)?))?;
|
||||
vm.attach_type(function, function_type)?;
|
||||
}
|
||||
for (type_name, name, operation) in [
|
||||
("Block", "bind", Operation::Bind),
|
||||
("Block", "mounts", Operation::Mounts),
|
||||
("Block", "invalidate", Operation::Invalidate),
|
||||
("Block", "onClick", Operation::OnClick),
|
||||
("Block", "on", Operation::On),
|
||||
("Block", "dispatch", Operation::Dispatch),
|
||||
("Block", "onEvent", Operation::OnEvent),
|
||||
("Block", "onMount", Operation::OnMount),
|
||||
("Block", "onUnmount", Operation::OnUnmount),
|
||||
("Block", "click", Operation::Click),
|
||||
("TextBlock", "setText", Operation::SetText),
|
||||
("TextBlock", "setColor", Operation::SetColor),
|
||||
("RectBlock", "setColor", Operation::SetColor),
|
||||
("ContainerBlock", "append", Operation::Append),
|
||||
("ContainerBlock", "insert", Operation::Insert),
|
||||
("ContainerBlock", "remove", Operation::Remove),
|
||||
("ContainerBlock", "replace", Operation::Replace),
|
||||
("ContainerBlock", "move", Operation::Move),
|
||||
("ContainerBlock", "children", Operation::Children),
|
||||
("Window", "close", Operation::CloseWindow),
|
||||
("Page", "moveToWindow", Operation::MoveWindow),
|
||||
("Page", "moveTab", Operation::MoveTab),
|
||||
("Page", "detachToWindow", Operation::Detach),
|
||||
("Page", "render", Operation::Render),
|
||||
("Page", "unmount", Operation::Unmount),
|
||||
("Page", "open", Operation::Open),
|
||||
("Page", "window", Operation::PageWindow),
|
||||
("Page", "close", Operation::Close),
|
||||
("Page", "activate", Operation::Activate),
|
||||
("Page", "navigate", Operation::Navigate),
|
||||
("Page", "back", Operation::Back),
|
||||
("Page", "forward", Operation::Forward),
|
||||
] {
|
||||
let expected = object(Some(&vm.get_attr(ui, type_name)?))?;
|
||||
let method = vm.allocate(ContextNativeFunction::new(
|
||||
name,
|
||||
TypeMethod {
|
||||
signature: method_signature(vm.object_store(), desktop, expected, operation)?,
|
||||
operation,
|
||||
expected,
|
||||
session: session.clone(),
|
||||
},
|
||||
vec![expected, desktop],
|
||||
))?;
|
||||
roots.push(method);
|
||||
vm.attach_type(method, function_type)?;
|
||||
vm.define_method(expected, name, method)?;
|
||||
}
|
||||
crate::window::install(vm, roots, desktop, tabs)?;
|
||||
let block_type = object(Some(&vm.get_attr(ui, "Block")?))?;
|
||||
crate::native_visual::install(vm, roots, desktop, block_type, function_type)?;
|
||||
let event_type = object(Some(&vm.get_attr(ui, "Event")?))?;
|
||||
let token_type = object(Some(&vm.get_attr(ui, "Subscription")?))?;
|
||||
crate::event_dispatch::install(vm, roots, event_type, token_type, function_type)?;
|
||||
crate::protocols::install(vm, roots, desktop, ui)?;
|
||||
let tasks = crate::tasks::install(vm, roots, ui, desktop)?;
|
||||
developer_pages::install(vm, ui, &session)?;
|
||||
let bridge = UiBridge { ui, session, tasks };
|
||||
developer_pages::install_start_page(vm, &bridge)?;
|
||||
Ok(bridge)
|
||||
}
|
||||
@@ -0,0 +1,789 @@
|
||||
//! Native Block operations executed on the owning VM worker.
|
||||
use super::*;
|
||||
|
||||
impl NativeCallable for Function {
|
||||
fn signature(&self) -> Option<CallSignature> {
|
||||
self.signature.clone()
|
||||
}
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(self.operation.arity())
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
use Operation::*;
|
||||
let arity = self.operation.arity();
|
||||
let (minimum, maximum) = (arity.required, arity.maximum);
|
||||
if !(minimum..=maximum).contains(&args.len()) {
|
||||
return Err(invalid("incorrect UI method argument count"));
|
||||
}
|
||||
if matches!(self.operation, Implement | Implements | Supports) {
|
||||
let capability = object(args.get(1))?;
|
||||
let value = match self.operation {
|
||||
Implement => {
|
||||
cx.implement_trait(object(args.first())?, capability)?;
|
||||
Value::Nil
|
||||
}
|
||||
Implements => Value::Bool(
|
||||
cx.store()
|
||||
.implements_trait(object(args.first())?, capability)?,
|
||||
),
|
||||
Supports => {
|
||||
// Validate the contract even for immediate scalar values.
|
||||
cx.store()
|
||||
.payload::<endor_core::EndorTraitObject>(capability, "Trait")?;
|
||||
Value::Bool(match args[0] {
|
||||
Value::Object(value) => cx.store().supports(value, capability)?,
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
return Ok(NativeResult::Return(value));
|
||||
}
|
||||
if matches!(self.operation, IsInstance | IsSubtype) {
|
||||
let candidate = object(args.first())?;
|
||||
let expected = object(args.get(1))?;
|
||||
let value = if matches!(self.operation, IsInstance) {
|
||||
cx.store().is_instance(candidate, expected)?
|
||||
} else {
|
||||
cx.store().is_subtype(candidate, expected)?
|
||||
};
|
||||
return Ok(NativeResult::Return(Value::Bool(value)));
|
||||
}
|
||||
if matches!(self.operation, Invalidate) {
|
||||
if cx.store().is_read_only() {
|
||||
return Err(invalid(
|
||||
"invalidation is forbidden during read-only rendering",
|
||||
));
|
||||
}
|
||||
let reason = args
|
||||
.first()
|
||||
.map(|value| text(Some(value)))
|
||||
.transpose()?
|
||||
.unwrap_or_else(|| "layout".into());
|
||||
if !matches!(reason.as_str(), "paint" | "layout" | "content") {
|
||||
return Err(invalid(
|
||||
"invalidation reason must be paint, layout or content",
|
||||
));
|
||||
}
|
||||
let owner = self.owner.ok_or(invalid("invalidation requires a Block"))?;
|
||||
let (data, _) = block::resolve(cx.store(), owner)?;
|
||||
let mut session = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?;
|
||||
let mut affected = std::collections::HashSet::new();
|
||||
for weak in &session.nodes {
|
||||
if let Some(block) = cx.upgrade(*weak)?
|
||||
&& block::resolve(cx.store(), block)?.0 == data
|
||||
{
|
||||
affected.insert(block);
|
||||
}
|
||||
}
|
||||
for presentation in session.presentations.values_mut() {
|
||||
presentation.invalidate(cx, &affected, &reason)?;
|
||||
}
|
||||
return Ok(NativeResult::Return(Value::Nil));
|
||||
}
|
||||
if matches!(self.operation, Mounts) {
|
||||
let owner = self.owner.ok_or(invalid("mount query requires a Block"))?;
|
||||
let session = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?;
|
||||
let mut positions = Vec::new();
|
||||
for (window, presentation) in &session.presentations {
|
||||
for (id, weak) in &presentation.mounts.active {
|
||||
if let Some(object) = cx.upgrade(*weak)?
|
||||
&& cx
|
||||
.store()
|
||||
.payload::<crate::mount::Mount>(object, "Mount")?
|
||||
.block
|
||||
== owner
|
||||
{
|
||||
positions.push((*window, *id, object));
|
||||
}
|
||||
}
|
||||
}
|
||||
positions.sort_unstable_by_key(|(window, id, _)| (*window, *id));
|
||||
let set = crate::mount::collection(
|
||||
cx,
|
||||
positions.into_iter().map(|(_, _, object)| object).collect(),
|
||||
session.desktop,
|
||||
)?;
|
||||
return Ok(NativeResult::Return(Value::Object(set)));
|
||||
}
|
||||
if matches!(self.operation, NewWindow) {
|
||||
let mut state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?;
|
||||
let definition = self
|
||||
.requested_type
|
||||
.ok_or(invalid("Window constructor requires a type"))?;
|
||||
let window = create_window(cx, &mut state, definition)?;
|
||||
return Ok(NativeResult::Return(Value::Object(window)));
|
||||
}
|
||||
if matches!(self.operation, CloseWindow) {
|
||||
let window = self
|
||||
.owner
|
||||
.ok_or(invalid("window close requires a receiver"))?;
|
||||
let id = cx
|
||||
.store()
|
||||
.payload::<crate::window::ManagedWindow>(window, "Window")?
|
||||
.id;
|
||||
crate::window::close(cx, window)?;
|
||||
let mut state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?;
|
||||
if let Some(view) = state.presentations.get_mut(&id) {
|
||||
cx.set_attr(view.desktop, "pending", Value::Nil)?;
|
||||
view.pending = Some(None);
|
||||
view.force_frame = true;
|
||||
view.closing = true;
|
||||
}
|
||||
return Ok(NativeResult::Return(Value::Nil));
|
||||
}
|
||||
if matches!(self.operation, Window) {
|
||||
let desktop = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?
|
||||
.desktop;
|
||||
return Ok(NativeResult::Return(
|
||||
cx.store().get_attr(desktop, "window")?,
|
||||
));
|
||||
}
|
||||
if matches!(self.operation, Viewport) {
|
||||
let desktop = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?
|
||||
.desktop;
|
||||
let Value::Object(input) = cx.store().get_attr(desktop, "viewport")? else {
|
||||
return Err(invalid("window viewport is unavailable"));
|
||||
};
|
||||
let width = cx.store().get_attr(input, "width")?;
|
||||
let height = cx.store().get_attr(input, "height")?;
|
||||
return Ok(NativeResult::Return(Value::Object(
|
||||
crate::native_visual::record(
|
||||
cx,
|
||||
desktop,
|
||||
"MeasureResult",
|
||||
vec![("width", width), ("height", height)],
|
||||
)?,
|
||||
)));
|
||||
}
|
||||
if matches!(self.operation, Stats) {
|
||||
if cx.store().is_read_only() {
|
||||
return Err(invalid(
|
||||
"runtime statistics are unavailable during read-only rendering",
|
||||
));
|
||||
}
|
||||
let session = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?;
|
||||
let mut blocks = 0_i64;
|
||||
let mut pages = 0_i64;
|
||||
for weak in &session.nodes {
|
||||
if let Some(object) = cx.upgrade(*weak)? {
|
||||
blocks += 1;
|
||||
if cx.store().payload::<block::Block>(object, "Block")?.page {
|
||||
pages += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
let objects = cx.store().object_count() as i64;
|
||||
let tabs = cx.store().dict_items(session.tabs)?.len() as i64;
|
||||
let stats = cx.new_object()?;
|
||||
for (name, value) in [
|
||||
("objects", objects),
|
||||
("blocks", blocks),
|
||||
("pages", pages),
|
||||
("tabs", tabs),
|
||||
("mounts", session.mounts.active.len() as i64),
|
||||
("snapshotVisited", session.snapshot_visited as i64),
|
||||
("snapshotReused", session.snapshot_reused as i64),
|
||||
("measured", session.layout.measured as i64),
|
||||
("sourceMeasureHits", session.measure_cache.hits as i64),
|
||||
("sourceMeasureMisses", session.measure_cache.misses as i64),
|
||||
("arranged", session.layout.arranged as i64),
|
||||
("layoutPasses", session.layout.settle_passes as i64),
|
||||
("layoutSlices", session.layout.slices as i64),
|
||||
("refreshYields", session.refresh_yields as i64),
|
||||
("refreshRestarts", session.refresh_restarts as i64),
|
||||
("layoutCancels", session.layout_cancels as i64),
|
||||
("paintCancels", session.paint_cancels as i64),
|
||||
("paintSlices", session.paint_slices as i64),
|
||||
("bindingEvaluations", session.binding_evaluations as i64),
|
||||
(
|
||||
"dependencyInvalidations",
|
||||
session.dependency_invalidations as i64,
|
||||
),
|
||||
] {
|
||||
cx.set_attr(stats, name, Value::Number(value.into()))?;
|
||||
}
|
||||
cx.set_attr(
|
||||
stats,
|
||||
"lastInvalidDependency",
|
||||
Value::Text(session.last_invalid_dependency.clone()),
|
||||
)?;
|
||||
cx.set_attr(
|
||||
stats,
|
||||
"windowDependencyDiagnostics",
|
||||
Value::Text(
|
||||
session
|
||||
.presentations
|
||||
.iter()
|
||||
.filter(|(_, view)| !view.last_invalid_dependency.is_empty())
|
||||
.map(|(id, view)| format!("{id}: {}", view.last_invalid_dependency))
|
||||
.collect::<Vec<_>>()
|
||||
.join("; "),
|
||||
),
|
||||
)?;
|
||||
return Ok(NativeResult::Return(Value::Object(stats)));
|
||||
}
|
||||
if matches!(self.operation, State) {
|
||||
let state = cx.new_object()?;
|
||||
attach_named_type(cx, state, "Object", &self.session)?;
|
||||
cx.set_attr(state, "value", args[0].clone())?;
|
||||
bind(cx, state, "set", StateSet, &self.session)?;
|
||||
bind(cx, state, "increment", Increment, &self.session)?;
|
||||
return Ok(NativeResult::Return(Value::Object(state)));
|
||||
}
|
||||
if matches!(self.operation, StateSet | Increment) {
|
||||
let owner = self.owner.ok_or(invalid("state method has no owner"))?;
|
||||
let value = if matches!(self.operation, StateSet) {
|
||||
args[0].clone()
|
||||
} else {
|
||||
let Value::Number(value) = cx.store().get_attr(owner, "value")? else {
|
||||
return Err(invalid("increment requires an integer state"));
|
||||
};
|
||||
let next = value
|
||||
.as_i64()
|
||||
.and_then(|n| n.checked_add(1))
|
||||
.ok_or(invalid("integer state increment exceeds its range"))?;
|
||||
Value::Number(next.into())
|
||||
};
|
||||
cx.set_attr(owner, "value", value)?;
|
||||
return Ok(NativeResult::Return(Value::Nil));
|
||||
}
|
||||
if matches!(self.operation, TextOf) {
|
||||
let source = object(args.first())?;
|
||||
let field = text(args.get(1))?;
|
||||
cx.store().get_attr(source, &field)?;
|
||||
let size = args
|
||||
.get(2)
|
||||
.map(|v| integer(Some(v)))
|
||||
.transpose()?
|
||||
.unwrap_or(1);
|
||||
if !(1..=8).contains(&size) {
|
||||
return Err(invalid("text size must be 1 through 8"));
|
||||
}
|
||||
let mut data = Data::new(
|
||||
Kind::Text {
|
||||
value: String::new(),
|
||||
size: size as u32,
|
||||
color: color(args.get(3), "#242422")?,
|
||||
},
|
||||
vec![],
|
||||
0.0,
|
||||
0.0,
|
||||
);
|
||||
data.text_binding = Some((source, field));
|
||||
return Ok(NativeResult::Return(Value::Object(new_block(
|
||||
cx,
|
||||
data,
|
||||
&self.session,
|
||||
)?)));
|
||||
}
|
||||
let constructor = match self.operation {
|
||||
Scroll => Some(Data::new(
|
||||
Kind::Scroll {
|
||||
width: dimension(args.first())?,
|
||||
height: dimension(args.get(1))?,
|
||||
},
|
||||
vec![object(args.get(2))?],
|
||||
0.0,
|
||||
0.0,
|
||||
)),
|
||||
Text => Some(Data::new(
|
||||
Kind::Text {
|
||||
value: text(args.first())?,
|
||||
size: args
|
||||
.get(1)
|
||||
.map(|v| integer(Some(v)))
|
||||
.transpose()?
|
||||
.unwrap_or(1)
|
||||
.try_into()
|
||||
.map_err(|_| invalid("text size exceeds limits"))?,
|
||||
color: color(args.get(2), "#242422")?,
|
||||
},
|
||||
vec![],
|
||||
0.0,
|
||||
0.0,
|
||||
)),
|
||||
Rect => Some(Data::new(
|
||||
Kind::Rect {
|
||||
width: dimension(args.first())?,
|
||||
height: dimension(args.get(1))?,
|
||||
radius: args
|
||||
.get(2)
|
||||
.map(|v| dimension(Some(v)))
|
||||
.transpose()?
|
||||
.unwrap_or(0.0),
|
||||
color: color(args.get(3), "#DCE8FF")?,
|
||||
},
|
||||
vec![],
|
||||
0.0,
|
||||
0.0,
|
||||
)),
|
||||
Spacer => Some(Data::new(
|
||||
Kind::Spacer(dimension(args.first())?),
|
||||
vec![],
|
||||
0.0,
|
||||
0.0,
|
||||
)),
|
||||
Row | Column => Some(Data::new(
|
||||
if matches!(self.operation, Row) {
|
||||
Kind::Row
|
||||
} else {
|
||||
Kind::Column
|
||||
},
|
||||
args[2..]
|
||||
.iter()
|
||||
.map(|v| object(Some(v)))
|
||||
.collect::<Result<_, _>>()?,
|
||||
dimension(args.first())?,
|
||||
dimension(args.get(1))?,
|
||||
)),
|
||||
Page => Some(Data::new(Kind::Page, vec![], 0.0, 0.0)),
|
||||
Button => {
|
||||
let label = new_block(
|
||||
cx,
|
||||
Data::new(
|
||||
Kind::Text {
|
||||
value: text(args.first())?,
|
||||
size: 1,
|
||||
color: "#243047".into(),
|
||||
},
|
||||
vec![],
|
||||
0.0,
|
||||
0.0,
|
||||
),
|
||||
&self.session,
|
||||
)?;
|
||||
Some(Data::new(Kind::Button, vec![label], 10.0, 0.0))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
if let Some(data) = constructor {
|
||||
if let Kind::Text { size, value, .. } = &data.kind
|
||||
&& (!(1..=8).contains(size) || value.len() > 16_384)
|
||||
{
|
||||
return Err(invalid("text exceeds size limits"));
|
||||
}
|
||||
return Ok(NativeResult::Return(Value::Object(new_typed_block(
|
||||
cx,
|
||||
data,
|
||||
&self.session,
|
||||
self.requested_type,
|
||||
)?)));
|
||||
}
|
||||
if matches!(self.operation, OpenValue | Present)
|
||||
&& let Value::Object(value) = args[0]
|
||||
{
|
||||
let (desktop, current) = {
|
||||
let state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?;
|
||||
(state.master, state.desktop)
|
||||
};
|
||||
let capability = desktop_type(cx.store(), "Presentable", desktop)?;
|
||||
if !cx
|
||||
.store()
|
||||
.object(value)?
|
||||
.payload()
|
||||
.as_any()
|
||||
.is::<block::Block>()
|
||||
&& cx.store().supports(value, capability)?
|
||||
{
|
||||
let definition = cx
|
||||
.store()
|
||||
.type_of(value)?
|
||||
.ok_or(invalid("untyped Presentable"))?;
|
||||
let function = cx
|
||||
.store()
|
||||
.lookup_method(definition, "present")?
|
||||
.ok_or(invalid("missing present method"))?;
|
||||
let window = object(Some(&cx.store().get_attr(current, "window")?))?;
|
||||
let complete = cx.allocate(ContextNativeFunction::new(
|
||||
"validate presentation",
|
||||
PresentResult {
|
||||
open: matches!(self.operation, OpenValue),
|
||||
session: self.session.clone(),
|
||||
},
|
||||
vec![desktop],
|
||||
))?;
|
||||
let instructions = [
|
||||
endor_core::Instruction::new(endor_core::Opcode::LoadConst, 0),
|
||||
endor_core::Instruction::simple(endor_core::Opcode::PushNull),
|
||||
endor_core::Instruction::new(endor_core::Opcode::LoadConst, 1),
|
||||
endor_core::Instruction::simple(endor_core::Opcode::PushNull),
|
||||
endor_core::Instruction::new(endor_core::Opcode::LoadConst, 2),
|
||||
endor_core::Instruction::new(endor_core::Opcode::LoadConst, 3),
|
||||
endor_core::Instruction::new(endor_core::Opcode::Call, 2),
|
||||
endor_core::Instruction::new(endor_core::Opcode::Call, 1),
|
||||
endor_core::Instruction::simple(endor_core::Opcode::ReturnValue),
|
||||
];
|
||||
let code = endor_core::EndorCode::from_instructions(
|
||||
&instructions,
|
||||
vec![
|
||||
Value::Object(complete),
|
||||
Value::Object(function),
|
||||
Value::Object(value),
|
||||
Value::Object(window),
|
||||
],
|
||||
endor_core::CodeLayout::default(),
|
||||
)?
|
||||
.with_location("Presentable.present", "<tessera>", 1);
|
||||
let code = cx.allocate(endor_core::EndorCodeObject::new(code))?;
|
||||
let globals = cx.new_dict()?;
|
||||
let driver = cx.new_function("Presentable.present", code, globals)?;
|
||||
attach_desktop_type(cx, driver, "Function", desktop)?;
|
||||
return Ok(NativeResult::Invoke {
|
||||
function: driver,
|
||||
arguments: vec![],
|
||||
});
|
||||
}
|
||||
}
|
||||
if matches!(self.operation, OpenValue) {
|
||||
let root = present_value(cx, &args[0], &self.session)?;
|
||||
let page = if cx.store().payload::<block::Block>(root, "Block")?.page {
|
||||
root
|
||||
} else {
|
||||
new_block(
|
||||
cx,
|
||||
Data::new(Kind::Page, vec![root], 0.0, 0.0),
|
||||
&self.session,
|
||||
)?
|
||||
};
|
||||
show(cx, page, &self.session)?;
|
||||
return Ok(NativeResult::Return(Value::Object(page)));
|
||||
}
|
||||
if matches!(self.operation, Present) {
|
||||
return Ok(NativeResult::Return(Value::Object(present_value(
|
||||
cx,
|
||||
&args[0],
|
||||
&self.session,
|
||||
)?)));
|
||||
}
|
||||
let owner = self.owner.ok_or(invalid("method has no owner"))?;
|
||||
if matches!(self.operation, Bind) {
|
||||
let field = text(args.first())?;
|
||||
let compute = object(args.get(1))?;
|
||||
return Ok(NativeResult::Return(Value::Object(
|
||||
crate::binding::connect(
|
||||
cx,
|
||||
owner,
|
||||
&field,
|
||||
compute,
|
||||
self.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?
|
||||
.master,
|
||||
)?,
|
||||
)));
|
||||
}
|
||||
if matches!(self.operation, MoveTab) {
|
||||
let position = usize::try_from(integer(args.first())?)
|
||||
.map_err(|_| invalid("tab position out of range"))?;
|
||||
let mut state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?;
|
||||
let id = page_window(cx.store(), &state, owner)?.ok_or(invalid("Page is not open"))?;
|
||||
let view = state
|
||||
.presentations
|
||||
.get_mut(&id)
|
||||
.ok_or(invalid("missing window"))?;
|
||||
let window = object(Some(&cx.store().get_attr(view.desktop, "window")?))?;
|
||||
crate::window::move_page(cx, window, owner, position)?;
|
||||
view.force_frame = true;
|
||||
return Ok(NativeResult::Return(Value::Object(owner)));
|
||||
}
|
||||
let (data_ref, data) = block::resolve(cx.store(), owner)?;
|
||||
let mut data = data.clone();
|
||||
let mut result = Value::Nil;
|
||||
match self.operation {
|
||||
SetText => match &mut data.kind {
|
||||
Kind::Text { value, .. } => {
|
||||
let next = text(args.first())?;
|
||||
if next.len() > 16_384 {
|
||||
return Err(invalid("text exceeds 16 KiB"));
|
||||
}
|
||||
*value = next;
|
||||
data.text_binding = None;
|
||||
cx.set_attr(owner, "text", args[0].clone())?;
|
||||
}
|
||||
_ => return Err(invalid("setText requires a text Block")),
|
||||
},
|
||||
SetColor => match &mut data.kind {
|
||||
Kind::Text { color: value, .. } | Kind::Rect { color: value, .. } => {
|
||||
*value = color(args.first(), "#242422")?;
|
||||
cx.set_attr(owner, "color", Value::Text(value.clone()))?;
|
||||
}
|
||||
_ => return Err(invalid("this Block has no color")),
|
||||
},
|
||||
Append | Insert | Remove | Replace | Move => {
|
||||
if !data.is_container() {
|
||||
return Err(invalid("expected a container Block"));
|
||||
}
|
||||
if matches!(self.operation, Append | Insert) {
|
||||
let (position, argument) = if matches!(self.operation, Insert) {
|
||||
let position = usize::try_from(integer(args.first())?)
|
||||
.map_err(|_| invalid("child position out of range"))?;
|
||||
if position > data.children.len() {
|
||||
return Err(invalid("child position out of range"));
|
||||
}
|
||||
(position, args.get(1))
|
||||
} else {
|
||||
(data.children.len(), args.first())
|
||||
};
|
||||
let child = object(argument)?;
|
||||
block::validate(cx.store(), child, Some(data_ref))?;
|
||||
let slot = data.next_slot;
|
||||
data.next_slot = slot
|
||||
.checked_add(1)
|
||||
.filter(|next| *next <= i64::MAX as u64)
|
||||
.ok_or(VmError::IdentityExhausted)?;
|
||||
data.children.insert(position, Child { slot, block: child });
|
||||
result = Value::Number((slot as i64).into());
|
||||
} else {
|
||||
let slot = integer(args.first())?;
|
||||
let index = data
|
||||
.children
|
||||
.iter()
|
||||
.position(|v| v.slot == slot)
|
||||
.ok_or(invalid("child slot does not exist"))?;
|
||||
match self.operation {
|
||||
Remove => {
|
||||
data.children.remove(index);
|
||||
}
|
||||
Replace => {
|
||||
let child = object(args.get(1))?;
|
||||
block::validate(cx.store(), child, Some(data_ref))?;
|
||||
data.children[index].block = child;
|
||||
}
|
||||
Move => {
|
||||
let to = usize::try_from(integer(args.get(1))?)
|
||||
.map_err(|_| invalid("child position out of range"))?;
|
||||
if to >= data.children.len() {
|
||||
return Err(invalid("child position out of range"));
|
||||
}
|
||||
let child = data.children.remove(index);
|
||||
data.children.insert(to, child);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Children => {
|
||||
let result = cx.new_dict()?;
|
||||
for child in data.children {
|
||||
cx.dict_set(
|
||||
result,
|
||||
Value::Text(child.slot.to_string()),
|
||||
Value::Object(child.block),
|
||||
)?;
|
||||
}
|
||||
return Ok(NativeResult::Return(Value::Object(result)));
|
||||
}
|
||||
Render | Navigate => {
|
||||
if !matches!(data.kind, Kind::Page) {
|
||||
return Err(invalid("expected a Page"));
|
||||
}
|
||||
let root = object(args.first())?;
|
||||
block::validate(cx.store(), root, Some(data_ref))?;
|
||||
if matches!(self.operation, Navigate) {
|
||||
if data.history.is_empty() {
|
||||
if let Some(old) = data.children.first() {
|
||||
data.history.push(old.block);
|
||||
}
|
||||
} else {
|
||||
data.history.truncate(data.history_index + 1);
|
||||
}
|
||||
data.history.push(root);
|
||||
data.history_index = data.history.len() - 1;
|
||||
}
|
||||
data.children = vec![Child {
|
||||
slot: 0,
|
||||
block: root,
|
||||
}];
|
||||
data.next_slot = data.next_slot.max(1);
|
||||
show(cx, owner, &self.session)?;
|
||||
}
|
||||
Back | Forward => {
|
||||
if data.history.is_empty() {
|
||||
return Ok(NativeResult::Return(Value::Nil));
|
||||
}
|
||||
let next = if matches!(self.operation, Back) {
|
||||
data.history_index.saturating_sub(1)
|
||||
} else {
|
||||
(data.history_index + 1).min(data.history.len() - 1)
|
||||
};
|
||||
data.history_index = next;
|
||||
data.children = vec![Child {
|
||||
slot: 0,
|
||||
block: data.history[next],
|
||||
}];
|
||||
show(cx, owner, &self.session)?;
|
||||
}
|
||||
Detach => {
|
||||
let window = {
|
||||
let mut state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?;
|
||||
let definition = desktop_type(cx.store(), "Window", state.master)?;
|
||||
create_window(cx, &mut state, definition)?
|
||||
};
|
||||
show_in(cx, owner, &self.session, Some(window))?;
|
||||
return Ok(NativeResult::Return(Value::Object(window)));
|
||||
}
|
||||
PageWindow => {
|
||||
let state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?;
|
||||
let value = if let Some(id) = page_window(cx.store(), &state, owner)? {
|
||||
cx.store()
|
||||
.get_attr(state.presentations[&id].desktop, "window")?
|
||||
} else {
|
||||
Value::Nil
|
||||
};
|
||||
return Ok(NativeResult::Return(value));
|
||||
}
|
||||
Open | Activate | MoveWindow => {
|
||||
if matches!(self.operation, MoveWindow)
|
||||
&& matches!(args.first(), None | Some(Value::Nil))
|
||||
{
|
||||
return Err(invalid("Page.moveToWindow requires a Window"));
|
||||
}
|
||||
let target = match args.first() {
|
||||
None | Some(Value::Nil) => None,
|
||||
Some(value) => Some(object(Some(value))?),
|
||||
};
|
||||
show_in(cx, owner, &self.session, target)?;
|
||||
return Ok(NativeResult::Return(Value::Object(owner)));
|
||||
}
|
||||
Unmount => {
|
||||
data.children.clear();
|
||||
}
|
||||
Close => {
|
||||
crate::tasks::cancel_owner(cx, owner)?;
|
||||
let mut state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?;
|
||||
if let Some(id) = page_window(cx.store(), &state, owner)? {
|
||||
// Closing the tab ends its presentation even if source
|
||||
// reopens it before the next layout can detach the Mounts.
|
||||
let page = cx.store().downgrade(owner)?;
|
||||
for weak in state.presentations[&id].mounts.ordered() {
|
||||
if let Some(mount) = cx.upgrade(weak)?
|
||||
&& cx
|
||||
.store()
|
||||
.payload::<crate::mount::Mount>(mount, "Mount")?
|
||||
.page
|
||||
== Some(page)
|
||||
{
|
||||
crate::tasks::cancel_owner(cx, mount)?;
|
||||
}
|
||||
}
|
||||
remove_page(
|
||||
cx,
|
||||
state
|
||||
.presentations
|
||||
.get_mut(&id)
|
||||
.ok_or(invalid("missing window"))?,
|
||||
owner,
|
||||
)?;
|
||||
}
|
||||
return Ok(NativeResult::Return(Value::Nil));
|
||||
}
|
||||
OnClick => {
|
||||
let handler = object(args.first())?;
|
||||
crate::event_dispatch::validate_handler(cx.store(), handler)?;
|
||||
data.click = Some(handler);
|
||||
result = Value::Object(owner);
|
||||
}
|
||||
On => {
|
||||
let kind = text(args.first())?;
|
||||
if kind.is_empty() || kind.len() > 128 {
|
||||
return Err(invalid("invalid event kind"));
|
||||
}
|
||||
let handler = object(args.get(1))?;
|
||||
crate::event_dispatch::validate_handler(cx.store(), handler)?;
|
||||
let capture = match args.get(2) {
|
||||
None | Some(Value::Bool(false)) => false,
|
||||
Some(Value::Bool(true)) => true,
|
||||
Some(Value::Text(phase)) if phase == "capture" => true,
|
||||
Some(Value::Text(phase)) if phase == "bubble" => false,
|
||||
_ => return Err(invalid("phase must be capture or bubble")),
|
||||
};
|
||||
let mut active = Vec::new();
|
||||
for token in &data.subscriptions {
|
||||
if cx
|
||||
.store()
|
||||
.payload::<crate::event_dispatch::Connection>(*token, "Connection")?
|
||||
.handler
|
||||
.is_some()
|
||||
{
|
||||
active.push(*token);
|
||||
}
|
||||
}
|
||||
if active.len() >= MAX_UI_NODES {
|
||||
return Err(invalid("too many event subscriptions"));
|
||||
}
|
||||
let connection = cx.allocate(crate::event_dispatch::Connection {
|
||||
kind,
|
||||
handler: Some(handler),
|
||||
capture,
|
||||
})?;
|
||||
let token = cx.allocate(crate::event_dispatch::Subscription {
|
||||
connection: cx.store().downgrade(connection)?,
|
||||
})?;
|
||||
attach_named_type(cx, token, "Subscription", &self.session)?;
|
||||
active.push(connection);
|
||||
data.subscriptions = active;
|
||||
result = Value::Object(token);
|
||||
}
|
||||
OnEvent | OnMount | OnUnmount => return Ok(NativeResult::Return(Value::Nil)),
|
||||
Click | Dispatch => {
|
||||
let desktop = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?
|
||||
.desktop;
|
||||
let (event, mount) = if matches!(self.operation, Click) {
|
||||
let definition = desktop_type(cx.store(), "Event", desktop)?;
|
||||
(
|
||||
crate::event_dispatch::new_event(cx, definition, "click")?,
|
||||
args.first(),
|
||||
)
|
||||
} else {
|
||||
(object(args.first())?, args.get(1))
|
||||
};
|
||||
let mount = mount.map(|value| object(Some(value))).transpose()?;
|
||||
return crate::event_dispatch::dispatch(cx, owner, event, mount, desktop);
|
||||
}
|
||||
_ => return Err(invalid("unsupported Block operation")),
|
||||
}
|
||||
cx.replace_payload(data_ref, data)?;
|
||||
Ok(NativeResult::Return(result))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
//! Canonical contracts for native Block methods and constructors.
|
||||
use super::*;
|
||||
|
||||
pub(super) fn method_signature(
|
||||
store: &endor_core::ObjectStore,
|
||||
desktop: ObjectRef,
|
||||
receiver: ObjectRef,
|
||||
operation: Operation,
|
||||
) -> Result<CallSignature, VmError> {
|
||||
use AnnotationType::{Any, Function, Nominal, Number, String as TextType, Unit};
|
||||
use Operation::*;
|
||||
let nominal = |name| desktop_type(store, name, desktop).map(Nominal);
|
||||
let (arguments, returns, effect) = match operation {
|
||||
Bind => (
|
||||
vec![TextType, Function],
|
||||
nominal("Subscription")?,
|
||||
CallEffect::Mutating,
|
||||
),
|
||||
Mounts => (vec![], nominal("ObjectList")?, CallEffect::ReadOnly),
|
||||
Children => (vec![], Any, CallEffect::ReadOnly),
|
||||
Invalidate => (vec![TextType], Unit, CallEffect::Mutating),
|
||||
SetText | SetColor => (vec![TextType], Unit, CallEffect::Mutating),
|
||||
Append => (vec![nominal("Block")?], Number, CallEffect::Mutating),
|
||||
Insert => (
|
||||
vec![Number, nominal("Block")?],
|
||||
Number,
|
||||
CallEffect::Mutating,
|
||||
),
|
||||
Remove => (vec![Number], Unit, CallEffect::Mutating),
|
||||
Replace => (vec![Number, nominal("Block")?], Unit, CallEffect::Mutating),
|
||||
Move => (vec![Number, Number], Unit, CallEffect::Mutating),
|
||||
Render | Navigate => (vec![nominal("Block")?], Unit, CallEffect::Mutating),
|
||||
OnClick => (vec![Function], Nominal(receiver), CallEffect::Mutating),
|
||||
OnEvent => (vec![nominal("Event")?], Unit, CallEffect::External),
|
||||
OnMount | OnUnmount => (vec![nominal("Mount")?], Unit, CallEffect::External),
|
||||
Click => (
|
||||
vec![nominal("Mount")?],
|
||||
nominal("Event")?,
|
||||
CallEffect::External,
|
||||
),
|
||||
Dispatch => (
|
||||
vec![nominal("Event")?, nominal("Mount")?],
|
||||
nominal("Event")?,
|
||||
CallEffect::External,
|
||||
),
|
||||
MoveWindow => (
|
||||
vec![nominal("Window")?],
|
||||
Nominal(receiver),
|
||||
CallEffect::Mutating,
|
||||
),
|
||||
MoveTab => (vec![Number], Nominal(receiver), CallEffect::Mutating),
|
||||
Activate => (vec![], Nominal(receiver), CallEffect::Mutating),
|
||||
Detach => (vec![], nominal("Window")?, CallEffect::Mutating),
|
||||
Unmount | Close | CloseWindow | Back | Forward => (vec![], Unit, CallEffect::Mutating),
|
||||
Open => (vec![Any], Nominal(receiver), CallEffect::Mutating),
|
||||
PageWindow => (vec![], Any, CallEffect::ReadOnly),
|
||||
On => (
|
||||
vec![TextType, Function, Any],
|
||||
nominal("Subscription")?,
|
||||
CallEffect::Mutating,
|
||||
),
|
||||
_ => return Err(invalid("unsupported native method signature")),
|
||||
};
|
||||
let arity = operation.arity();
|
||||
let mut parameters = vec![Nominal(receiver)];
|
||||
parameters.extend(arguments);
|
||||
let mut signature = CallSignature {
|
||||
arity: endor_core::CallArity::range(arity.required + 1, arity.maximum + 1),
|
||||
parameters: parameters.into_iter().map(CallType::from).collect(),
|
||||
variadic: None,
|
||||
returns: returns.into(),
|
||||
effect,
|
||||
};
|
||||
match operation {
|
||||
Open => signature.parameters[1] = CallType::nullable(nominal("Window")?),
|
||||
PageWindow => signature.returns = CallType::nullable(nominal("Window")?),
|
||||
On => signature.parameters[3] = CallType::Union(vec![AnnotationType::Bool, TextType]),
|
||||
_ => {}
|
||||
}
|
||||
Ok(signature)
|
||||
}
|
||||
|
||||
pub(super) fn operation_signature(
|
||||
store: &endor_core::ObjectStore,
|
||||
desktop: ObjectRef,
|
||||
operation: Operation,
|
||||
) -> Result<CallSignature, VmError> {
|
||||
use AnnotationType::{Any, Bool, Number, String as TextType, Trait, Type, Unit};
|
||||
use Operation::*;
|
||||
let nominal = |name| desktop_type(store, name, desktop).map(AnnotationType::Nominal);
|
||||
let (parameters, variadic, returns, effect) = match operation {
|
||||
IsInstance => (vec![Any, Type], None, Bool, CallEffect::ReadOnly),
|
||||
IsSubtype => (vec![Type, Type], None, Bool, CallEffect::ReadOnly),
|
||||
Implement => (vec![Type, Trait], None, Unit, CallEffect::Mutating),
|
||||
Implements => (vec![Type, Trait], None, Bool, CallEffect::ReadOnly),
|
||||
Supports => (vec![Any, Trait], None, Bool, CallEffect::ReadOnly),
|
||||
OpenValue => (vec![Any], None, nominal("Page")?, CallEffect::Mutating),
|
||||
Present => (vec![Any], None, nominal("Block")?, CallEffect::Delegated),
|
||||
State => (vec![Any], None, Any, CallEffect::ReadOnly),
|
||||
StateSet => (vec![Any], None, Unit, CallEffect::Mutating),
|
||||
Increment => (vec![], None, Unit, CallEffect::Mutating),
|
||||
Stats => (vec![], None, Any, CallEffect::External),
|
||||
Viewport => (
|
||||
vec![],
|
||||
None,
|
||||
nominal("MeasureResult")?,
|
||||
CallEffect::ReadOnly,
|
||||
),
|
||||
Window => (vec![], None, nominal("Window")?, CallEffect::ReadOnly),
|
||||
NewWindow => (vec![], None, nominal("Window")?, CallEffect::Mutating),
|
||||
TextOf => (
|
||||
vec![Any, TextType, Number, TextType],
|
||||
None,
|
||||
nominal("TextBlock")?,
|
||||
CallEffect::ReadOnly,
|
||||
),
|
||||
Text => (
|
||||
vec![TextType, Number, TextType],
|
||||
None,
|
||||
nominal("TextBlock")?,
|
||||
CallEffect::ReadOnly,
|
||||
),
|
||||
Rect => (
|
||||
vec![Number, Number, Number, TextType],
|
||||
None,
|
||||
nominal("RectBlock")?,
|
||||
CallEffect::ReadOnly,
|
||||
),
|
||||
Spacer => (vec![Number], None, nominal("Spacer")?, CallEffect::ReadOnly),
|
||||
Scroll => (
|
||||
vec![Number, Number, nominal("Block")?],
|
||||
None,
|
||||
nominal("ScrollBlock")?,
|
||||
CallEffect::ReadOnly,
|
||||
),
|
||||
Row | Column => (
|
||||
vec![Number, Number],
|
||||
Some(nominal("Block")?),
|
||||
nominal(if matches!(operation, Row) {
|
||||
"Row"
|
||||
} else {
|
||||
"Column"
|
||||
})?,
|
||||
CallEffect::ReadOnly,
|
||||
),
|
||||
Button => (
|
||||
vec![TextType],
|
||||
None,
|
||||
nominal("Button")?,
|
||||
CallEffect::ReadOnly,
|
||||
),
|
||||
Page => (vec![], None, nominal("Page")?, CallEffect::ReadOnly),
|
||||
_ => return Err(invalid("unsupported UI function signature")),
|
||||
};
|
||||
Ok(CallSignature {
|
||||
arity: operation.arity(),
|
||||
parameters: parameters.into_iter().map(CallType::from).collect(),
|
||||
variadic: variadic.map(CallType::from),
|
||||
returns: returns.into(),
|
||||
effect,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
//! Owned immutable visual derivation; no managed VM handles.
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct UiNode {
|
||||
pub flex: f32,
|
||||
pub flex_policy: crate::layout::FlexPolicy,
|
||||
pub main_align: crate::layout::MainAlign,
|
||||
pub block_id: String,
|
||||
pub protocol_key: String,
|
||||
pub slots: Vec<u64>,
|
||||
pub interactive: bool,
|
||||
pub kind: UiKind,
|
||||
}
|
||||
|
||||
impl UiNode {
|
||||
pub fn children(&self) -> &[Arc<UiNode>] {
|
||||
match &self.kind {
|
||||
UiKind::Column { children, .. }
|
||||
| UiKind::Row { children, .. }
|
||||
| UiKind::Button { children, .. }
|
||||
| UiKind::Scroll { children, .. } => children,
|
||||
_ => &[],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_flex(&self) -> bool {
|
||||
self.flex > 0.0 || self.flex_policy != crate::layout::FlexPolicy::default()
|
||||
}
|
||||
|
||||
pub fn shallow_eq(&self, other: &Self) -> bool {
|
||||
if self.flex_policy != other.flex_policy
|
||||
|| self.flex != other.flex
|
||||
|| self.main_align != other.main_align
|
||||
|| self.block_id != other.block_id
|
||||
|| self.protocol_key != other.protocol_key
|
||||
|| self.slots != other.slots
|
||||
|| self.interactive != other.interactive
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let same_children = || {
|
||||
self.children().len() == other.children().len()
|
||||
&& self
|
||||
.children()
|
||||
.iter()
|
||||
.zip(other.children())
|
||||
.all(|(a, b)| Arc::ptr_eq(a, b))
|
||||
};
|
||||
match (&self.kind, &other.kind) {
|
||||
(
|
||||
UiKind::Text {
|
||||
value: a,
|
||||
size: sa,
|
||||
color: ca,
|
||||
},
|
||||
UiKind::Text {
|
||||
value: b,
|
||||
size: sb,
|
||||
color: cb,
|
||||
},
|
||||
) => a == b && sa == sb && ca == cb,
|
||||
(
|
||||
UiKind::Rect {
|
||||
width: a,
|
||||
height: b,
|
||||
radius: c,
|
||||
color: d,
|
||||
},
|
||||
UiKind::Rect {
|
||||
width: e,
|
||||
height: f,
|
||||
radius: g,
|
||||
color: h,
|
||||
},
|
||||
) => (a, b, c, d) == (e, f, g, h),
|
||||
(UiKind::Spacer(a), UiKind::Spacer(b)) => a == b,
|
||||
(
|
||||
UiKind::Scroll {
|
||||
axis: aa,
|
||||
width: a,
|
||||
height: b,
|
||||
padding: pa,
|
||||
gap: ga,
|
||||
children: _,
|
||||
},
|
||||
UiKind::Scroll {
|
||||
axis: ab,
|
||||
width: c,
|
||||
height: d,
|
||||
padding: pb,
|
||||
gap: gb,
|
||||
children: _,
|
||||
},
|
||||
) => aa == ab && a == c && b == d && pa == pb && ga == gb && same_children(),
|
||||
(
|
||||
UiKind::Column {
|
||||
padding: a, gap: b, ..
|
||||
},
|
||||
UiKind::Column {
|
||||
padding: c, gap: d, ..
|
||||
},
|
||||
)
|
||||
| (
|
||||
UiKind::Row {
|
||||
padding: a, gap: b, ..
|
||||
},
|
||||
UiKind::Row {
|
||||
padding: c, gap: d, ..
|
||||
},
|
||||
)
|
||||
| (
|
||||
UiKind::Button {
|
||||
padding: a, gap: b, ..
|
||||
},
|
||||
UiKind::Button {
|
||||
padding: c, gap: d, ..
|
||||
},
|
||||
) => a == c && b == d && same_children(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum UiKind {
|
||||
Button {
|
||||
padding: f32,
|
||||
gap: f32,
|
||||
children: Vec<Arc<UiNode>>,
|
||||
},
|
||||
Text {
|
||||
value: String,
|
||||
size: u32,
|
||||
color: String,
|
||||
},
|
||||
Rect {
|
||||
width: f32,
|
||||
height: f32,
|
||||
radius: f32,
|
||||
color: String,
|
||||
},
|
||||
Column {
|
||||
padding: f32,
|
||||
gap: f32,
|
||||
children: Vec<Arc<UiNode>>,
|
||||
},
|
||||
Row {
|
||||
padding: f32,
|
||||
gap: f32,
|
||||
children: Vec<Arc<UiNode>>,
|
||||
},
|
||||
Spacer(f32),
|
||||
Scroll {
|
||||
axis: crate::scroll::Axis,
|
||||
width: f32,
|
||||
height: f32,
|
||||
padding: f32,
|
||||
gap: f32,
|
||||
children: Vec<Arc<UiNode>>,
|
||||
},
|
||||
}
|
||||
+21
-37
@@ -1,41 +1,25 @@
|
||||
mod activity;
|
||||
mod api;
|
||||
mod app;
|
||||
mod binding;
|
||||
mod block;
|
||||
mod clipboard;
|
||||
mod developer_tools;
|
||||
mod display_list;
|
||||
mod document;
|
||||
mod endor_host;
|
||||
mod endor_script;
|
||||
mod event_dispatch;
|
||||
mod events;
|
||||
mod geometry;
|
||||
mod io_tasks;
|
||||
mod layout;
|
||||
mod mount;
|
||||
//! Application composition root. Directory modules own implementation; these
|
||||
//! crate-private aliases keep existing internal paths stable during reorganization.
|
||||
mod bridge;
|
||||
mod model;
|
||||
mod render;
|
||||
mod runtime;
|
||||
mod shell;
|
||||
|
||||
pub(crate) use bridge::ui_bridge;
|
||||
pub(crate) use model::{
|
||||
binding, block, document, mount, object_list, presentation, protocols, snapshot, window,
|
||||
};
|
||||
pub(crate) use render::{
|
||||
display_list, geometry, layout, native_visual, scene, scroll, software_renderer, source_hit,
|
||||
source_layout, source_paint, text,
|
||||
};
|
||||
pub(crate) use runtime::{
|
||||
api, endor_host, endor_script, event_dispatch, events, io_tasks, tasks, vm_sequence,
|
||||
};
|
||||
#[cfg(target_os = "macos")]
|
||||
mod native_chrome;
|
||||
mod native_visual;
|
||||
mod object_list;
|
||||
mod presentation;
|
||||
mod protocols;
|
||||
mod scene;
|
||||
mod scroll;
|
||||
mod snapshot;
|
||||
mod software_renderer;
|
||||
mod source_hit;
|
||||
mod source_layout;
|
||||
mod source_paint;
|
||||
mod sources;
|
||||
mod system_ui;
|
||||
mod tabs;
|
||||
mod tasks;
|
||||
mod text;
|
||||
mod ui_bridge;
|
||||
mod vm_sequence;
|
||||
mod window;
|
||||
pub(crate) use shell::native_chrome;
|
||||
pub(crate) use shell::{activity, app, clipboard, developer_tools, sources, system_ui, tabs};
|
||||
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// Module ownership follows the directory; crate-root aliases keep internal call sites stable.
|
||||
pub(crate) mod binding;
|
||||
pub(crate) mod block;
|
||||
pub(crate) mod document;
|
||||
pub(crate) mod mount;
|
||||
pub(crate) mod object_list;
|
||||
pub(crate) mod presentation;
|
||||
pub(crate) mod protocols;
|
||||
pub(crate) mod snapshot;
|
||||
pub(crate) mod window;
|
||||
@@ -0,0 +1,12 @@
|
||||
// Module ownership follows the directory; crate-root aliases keep internal call sites stable.
|
||||
pub(crate) mod display_list;
|
||||
pub(crate) mod geometry;
|
||||
pub(crate) mod layout;
|
||||
pub(crate) mod native_visual;
|
||||
pub(crate) mod scene;
|
||||
pub(crate) mod scroll;
|
||||
pub(crate) mod software_renderer;
|
||||
pub(crate) mod source_hit;
|
||||
pub(crate) mod source_layout;
|
||||
pub(crate) mod source_paint;
|
||||
pub(crate) mod text;
|
||||
@@ -0,0 +1,680 @@
|
||||
mod guide;
|
||||
mod worker;
|
||||
|
||||
use guide::agent_guide;
|
||||
use worker::{PendingRequest, RequestProgress, Worker};
|
||||
|
||||
use std::{
|
||||
io::Read,
|
||||
ops::{Deref, DerefMut},
|
||||
panic::{AssertUnwindSafe, catch_unwind},
|
||||
sync::{
|
||||
Arc, RwLock,
|
||||
mpsc::{Receiver, SyncSender, TrySendError, sync_channel},
|
||||
},
|
||||
sync::{
|
||||
Condvar, Mutex,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
},
|
||||
thread,
|
||||
};
|
||||
|
||||
use anyhow::{Context as _, Result};
|
||||
use tiny_http::{Header, Method, Request, Response, Server, StatusCode};
|
||||
use winit::event_loop::EventLoopProxy;
|
||||
|
||||
use crate::{
|
||||
activity::{Activity, ActivityLog},
|
||||
app::AppEvent,
|
||||
document::NamespaceState,
|
||||
endor_host,
|
||||
};
|
||||
|
||||
pub const API_ADDRESS: &str = "127.0.0.1:4737";
|
||||
const MAX_CODE_SIZE: u64 = endor_host::MAX_SOURCE_BYTES as u64;
|
||||
type Notify = Arc<dyn Fn() + Send + Sync>;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ShutdownOutcome {
|
||||
pub summary: String,
|
||||
pub error: Option<String>,
|
||||
}
|
||||
type ShutdownCompletion = Arc<(Mutex<Option<ShutdownOutcome>>, Condvar)>;
|
||||
#[derive(Clone)]
|
||||
pub struct RuntimeControl {
|
||||
sender: SyncSender<()>,
|
||||
requested: Arc<AtomicBool>,
|
||||
completion: ShutdownCompletion,
|
||||
}
|
||||
impl RuntimeControl {
|
||||
pub fn request_shutdown(&self) -> bool {
|
||||
if self.requested.swap(true, Ordering::AcqRel) {
|
||||
return true;
|
||||
}
|
||||
if self.sender.try_send(()).is_ok() {
|
||||
true
|
||||
} else {
|
||||
self.requested.store(false, Ordering::Release);
|
||||
false
|
||||
}
|
||||
}
|
||||
pub fn is_exiting(&self) -> bool {
|
||||
self.requested.load(Ordering::Acquire)
|
||||
}
|
||||
pub fn wait_shutdown(&self, timeout: std::time::Duration) -> Option<ShutdownOutcome> {
|
||||
let (lock, ready) = &*self.completion;
|
||||
let result = lock.lock().ok()?;
|
||||
let (result, _) = ready
|
||||
.wait_timeout_while(result, timeout, |result| result.is_none())
|
||||
.ok()?;
|
||||
result.clone()
|
||||
}
|
||||
}
|
||||
struct Shutdown {
|
||||
receiver: Receiver<()>,
|
||||
control: RuntimeControl,
|
||||
proxy: EventLoopProxy<AppEvent>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum RequestKind {
|
||||
Event,
|
||||
Code,
|
||||
Expression,
|
||||
Repl,
|
||||
ResetRepl,
|
||||
}
|
||||
|
||||
struct BuildRequest {
|
||||
request: ObservedRequest,
|
||||
kind: RequestKind,
|
||||
source: String,
|
||||
namespace: String,
|
||||
submission: u64,
|
||||
}
|
||||
|
||||
pub fn start(
|
||||
namespace: Arc<RwLock<NamespaceState>>,
|
||||
proxy: EventLoopProxy<AppEvent>,
|
||||
) -> Result<(Activity, RuntimeControl)> {
|
||||
let (sender, receiver) = sync_channel(1);
|
||||
let control = RuntimeControl {
|
||||
sender,
|
||||
requested: Arc::new(AtomicBool::new(false)),
|
||||
completion: Arc::new((Mutex::new(None), Condvar::new())),
|
||||
};
|
||||
let shutdown = Shutdown {
|
||||
receiver,
|
||||
control: control.clone(),
|
||||
proxy: proxy.clone(),
|
||||
};
|
||||
let server = Server::http(API_ADDRESS)
|
||||
.map_err(|error| anyhow::anyhow!(error))
|
||||
.with_context(|| format!("bind Tessera API to {API_ADDRESS}"))?;
|
||||
let notify: Notify = Arc::new(move || {
|
||||
let _ = proxy.send_event(AppEvent::DocumentUpdated);
|
||||
});
|
||||
let activity = Arc::new(Mutex::new(ActivityLog::default()));
|
||||
start_server_observed(
|
||||
Arc::new(server),
|
||||
namespace,
|
||||
notify.clone(),
|
||||
activity.clone(),
|
||||
notify,
|
||||
Some(shutdown),
|
||||
)?;
|
||||
Ok((activity, control))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn start_server(
|
||||
server: Arc<Server>,
|
||||
namespace: Arc<RwLock<NamespaceState>>,
|
||||
notify: Notify,
|
||||
) -> Result<thread::JoinHandle<()>> {
|
||||
start_server_observed(
|
||||
server,
|
||||
namespace,
|
||||
notify,
|
||||
Arc::new(Mutex::new(ActivityLog::default())),
|
||||
Arc::new(|| {}),
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
fn start_server_observed(
|
||||
server: Arc<Server>,
|
||||
namespace: Arc<RwLock<NamespaceState>>,
|
||||
notify: Notify,
|
||||
activity: Activity,
|
||||
observer_notify: Notify,
|
||||
shutdown: Option<Shutdown>,
|
||||
) -> Result<thread::JoinHandle<()>> {
|
||||
let (sender, receiver) = sync_channel::<BuildRequest>(8);
|
||||
let worker_namespace = namespace.clone();
|
||||
let worker_notify = notify.clone();
|
||||
let exiting = shutdown
|
||||
.as_ref()
|
||||
.map(|shutdown| shutdown.control.requested.clone());
|
||||
thread::Builder::new()
|
||||
.name("tessera-endor-worker".into())
|
||||
.spawn(move || {
|
||||
let mut worker = Worker::default();
|
||||
let mut pending: Option<(BuildRequest, PendingRequest)> = None;
|
||||
loop {
|
||||
if let Some(shutdown) = &shutdown
|
||||
&& shutdown.receiver.try_recv().is_ok()
|
||||
{
|
||||
if let Some((job, input)) = pending.take() {
|
||||
drop(input);
|
||||
let _ = job
|
||||
.request
|
||||
.respond(error_response(StatusCode(503), "application is exiting"));
|
||||
}
|
||||
let outcome = worker.shutdown_runtime();
|
||||
while let Ok(job) = receiver.try_recv() {
|
||||
let _ = job
|
||||
.request
|
||||
.respond(error_response(StatusCode(503), "application is exiting"));
|
||||
}
|
||||
if let Ok(mut current) = worker_namespace.write() {
|
||||
current.runtime_session = 0;
|
||||
current.window_commands.clear();
|
||||
current.document.frame.session = 0;
|
||||
current.document.frame.focus = None;
|
||||
for view in current.document.windows.values_mut() {
|
||||
view.frame.session = 0;
|
||||
view.frame.focus = None;
|
||||
}
|
||||
}
|
||||
eprintln!("{}", outcome.summary);
|
||||
let (lock, ready) = &*shutdown.control.completion;
|
||||
if let Ok(mut result) = lock.lock() {
|
||||
*result = Some(outcome.clone());
|
||||
ready.notify_all();
|
||||
}
|
||||
let _ = shutdown.proxy.send_event(AppEvent::ShutdownComplete {
|
||||
error: outcome.error,
|
||||
});
|
||||
break;
|
||||
}
|
||||
if let Some((job, input)) = pending.take() {
|
||||
match worker.resume_request(&job, input, &worker_namespace, &worker_notify) {
|
||||
RequestProgress::Pending(input) => {
|
||||
pending = Some((job, input));
|
||||
// A soft VM quantum is a control boundary, not a
|
||||
// minimum-duration time slice. Yield to other ready
|
||||
// threads without charging a timer delay per quantum.
|
||||
thread::yield_now();
|
||||
}
|
||||
RequestProgress::Complete(response) => {
|
||||
let _ = job.request.respond(response);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
worker.refresh_viewport(&worker_namespace, &worker_notify);
|
||||
let wait = if worker.repl.as_ref().is_some_and(|(_, runtime)| {
|
||||
runtime.has_pending_refresh() || runtime.has_cooperative_tasks()
|
||||
}) {
|
||||
std::time::Duration::ZERO
|
||||
} else {
|
||||
std::time::Duration::from_millis(100)
|
||||
};
|
||||
match receiver.recv_timeout(wait) {
|
||||
Ok(job) => {
|
||||
match worker.begin_request(&job, &worker_namespace, &worker_notify) {
|
||||
RequestProgress::Pending(input) => {
|
||||
if matches!(&input, PendingRequest::BeforeInput) {
|
||||
eprintln!(
|
||||
"Tessera worker: submission {} waits for active refresh",
|
||||
job.submission
|
||||
);
|
||||
}
|
||||
pending = Some((job, input));
|
||||
}
|
||||
RequestProgress::Complete(response) => {
|
||||
let _ = job.request.respond(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(std::sync::mpsc::RecvTimeoutError::Disconnected) => break,
|
||||
Err(std::sync::mpsc::RecvTimeoutError::Timeout) => {
|
||||
if worker.repl.as_ref().is_some_and(|(epoch, runtime)| {
|
||||
worker_namespace.read().is_ok_and(|current| {
|
||||
current.submission != *epoch
|
||||
&& current.runtime_session != runtime.id
|
||||
})
|
||||
}) {
|
||||
worker.repl = None;
|
||||
}
|
||||
if wait.is_zero() {
|
||||
thread::yield_now();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.context("start Aster execution worker")?;
|
||||
thread::Builder::new()
|
||||
.name("tessera-agent-api".to_owned())
|
||||
.spawn(move || {
|
||||
for request in server.incoming_requests() {
|
||||
if exiting
|
||||
.as_ref()
|
||||
.is_some_and(|flag| flag.load(Ordering::Acquire))
|
||||
&& !matches!(request.method(), Method::Get | Method::Options)
|
||||
{
|
||||
let _ =
|
||||
request.respond(error_response(StatusCode(503), "application is exiting"));
|
||||
continue;
|
||||
}
|
||||
handle(
|
||||
request,
|
||||
&namespace,
|
||||
¬ify,
|
||||
&sender,
|
||||
&activity,
|
||||
&observer_notify,
|
||||
);
|
||||
}
|
||||
})
|
||||
.context("start Tessera agent API thread")
|
||||
}
|
||||
|
||||
// Capture only allowlisted headers: credentials and cookies never enter the inspector.
|
||||
struct ObservedRequest {
|
||||
inner: Request,
|
||||
activity: Activity,
|
||||
id: u64,
|
||||
notify: Notify,
|
||||
}
|
||||
impl ObservedRequest {
|
||||
fn new(inner: Request, activity: Activity, notify: Notify) -> Self {
|
||||
let headers = inner
|
||||
.headers()
|
||||
.iter()
|
||||
.filter(|h| h.field.equiv("Content-Type") || h.field.equiv("Content-Length"))
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
let origin = if inner
|
||||
.headers()
|
||||
.iter()
|
||||
.any(|h| h.field.equiv("X-Tessera-Origin") && h.value.as_str() == "console")
|
||||
{
|
||||
"Console"
|
||||
} else {
|
||||
"HTTP"
|
||||
}
|
||||
.to_owned();
|
||||
let id = activity.lock().unwrap().begin(
|
||||
inner.method().to_string(),
|
||||
inner.url().to_owned(),
|
||||
origin,
|
||||
headers,
|
||||
);
|
||||
notify();
|
||||
Self {
|
||||
inner,
|
||||
activity,
|
||||
id,
|
||||
notify,
|
||||
}
|
||||
}
|
||||
fn record_body(&self, body: &str) {
|
||||
self.activity.lock().unwrap().body(self.id, body);
|
||||
(self.notify)();
|
||||
}
|
||||
fn respond(self, response: Response<std::io::Cursor<Vec<u8>>>) -> std::io::Result<()> {
|
||||
let status = response.status_code();
|
||||
let headers = response.headers().to_vec();
|
||||
let length = response.data_length();
|
||||
let reader = response.into_reader();
|
||||
self.activity.lock().unwrap().finish(
|
||||
self.id,
|
||||
status.0,
|
||||
&String::from_utf8_lossy(reader.get_ref()),
|
||||
headers
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
);
|
||||
(self.notify)();
|
||||
self.inner
|
||||
.respond(Response::new(status, headers, reader, length, None))
|
||||
}
|
||||
}
|
||||
impl Deref for ObservedRequest {
|
||||
type Target = Request;
|
||||
fn deref(&self) -> &Request {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
impl DerefMut for ObservedRequest {
|
||||
fn deref_mut(&mut self) -> &mut Request {
|
||||
&mut self.inner
|
||||
}
|
||||
}
|
||||
|
||||
fn handle(
|
||||
request: Request,
|
||||
namespace: &Arc<RwLock<NamespaceState>>,
|
||||
notify: &Notify,
|
||||
sender: &SyncSender<BuildRequest>,
|
||||
activity: &Activity,
|
||||
observer_notify: &Notify,
|
||||
) {
|
||||
let request = ObservedRequest::new(request, activity.clone(), observer_notify.clone());
|
||||
let method = request.method().clone();
|
||||
let path = request
|
||||
.url()
|
||||
.split('?')
|
||||
.next()
|
||||
.unwrap_or(request.url())
|
||||
.to_owned();
|
||||
|
||||
let evaluation = namespace_from_route(&path, "/evaluate");
|
||||
let repl = namespace_from_route(&path, "/repl");
|
||||
let event = namespace_from_route(&path, "/events");
|
||||
let route = if method == Method::Put {
|
||||
namespace_from_path(&path).map(|name| (name, RequestKind::Code))
|
||||
} else if method == Method::Post {
|
||||
event
|
||||
.map(|name| (name, RequestKind::Event))
|
||||
.or_else(|| repl.map(|name| (name, RequestKind::Repl)))
|
||||
.or(evaluation.map(|name| (name, RequestKind::Expression)))
|
||||
} else if method == Method::Delete {
|
||||
repl.map(|name| (name, RequestKind::ResetRepl))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some((addressed, kind)) = route {
|
||||
submit(request, addressed, namespace, sender, kind);
|
||||
return;
|
||||
}
|
||||
let response = if method == Method::Get && path == "/agent" {
|
||||
match namespace.read() {
|
||||
Ok(namespace) => markdown(StatusCode(200), agent_guide(&namespace)),
|
||||
Err(_) => error_response(StatusCode(500), "namespace lock is poisoned"),
|
||||
}
|
||||
} else if let Some(addressed_namespace) = namespace_from_path(&path).map(str::to_owned) {
|
||||
code_request(method, &addressed_namespace, namespace, notify)
|
||||
} else if method == Method::Options {
|
||||
text(StatusCode(204), "", "text/plain")
|
||||
} else {
|
||||
error_response(StatusCode(404), "route not found; start with GET /agent")
|
||||
};
|
||||
|
||||
let _ = request.respond(response);
|
||||
}
|
||||
|
||||
fn code_request(
|
||||
method: Method,
|
||||
addressed_namespace: &str,
|
||||
namespace: &Arc<RwLock<NamespaceState>>,
|
||||
notify: &Notify,
|
||||
) -> Response<std::io::Cursor<Vec<u8>>> {
|
||||
let Ok(current) = namespace.read() else {
|
||||
return error_response(StatusCode(500), "namespace lock is poisoned");
|
||||
};
|
||||
if addressed_namespace != current.name {
|
||||
return error_response(
|
||||
StatusCode(404),
|
||||
format!(
|
||||
"namespace `{addressed_namespace}` is not active; current namespace is `{}`",
|
||||
current.name
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if method == Method::Get {
|
||||
let mut response = text(
|
||||
StatusCode(200),
|
||||
¤t.document.source,
|
||||
"text/plain; charset=utf-8",
|
||||
);
|
||||
add_header(
|
||||
&mut response,
|
||||
"X-Tessera-Revision",
|
||||
¤t.revision.to_string(),
|
||||
);
|
||||
add_header(
|
||||
&mut response,
|
||||
"X-Tessera-Session",
|
||||
¤t.document.frame.session.to_string(),
|
||||
);
|
||||
add_header(
|
||||
&mut response,
|
||||
"X-Tessera-Window",
|
||||
¤t.document.frame.window.to_string(),
|
||||
);
|
||||
add_header(
|
||||
&mut response,
|
||||
"X-Tessera-Layout-Version",
|
||||
¤t.document.frame.layout_version.to_string(),
|
||||
);
|
||||
if let Some(viewport) = current.viewport {
|
||||
add_header(
|
||||
&mut response,
|
||||
"X-Tessera-Viewport-Width",
|
||||
&viewport.width.to_string(),
|
||||
);
|
||||
add_header(
|
||||
&mut response,
|
||||
"X-Tessera-Viewport-Height",
|
||||
&viewport.height.to_string(),
|
||||
);
|
||||
}
|
||||
add_header(
|
||||
&mut response,
|
||||
"X-Tessera-Source-Kind",
|
||||
if current
|
||||
.document
|
||||
.root
|
||||
.as_ref()
|
||||
.is_some_and(|root| root.kind == "repl-session")
|
||||
{
|
||||
"repl-transcript"
|
||||
} else {
|
||||
"source-snapshot"
|
||||
},
|
||||
);
|
||||
return response;
|
||||
}
|
||||
drop(current);
|
||||
|
||||
match method {
|
||||
Method::Delete => match namespace.write() {
|
||||
Ok(mut current) => {
|
||||
let revision = match current.clear() {
|
||||
Ok(revision) => revision,
|
||||
Err(error) => return error_response(StatusCode(500), error.to_string()),
|
||||
};
|
||||
drop(current);
|
||||
notify();
|
||||
json(
|
||||
StatusCode(200),
|
||||
serde_json::json!({
|
||||
"ok": true,
|
||||
"namespace": addressed_namespace,
|
||||
"revision": revision
|
||||
}),
|
||||
)
|
||||
}
|
||||
Err(_) => error_response(StatusCode(500), "namespace lock is poisoned"),
|
||||
},
|
||||
Method::Options => text(StatusCode(204), "", "text/plain"),
|
||||
_ => error_response(StatusCode(405), "code supports GET, PUT, and DELETE"),
|
||||
}
|
||||
}
|
||||
|
||||
fn submit(
|
||||
mut request: ObservedRequest,
|
||||
addressed: &str,
|
||||
namespace: &Arc<RwLock<NamespaceState>>,
|
||||
sender: &SyncSender<BuildRequest>,
|
||||
kind: RequestKind,
|
||||
) {
|
||||
let source = match read_code(&mut request) {
|
||||
Ok(source) => source,
|
||||
Err(error) => {
|
||||
let _ = request.respond(error_response(StatusCode(400), error.to_string()));
|
||||
return;
|
||||
}
|
||||
};
|
||||
request.record_body(&source);
|
||||
let Ok(mut current) = namespace.write() else {
|
||||
let _ = request.respond(error_response(
|
||||
StatusCode(500),
|
||||
"namespace lock is poisoned",
|
||||
));
|
||||
return;
|
||||
};
|
||||
if current.name != addressed {
|
||||
let _ = request.respond(error_response(StatusCode(404), "namespace is not active"));
|
||||
return;
|
||||
}
|
||||
let submission = match if kind == RequestKind::Code {
|
||||
current.next_submission()
|
||||
} else {
|
||||
Ok(current.submission)
|
||||
} {
|
||||
Ok(id) => id,
|
||||
Err(error) => {
|
||||
let _ = request.respond(error_response(StatusCode(500), error.to_string()));
|
||||
return;
|
||||
}
|
||||
};
|
||||
let job = BuildRequest {
|
||||
request,
|
||||
kind,
|
||||
source,
|
||||
namespace: addressed.into(),
|
||||
submission,
|
||||
};
|
||||
match sender.try_send(job) {
|
||||
// A rejected queue entry never invalidates accepted work. The worker
|
||||
// uses this same lock when committing, so publication is atomic.
|
||||
Ok(()) => {
|
||||
if kind == RequestKind::Code {
|
||||
current.submission = submission;
|
||||
}
|
||||
}
|
||||
Err(TrySendError::Full(job)) => {
|
||||
let _ = job
|
||||
.request
|
||||
.respond(error_response(StatusCode(503), "build queue is full"));
|
||||
}
|
||||
Err(TrySendError::Disconnected(job)) => {
|
||||
let _ = job.request.respond(error_response(
|
||||
StatusCode(503),
|
||||
"execution worker is unavailable",
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn superseded(submission: u64) -> Response<std::io::Cursor<Vec<u8>>> {
|
||||
json(
|
||||
StatusCode(409),
|
||||
serde_json::json!({ "ok": false, "submission": submission,
|
||||
"error": "submission superseded by a newer PUT or DELETE" }),
|
||||
)
|
||||
}
|
||||
|
||||
fn namespace_from_route<'a>(path: &'a str, suffix: &str) -> Option<&'a str> {
|
||||
path.strip_prefix("/v1/namespaces/")?
|
||||
.strip_suffix(suffix)
|
||||
.filter(|namespace| !namespace.is_empty() && !namespace.contains('/'))
|
||||
}
|
||||
fn namespace_from_path(path: &str) -> Option<&str> {
|
||||
namespace_from_route(path, "/code")
|
||||
}
|
||||
|
||||
fn read_code(request: &mut Request) -> Result<String> {
|
||||
if request
|
||||
.body_length()
|
||||
.is_some_and(|length| length as u64 > MAX_CODE_SIZE)
|
||||
{
|
||||
anyhow::bail!("code exceeds the 1 MiB limit");
|
||||
}
|
||||
let mut code = String::new();
|
||||
request
|
||||
.as_reader()
|
||||
.take(MAX_CODE_SIZE + 1)
|
||||
.read_to_string(&mut code)
|
||||
.context("read code")?;
|
||||
if code.len() as u64 > MAX_CODE_SIZE {
|
||||
anyhow::bail!("code exceeds the 1 MiB limit");
|
||||
}
|
||||
Ok(code)
|
||||
}
|
||||
|
||||
fn compile_error(error: anyhow::Error) -> Response<std::io::Cursor<Vec<u8>>> {
|
||||
let mut diagnostic =
|
||||
serde_json::json!({ "severity": "error", "message": format!("{error:#}") });
|
||||
if let Some(source) = error.downcast_ref::<frontend::SourceDiagnostic>() {
|
||||
diagnostic["line"] = source.location.line.into();
|
||||
diagnostic["column"] = source.location.column.into();
|
||||
diagnostic["start_byte"] = source.diagnostic.span.start.into();
|
||||
diagnostic["end_byte"] = source.diagnostic.span.end.into();
|
||||
}
|
||||
json(
|
||||
StatusCode(422),
|
||||
serde_json::json!({
|
||||
"ok": false,
|
||||
"diagnostics": [diagnostic]
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
fn error_response(
|
||||
status: StatusCode,
|
||||
message: impl Into<String>,
|
||||
) -> Response<std::io::Cursor<Vec<u8>>> {
|
||||
json(status, serde_json::json!({ "error": message.into() }))
|
||||
}
|
||||
|
||||
fn json(status: StatusCode, value: serde_json::Value) -> Response<std::io::Cursor<Vec<u8>>> {
|
||||
text(
|
||||
status,
|
||||
&value.to_string(),
|
||||
"application/json; charset=utf-8",
|
||||
)
|
||||
}
|
||||
|
||||
fn markdown(status: StatusCode, value: String) -> Response<std::io::Cursor<Vec<u8>>> {
|
||||
text(status, &value, "text/markdown; charset=utf-8")
|
||||
}
|
||||
|
||||
fn text(status: StatusCode, value: &str, content_type: &str) -> Response<std::io::Cursor<Vec<u8>>> {
|
||||
let mut response = Response::from_string(value).with_status_code(status);
|
||||
add_header(&mut response, "Content-Type", content_type);
|
||||
add_header(
|
||||
&mut response,
|
||||
"Access-Control-Allow-Origin",
|
||||
"http://127.0.0.1",
|
||||
);
|
||||
add_header(
|
||||
&mut response,
|
||||
"Access-Control-Allow-Methods",
|
||||
"GET, PUT, POST, DELETE, OPTIONS",
|
||||
);
|
||||
add_header(
|
||||
&mut response,
|
||||
"Access-Control-Allow-Headers",
|
||||
"Content-Type, X-Tessera-Origin",
|
||||
);
|
||||
response
|
||||
}
|
||||
|
||||
fn add_header(response: &mut Response<std::io::Cursor<Vec<u8>>>, name: &str, value: &str) {
|
||||
if let Ok(header) = Header::from_bytes(name, value) {
|
||||
response.add_header(header);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -0,0 +1,216 @@
|
||||
//! Live agent-facing guide generated from the current namespace.
|
||||
use super::*;
|
||||
|
||||
pub(super) fn agent_guide(namespace: &NamespaceState) -> String {
|
||||
format!(
|
||||
r##"# Tessera Agent API
|
||||
|
||||
Current namespace: `{name}`
|
||||
Current revision: `{revision}`
|
||||
|
||||
Submit an ordinary Endor script. Tessera embeds Aster's frontend, compiler and VM.
|
||||
The namespace comes from the request path. Top-level bindings share the candidate
|
||||
VM's globals; `ui.page().render(root)` selects the visible UI. No main function is
|
||||
required. Typed helper functions and the older main-returning-View form also work.
|
||||
|
||||
## Code CRUD
|
||||
|
||||
- Read: `GET http://{address}/v1/namespaces/{name}/code`
|
||||
- Create or update: `PUT http://{address}/v1/namespaces/{name}/code`
|
||||
- Delete: `DELETE http://{address}/v1/namespaces/{name}/code`
|
||||
|
||||
Send PUT bodies as `text/plain; charset=utf-8`.
|
||||
|
||||
```endor
|
||||
{example}```
|
||||
|
||||
## Live Console session
|
||||
|
||||
`POST http://{address}/v1/namespaces/{name}/repl` accepts statements, function
|
||||
definitions and expressions as text/plain. Consecutive requests use one real VM
|
||||
and globals dictionary on the execution worker. `title = ui.text("Hello")` creates
|
||||
an object without displaying it. A later `page.render(root)` mounts its page. UI references share replacement state: after mounting, assigning a new UI value to a reference updates its aliases and mounted positions. `page.unmount()` releases the mount.
|
||||
`let title = ...` is also supported. `_` retains the actual last value. No input
|
||||
history is replayed. Responses include session/input IDs, value, binding count,
|
||||
rendered flag and revision. Before the first mount the page/revision stay unchanged; afterwards successful inputs publish changed mounted references automatically.
|
||||
|
||||
`DELETE http://{address}/v1/namespaces/{name}/repl` resets Console objects and bindings,
|
||||
leaving the displayed native snapshot intact. Parsing/compilation happen before
|
||||
execution. On runtime error earlier statements in that input may remain live, but
|
||||
its pending render is discarded; previous displayed page is preserved.
|
||||
|
||||
Session limits: 256 executed inputs, 1 MiB transcript, 10000 cumulative AST nodes,
|
||||
4096 retained visual objects and 64 retained pages. Aster collects unreachable objects/cycles between inputs; there is no fixed UI pool. No VM handles cross to the window.
|
||||
A newer accepted complete-source PUT or code DELETE invalidates queued Console inputs. A running input settles before a queued PUT candidate is built; code DELETE revokes that runtime immediately.
|
||||
A successful PUT retains its fresh VM as the live program for Console and GUI events;
|
||||
a failed PUT preserves the previous program. DELETE releases the live context.
|
||||
GET /code returns the source of the displayed snapshot: exact submitted source for
|
||||
PUT, an annotated Console transcript after a REPL render. X-Tessera-Source-Kind
|
||||
identifies source-snapshot versus repl-transcript; a transcript is not a replay log.
|
||||
|
||||
The compatibility `POST http://{address}/v1/namespaces/{name}/evaluate` endpoint
|
||||
still accepts one isolated expression in a fresh VM without ui or previous bindings.
|
||||
It does not publish a page or change revision. Console does not use this endpoint.
|
||||
All execution endpoints share the eight-entry queue. These are in-process bounded
|
||||
host executions, not a complete untrusted-code sandbox or a process-isolation design.
|
||||
|
||||
## Managed visual types
|
||||
|
||||
`Object`, `Type`, `Function`, `Task`, `Block`, `ContainerBlock`, `TextBlock`, `RectBlock`,
|
||||
`Spacer`, `Row`, `Column`, `Button`, `Page`, `Mount`, and `Event` are managed nominal
|
||||
Type objects. Use `page = Page()` and `label = TextBlock("Hello")` in Endor source.
|
||||
The existing ui constructors return these same typed objects. `page.type`,
|
||||
`Page.base`, `Page.name`, `isInstance(page, Block)` and `isSubtype(Page, Block)`
|
||||
expose actual type relations. Types, bases, instances and native constructors live
|
||||
in the same GC graph. Ordinary source classes support `class Child: Base`, typed field
|
||||
declarations, explicit first `self` parameters, positional field construction and
|
||||
member assignment. Inherited methods bind the actual receiver; overridden methods
|
||||
are dynamically selected through self. Concrete native visual subclasses reuse real native allocators; abstract bases remain unconstructible. Explicit traits and source parameter/return annotation checks are enabled; declared-field construction/write checks are enabled alongside source function checks; complete initialization and static/effect typing remain pending. Native Block/Page methods use the same type method tables and binding path.
|
||||
|
||||
Window is a host-provided managed resource: ui.window(), page.window(), page.open(window), window.pages()/id()/viewport(), resize(width,height), moveTo(x,y), setTitle(text) and focus(). Requests project to their actual native window only after successful input/candidate completion and carry the current runtime session. Resize is asynchronous and the reported viewport is authoritative; this host accepts 1..4096 logical dimensions with a native 720x480 minimum. Failed input/candidates discard pending requests and read-only rendering rejects window effects. Open Pages appear in native tab chrome, with page.title, click activation/close, Ctrl+Tab cycling and Cmd/Ctrl+W close when page keyboard focus is active. Overflow arrows reach additional pages. These operations call actual Page methods in the same VM; tab IDs are weak runtime projections and add no GC roots. The 36-logical-pixel bar reduces Page constraint height; window/ui viewport reports the full inner size and native pointer positions are translated into content coordinates. Window() now creates additional native windows in the same VM, up to 16 open resources. Page.open(window)/moveToWindow(window) preserve Page and business identity while replacing Mounts; detachToWindow() creates and returns a new Window. Dragging a tab away from its strip invokes the same method. Window.close()/secondary OS close remove Page roots, unmount, and retire the resource context; retained Pages can reopen in another live window, and closed Window resources reject viewport/resize/title/focus operations. Closing the primary OS shell exits the application. Secondary viewport inputs and frame publication use the same worker. Secondary close after callback/rendering failure uses host-only teardown without invoking source callbacks or resuming execution. After reset/discard, closing an old picture never touches a fresh VM resource with the same number; viewport inputs are also generation-scoped. A teardown failure discards the affected VM and disables remaining pictures. Native initialization/surface errors are reported rather than panicking; failed secondary creation leaves a managed resource closable from Console. Native tab reordering, existing-window drops and release-point placement use the managed methods described below. Application-exit cleanup is described below.
|
||||
|
||||
Application exit now uses a private VM-worker control channel, independent of HTTP queue capacity. Main native close and a managed primary Window.close request asynchronous cleanup; duplicate requests coalesce and mutation requests are rejected with 503 while exiting. An unpublished candidate/input refresh is cancelled without replay. The current VM cancels all Task entries, closes managed windows, detaches occurrences child-before-parent per window, and invokes normal onUnmount hooks once. It does not run layout/paint during shutdown. All windows are closed before hooks run; new windows and tasks are forbidden. A stopped/faulted VM detaches without source hooks; reset/discarded pictures cannot revive an old VM. A hook error aborts remaining source hooks, releases prepared hook roots, drops the VM and reports failure before native exit. Completed shutdown is acknowledged to the GUI, which then ends the event loop. An OS exit bypassing CloseRequested uses a five-second bounded final fallback; non-cooperative native calls remain atomic and force-kill/crash cannot guarantee notifications. Native stderr records the window/mount/task-entry counts and whether source hooks were enabled, or the cleanup error. See examples/exit-lifecycle.endor. Cross-platform exit/drag validation remains broader follow-up work.
|
||||
|
||||
Foreground REPL/events now retain a BeforeInput request while an existing idle layout/paint refresh advances one stage/quantum per worker turn. They execute their source only after that refresh settles, so mutations never enter its read-only scope. New task callbacks are not delivered ahead of this accepted input. Shutdown can cancel the waiting request with 503, and superseded submissions still return 409. Reset cancels/discards the old VM instead of synchronously draining its unpublished refresh. Source parsing/compilation and ordinary synchronous source/native calls remain atomic boundaries; this change removes the worker's synchronous pre-input refresh drain. Native stderr records the submission once when a request first waits for an active refresh; it does not log source text or repeat the line for each quantum. Ready layout/paint/coroutine quanta and pending input/candidates yield to ready OS threads without a fixed timer delay; queue, shutdown, generation and viewport checks still run between quanta. Only idle work or external waits use the normal 100 ms polling wait.
|
||||
|
||||
Source layout/paint now validate name-level read observations from Aster: each globals/builtins lookup records its text key and observed presence/value, while dictionary kind checks remain separate. Updating the REPL result `_` or another unread global no longer invalidates these frames solely because the whole globals dictionary version changed. Reading `_` still observes its value; adding a previously missing global correctly invalidates a builtin fallback. Ordinary native dictionary iteration/content reads retain whole-object version dependencies. Measurement cache hits replay their recorded observations into the outer solve; they do not drop dependencies merely because source execution was skipped. Cache observations contain borrowed handles (including object-valued names), add no GC roots, and never write comparison snapshots back into language objects. Invalid-name diagnostics report only identity/key, not captured values. Block binding uses the same precise observations through the synchronous read-only API; other legacy callers of the object-list API remain conservative. See examples/global-dependencies.endor.
|
||||
|
||||
|
||||
|
||||
|
||||
While a native tab drag is held over an overflow arrow area, the strip waits 350ms then reveals one hidden tab every 120ms, including in a compatible destination window. The preview scroll does not activate Pages or change business state. Drawing, hit testing and insertion gaps share the same transient visible range; release uses its full-order insertion index. Leaving the strip stops the timer; release, Escape, a new press or runtime generation change restores the normal active-tab-centered strip. A resize or changing tab count clamps the range. Native drag/mixed-DPI behavior still requires platform validation; application-exit cleanup is described below.
|
||||
|
||||
|
||||
ContainerBlock.insert(position,block) accepts a zero-based position through the current count, returns a new stable slot and preserves existing slots/Mounts. Invalid indices and child cycles fail before changing the child list. Page.moveTab(position) uses a final zero-based index in its owning window. Native drops invoke the actual Page moveToWindow/moveTab/activate methods; a declined or redirected window move skips destination reordering. A drop allows 300000 instructions per method. Source overrides participate; earlier writes do not roll back after failure. Window.moveTo(x,y) queues the physical desktop outer origin, with signed integers within +/-1000000. Detached placement preserves the saved grab offset; the window manager may adjust it and unsupported global placement reports a diagnostic. Dragging uses a 12-logical-pixel threshold, visible insertion marker and Escape cancellation. Overflow auto-scroll, external-app occlusion and mixed-DPI verification remain pending. See examples/tab-placement.endor.
|
||||
|
||||
Source measure and arrange overrides execute bottom-up and top-down in one read-only VM layout call. Structural Mount links exist before first measurement; bounds queries reject premature geometry. Native base layout uses current occurrence child measurements, and Arrangement must assign every stable child slot exactly once. Layout dependencies changed by lifecycle hooks trigger another pass before publication. Page constraints now use the current logical window viewport. Column/Button propagate cross-axis width and Row propagates cross-axis height; desired sizes are clamped. ui.viewport() provides a managed snapshot whose private input participates in rendering dependencies. Native resize updates are coalesced on the same worker without adding source inputs. Source measurement caches use Mount/method/children/constraints and actual subcall object reads, including returned-result decoding; Mount-reading methods conservatively bypass caching. ui.stats() exposes sourceMeasureHits/sourceMeasureMisses outside read-only rendering. Native TextBlock wrapping now uses the occurrence width in measurement/cache/painting; source measurement/arrangement now repeats until constraints and geometry settle; additional allocation policies remain pending; ScrollBlock scrolling is described below.
|
||||
|
||||
Source layout solves repeat in one read-only call until constraints/sizes/bounds are unchanged, reusing one bytecode frame. Source-arranged changed dimensions become exact per-axis constraints for this solve; source container measurements differing from native results constrain content using the same container policy. Selected limits reset on later inputs/resizes. Nonconsecutive repeated states report a cycle. No fixed pass/hop cutoff is used; all passes share the 1000000-instruction/128-frame budget and budget failure is explicit. Measurement clears provisional Mount geometry, and only complete settled frames publish. ui.stats().layoutPasses reports work; source/cache counters include all passes. VM annotation checks distinguish validation-only from content reads, preserving Mount-typed independent measurement caching; actual Mount reads still bypass conservatively. Resumable solving remains pending. See examples/layout-negotiation.endor.
|
||||
|
||||
TextBlock now wraps words/glyphs at its available width and measures the resulting height. Native and source-base measurement paths use current constraints; native shape/font caches include wrap width. Painting carries allocated width/height, clips glyphs and keeps ancestor scroll clipping. Source text PaintCommand may supply both wrapWidth/wrapHeight (finite nonnegative logical dimensions up to 1000000); neither preserves legacy unwrapped paint, and a partial pair is rejected. Native TextBlock.paint supplies the pair. These are derived draw bounds, not another business object. Management UI text remains unwrapped. Resumable solving and broad fractional-DPI validation remain pending. See examples/wrapped-text.endor.
|
||||
|
||||
Source paint overrides execute in the actual frame pipeline under a read-only heap policy. Source hitTest overrides similarly refine native pointer targets in VM paint order; Point.inside(bounds) and Point.inCircle(cx, cy, radius) provide primitive shape queries. Managed DisplayList/ObjectList/PaintCommand and Constraints/Bounds/Point results are ordinary runtime objects.
|
||||
|
||||
ScrollBlock(width,height,child) is a ContainerBlock with managed viewport dimensions and independent per-Mount offsets. mount.scrollTo(x,y), scrollBy(dx,dy), scrollPosition() and scrollIntoView() operate on actual occurrences. Position snapshots expose x/y/maxX/maxY from committed layout; relative requests accumulate and offsets clamp after content/viewport changes. Detached Mounts and read-only rendering mutations are rejected. scrollIntoView and requestFocus adjust nested scrollable ancestors. Native/source paint, focus outlines, hit testing and pointer selection share translated geometry and ancestor clips. Remounting starts a new offset. Paint x/y may be signed after scrolling; dimensions/radii remain nonnegative and coordinate budgets still apply. See examples/scroll.endor. Wheel chooses one eligible ancestor (not per-axis split); native scrollbar dragging, touch inertia and PageUp/PageDown remain pending.
|
||||
|
||||
Native wheel POST /events uses kind scroll with the normal window/session/layout_version, a scrollable mount ID, point=[x,y], delta=[dx,dy], and no press_point. Deltas are signed finite logical pixels within +/-1000000; positive moves toward the end of content. Other kinds must omit delta. Native Shift+wheel maps to horizontal. The host checks the active committed frame, target attachment and clipped viewport before invoking Mount.scrollBy. These fields are transport metadata; source code uses the Endor methods above.
|
||||
|
||||
ui.after(owner,key,milliseconds,callback) returns Task. The zero-argument callback runs on the owning VM worker after at least the integer 0..86400000 ms delay and must return Unit. Idle polling can add up to 100 ms; execution load may delay delivery further. Task.cancel/active/status expose cancellation, eligibility and pending/running/completed/cancelled/failed state. One owner/key replaces the prior pending task. Owner scopes and callback captures are managed strong edges; scheduler and owner links are weak. ui is an application owner. Hidden live objects continue; Page close cancels its and its Mount tasks, even close/reopen within one input. Page movement preserves Page tasks but replaces Mounts. Window close cancels its Pages/tasks; reset/DELETE/program replacement discard old scheduler/VM and generation checks reject stale publication. Failed PUT preserves old tasks. Callback failure stops the domain and cancels remaining tasks; earlier writes do not roll back. Read-only rendering cannot schedule/cancel. Limits: 64 pending per owner, 1024 per runtime, 64 delivered per poll, 128 frames/100000 instructions per callback. Providers support timers, asynchronous text-file reads and HTTP(S) text GET; await is supported in ui.spawn calls.
|
||||
|
||||
Source function parameter annotations are checked before the body and return annotations before returning. Object accepts any live value; Unit accepts nil; Number, String/Text and Bool match scalar kinds. Function includes source/native functions and bound methods, while callable class definitions remain Type. View is a compatibility alias for Block. Other names resolve actual Type/Trait objects in the function's globals then captured builtins at each call. The method's own class uses the receiver's actual owning definition, preserving old bound methods after REPL redefinition. Other type names are not frozen at definition. UnknownAnnotation and TypeMismatch report failures; bad returns do not roll back earlier writes. Declared-field construction and set_attr writes are also checked, as described below. Static inference, generic and static effect typing remain pending.
|
||||
|
||||
Declared fields are checked at construction and set_attr writes through the same enabled type-check switch. Native subclass fields are validated before native allocation/opening effects. Failure preserves the field; declared deletion is rejected. Inherited fields use their declaring definition/environment, the declaring class name keeps its actual identity after REPL redefinition, and other names resolve dynamically in declaration globals/builtins. Shared Block forwarding selects the current content type/storage. This does not scan old objects or revalidate all referring fields after shared-reference changes; trusted payload/storage/attach operations and complete initialization remain host responsibilities. Static/effect typing and local/captured type annotations remain pending. See examples/field-contracts.endor.
|
||||
|
||||
Native methods now publish positional CallArity intervals, checked by the VM before invocation. Source defaults and bound receivers participate in the same query. Traits validate acceptance of their canonical count including self and reject native methods without metadata. Event listeners/onClick require Function metadata accepting zero arguments or one Event, preferring Event if both work. Binding computes and Task callbacks require zero-argument acceptance before registration/replacement. Generic Type constructor reflection and complete native signature coverage remain separate gaps. See examples/native-signatures.endor.
|
||||
|
||||
Native CallSignature checks resolved parameter/return types for visual measure/arrange/paint/hitTest, Point queries, Window/Block/Container/Page/Mount/Task/Event/Subscription methods and ObjectList.at. Signature definitions are traced managed edges. Parameters fail before dispatch; final results delegated to source/native functions must satisfy all pending native return contracts, with rooted definitions and the same frame/instruction budgets. Wrong returns release scoped results but do not undo earlier writes. CallEffect ReadOnly allows result allocation; Delegated allows a read-only native wrapper while delegated targets keep the same VM read-only/budget scope (ui.present); Mutating/External calls are rejected before invocation during read-only execution. Block.click returns its generated Event; Block.dispatch returns the delivered Event. Dispatch/click and lifecycle handler contracts permit External effects; the default no-op does not constrain native overrides to ReadOnly. Existing heap barriers still apply, and this does not sandbox trusted native I/O. CallType unions preserve every branch definition. Page.open accepts Window or nil; page.window returns Window or nil; Block.on accepts Bool or String for its optional phase, while phase names retain domain validation. Mount relation queries are nullable, and bounds() is a real Bounds object usable by Point.inside. Native union metadata does not add Endor union syntax. Source method overrides now enforce parameter contravariance, return covariance and accepted-count preservation at class creation/method replacement, with call-time rechecks for dynamic annotation names. Ancestor replacement checks overriding descendants atomically. Unknown forward names may defer until invocation; known incompatibilities reject before effects. Known effects may only shrink; conservative source/call-graph ReadOnly proofs supplement runtime barriers. See examples/method-contracts.endor. Public ui functions, captured state methods and native factories publish signatures after the registry exists. Factories check the Type receiver/general result/effect and split native options from requested-class fields before validating both; omitted Rect/Text options and Row/Column variable children cannot absorb subclass fields. Event/ObjectList keep dedicated member/field checks. Generic Type reflection still has no single fixed constructor signature. See examples/constructor-contracts.endor. Current global/builtins/closure/receiver call graphs may prove ReadOnly without execution; unresolved targets/results, shared writes and Delegated targets remain unknown. Unknown legacy metadata remains unknown. See examples/visual-protocols.endor and examples/layout-negotiation.endor.
|
||||
|
||||
Trait definitions Visual, EventTarget, Children and Presentable are managed nominal capabilities. ui.implement(type,capability) explicitly declares an implementation after required-method/positional-arity/type/known-native-effect checks; ui.implements(type,capability) and ui.supports(value,capability) query it. Block declares Visual/EventTarget; ContainerBlock declares Children, inherited by Page. Same-name methods alone never declare an implementation. Source subclass construction and host method replacement validate inherited/affected descendant contracts. Source/native positional intervals are checked, and missing native arity metadata prevents a capability declaration; source parameter/return annotations are checked at invocation. These capabilities use typed signatures: registration checks parameter contravariance, return covariance and known native effects. Actual calls recheck dynamic names and final results across delegation, with rooted return definitions. Explicit typed method annotations remain checked even if a different host disables global source checks; concrete implementations keep wider inputs and optional convenience forms. General source effects and formal trait syntax remain pending. EventTarget requires canonical on/dispatch/onEvent arities 3/2/1 after self; native optional convenience forms remain.
|
||||
|
||||
For a plain object explicitly implementing Presentable, present(self, window: Window): Block is invoked by ui.present(value) or ui.open(value), using the current managed Window and the same VM budget. The result must be an actual Block. Blocks pass through directly; unregistered values retain the summary fallback. Source views retain their business object via managed fields/callbacks/bindings, as in examples/presentable.endor. Viewing function definitions does not itself execute them. Rendering methods still run read-only with nominal result checks.
|
||||
|
||||
Block.bind(property, compute) binds an existing managed Block field to a zero-argument function and returns Subscription (disconnect/isConnected). This includes source-defined fields and native TextBlock.text/size/color, RectBlock.width/height/radius/color, Spacer.size and container padding/gap. Native fields can also be assigned directly. The target content owns compute/captures; tokens and host registry are weak. Rebinding disconnects the old connection; disconnect keeps the last value. Actual reads track global-name presence/value separately from whole-object reads; ordinary dictionary content access remains conservative. No explicit source-list parameter is required. Unrelated global updates reuse valid compute results, while direct output overwrites still trigger repair. ui.stats().bindingEvaluations counts computations in completed refreshes over this VM lifetime, including initial and hidden bindings. Hidden retained Blocks update at successful input/event stabilization boundaries before all windows publish. Computes are read-only for existing objects and may allocate results. They have 100000 instructions/128 frames each, 128 active bindings per Block and a 10000-computation refresh limit that errors rather than truncates propagation. Binding failure stops the live VM and preserves published pictures. Non-Block targets, explicit dependency lists and general type/effect checking remain pending. See examples/property-bindings.endor.
|
||||
|
||||
Native input POST /events is a transport envelope, not Endor source. Each frame and input carries an opaque runtime window identity; omitted input window defaults to 1 for existing clients. GET /code exposes X-Tessera-Window. A window/session/layout identity mismatch is rejected before invoking code. Tab actions use kind tab-activate/tab-close/tab-detach/tab-drop and the mount wire field carries the opaque tab ID from frame.tabs; point/press_point must be omitted. tab-drop additionally requires tab_drop={{window,layout_version,index}}, where index is a published destination gap from 0 through its tab count (at most 64). Both source and destination orders must still match their published frames. tab-detach alone accepts optional screen_position=[x,y] as signed integer physical desktop coordinates within +/-1000000; other kinds must omit it. All spatial/tab actions validate session and layout_version before dispatch. Resource window-close uses mount=0 and no points; it validates the live window/session rather than its old layout version. The window
|
||||
sends current session, layout_version and Mount identity; stale positions fail without calling a callback. Pointer clicks also include point and press_point [x,y] in logical page coordinates. Both targets are resolved through read-only hitTest, with fallback behind a rejected candidate; a click is dispatched only when both resolve to the same Mount. Keyboard/code clicks omit coordinates and remain semantic activation. GET /code also exposes X-Tessera-Session and X-Tessera-Layout-Version headers for transport clients. Native mouse, Tab, Enter and Space delegate to the same
|
||||
managed click/focus methods used by code. Events appear in Network, not Console source history.
|
||||
|
||||
ScrollBlock.axis is a managed visual attribute: "both" (default), "vertical" or "horizontal". The default preserves two-axis unconstrained content. Vertical restricts content width to the actual occurrence viewport minus padding; horizontal restricts height. Source-arranged viewport dimensions are used in subsequent measurement. The disabled scroll axis has zero offset/limit and is clamped after updates. Composition remains vertical; a Row child can arrange horizontal content. See examples/scroll-axis.endor.
|
||||
|
||||
ContainerBlock.mainAlign accepts "start" (default), "center", "end" or "space-between". Native arrangement uses allocated Bounds after padding/minimum gap, distributes positive remaining main-axis space and keeps child sizes unchanged. Overflow keeps start placement. Explicit source arrange placements remain authoritative; this is alignment, not flex sizing.
|
||||
|
||||
Block.flex is a nonnegative weight (default 0). Native containers reserve fixed measured children, padding and gaps, then share remaining allocated main-axis space between positive weights with zero basis. Actual child allocation feeds remeasurement. It does not request parent expansion. Further controls are described below.
|
||||
|
||||
|
||||
Flex main-axis policy: flexBasis is "auto" by default (zero basis when flex > 0, otherwise the first measured size of this occurrence in the current solve); a number supplies an explicit basis. flexMin defaults to 0, flexMax to 1000000, and flexShrink to 0. All numbers are finite/nonnegative and at most 1000000; flexMin must not exceed flexMax. The parent clamps bases to min/max, distributes positive space by flex, and redistributes space left after a maximum is reached. Deficits shrink by flexShrink times the original basis, freezing at minima. A fixed child can opt into shrink without growth. Unresolvable minimum overflow is preserved, and remaining positive space follows mainAlign. The policy applies to width in a Row and height in Column-like containers; these are not independent width/height bounds. Source arrange overrides remain authoritative. Preferred sizes are derived per occurrence and reset for each new solve, never shared through Block state. See examples/flex-constraints.endor. Layout continuation remains unfinished.
|
||||
|
||||
|
||||
When an occurrence's cross-axis constraint changes during settling, its preferred main-axis size is invalidated and remeasured. Any obsolete native flex allocation on that axis is removed for the replacement measurement, so narrowing a nested Column can increase wrapped text height. Source arrange allocations remain explicit. Preferred-size presence and values participate in convergence/cycle detection.
|
||||
|
||||
|
||||
The source layout driver now uses Aster's resumable read-only call API with a soft quantum of 256 instructions. Pauses retain the same VM frames, operand/local roots, return contracts and read tracking; total instruction/frame limits still apply across slices. ui.stats().layoutSlices counts slices in the most recent solve (native fast path: 1). The worker currently resumes Pending immediately after yielding its OS time slice. Parking the solve across worker turns, scheduling other work and handling newer inputs before completion are not implemented yet. Native callbacks are not preempted. Only the completed settled frame is published.
|
||||
|
||||
|
||||
source_layout::start now returns either Complete(Draft) or Pending(Work). The host-owned Work retains the unpublished frame, derived runtime/cache snapshots, convergence plan and prepare root without borrowing caller frame/cache variables. Work::resume consumes the saved job and advances the same VM continuation; Work::cancel closes that continuation and releases the prepare root without merging a draft. A second start is rejected while any read-only execution is active. Every pending Work must be resumed or explicitly cancelled with its owning VM; dropping it is not cancellation. Synchronous ReplSession operations drain the same saved refresh state. The worker parks refresh jobs; cancellation restores still-pending Mount preparation.
|
||||
|
||||
|
||||
UiBridge::begin_layout_frame/resume_layout_frame now expose PendingLayout around the source job. This bridge-level continuation also owns its target window, page snapshot, tab projection, viewport restoration and retained lifecycle hook root. Only the Complete branch projects scroll/focus, captures dependency versions, merges derived caches, commits Mount geometry and runs deferred hooks. Resume restores the saved window context, and failure releases hook roots. ReplSession uses this protocol through its saved refresh state. Viewport refresh supports cross-worker-turn scheduling and prepared-Mount rollback; callers must not drop a pending bridge layout as a substitute for cancellation.
|
||||
|
||||
|
||||
Viewport refresh now advances through ReplSession's saved refresh state on worker idle turns. A turn advances one traversal stage or a 256-instruction layout quantum; a pending job shortens the next worker wait to 1 ms. Tasks/window commands and document publication wait for complete refresh. ui.stats().refreshYields reports cooperative idle returns. Mutating requests wait across worker turns for the existing job, so they cannot run inside its read-only scope. Mutating requests are serialized; newer viewport targets coalesce by cancelling unpublished layout. Initial source execution remains atomic; initial layout parks across worker turns. Explicit REPL/event refresh parks across worker turns. Idle tasks deliver at most one callback per turn and park subsequent layout; callbacks and individual native nodes remain atomic. Large intrinsic trees use the sliced driver; small intrinsic trees keep the fast path.
|
||||
|
||||
|
||||
Runtime mutation entry points reject direct calls while refresh work is pending, before executing source or changing metadata; task polling defers. The API worker drains the saved refresh before accepting those mutations, keeping the runtime usable. Incremental refresh keeps the prior complete document map until a stable pass, including across window traversal boundaries where no VM read-only frame is currently active.
|
||||
|
||||
|
||||
New viewport targets now coalesce pending refresh work. The runtime cancels only an unfinished bridge layout, restores its Mount checkpoint, preserves completed per-window drafts/callback effects and restarts traversal with the latest viewport map. refreshRestarts counts target replacements; layoutCancels counts replacements that actually closed a pending VM layout. Unchanged targets resume the same job. A new external target resets its convergence budget; internal settling does not. Ordinary source/event mutations still serialize behind refresh rather than roll back application effects.
|
||||
|
||||
|
||||
Cancellation checkpoints own explicit VM roots until restored or released. Initial presentations may have no mount dictionary; cancellation restores that absence too. Saved metadata values retain object-valued attributes. A pending refresh can restart while keeping already completed window drafts; no onMount/onUnmount callback is replayed merely because the viewport target changed. Mount-owned tasks are cancelled immediately before an actual onUnmount callback, never during abandoned preparation.
|
||||
|
||||
REPL/event requests retain their HTTP request and scalar result until the complete window set settles. The worker advances one stage/quantum per turn, takes current native viewport targets each time and keeps later mutations queued. GET /code keeps returning the last complete publication. Response metadata and native commands publish together after settling; no source/event callback is replayed. A running input can finish before a newer queued PUT, preserving a consistent old runtime if that candidate fails; DELETE revokes the owner and prevents its late publication. Source execution/callbacks and structural preparation and final command projection remain atomic; source paint execution can yield.
|
||||
|
||||
Complete-source PUT also parks an isolated candidate VM during initial layout. The worker retains its HTTP request and the prior live VM, advances one candidate stage/quantum per turn and commits only after its full window set settles. New PUT/DELETE submissions discard obsolete candidates and explicitly cancel their pending layout. Failure keeps the prior live owner; accepting a replacement alone does not revoke that owner. Candidate viewport updates use only the surviving primary shell; secondary native resource IDs and sizes still belong to the old VM until successful publication. Parsing, compilation, source execution, structural preparation and final command projection remain atomic; source paint execution can yield.
|
||||
|
||||
Source paint now uses a resumable read-only VM call with the same 256-instruction quantum and a cumulative 1,000,000-instruction budget. The pending job owns the unpublished frame, visual snapshot, decoded command buffer and prepare root. The refresh worker resumes paint before advancing to another window and publishes only the full stable window set. New viewport targets cancel unfinished paint, discard partial commands and force that window to refresh. Already completed layout/Mount geometry and lifecycle callbacks remain committed; cancelling paint does not replay or undo them. Failure/discard explicitly closes the read-only continuation and releases its roots. paintSlices reports the most recently completed paint solve (1 when the solve completes within its first quantum); paintCancels counts viewport replacements that closed pending paint. Layout checkpoint rollback remains limited to unfinished layout preparation. Native callback bodies, driver preparation, command decoding/projection and rasterization remain atomic.
|
||||
|
||||
Layout and paint drivers now prepare one occurrence at a time. Their fixed-size outer bytecode repeats on the same VM frame; a short-lived helper retains only the current call, its bounds/arguments and collector. The helper is released before the next occurrence. Layout keeps bottom-up measure, top-down arrange and the same settling loop. Paint advances even intrinsic method classification through VM quanta. The weak occurrence list and native scratch/output data remain proportional to the actual tree, but preparation no longer allocates managed callables/Bounds for the whole tree before the first slice. All helpers share the original read-only scope and cumulative instruction/frame limits. Weak-list copying, structural extraction, settling and final projection remain bounded atomic native work.
|
||||
|
||||
ui.stats().dependencyInvalidations counts observed layout/paint dependency mismatches. lastInvalidDependency records the phase, object kind/identity and old/current versions without rendering its fields or retaining it. An input changing its globals is an expected invalidation; compare idle document versions before diagnosing a refresh loop.
|
||||
|
||||
ui.readText(owner,key,path[,callback]) returns an owner-scoped Task and reads a regular UTF-8 file off the VM thread. Paths use native filesystem syntax; absolute paths are recommended. The optional callback takes zero arguments and must return Unit; it runs only on successful read and can use task.result(). Without a callback, poll status then read result from code. result() is available while a success callback is running or after completion (timers return Unit); error() returns an empty String until failed, then the provider/callback error. A provider failure marks the task failed and skips its callback without stopping the VM; a source callback failure still stops the shared domain. Owner/key replacement, explicit cancellation, close/reset/VM discard and GC drop the provider lease, remove queued completion and reject late delivery. In-progress OS reads may finish, but cannot deliver after cancellation. Only the owning VM worker updates managed results and rechecks owner/key identity. No VM handles enter provider threads beyond opaque weak identities.
|
||||
|
||||
The lazy shared pool has four threads and a 64-job queue. Each runtime permits 16 outstanding I/O requests (one temporary replacement reservation), and each read is capped at 1 MiB by metadata plus actual streaming length; non-regular files, non-UTF-8 data and over-limit content fail rather than truncate. These limits do not constitute a full filesystem sandbox. The provider returns text in the same managed Task, not a second application-state store. Task await is supported through ui.spawn; see the await contract below. See examples/async-file.endor; from REPL call reader.read("/absolute/path.txt") to update its actual TextBlock, even when that object is hidden but retained.
|
||||
|
||||
ui.fetchText(owner,key,url[,callback]) performs an asynchronous HTTP(S) GET using the same Task, owner/key replacement and success-only callback protocol as readText. Example: fetcher.fetch("http://127.0.0.1:4737/agent") after loading examples/async-network.endor. The example retains the complete result in fetcher.response and displays completion status; it does not put arbitrary network content into a TextBlock, whose own 16 KiB limit is independent of the provider limit. Only 2xx responses produce a UTF-8 result; HTTP failures, invalid UTF-8, oversize bodies and transport errors set status() to failed with error(). It verifies HTTPS certificates, follows at most five HTTP(S) redirects, has a 10-second connect and 30-second total transfer timeout (starting when a worker takes the request), and bounds decoded text to 1 MiB without truncation. URLs are limited to 8192 bytes and must not contain credentials or control characters. This GET API does not accept request bodies, custom headers or authentication.
|
||||
|
||||
The current transport uses a separate system curl process per request (/usr/bin/curl on Unix, curl.exe on Windows); missing or incompatible curl fails the Task. User curlrc and URL globbing are disabled; URL data is passed through escaped stdin configuration rather than command arguments. TLS and normal system proxy behavior remain enabled. Cancellation kills an active HTTP process immediately and the provider worker reaps it; the VM thread never waits for the process. All file and HTTP requests share the per-runtime 16-task limit and global four-worker/64-job queue. In-progress file reads remain cooperatively cancelled at delivery. Network access is not a security sandbox, and this is a text GET provider rather than a general HTTP client. Task await is supported through ui.spawn; see below.
|
||||
|
||||
ui.spawn(owner,key,function) creates an owner-scoped cooperative Task for a zero-argument function; its returned value is retained as the Task result. Each owning VM poll resumes at most a 256-instruction quantum per selected Task, rotates runnable tasks fairly, and retains source frames in an Aster-managed coroutine edge. Calls and writes may interleave between quanta; prior writes are not rolled back on cancellation or error. Pending/running Task replacement, owner closure, GC and reset release parked frames through the same managed graph. Native calls remain atomic and all quanta share the 128-frame/100000-instruction callback limit; a native entry may run during preparation. result() is unavailable until spawn completes. A source error still stops the shared runtime. See examples/cooperative-tasks.endor. Endor await expressions now suspend these calls on a Task without replaying the operand. See the await contract below.
|
||||
|
||||
Inside a function run by ui.spawn, `value = await task` waits for any timer/file/network/spawn Task and resumes at the same expression with its retained result. A source function may return a Number, String, managed Object or Unit; normal source annotations still apply. Task.result() and await share the result. `ui.sleep(owner,key,milliseconds)` creates a callback-free timer Task returning Unit. Plain calls/REPL can await an already completed Task; a pending await requires a coroutine and fails explicitly rather than blocking. There is no new async function declaration: ui.spawn explicitly schedules an ordinary Endor function. See examples/await-file.endor.
|
||||
|
||||
A waiting coroutine retains its evaluated operand and frames as managed edges; waiting performs no VM execution or active polling. Source side effects and IO initiation before await are not replayed. When the dependency completes, the owning VM worker resumes the waiter through the existing fair quantum scheduler. Cancelling/replacing/closing the waiter releases its frames and operand; it does not automatically cancel an independently owned or shared dependency. Dependency cancellation propagates cancellation to its waiters without running the remainder. An unhandled dependency failure becomes a source await error (with the original provider message), fails the waiter and follows the existing shared-runtime fault rule; provider failure alone still only fails its own Task. Self-await and cyclic Task waits fail explicitly. Read-only layout/paint cannot await. Waiting state is reported as running, while active() remains true; result() is unavailable until completion. These APIs do not introduce try/finally or change the existing exception model.
|
||||
|
||||
|
||||
|
||||
|
||||
## UI host object
|
||||
|
||||
Positional arguments only:
|
||||
|
||||
- `ui.text(value, size = 1, color = "#242422")`; integer size 1..8.
|
||||
- `ui.rect(width, height, radius = 0, color = "#DCE8FF")`.
|
||||
- `ui.column(padding, gap, child...)` and `ui.row(padding, gap, child...)`.
|
||||
- `ui.spacer(size)`.
|
||||
- `ui.page()` creates a page; `page.render(root)` mounts its root; `page.unmount()` releases the mount. The last render
|
||||
in a successful submission selects the page shown in this namespace.
|
||||
|
||||
Defaults above describe the host API; do not write keyword arguments in Endor.
|
||||
Colors use #RRGGBB or #RRGGBBAA. Dimensions are finite numbers in 0..1000000.
|
||||
Use newlines between complete top-level statements. Multiline calls, function
|
||||
bodies and expression continuations are passed to Aster as complete inputs.
|
||||
Limits: 1 MiB source, 4096 constructed nodes, 64 pages, 64 UI levels, 10000 expanded
|
||||
layout nodes, 16 KiB per text, 128 VM frames. Script statements each receive an
|
||||
equal share of a total 1000000-instruction allowance. Older module initialization
|
||||
and main execution each retain their own 1000000-instruction allowance.
|
||||
|
||||
PUT waits for its worker result. Errors return 422 with diagnostics and preserve
|
||||
the last successful revision. A newer accepted PUT or DELETE supersedes older
|
||||
work (409); a full eight-entry queue returns 503. DELETE immediately clears the
|
||||
document. GET remains available while Aster executes. The window redraws from an
|
||||
owned snapshot; resize does not rerun Endor. Text uses system fonts, antialiasing
|
||||
and font fallback; Chinese needs an installed CJK font. Size 1 is 14 logical pixels
|
||||
with 20-pixel line height; larger sizes multiply both. Native Block methods include
|
||||
setText/setColor, container append/insert/remove/replace/move, Page open/close/navigation,
|
||||
and code-driven button.onClick/click. ui.state and ui.textOf provide explicit text
|
||||
binding. Mouse routing, tab chrome/multiple windows and incremental layout remain
|
||||
in progress; process isolation is future work. Console retains objects
|
||||
only in its explicitly resettable in-memory VM. It is not an untrusted-code sandbox.
|
||||
"##,
|
||||
name = namespace.name,
|
||||
revision = namespace.revision,
|
||||
address = API_ADDRESS,
|
||||
example = include_str!("../../../examples/page.endor"),
|
||||
)
|
||||
}
|
||||
@@ -9,7 +9,7 @@ use std::{
|
||||
#[test]
|
||||
fn preserved_picture_close_does_not_retire_same_number_in_fresh_console_vm() {
|
||||
let (_, mut picture) = endor_host::ReplSession::load(
|
||||
include_str!("../../examples/windows.endor"),
|
||||
include_str!("../../../examples/windows.endor"),
|
||||
"app.main",
|
||||
1,
|
||||
150,
|
||||
@@ -250,7 +250,7 @@ fn console_keeps_memory_until_reset_or_complete_put_without_erasing_the_page() {
|
||||
assert_eq!(client.request("POST", repl, "retained = 42").0, 200);
|
||||
assert_eq!(
|
||||
client
|
||||
.request("PUT", code, include_str!("../../examples/page.endor"))
|
||||
.request("PUT", code, include_str!("../../../examples/page.endor"))
|
||||
.0,
|
||||
200
|
||||
);
|
||||
@@ -274,7 +274,7 @@ fn http_executes_real_endor_preserves_failed_updates_and_supports_delete() {
|
||||
api: Some(api),
|
||||
};
|
||||
let route = "/v1/namespaces/app.main/code";
|
||||
let example = include_str!("../../examples/page.endor");
|
||||
let example = include_str!("../../../examples/page.endor");
|
||||
let (status, _, guide) = client.request("GET", "/agent", "");
|
||||
assert_eq!(status, 200);
|
||||
assert!(guide.contains("let myui = ui.page()"));
|
||||
@@ -392,7 +392,7 @@ fn http_delete_remains_available_and_invalidates_queued_put() {
|
||||
let release = Release(release_tx);
|
||||
let client = &client;
|
||||
let route = "/v1/namespaces/app.main/code";
|
||||
let example = include_str!("../../examples/page.endor");
|
||||
let example = include_str!("../../../examples/page.endor");
|
||||
let first = scope.spawn(move || client.request("PUT", route, example));
|
||||
entered_rx.recv_timeout(Duration::from_secs(10)).unwrap();
|
||||
let pending = scope.spawn(move || client.request("PUT", route, example));
|
||||
@@ -0,0 +1,920 @@
|
||||
//! Serial VM ownership, incremental requests, publication and shutdown.
|
||||
use super::*;
|
||||
|
||||
type HttpResponse = Response<std::io::Cursor<Vec<u8>>>;
|
||||
type InputOutcome =
|
||||
std::thread::Result<Result<(endor_host::ReplResult, Vec<crate::window::Command>)>>;
|
||||
|
||||
type CandidateOutcome = std::thread::Result<
|
||||
Result<(
|
||||
endor_host::ReplSession,
|
||||
crate::document::RenderDocument,
|
||||
Vec<crate::window::Command>,
|
||||
)>,
|
||||
>;
|
||||
|
||||
pub(super) struct PendingInput {
|
||||
epoch: u64,
|
||||
id: u64,
|
||||
event: bool,
|
||||
result: endor_host::ReplResult,
|
||||
}
|
||||
|
||||
pub(super) enum PendingRequest {
|
||||
BeforeInput,
|
||||
Input(Box<PendingInput>),
|
||||
Candidate(Box<endor_host::ReplSession>),
|
||||
}
|
||||
|
||||
pub(super) enum RequestProgress {
|
||||
Pending(PendingRequest),
|
||||
Complete(HttpResponse),
|
||||
}
|
||||
|
||||
fn current_viewports(
|
||||
current: &NamespaceState,
|
||||
) -> std::collections::BTreeMap<u64, crate::layout::Size> {
|
||||
let mut viewports: std::collections::BTreeMap<_, _> = current
|
||||
.window_viewports
|
||||
.iter()
|
||||
.filter(|(id, _)| {
|
||||
**id == crate::window::MAIN_WINDOW
|
||||
|| (current.runtime_session != 0
|
||||
&& current
|
||||
.document
|
||||
.windows
|
||||
.get(id)
|
||||
.is_some_and(|view| view.frame.session == current.runtime_session))
|
||||
})
|
||||
.map(|(id, size)| (*id, *size))
|
||||
.collect();
|
||||
if let Some(viewport) = current.viewport {
|
||||
viewports.insert(crate::window::MAIN_WINDOW, viewport);
|
||||
}
|
||||
viewports
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct Worker {
|
||||
pub(super) repl: Option<(u64, endor_host::ReplSession)>,
|
||||
pub(super) next_session: u64,
|
||||
}
|
||||
impl Worker {
|
||||
pub(super) fn shutdown_runtime(&mut self) -> ShutdownOutcome {
|
||||
let Some((_, mut runtime)) = self.repl.take() else {
|
||||
return ShutdownOutcome {
|
||||
summary: "Tessera shutdown: no live runtime".into(),
|
||||
error: None,
|
||||
};
|
||||
};
|
||||
let callbacks = !runtime.is_faulted();
|
||||
let result = catch_unwind(AssertUnwindSafe(|| runtime.shutdown()));
|
||||
match result {
|
||||
Ok(Ok((windows, mounts, tasks))) => ShutdownOutcome {
|
||||
summary: format!(
|
||||
"Tessera shutdown: {windows} windows, {mounts} mounts, {tasks} task entries; callbacks={callbacks}"
|
||||
),
|
||||
error: None,
|
||||
},
|
||||
result => {
|
||||
let error = match result {
|
||||
Ok(Err(error)) => format!("shutdown cleanup failed: {error:#}"),
|
||||
_ => "shutdown cleanup failed after an internal panic".into(),
|
||||
};
|
||||
let error: String = error.chars().take(4096).collect();
|
||||
ShutdownOutcome {
|
||||
summary: error.clone(),
|
||||
error: Some(error),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn close_inactive_window(
|
||||
&mut self,
|
||||
input: &crate::events::Input,
|
||||
epoch: u64,
|
||||
namespace: &Arc<RwLock<NamespaceState>>,
|
||||
notify: &Notify,
|
||||
) -> Response<std::io::Cursor<Vec<u8>>> {
|
||||
if input.window == crate::window::MAIN_WINDOW {
|
||||
return error_response(
|
||||
StatusCode(409),
|
||||
"close the primary shell with its OS window control",
|
||||
);
|
||||
}
|
||||
let owns_runtime = self.repl.as_ref().is_some_and(|(owner, runtime)| {
|
||||
*owner == epoch && runtime.id == input.session && input.session != 0
|
||||
});
|
||||
let mut discarded = false;
|
||||
if owns_runtime {
|
||||
let result = catch_unwind(AssertUnwindSafe(|| {
|
||||
self.repl
|
||||
.as_mut()
|
||||
.expect("owned runtime")
|
||||
.1
|
||||
.retire_window(input.window)
|
||||
}));
|
||||
if !matches!(result, Ok(Ok(()))) {
|
||||
// Never keep a half-cleaned VM live or borrow another generation.
|
||||
self.repl = None;
|
||||
discarded = true;
|
||||
}
|
||||
}
|
||||
let Ok(mut current) = namespace.write() else {
|
||||
return error_response(StatusCode(500), "namespace lock poisoned");
|
||||
};
|
||||
if current.submission != epoch {
|
||||
return superseded(epoch);
|
||||
}
|
||||
let Some(view) = current.document.windows.get(&input.window) else {
|
||||
return error_response(StatusCode(409), "window is no longer active");
|
||||
};
|
||||
if view.frame.session != input.session {
|
||||
return error_response(
|
||||
StatusCode(409),
|
||||
"window belongs to another runtime generation",
|
||||
);
|
||||
}
|
||||
let mut document = current.document.clone();
|
||||
document.windows.remove(&input.window);
|
||||
if discarded {
|
||||
document.frame.session = 0;
|
||||
document.frame.focus = None;
|
||||
for view in document.windows.values_mut() {
|
||||
view.frame.session = 0;
|
||||
view.frame.focus = None;
|
||||
}
|
||||
current.runtime_session = 0;
|
||||
current.window_commands.clear();
|
||||
}
|
||||
match current.commit(epoch, document) {
|
||||
Ok(Some(_)) => {}
|
||||
Ok(None) => return superseded(epoch),
|
||||
Err(error) => return error_response(StatusCode(500), error.to_string()),
|
||||
}
|
||||
current.window_viewports.remove(&input.window);
|
||||
drop(current);
|
||||
notify();
|
||||
json(
|
||||
StatusCode(200),
|
||||
serde_json::json!({"ok":true,"execution":"window-retire","window":input.window,"callbacks":false,"runtime_discarded":discarded}),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn refresh_viewport(
|
||||
&mut self,
|
||||
namespace: &Arc<RwLock<NamespaceState>>,
|
||||
notify: &Notify,
|
||||
) {
|
||||
self.refresh_viewport_mode(namespace, notify, false);
|
||||
}
|
||||
|
||||
pub(super) fn refresh_viewport_mode(
|
||||
&mut self,
|
||||
namespace: &Arc<RwLock<NamespaceState>>,
|
||||
notify: &Notify,
|
||||
before_input: bool,
|
||||
) {
|
||||
let (epoch, viewports) = match namespace.read() {
|
||||
Ok(current) => {
|
||||
let viewports = current_viewports(¤t);
|
||||
(current.submission, viewports)
|
||||
}
|
||||
Err(_) => return,
|
||||
};
|
||||
let Some((owner, runtime)) = &mut self.repl else {
|
||||
return;
|
||||
};
|
||||
if *owner != epoch {
|
||||
if let Ok(current) = namespace.read() {
|
||||
self.preserve_live_owner(¤t);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let id = runtime.id;
|
||||
let result = catch_unwind(AssertUnwindSafe(|| -> Result<_> {
|
||||
if runtime.is_faulted() {
|
||||
runtime.poll_tasks()?;
|
||||
return Ok((None, Vec::new()));
|
||||
}
|
||||
let resized = runtime.resize_windows_incremental(&viewports, false)?;
|
||||
if runtime.has_pending_refresh() {
|
||||
return Ok((None, Vec::new()));
|
||||
}
|
||||
// An accepted foreground input waits only for the existing
|
||||
// refresh; do not keep placing new callbacks ahead of it.
|
||||
let completed = if before_input {
|
||||
None
|
||||
} else {
|
||||
runtime.poll_tasks_incremental(&viewports)?
|
||||
};
|
||||
if runtime.has_pending_refresh() {
|
||||
// A complete earlier resize may publish; task effects and their
|
||||
// native commands wait until the task's refresh has settled.
|
||||
return Ok((resized, Vec::new()));
|
||||
}
|
||||
Ok((completed.or(resized), runtime.take_window_commands()?))
|
||||
}));
|
||||
let mut current = match namespace.write() {
|
||||
Ok(current) => current,
|
||||
Err(_) => return,
|
||||
};
|
||||
if current.submission != epoch || current.runtime_session != id {
|
||||
return;
|
||||
}
|
||||
let (document, commands) = match result {
|
||||
Ok(Ok((document, commands))) => {
|
||||
if let Some(document) = document {
|
||||
(document, Some(commands))
|
||||
} else {
|
||||
let projected = !commands.is_empty();
|
||||
current.publish_window_commands(id, commands);
|
||||
drop(current);
|
||||
if projected {
|
||||
notify();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
failure => {
|
||||
let mut document = current.document.clone();
|
||||
document.frame.fault = Some(match failure {
|
||||
Ok(Err(error)) => format!("Runtime background update failed: {error:#}")
|
||||
.chars()
|
||||
.take(1024)
|
||||
.collect(),
|
||||
_ => {
|
||||
self.repl = None;
|
||||
current.runtime_session = 0;
|
||||
current.window_commands.clear();
|
||||
"Runtime discarded after an internal background failure".into()
|
||||
}
|
||||
});
|
||||
for view in document.windows.values_mut() {
|
||||
view.frame.fault = document.frame.fault.clone();
|
||||
}
|
||||
(document, None)
|
||||
}
|
||||
};
|
||||
let changed = matches!(current.commit(epoch, document), Ok(Some(_)));
|
||||
if changed && let Some(commands) = commands {
|
||||
current.publish_window_commands(id, commands);
|
||||
}
|
||||
drop(current);
|
||||
if changed {
|
||||
notify();
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn begin_request(
|
||||
&mut self,
|
||||
job: &BuildRequest,
|
||||
namespace: &Arc<RwLock<NamespaceState>>,
|
||||
notify: &Notify,
|
||||
) -> RequestProgress {
|
||||
if job.kind == RequestKind::Code {
|
||||
return self.begin_program_request(job, namespace, notify);
|
||||
}
|
||||
if job.kind == RequestKind::Expression {
|
||||
return RequestProgress::Complete(build(job, namespace, notify));
|
||||
}
|
||||
// Advance one existing refresh quantum, then park the HTTP request.
|
||||
// No input statement executes inside the read-only scope; shutdown and
|
||||
// newer viewport targets can be observed at every worker turn.
|
||||
self.refresh_viewport_mode(namespace, notify, true);
|
||||
let epoch = match namespace.read() {
|
||||
Ok(current) => current.submission,
|
||||
Err(_) => {
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(500),
|
||||
"namespace lock is poisoned",
|
||||
));
|
||||
}
|
||||
};
|
||||
if epoch != job.submission {
|
||||
return RequestProgress::Complete(superseded(job.submission));
|
||||
}
|
||||
if job.kind == RequestKind::ResetRepl {
|
||||
self.repl = None;
|
||||
if let Ok(mut current) = namespace.write() {
|
||||
current.document.frame.session = 0;
|
||||
current.document.frame.focus = None;
|
||||
for document in current.document.windows.values_mut() {
|
||||
document.frame.session = 0;
|
||||
document.frame.focus = None;
|
||||
}
|
||||
current.runtime_session = 0;
|
||||
current.window_commands.clear();
|
||||
}
|
||||
notify();
|
||||
return RequestProgress::Complete(json(
|
||||
StatusCode(200),
|
||||
serde_json::json!({"ok":true,"execution":"repl-reset","persistent":true,"session_reset":true,"message":"Console memory cleared; displayed page preserved"}),
|
||||
));
|
||||
}
|
||||
if self
|
||||
.repl
|
||||
.as_ref()
|
||||
.is_some_and(|(_, runtime)| runtime.has_pending_refresh())
|
||||
{
|
||||
return RequestProgress::Pending(PendingRequest::BeforeInput);
|
||||
}
|
||||
let event = if job.kind == RequestKind::Event {
|
||||
let input: crate::events::Input = match serde_json::from_str(&job.source) {
|
||||
Ok(input) => input,
|
||||
Err(error) => {
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(400),
|
||||
error.to_string(),
|
||||
));
|
||||
}
|
||||
};
|
||||
if !input.kind.starts_with("developer-open:")
|
||||
&& !matches!(
|
||||
input.kind.as_str(),
|
||||
"click"
|
||||
| "focus"
|
||||
| "scroll"
|
||||
| "tab-activate"
|
||||
| "tab-close"
|
||||
| "tab-detach"
|
||||
| "tab-drop"
|
||||
| "window-close"
|
||||
)
|
||||
{
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(400),
|
||||
"unsupported event kind",
|
||||
));
|
||||
}
|
||||
if let Err(message) = input.validate() {
|
||||
return RequestProgress::Complete(error_response(StatusCode(400), message));
|
||||
}
|
||||
let current = match namespace.read() {
|
||||
Ok(current) => current,
|
||||
Err(_) => {
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(500),
|
||||
"namespace lock poisoned",
|
||||
));
|
||||
}
|
||||
};
|
||||
let frame = if input.window == crate::window::MAIN_WINDOW {
|
||||
¤t.document.frame
|
||||
} else {
|
||||
let Some(document) = current.document.windows.get(&input.window) else {
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(409),
|
||||
"window is no longer active",
|
||||
));
|
||||
};
|
||||
&document.frame
|
||||
};
|
||||
if input.kind == "window-close"
|
||||
&& frame.window == input.window
|
||||
&& frame.session == input.session
|
||||
{
|
||||
let owns = self.repl.as_ref().is_some_and(|(owner, runtime)| {
|
||||
*owner == epoch && runtime.id == input.session && input.session != 0
|
||||
});
|
||||
let stopped = frame.fault.is_some()
|
||||
|| !owns
|
||||
|| self
|
||||
.repl
|
||||
.as_ref()
|
||||
.is_some_and(|(_, runtime)| runtime.is_faulted());
|
||||
if stopped {
|
||||
drop(current);
|
||||
return RequestProgress::Complete(
|
||||
self.close_inactive_window(&input, epoch, namespace, notify),
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(target) = &input.tab_drop {
|
||||
let target_frame = if target.window == crate::window::MAIN_WINDOW {
|
||||
Some(¤t.document.frame)
|
||||
} else {
|
||||
current
|
||||
.document
|
||||
.windows
|
||||
.get(&target.window)
|
||||
.map(|document| &document.frame)
|
||||
};
|
||||
if target_frame.is_none_or(|frame| {
|
||||
frame.window != target.window
|
||||
|| frame.session != input.session
|
||||
|| frame.layout_version != target.layout_version
|
||||
|| frame.fault.is_some()
|
||||
|| target.index > frame.tabs.len()
|
||||
}) || self
|
||||
.repl
|
||||
.as_ref()
|
||||
.is_none_or(|(_, runtime)| !runtime.accepts_tab_drop(&input))
|
||||
{
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(409),
|
||||
"drop targets an obsolete or inactive frame",
|
||||
));
|
||||
}
|
||||
}
|
||||
if frame.window != input.window
|
||||
|| frame.session != input.session
|
||||
|| (input.kind != "window-close" && frame.layout_version != input.layout_version)
|
||||
|| frame.fault.is_some()
|
||||
|| if input.kind == "window-close" || input.kind.starts_with("developer-open:") {
|
||||
input.mount != 0
|
||||
} else if matches!(
|
||||
input.kind.as_str(),
|
||||
"tab-activate" | "tab-close" | "tab-detach" | "tab-drop"
|
||||
) {
|
||||
!frame.tabs.iter().any(|tab| tab.id == input.mount)
|
||||
} else {
|
||||
!frame.mounts.iter().any(|mount| {
|
||||
mount.id == input.mount
|
||||
&& (mount.interactive
|
||||
|| input.kind == "scroll" && mount.scroll.is_some())
|
||||
})
|
||||
}
|
||||
|| self.repl.as_ref().is_none_or(|(context, runtime)| {
|
||||
*context != epoch
|
||||
|| runtime.id != input.session
|
||||
|| (input.kind != "window-close" && !runtime.accepts_window(input.window))
|
||||
})
|
||||
{
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(409),
|
||||
"event targets an obsolete or inactive frame",
|
||||
));
|
||||
}
|
||||
Some(input)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if self
|
||||
.repl
|
||||
.as_ref()
|
||||
.is_none_or(|(current, _)| *current != epoch)
|
||||
{
|
||||
self.next_session = match self.next_session.checked_add(1) {
|
||||
Some(id) => id,
|
||||
None => {
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(500),
|
||||
"session identities exhausted",
|
||||
));
|
||||
}
|
||||
};
|
||||
let viewport = namespace.read().ok().and_then(|current| current.viewport);
|
||||
match endor_host::ReplSession::new_with_viewport(self.next_session, viewport) {
|
||||
Ok(session) => {
|
||||
if let Ok(mut current) = namespace.write()
|
||||
&& current.submission == epoch
|
||||
{
|
||||
current.publish_window_commands(session.id, Vec::new());
|
||||
}
|
||||
self.repl = Some((epoch, session));
|
||||
}
|
||||
Err(error) => {
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(500),
|
||||
error.to_string(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
let viewports = match namespace.read() {
|
||||
Ok(current) => current_viewports(¤t),
|
||||
Err(_) => {
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(500),
|
||||
"namespace lock is poisoned",
|
||||
));
|
||||
}
|
||||
};
|
||||
let session = &mut self.repl.as_mut().expect("initialized REPL").1;
|
||||
let id = session.id;
|
||||
let result = catch_unwind(AssertUnwindSafe(|| -> Result<_> {
|
||||
let result = if let Some(event) = &event {
|
||||
session.dispatch_incremental(event, &viewports)?
|
||||
} else {
|
||||
session.execute_incremental(&job.source, &job.namespace, &viewports)?
|
||||
};
|
||||
let commands = if session.has_pending_refresh() {
|
||||
Vec::new()
|
||||
} else {
|
||||
session.take_window_commands()?
|
||||
};
|
||||
Ok((result, commands))
|
||||
}));
|
||||
let faulted = session.is_faulted();
|
||||
if session.has_pending_refresh() {
|
||||
if let Ok(Ok((result, _))) = result {
|
||||
return RequestProgress::Pending(PendingRequest::Input(Box::new(PendingInput {
|
||||
epoch,
|
||||
id,
|
||||
event: event.is_some(),
|
||||
result,
|
||||
})));
|
||||
}
|
||||
// A failed start must never leave a request waiting on a broken VM.
|
||||
self.repl = None;
|
||||
}
|
||||
RequestProgress::Complete(self.finish_input(
|
||||
job,
|
||||
namespace,
|
||||
notify,
|
||||
epoch,
|
||||
id,
|
||||
event.is_some(),
|
||||
faulted,
|
||||
result,
|
||||
))
|
||||
}
|
||||
|
||||
pub(super) fn resume_request(
|
||||
&mut self,
|
||||
job: &BuildRequest,
|
||||
pending: PendingRequest,
|
||||
namespace: &Arc<RwLock<NamespaceState>>,
|
||||
notify: &Notify,
|
||||
) -> RequestProgress {
|
||||
match pending {
|
||||
PendingRequest::BeforeInput => self.begin_request(job, namespace, notify),
|
||||
PendingRequest::Input(input) => self.resume_input(job, input, namespace, notify),
|
||||
PendingRequest::Candidate(runtime) => {
|
||||
self.resume_candidate(job, runtime, namespace, notify)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn resume_input(
|
||||
&mut self,
|
||||
job: &BuildRequest,
|
||||
mut input: Box<PendingInput>,
|
||||
namespace: &Arc<RwLock<NamespaceState>>,
|
||||
notify: &Notify,
|
||||
) -> RequestProgress {
|
||||
let viewports = match namespace.read() {
|
||||
Ok(current)
|
||||
if current.submission == input.epoch || current.runtime_session == input.id =>
|
||||
{
|
||||
current_viewports(¤t)
|
||||
}
|
||||
Ok(_) => {
|
||||
self.repl = None;
|
||||
return RequestProgress::Complete(superseded(job.submission));
|
||||
}
|
||||
Err(_) => {
|
||||
self.repl = None;
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(500),
|
||||
"namespace lock is poisoned",
|
||||
));
|
||||
}
|
||||
};
|
||||
let Some((epoch, session)) = &mut self.repl else {
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(409),
|
||||
"input runtime was discarded",
|
||||
));
|
||||
};
|
||||
if *epoch != input.epoch || session.id != input.id {
|
||||
return RequestProgress::Complete(superseded(job.submission));
|
||||
}
|
||||
let resumed = catch_unwind(AssertUnwindSafe(|| -> Result<_> {
|
||||
let document = session.resize_windows_incremental(&viewports, false)?;
|
||||
if session.has_pending_refresh() {
|
||||
return Ok(None);
|
||||
}
|
||||
Ok(Some((document, session.take_window_commands()?)))
|
||||
}));
|
||||
let faulted = session.is_faulted();
|
||||
let result = match resumed {
|
||||
Ok(Ok(None)) => return RequestProgress::Pending(PendingRequest::Input(input)),
|
||||
Ok(Ok(Some((document, commands)))) => {
|
||||
input.result.document = document;
|
||||
Ok(Ok((input.result, commands)))
|
||||
}
|
||||
Ok(Err(error)) => Ok(Err(error)),
|
||||
Err(panic) => Err(panic),
|
||||
};
|
||||
RequestProgress::Complete(self.finish_input(
|
||||
job,
|
||||
namespace,
|
||||
notify,
|
||||
input.epoch,
|
||||
input.id,
|
||||
input.event,
|
||||
faulted,
|
||||
result,
|
||||
))
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn finish_input(
|
||||
&mut self,
|
||||
job: &BuildRequest,
|
||||
namespace: &Arc<RwLock<NamespaceState>>,
|
||||
notify: &Notify,
|
||||
epoch: u64,
|
||||
id: u64,
|
||||
event: bool,
|
||||
faulted: bool,
|
||||
result: InputOutcome,
|
||||
) -> HttpResponse {
|
||||
let Ok(mut current) = namespace.write() else {
|
||||
return error_response(StatusCode(500), "namespace lock is poisoned");
|
||||
};
|
||||
let epoch = if current.submission != epoch {
|
||||
if current.runtime_session != id {
|
||||
drop(current);
|
||||
self.repl = None;
|
||||
return superseded(job.submission);
|
||||
}
|
||||
// Accepted PUTs invalidate queued inputs, not a mutation already
|
||||
// executing on this owner. Settle it before building the candidate
|
||||
// so a failed replacement can preserve a consistent live heap.
|
||||
if let Some((owner, runtime)) = &mut self.repl
|
||||
&& runtime.id == id
|
||||
{
|
||||
*owner = current.submission;
|
||||
}
|
||||
current.submission
|
||||
} else {
|
||||
epoch
|
||||
};
|
||||
match result {
|
||||
Ok(Ok((result, commands))) => {
|
||||
let projected = !commands.is_empty();
|
||||
let rendered = result.document.is_some();
|
||||
if let Some(document) = result.document {
|
||||
match current.commit(epoch, document) {
|
||||
Ok(Some(_)) => {}
|
||||
Ok(None) => return superseded(job.submission),
|
||||
Err(error) => return error_response(StatusCode(500), error.to_string()),
|
||||
}
|
||||
}
|
||||
current.publish_window_commands(id, commands);
|
||||
let revision = current.revision;
|
||||
drop(current);
|
||||
if rendered || projected {
|
||||
notify();
|
||||
}
|
||||
json(
|
||||
StatusCode(200),
|
||||
serde_json::json!({"ok":true,"execution":if event { "event" } else { "repl" },"persistent":true,"session":id,"input":result.input,"value":result.value,"bindings":result.bindings,"rendered":rendered,"revision":revision}),
|
||||
)
|
||||
}
|
||||
Ok(Err(error)) => {
|
||||
if event || faulted {
|
||||
let mut document = current.document.clone();
|
||||
// Preserve the first failure of this VM; subsequent
|
||||
// rejected Console input must not hide the callback cause.
|
||||
// A preserved picture from another generation is unrelated.
|
||||
let fault = (document.frame.session == id)
|
||||
.then(|| document.frame.fault.clone())
|
||||
.flatten()
|
||||
.unwrap_or_else(|| format!("{error:#}").chars().take(1024).collect());
|
||||
document.frame.fault = Some(fault.clone());
|
||||
for view in document.windows.values_mut() {
|
||||
view.frame.fault = Some(fault.clone());
|
||||
}
|
||||
let _ = current.commit(epoch, document);
|
||||
drop(current);
|
||||
notify();
|
||||
}
|
||||
compile_error(error)
|
||||
}
|
||||
Err(_) => {
|
||||
let mut document = current.document.clone();
|
||||
document.frame.fault =
|
||||
Some("Runtime discarded after an internal execution failure".into());
|
||||
for view in document.windows.values_mut() {
|
||||
view.frame.fault = document.frame.fault.clone();
|
||||
}
|
||||
current.runtime_session = 0;
|
||||
current.window_commands.clear();
|
||||
let _ = current.commit(epoch, document);
|
||||
drop(current);
|
||||
self.repl = None;
|
||||
notify();
|
||||
json(
|
||||
StatusCode(500),
|
||||
serde_json::json!({"ok":false,"session_reset":true,"error":"Console execution failed internally; session discarded, displayed page preserved"}),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An accepted PUT changes the submission, but does not revoke the old
|
||||
/// runtime. DELETE clears runtime_session and does revoke it.
|
||||
pub(super) fn preserve_live_owner(&mut self, current: &NamespaceState) {
|
||||
if let Some((epoch, runtime)) = &mut self.repl {
|
||||
if current.runtime_session == runtime.id {
|
||||
*epoch = current.submission;
|
||||
} else {
|
||||
self.repl = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn begin_program_request(
|
||||
&mut self,
|
||||
job: &BuildRequest,
|
||||
namespace: &Arc<RwLock<NamespaceState>>,
|
||||
notify: &Notify,
|
||||
) -> RequestProgress {
|
||||
let viewport = match namespace.read() {
|
||||
Ok(current) if current.submission == job.submission => current.viewport,
|
||||
Ok(current) => {
|
||||
self.preserve_live_owner(¤t);
|
||||
return RequestProgress::Complete(superseded(job.submission));
|
||||
}
|
||||
Err(_) => {
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(500),
|
||||
"namespace lock poisoned",
|
||||
));
|
||||
}
|
||||
};
|
||||
self.next_session = match self.next_session.checked_add(1) {
|
||||
Some(id) => id,
|
||||
None => {
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(500),
|
||||
"session identities exhausted",
|
||||
));
|
||||
}
|
||||
};
|
||||
let id = self.next_session;
|
||||
let started = catch_unwind(AssertUnwindSafe(|| {
|
||||
endor_host::ReplSession::load_incremental(
|
||||
&job.source,
|
||||
&job.namespace,
|
||||
job.submission,
|
||||
id,
|
||||
viewport,
|
||||
)
|
||||
}));
|
||||
let result = match started {
|
||||
Ok(Ok((runtime, None))) => {
|
||||
return RequestProgress::Pending(PendingRequest::Candidate(Box::new(runtime)));
|
||||
}
|
||||
Ok(Ok((runtime, Some(document)))) => match runtime.take_window_commands() {
|
||||
Ok(commands) => Ok(Ok((runtime, document, commands))),
|
||||
Err(error) => Ok(Err(error)),
|
||||
},
|
||||
Ok(Err(error)) => Ok(Err(error)),
|
||||
Err(panic) => Err(panic),
|
||||
};
|
||||
RequestProgress::Complete(self.finish_candidate(job, namespace, notify, id, result))
|
||||
}
|
||||
|
||||
fn resume_candidate(
|
||||
&mut self,
|
||||
job: &BuildRequest,
|
||||
mut runtime: Box<endor_host::ReplSession>,
|
||||
namespace: &Arc<RwLock<NamespaceState>>,
|
||||
notify: &Notify,
|
||||
) -> RequestProgress {
|
||||
let viewports = match namespace.read() {
|
||||
Ok(current) if current.submission == job.submission => {
|
||||
// Secondary native resources still belong to the old VM. Only
|
||||
// the primary shell's current viewport applies to a candidate.
|
||||
current
|
||||
.viewport
|
||||
.map(|size| (crate::window::MAIN_WINDOW, size))
|
||||
.into_iter()
|
||||
.collect()
|
||||
}
|
||||
Ok(current) => {
|
||||
self.preserve_live_owner(¤t);
|
||||
return RequestProgress::Complete(superseded(job.submission));
|
||||
}
|
||||
Err(_) => {
|
||||
return RequestProgress::Complete(error_response(
|
||||
StatusCode(500),
|
||||
"namespace lock poisoned",
|
||||
));
|
||||
}
|
||||
};
|
||||
let id = runtime.id;
|
||||
let resumed = catch_unwind(AssertUnwindSafe(|| -> Result<_> {
|
||||
let document = runtime.resize_windows_incremental(&viewports, false)?;
|
||||
if runtime.has_pending_refresh() {
|
||||
return Ok(None);
|
||||
}
|
||||
let document =
|
||||
document.ok_or_else(|| anyhow::anyhow!("program did not publish a Page"))?;
|
||||
Ok(Some((document, runtime.take_window_commands()?)))
|
||||
}));
|
||||
let result = match resumed {
|
||||
Ok(Ok(None)) => return RequestProgress::Pending(PendingRequest::Candidate(runtime)),
|
||||
Ok(Ok(Some((document, commands)))) => Ok(Ok((*runtime, document, commands))),
|
||||
Ok(Err(error)) => Ok(Err(error)),
|
||||
Err(panic) => Err(panic),
|
||||
};
|
||||
RequestProgress::Complete(self.finish_candidate(job, namespace, notify, id, result))
|
||||
}
|
||||
|
||||
fn finish_candidate(
|
||||
&mut self,
|
||||
job: &BuildRequest,
|
||||
namespace: &Arc<RwLock<NamespaceState>>,
|
||||
notify: &Notify,
|
||||
id: u64,
|
||||
result: CandidateOutcome,
|
||||
) -> HttpResponse {
|
||||
let Ok(mut current) = namespace.write() else {
|
||||
return error_response(StatusCode(500), "namespace lock poisoned");
|
||||
};
|
||||
if current.submission != job.submission {
|
||||
self.preserve_live_owner(¤t);
|
||||
return superseded(job.submission);
|
||||
}
|
||||
match result {
|
||||
Ok(Ok((runtime, document, commands))) => match current.commit(job.submission, document)
|
||||
{
|
||||
Ok(Some(revision)) => {
|
||||
current.publish_window_commands(id, commands);
|
||||
self.repl = Some((job.submission, runtime));
|
||||
drop(current);
|
||||
notify();
|
||||
json(
|
||||
StatusCode(200),
|
||||
serde_json::json!({"ok":true,"namespace":job.namespace,"submission":job.submission,"revision":revision,"diagnostics":[],"session":id,"persistent":true}),
|
||||
)
|
||||
}
|
||||
Ok(None) => superseded(job.submission),
|
||||
Err(error) => error_response(StatusCode(500), error.to_string()),
|
||||
},
|
||||
failed => {
|
||||
// The candidate never mutated the displayed program's heap.
|
||||
// Restore that program's event epoch when a replacement fails.
|
||||
self.preserve_live_owner(¤t);
|
||||
drop(current);
|
||||
match failed {
|
||||
Ok(Err(error)) => compile_error(error),
|
||||
_ => error_response(
|
||||
StatusCode(500),
|
||||
"candidate failed internally; previous runtime preserved",
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn build(
|
||||
job: &BuildRequest,
|
||||
namespace: &Arc<RwLock<NamespaceState>>,
|
||||
notify: &Notify,
|
||||
) -> Response<std::io::Cursor<Vec<u8>>> {
|
||||
if job.kind == RequestKind::Expression {
|
||||
return match catch_unwind(AssertUnwindSafe(|| endor_host::evaluate(&job.source))) {
|
||||
Ok(Ok(value)) => json(
|
||||
StatusCode(200),
|
||||
serde_json::json!({"ok":true,"value":value,"execution":"isolated-expression","persistent":false}),
|
||||
),
|
||||
Ok(Err(error)) => compile_error(error),
|
||||
Err(_) => error_response(StatusCode(500), "expression execution failed internally"),
|
||||
};
|
||||
}
|
||||
match namespace.read() {
|
||||
Ok(current) if current.submission != job.submission => return superseded(job.submission),
|
||||
Err(_) => return error_response(StatusCode(500), "namespace lock is poisoned"),
|
||||
_ => {}
|
||||
}
|
||||
// Only an independent native snapshot crosses into the published state.
|
||||
// A fresh VM is discarded on success, error and unwind alike.
|
||||
let result = catch_unwind(AssertUnwindSafe(|| {
|
||||
endor_host::compile(&job.source, &job.namespace, job.submission)
|
||||
}));
|
||||
let Ok(mut current) = namespace.write() else {
|
||||
return error_response(StatusCode(500), "namespace lock is poisoned");
|
||||
};
|
||||
if current.submission != job.submission {
|
||||
return superseded(job.submission);
|
||||
}
|
||||
match result {
|
||||
Ok(Ok(document)) => match current.commit(job.submission, document) {
|
||||
Ok(Some(revision)) => {
|
||||
drop(current);
|
||||
notify();
|
||||
json(
|
||||
StatusCode(200),
|
||||
serde_json::json!({ "ok": true, "namespace": job.namespace,
|
||||
"submission": job.submission, "revision": revision, "diagnostics": [] }),
|
||||
)
|
||||
}
|
||||
Ok(None) => superseded(job.submission),
|
||||
Err(error) => error_response(StatusCode(500), error.to_string()),
|
||||
},
|
||||
Ok(Err(error)) => compile_error(error),
|
||||
Err(_) => error_response(
|
||||
StatusCode(500),
|
||||
"candidate execution failed internally; previous document preserved",
|
||||
),
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
use super::*;
|
||||
use crate::document::{NamespaceState, RenderCommand};
|
||||
|
||||
const EXAMPLE: &str = include_str!("../../examples/hello.endor");
|
||||
const PAGE: &str = include_str!("../../examples/page.endor");
|
||||
const EXAMPLE: &str = include_str!("../../../examples/hello.endor");
|
||||
const PAGE: &str = include_str!("../../../examples/page.endor");
|
||||
|
||||
#[test]
|
||||
fn actual_mount_version_reads_still_bypass_measurement_cache() {
|
||||
@@ -36,7 +36,7 @@ page.render(rect)
|
||||
#[test]
|
||||
fn source_allocations_and_measurement_limits_settle_before_publication() {
|
||||
let (mut session, initial) = ReplSession::load_with_viewport(
|
||||
include_str!("../../examples/layout-negotiation.endor"),
|
||||
include_str!("../../../examples/layout-negotiation.endor"),
|
||||
"app.main",
|
||||
1,
|
||||
240,
|
||||
@@ -283,7 +283,7 @@ page.render(Column(0,8,Column(0,8,paragraph,tail),Column(50,8,paragraph)))
|
||||
#[test]
|
||||
fn native_signatures_validate_registration_and_deliver_the_event_argument() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
include_str!("../../examples/native-signatures.endor"),
|
||||
include_str!("../../../examples/native-signatures.endor"),
|
||||
"app.main",
|
||||
1,
|
||||
220,
|
||||
@@ -349,7 +349,7 @@ fn native_signatures_validate_registration_and_deliver_the_event_argument() {
|
||||
#[test]
|
||||
fn checked_fields_reject_native_constructor_side_effects_and_preserve_live_values() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
include_str!("../../examples/field-contracts.endor"),
|
||||
include_str!("../../../examples/field-contracts.endor"),
|
||||
"app.main",
|
||||
1,
|
||||
210,
|
||||
@@ -515,7 +515,7 @@ fn positional_insert_preserves_existing_slots_and_mounts_and_rejects_invalid_gra
|
||||
#[test]
|
||||
fn tab_drop_preserves_page_identity_calls_source_methods_and_rejects_stale_targets() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
include_str!("../../examples/tab-placement.endor"),
|
||||
include_str!("../../../examples/tab-placement.endor"),
|
||||
"app.main",
|
||||
1,
|
||||
201,
|
||||
@@ -1009,7 +1009,7 @@ fn orphan_task_scope_is_collectable_and_callback_failure_stops_remaining_work()
|
||||
#[test]
|
||||
fn source_annotations_classify_functions_and_reject_before_body() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
include_str!("../../examples/function-types.endor"),
|
||||
include_str!("../../../examples/function-types.endor"),
|
||||
"app.main",
|
||||
1,
|
||||
180,
|
||||
@@ -1180,7 +1180,7 @@ fn stopped_window_teardown_detaches_mounts_without_running_source_hooks() {
|
||||
#[test]
|
||||
fn native_windows_share_business_state_move_pages_and_release_closed_contexts() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
include_str!("../../examples/windows.endor"),
|
||||
include_str!("../../../examples/windows.endor"),
|
||||
"app.main",
|
||||
1,
|
||||
130,
|
||||
@@ -1279,7 +1279,7 @@ fn native_windows_share_business_state_move_pages_and_release_closed_contexts()
|
||||
#[test]
|
||||
fn failed_input_after_window_close_cannot_leave_owned_mounts_in_closed_context() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
include_str!("../../examples/windows.endor"),
|
||||
include_str!("../../../examples/windows.endor"),
|
||||
"app.main",
|
||||
1,
|
||||
131,
|
||||
@@ -1633,7 +1633,7 @@ page2.moveToWindow(window2)
|
||||
#[test]
|
||||
fn source_measure_cache_reuses_independent_results_and_invalidates_model_changes() {
|
||||
let (mut session, initial) = ReplSession::load_with_viewport(
|
||||
include_str!("../../examples/layout-cache.endor"),
|
||||
include_str!("../../../examples/layout-cache.endor"),
|
||||
"app.main",
|
||||
101,
|
||||
1,
|
||||
@@ -1748,7 +1748,7 @@ fn source_measure_cache_tracks_fields_of_an_existing_returned_result() {
|
||||
#[test]
|
||||
fn viewport_resize_changes_constraints_and_preserves_mount_identity_without_source_input() {
|
||||
let (mut session, initial) = ReplSession::load_with_viewport(
|
||||
include_str!("../../examples/layout-cache.endor"),
|
||||
include_str!("../../../examples/layout-cache.endor"),
|
||||
"app.main",
|
||||
102,
|
||||
1,
|
||||
@@ -1803,7 +1803,7 @@ fn viewport_resize_changes_constraints_and_preserves_mount_identity_without_sour
|
||||
assert!(!session.is_faulted());
|
||||
}
|
||||
|
||||
const SOURCE_LAYOUT: &str = include_str!("../../examples/source-layout.endor");
|
||||
const SOURCE_LAYOUT: &str = include_str!("../../../examples/source-layout.endor");
|
||||
|
||||
#[test]
|
||||
fn source_layout_uses_initial_mount_links_child_measurements_and_model_dependencies() {
|
||||
@@ -1937,7 +1937,7 @@ fn source_hit_filters_shape_falls_back_and_requires_matching_press_release() {
|
||||
([9999.0, 9999.0], [9999.0, 9999.0], "0", "0"),
|
||||
] {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
include_str!("../../examples/source-hit.endor"),
|
||||
include_str!("../../../examples/source-hit.endor"),
|
||||
"app.main",
|
||||
81,
|
||||
1,
|
||||
@@ -1986,7 +1986,7 @@ fn source_hit_rejects_wrong_result_and_business_writes_before_callbacks() {
|
||||
"read-only",
|
||||
),
|
||||
] {
|
||||
let source = include_str!("../../examples/source-hit.endor")
|
||||
let source = include_str!("../../../examples/source-hit.endor")
|
||||
.replace("return point.inCircle(40, 40, 40)", body);
|
||||
let (mut session, initial) = ReplSession::load(&source, "app.main", 82, 1).unwrap();
|
||||
let circle = initial
|
||||
@@ -2063,8 +2063,8 @@ fn resumable_paint_source(copies: usize, locals: usize) -> String {
|
||||
#[test]
|
||||
fn collecting_lazy_helpers_does_not_invalidate_stable_layout_or_paint() {
|
||||
for source in [
|
||||
include_str!("../../examples/flex-constraints.endor"),
|
||||
include_str!("../../examples/source-paint.endor"),
|
||||
include_str!("../../../examples/flex-constraints.endor"),
|
||||
include_str!("../../../examples/source-paint.endor"),
|
||||
] {
|
||||
let (mut session, initial) = ReplSession::load(source, "app.main", 281, 1).unwrap();
|
||||
session
|
||||
@@ -2257,7 +2257,7 @@ fn source_paint_can_rebind_old_plain_reference_to_new_result_without_mutating_it
|
||||
#[test]
|
||||
fn source_paint_overrides_native_commands_and_reacts_to_heap_field_writes() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
include_str!("../../examples/source-paint.endor"),
|
||||
include_str!("../../../examples/source-paint.endor"),
|
||||
"app.main",
|
||||
71,
|
||||
1,
|
||||
@@ -2334,13 +2334,13 @@ fn source_paint_rejects_business_mutation_before_it_happens_and_restores_scope()
|
||||
.set_attr(rect, "tint", Value::Text("#526AC7".into()))
|
||||
.unwrap();
|
||||
let bad_color =
|
||||
include_str!("../../examples/source-paint.endor").replace("#ED6A5A", "invalid color");
|
||||
include_str!("../../../examples/source-paint.endor").replace("#ED6A5A", "invalid color");
|
||||
assert!(ReplSession::load(&bad_color, "app.main", 73, 1).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_paint_is_stable_when_mount_notifications_overflow_the_change_batch() {
|
||||
let fixture = include_str!("../../examples/source-paint.endor");
|
||||
let fixture = include_str!("../../../examples/source-paint.endor");
|
||||
let mut source = fixture[..fixture.find("root = Column").unwrap()].to_owned();
|
||||
source.push_str("root = Column(0, 0");
|
||||
for _ in 0..1100 {
|
||||
@@ -2355,7 +2355,7 @@ fn source_paint_is_stable_when_mount_notifications_overflow_the_change_batch() {
|
||||
#[test]
|
||||
fn constructor_options_and_subclass_fields_have_independent_contracts() {
|
||||
let (mut session, document) = ReplSession::load(
|
||||
include_str!("../../examples/constructor-contracts.endor"),
|
||||
include_str!("../../../examples/constructor-contracts.endor"),
|
||||
"app.main",
|
||||
166,
|
||||
1,
|
||||
@@ -2455,7 +2455,7 @@ fn constructor_options_and_subclass_fields_have_independent_contracts() {
|
||||
|
||||
#[test]
|
||||
fn source_overrides_accept_wider_inputs_and_more_specific_results() {
|
||||
let source = include_str!("../../examples/method-contracts.endor");
|
||||
let source = include_str!("../../../examples/method-contracts.endor");
|
||||
let (mut session, document) = ReplSession::load(source, "app.main", 164, 1).unwrap();
|
||||
document.validate().unwrap();
|
||||
assert_eq!(
|
||||
@@ -2497,7 +2497,7 @@ fn source_overrides_accept_wider_inputs_and_more_specific_results() {
|
||||
#[test]
|
||||
fn nullable_page_methods_union_event_options_and_nominal_mount_bounds_compose() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
include_str!("../../examples/visual-protocols.endor"),
|
||||
include_str!("../../../examples/visual-protocols.endor"),
|
||||
"app.main",
|
||||
163,
|
||||
1,
|
||||
@@ -2534,7 +2534,7 @@ fn nullable_page_methods_union_event_options_and_nominal_mount_bounds_compose()
|
||||
#[test]
|
||||
fn native_contracts_reject_wrong_types_before_geometry_or_window_effects() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
include_str!("../../examples/visual-protocols.endor"),
|
||||
include_str!("../../../examples/visual-protocols.endor"),
|
||||
"app.main",
|
||||
162,
|
||||
1,
|
||||
@@ -2586,7 +2586,7 @@ fn native_contracts_reject_wrong_types_before_geometry_or_window_effects() {
|
||||
#[test]
|
||||
fn native_visual_methods_use_managed_values_and_match_real_geometry() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
include_str!("../../examples/visual-protocols.endor"),
|
||||
include_str!("../../../examples/visual-protocols.endor"),
|
||||
"app.main",
|
||||
61,
|
||||
1,
|
||||
@@ -2647,7 +2647,7 @@ fn native_visual_methods_use_managed_values_and_match_real_geometry() {
|
||||
#[test]
|
||||
fn explicit_invalidation_publishes_once_preserves_mount_and_remeasures_only_when_requested() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
include_str!("../../examples/visual-protocols.endor"),
|
||||
include_str!("../../../examples/visual-protocols.endor"),
|
||||
"app.main",
|
||||
62,
|
||||
1,
|
||||
@@ -2708,7 +2708,7 @@ fn explicit_invalidation_publishes_once_preserves_mount_and_remeasures_only_when
|
||||
#[test]
|
||||
fn mount_hooks_run_per_occurrence_settle_and_unmount_before_parent() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
include_str!("../../examples/mount-lifecycle.endor"),
|
||||
include_str!("../../../examples/mount-lifecycle.endor"),
|
||||
"app.main",
|
||||
51,
|
||||
1,
|
||||
@@ -2787,7 +2787,7 @@ fn mount_hooks_run_per_occurrence_settle_and_unmount_before_parent() {
|
||||
#[test]
|
||||
fn page_switch_replaces_mount_context_even_for_shared_root() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
include_str!("../../examples/mount-lifecycle.endor"),
|
||||
include_str!("../../../examples/mount-lifecycle.endor"),
|
||||
"app.main",
|
||||
52,
|
||||
1,
|
||||
@@ -2857,7 +2857,11 @@ fn lifecycle_hook_can_edit_container_without_session_lock_and_failure_stops_doma
|
||||
}
|
||||
|
||||
fn event_session(extra: &str) -> (ReplSession, RenderDocument) {
|
||||
let source = format!("{}\n{}", include_str!("../../examples/events.endor"), extra);
|
||||
let source = format!(
|
||||
"{}\n{}",
|
||||
include_str!("../../../examples/events.endor"),
|
||||
extra
|
||||
);
|
||||
ReplSession::load(&source, "app.main", 41, 1).unwrap()
|
||||
}
|
||||
|
||||
@@ -3061,7 +3065,7 @@ fn event_failure_releases_dispatch_guard_and_token_does_not_retain_target() {
|
||||
#[test]
|
||||
fn source_native_subclasses_share_live_fields_and_release_replaced_storage() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
include_str!("../../examples/native-subclasses.endor"),
|
||||
include_str!("../../../examples/native-subclasses.endor"),
|
||||
"app.main",
|
||||
31,
|
||||
1,
|
||||
@@ -3143,7 +3147,7 @@ fn source_native_subclasses_share_live_fields_and_release_replaced_storage() {
|
||||
#[test]
|
||||
fn loaded_program_console_and_native_events_share_unique_source_ids() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
include_str!("../../examples/managed-types.endor"),
|
||||
include_str!("../../../examples/managed-types.endor"),
|
||||
"app.main",
|
||||
1,
|
||||
1,
|
||||
@@ -3194,7 +3198,7 @@ fn loaded_program_console_and_native_events_share_unique_source_ids() {
|
||||
#[test]
|
||||
fn scroll_occurrences_are_independent_and_clipped_pointer_input_is_ignored() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
include_str!("../../examples/scroll.endor"),
|
||||
include_str!("../../../examples/scroll.endor"),
|
||||
"app.main",
|
||||
1,
|
||||
240,
|
||||
@@ -3626,7 +3630,7 @@ fn idle_tasks_wait_for_prior_callback_refresh_before_next_delivery() {
|
||||
#[test]
|
||||
fn incremental_viewport_refresh_retains_published_documents_until_complete() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
include_str!("../../examples/flex-constraints.endor"),
|
||||
include_str!("../../../examples/flex-constraints.endor"),
|
||||
"app.main",
|
||||
271,
|
||||
1,
|
||||
@@ -3967,7 +3971,7 @@ fn main_alignment_updates_live_geometry_without_changing_sizes() {
|
||||
#[test]
|
||||
fn scroll_axes_wrap_shared_text_and_clamp_only_the_enabled_offsets() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
include_str!("../../examples/scroll-axis.endor"),
|
||||
include_str!("../../../examples/scroll-axis.endor"),
|
||||
"app.main",
|
||||
260,
|
||||
1,
|
||||
@@ -4606,7 +4610,7 @@ fn presentable_type_contracts_reject_before_registration_or_body_effects() {
|
||||
#[test]
|
||||
fn presentable_dispatch_preserves_source_identity_and_reactive_display() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
include_str!("../../examples/presentable.endor"),
|
||||
include_str!("../../../examples/presentable.endor"),
|
||||
"app.main",
|
||||
1,
|
||||
230,
|
||||
@@ -4855,7 +4859,7 @@ page.render(rect)
|
||||
#[test]
|
||||
fn source_render_caches_do_not_root_a_page_block_waiting_frame_cycle() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
include_str!("../../examples/gc-lifecycle.endor"),
|
||||
include_str!("../../../examples/gc-lifecycle.endor"),
|
||||
"app.main",
|
||||
902,
|
||||
1,
|
||||
@@ -5245,7 +5249,7 @@ fn top_level_goal_script_renders_without_a_main_or_synthetic_wrapper() {
|
||||
matches!(&document.frame.commands[1], RenderCommand::RoundedRect { x: 24.0, y: 76.0, width: 240.0, height: 80.0, radius: 12.0, color } if color == "#DCE8FF")
|
||||
);
|
||||
assert_eq!(document.display_list(2.0).unwrap().commands().len(), 3);
|
||||
let wrapped = compile(include_str!("../../examples/main.endor"), "app.main", 10).unwrap();
|
||||
let wrapped = compile(include_str!("../../../examples/main.endor"), "app.main", 10).unwrap();
|
||||
assert_eq!(
|
||||
serde_json::to_value(&document.frame.commands).unwrap(),
|
||||
serde_json::to_value(&wrapped.frame.commands).unwrap()
|
||||
@@ -0,0 +1,9 @@
|
||||
// Module ownership follows the directory; crate-root aliases keep internal call sites stable.
|
||||
pub(crate) mod api;
|
||||
pub(crate) mod endor_host;
|
||||
pub(crate) mod endor_script;
|
||||
pub(crate) mod event_dispatch;
|
||||
pub(crate) mod events;
|
||||
pub(crate) mod io_tasks;
|
||||
pub(crate) mod tasks;
|
||||
pub(crate) mod vm_sequence;
|
||||
@@ -0,0 +1,10 @@
|
||||
// Module ownership follows the directory; crate-root aliases keep internal call sites stable.
|
||||
pub(crate) mod activity;
|
||||
pub(crate) mod app;
|
||||
pub(crate) mod clipboard;
|
||||
pub(crate) mod developer_tools;
|
||||
#[cfg(target_os = "macos")]
|
||||
pub(crate) mod native_chrome;
|
||||
pub(crate) mod sources;
|
||||
pub(crate) mod system_ui;
|
||||
pub(crate) mod tabs;
|
||||
@@ -54,7 +54,7 @@ leaving the editor. Rows and drag handles are excluded from Tab traversal. Text
|
||||
editing, clipboard and IME remain host adapters; the widget layer owns their chrome
|
||||
and focus presentation. `inline_input` registers a text-input target without a
|
||||
background or focus border; a terminal-style host draws its own caret in the same
|
||||
scrollable stream as output. `src/clipboard.rs` guarantees UTF-8 for macOS clipboard
|
||||
scrollable stream as output. `src/shell/clipboard.rs` guarantees UTF-8 for macOS clipboard
|
||||
subprocesses, independent of Finder's locale.
|
||||
|
||||
Tessera's developer tools are the first consumer. Domain actions, HTTP calls,
|
||||
Reference in New Issue
Block a user