Compare commits
2 Commits
65f5092f0f
...
ae89dfad1e
| Author | SHA1 | Date | |
|---|---|---|---|
| ae89dfad1e | |||
| 618bffdada |
@@ -544,4 +544,7 @@ Complete-source candidates now separate one-time compilation/source execution fr
|
||||
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 no override needs a pause); 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.
|
||||
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.
|
||||
|
||||
+4
-1
@@ -199,4 +199,7 @@ Complete-source candidates now separate one-time compilation/source execution fr
|
||||
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 no override needs a pause); 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.
|
||||
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.
|
||||
|
||||
+3
-1
@@ -1501,7 +1501,9 @@ REPL/event requests retain their HTTP request and scalar result until the comple
|
||||
|
||||
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 no override needs a pause); 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.
|
||||
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 host object
|
||||
|
||||
|
||||
@@ -3221,6 +3221,64 @@ page.render(block)
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layout_and_paint_prepare_keep_only_current_occurrence_managed_helpers() {
|
||||
for copies in [160, 640] {
|
||||
let (mut session, initial) =
|
||||
ReplSession::load(&resumable_paint_source(copies, 0), "app.main", 280, 1).unwrap();
|
||||
let before = session.candidate.vm.object_count();
|
||||
let progress = session
|
||||
.bridge
|
||||
.begin_paint_frame(
|
||||
&mut session.candidate.vm,
|
||||
initial.ui_root.clone(),
|
||||
initial.frame,
|
||||
)
|
||||
.unwrap();
|
||||
let crate::source_paint::Progress::Pending(work) = progress else {
|
||||
panic!("paint must yield");
|
||||
};
|
||||
// Each quantum may retain its current helper/results, not a Bounds
|
||||
// and collector for every occurrence before reaching the first one.
|
||||
assert!(session.candidate.vm.object_count() < before + 256);
|
||||
session
|
||||
.bridge
|
||||
.cancel_paint_frame(&mut session.candidate.vm, crate::window::MAIN_WINDOW, *work)
|
||||
.unwrap();
|
||||
assert!(!session.candidate.vm.has_suspended_call());
|
||||
session
|
||||
.bridge
|
||||
.set_viewport(
|
||||
&mut session.candidate.vm,
|
||||
Some(crate::layout::Size {
|
||||
width: 900.0,
|
||||
height: 650.0,
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
let root = session
|
||||
.bridge
|
||||
.prepare_frame(&mut session.candidate.vm)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let before = session.candidate.vm.object_count();
|
||||
let progress = session
|
||||
.bridge
|
||||
.begin_layout_frame(&mut session.candidate.vm, root)
|
||||
.unwrap();
|
||||
let crate::ui_bridge::LayoutProgress::Pending(work) = progress else {
|
||||
panic!("layout must yield");
|
||||
};
|
||||
assert!(session.candidate.vm.object_count() < before + 256);
|
||||
session
|
||||
.bridge
|
||||
.cancel_layout_frame(&mut session.candidate.vm, *work)
|
||||
.unwrap();
|
||||
assert!(!session.candidate.vm.has_suspended_call());
|
||||
assert!(!session.candidate.vm.object_store().is_read_only());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pending_paint_retargets_without_replaying_completed_mount_hooks() {
|
||||
let (mut session, initial) =
|
||||
|
||||
+95
-72
@@ -10,8 +10,8 @@ use crate::{
|
||||
};
|
||||
use anyhow::Result;
|
||||
use endor_core::{
|
||||
CodeLayout, ContextNativeFunction, EndorCode, EndorCodeObject, Instruction, NativeCallable,
|
||||
NativeContext, NativeResult, ObjectRef, Opcode, Value, Vm, VmError, WeakObjectRef,
|
||||
ContextNativeFunction, NativeCallable, NativeContext, NativeResult, ObjectRef, Value, Vm,
|
||||
VmError, WeakObjectRef,
|
||||
};
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
|
||||
@@ -479,7 +479,7 @@ impl NativeCallable for Collect {
|
||||
#[derive(Debug)]
|
||||
struct Settle {
|
||||
plan: Shared,
|
||||
mounts: Vec<WeakObjectRef>,
|
||||
mounts: Arc<[WeakObjectRef]>,
|
||||
}
|
||||
impl NativeCallable for Settle {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
@@ -585,7 +585,7 @@ impl NativeCallable for Settle {
|
||||
};
|
||||
if repeat {
|
||||
// No stale geometry from a prior pass is observable during measurement.
|
||||
for weak in &self.mounts {
|
||||
for weak in self.mounts.iter() {
|
||||
let mount = cx.upgrade(*weak)?.ok_or(invalid("layout Mount expired"))?;
|
||||
if let Some(context) = &cx.store().payload::<Mount>(mount, "Mount")?.layout {
|
||||
context
|
||||
@@ -609,80 +609,103 @@ impl NativeCallable for Prepare {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(0))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, _: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let mut instructions = Vec::new();
|
||||
let mut constants = Vec::new();
|
||||
for phase in [Phase::Measure, Phase::Arrange] {
|
||||
let indices: Vec<_> = match phase {
|
||||
Phase::Measure => (0..self.mounts.len()).rev().collect(),
|
||||
Phase::Arrange => (0..self.mounts.len()).collect(),
|
||||
};
|
||||
for index in indices {
|
||||
let mount = cx
|
||||
.upgrade(self.mounts[index])?
|
||||
.ok_or(invalid("layout Mount expired"))?;
|
||||
let step = cx.allocate(ContextNativeFunction::new(
|
||||
"layout step",
|
||||
Step {
|
||||
plan: self.plan.clone(),
|
||||
index,
|
||||
phase,
|
||||
mount,
|
||||
desktop: self.desktop,
|
||||
},
|
||||
vec![mount, self.desktop],
|
||||
))?;
|
||||
let collector = cx.allocate(ContextNativeFunction::new(
|
||||
"collect layout",
|
||||
Collect {
|
||||
plan: self.plan.clone(),
|
||||
index,
|
||||
phase,
|
||||
desktop: self.desktop,
|
||||
},
|
||||
vec![self.desktop],
|
||||
))?;
|
||||
let start = constants.len() as u32;
|
||||
constants.extend([Value::Object(collector), Value::Object(step)]);
|
||||
instructions.extend([
|
||||
Instruction::new(Opcode::LoadConst, start),
|
||||
Instruction::simple(Opcode::PushNull),
|
||||
Instruction::new(Opcode::LoadConst, start + 1),
|
||||
Instruction::simple(Opcode::PushNull),
|
||||
Instruction::new(Opcode::Call, 0),
|
||||
Instruction::new(Opcode::Call, 1),
|
||||
Instruction::simple(Opcode::PopTop),
|
||||
]);
|
||||
let advance = cx.allocate(ContextNativeFunction::new(
|
||||
"next layout occurrence",
|
||||
Advance {
|
||||
plan: self.plan.clone(),
|
||||
mounts: self.mounts.clone().into(),
|
||||
desktop: self.desktop,
|
||||
next: Mutex::new(0),
|
||||
},
|
||||
vec![self.desktop],
|
||||
))?;
|
||||
let function = crate::vm_sequence::repeat_call(cx, advance, "source layout", self.desktop)?;
|
||||
Ok(NativeResult::Invoke {
|
||||
function,
|
||||
arguments: vec![],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Advance {
|
||||
plan: Shared,
|
||||
mounts: Arc<[WeakObjectRef]>,
|
||||
desktop: ObjectRef,
|
||||
next: Mutex<usize>,
|
||||
}
|
||||
impl NativeCallable for Advance {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(0))
|
||||
}
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, _: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let count = self.mounts.len();
|
||||
let position = {
|
||||
let mut next = self
|
||||
.next
|
||||
.lock()
|
||||
.map_err(|_| invalid("layout cursor poisoned"))?;
|
||||
let position = *next;
|
||||
if position < count * 2 {
|
||||
*next += 1;
|
||||
}
|
||||
}
|
||||
let settle = cx.allocate(ContextNativeFunction::new(
|
||||
"settle source layout",
|
||||
Settle {
|
||||
position
|
||||
};
|
||||
if position == count * 2 {
|
||||
let settled = Settle {
|
||||
plan: self.plan.clone(),
|
||||
mounts: self.mounts.clone(),
|
||||
}
|
||||
.invoke(cx, &[])?;
|
||||
let NativeResult::Return(Value::Bool(repeat)) = settled else {
|
||||
return Err(invalid("invalid settling result"));
|
||||
};
|
||||
if repeat {
|
||||
*self
|
||||
.next
|
||||
.lock()
|
||||
.map_err(|_| invalid("layout cursor poisoned"))? = 0;
|
||||
}
|
||||
return Ok(NativeResult::Return(Value::Bool(repeat)));
|
||||
}
|
||||
let (phase, index) = if position < count {
|
||||
(Phase::Measure, count - position - 1)
|
||||
} else {
|
||||
(Phase::Arrange, position - count)
|
||||
};
|
||||
let mount = cx
|
||||
.upgrade(self.mounts[index])?
|
||||
.ok_or(invalid("layout Mount expired"))?;
|
||||
let step = cx.allocate(ContextNativeFunction::new(
|
||||
"layout step",
|
||||
Step {
|
||||
plan: self.plan.clone(),
|
||||
index,
|
||||
phase,
|
||||
mount,
|
||||
desktop: self.desktop,
|
||||
},
|
||||
vec![],
|
||||
vec![mount, self.desktop],
|
||||
))?;
|
||||
let check = constants.len() as u32;
|
||||
constants.push(Value::Object(settle));
|
||||
instructions.extend([
|
||||
Instruction::new(Opcode::LoadConst, check),
|
||||
Instruction::simple(Opcode::PushNull),
|
||||
Instruction::new(Opcode::Call, 0),
|
||||
]);
|
||||
crate::vm_sequence::repeat_while(&mut instructions)?;
|
||||
let end = constants.len() as u32;
|
||||
constants.push(Value::Nil);
|
||||
instructions.extend([
|
||||
Instruction::new(Opcode::LoadConst, end),
|
||||
Instruction::simple(Opcode::ReturnValue),
|
||||
]);
|
||||
let code = EndorCode::from_instructions(&instructions, constants, CodeLayout::default())?
|
||||
.with_location("<source layout>", "<tessera>", 1);
|
||||
let code = cx.allocate(EndorCodeObject::new(code))?;
|
||||
let globals = cx.new_dict()?;
|
||||
let function = cx.new_function("source layout", code, globals)?;
|
||||
let collector = cx.allocate(ContextNativeFunction::new(
|
||||
"collect layout",
|
||||
Collect {
|
||||
plan: self.plan.clone(),
|
||||
index,
|
||||
phase,
|
||||
desktop: self.desktop,
|
||||
},
|
||||
vec![self.desktop],
|
||||
))?;
|
||||
let function = crate::vm_sequence::collect_and_continue(
|
||||
cx,
|
||||
collector,
|
||||
step,
|
||||
vec![],
|
||||
"layout occurrence",
|
||||
self.desktop,
|
||||
)?;
|
||||
Ok(NativeResult::Invoke {
|
||||
function,
|
||||
arguments: vec![],
|
||||
|
||||
+91
-75
@@ -9,8 +9,8 @@ use crate::{
|
||||
};
|
||||
use anyhow::{Result, bail};
|
||||
use endor_core::{
|
||||
CodeLayout, ContextNativeFunction, EndorCode, EndorCodeObject, Instruction, NativeCallable,
|
||||
NativeContext, NativeResult, ObjectRef, ObjectStore, Opcode, Value, Vm, VmError, WeakObjectRef,
|
||||
ContextNativeFunction, NativeCallable, NativeContext, NativeResult, ObjectRef, ObjectStore,
|
||||
Value, Vm, VmError, WeakObjectRef,
|
||||
};
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet, HashMap},
|
||||
@@ -189,83 +189,99 @@ impl NativeCallable for Prepare {
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, _: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let mut constants = Vec::new();
|
||||
let mut instructions = Vec::new();
|
||||
for (id, weak) in &self.mounts {
|
||||
let mount = cx
|
||||
.upgrade(*weak)?
|
||||
.ok_or(invalid("paint Mount has expired"))?;
|
||||
let data = cx.store().payload::<Mount>(mount, "Mount")?.clone();
|
||||
if !data.mounted {
|
||||
return Err(invalid("paint Mount is detached"));
|
||||
}
|
||||
let definition = cx
|
||||
.store()
|
||||
.type_of(data.block)?
|
||||
.ok_or(invalid("untyped paint target"))?;
|
||||
let function = cx
|
||||
.store()
|
||||
.lookup_method(definition, "paint")?
|
||||
.ok_or(invalid("missing paint method"))?;
|
||||
if crate::native_visual::is_intrinsic(cx.store(), function, "paint", self.desktop)? {
|
||||
continue;
|
||||
}
|
||||
let bounds = cx.new_object()?;
|
||||
attach_desktop_type(cx, bounds, "Bounds", self.desktop)?;
|
||||
for (name, value) in [
|
||||
("x", data.geometry.x),
|
||||
("y", data.geometry.y),
|
||||
("width", data.geometry.width),
|
||||
("height", data.geometry.height),
|
||||
] {
|
||||
cx.set_attr(bounds, name, Value::Number((value as f64).into()))?;
|
||||
}
|
||||
let collector = cx.allocate(ContextNativeFunction::new(
|
||||
"collect source paint",
|
||||
Collect {
|
||||
desktop: self.desktop,
|
||||
mount: *id,
|
||||
output: self.output.clone(),
|
||||
},
|
||||
vec![self.desktop],
|
||||
))?;
|
||||
let start = constants.len() as u32;
|
||||
constants.extend([
|
||||
Value::Object(collector),
|
||||
Value::Object(function),
|
||||
let advance = cx.allocate(ContextNativeFunction::new(
|
||||
"next paint occurrence",
|
||||
Advance {
|
||||
desktop: self.desktop,
|
||||
mounts: self.mounts.clone().into(),
|
||||
next: Mutex::new(0),
|
||||
output: self.output.clone(),
|
||||
},
|
||||
vec![self.desktop],
|
||||
))?;
|
||||
let function = crate::vm_sequence::repeat_call(cx, advance, "source paint", self.desktop)?;
|
||||
Ok(NativeResult::Invoke {
|
||||
function,
|
||||
arguments: vec![],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Advance {
|
||||
desktop: ObjectRef,
|
||||
mounts: Arc<[(u64, WeakObjectRef)]>,
|
||||
next: Mutex<usize>,
|
||||
output: Output,
|
||||
}
|
||||
impl NativeCallable for Advance {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(0))
|
||||
}
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, _: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let occurrence = {
|
||||
let mut next = self
|
||||
.next
|
||||
.lock()
|
||||
.map_err(|_| invalid("paint cursor poisoned"))?;
|
||||
let occurrence = self.mounts.get(*next).copied();
|
||||
*next += usize::from(occurrence.is_some());
|
||||
occurrence
|
||||
};
|
||||
let Some((id, weak)) = occurrence else {
|
||||
return Ok(NativeResult::Return(Value::Bool(false)));
|
||||
};
|
||||
let mount = cx
|
||||
.upgrade(weak)?
|
||||
.ok_or(invalid("paint Mount has expired"))?;
|
||||
let data = cx.store().payload::<Mount>(mount, "Mount")?.clone();
|
||||
if !data.mounted {
|
||||
return Err(invalid("paint Mount is detached"));
|
||||
}
|
||||
let definition = cx
|
||||
.store()
|
||||
.type_of(data.block)?
|
||||
.ok_or(invalid("untyped paint target"))?;
|
||||
let function = cx
|
||||
.store()
|
||||
.lookup_method(definition, "paint")?
|
||||
.ok_or(invalid("missing paint method"))?;
|
||||
if crate::native_visual::is_intrinsic(cx.store(), function, "paint", self.desktop)? {
|
||||
return Ok(NativeResult::Return(Value::Bool(true)));
|
||||
}
|
||||
let bounds = cx.new_object()?;
|
||||
attach_desktop_type(cx, bounds, "Bounds", self.desktop)?;
|
||||
for (name, value) in [
|
||||
("x", data.geometry.x),
|
||||
("y", data.geometry.y),
|
||||
("width", data.geometry.width),
|
||||
("height", data.geometry.height),
|
||||
] {
|
||||
cx.set_attr(bounds, name, Value::Number((value as f64).into()))?;
|
||||
}
|
||||
let collector = cx.allocate(ContextNativeFunction::new(
|
||||
"collect source paint",
|
||||
Collect {
|
||||
desktop: self.desktop,
|
||||
mount: id,
|
||||
output: self.output.clone(),
|
||||
},
|
||||
vec![self.desktop],
|
||||
))?;
|
||||
let function = crate::vm_sequence::collect_and_continue(
|
||||
cx,
|
||||
collector,
|
||||
function,
|
||||
vec![
|
||||
Value::Object(data.block),
|
||||
Value::Object(mount),
|
||||
Value::Object(bounds),
|
||||
]);
|
||||
instructions.extend([
|
||||
Instruction::new(Opcode::LoadConst, start),
|
||||
Instruction::simple(Opcode::PushNull),
|
||||
Instruction::new(Opcode::LoadConst, start + 1),
|
||||
Instruction::simple(Opcode::PushNull),
|
||||
Instruction::new(Opcode::LoadConst, start + 2),
|
||||
Instruction::new(Opcode::LoadConst, start + 3),
|
||||
Instruction::new(Opcode::LoadConst, start + 4),
|
||||
Instruction::new(Opcode::Call, 3),
|
||||
Instruction::new(Opcode::Call, 1),
|
||||
Instruction::simple(Opcode::PopTop),
|
||||
]);
|
||||
}
|
||||
if instructions.is_empty() {
|
||||
return Ok(NativeResult::Return(Value::Nil));
|
||||
}
|
||||
let index = constants.len() as u32;
|
||||
constants.push(Value::Nil);
|
||||
instructions.extend([
|
||||
Instruction::new(Opcode::LoadConst, index),
|
||||
Instruction::simple(Opcode::ReturnValue),
|
||||
]);
|
||||
let code = EndorCode::from_instructions(&instructions, constants, CodeLayout::default())?
|
||||
.with_location("<source paint>", "<tessera>", 1);
|
||||
let code = cx.allocate(EndorCodeObject::new(code))?;
|
||||
let globals = cx.new_dict()?;
|
||||
let driver = cx.new_function("source paint", code, globals)?;
|
||||
],
|
||||
"paint occurrence",
|
||||
self.desktop,
|
||||
)?;
|
||||
Ok(NativeResult::Invoke {
|
||||
function: driver,
|
||||
function,
|
||||
arguments: vec![],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -34,6 +34,82 @@ pub fn build(
|
||||
Ok(driver)
|
||||
}
|
||||
|
||||
/// A fixed-size driver. Each callback returns whether another occurrence is
|
||||
/// needed; delegated source calls and all iterations share this VM budget.
|
||||
pub fn repeat_call(
|
||||
cx: &mut NativeContext<'_>,
|
||||
callback: ObjectRef,
|
||||
name: &'static str,
|
||||
desktop: ObjectRef,
|
||||
) -> Result<ObjectRef, VmError> {
|
||||
let mut instructions = vec![
|
||||
Instruction::new(Opcode::LoadConst, 0),
|
||||
Instruction::simple(Opcode::PushNull),
|
||||
Instruction::new(Opcode::Call, 0),
|
||||
];
|
||||
repeat_while(&mut instructions)?;
|
||||
instructions.extend([
|
||||
Instruction::new(Opcode::LoadConst, 1),
|
||||
Instruction::simple(Opcode::ReturnValue),
|
||||
]);
|
||||
driver(
|
||||
cx,
|
||||
instructions,
|
||||
vec![Value::Object(callback), Value::Nil],
|
||||
name,
|
||||
desktop,
|
||||
)
|
||||
}
|
||||
|
||||
/// Prepare only the current occurrence, collect its result, then continue the
|
||||
/// outer driver. The helper frame and its managed captures die before the next.
|
||||
pub fn collect_and_continue(
|
||||
cx: &mut NativeContext<'_>,
|
||||
collector: ObjectRef,
|
||||
function: ObjectRef,
|
||||
arguments: Vec<Value>,
|
||||
name: &'static str,
|
||||
desktop: ObjectRef,
|
||||
) -> Result<ObjectRef, VmError> {
|
||||
let count = arguments.len();
|
||||
let mut constants = vec![Value::Object(collector), Value::Object(function)];
|
||||
constants.extend(arguments);
|
||||
constants.push(Value::Bool(true));
|
||||
let mut instructions = vec![
|
||||
Instruction::new(Opcode::LoadConst, 0),
|
||||
Instruction::simple(Opcode::PushNull),
|
||||
Instruction::new(Opcode::LoadConst, 1),
|
||||
Instruction::simple(Opcode::PushNull),
|
||||
];
|
||||
for index in 0..count {
|
||||
instructions.push(Instruction::new(Opcode::LoadConst, index as u32 + 2));
|
||||
}
|
||||
instructions.extend([
|
||||
Instruction::new(Opcode::Call, count as u32),
|
||||
Instruction::new(Opcode::Call, 1),
|
||||
Instruction::simple(Opcode::PopTop),
|
||||
Instruction::new(Opcode::LoadConst, count as u32 + 2),
|
||||
Instruction::simple(Opcode::ReturnValue),
|
||||
]);
|
||||
driver(cx, instructions, constants, name, desktop)
|
||||
}
|
||||
|
||||
fn driver(
|
||||
cx: &mut NativeContext<'_>,
|
||||
instructions: Vec<Instruction>,
|
||||
constants: Vec<Value>,
|
||||
name: &'static str,
|
||||
desktop: ObjectRef,
|
||||
) -> Result<ObjectRef, VmError> {
|
||||
let code = EndorCode::from_instructions(&instructions, constants, CodeLayout::default())?
|
||||
.with_location(name, "<tessera>", 1);
|
||||
let code = cx.allocate(EndorCodeObject::new(code))?;
|
||||
let globals = cx.new_dict()?;
|
||||
let function = cx.new_function(name, code, globals)?;
|
||||
crate::ui_bridge::attach_desktop_type(cx, function, "Function", desktop)?;
|
||||
Ok(function)
|
||||
}
|
||||
|
||||
/// Consume the condition on the stack: true repeats this same frame from zero,
|
||||
/// false falls through. Operand widths include EXTENDED_ARG code units.
|
||||
pub fn repeat_while(instructions: &mut Vec<Instruction>) -> Result<(), VmError> {
|
||||
|
||||
Reference in New Issue
Block a user