diff --git a/assets/test_prelude.ld b/assets/test_prelude.ld index 79a5fcd..3dc08a0 100644 --- a/assets/test_prelude.ld +++ b/assets/test_prelude.ld @@ -1241,14 +1241,22 @@ fn link! { "Creates a 'hard link' between two processes: if either one dies, they both do." (pid1 as :keyword, pid2 as :keyword) -> link! (pid1, pid2, :report) (pid1 as :keyword, pid2 as :keyword, :report) -> base :process (:link_report, pid1, pid2) - (pid1 as :keyword, pid2 as :keyword, :panic) -> base :process (:link_panic, pid1, pid2) + (pid1 as :keyword, pid2 as :keyword, :enforce) -> base :process (:link_enforce, pid1, pid2) } -fn msgs () -> base :process (:msgs) +fn msgs { + "Returns the entire contents of the current process as a list. Leaves all messages in the process mailbox." + () -> base :process (:msgs) +} -fn flush! () -> base :process (:flush) +fn flush! { + "Clears the current process's mailbox." + () -> base :process (:flush)} -fn sleep! (ms as :number) -> base :process (:sleep, ms) +fn sleep! { + "Puts the current process to sleep for at least the specified number of milliseconds." + (ms as :number) -> base :process (:sleep, ms) +} #{ self @@ -1256,8 +1264,11 @@ fn sleep! (ms as :number) -> base :process (:sleep, ms) msgs spawn! yield! + alive? link! + flush! + sleep! abs abs diff --git a/src/vm.rs b/src/vm.rs index add7909..f36c1ff 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -289,7 +289,7 @@ impl Creature { .borrow_mut() .send_msg(pid, args[2].clone()); } - self.push(Value::Nil); + self.push(Value::Keyword("ok")); } "spawn" => { println!("spawning new process!"); @@ -300,8 +300,25 @@ impl Creature { } "yield" => { self.r#yield = true; - self.push(Value::Nil); + self.push(Value::Keyword("ok")); } + "alive" => { + let Value::Keyword(pid) = args[1].clone() else { + unreachable!(); + }; + let is_alive = self.zoo.as_ref().borrow().is_alive(pid); + if is_alive { + self.push(Value::True) + } else { + self.push(Value::False) + } + } + "link" => todo!(), + "flush" => { + self.mbx = VecDeque::new(); + self.push(Value::Keyword("ok")); + } + "sleep" => {} msg => panic!("Process does not understand message: {msg}"), } }