Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# The __foo stuff is a compiler hack for running raw instructions,
# so __foo runs the "foo" instruction. The single "_" stuff is to
# tell the compiler to automatically generate a register for a value.
class Pid:
def construct(id):
let @id = id
pub def id:
@id
class Process:
pub def self.spawn(code):
Pid.new(__spawn_process(_, code))
pub def self.receive:
__receive_process_message(_)
pub def self.send(pid, message):
__send_process_message(_, pid.id, message)
pub def self.current:
Pid.new(__get_current_pid(_))
let pong = Process.spawn:
let received = Process.receive
let pid = received[0]
let msg = received[1]
STDOUT.puts(msg)
Process.send(pid, "pong")
Process.send(pong, [Process.current, "ping"])
STDOUT.puts(Process.receive)
ping
pong
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.