import assert from 'node:assert/strict'; import {readFileSync,writeFileSync} from 'node:fs'; const components=[['threads','os-threads/src/threads.rs','thread'],['context','os-context-switch/src/context.rs','context'],['runqueue','os-runqueue/src/runqueue.rs','queue'],['local','os-percpu-runqueue/src/local.rs','local']]; const substitutions=[['turkos_os_threads::threads','crate::threads'],['turkos_os_context_switch::context','crate::context'],['turkos_os_runqueue::runqueue','crate::runqueue']]; export function migrationHostSources(){return components.map(([name,path,extension])=>{ let source=readFileSync(path,'utf8');for(const[a,b]of substitutions)source=source.replaceAll(a,b); source+='\n'+readFileSync(`os-thread-migration/src/${extension}-extension.rs`,'utf8'); if(name==='threads')source+='\nimpl Table{pub fn stack_observation(&self,id:ThreadId)->Result{self.context()?;let i=self.index(id)?;self.backend.observe(self.slots[i].stack.as_ref().ok_or(Error::State)?)} }\n'; if(name==='runqueue')source+='\nimpl Queue{/// # Safety\n/// Preserve every retained queue member and its backend pins.\npub unsafe fn with_migration_backend(&mut self,f:impl FnOnce(&mut B)->R)->R{f(&mut self.backend)}}\n'; return {name,path:`os-thread-migration/src/${name}.rs`,source}; });} export function writeMigrationHostSources(){for(const s of migrationHostSources())writeFileSync(s.path,s.source);} export function verifyMigrationHostSources(){for(const s of migrationHostSources())assert.equal(readFileSync(s.path,'utf8'),s.source,s.path);}