Publish UI factory contracts and separate native options from subclass fields
This commit is contained in:
+3
-3
@@ -7,13 +7,13 @@
|
||||
| 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, 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 native constructor preflight and 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 and immutable frame extraction |
|
||||
| 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 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, 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 managed Event/Subscription methods, weak Subscription tokens, Block-owned connections and occurrence-specific capture/target/bubble through a budgeted VM driver |
|
||||
| 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 |
|
||||
| tasks.rs | Typed Task/ui.after methods, managed owner scopes and callbacks, weak timer index, request-key replacement, lifecycle cancellation and budgeted worker delivery |
|
||||
@@ -24,7 +24,7 @@
|
||||
| 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, 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, value conversion and bounded results |
|
||||
| object_list.rs | Typed read-only indexed access and traced results shared by Mount queries and visual protocol 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 |
|
||||
|
||||
+1
-1
@@ -1103,7 +1103,7 @@ Declared fields are checked at construction and set_attr writes through the same
|
||||
|
||||
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; Mutating/External calls are rejected before invocation during read-only execution. 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. Native effects may only shrink; source effects remain unknown and runtime read-only barriers still apply. See examples/method-contracts.endor. Constructors/other API coverage and static source effect inference remain pending. Unknown legacy metadata remains unknown. See examples/visual-protocols.endor and examples/layout-negotiation.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. 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. Native effects may only shrink; source effects remain unknown and runtime read-only barriers still apply. 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. Source/Delegated transitive effects remain unknown; static inference remains pending. 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. Source static effects and formal trait syntax remain pending. EventTarget requires canonical on/dispatch/onEvent arities 3/2/1 after self; native optional convenience forms remain.
|
||||
|
||||
|
||||
@@ -2951,6 +2951,107 @@ page.render(block)
|
||||
assert!(session.refresh_document().unwrap().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn constructor_options_and_subclass_fields_have_independent_contracts() {
|
||||
let (mut session, document) = ReplSession::load(
|
||||
include_str!("../examples/constructor-contracts.endor"),
|
||||
"app.main",
|
||||
166,
|
||||
1,
|
||||
)
|
||||
.unwrap();
|
||||
document.validate().unwrap();
|
||||
for (expression, expected) in [
|
||||
("rect.width", "180"),
|
||||
("rect.radius", "0"),
|
||||
("rect.tag", "\"省略 radius/color 后的字段\""),
|
||||
("root.tag", "\"可变子项之后的字段\""),
|
||||
("event.kind", "\"click\""),
|
||||
("items.count", "2"),
|
||||
("ui.isInstance(items.at(0), TaggedRect)", "true"),
|
||||
] {
|
||||
assert_eq!(
|
||||
session.execute(expression, "app.main").unwrap().value,
|
||||
expected,
|
||||
"{expression}"
|
||||
);
|
||||
}
|
||||
let blocks = session
|
||||
.execute("ui.stats().blocks", "app.main")
|
||||
.unwrap()
|
||||
.value;
|
||||
for (expression, expected) in [
|
||||
("TaggedRect(\"bad\", 60, \"tag\")", "expects Number"),
|
||||
("TaggedColumn(0, 0, 7, \"tag\")", "expects Block"),
|
||||
("ui.rect(1, 2, \"bad\")", "expects Number"),
|
||||
("ui.text(7)", "expects String"),
|
||||
("TaggedEvent(7, \"tag\")", "expects String"),
|
||||
("ui.isSubtype(7, Block)", "expects Type"),
|
||||
] {
|
||||
let error = session
|
||||
.execute(expression, "app.main")
|
||||
.err()
|
||||
.expect("invalid typed constructor/API");
|
||||
assert!(
|
||||
error.to_string().contains(expected),
|
||||
"{expression}: {error:#}"
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("ui.stats().blocks", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
blocks
|
||||
);
|
||||
session.execute("button.click()", "app.main").unwrap();
|
||||
assert_eq!(
|
||||
session.execute("rect.color", "app.main").unwrap().value,
|
||||
"\"#237A45\""
|
||||
);
|
||||
for name in [
|
||||
"open",
|
||||
"present",
|
||||
"text",
|
||||
"rect",
|
||||
"spacer",
|
||||
"row",
|
||||
"column",
|
||||
"button",
|
||||
"page",
|
||||
"state",
|
||||
"textOf",
|
||||
"stats",
|
||||
"viewport",
|
||||
"window",
|
||||
"isInstance",
|
||||
"isSubtype",
|
||||
"implement",
|
||||
"implements",
|
||||
"supports",
|
||||
"after",
|
||||
] {
|
||||
let Value::Object(function) = session
|
||||
.candidate
|
||||
.vm
|
||||
.get_attr(session.bridge.ui, name)
|
||||
.unwrap()
|
||||
else {
|
||||
panic!("native Function")
|
||||
};
|
||||
let signature = session
|
||||
.candidate
|
||||
.vm
|
||||
.object_store()
|
||||
.native_signature(function)
|
||||
.unwrap()
|
||||
.expect("published UI signature");
|
||||
signature
|
||||
.validate(session.candidate.vm.object_store())
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_overrides_accept_wider_inputs_and_more_specific_results() {
|
||||
let source = include_str!("../examples/method-contracts.endor");
|
||||
|
||||
@@ -179,8 +179,13 @@ impl NativeCallable for Method {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Constructor;
|
||||
pub struct Constructor {
|
||||
pub signature: Option<endor_core::CallSignature>,
|
||||
}
|
||||
impl NativeCallable for Constructor {
|
||||
fn signature(&self) -> Option<endor_core::CallSignature> {
|
||||
self.signature.clone()
|
||||
}
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::range(2, usize::MAX))
|
||||
}
|
||||
|
||||
@@ -102,9 +102,13 @@ pub fn items(store: &endor_core::ObjectStore, list: ObjectRef) -> Result<&[Objec
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Constructor {
|
||||
pub signature: Option<endor_core::CallSignature>,
|
||||
pub desktop: ObjectRef,
|
||||
}
|
||||
impl NativeCallable for Constructor {
|
||||
fn signature(&self) -> Option<endor_core::CallSignature> {
|
||||
self.signature.clone()
|
||||
}
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::range(1, usize::MAX))
|
||||
}
|
||||
|
||||
+217
-2
@@ -396,8 +396,90 @@ fn method_signature(
|
||||
Ok(signature)
|
||||
}
|
||||
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Function {
|
||||
signature: Option<CallSignature>,
|
||||
operation: Operation,
|
||||
owner: Option<ObjectRef>,
|
||||
session: Shared,
|
||||
@@ -432,6 +514,7 @@ impl NativeCallable for TypeMethod {
|
||||
return Err(invalid("incorrect receiver type for visual method"));
|
||||
}
|
||||
Function {
|
||||
signature: None,
|
||||
operation: self.operation,
|
||||
owner: Some(owner),
|
||||
session: self.session.clone(),
|
||||
@@ -445,11 +528,16 @@ impl NativeCallable for TypeMethod {
|
||||
/// constructor options precede the subclass's inherited/own field arguments.
|
||||
#[derive(Debug)]
|
||||
struct NativeFactory {
|
||||
signature: Option<CallSignature>,
|
||||
options: Option<CallSignature>,
|
||||
operation: Operation,
|
||||
session: Shared,
|
||||
}
|
||||
|
||||
impl NativeCallable for NativeFactory {
|
||||
fn signature(&self) -> Option<CallSignature> {
|
||||
self.signature.clone()
|
||||
}
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::range(
|
||||
self.operation.arity().required + 1,
|
||||
@@ -471,7 +559,16 @@ impl NativeCallable for NativeFactory {
|
||||
.ok_or(invalid("missing subclass field arguments"))?;
|
||||
cx.store()
|
||||
.check_class_field_arguments(requested, &values[native_count..])?;
|
||||
self.options
|
||||
.as_ref()
|
||||
.ok_or(invalid("native factory is not initialized"))?
|
||||
.check_arguments(
|
||||
cx.store(),
|
||||
"native constructor options",
|
||||
&values[..native_count],
|
||||
)?;
|
||||
let result = Function {
|
||||
signature: None,
|
||||
operation: self.operation,
|
||||
owner: None,
|
||||
session: self.session.clone(),
|
||||
@@ -554,6 +651,7 @@ fn bind(
|
||||
let function = cx.allocate(ContextNativeFunction::new(
|
||||
name,
|
||||
Function {
|
||||
signature: Some(operation_signature(cx.store(), desktop, operation)?),
|
||||
operation,
|
||||
owner: Some(owner),
|
||||
session: session.clone(),
|
||||
@@ -811,6 +909,9 @@ fn present_value(
|
||||
}
|
||||
|
||||
impl NativeCallable for Function {
|
||||
fn signature(&self) -> Option<CallSignature> {
|
||||
self.signature.clone()
|
||||
}
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(self.operation.arity())
|
||||
}
|
||||
@@ -2515,6 +2616,8 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
next_mount: 0,
|
||||
retired_commands: Vec::new(),
|
||||
}));
|
||||
let mut public_functions = Vec::new();
|
||||
let mut factories = Vec::new();
|
||||
for (name, operation) in [
|
||||
("implement", Operation::Implement),
|
||||
("implements", Operation::Implements),
|
||||
@@ -2539,6 +2642,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
let function = vm.allocate(ContextNativeFunction::new(
|
||||
name,
|
||||
Function {
|
||||
signature: None,
|
||||
operation,
|
||||
owner: None,
|
||||
session: session.clone(),
|
||||
@@ -2548,6 +2652,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
))?;
|
||||
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]);
|
||||
@@ -2582,7 +2687,10 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
Some("object-list") => {
|
||||
let factory = vm.allocate(ContextNativeFunction::new(
|
||||
"object-list",
|
||||
crate::object_list::Constructor { desktop },
|
||||
crate::object_list::Constructor {
|
||||
desktop,
|
||||
signature: None,
|
||||
},
|
||||
vec![desktop],
|
||||
))?;
|
||||
roots.push(factory);
|
||||
@@ -2593,7 +2701,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
Some("event") => {
|
||||
let factory = vm.allocate(ContextNativeFunction::new(
|
||||
"event",
|
||||
crate::event_dispatch::Constructor,
|
||||
crate::event_dispatch::Constructor { signature: None },
|
||||
vec![],
|
||||
))?;
|
||||
roots.push(factory);
|
||||
@@ -2617,6 +2725,8 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
let factory = vm.allocate(ContextNativeFunction::new(
|
||||
constructor_name,
|
||||
NativeFactory {
|
||||
signature: None,
|
||||
options: None,
|
||||
operation,
|
||||
session: session.clone(),
|
||||
},
|
||||
@@ -2629,6 +2739,10 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
}
|
||||
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))?;
|
||||
@@ -2681,6 +2795,107 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
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",
|
||||
|
||||
Reference in New Issue
Block a user