do some work on linking, unravel it, spawn! is now a normal fn
This commit is contained in:
parent
e76e9f5348
commit
369f8a54f4
|
@ -403,7 +403,7 @@ function __wbg_get_imports() {
|
||||||
_assertBoolean(ret);
|
_assertBoolean(ret);
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
imports.wbg.__wbindgen_closure_wrapper8088 = function() { return logError(function (arg0, arg1, arg2) {
|
imports.wbg.__wbindgen_closure_wrapper8090 = function() { return logError(function (arg0, arg1, arg2) {
|
||||||
const ret = makeMutClosure(arg0, arg1, 354, __wbg_adapter_20);
|
const ret = makeMutClosure(arg0, arg1, 354, __wbg_adapter_20);
|
||||||
return ret;
|
return ret;
|
||||||
}, arguments) };
|
}, arguments) };
|
||||||
|
|
Binary file not shown.
48
src/vm.rs
48
src/vm.rs
|
@ -73,6 +73,8 @@ pub struct Creature {
|
||||||
zoo: Rc<RefCell<Zoo>>,
|
zoo: Rc<RefCell<Zoo>>,
|
||||||
r#yield: bool,
|
r#yield: bool,
|
||||||
scrutinee: Option<Value>,
|
scrutinee: Option<Value>,
|
||||||
|
parents: Vec<&'static str>,
|
||||||
|
siblings: Vec<&'static str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Creature {
|
impl std::fmt::Display for Creature {
|
||||||
|
@ -120,6 +122,8 @@ impl Creature {
|
||||||
r#yield: false,
|
r#yield: false,
|
||||||
msg_idx: 0,
|
msg_idx: 0,
|
||||||
scrutinee: None,
|
scrutinee: None,
|
||||||
|
parents: vec![],
|
||||||
|
siblings: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,6 +259,45 @@ impl Creature {
|
||||||
self.push(Value::Keyword("ok"));
|
self.push(Value::Keyword("ok"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: fix these based on what I decide about `link` & `monitor`
|
||||||
|
fn link_report(&mut self, parent: Value, child: Value) {
|
||||||
|
let (Value::Keyword(parent), Value::Keyword(child)) = (parent, child) else {
|
||||||
|
unreachable!("expected keyword pids in link_report");
|
||||||
|
};
|
||||||
|
let child = if child == self.pid {
|
||||||
|
self
|
||||||
|
} else {
|
||||||
|
&mut self.zoo.borrow_mut().catch(child)
|
||||||
|
};
|
||||||
|
child.parents.push(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn link_panic(&mut self, left_pid: Value, right_pid: Value) {
|
||||||
|
let (Value::Keyword(left_id), Value::Keyword(right_id)) = (left_pid, right_pid) else {
|
||||||
|
unreachable!("expected keyword pids in link_panic");
|
||||||
|
};
|
||||||
|
// if we're linking to ourselves, we don't need to do anything
|
||||||
|
if left_id == self.pid && right_id == self.pid {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let mut zoo = self.zoo.borrow_mut();
|
||||||
|
// fancy footwork w/ cases: we can't catch ourselves in the zoo
|
||||||
|
if left_id == self.pid {
|
||||||
|
self.siblings.push(right_id);
|
||||||
|
let mut right = zoo.catch(right_id);
|
||||||
|
right.siblings.push(self.pid);
|
||||||
|
} else if right_id == self.pid {
|
||||||
|
self.siblings.push(left_id);
|
||||||
|
let mut left = zoo.catch(left_id);
|
||||||
|
left.siblings.push(self.pid);
|
||||||
|
} else {
|
||||||
|
let mut left = zoo.catch(left_id);
|
||||||
|
let mut right = zoo.catch(right_id);
|
||||||
|
left.siblings.push(right_id);
|
||||||
|
right.siblings.push(left_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_msg(&mut self, args: Vec<Value>) {
|
fn handle_msg(&mut self, args: Vec<Value>) {
|
||||||
println!("message received by {}: {}", self.pid, args[0]);
|
println!("message received by {}: {}", self.pid, args[0]);
|
||||||
let Value::Keyword(msg) = args.first().unwrap() else {
|
let Value::Keyword(msg) = args.first().unwrap() else {
|
||||||
|
@ -267,7 +310,7 @@ impl Creature {
|
||||||
let f = args[1].clone();
|
let f = args[1].clone();
|
||||||
let proc = Creature::spawn(f, self.zoo.clone(), self.debug);
|
let proc = Creature::spawn(f, self.zoo.clone(), self.debug);
|
||||||
let id = self.zoo.as_ref().borrow_mut().put(proc);
|
let id = self.zoo.as_ref().borrow_mut().put(proc);
|
||||||
println!("spawning new process {id}!");
|
console_log!("spawning new process {id}!");
|
||||||
self.push(Value::Keyword(id));
|
self.push(Value::Keyword(id));
|
||||||
}
|
}
|
||||||
"yield" => {
|
"yield" => {
|
||||||
|
@ -286,7 +329,8 @@ impl Creature {
|
||||||
self.push(Value::False)
|
self.push(Value::False)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"link" => todo!(),
|
"link_panic" => self.link_panic(args[1].clone(), args[2].clone()),
|
||||||
|
"link_report" => self.link_report(args[1].clone(), args[2].clone()),
|
||||||
"flush" => {
|
"flush" => {
|
||||||
let msgs = self.mbx.iter().cloned().collect::<Vec<_>>();
|
let msgs = self.mbx.iter().cloned().collect::<Vec<_>>();
|
||||||
let msgs = Vector::from(msgs);
|
let msgs = Vector::from(msgs);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user